initial commit

This commit is contained in:
2024-04-29 13:12:44 +05:45
commit 34887303c5
19300 changed files with 5268802 additions and 0 deletions

View File

@ -0,0 +1,218 @@
<?php
/**
* Main class for WP-Admin hooks
*
* This class loads all of our backend hooks and sets up admin interfaces
*
* @subpackage Admin interfaces
* @author Padam Shankhadev
* @since 1.0
* @var opts - plugin options
*/
class Nepali_Post_Date_Admin
{
private $opts;
/**
* Nepali Post Date Admin constructor
*
* Constructor first checks for the plugin version, and if this is the first activation, plugin adds version info in the DB with autoload option set to false.
* That way we can easily update across versions, if we decide to add options to the plugin, or change plugin settings and defaults
*
* @return void
* @author Padam Shankhadev
* @since 1.0
*/
public function __construct()
{
$default_opts = array(
'active' => array( 'date' => true, 'time' => true, 'modified_date' => false, 'modified_time' => false ),
'date_format' => 'd m y, l',
'custom_date_format' => ''
);
$default_opts = apply_filters('npd_modify_default_opts', $default_opts);
$this->opts = get_option('npd_opts', $default_opts);
add_action('admin_init', array($this, 'register_settings'));
add_filter('plugin_action_links_' . NEPALIPOSTDATE_BASENAME, array(&$this, 'add_settings_link'));
}
/**
* Function that is hooked into the admin initialisation and registers settings
*
* @return void
* @author Padam Shankhadev
* @since 1.0
*/
public function register_settings()
{
add_settings_section( 'npd_opts', __( 'Nepali Post Date Options', 'npdate'), array(&$this, 'settings_section_info' ), 'general' );
add_settings_field( 'npd_opts[active]', __( 'Apply Nepali Date format to', 'npdate'), array(&$this, 'active_callback' ), 'general', 'npd_opts', $this->opts['active'] );
add_settings_field( 'npd_opts[date_format]', __( 'Apply Date Format', 'npdate' ), array(&$this, 'date_format_callback' ), 'general', 'npd_opts', $this->opts['date_format'] );
add_settings_field( 'npd_opts[custom_date_format]', __( 'Custom Date Format', 'npdate' ), array(&$this, 'custom_date_format_callback' ), 'general', 'npd_opts', $this->opts['custom_date_format'] );
add_settings_field( 'npd_opts[today_date_format]', __( 'Today Date Format', 'npdate' ), array(&$this, 'today_date_format_callback' ), 'general', 'npd_opts', $this->opts['today_date_format'] );
add_settings_section( 'npd_description', __( 'How to use shortcode and function in theme template and files.', 'npdate'), array(&$this, 'settings_section_usage' ), 'general' );
register_setting( 'general', 'npd_opts', array(&$this, 'sanitize_opts' ) );
}
/**
* Function that displays the section heading information
*
* @author Padam Shankhadev
* @since 1.0
*/
public function settings_section_info()
{
echo '<div id="nepali-post-date"><hr/></div>';
}
/**
* Function that displays the section heading information
*
* @author Padam Shankhadev
* @since 1.0
*/
public function settings_section_usage()
{
echo '<div id="nepali-post-date">
<hr/>
<ol>
<li><code>'.htmlentities('<?php echo get_nepali_post_date("2020-01-01 10:00"); ?>').'</code> convert AD into nepali BS (bikram sambat) date.</li>
<li><code>'.htmlentities('<?php echo do_shortcode("[nepali_post_date post_date=\'2020-01-01 10:00\']"); ?>').'</code> convert AD into nepali BS (bikram sambat) date.</li>
<li><code>'.htmlentities('<?php echo get_nepali_today_date(); ?>').'</code> get today BS (bikram sambat) date.</li>
<li><code>'.htmlentities('<?php echo do_shortcode("[nepali_today_date]"); ?>').'</code> get today BS (bikram sambat) date.</li>
<li><code>'.htmlentities('<?php echo convert_nepali_number("0123456789"); ?>').'</code> convert any english number into nepali number.</li>
<li><code>'.htmlentities('<?php echo do_shortcode("[nepali_number number=0123456789]"); ?>').'</code> convert any english number into nepali number.</li>
</ol>
</div>';
}
/**
* Function that displays the plugin activation checkbox
*
* @author Padam Shankhadev
* @since 1.0
*/
public function active_callback( $active )
{
$checked_time = checked( $active['time'], 1, false );
$checked_date = checked( $active['date'], 1, false );
$checked_modified_time = checked( $active['modified_time'], 1, false );
$checked_modified_date = checked( $active['modified_date'], 1, false );
echo "<input type=\"checkbox\" name=\"npd_opts[active][date]\" ${checked_date}>" . __( 'Date', 'npdate' ) . '&nbsp;&nbsp;&nbsp;';
echo "<input type=\"checkbox\" name=\"npd_opts[active][time]\" ${checked_time}>" . __( 'Time', 'npdate' ) . '&nbsp;&nbsp;&nbsp;';
echo "<input type=\"checkbox\" name=\"npd_opts[active][modified_date]\" ${checked_modified_date}>" . __( 'Date (modified)', 'npdate' ) . '&nbsp;&nbsp;&nbsp;';
echo "<input type=\"checkbox\" name=\"npd_opts[active][modified_time]\" ${checked_modified_time}>" . __( 'Time (modified)', 'npdate' );
}
/**
* Function that displays the string dateformat select box
*
* @author Padam Shankhadev
* @since 1.0
*/
public function date_format_callback($date_format)
{
$date_formats = apply_filters( 'npd_date_format_opts', array('d m y, l' => __('१ बैशाख २०७३, बुधबार', 'nepali-post-date' ), 'y, d m l' => __('२०७३, १ बैशाख बुधबार', 'nepali-post-date' ) ) );
$html = '<select name="npd_opts[date_format]">';
foreach ( $date_formats as $value => $label ) {
$selected = selected( $date_format, $value, false );
$html .= '<option value="' . $value . '" ' . $selected . '>' . $label . '</option>';
}
$html .= '</select>';
echo $html;
}
/**
* Display custom date setting
*
* @since 1.1
*/
public function custom_date_format_callback( $custom_date_format )
{
echo '<input type="text" name="npd_opts[custom_date_format]" value="' . esc_attr( $custom_date_format ) . '"/> (e.g: d m y, l)<p>[Note: d = गते (१), m = महिना (बैशाख), y = बर्ष (२०७७), l = दिन (शनिबार)]</p>';
}
/**
* Display today date setting
*
* @since 1.1
*/
public function today_date_format_callback( $custom_date_format )
{
echo '<input type="text" name="npd_opts[today_date_format]" value="' . esc_attr( $today_date_format ) . '"/> (e.g: d m y, l)<p>[Note: d = गते (१), m = महिना (बैशाख), y = बर्ष (२०७७), l = दिन (शनिबार)]</p>';
}
/**
* Function that sanitizes plugin options on save
*
* @author Padam Shankhadev
* @since 1.0
* @param array $opts Nepali Post Date options
* @return array $opts Sanitized options array
*
*/
public function sanitize_opts( $opts )
{
if ( isset( $opts['active']['date'] ) ) {
$opts['active']['date'] = true;
} else {
$opts['active']['date'] = false;
}
if ( isset( $opts['active']['time'] ) ) {
$opts['active']['time'] = true;
} else {
$opts['active']['time'] = false;
}
if ( isset( $opts['active']['modified_date'] ) ) {
$opts['active']['modified_date'] = true;
} else {
$opts['active']['modified_date'] = false;
}
if ( isset( $opts['active']['modified_time'] ) ) {
$opts['active']['modified_time'] = true;
} else {
$opts['active']['modified_time'] = false;
}
$opts['custom_date_format'] = esc_html( $opts['custom_date_format'] );
$opts['today_date_format'] = esc_html( $opts['today_date_format'] );
return $opts;
}
public function add_settings_link( $links )
{
$admin_url = admin_url();
$link = array( '<a href="' . $admin_url . 'options-general.php#nepali-post-date">Settings</a>' );
return array_merge( $links, $link );
}
}
?>

View File

@ -0,0 +1,201 @@
<?php
/**
* Main Nepali Post Date plugin class.
*
* This class loads plugin options, sets filters and converts the date on selected hooks.
*
* @subpackage Frontend interfaces
* @author Padam Shankhadev
* @since 1.0
* @var opts - plugin options
*/
class Nepali_Post_Date_Frontend
{
private $opts;
private $date;
/**
* Class Constructor
*
* Loads default options, sets default filter list and adds convert_date filter to selected locations
*
* @author Padam Shankhadev
* @since 1.0
*/
public function __construct()
{
$this->date = new Nepali_Date();
$default_opts = [
'active' => [
'date' => true,
'time' => true,
'modified_date' => false,
'modified_time' => false
],
'date_format' => 'd m y, l',
'custom_date_format' => '',
'today_date_format' => ''
];
$default_opts = apply_filters( 'npd_modify_default_opts', $default_opts );
$this->opts = get_option( 'npd_opts', $default_opts );
$filter_list = array();
if ($this->opts['active']['date']):
$filter_list = array_merge( $filter_list, array( 'get_the_date', 'the_date' ) );
endif;
if ($this->opts['active']['time']) :
$filter_list = array_merge( $filter_list, array( 'get_the_time', 'the_time' ) );
endif;
if ( $this->opts['active']['modified_date'] ) :
$filter_list = array_merge( $filter_list, array( 'get_the_modified_date', 'the_modified_date' ) );
endif;
if ( $this->opts['active']['modified_time'] ) :
$filter_list = array_merge( $filter_list, array( 'get_the_modified_time', 'the_modified_time' ) );
endif;
/**
* Filter the list of applicable filter locations
*
* @since 1.0
* @param array $filter_list List of filters for time appearance change
*
*/
$filters = apply_filters(
'npd_filters',
$filter_list
);
foreach ( $filters as $filter ) :
add_filter( $filter, array( &$this, 'convert_date' ), 10, 1);
endforeach;
add_shortcode( 'nepali_post_date', array( &$this, 'nepali_post_date_shortcode') );
add_shortcode( 'nepali_today_date', array( &$this, 'nepali_today_date_shortcode') );
add_shortcode( 'nepali_number', array( &$this, 'nepali_number_shortcode') );
}
/**
* Main plugin function which does the date conversion.
*
* @param string $orig_time Original time / date string
* @author Padam Shankhadev
* @since 1.0
*/
public function convert_date( $orig_time )
{
global $post;
$converted_date = '';
//If option not set as active return original string.
if (!$this->opts['active']) {
return $orig_time;
}
if ($this->opts['custom_date_format']) {
$format = $this->opts['custom_date_format'];
} else {
$format = $this->opts['date_format'];
}
if ( $this->opts['active']['time'] ) {
$converted_date = $this->get_converted_nepali_date( strtotime( $post->post_date ), $format, true );
} else {
$converted_date = $this->get_converted_nepali_date( strtotime( $post->post_date ), $format );
}
return $converted_date;
}
public function nepali_post_date_shortcode( $attrs = array() )
{
extract( shortcode_atts( array(
'post_date' => time(),
), $attrs) );
if ( $this->opts['custom_date_format'] ) {
$format = $this->opts['custom_date_format'];
} else {
$format = $this->opts['date_format'];
}
if ( $this->opts['active']['time'] ) {
$converted_date = $this->get_converted_nepali_date( strtotime( $post_date ), $format, true );
} else {
$converted_date = $this->get_converted_nepali_date( strtotime( $post_date ), $format );
}
return $converted_date;
}
public function nepali_today_date_shortcode( $attrs = array() )
{
if ( $this->opts['today_date_format'] ) {
$format = $this->opts['today_date_format'];
} else {
$format = $this->opts['date_format'];
}
return $this->get_converted_nepali_date( time(), $format );
}
public function nepali_number_shortcode( $attrs = array() )
{
extract( shortcode_atts( array(
'number' => '0123456789',
), $attrs) );
return $this->convert_into_nepali_number( $number );
}
public function get_converted_nepali_date( $date, $format, $time = false )
{
$nepali_calender = $this->date->eng_to_nep( date( 'Y', $date ), date( 'm', $date ), date( 'd', $date ) );
$converted_date = str_replace( ['l', 'd', 'm', 'y' ], [
$nepali_calender['day'],
$this->date->convert_to_nepali_number( $nepali_calender['date'] ),
$nepali_calender['nmonth'],
$this->date->convert_to_nepali_number( $nepali_calender['year'] )
], $format );
if( $time ) {
$converted_date .= ' ' . $this->date->convert_to_nepali_number( date( 'H', $date ) ) . ':' . $this->date->convert_to_nepali_number( date( 'i', $date ) );
}
return $converted_date;
}
public function convert_into_nepali_number( $str ) {
if( empty( $str ) ) {
return 'Please enter the value.';
}
$search = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
$replace = ['', '१', '२', '३', '४', '५', '६', '७', '८', '९'];
$string = str_replace($search, $replace, $str);
return $string;
}
}

View File

@ -0,0 +1,544 @@
<?php
class Nepali_Date
{
// Data for nepali date
private $_bs = array(
0 => array(2000, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),
1 => array(2001, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
2 => array(2002, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),
3 => array(2003, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
4 => array(2004, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),
5 => array(2005, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
6 => array(2006, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),
7 => array(2007, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
8 => array(2008, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31),
9 => array(2009, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
10 => array(2010, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),
11 => array(2011, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
12 => array(2012, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30),
13 => array(2013, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
14 => array(2014, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),
15 => array(2015, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
16 => array(2016, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30),
17 => array(2017, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
18 => array(2018, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30),
19 => array(2019, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),
20 => array(2020, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30),
21 => array(2021, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
22 => array(2022, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30),
23 => array(2023, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),
24 => array(2024, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30),
25 => array(2025, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
26 => array(2026, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
27 => array(2027, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),
28 => array(2028, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
29 => array(2029, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30),
30 => array(2030, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
31 => array(2031, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),
32 => array(2032, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
33 => array(2033, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),
34 => array(2034, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
35 => array(2035, 30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31),
36 => array(2036, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
37 => array(2037, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),
38 => array(2038, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
39 => array(2039, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30),
40 => array(2040, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
41 => array(2041, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),
42 => array(2042, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
43 => array(2043, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30),
44 => array(2044, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
45 => array(2045, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30),
46 => array(2046, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
47 => array(2047, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30),
48 => array(2048, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
49 => array(2049, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30),
50 => array(2050, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),
51 => array(2051, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30),
52 => array(2052, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
53 => array(2053, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30),
54 => array(2054, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),
55 => array(2055, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
56 => array(2056, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30),
57 => array(2057, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
58 => array(2058, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),
59 => array(2059, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
60 => array(2060, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),
61 => array(2061, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
62 => array(2062, 30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31),
63 => array(2063, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
64 => array(2064, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),
65 => array(2065, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
66 => array(2066, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31),
67 => array(2067, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
68 => array(2068, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30),
69 => array(2069, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
70 => array(2070, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30),
71 => array(2071, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
72 => array(2072, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30),
73 => array(2073, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31),
74 => array(2074, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30),
75 => array(2075, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
76 => array(2076, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30),
77 => array(2077, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31),
78 => array(2078, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30),
79 => array(2079, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30),
80 => array(2080, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30),
81 => array(2081, 31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30),
82 => array(2082, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30),
83 => array(2083, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30),
84 => array(2084, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30),
85 => array(2085, 31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30),
86 => array(2086, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30),
87 => array(2087, 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30),
88 => array(2088, 30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30),
89 => array(2089, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30),
90 => array(2090, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30)
);
private $_nep_date = array('year' => '', 'month' => '', 'date' => '', 'day' => '', 'nmonth' => '', 'num_day' => '');
private $_eng_date = array('year' => '', 'month' => '', 'date' => '', 'day' => '', 'emonth' => '', 'num_day' => '');
public $debug_info = "";
/**
* Return day
*
* @param int $day
* @return string
*/
private function _get_day_of_week($day)
{
switch ($day) {
case 1:
$day = "आईतवार";
break;
case 2:
$day = "सोमबार";
break;
case 3:
$day = "मंगलवार";
break;
case 4:
$day = "बुधबार";
break;
case 5:
$day = "बिहीबार";
break;
case 6:
$day = "शुक्रबार";
break;
case 7:
$day = "शनिबार";
break;
}
return $day;
}
/**
* Return english month name
*
* @param int $m
* @return string
*/
private function _get_english_month($m)
{
$eMonth = FALSE;
switch ($m) {
case 1:
$eMonth = "January";
break;
case 2:
$eMonth = "February";
break;
case 3:
$eMonth = "March";
break;
case 4:
$eMonth = "April";
break;
case 5:
$eMonth = "May";
break;
case 6:
$eMonth = "June";
break;
case 7:
$eMonth = "July";
break;
case 8:
$eMonth = "August";
break;
case 9:
$eMonth = "September";
break;
case 10:
$eMonth = "October";
break;
case 11:
$eMonth = "November";
break;
case 12:
$eMonth = "December";
}
return $eMonth;
}
/**
* Return nepali month name
*
* @param int $m
* @return string
*/
private function _get_nepali_month($m)
{
$n_month = FALSE;
switch ($m) {
case 1:
$n_month = "बैशाख";
break;
case 2:
$n_month = "जेष्ठ";
break;
case 3:
$n_month = "असार";
break;
case 4:
$n_month = "श्रावण";
break;
case 5:
$n_month = "भाद्र";
break;
case 6:
$n_month = "आश्विन";
break;
case 7:
$n_month = "कार्तिक";
break;
case 8:
$n_month = "मंसिर";
break;
case 9:
$n_month = "पुष";
break;
case 10:
$n_month = "माघ";
break;
case 11:
$n_month = "फाल्गुन";
break;
case 12:
$n_month = "चैत्र";
break;
}
return $n_month;
}
/**
* Check if date range is in english
*
* @param int $yy
* @param int $mm
* @param int $dd
* @return bool
*/
private function _is_in_range_eng($yy, $mm, $dd)
{
if ($yy < 1944 || $yy > 2033) {
return 'Supported only between 1944-2022';
}
if ($mm < 1 || $mm > 12) {
return 'Error! month value can be between 1-12 only';
}
if ($dd < 1 || $dd > 31) {
return 'Error! day value can be between 1-31 only';
}
return TRUE;
}
/**
* Check if date is with in nepali data range
*
* @param int $yy
* @param int $mm
* @param int $dd
* @return bool
*/
private function _is_in_range_nep($yy, $mm, $dd)
{
if ($yy < 2000 || $yy > 2089) {
return 'Supported only between 2000-2089';
}
if ($mm < 1 || $mm > 12) {
return 'Error! month value can be between 1-12 only';
}
if ($dd < 1 || $dd > 32) {
return 'Error! day value can be between 1-31 only';
}
return TRUE;
}
/**
* Calculates wheather english year is leap year or not
*
* @param int $year
* @return bool
*/
public function is_leap_year($year)
{
$a = $year;
if ($a % 100 == 0) {
if ($a % 400 == 0) {
return TRUE;
} else {
return FALSE;
}
} else {
if ($a % 4 == 0) {
return TRUE;
} else {
return FALSE;
}
}
}
/**
* currently can only calculate the date between AD 1944-2033...
*
* @param int $yy
* @param int $mm
* @param int $dd
* @return array
*/
public function eng_to_nep($yy, $mm, $dd)
{
// Check for date range
$chk = $this->_is_in_range_eng($yy, $mm, $dd);
if ($chk !== TRUE) {
die($chk);
} else {
// Month data.
$month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
// Month for leap year
$lmonth = array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
$def_eyy = 1944; // initial english date.
$def_nyy = 2000;
$def_nmm = 9;
$def_ndd = 17 - 1; // inital nepali date.
$total_eDays = 0;
$total_nDays = 0;
$a = 0;
$day = 7 - 1;
$m = 0;
$y = 0;
$i = 0;
$j = 0;
$numDay = 0;
// Count total no. of days in-terms year
for ($i = 0; $i < ($yy - $def_eyy); $i++) //total days for month calculation...(english)
{
if ($this->is_leap_year($def_eyy + $i) === TRUE) {
for ($j = 0; $j < 12; $j++) {
$total_eDays += $lmonth[$j];
}
} else {
for ($j = 0; $j < 12; $j++) {
$total_eDays += $month[$j];
}
}
}
// Count total no. of days in-terms of month
for ($i = 0; $i < ($mm - 1); $i++) {
if ($this->is_leap_year($yy) === TRUE) {
$total_eDays += $lmonth[$i];
} else {
$total_eDays += $month[$i];
}
}
// Count total no. of days in-terms of date
$total_eDays += $dd;
$i = 0;
$j = $def_nmm;
$total_nDays = $def_ndd;
$m = $def_nmm;
$y = $def_nyy;
// Count nepali date from array
while ($total_eDays != 0) {
$a = $this->_bs[$i][$j];
$total_nDays++; //count the days
$day++; //count the days interms of 7 days
if ($total_nDays > $a) {
$m++;
$total_nDays = 1;
$j++;
}
if ($day > 7) {
$day = 1;
}
if ($m > 12) {
$y++;
$m = 1;
}
if ($j > 12) {
$j = 1;
$i++;
}
$total_eDays--;
}
$numDay = $day;
$this->_nep_date['year'] = $y;
$this->_nep_date['month'] = $m;
$this->_nep_date['date'] = $total_nDays;
$this->_nep_date['day'] = $this->_get_day_of_week($day);
$this->_nep_date['nmonth'] = $this->_get_nepali_month($m);
$this->_nep_date['num_day'] = $numDay;
return $this->_nep_date;
}
}
/**
* Currently can only calculate the date between BS 2000-2089
*
* @param int $yy
* @param int $mm
* @param int $dd
* @return array
*/
public function nep_to_eng($yy, $mm, $dd)
{
$def_eyy = 1943;
$def_emm = 4;
$def_edd = 14 - 1; // initial english date.
$def_nyy = 2000;
$def_nmm = 1;
$def_ndd = 1; // iniital equivalent nepali date.
$total_eDays = 0;
$total_nDays = 0;
$a = 0;
$day = 4 - 1;
$m = 0;
$y = 0;
$i = 0;
$k = 0;
$numDay = 0;
$month = array(
0,
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31
);
$lmonth = array(
0,
31,
29,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31
);
// Check for date range
$chk = $this->_is_in_range_nep($yy, $mm, $dd);
if ($chk !== TRUE) {
die($chk);
} else {
// Count total days in-terms of year
for ($i = 0; $i < ($yy - $def_nyy); $i++) {
for ($j = 1; $j <= 12; $j++) {
$total_nDays += $this->_bs[$k][$j];
}
$k++;
}
// Count total days in-terms of month
for ($j = 1; $j < $mm; $j++) {
$total_nDays += $this->_bs[$k][$j];
}
// Count total days in-terms of dat
$total_nDays += $dd;
// Calculation of equivalent english date...
$total_eDays = $def_edd;
$m = $def_emm;
$y = $def_eyy;
while ($total_nDays != 0) {
if ($this->is_leap_year($y)) {
$a = $lmonth[$m];
} else {
$a = $month[$m];
}
$total_eDays++;
$day++;
if ($total_eDays > $a) {
$m++;
$total_eDays = 1;
if ($m > 12) {
$y++;
$m = 1;
}
}
if ($day > 7) {
$day = 1;
}
$total_nDays--;
}
$numDay = $day;
$this->_eng_date['year'] = $y;
$this->_eng_date['month'] = $m;
$this->_eng_date['date'] = $total_eDays;
$this->_eng_date['day'] = $this->_get_day_of_week($day);
$this->_eng_date['nmonth'] = $this->_get_english_month($m);
$this->_eng_date['num_day'] = $numDay;
return $this->_eng_date;
}
}
function convert_to_nepali_number($str)
{
$str = strval($str);
$array = array(0 => '&#2406;',
1 => '&#2407;',
2 => '&#2408;',
3 => '&#2409;',
4 => '&#2410;',
5 => '&#2411;',
6 => '&#2412;',
7 => '&#2413;',
8 => '&#2414;',
9 => '&#2415;',
/*'.'=>'&#2404;'*/
);
$utf = "";
$cnt = strlen($str);
for ($i = 0; $i < $cnt; $i++) {
if (!isset($array[$str[$i]])) {
$utf .= $str[$i];
} else
$utf .= $array[$str[$i]];
}
return $utf;
}
}
// Example:
// $cal = new Nepali_Calendar();
// print_r ($cal->eng_to_nep(2008,11,23));
// print_r($cal->nep_to_eng(2065,8,8));

View File

@ -0,0 +1,40 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2017-01-30 15:50+0545\n"
"PO-Revision-Date: 2017-01-30 16:14+0545\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.8.7.1\n"
"X-Poedit-KeywordsList: __;_e\n"
"X-Poedit-Basepath: .\n"
"Last-Translator: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: ne_NP\n"
"X-Poedit-SearchPath-0: ..\n"
#: ../class.nepali.date.admin.php:57
msgid "Nepali Post Date Options"
msgstr "नेपाली पोस्टडेट ओप्सन"
#: ../class.nepali.date.admin.php:59
msgid "Apply Nepali Date format to"
msgstr "नेपाली पोस्टडेट अप्लाई गर्नुस"
#: ../class.nepali.date.admin.php:60
msgid "Apply Date Format"
msgstr "मिती फोर्म्याथ "
#: ../class.nepali.date.admin.php:61
msgid "Custom Date Format"
msgstr "कस्टम मिती फोर्म्याथ"
#: ../class.nepali.date.admin.php:88
msgid "Date"
msgstr "मिती"
#: ../class.nepali.date.admin.php:89
msgid "Time"
msgstr "समय"

View File

@ -0,0 +1,39 @@
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2017-01-30 16:15+0545\n"
"PO-Revision-Date: 2016-01-06 18:46+0100\n"
"Last-Translator: MeksHQ <support@mekshq.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.8.7.1\n"
"X-Poedit-KeywordsList: __;_e\n"
"X-Poedit-Basepath: .\n"
"X-Poedit-SearchPath-0: ..\n"
#: ../class.nepali.date.admin.php:57
msgid "Nepali Post Date Options"
msgstr ""
#: ../class.nepali.date.admin.php:59
msgid "Apply Nepali Date format to"
msgstr ""
#: ../class.nepali.date.admin.php:60
msgid "Apply Date Format"
msgstr ""
#: ../class.nepali.date.admin.php:61
msgid "Custom Date Format"
msgstr ""
#: ../class.nepali.date.admin.php:88
msgid "Date"
msgstr ""
#: ../class.nepali.date.admin.php:89
msgid "Time"
msgstr ""

View File

@ -0,0 +1,137 @@
<?php
/*
Plugin Name: Nepali Post Date
Plugin URI: https://wordpress.org/plugins/nepali-post-date/
Description: Nepali Post date is a wordpress plugin that converts the English date format to nepal date format. Not only does it convert the date format but also the hours too.
Version: 5.1.1
Author: Padam Shankhadev
Author URI: https://www.padamshankhadev.com
*/
/* Prevent Direct access */
if ( !defined( 'DB_NAME' ) ) {
header( 'HTTP/1.0 403 Forbidden' );
die;
}
/* Define BaseName */
if ( !defined( 'NEPALIPOSTDATE_BASENAME' ) )
define( 'NEPALIPOSTDATE_BASENAME', plugin_basename( __FILE__ ) );
/* Define plugin url */
if( !defined('NEPALIPOSTDATE_PLUGIN_URL' ))
define('NEPALIPOSTDATE_PLUGIN_URL', plugin_dir_url(__FILE__));
/* Define plugin path */
if( !defined('NEPALIPOSTDATE_PLUGIN_DIR' ))
define('NEPALIPOSTDATE_PLUGIN_DIR', plugin_dir_path(__FILE__));
/* Plugin version */
define('NEPALIPOSTDATE', '5.1.1');
/* Load Up the text domain */
function npdate_textdomain() {
load_plugin_textdomain( 'npdate', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
add_action( 'plugins_loaded', 'npdate_textdomain' );
/* Check if we're running compatible software */
if ( version_compare( PHP_VERSION, '5.2', '<' ) && version_compare( WP_VERSION, '3.7', '<' ) ) {
if ( is_admin() ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
deactivate_plugins( __FILE__ );
wp_die( __( 'Nepali post date plugin requires WordPress 3.8 and PHP 5.3 or greater. The plugin has now disabled itself' ) );
}
}
/* Let's load up our plugin */
function npd_frontend_init() {
require_once( NEPALIPOSTDATE_PLUGIN_DIR . 'class.nepali.date.php' );
require_once( NEPALIPOSTDATE_PLUGIN_DIR . 'class.nepali.date.front.php' );
new Nepali_Post_Date_Frontend();
}
function npd_admin_init() {
require_once( NEPALIPOSTDATE_PLUGIN_DIR . 'class.nepali.date.admin.php' );
new Nepali_Post_Date_Admin();
}
if( is_admin() ) :
add_action( 'plugins_loaded', 'npd_admin_init', 15 );
else :
add_action( 'plugins_loaded', 'npd_frontend_init', 50 );
endif;
if( ! function_exists( 'get_nepali_post_date' )) {
function get_nepali_post_date( $post_date ) {
$f_date = new Nepali_Post_Date_Frontend();
$default_opts = array(
'active' => array( 'date' => true, 'time' => true ),
'date_format' => 'd m y, l',
'custom_date_format' => ''
);
$default_opts = apply_filters( 'npd_modify_default_opts', $default_opts );
$opts = get_option( 'npd_opts', $default_opts );
$post_date = ( !empty( $post_date ) ) ? strtotime( $post_date ) : time();
if ( $opts['custom_date_format'] ) {
$format = $opts['custom_date_format'];
} else {
$format = $opts['date_format'];
}
if ( $opts['active']['time'] ) {
$converted_date = $f_date->get_converted_nepali_date( $post_date, $format, true );
} else {
$converted_date = $f_date->get_converted_nepali_date( $post_date, $format );
}
return $converted_date;
}
}
if( ! function_exists( 'get_nepali_today_date' ) ) {
function get_nepali_today_date() {
$f_date = new Nepali_Post_Date_Frontend();
$default_opts = array(
'date_format' => 'd m y, l',
'today_date_format' => ''
);
$default_opts = apply_filters( 'npd_modify_default_opts', $default_opts );
$opts = get_option( 'npd_opts', $default_opts );
if ( $opts['today_date_format'] ) {
$format = $opts['today_date_format'];
} else {
$format = $opts['date_format'];
}
return $f_date->get_converted_nepali_date( time(), $format );
}
}
if( ! function_exists( 'convert_into_nepali_number' ) ) {
function convert_into_nepali_number( $str ) {
$f_date = new Nepali_Post_Date_Frontend();
return $f_date->convert_into_nepali_number( $str );
}
}

View File

@ -0,0 +1,74 @@
=== Nepali Post Date ===
Contributors: shankhadev123
Tags: Nepali Post Date, Nepal, Nepali, Nepali Date, Nepali Date Convert
Requires at least: 3.6
Tested up to: 5.5
Stable tag: 5.1.1
License: GPLv2 or later
== Description ==
Nepali Post date is a wordpress plugin that converts the English date format to nepal date format. Not only does it convert the date format but also the hours too.
Who is it useful for ?
The plugin is useful for any website that needs to display the date and time in Nepali Calendar format. With the shortcodes built one can use the feature to display:
a) Date in Nepali format
b) Post date and hours in Nepali format
c) Post modified Date and Hours in Nepali format
The Nepali Post Date, WordPress Plugin is popular among the Nepali news portals built on WordPress becasue as per the regulation each news should have:
i) News Post Date and Time
ii) News Modified date and Time
== Features ==
* Convert post date into nepali BS date.
* Time ago option only available in [Pro Version](https://padamshankhadev.com)
* Convert the date using function get_nepali_post_date('your-date') or using shortcode [nepali_post_date post_date='your-date'].
* Get today date using function get_nepali_today_date() or using shortcode [nepali_today_date].
* Convert any number into nepali number using function convert_nepali_number('your-number') or using shortcode [nepali_number number='your-number'].
== Screenshots ==
1. Admin setting
2. Front Display
== Installation ==
Upload the Nepali Post Date plugin to your blog, Activate it.
1, 2, 3: You're done!
== Changelog ==
= 5.1.1 =
* Added plugin usage description in admin page.
* Fixes minor bugs.
= 5.1.0 =
* Added shortcode [nepali_number number='your-number']
* Added plugin function convert_nepali_number('your-number')
= 5.0.0 =
* Fixes the bugs.
* Refactor unwanted codes.
= 4.0.0 =
* Fixes the bugs.
= 3.0.0 =
* Added shortcode [nepali_post_date post_date='your-date'].
* Added plugin function where you want to convert date manually like get_nepali_post_date('your-date').
= 2.0.0 =
* Support nepali translation.
= 1.0.0 =
* This is first version of the plugin.
== Developers ==
* Padam Shankhadev

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB