Parsi Date - Version 2.2.3

Version Description

  • Conflict timezone with wordpress default timezone #issue
Download this release

Release Info

Developer mostafa.s1990
Plugin Icon Parsi Date
Version 2.2.3
Comparing to
See all releases

Code changes from version 2.2.2 to 2.2.3

README.md ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Persian date support for WordPress
2
+
3
+ Description
4
+ -----------
5
+
6
+ This package is made by Persian developers to bring so much better experience of Persian WordPress. It includes Shamsi (Jalali) calendar, character issues fixes and Right-To-Left fix for WordPress back-end environment.
7
+
8
+ List of some features:
9
+
10
+ - Shamsi (Jalali) date in Posts, comments, pages, archives, search, categories
11
+ - Shamsi (Jalali) date in Permalinks
12
+ - Shamsi (Jalali) date in admin sections such as posts lists, comments lists, pages lists
13
+ - Shamsi (Jalali) date in post quick edit, comment quick edit, page quick edit of admin panel
14
+ - Shamsi (Jalali) calender widget
15
+ - Shamsi (Jalali) archive widget
16
+ - RTL and fixed tinymce editor
17
+ - Poweful and fast function for fixing Arabic (ي , ك) to Persian (ی , ک)
18
+ - Poweful and fast function for Persian numbers
19
+ - Low resources usage
includes/admin/lists-fix.php CHANGED
@@ -13,22 +13,26 @@
13
  * @author Ehsaan
14
  * @return void
15
  */
16
- function wpp_enqueue_admin_scripts() {
17
- wp_register_script( 'wpp_admin', WP_PARSI_URL . 'assets/js/admin.js', false, WP_PARSI_VER );
18
- wp_enqueue_script( 'wpp_admin' );
 
19
  }
20
- add_action( 'admin_enqueue_scripts', 'wpp_enqueue_admin_scripts' );
 
21
 
22
  /**
23
  * Hooks admin functions for restrict posts in edit pages
24
  *
25
  * @return void
26
  */
27
- function wpp_backend_init() {
28
- add_action( 'restrict_manage_posts', 'wpp_restrict_posts' );
29
- add_filter( 'posts_where', 'wpp_admin_posts_where' );
 
30
  }
31
- add_action( 'load-edit.php', 'wpp_backend_init' );
 
32
 
33
  /**
34
  * Limits posts to a certain date, if date setted
@@ -36,14 +40,15 @@ add_action( 'load-edit.php', 'wpp_backend_init' );
36
  * @param string $where Query pointer
37
  * @return string New Pointer
38
  */
39
- function wpp_admin_posts_where( $where ) {
40
- global $wp_query;
41
- if ( isset( $_GET['mfa'] ) && $_GET['mfa'] != '0' ) {
42
- $wp_query->query_vars['m'] = $_GET['mfa'];
43
- $where = wpp_posts_where( $where );
44
- }
 
45
 
46
- return $where;
47
  }
48
 
49
  /**
@@ -52,40 +57,41 @@ function wpp_admin_posts_where( $where ) {
52
  * @author Parsa Kafi
53
  * @return void
54
  */
55
- function wpp_restrict_posts() {
56
- global $post_type, $post_status, $wpdb, $persian_month_names;
 
57
 
58
- $post_status_w = "AND post_status <> 'auto-draft'";
59
- if($post_status != "") {
60
- if(is_string($post_status))
61
- $post_status_w .= " AND post_status = '$post_status'";
62
- }else
63
- $post_status_w .= " AND post_status <> 'trash'";
64
 
65
- $sql = "SELECT DISTINCT date( post_date ) AS date
66
  FROM $wpdb->posts
67
  WHERE post_type='$post_type' {$post_status_w} AND date( post_date ) <> '0000-00-00'
68
  ORDER BY post_date";
69
- $list = $wpdb->get_col( $sql );
70
- if ( empty( $list ) )
71
- return;
 
 
 
72
 
73
- $m = isset( $_GET['mfa'] ) ? (int) $_GET['mfa'] : 0;
74
- $predate = '';
 
 
 
 
 
75
 
76
- echo '<select name="mfa">';
77
- echo '<option ' . selected( $m, 0, false ) . ' value="0">' . __( 'Show All Dates' , 'wp-parsidate' ) . '</option>' . PHP_EOL;
78
- foreach( $list as $date ) {
79
- $date = parsidate( 'Ym', $date, 'eng' );
80
- $year = substr( $date, 0, 4 );
81
- $month = substr( $date, 4, 2 );
82
- $month = $persian_month_names[intval( $month )];
83
 
84
- if ( $predate != $date ) {
85
- echo sprintf( '<option %s value="%s">%s</option>', selected( $m, $date, false ), $date, $month . ' ' . fixnumber( $year ) );
86
- }
87
-
88
- $predate = $date;
89
- }
90
- echo '</select>';
91
  }
13
  * @author Ehsaan
14
  * @return void
15
  */
16
+ function wpp_enqueue_admin_scripts()
17
+ {
18
+ wp_register_script('wpp_admin', WP_PARSI_URL . 'assets/js/admin.js', false, WP_PARSI_VER);
19
+ wp_enqueue_script('wpp_admin');
20
  }
21
+
22
+ add_action('admin_enqueue_scripts', 'wpp_enqueue_admin_scripts');
23
 
24
  /**
25
  * Hooks admin functions for restrict posts in edit pages
26
  *
27
  * @return void
28
  */
29
+ function wpp_backend_init()
30
+ {
31
+ add_action('restrict_manage_posts', 'wpp_restrict_posts');
32
+ add_filter('posts_where', 'wpp_admin_posts_where');
33
  }
34
+
35
+ add_action('load-edit.php', 'wpp_backend_init');
36
 
37
  /**
38
  * Limits posts to a certain date, if date setted
40
  * @param string $where Query pointer
41
  * @return string New Pointer
42
  */
43
+ function wpp_admin_posts_where($where)
44
+ {
45
+ global $wp_query;
46
+ if (isset($_GET['mfa']) && $_GET['mfa'] != '0') {
47
+ $wp_query->query_vars['m'] = $_GET['mfa'];
48
+ $where = wpp_posts_where($where);
49
+ }
50
 
51
+ return $where;
52
  }
53
 
54
  /**
57
  * @author Parsa Kafi
58
  * @return void
59
  */
60
+ function wpp_restrict_posts()
61
+ {
62
+ global $post_type, $post_status, $wpdb, $persian_month_names;
63
 
64
+ $post_status_w = "AND post_status <> 'auto-draft'";
65
+ if ($post_status != "") {
66
+ if (is_string($post_status))
67
+ $post_status_w .= " AND post_status = '$post_status'";
68
+ } else
69
+ $post_status_w .= " AND post_status <> 'trash'";
70
 
71
+ $sql = "SELECT DISTINCT date( post_date ) AS date
72
  FROM $wpdb->posts
73
  WHERE post_type='$post_type' {$post_status_w} AND date( post_date ) <> '0000-00-00'
74
  ORDER BY post_date";
75
+ $list = $wpdb->get_col($sql);
76
+ if (empty($list))
77
+ return;
78
+
79
+ $m = isset($_GET['mfa']) ? (int)$_GET['mfa'] : 0;
80
+ $predate = '';
81
 
82
+ echo '<select name="mfa">';
83
+ echo '<option ' . selected($m, 0, false) . ' value="0">' . __('Show All Dates', 'wp-parsidate') . '</option>' . PHP_EOL;
84
+ foreach ($list as $date) {
85
+ $date = parsidate('Ym', $date, 'eng');
86
+ $year = substr($date, 0, 4);
87
+ $month = substr($date, 4, 2);
88
+ $month = $persian_month_names[intval($month)];
89
 
90
+ if ($predate != $date) {
91
+ echo sprintf('<option %s value="%s">%s</option>', selected($m, $date, false), $date, $month . ' ' . fixnumber($year));
92
+ }
 
 
 
 
93
 
94
+ $predate = $date;
95
+ }
96
+ echo '</select>';
 
 
 
 
97
  }
includes/admin/other-fix.php CHANGED
@@ -5,50 +5,46 @@
5
  * @package WP-Parsidate
6
  * @subpackage Admin/Other
7
  */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) exit; // No direct access allowed
10
 
11
- if(is_admin()) {
 
 
12
  /**
13
- * Fix Broken Plugins Update Link
14
- *
15
- * @author Parsa Kafi
16
- * @parms string $buffer admin page
17
- * @return string
18
- */
19
- function wpp_plugins_update_link_fix($buffer)
20
- {
21
- if (get_locale() == 'fa_IR')
22
- {
23
- if(preg_match_all('(صورت <a.*?>خودکار به‌روز کنید<\/a>)', $buffer, $update_links))
24
- {
25
- foreach($update_links[0] as $link)
26
- {
27
- preg_match('/<a href="(.+)">/', $link, $href);
28
- if(! wp_http_validate_url($href[1]))
29
- {
30
  preg_match('!https?://\S+!', $link, $url);
31
- $link_f = ' صورت '.'<a href="'.$url[0].'"> خودکار به‌روز کنید</a>';
32
  $buffer = str_replace($link, $link_f, $buffer);
33
  }
34
- }
35
- }
36
- }
37
-
38
- return $buffer;
39
- }
40
 
41
- add_action('init', 'wpp_admin_buffer_start');
42
- add_action('admin_footer', 'wpp_admin_buffer_end');
43
- function wpp_admin_buffer_start()
44
- {
45
  global $pagenow;
46
- if($pagenow == 'plugins.php')
47
  ob_start("wpp_plugins_update_link_fix");
48
- }
49
 
50
- function wpp_admin_buffer_end()
51
- {
52
- ob_end_flush();
53
- }
54
  }
5
  * @package WP-Parsidate
6
  * @subpackage Admin/Other
7
  */
 
 
8
 
9
+ if (!defined('ABSPATH')) exit; // No direct access allowed
10
+
11
+ if (is_admin()) {
12
  /**
13
+ * Fix Broken Plugins Update Link
14
+ *
15
+ * @author Parsa Kafi
16
+ * @parms string $buffer admin page
17
+ * @return string
18
+ */
19
+ function wpp_plugins_update_link_fix($buffer)
20
+ {
21
+ if (get_locale() == 'fa_IR') {
22
+ if (preg_match_all('(صورت <a.*?>خودکار به‌روز کنید<\/a>)', $buffer, $update_links)) {
23
+ foreach ($update_links[0] as $link) {
24
+ preg_match('/<a href="(.+)">/', $link, $href);
25
+ if (!wp_http_validate_url($href[1])) {
 
 
 
 
26
  preg_match('!https?://\S+!', $link, $url);
27
+ $link_f = ' صورت ' . '<a href="' . $url[0] . '"> خودکار به‌روز کنید</a>';
28
  $buffer = str_replace($link, $link_f, $buffer);
29
  }
30
+ }
31
+ }
32
+ }
33
+
34
+ return $buffer;
35
+ }
36
 
37
+ add_action('init', 'wpp_admin_buffer_start');
38
+ add_action('admin_footer', 'wpp_admin_buffer_end');
39
+ function wpp_admin_buffer_start()
40
+ {
41
  global $pagenow;
42
+ if ($pagenow == 'plugins.php')
43
  ob_start("wpp_plugins_update_link_fix");
44
+ }
45
 
46
+ function wpp_admin_buffer_end()
47
+ {
48
+ ob_end_flush();
49
+ }
50
  }
includes/admin/styles-fix.php CHANGED
@@ -13,11 +13,13 @@
13
  * @since 2.0
14
  * @return void
15
  */
16
- function wpp_fix_editor_rtl() {
17
- wp_enqueue_style( 'functions', WP_PARSI_URL . 'assets/css/admin-fix.css', false, WP_PARSI_VER, 'all' );
 
18
  }
19
- add_action( 'admin_print_styles-plugin-editor.php', 'wpp_fix_editor_rtl', 10 );
20
- add_action( 'admin_print_styles-theme-editor.php', 'wpp_fix_editor_rtl', 10 );
 
21
 
22
  /**
23
  * Fixes TinyMCE font
@@ -25,28 +27,32 @@ add_action( 'admin_print_styles-theme-editor.php', 'wpp_fix_editor_rtl', 10 );
25
  * @since 2.0
26
  * @return void
27
  */
28
- function wpp_fix_tinymce_font() {
 
29
  global $wpp_settings;
30
 
31
- add_editor_style( WP_PARSI_URL . 'assets/css/editor.css' );
32
- if ( ! isset( $wpp_settings[ 'droidsans_editor' ] ) || $wpp_settings[ 'droidsans_editor' ] != 'disable' ) {
33
- add_editor_style( WP_PARSI_URL . 'assets/css/editor-font.css' );
34
- }
35
  }
36
- add_filter( 'init', 'wpp_fix_tinymce_font', 9 );
 
37
 
38
  /**
39
  * Style for whole Admin side
40
  *
41
- * @since 2.1.5
42
- * @return void
43
  */
44
- function wpp_enqueue_admin() {
 
45
  global $wpp_settings;
46
 
47
- if ( ! isset( $wpp_settings[ 'droidsans_admin' ] ) || $wpp_settings[ 'droidsans_admin' ] != 'disable' ) {
48
- wp_enqueue_style( 'wp-parsi-fonts', WP_PARSI_URL . 'assets/css/admin-fonts.css', false, WP_PARSI_VER, 'all' );
49
- wp_enqueue_style( 'wp-parsi-admin', WP_PARSI_URL . 'assets/css/admin-styles.css', false, WP_PARSI_VER, 'all' );
50
  }
51
  }
52
- add_action( 'admin_enqueue_scripts', 'wpp_enqueue_admin' );
 
13
  * @since 2.0
14
  * @return void
15
  */
16
+ function wpp_fix_editor_rtl()
17
+ {
18
+ wp_enqueue_style('functions', WP_PARSI_URL . 'assets/css/admin-fix.css', false, WP_PARSI_VER, 'all');
19
  }
20
+
21
+ add_action('admin_print_styles-plugin-editor.php', 'wpp_fix_editor_rtl', 10);
22
+ add_action('admin_print_styles-theme-editor.php', 'wpp_fix_editor_rtl', 10);
23
 
24
  /**
25
  * Fixes TinyMCE font
27
  * @since 2.0
28
  * @return void
29
  */
30
+ function wpp_fix_tinymce_font()
31
+ {
32
  global $wpp_settings;
33
 
34
+ add_editor_style(WP_PARSI_URL . 'assets/css/editor.css');
35
+ if (!isset($wpp_settings['droidsans_editor']) || $wpp_settings['droidsans_editor'] != 'disable') {
36
+ add_editor_style(WP_PARSI_URL . 'assets/css/editor-font.css');
37
+ }
38
  }
39
+
40
+ add_filter('init', 'wpp_fix_tinymce_font', 9);
41
 
42
  /**
43
  * Style for whole Admin side
44
  *
45
+ * @since 2.1.5
46
+ * @return void
47
  */
48
+ function wpp_enqueue_admin()
49
+ {
50
  global $wpp_settings;
51
 
52
+ if (!isset($wpp_settings['droidsans_admin']) || $wpp_settings['droidsans_admin'] != 'disable') {
53
+ wp_enqueue_style('wp-parsi-fonts', WP_PARSI_URL . 'assets/css/admin-fonts.css', false, WP_PARSI_VER, 'all');
54
+ wp_enqueue_style('wp-parsi-admin', WP_PARSI_URL . 'assets/css/admin-styles.css', false, WP_PARSI_VER, 'all');
55
  }
56
  }
57
+
58
+ add_action('admin_enqueue_scripts', 'wpp_enqueue_admin');
includes/fixes-archive.php CHANGED
@@ -7,7 +7,7 @@
7
  * @author Mobin Ghasempoor
8
  */
9
 
10
- add_filter('wp_title','wpp_fix_title');
11
 
12
  /**
13
  * Fixes titles for archives
@@ -17,22 +17,23 @@ add_filter('wp_title','wpp_fix_title');
17
  * @param string $seplocation Seperator location
18
  * @return string New archive title
19
  */
20
- function wpp_fix_title( $title, $sep = '»', $seplocation = 'right' ) {
21
- global $persian_month_names, $wp_query, $wpp_settings;
22
- $query = $wp_query->query;
 
23
 
24
- if ( ! is_archive() || ( is_archive() && ! isset( $query['monthnum'] )) || ( $wpp_settings['persian_date'] == 'disable' ) )
25
- return $title;
26
 
27
- if ( $seplocation == 'right' )
28
- $query = array_reverse( $query );
29
 
30
- $query['monthnum'] = $persian_month_names[intval( $query['monthnum'] )];
31
 
32
- $title = implode( " $sep ", $query ) . " $sep ";
33
 
34
- if ( $wpp_settings['conv_page_title'] != 'disable' )
35
- $title = fixnumber($title);
36
 
37
- return $title;
38
  }
7
  * @author Mobin Ghasempoor
8
  */
9
 
10
+ add_filter('wp_title', 'wpp_fix_title');
11
 
12
  /**
13
  * Fixes titles for archives
17
  * @param string $seplocation Seperator location
18
  * @return string New archive title
19
  */
20
+ function wpp_fix_title($title, $sep = '»', $seplocation = 'right')
21
+ {
22
+ global $persian_month_names, $wp_query, $wpp_settings;
23
+ $query = $wp_query->query;
24
 
25
+ if (!is_archive() || (is_archive() && !isset($query['monthnum'])) || ($wpp_settings['persian_date'] == 'disable'))
26
+ return $title;
27
 
28
+ if ($seplocation == 'right')
29
+ $query = array_reverse($query);
30
 
31
+ $query['monthnum'] = $persian_month_names[intval($query['monthnum'])];
32
 
33
+ $title = implode(" $sep ", $query) . " $sep ";
34
 
35
+ if ($wpp_settings['conv_page_title'] != 'disable')
36
+ $title = fixnumber($title);
37
 
38
+ return $title;
39
  }
includes/fixes-archives.php CHANGED
@@ -1,175 +1,154 @@
1
  <?php
2
 
3
- /**
4
- * Create Persian Archives
5
- *
6
- * @param string $args
7
- * @return string
8
- */
9
- function wpp_get_archives($args='')
10
- {
11
- global $wpdb, $wp_locale,$persian_month_names;
12
- $defaults = array(
13
- 'type' => 'monthly', 'limit' => '',
14
- 'format' => 'html', 'before' => '',
15
- 'after' => '', 'show_post_count' => false,
16
- 'echo' => 1, 'order' => 'DESC');
17
-
18
- $r = wp_parse_args( $args, $defaults );
19
- extract( $r, EXTR_SKIP );
20
- $archive_link_m =home_url("'?m='");
21
-
22
- $results= $wpdb->get_results( "SELECT date( post_date )as date,count(ID)as count FROM $wpdb->posts WHERE post_date < NOW() AND post_type = 'post' AND post_status = 'publish' group by date ORDER BY post_date DESC");
23
- if(!empty($results))
24
- {
25
- if($type=='yearly')
26
- {
27
- $old_date=parsidate('Y',$results[0]->date,'eng');
28
- $count=$results[0]->count;
29
- $c=count($results);
30
- for($i=1;$i<$c;$i++)
31
- {
32
- $dt=$results[$i];
33
- $date=parsidate('Y',$dt->date,'eng');
34
- if($date==$old_date)
35
- $count+=$dt->count;
36
- else
37
- {
38
- echo_yarchive($old_date,$format,$before,$count,$show_post_count);
39
- $old_date=$date;
40
- $count=$dt->count;
41
- }
42
- }
43
- echo_yarchive($old_date,$format,$before,$count,$show_post_count);
44
- }
45
- elseif($type=='monthly')
46
- {
47
- $old_date=parsidate('Ym',$results[0]->date,'eng');
48
- $count=$results[0]->count;
49
- $c=count($results);
50
- for($i=1;$i<$c;$i++)
51
- {
52
- $dt=$results[$i];
53
- $date=parsidate('Ym',$dt->date,'eng');
54
- if($date==$old_date)
55
- $count+=$dt->count;
56
- else
57
- {
58
- echo_marchive($old_date,$format,$before,$count,$show_post_count);
59
- $old_date=$date;
60
- $count=$dt->count;
61
- }
62
- }
63
- echo_marchive($old_date,$format,$before,$count,$show_post_count);
64
- }
65
- elseif($type=='daily')
66
- {
67
- foreach($results as $row)
68
- {
69
- $date = parsidate('Y,m,d',$row->date,'eng');
70
- $date=explode(',',$date);
71
- if($show_post_count)
72
- $count='&nbsp;('.fixnumber($row->count).')';
73
- else
74
- $count = '';
75
- $text = fixnumber($date[2]).' '.$persian_month_names[intval($date[1])].' '.fixnumber($date[0]);
76
- echo get_archives_link(get_day_link($date[0],$date[1],$date[2]),$text,$format, $before, $count);
77
- }
78
- }
79
- }
80
- }
81
-
82
- function echo_yarchive($year,$format,$before,$count,$show_post_count)
83
- {
84
- if($show_post_count)
85
- $count='&nbsp;('.fixnumber($count).')';
86
- else
87
- $count='';
88
- echo get_archives_link(get_year_link($year),fixnumber($year), $format, $before,$count);
89
- }
90
-
91
- function echo_marchive($old_date,$format,$before,$count,$show_post_count)
92
- {
93
- global $persian_month_names;
94
- $year=substr($old_date,0,4);
95
- $month=substr($old_date,4,2);
96
- if($show_post_count)
97
- $count='&nbsp;('.fixnumber($count).')';
98
- else
99
- $count='';
100
- echo get_archives_link(get_month_link($year,$month),$persian_month_names[intval($month)].' '.fixnumber($year), $format, $before,$count);
101
- }
102
-
103
- function wp_get_parchives($args='')
104
- {
105
- global $wpdb, $wp_locale,$persian_month_names;
106
- $defaults = array(
107
- 'type' => 'monthly', 'limit' => '',
108
- 'format' => 'html', 'before' => '',
109
- 'after' => '', 'show_post_count' => false,
110
- 'echo' => 1, 'order' => 'DESC');
111
-
112
- $r = wp_parse_args( $args, $defaults );
113
- extract( $r, EXTR_SKIP );
114
- $archive_link_m =home_url("'?m='");
115
-
116
- $results= $wpdb->get_results( "SELECT date( post_date )as date,count(ID)as count FROM $wpdb->posts WHERE post_date < NOW() AND post_type = 'post' AND post_status = 'publish' group by date ORDER BY post_date DESC");
117
- if(!empty($results))
118
- {
119
- if($type=='yearly')
120
- {
121
- $old_date=parsidate('Y',$results[0]->date,'eng');
122
- $count=$results[0]->count;
123
- $c=count($results);
124
- for($i=1;$i<$c;$i++)
125
- {
126
- $dt=$results[$i];
127
- $date=parsidate('Y',$dt->date,'eng');
128
- if($date==$old_date)
129
- $count+=$dt->count;
130
- else
131
- {
132
- echo_yarchive($old_date,$format,$before,$count,$show_post_count);
133
- $old_date=$date;
134
- $count=$dt->count;
135
- }
136
- }
137
- echo_yarchive($old_date,$format,$before,$count,$show_post_count);
138
- }
139
- elseif($type=='monthly')
140
- {
141
- $old_date=parsidate('Ym',$results[0]->date,'eng');
142
- $count=$results[0]->count;
143
- $c=count($results);
144
- for($i=1;$i<$c;$i++)
145
- {
146
- $dt=$results[$i];
147
- $date=parsidate('Ym',$dt->date,'eng');
148
- if($date==$old_date)
149
- $count+=$dt->count;
150
- else
151
- {
152
- echo_marchive($old_date,$format,$before,$count,$show_post_count);
153
- $old_date=$date;
154
- $count=$dt->count;
155
- }
156
- }
157
- echo_marchive($old_date,$format,$before,$count,$show_post_count);
158
- }
159
- elseif($type=='daily')
160
- {
161
- foreach($results as $row)
162
- {
163
- $date = parsidate('Y,m,d',$row->date,'eng');
164
- $date=explode(',',$date);
165
- if($show_post_count)
166
- $count='&nbsp;('.fixnumber($row->count).')';
167
- else
168
- $count = '';
169
- $text = fixnumber($date[2]).' '.$persian_month_names[intval($date[1])].' '.fixnumber($date[0]);
170
- echo get_archives_link(get_day_link($date[0],$date[1],$date[2]),$text,$format, $before, $count);
171
- }
172
- }
173
- }
174
- }
175
  ?>
1
  <?php
2
 
3
+ /**
4
+ * Create Persian Archives
5
+ *
6
+ * @param string $args
7
+ * @return string
8
+ */
9
+ function wpp_get_archives($args = '')
10
+ {
11
+ global $wpdb, $wp_locale, $persian_month_names;
12
+ $defaults = array(
13
+ 'type' => 'monthly', 'limit' => '',
14
+ 'format' => 'html', 'before' => '',
15
+ 'after' => '', 'show_post_count' => false,
16
+ 'echo' => 1, 'order' => 'DESC');
17
+
18
+ $r = wp_parse_args($args, $defaults);
19
+ extract($r, EXTR_SKIP);
20
+ $archive_link_m = home_url("'?m='");
21
+
22
+ $results = $wpdb->get_results("SELECT date( post_date )as date,count(ID)as count FROM $wpdb->posts WHERE post_date < NOW() AND post_type = 'post' AND post_status = 'publish' group by date ORDER BY post_date DESC");
23
+ if (!empty($results)) {
24
+ if ($type == 'yearly') {
25
+ $old_date = parsidate('Y', $results[0]->date, 'eng');
26
+ $count = $results[0]->count;
27
+ $c = count($results);
28
+ for ($i = 1; $i < $c; $i++) {
29
+ $dt = $results[$i];
30
+ $date = parsidate('Y', $dt->date, 'eng');
31
+ if ($date == $old_date)
32
+ $count += $dt->count;
33
+ else {
34
+ echo_yarchive($old_date, $format, $before, $count, $show_post_count);
35
+ $old_date = $date;
36
+ $count = $dt->count;
37
+ }
38
+ }
39
+ echo_yarchive($old_date, $format, $before, $count, $show_post_count);
40
+ } elseif ($type == 'monthly') {
41
+ $old_date = parsidate('Ym', $results[0]->date, 'eng');
42
+ $count = $results[0]->count;
43
+ $c = count($results);
44
+ for ($i = 1; $i < $c; $i++) {
45
+ $dt = $results[$i];
46
+ $date = parsidate('Ym', $dt->date, 'eng');
47
+ if ($date == $old_date)
48
+ $count += $dt->count;
49
+ else {
50
+ echo_marchive($old_date, $format, $before, $count, $show_post_count);
51
+ $old_date = $date;
52
+ $count = $dt->count;
53
+ }
54
+ }
55
+ echo_marchive($old_date, $format, $before, $count, $show_post_count);
56
+ } elseif ($type == 'daily') {
57
+ foreach ($results as $row) {
58
+ $date = parsidate('Y,m,d', $row->date, 'eng');
59
+ $date = explode(',', $date);
60
+ if ($show_post_count)
61
+ $count = '&nbsp;(' . fixnumber($row->count) . ')';
62
+ else
63
+ $count = '';
64
+ $text = fixnumber($date[2]) . ' ' . $persian_month_names[intval($date[1])] . ' ' . fixnumber($date[0]);
65
+ echo get_archives_link(get_day_link($date[0], $date[1], $date[2]), $text, $format, $before, $count);
66
+ }
67
+ }
68
+ }
69
+ }
70
+
71
+ function echo_yarchive($year, $format, $before, $count, $show_post_count)
72
+ {
73
+ if ($show_post_count)
74
+ $count = '&nbsp;(' . fixnumber($count) . ')';
75
+ else
76
+ $count = '';
77
+ echo get_archives_link(get_year_link($year), fixnumber($year), $format, $before, $count);
78
+ }
79
+
80
+ function echo_marchive($old_date, $format, $before, $count, $show_post_count)
81
+ {
82
+ global $persian_month_names;
83
+ $year = substr($old_date, 0, 4);
84
+ $month = substr($old_date, 4, 2);
85
+ if ($show_post_count)
86
+ $count = '&nbsp;(' . fixnumber($count) . ')';
87
+ else
88
+ $count = '';
89
+ echo get_archives_link(get_month_link($year, $month), $persian_month_names[intval($month)] . ' ' . fixnumber($year), $format, $before, $count);
90
+ }
91
+
92
+ function wp_get_parchives($args = '')
93
+ {
94
+ global $wpdb, $wp_locale, $persian_month_names;
95
+ $defaults = array(
96
+ 'type' => 'monthly', 'limit' => '',
97
+ 'format' => 'html', 'before' => '',
98
+ 'after' => '', 'show_post_count' => false,
99
+ 'echo' => 1, 'order' => 'DESC');
100
+
101
+ $r = wp_parse_args($args, $defaults);
102
+ extract($r, EXTR_SKIP);
103
+ $archive_link_m = home_url("'?m='");
104
+
105
+ $results = $wpdb->get_results("SELECT date( post_date )as date,count(ID)as count FROM $wpdb->posts WHERE post_date < NOW() AND post_type = 'post' AND post_status = 'publish' group by date ORDER BY post_date DESC");
106
+ if (!empty($results)) {
107
+ if ($type == 'yearly') {
108
+ $old_date = parsidate('Y', $results[0]->date, 'eng');
109
+ $count = $results[0]->count;
110
+ $c = count($results);
111
+ for ($i = 1; $i < $c; $i++) {
112
+ $dt = $results[$i];
113
+ $date = parsidate('Y', $dt->date, 'eng');
114
+ if ($date == $old_date)
115
+ $count += $dt->count;
116
+ else {
117
+ echo_yarchive($old_date, $format, $before, $count, $show_post_count);
118
+ $old_date = $date;
119
+ $count = $dt->count;
120
+ }
121
+ }
122
+ echo_yarchive($old_date, $format, $before, $count, $show_post_count);
123
+ } elseif ($type == 'monthly') {
124
+ $old_date = parsidate('Ym', $results[0]->date, 'eng');
125
+ $count = $results[0]->count;
126
+ $c = count($results);
127
+ for ($i = 1; $i < $c; $i++) {
128
+ $dt = $results[$i];
129
+ $date = parsidate('Ym', $dt->date, 'eng');
130
+ if ($date == $old_date)
131
+ $count += $dt->count;
132
+ else {
133
+ echo_marchive($old_date, $format, $before, $count, $show_post_count);
134
+ $old_date = $date;
135
+ $count = $dt->count;
136
+ }
137
+ }
138
+ echo_marchive($old_date, $format, $before, $count, $show_post_count);
139
+ } elseif ($type == 'daily') {
140
+ foreach ($results as $row) {
141
+ $date = parsidate('Y,m,d', $row->date, 'eng');
142
+ $date = explode(',', $date);
143
+ if ($show_post_count)
144
+ $count = '&nbsp;(' . fixnumber($row->count) . ')';
145
+ else
146
+ $count = '';
147
+ $text = fixnumber($date[2]) . ' ' . $persian_month_names[intval($date[1])] . ' ' . fixnumber($date[0]);
148
+ echo get_archives_link(get_day_link($date[0], $date[1], $date[2]), $text, $format, $before, $count);
149
+ }
150
+ }
151
+ }
152
+ }
153
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  ?>
includes/fixes-calendar.php CHANGED
@@ -1,239 +1,238 @@
1
  <?php
2
 
3
- /**
4
- * Create Persian Calendar
5
- *
6
- * @param string $args
7
- * @author Mobin Ghasempoor
8
- * @author Parsa Kafi
9
- * @return string
10
- */
11
- function wpp_get_calendar($args='')
12
- {
13
- global $wp_query , $wpdb, $m, $monthnum, $year, $day, $posts;
14
-
15
- $pd = bn_parsidate::getInstance();
16
- $jm = $monthnum;
17
- if ($m != '') {
18
- $m = preg_replace("/[^0-9]/", "", $m);
19
- $jy = substr($m, 0, 4);
20
- } elseif ($year !== ''){
21
- $jy = $year;
22
- }
23
-
24
- if($jy>1500)
25
- list($jy,$jm,$jd) = $pd->gregorian_to_persian($year,$monthnum,$day);
26
-
27
- if ( !$posts ){
28
- $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
29
- if ( !$gotsome )
30
- return;
31
- }
32
-
33
- $week_begins = intval(get_option('start_of_week'));
34
- $w = isset($_GET['w'])?intval($_GET['w']):'';
35
- $is_gregorian= false;
36
-
37
- if ( !empty($jm) && !empty($jy) ){
38
- $thismonth = ''.zeroise(intval($jm), 2);
39
- $thisyear = ''.intval($jy);
40
-
41
- } elseif ( !empty($w) ) {
42
- $thisyear = ''.intval(substr($m, 0, 4));
43
- $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
44
- $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
45
-
46
- } elseif ( !empty($m) ) {
47
- $thisyear = ''.intval(substr($m, 0, 4));
48
- if ( strlen($m) < 6 )
49
- $thismonth = '01';
50
- else
51
- $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
52
-
53
- } else {
54
- $is_gregorian = true;
55
- $thisyear = gmdate('Y', current_time('timestamp')+get_option('gmt_offset') * 3600);
56
- $thismonth = gmdate('m', current_time('timestamp')+get_option('gmt_offset') * 3600);
57
- $thisday = gmdate('d', current_time('timestamp')+get_option('gmt_offset') * 3600);
58
- }
59
-
60
- //print_r($wp_query->query_vars);
61
-
62
- if ($is_gregorian)
63
- {
64
- list($jthisyear,$jthismonth,$jthisday) = $pd->gregorian_to_persian($thisyear,$thismonth,$thisday);
65
- $unixmonth = $pd->gregurian_date('Y-m-d 00:00:00',"$jthisyear-$jthismonth-01");
66
- } else {
67
- $gdate = $pd->persian_to_gregorian($thisyear,$thismonth,1);
68
- $unixmonth = mktime(0, 0 , 0, $gdate[1], 1, $gdate[0]);
69
- $jthisyear = $thisyear;
70
- $jthismonth = $thismonth;
71
- }
72
-
73
- $jnextmonth = $jthismonth + 1;
74
- $jnextyear = $jthisyear;
75
-
76
-
77
- if ($jnextmonth > 12)
78
- {
79
- $jnextmonth = 1;
80
- $jnextyear++;
81
- }
82
-
83
- $start = $pd->gregurian_date('Y-m-d 00:00:00',"$jthisyear-$jthismonth-01");
84
- $end = $pd->gregurian_date('Y-m-d 23:59:59',"$jnextyear-$jthismonth-".$pd->j_days_in_month[$jthismonth - 1]);
85
-
86
- //echo "Start Date: ".$start.", End Date: ".$end."<br>";
87
-
88
- $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
89
  FROM $wpdb->posts
90
  WHERE post_date < '$start'
91
  AND post_type = 'post' AND post_status = 'publish'
92
  ORDER BY post_date DESC
93
  LIMIT 1");
94
- $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
95
  FROM $wpdb->posts
96
  WHERE post_date >= '$end'
97
  AND post_type = 'post' AND post_status = 'publish'
98
  ORDER BY post_date ASC
99
  LIMIT 1");
100
 
101
- $calendar_output = '<table id="wp-calendar" style="direction: rtl" class="widget_calendar">
102
- <caption>' . $pd->persian_month_names[(int)$jthismonth ] . ' ' . $pd->persian_date('Y', $unixmonth) . '</caption>
103
  <thead>
104
  <tr>';
105
- $myweek = array();
106
- for ( $wdcount=0; $wdcount<=6; $wdcount++ )
107
- {$myweek[] = $pd->persian_day_small[($wdcount+$week_begins)%7];}
 
108
 
109
- foreach ( $myweek as $wd )
110
- {$calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$wd</th>";}
 
111
 
112
- $calendar_output .= '
113
  </tr>
114
  </thead>
115
 
116
  <tfoot>
117
  <tr>';
118
 
119
- if($previous){
120
- $previous_month = $jthismonth - 1;
121
- $previous_year = $jthisyear;
122
- if ($previous_month == 0){
123
- $previous_month = 12;
124
- $previous_year--;
125
- }
126
-
127
- $calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="'.get_month_link($previous_year, $previous_month).
128
- '">&laquo; ' . $pd->persian_month_names[$previous_month] . '</a></td>';
129
- }else {
130
- $calendar_output .= "\n\t\t" . '<td colspan="3" id="prev" class="pad">&nbsp;</td>';
131
- }
132
-
133
- $calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
134
-
135
- if($next){
136
- $next_month = $jthismonth + 1;
137
- $next_year = $jthisyear;
138
- if ($next_month == 13){
139
- $next_month = 1;
140
- $next_year ++;
141
- }
142
- $calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="'.get_month_link($next_year, $next_month).
143
- '">' . $pd->persian_month_names[$next_month]. ' &raquo;</a></td>';
144
- }else {
145
- $calendar_output .= "\n\t\t" . '<td colspan="3" id="next" class="pad">&nbsp;</td>';
146
- }
147
-
148
- $calendar_output .= '
149
  </tr>
150
  </tfoot>
151
 
152
  <tbody>
153
  <tr>';
154
 
155
- //____________________________________________________________________________________________________________________________________
156
 
157
- $sql = "SELECT DISTINCT DAYOFMONTH(post_date),MONTH(post_date),YEAR(post_date)
158
  FROM $wpdb->posts
159
  WHERE post_date > '$start' AND post_date < '$end'
160
  AND post_type = 'post'
161
  AND post_status = 'publish'";
162
- $dayswithposts = $wpdb->get_results($sql, ARRAY_N);
163
-
164
- if ( $dayswithposts ){
165
- foreach ($dayswithposts as $daywith )
166
- {$daywithpost[] = $pd->persian_date('j',"$daywith[2]-$daywith[1]-$daywith[0]",'eng');}
167
-
168
- } else {
169
- $daywithpost = array();
170
- }
171
-
172
- if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
173
- $ak_title_separator = "\n";
174
- else
175
- $ak_title_separator = ', ';
176
-
177
- $ak_titles_for_day = array();
178
- $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom, MONTH(post_date) as month, YEAR(post_date) as year
 
179
  FROM $wpdb->posts WHERE post_date >= '$start'
180
  AND post_date <= '$end'
181
  AND post_type = 'post' AND post_status = 'publish'");
182
 
183
- if ( $ak_post_titles )
184
- {
185
- foreach ($ak_post_titles as $ak_post_title )
186
- {/** This filter is documented in wp-includes/post-template.php */
187
- $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ));
188
- $ak_post_title->dom = $pd->persian_date('j',"$ak_post_title->year-$ak_post_title->month-$ak_post_title->dom",'eng');
189
-
190
- if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
191
- $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
192
- if ( empty($ak_titles_for_day[$ak_post_title->dom]) ) // first one
193
- $ak_titles_for_day[$ak_post_title->dom] = $post_title;
194
- else
195
- $ak_titles_for_day[$ak_post_title->dom] .= $ak_title_separator . $post_title;
196
- }
197
- }
198
-
199
- //$pad = calendar_week_mod(date('w',strtotime($unixmonth))-$week_begins);
200
-
201
- $pad = wppd_get_pad($jthisyear."-".$jthismonth);
202
- //echo "<br />begin=$week_begins<br />pad=$pad<br />";
203
-
204
- if (0 != $pad)
205
- $calendar_output .= "\n\t\t".'<td colspan="'.$pad.'" class="pad">&nbsp;</td>';
206
-
207
- $daysinmonth = intval($pd->persian_date('t', $unixmonth,'eng'));
208
-
209
- for ($day = 1; $day <= $daysinmonth; ++$day)
210
- {
211
- list($thiyear,$thismonth,$thisday) = $pd->persian_to_gregorian($jthisyear,$jthismonth,$day);
212
- if (isset($newrow) && $newrow)
213
- $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
214
- $newrow = false;
215
-
216
- if ($thisday == gmdate('j', (time() + (get_option('gmt_offset') * 3600))) && $thismonth == gmdate('m', time()+(get_option('gmt_offset') * 3600)) && $thisyear == gmdate('Y', time()+(get_option('gmt_offset') * 3600)))
217
- $calendar_output .= '<td id="today">';
218
- else
219
- $calendar_output .= '<td>';
220
-
221
- $p_day =(empty($val['sep_datesnum'])?$day:per_number($day));
222
-
223
- if (in_array($day, $daywithpost)) // any posts today?
224
- $calendar_output .= '<a href="' . get_day_link($jthisyear, $jthismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$p_day</a>";
225
- else
226
- $calendar_output .= $p_day;
227
- $calendar_output .= '</td>';
228
-
229
- if (6 == calendar_week_mod($pd->gregurian_date('w',"$jthisyear-$jthismonth-$day")-$week_begins))
230
- $newrow = true;
231
- }
232
- $pad = 7 - calendar_week_mod($pd->gregurian_date('w',"$jthisyear-$jthismonth-$day",'eng')-$week_begins);
233
  if ($pad != 0 && $pad != 7)
234
- $calendar_output .= "\n\t\t".'<td class="pad" colspan="'.$pad.'">&nbsp;</td>';
235
-
236
- echo $calendar_output ."\n\t</tr>\n\t</tbody>\n\t</table>";
237
  }
238
 
239
  /**
@@ -242,10 +241,12 @@
242
  * @param string $date
243
  * @return int
244
  */
245
- function wppd_get_pad($date){
246
- $pd = bn_parsidate::getInstance();
247
- $p = $pd->persian_date("w",$pd->gregurian_date("Y-m-d",$date."-01"),"eng");
 
248
 
249
- return $p;
250
  }
 
251
  ?>
1
  <?php
2
 
3
+ /**
4
+ * Create Persian Calendar
5
+ *
6
+ * @param string $args
7
+ * @author Mobin Ghasempoor
8
+ * @author Parsa Kafi
9
+ * @return string
10
+ */
11
+ function wpp_get_calendar($args = '')
12
+ {
13
+ global $wp_query, $wpdb, $m, $monthnum, $year, $day, $posts;
14
+
15
+ $pd = bn_parsidate::getInstance();
16
+ $jm = $monthnum;
17
+ if ($m != '') {
18
+ $m = preg_replace("/[^0-9]/", "", $m);
19
+ $jy = substr($m, 0, 4);
20
+ } elseif ($year !== '') {
21
+ $jy = $year;
22
+ }
23
+
24
+ if ($jy > 1500)
25
+ list($jy, $jm, $jd) = $pd->gregorian_to_persian($year, $monthnum, $day);
26
+
27
+ if (!$posts) {
28
+ $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
29
+ if (!$gotsome)
30
+ return;
31
+ }
32
+
33
+ $week_begins = intval(get_option('start_of_week'));
34
+ $w = isset($_GET['w']) ? intval($_GET['w']) : '';
35
+ $is_gregorian = false;
36
+
37
+ if (!empty($jm) && !empty($jy)) {
38
+ $thismonth = '' . zeroise(intval($jm), 2);
39
+ $thisyear = '' . intval($jy);
40
+
41
+ } elseif (!empty($w)) {
42
+ $thisyear = '' . intval(substr($m, 0, 4));
43
+ $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
44
+ $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
45
+
46
+ } elseif (!empty($m)) {
47
+ $thisyear = '' . intval(substr($m, 0, 4));
48
+ if (strlen($m) < 6)
49
+ $thismonth = '01';
50
+ else
51
+ $thismonth = '' . zeroise(intval(substr($m, 4, 2)), 2);
52
+
53
+ } else {
54
+ $is_gregorian = true;
55
+ $thisyear = gmdate('Y', current_time('timestamp') + get_option('gmt_offset') * 3600);
56
+ $thismonth = gmdate('m', current_time('timestamp') + get_option('gmt_offset') * 3600);
57
+ $thisday = gmdate('d', current_time('timestamp') + get_option('gmt_offset') * 3600);
58
+ }
59
+
60
+ //print_r($wp_query->query_vars);
61
+
62
+ if ($is_gregorian) {
63
+ list($jthisyear, $jthismonth, $jthisday) = $pd->gregorian_to_persian($thisyear, $thismonth, $thisday);
64
+ $unixmonth = $pd->gregurian_date('Y-m-d 00:00:00', "$jthisyear-$jthismonth-01");
65
+ } else {
66
+ $gdate = $pd->persian_to_gregorian($thisyear, $thismonth, 1);
67
+ $unixmonth = mktime(0, 0, 0, $gdate[1], 1, $gdate[0]);
68
+ $jthisyear = $thisyear;
69
+ $jthismonth = $thismonth;
70
+ }
71
+
72
+ $jnextmonth = $jthismonth + 1;
73
+ $jnextyear = $jthisyear;
74
+
75
+
76
+ if ($jnextmonth > 12) {
77
+ $jnextmonth = 1;
78
+ $jnextyear++;
79
+ }
80
+
81
+ $start = $pd->gregurian_date('Y-m-d 00:00:00', "$jthisyear-$jthismonth-01");
82
+ $end = $pd->gregurian_date('Y-m-d 23:59:59', "$jnextyear-$jthismonth-" . $pd->j_days_in_month[$jthismonth - 1]);
83
+
84
+ //echo "Start Date: ".$start.", End Date: ".$end."<br>";
85
+
86
+ $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
 
 
87
  FROM $wpdb->posts
88
  WHERE post_date < '$start'
89
  AND post_type = 'post' AND post_status = 'publish'
90
  ORDER BY post_date DESC
91
  LIMIT 1");
92
+ $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
93
  FROM $wpdb->posts
94
  WHERE post_date >= '$end'
95
  AND post_type = 'post' AND post_status = 'publish'
96
  ORDER BY post_date ASC
97
  LIMIT 1");
98
 
99
+ $calendar_output = '<table id="wp-calendar" style="direction: rtl" class="widget_calendar">
100
+ <caption>' . $pd->persian_month_names[(int)$jthismonth] . ' ' . $pd->persian_date('Y', $unixmonth) . '</caption>
101
  <thead>
102
  <tr>';
103
+ $myweek = array();
104
+ for ($wdcount = 0; $wdcount <= 6; $wdcount++) {
105
+ $myweek[] = $pd->persian_day_small[($wdcount + $week_begins) % 7];
106
+ }
107
 
108
+ foreach ($myweek as $wd) {
109
+ $calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$wd</th>";
110
+ }
111
 
112
+ $calendar_output .= '
113
  </tr>
114
  </thead>
115
 
116
  <tfoot>
117
  <tr>';
118
 
119
+ if ($previous) {
120
+ $previous_month = $jthismonth - 1;
121
+ $previous_year = $jthisyear;
122
+ if ($previous_month == 0) {
123
+ $previous_month = 12;
124
+ $previous_year--;
125
+ }
126
+
127
+ $calendar_output .= "\n\t\t" . '<td colspan="3" id="prev"><a href="' . get_month_link($previous_year, $previous_month) .
128
+ '">&laquo; ' . $pd->persian_month_names[$previous_month] . '</a></td>';
129
+ } else {
130
+ $calendar_output .= "\n\t\t" . '<td colspan="3" id="prev" class="pad">&nbsp;</td>';
131
+ }
132
+
133
+ $calendar_output .= "\n\t\t" . '<td class="pad">&nbsp;</td>';
134
+
135
+ if ($next) {
136
+ $next_month = $jthismonth + 1;
137
+ $next_year = $jthisyear;
138
+ if ($next_month == 13) {
139
+ $next_month = 1;
140
+ $next_year++;
141
+ }
142
+ $calendar_output .= "\n\t\t" . '<td colspan="3" id="next"><a href="' . get_month_link($next_year, $next_month) .
143
+ '">' . $pd->persian_month_names[$next_month] . ' &raquo;</a></td>';
144
+ } else {
145
+ $calendar_output .= "\n\t\t" . '<td colspan="3" id="next" class="pad">&nbsp;</td>';
146
+ }
147
+
148
+ $calendar_output .= '
149
  </tr>
150
  </tfoot>
151
 
152
  <tbody>
153
  <tr>';
154
 
155
+ //____________________________________________________________________________________________________________________________________
156
 
157
+ $sql = "SELECT DISTINCT DAYOFMONTH(post_date),MONTH(post_date),YEAR(post_date)
158
  FROM $wpdb->posts
159
  WHERE post_date > '$start' AND post_date < '$end'
160
  AND post_type = 'post'
161
  AND post_status = 'publish'";
162
+ $dayswithposts = $wpdb->get_results($sql, ARRAY_N);
163
+
164
+ if ($dayswithposts) {
165
+ foreach ($dayswithposts as $daywith) {
166
+ $daywithpost[] = $pd->persian_date('j', "$daywith[2]-$daywith[1]-$daywith[0]", 'eng');
167
+ }
168
+
169
+ } else {
170
+ $daywithpost = array();
171
+ }
172
+
173
+ if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
174
+ $ak_title_separator = "\n";
175
+ else
176
+ $ak_title_separator = ', ';
177
+
178
+ $ak_titles_for_day = array();
179
+ $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom, MONTH(post_date) as month, YEAR(post_date) as year
180
  FROM $wpdb->posts WHERE post_date >= '$start'
181
  AND post_date <= '$end'
182
  AND post_type = 'post' AND post_status = 'publish'");
183
 
184
+ if ($ak_post_titles) {
185
+ foreach ($ak_post_titles as $ak_post_title) {
186
+ /** This filter is documented in wp-includes/post-template.php */
187
+ $post_title = esc_attr(apply_filters('the_title', $ak_post_title->post_title, $ak_post_title->ID));
188
+ $ak_post_title->dom = $pd->persian_date('j', "$ak_post_title->year-$ak_post_title->month-$ak_post_title->dom", 'eng');
189
+
190
+ if (empty($ak_titles_for_day['day_' . $ak_post_title->dom]))
191
+ $ak_titles_for_day['day_' . $ak_post_title->dom] = '';
192
+ if (empty($ak_titles_for_day[$ak_post_title->dom])) // first one
193
+ $ak_titles_for_day[$ak_post_title->dom] = $post_title;
194
+ else
195
+ $ak_titles_for_day[$ak_post_title->dom] .= $ak_title_separator . $post_title;
196
+ }
197
+ }
198
+
199
+ //$pad = calendar_week_mod(date('w',strtotime($unixmonth))-$week_begins);
200
+
201
+ $pad = wppd_get_pad($jthisyear . "-" . $jthismonth);
202
+ //echo "<br />begin=$week_begins<br />pad=$pad<br />";
203
+
204
+ if (0 != $pad)
205
+ $calendar_output .= "\n\t\t" . '<td colspan="' . $pad . '" class="pad">&nbsp;</td>';
206
+
207
+ $daysinmonth = intval($pd->persian_date('t', $unixmonth, 'eng'));
208
+
209
+ for ($day = 1; $day <= $daysinmonth; ++$day) {
210
+ list($thiyear, $thismonth, $thisday) = $pd->persian_to_gregorian($jthisyear, $jthismonth, $day);
211
+ if (isset($newrow) && $newrow)
212
+ $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
213
+ $newrow = false;
214
+
215
+ if ($thisday == gmdate('j', (time() + (get_option('gmt_offset') * 3600))) && $thismonth == gmdate('m', time() + (get_option('gmt_offset') * 3600)) && $thisyear == gmdate('Y', time() + (get_option('gmt_offset') * 3600)))
216
+ $calendar_output .= '<td id="today">';
217
+ else
218
+ $calendar_output .= '<td>';
219
+
220
+ $p_day = (empty($val['sep_datesnum']) ? $day : per_number($day));
221
+
222
+ if (in_array($day, $daywithpost)) // any posts today?
223
+ $calendar_output .= '<a href="' . get_day_link($jthisyear, $jthismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$p_day</a>";
224
+ else
225
+ $calendar_output .= $p_day;
226
+ $calendar_output .= '</td>';
227
+
228
+ if (6 == calendar_week_mod($pd->gregurian_date('w', "$jthisyear-$jthismonth-$day") - $week_begins))
229
+ $newrow = true;
230
+ }
231
+ $pad = 7 - calendar_week_mod($pd->gregurian_date('w', "$jthisyear-$jthismonth-$day", 'eng') - $week_begins);
 
 
232
  if ($pad != 0 && $pad != 7)
233
+ $calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . $pad . '">&nbsp;</td>';
234
+
235
+ echo $calendar_output . "\n\t</tr>\n\t</tbody>\n\t</table>";
236
  }
237
 
238
  /**
241
  * @param string $date
242
  * @return int
243
  */
244
+ function wppd_get_pad($date)
245
+ {
246
+ $pd = bn_parsidate::getInstance();
247
+ $p = $pd->persian_date("w", $pd->gregurian_date("Y-m-d", $date . "-01"), "eng");
248
 
249
+ return $p;
250
  }
251
+
252
  ?>
includes/fixes-dates.php CHANGED
@@ -9,14 +9,14 @@
9
 
10
  global $wpp_settings;
11
 
12
- if ( $wpp_settings['persian_date'] != 'disable' ) {
13
- add_filter( 'the_time', 'wpp_fix_post_time', 10, 2 );
14
- add_filter( 'the_date', 'wpp_fix_post_date', 10, 2 );
15
- add_filter( 'get_comment_time', 'wpp_fix_comment_time', 10, 2 );
16
- add_filter( 'get_comment_date', 'wpp_fix_comment_date', 10, 2 );
17
- add_filter( 'get_post_modified_time', 'wpp_fix_post_date', 10, 2 );
18
-
19
- add_action( 'date_i18n', 'wpp_fix_i18n', 10, 3 );
20
  }
21
 
22
  /**
@@ -26,20 +26,21 @@ if ( $wpp_settings['persian_date'] != 'disable' ) {
26
  * @param string $format Date format
27
  * @return string Formatted date
28
  */
29
- function wpp_fix_post_date( $time, $format = '' ) {
30
- global $post, $wpp_settings;
31
-
32
- // It's seems some plugin like acf does not exits $post.
33
- if( empty($post) )
34
- return $time;
35
-
36
- if ( empty( $format ) )
37
- $format = get_option( 'date_format' );
38
-
39
- if ( $wpp_settings['conv_dates'] == 'disable' )
40
- return parsidate( $format, $post->post_date, 'eng' );
41
- else
42
- return parsidate( $format, $post->post_date );
 
43
  }
44
 
45
  /**
@@ -49,15 +50,16 @@ function wpp_fix_post_date( $time, $format = '' ) {
49
  * @param string $format Date format
50
  * @return string Formatted date
51
  */
52
- function wpp_fix_post_time( $time, $format = '' ) {
53
- global $post, $wpp_settings;
54
- if ( empty( $format ) )
55
- $format = get_option( 'time_format' );
56
-
57
- if ( $wpp_settings['conv_dates'] == 'disable' )
58
- return parsidate( $format, $post->post_date, 'eng' );
59
- else
60
- return parsidate( $format, $post->post_date );
 
61
  }
62
 
63
  /**
@@ -67,15 +69,16 @@ function wpp_fix_post_time( $time, $format = '' ) {
67
  * @param string $fomat Date format
68
  * @return string Formatted date
69
  */
70
- function wpp_fix_comment_time( $time, $format = '' ) {
71
- global $comment, $wpp_settings;
72
- if ( empty( $format ) )
73
- $format = get_option( 'time_format' );
74
-
75
- if ( $wpp_settings['conv_dates'] == 'disable' )
76
- return parsidate( $format, $comment->comment_date, 'eng' );
77
- else
78
- return parsidate( $format, $comment->comment_date );
 
79
  }
80
 
81
  /**
@@ -85,15 +88,16 @@ function wpp_fix_comment_time( $time, $format = '' ) {
85
  * @param string $fomat Date format
86
  * @return string Formatted date
87
  */
88
- function wpp_fix_comment_date( $time, $format = '' ) {
89
- global $comment, $wpp_settings;
90
- if ( empty( $format ) )
91
- $format = get_option( 'date_format' );
92
-
93
- if ( $wpp_settings['conv_dates'] == 'disable' )
94
- return parsidate( $format, $comment->comment_date, 'eng' );
95
- else
96
- return parsidate( $format, $comment->comment_date );
 
97
  }
98
 
99
  /**
@@ -104,22 +108,23 @@ function wpp_fix_comment_date( $time, $format = '' ) {
104
  * @param string $gmt GMT timestamp
105
  * @return string Formatted time
106
  */
107
- function wpp_fix_i18n( $format_string, $timestamp, $gmt ) {
108
- global $wpp_settings;
 
109
 
110
- if(function_exists('debug_backtrace')) {
111
- $callers = debug_backtrace();
112
 
113
- // WordPress SEO OpenGraph Dates fix
114
- if (isset($callers[6]['class']) && $callers[6]['class'] == 'WPSEO_OpenGraph') return $format_string;
115
- if (isset($callers[6]['function']) && $callers[6]['function'] == 'get_the_modified_date') return $format_string;
116
 
117
- // WooCommerce order detail fix
118
- if(isset($callers['4']['class']) && $callers['4']['class']=='WC_Meta_Box_Order_Data') return $format_string;
119
- }
120
 
121
- if ( $wpp_settings['conv_dates'] == 'disable' )
122
- return parsidate( $timestamp, $gmt, 'eng' );
123
- else
124
- return parsidate( $timestamp, $gmt );
125
  }
9
 
10
  global $wpp_settings;
11
 
12
+ if ($wpp_settings['persian_date'] != 'disable') {
13
+ add_filter('the_time', 'wpp_fix_post_time', 10, 2);
14
+ add_filter('the_date', 'wpp_fix_post_date', 10, 2);
15
+ add_filter('get_comment_time', 'wpp_fix_comment_time', 10, 2);
16
+ add_filter('get_comment_date', 'wpp_fix_comment_date', 10, 2);
17
+ add_filter('get_post_modified_time', 'wpp_fix_post_date', 10, 2);
18
+
19
+ add_action('date_i18n', 'wpp_fix_i18n', 10, 3);
20
  }
21
 
22
  /**
26
  * @param string $format Date format
27
  * @return string Formatted date
28
  */
29
+ function wpp_fix_post_date($time, $format = '')
30
+ {
31
+ global $post, $wpp_settings;
32
+
33
+ // It's seems some plugin like acf does not exits $post.
34
+ if (empty($post))
35
+ return $time;
36
+
37
+ if (empty($format))
38
+ $format = get_option('date_format');
39
+
40
+ if ($wpp_settings['conv_dates'] == 'disable')
41
+ return parsidate($format, $post->post_date, 'eng');
42
+ else
43
+ return parsidate($format, $post->post_date);
44
  }
45
 
46
  /**
50
  * @param string $format Date format
51
  * @return string Formatted date
52
  */
53
+ function wpp_fix_post_time($time, $format = '')
54
+ {
55
+ global $post, $wpp_settings;
56
+ if (empty($format))
57
+ $format = get_option('time_format');
58
+
59
+ if ($wpp_settings['conv_dates'] == 'disable')
60
+ return parsidate($format, $post->post_date, 'eng');
61
+ else
62
+ return parsidate($format, $post->post_date);
63
  }
64
 
65
  /**
69
  * @param string $fomat Date format
70
  * @return string Formatted date
71
  */
72
+ function wpp_fix_comment_time($time, $format = '')
73
+ {
74
+ global $comment, $wpp_settings;
75
+ if (empty($format))
76
+ $format = get_option('time_format');
77
+
78
+ if ($wpp_settings['conv_dates'] == 'disable')
79
+ return parsidate($format, $comment->comment_date, 'eng');
80
+ else
81
+ return parsidate($format, $comment->comment_date);
82
  }
83
 
84
  /**
88
  * @param string $fomat Date format
89
  * @return string Formatted date
90
  */
91
+ function wpp_fix_comment_date($time, $format = '')
92
+ {
93
+ global $comment, $wpp_settings;
94
+ if (empty($format))
95
+ $format = get_option('date_format');
96
+
97
+ if ($wpp_settings['conv_dates'] == 'disable')
98
+ return parsidate($format, $comment->comment_date, 'eng');
99
+ else
100
+ return parsidate($format, $comment->comment_date);
101
  }
102
 
103
  /**
108
  * @param string $gmt GMT timestamp
109
  * @return string Formatted time
110
  */
111
+ function wpp_fix_i18n($format_string, $timestamp, $gmt)
112
+ {
113
+ global $wpp_settings;
114
 
115
+ if (function_exists('debug_backtrace')) {
116
+ $callers = debug_backtrace();
117
 
118
+ // WordPress SEO OpenGraph Dates fix
119
+ if (isset($callers[6]['class']) && $callers[6]['class'] == 'WPSEO_OpenGraph') return $format_string;
120
+ if (isset($callers[6]['function']) && $callers[6]['function'] == 'get_the_modified_date') return $format_string;
121
 
122
+ // WooCommerce order detail fix
123
+ if (isset($callers['4']['class']) && $callers['4']['class'] == 'WC_Meta_Box_Order_Data') return $format_string;
124
+ }
125
 
126
+ if ($wpp_settings['conv_dates'] == 'disable')
127
+ return parsidate($timestamp, $gmt, 'eng');
128
+ else
129
+ return parsidate($timestamp, $gmt);
130
  }
includes/fixes-misc.php CHANGED
@@ -10,31 +10,31 @@
10
 
11
  global $wpp_settings;
12
 
13
- if ( isset( $wpp_settings['conv_page_title'] ) && $wpp_settings['conv_page_title'] != 'disable' )
14
- add_filter( 'wp_title', 'fixnumber' , 20 );
15
 
16
- if ( isset( $wpp_settings['conv_title'] ) && $wpp_settings['conv_title'] != 'disable' )
17
- add_filter( 'the_title', 'fixnumber' , 20 );
18
 
19
- if ( isset( $wpp_settings['conv_contents'] ) && $wpp_settings['conv_contents'] != 'disable' )
20
- add_filter( 'the_content', 'fixnumber' );
21
 
22
- if ( isset( $wpp_settings['conv_excerpt'] ) && $wpp_settings['conv_excerpt'] != 'disable' )
23
- add_filter( 'the_excerpt', 'fixnumber' );
24
 
25
- if ( isset( $wpp_settings['conv_comments'] ) && $wpp_settings['conv_comments'] != 'disable' )
26
- add_filter( 'comment_text', 'fixnumber' );
27
 
28
- if ( isset( $wpp_settings['conv_comment_count'] ) && $wpp_settings['conv_comment_count'] != 'disable' )
29
- add_filter( 'comments_number', 'fixnumber' );
30
 
31
- if ( isset( $wpp_settings['conv_cats'] ) && $wpp_settings['conv_cats'] != 'disable' )
32
- add_filter( 'wp_list_categories', 'fixnumber' );
33
 
34
- if ( isset( $wpp_settings['conv_arabic'] ) && $wpp_settings['conv_arabic'] != 'disable' ) {
35
- add_filter( 'the_content', 'fixarabic' );
36
- add_filter( 'the_title', 'fixarabic' );
37
- add_filter( 'comment_text', 'fixarabic' );
38
- add_filter( 'wp_list_categories', 'fixarabic' );
39
- add_filter( 'the_excerpt', 'fixarabic' );
40
  }
10
 
11
  global $wpp_settings;
12
 
13
+ if (isset($wpp_settings['conv_page_title']) && $wpp_settings['conv_page_title'] != 'disable')
14
+ add_filter('wp_title', 'fixnumber', 20);
15
 
16
+ if (isset($wpp_settings['conv_title']) && $wpp_settings['conv_title'] != 'disable')
17
+ add_filter('the_title', 'fixnumber', 20);
18
 
19
+ if (isset($wpp_settings['conv_contents']) && $wpp_settings['conv_contents'] != 'disable')
20
+ add_filter('the_content', 'fixnumber');
21
 
22
+ if (isset($wpp_settings['conv_excerpt']) && $wpp_settings['conv_excerpt'] != 'disable')
23
+ add_filter('the_excerpt', 'fixnumber');
24
 
25
+ if (isset($wpp_settings['conv_comments']) && $wpp_settings['conv_comments'] != 'disable')
26
+ add_filter('comment_text', 'fixnumber');
27
 
28
+ if (isset($wpp_settings['conv_comment_count']) && $wpp_settings['conv_comment_count'] != 'disable')
29
+ add_filter('comments_number', 'fixnumber');
30
 
31
+ if (isset($wpp_settings['conv_cats']) && $wpp_settings['conv_cats'] != 'disable')
32
+ add_filter('wp_list_categories', 'fixnumber');
33
 
34
+ if (isset($wpp_settings['conv_arabic']) && $wpp_settings['conv_arabic'] != 'disable') {
35
+ add_filter('the_content', 'fixarabic');
36
+ add_filter('the_title', 'fixarabic');
37
+ add_filter('comment_text', 'fixarabic');
38
+ add_filter('wp_list_categories', 'fixarabic');
39
+ add_filter('the_excerpt', 'fixarabic');
40
  }
includes/fixes-permalinks.php CHANGED
@@ -8,10 +8,10 @@
8
  */
9
  global $wpp_settings;
10
 
11
- if ( $wpp_settings['conv_permalinks'] == 'enable' ) {
12
- add_filter( 'posts_where', 'wpp_posts_where' );
13
- add_action( 'pre_get_posts', 'wpp_pre_get_posts' );
14
- add_filter( 'post_link', 'wpp_permalink', 10, 3 );
15
  }
16
 
17
  /**
@@ -20,104 +20,105 @@ if ( $wpp_settings['conv_permalinks'] == 'enable' ) {
20
  * @param string $where
21
  * @return string
22
  */
23
- function wpp_posts_where( $where ) {
24
- global $wp_query, $wpdb ;
25
- if ( empty( $wp_query->query_vars ) )
26
- return $where;
27
-
28
- $pd = bn_parsidate::getInstance();
29
-
30
- $m = ( isset( $wp_query->query_vars['m'] ) ) ? $wp_query->query_vars['m'] : '';
31
- $hour = ( isset( $wp_query->query_vars['hour'] ) ) ? $wp_query->query_vars['hour'] : '';
32
- $minute = ( isset( $wp_query->query_vars['minute'] ) ) ? $wp_query->query_vars['minute'] : '';
33
- $second = ( isset( $wp_query->query_vars['second'] ) ) ? $wp_query->query_vars['second'] : '';
34
- $year = ( isset( $wp_query->query_vars['year'] ) ) ? $wp_query->query_vars['year'] : '';
35
- $month = ( isset( $wp_query->query_vars['month'] ) ) ? $wp_query->query_vars['month'] : '';
36
- $day = ( isset( $wp_query->query_vars['day'] ) ) ? $wp_query->query_vars['day'] : '';
37
-
38
- if ( ! empty( $m ) ) {
39
- $len = strlen( $m );
40
- $year = substr( $m, 0, 4 );
41
- if ( $len > 5 )
42
- $month = substr( $m, 4, 2 );
43
- if ( $len > 7 )
44
- $day = substr( $m, 6, 2 );
45
- if ( $len > 9 )
46
- $hour = substr( $m, 8, 2 );
47
- if ( $len > 11 )
48
- $minute = substr( $m, 10, 2 );
49
- if ( $len > 13 )
50
- $second = substr( $m, 12, 2 );
51
- }
52
-
53
- if ( empty( $year ) || $year > 1700 )
54
- return $where;
55
-
56
- $stamon = 1;
57
- $staday = 1;
58
- $stahou = '00';
59
- $stamin = '00';
60
- $stasec = '00';
61
- $endmon = 1;
62
- $endday = 1;
63
- $endhou = '00';
64
- $endmin = '00';
65
- $endsec = '00';
66
-
67
- $stayear = $year;
68
- $endyear = $year+1;
69
-
70
- if ( $month != '' ) {
71
- $stamon = $month;
72
- $endmon = ( $month == 12 ? 1 : $month + 1 );
73
- $endyear= ( $endmon == 1 ? $stayear + 1 : $stayear );
74
- }
75
-
76
- if ( $day != '' ) {
77
- $staday = $day;
78
- $endday = ( $day == $pd->j_days_in_month[(int)$month-1] ? 1 : $day + 1 );
79
- $endmon = ( $endday == 1 ? $stamon + 1 : $stamon );
80
- }
81
-
82
- if ( $hour != '' ) {
83
- $stahou = $hour;
84
- $endhou = ( $hour == 24 ? '00' : $hour+1 );
85
- $endday = ( $endhou == '00' ? $staday + 1 : $staday );
86
- }
87
-
88
- if ( $minute != '' ) {
89
- $stamin = $minute;
90
- $endmin = ( $minute == 59 ? '00' : $minute+1 );
91
- $endhou = ( $endmin == '00' ? $stahou + 1 : $stahou );
92
- }
93
-
94
- if ( $second != '' ) {
95
- $stasec = $second;
96
- $endsec = ( $second == 59 ? '00' : $second + 1 );
97
- $endmin = ( $endsec == '00' ? $stamin + 1: $stamin );
98
- }
99
-
100
- $stadate = "$stayear-$stamon-$staday";
101
- $enddate = "$endyear-$endmon-$endday";
102
- $stadate = gregdate( 'Y-m-d', $stadate );
103
- $enddate = gregdate( 'Y-m-d', $enddate );
104
- $stadate .= " $stahou:$stamin:$stasec";
105
- $enddate .= " $endhou:$endmin:$endsec";
106
-
107
- $patterns = array('/YEAR\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
108
- '/DAYOFMONTH\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
109
- '/MONTH\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
110
- '/HOUR\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
111
- '/MINUTE\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
112
- '/SECOND\((.*?)post_date\s*\)\s*=\s*[0-9\']*/');
113
- foreach( $patterns as $pattern )
114
- $where = preg_replace( $pattern, '1=1', $where );
115
-
116
- $prefixp = "{$wpdb->posts}.";
117
- $prefixp = ( strpos( $where, $prefixp ) == false ) ? '' : $prefixp;
118
-
119
- $where .= " AND {$prefixp}post_date >= '$stadate' AND {$prefixp}post_date < '$enddate' ";
120
- return $where;
 
121
  }
122
 
123
  /**
@@ -126,106 +127,107 @@ function wpp_posts_where( $where ) {
126
  * @param WP_Query $query
127
  * @return mixed
128
  */
129
- function wpp_pre_get_posts( $query ) {
130
- global $wpdb;
131
-
132
- $permalink = $query->query;
133
- $year = '';
134
- $monthnum = '';
135
- $day = '';//start
136
-
137
- if ( isset( $permalink['year'] ) )
138
- $year = $permalink['year'];
139
- if ( isset( $permalink['monthnum'] ) )
140
- $monthnum = $permalink['monthnum'];
141
- if ( isset( $permalink['day'] ) )
142
- $day = $permalink['day'];
143
- if($year > 1700)
144
- return $query;
145
-
146
- $out = false;
147
- $pd = bn_parsidate::getInstance();
148
- if ( isset( $permalink['name'] ) ) {
149
- $var = $wpdb->get_var( "SELECT post_date FROM {$wpdb->prefix}posts WHERE post_name='{$permalink['name']}' ORDER BY id" );
150
- $per = parsidate( 'Y-m-d', $var, 'eng' );
151
- //update_option('options', $per );
152
- $per = explode( '-', $per );
153
- $out = true;
154
-
155
- if ( $year != $per[0] )
156
- $out = false;
157
- if ( $out && $monthnum != $per[1])
158
- $out = false;
159
- if ( $out && $day != $per[2])
160
- $out = false;
161
-
162
- } elseif(isset($permalink['post_id'])) {
163
- $out = true;
164
- $var = $wpdb->get_var( "SELECT post_date FROM {$wpdb->prefix}posts WHERE ID={$permalink['post_id']}" );
165
- } elseif( ! empty( $year ) && ! empty( $monthnum ) && ! empty( $day ) ) {
166
- $out = true;
167
- $var = gregdate( 'Y-m-d', "$year-$monthnum-$day" );
168
- }elseif(! empty( $year ) && ! empty( $monthnum )){
169
- $stadate = $pd->persian_to_gregorian($year,$monthnum,1);
170
- $enddate = $pd->persian_to_gregorian($year,$monthnum,$pd->j_days_in_month[($monthnum-1)]);
171
- $date_query = array(
172
- array(
173
- 'after' => array(
174
- 'year' => $stadate[0],
175
- 'month' => $stadate[1],
176
- 'day' => $stadate[2] - 1,
177
- ),
178
- 'before' => array(
179
- 'year' => $enddate[0],
180
- 'month' => $enddate[1],
181
- 'day' => $enddate[2] + 1,
182
- ),
183
- 'inclusive' => TRUE,
184
- ),
185
- );
186
- $query->set('date_query', $date_query);
187
-
188
- // commented for get year & month in calander widget
189
- // $query->set('year', '');
190
- // $query->set('monthnum', '');
191
- $out = false;
192
-
193
- }elseif(! empty( $year )){
194
- $stadate = $pd->persian_to_gregorian($year,1,1);
195
- $enddate = $pd->persian_to_gregorian(($year+1),1,1);
196
- $date_query = array(
197
- array(
198
- 'after' => array(
199
- 'year' => $stadate[0],
200
- 'month' => $stadate[1],
201
- 'day' => $stadate[2] - 1,
202
- ),
203
- 'before' => array(
204
- 'year' => $enddate[0],
205
- 'month' => $enddate[1],
206
- 'day' => $enddate[2],
207
- ),
208
- 'inclusive' => TRUE,
209
- ),
210
- );
211
- $query->set('date_query', $date_query);
212
- // $query->set('year', '');
213
- $out = false;
214
- }
215
-
216
- if ( $out ) {
217
- preg_match_all( '!\d+!', $var, $matches );
218
- $var = $matches[0];
219
-
220
- $query->set( 'year', $var[0] );
221
- $query->set( 'monthnum', $var[1] );
222
- $query->set( 'day', $var[2] );
223
- }
 
224
 
225
  // $query->set('')
226
 
227
- return $query;
228
-
229
  }
230
 
231
  /**
@@ -236,86 +238,88 @@ function wpp_pre_get_posts( $query ) {
236
  * @param bool $leavename
237
  * @return string New permalink
238
  */
239
- function wpp_permalink( $perma, $post, $leavename = false ) {
240
- if ( empty( $post->ID ) )
241
- return false;
242
- if ( $post->post_type == 'page' || $post->post_status == 'static' )
243
- return get_page_link( $post->ID );
244
- elseif( $post->post_type == 'attachment' )
245
- return get_attachment_link( $post->ID );
246
- elseif( in_array( $post->post_type, get_post_types( array( '_builtin' => false ) ) ) )
247
- return get_post_permalink( $post->ID );
248
-
249
- $permalink = get_option( 'permalink_structure' );
250
- preg_match_all( '/%([^\/]*)%/', $permalink, $rewritecode );
251
- $rewritecode = $rewritecode[0];
252
- if ( '' != $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) {
253
- if ( $leavename )
254
- $rewritecode = array_diff( $rewritecode, array( '%postname%', '%pagename%' ) );
255
-
256
- $date = explode( ' ', parsidate( 'Y m d H i s', $post->post_date, 'eng' ) );
257
- $out = array();
258
-
259
- foreach( $rewritecode as $rewrite ) {
260
- switch( $rewrite ) {
261
- case '%year%':
262
- $out[] = $date[0];
263
- break;
264
- case '%monthnum%':
265
- $out[] = $date[1];
266
- break;
267
- case '%day%':
268
- $out[] = $date[2];
269
- break;
270
- case '%hour%':
271
- $out[] = $date[3];
272
- break;
273
- case '%minute%':
274
- $out[] = $date[4];
275
- break;
276
- case '%second%':
277
- $out[] = $date[5];
278
- break;
279
- case '%post_id%':
280
- $out[] = $post->ID;
281
- break;
282
- case '%postname%':
283
- $out[] = $post->post_name;
284
- break;
285
- case '%category%':
286
- $category = '';
287
- $cats = get_the_category( $post->ID );
288
- if ( $cats ) {
289
- usort( $cats, '_usort_terms_by_ID' );
290
- $category = $cats[0]->slug;
291
- if ( $parent = $cats[0]->parent )
292
- $category = get_category_parents( $parent, false, '/', true );
293
-
294
- if($cats[0]->parent != 0)
295
- $category .= $cats[0]->slug ;
296
- }
297
- if ( empty( $category ) ) {
298
- $default_category = get_term( get_option( 'default_category' ), 'category' );
299
- $category = is_wp_error( $default_category ) ? '' : $default_category->slug;
300
- }
301
- $out[] = $category;
302
- break;
303
- case '%author%':
304
- $authordata = get_userdata( $post->post_author );
305
- $out[] = $authordata->user_nicename;
306
- break;
307
- case '%pagename%':
308
- $out[] = $post->post_name;
309
- break;
310
- default:
311
- unset( $rewritecode[array_search( $rewrite, $rewritecode )] );
312
- break;
313
- }
314
- }
315
- $permalink = home_url( str_replace( $rewritecode, $out, $permalink ) );
316
- return user_trailingslashit( $permalink, 'single' );
317
- } else {
318
- return home_url( "?p=$post->ID" );
319
- }
 
320
  }
 
321
  ?>
8
  */
9
  global $wpp_settings;
10
 
11
+ if ($wpp_settings['conv_permalinks'] == 'enable') {
12
+ add_filter('posts_where', 'wpp_posts_where');
13
+ add_action('pre_get_posts', 'wpp_pre_get_posts');
14
+ add_filter('post_link', 'wpp_permalink', 10, 3);
15
  }
16
 
17
  /**
20
  * @param string $where
21
  * @return string
22
  */
23
+ function wpp_posts_where($where)
24
+ {
25
+ global $wp_query, $wpdb;
26
+ if (empty($wp_query->query_vars))
27
+ return $where;
28
+
29
+ $pd = bn_parsidate::getInstance();
30
+
31
+ $m = (isset($wp_query->query_vars['m'])) ? $wp_query->query_vars['m'] : '';
32
+ $hour = (isset($wp_query->query_vars['hour'])) ? $wp_query->query_vars['hour'] : '';
33
+ $minute = (isset($wp_query->query_vars['minute'])) ? $wp_query->query_vars['minute'] : '';
34
+ $second = (isset($wp_query->query_vars['second'])) ? $wp_query->query_vars['second'] : '';
35
+ $year = (isset($wp_query->query_vars['year'])) ? $wp_query->query_vars['year'] : '';
36
+ $month = (isset($wp_query->query_vars['month'])) ? $wp_query->query_vars['month'] : '';
37
+ $day = (isset($wp_query->query_vars['day'])) ? $wp_query->query_vars['day'] : '';
38
+
39
+ if (!empty($m)) {
40
+ $len = strlen($m);
41
+ $year = substr($m, 0, 4);
42
+ if ($len > 5)
43
+ $month = substr($m, 4, 2);
44
+ if ($len > 7)
45
+ $day = substr($m, 6, 2);
46
+ if ($len > 9)
47
+ $hour = substr($m, 8, 2);
48
+ if ($len > 11)
49
+ $minute = substr($m, 10, 2);
50
+ if ($len > 13)
51
+ $second = substr($m, 12, 2);
52
+ }
53
+
54
+ if (empty($year) || $year > 1700)
55
+ return $where;
56
+
57
+ $stamon = 1;
58
+ $staday = 1;
59
+ $stahou = '00';
60
+ $stamin = '00';
61
+ $stasec = '00';
62
+ $endmon = 1;
63
+ $endday = 1;
64
+ $endhou = '00';
65
+ $endmin = '00';
66
+ $endsec = '00';
67
+
68
+ $stayear = $year;
69
+ $endyear = $year + 1;
70
+
71
+ if ($month != '') {
72
+ $stamon = $month;
73
+ $endmon = ($month == 12 ? 1 : $month + 1);
74
+ $endyear = ($endmon == 1 ? $stayear + 1 : $stayear);
75
+ }
76
+
77
+ if ($day != '') {
78
+ $staday = $day;
79
+ $endday = ($day == $pd->j_days_in_month[(int)$month - 1] ? 1 : $day + 1);
80
+ $endmon = ($endday == 1 ? $stamon + 1 : $stamon);
81
+ }
82
+
83
+ if ($hour != '') {
84
+ $stahou = $hour;
85
+ $endhou = ($hour == 24 ? '00' : $hour + 1);
86
+ $endday = ($endhou == '00' ? $staday + 1 : $staday);
87
+ }
88
+
89
+ if ($minute != '') {
90
+ $stamin = $minute;
91
+ $endmin = ($minute == 59 ? '00' : $minute + 1);
92
+ $endhou = ($endmin == '00' ? $stahou + 1 : $stahou);
93
+ }
94
+
95
+ if ($second != '') {
96
+ $stasec = $second;
97
+ $endsec = ($second == 59 ? '00' : $second + 1);
98
+ $endmin = ($endsec == '00' ? $stamin + 1 : $stamin);
99
+ }
100
+
101
+ $stadate = "$stayear-$stamon-$staday";
102
+ $enddate = "$endyear-$endmon-$endday";
103
+ $stadate = gregdate('Y-m-d', $stadate);
104
+ $enddate = gregdate('Y-m-d', $enddate);
105
+ $stadate .= " $stahou:$stamin:$stasec";
106
+ $enddate .= " $endhou:$endmin:$endsec";
107
+
108
+ $patterns = array('/YEAR\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
109
+ '/DAYOFMONTH\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
110
+ '/MONTH\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
111
+ '/HOUR\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
112
+ '/MINUTE\((.*?)post_date\s*\)\s*=\s*[0-9\']*/',
113
+ '/SECOND\((.*?)post_date\s*\)\s*=\s*[0-9\']*/');
114
+ foreach ($patterns as $pattern)
115
+ $where = preg_replace($pattern, '1=1', $where);
116
+
117
+ $prefixp = "{$wpdb->posts}.";
118
+ $prefixp = (strpos($where, $prefixp) == false) ? '' : $prefixp;
119
+
120
+ $where .= " AND {$prefixp}post_date >= '$stadate' AND {$prefixp}post_date < '$enddate' ";
121
+ return $where;
122
  }
123
 
124
  /**
127
  * @param WP_Query $query
128
  * @return mixed
129
  */
130
+ function wpp_pre_get_posts($query)
131
+ {
132
+ global $wpdb;
133
+
134
+ $permalink = $query->query;
135
+ $year = '';
136
+ $monthnum = '';
137
+ $day = '';//start
138
+
139
+ if (isset($permalink['year']))
140
+ $year = $permalink['year'];
141
+ if (isset($permalink['monthnum']))
142
+ $monthnum = $permalink['monthnum'];
143
+ if (isset($permalink['day']))
144
+ $day = $permalink['day'];
145
+ if ($year > 1700)
146
+ return $query;
147
+
148
+ $out = false;
149
+ $pd = bn_parsidate::getInstance();
150
+ if (isset($permalink['name'])) {
151
+ $var = $wpdb->get_var("SELECT post_date FROM {$wpdb->prefix}posts WHERE post_name='{$permalink['name']}' ORDER BY id");
152
+ $per = parsidate('Y-m-d', $var, 'eng');
153
+ //update_option('options', $per );
154
+ $per = explode('-', $per);
155
+ $out = true;
156
+
157
+ if ($year != $per[0])
158
+ $out = false;
159
+ if ($out && $monthnum != $per[1])
160
+ $out = false;
161
+ if ($out && $day != $per[2])
162
+ $out = false;
163
+
164
+ } elseif (isset($permalink['post_id'])) {
165
+ $out = true;
166
+ $var = $wpdb->get_var("SELECT post_date FROM {$wpdb->prefix}posts WHERE ID={$permalink['post_id']}");
167
+ } elseif (!empty($year) && !empty($monthnum) && !empty($day)) {
168
+ $out = true;
169
+ $var = gregdate('Y-m-d', "$year-$monthnum-$day");
170
+ } elseif (!empty($year) && !empty($monthnum)) {
171
+ $stadate = $pd->persian_to_gregorian($year, $monthnum, 1);
172
+ $enddate = $pd->persian_to_gregorian($year, $monthnum, $pd->j_days_in_month[($monthnum - 1)]);
173
+ $date_query = array(
174
+ array(
175
+ 'after' => array(
176
+ 'year' => $stadate[0],
177
+ 'month' => $stadate[1],
178
+ 'day' => $stadate[2] - 1,
179
+ ),
180
+ 'before' => array(
181
+ 'year' => $enddate[0],
182
+ 'month' => $enddate[1],
183
+ 'day' => $enddate[2] + 1,
184
+ ),
185
+ 'inclusive' => TRUE,
186
+ ),
187
+ );
188
+ $query->set('date_query', $date_query);
189
+
190
+ // commented for get year & month in calander widget
191
+ // $query->set('year', '');
192
+ // $query->set('monthnum', '');
193
+ $out = false;
194
+
195
+ } elseif (!empty($year)) {
196
+ $stadate = $pd->persian_to_gregorian($year, 1, 1);
197
+ $enddate = $pd->persian_to_gregorian(($year + 1), 1, 1);
198
+ $date_query = array(
199
+ array(
200
+ 'after' => array(
201
+ 'year' => $stadate[0],
202
+ 'month' => $stadate[1],
203
+ 'day' => $stadate[2] - 1,
204
+ ),
205
+ 'before' => array(
206
+ 'year' => $enddate[0],
207
+ 'month' => $enddate[1],
208
+ 'day' => $enddate[2],
209
+ ),
210
+ 'inclusive' => TRUE,
211
+ ),
212
+ );
213
+ $query->set('date_query', $date_query);
214
+ // $query->set('year', '');
215
+ $out = false;
216
+ }
217
+
218
+ if ($out) {
219
+ preg_match_all('!\d+!', $var, $matches);
220
+ $var = $matches[0];
221
+
222
+ $query->set('year', $var[0]);
223
+ $query->set('monthnum', $var[1]);
224
+ $query->set('day', $var[2]);
225
+ }
226
 
227
  // $query->set('')
228
 
229
+ return $query;
230
+
231
  }
232
 
233
  /**
238
  * @param bool $leavename
239
  * @return string New permalink
240
  */
241
+ function wpp_permalink($perma, $post, $leavename = false)
242
+ {
243
+ if (empty($post->ID))
244
+ return false;
245
+ if ($post->post_type == 'page' || $post->post_status == 'static')
246
+ return get_page_link($post->ID);
247
+ elseif ($post->post_type == 'attachment')
248
+ return get_attachment_link($post->ID);
249
+ elseif (in_array($post->post_type, get_post_types(array('_builtin' => false))))
250
+ return get_post_permalink($post->ID);
251
+
252
+ $permalink = get_option('permalink_structure');
253
+ preg_match_all('/%([^\/]*)%/', $permalink, $rewritecode);
254
+ $rewritecode = $rewritecode[0];
255
+ if ('' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft'))) {
256
+ if ($leavename)
257
+ $rewritecode = array_diff($rewritecode, array('%postname%', '%pagename%'));
258
+
259
+ $date = explode(' ', parsidate('Y m d H i s', $post->post_date, 'eng'));
260
+ $out = array();
261
+
262
+ foreach ($rewritecode as $rewrite) {
263
+ switch ($rewrite) {
264
+ case '%year%':
265
+ $out[] = $date[0];
266
+ break;
267
+ case '%monthnum%':
268
+ $out[] = $date[1];
269
+ break;
270
+ case '%day%':
271
+ $out[] = $date[2];
272
+ break;
273
+ case '%hour%':
274
+ $out[] = $date[3];
275
+ break;
276
+ case '%minute%':
277
+ $out[] = $date[4];
278
+ break;
279
+ case '%second%':
280
+ $out[] = $date[5];
281
+ break;
282
+ case '%post_id%':
283
+ $out[] = $post->ID;
284
+ break;
285
+ case '%postname%':
286
+ $out[] = $post->post_name;
287
+ break;
288
+ case '%category%':
289
+ $category = '';
290
+ $cats = get_the_category($post->ID);
291
+ if ($cats) {
292
+ usort($cats, '_usort_terms_by_ID');
293
+ $category = $cats[0]->slug;
294
+ if ($parent = $cats[0]->parent)
295
+ $category = get_category_parents($parent, false, '/', true);
296
+
297
+ if ($cats[0]->parent != 0)
298
+ $category .= $cats[0]->slug;
299
+ }
300
+ if (empty($category)) {
301
+ $default_category = get_term(get_option('default_category'), 'category');
302
+ $category = is_wp_error($default_category) ? '' : $default_category->slug;
303
+ }
304
+ $out[] = $category;
305
+ break;
306
+ case '%author%':
307
+ $authordata = get_userdata($post->post_author);
308
+ $out[] = $authordata->user_nicename;
309
+ break;
310
+ case '%pagename%':
311
+ $out[] = $post->post_name;
312
+ break;
313
+ default:
314
+ unset($rewritecode[array_search($rewrite, $rewritecode)]);
315
+ break;
316
+ }
317
+ }
318
+ $permalink = home_url(str_replace($rewritecode, $out, $permalink));
319
+ return user_trailingslashit($permalink, 'single');
320
+ } else {
321
+ return home_url("?p=$post->ID");
322
+ }
323
  }
324
+
325
  ?>
includes/general.php CHANGED
@@ -9,10 +9,10 @@
9
  */
10
  global $wpp_settings;
11
 
12
- add_filter( 'login_headerurl', 'wpp_login_headerurl', 10, 2 );
13
- add_filter( 'locale', 'wp_parsi_set_locale' );
14
- add_action( 'admin_notices', 'wpp_activation_notice' );
15
- add_action( 'admin_init', 'wpp_dismiss_notice_action' );
16
 
17
  /**
18
  * Change Locale WordPress Admin and Front-end user
@@ -20,18 +20,27 @@ add_action( 'admin_init', 'wpp_dismiss_notice_action' );
20
  * @param String $locale
21
  * @return String
22
  */
23
- function wp_parsi_set_locale($locale) {
24
- $settings = get_option( 'wpp_settings' );
25
- if ( $settings['admin_lang'] == 'enable' ) { $admin_locale = "fa_IR"; }elseif($settings['admin_lang'] == 'disable'){ $admin_locale = "en_US"; }
26
- if ( $settings['user_lang'] == 'enable' ) { $user_locale = "fa_IR"; }elseif($settings['user_lang'] == 'disable'){ $user_locale = "en_US"; }
27
-
28
- $locale_s = ( is_admin() ) ? $admin_locale : $user_locale;
29
-
30
- if(! empty($locale_s))
31
- $locale = $locale_s;
32
-
33
- setlocale(LC_ALL, $locale );
34
- return $locale;
 
 
 
 
 
 
 
 
 
35
  }
36
 
37
 
@@ -41,15 +50,16 @@ function wp_parsi_set_locale($locale) {
41
  * @since 1.0
42
  * @return bool True when page is feed, false when page isn't feed
43
  */
44
- function wpp_is_feed() {
45
- if ( is_feed() )
46
- return true;
 
47
 
48
- $path = $_SERVER['REQUEST_URI'];
49
- $exts = array( 'xml', 'gz', 'xsl' );
50
- $ext = pathinfo( $path, PATHINFO_EXTENSION );
51
 
52
- return in_array( $ext, $exts );
53
  }
54
 
55
  /**
@@ -58,12 +68,13 @@ function wpp_is_feed() {
58
  * @param string $number Numbers
59
  * @return string Formatted numbers
60
  */
61
- function per_number( $number ) {
62
- return str_replace(
63
- range( 0, 9 ),
64
- array( '۰','۱','۲','۳','۴','۵','۶','۷','۸','۹' ),
65
- $number
66
- );
 
67
  }
68
 
69
  /**
@@ -72,12 +83,13 @@ function per_number( $number ) {
72
  * @param string $number Numbers
73
  * @return string Formatted numbers
74
  */
75
- function eng_number( $number ) {
76
- return str_replace(
77
- array( '۰','۱','۲','۳','۴','۵','۶','۷','۸','۹' ),
78
- range( 0, 9 ),
79
- $number
80
- );
 
81
  }
82
 
83
  /**
@@ -86,10 +98,11 @@ function eng_number( $number ) {
86
  * @param string $content Post content
87
  * @return string Formatted content
88
  */
89
- function persian_number( $content ) {
90
- return(
91
- isset($content[1]) ? per_number( $content[1] ) : $content[0]
92
- );
 
93
  }
94
 
95
  /**
@@ -98,8 +111,9 @@ function persian_number( $content ) {
98
  * @param string $content
99
  * @return mixed
100
  */
101
- function fixnumber( $content ) {
102
- return preg_replace_callback( '/(?:&#\d{2,4};)|(?:[0]?[a-z][\x20-\x3B=\x3F-\x7F]*)|(\d+[\.\d]*)|<\s*[^>]+>/i','persian_number',$content);
 
103
  }
104
 
105
  /**
@@ -108,8 +122,9 @@ function fixnumber( $content ) {
108
  * @param string $content
109
  * @return mixed
110
  */
111
- function fixarabic( $content ) {
112
- return str_replace( array( 'ي','ك','٤','٥','٦','ة' ), array( 'ی','ک','۴','۵','۶','ه' ), $content );
 
113
  }
114
 
115
  /**
@@ -119,7 +134,7 @@ function fixarabic( $content ) {
119
  */
120
  function wpp_login_headerurl()
121
  {
122
- return 'http://wp-parsi.com';
123
  }
124
 
125
  /**
@@ -129,17 +144,18 @@ function wpp_login_headerurl()
129
  * @author Ehsaan
130
  * @return void
131
  */
132
- function wpp_activation_notice() {
133
- $dismissed = get_option( 'wpp_dismissed', false );
 
134
 
135
- if ( ! $dismissed ) {
136
- global $wpp_settings;
137
 
138
- if ( $wpp_settings[ 'persian_date' ] != 'enable' ) {
139
- $output = sprintf( __( '<div class="updated wpp-message"><p>ParsiDate activated, you may need to configure it to work properly. <a href="%s">Go to configuartion page</a> &ndash; <a href="%s">Dismiss</a></p></div>', 'wp-parsidate' ), admin_url( 'admin.php?page=wp-parsi-settings' ), add_query_arg( 'wpp-action', 'dismiss-notice' ) );
140
- echo $output;
141
- }
142
- }
143
  }
144
 
145
  /**
@@ -148,8 +164,9 @@ function wpp_activation_notice() {
148
  * @author Ehsaan
149
  * @return void
150
  */
151
- function wpp_dismiss_notice_action() {
152
- if ( isset( $_GET[ 'wpp-action' ] ) && $_GET[ 'wpp-action' ] == 'dismiss-notice' ) {
153
- update_option( 'wpp_dismissed', true );
154
- }
 
155
  }
9
  */
10
  global $wpp_settings;
11
 
12
+ add_filter('login_headerurl', 'wpp_login_headerurl', 10, 2);
13
+ add_filter('locale', 'wp_parsi_set_locale');
14
+ add_action('admin_notices', 'wpp_activation_notice');
15
+ add_action('admin_init', 'wpp_dismiss_notice_action');
16
 
17
  /**
18
  * Change Locale WordPress Admin and Front-end user
20
  * @param String $locale
21
  * @return String
22
  */
23
+ function wp_parsi_set_locale($locale)
24
+ {
25
+ $settings = get_option('wpp_settings');
26
+ if ($settings['admin_lang'] == 'enable') {
27
+ $admin_locale = "fa_IR";
28
+ } elseif ($settings['admin_lang'] == 'disable') {
29
+ $admin_locale = "en_US";
30
+ }
31
+ if ($settings['user_lang'] == 'enable') {
32
+ $user_locale = "fa_IR";
33
+ } elseif ($settings['user_lang'] == 'disable') {
34
+ $user_locale = "en_US";
35
+ }
36
+
37
+ $locale_s = (is_admin()) ? $admin_locale : $user_locale;
38
+
39
+ if (!empty($locale_s))
40
+ $locale = $locale_s;
41
+
42
+ setlocale(LC_ALL, $locale);
43
+ return $locale;
44
  }
45
 
46
 
50
  * @since 1.0
51
  * @return bool True when page is feed, false when page isn't feed
52
  */
53
+ function wpp_is_feed()
54
+ {
55
+ if (is_feed())
56
+ return true;
57
 
58
+ $path = $_SERVER['REQUEST_URI'];
59
+ $exts = array('xml', 'gz', 'xsl');
60
+ $ext = pathinfo($path, PATHINFO_EXTENSION);
61
 
62
+ return in_array($ext, $exts);
63
  }
64
 
65
  /**
68
  * @param string $number Numbers
69
  * @return string Formatted numbers
70
  */
71
+ function per_number($number)
72
+ {
73
+ return str_replace(
74
+ range(0, 9),
75
+ array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'),
76
+ $number
77
+ );
78
  }
79
 
80
  /**
83
  * @param string $number Numbers
84
  * @return string Formatted numbers
85
  */
86
+ function eng_number($number)
87
+ {
88
+ return str_replace(
89
+ array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'),
90
+ range(0, 9),
91
+ $number
92
+ );
93
  }
94
 
95
  /**
98
  * @param string $content Post content
99
  * @return string Formatted content
100
  */
101
+ function persian_number($content)
102
+ {
103
+ return (
104
+ isset($content[1]) ? per_number($content[1]) : $content[0]
105
+ );
106
  }
107
 
108
  /**
111
  * @param string $content
112
  * @return mixed
113
  */
114
+ function fixnumber($content)
115
+ {
116
+ return preg_replace_callback('/(?:&#\d{2,4};)|(?:[0]?[a-z][\x20-\x3B=\x3F-\x7F]*)|(\d+[\.\d]*)|<\s*[^>]+>/i', 'persian_number', $content);
117
  }
118
 
119
  /**
122
  * @param string $content
123
  * @return mixed
124
  */
125
+ function fixarabic($content)
126
+ {
127
+ return str_replace(array('ي', 'ك', '٤', '٥', '٦', 'ة'), array('ی', 'ک', '۴', '۵', '۶', 'ه'), $content);
128
  }
129
 
130
  /**
134
  */
135
  function wpp_login_headerurl()
136
  {
137
+ return 'http://wp-parsi.com';
138
  }
139
 
140
  /**
144
  * @author Ehsaan
145
  * @return void
146
  */
147
+ function wpp_activation_notice()
148
+ {
149
+ $dismissed = get_option('wpp_dismissed', false);
150
 
151
+ if (!$dismissed) {
152
+ global $wpp_settings;
153
 
154
+ if ($wpp_settings['persian_date'] != 'enable') {
155
+ $output = sprintf(__('<div class="updated wpp-message"><p>ParsiDate activated, you may need to configure it to work properly. <a href="%s">Go to configuartion page</a> &ndash; <a href="%s">Dismiss</a></p></div>', 'wp-parsidate'), admin_url('admin.php?page=wp-parsi-settings'), add_query_arg('wpp-action', 'dismiss-notice'));
156
+ echo $output;
157
+ }
158
+ }
159
  }
160
 
161
  /**
164
  * @author Ehsaan
165
  * @return void
166
  */
167
+ function wpp_dismiss_notice_action()
168
+ {
169
+ if (isset($_GET['wpp-action']) && $_GET['wpp-action'] == 'dismiss-notice') {
170
+ update_option('wpp_dismissed', true);
171
+ }
172
  }
includes/install.php CHANGED
@@ -7,7 +7,7 @@
7
  * @subpackage Core/Install
8
  */
9
 
10
- register_activation_hook( WP_PARSI_ROOT, 'wpp_install' );
11
 
12
  /**
13
  * Copys files from plugin languages folder to global languages folder
@@ -15,17 +15,18 @@ register_activation_hook( WP_PARSI_ROOT, 'wpp_install' );
15
  * @since 1.0
16
  * @return void
17
  */
18
- function wpp_install() {
19
-
20
- /*if ( ! is_dir( WP_CONTENT_DIR . '/languages' ) )
21
- mkdir( WP_CONTENT_DIR . '/languages/' );
22
 
23
- $source = WP_PARSI_DIR . 'languages/*';
24
- $destination = WP_CONTENT_DIR . '/languages/';
25
- $files = glob( $source );
26
 
27
- foreach( $files as $file )
28
- @ copy( $file, $destination . basename( $file ) );*/
 
29
 
30
- update_option( 'wpp_settings', array() );
 
 
 
31
  }
7
  * @subpackage Core/Install
8
  */
9
 
10
+ register_activation_hook(WP_PARSI_ROOT, 'wpp_install');
11
 
12
  /**
13
  * Copys files from plugin languages folder to global languages folder
15
  * @since 1.0
16
  * @return void
17
  */
18
+ function wpp_install()
19
+ {
 
 
20
 
21
+ /*if ( ! is_dir( WP_CONTENT_DIR . '/languages' ) )
22
+ mkdir( WP_CONTENT_DIR . '/languages/' );
 
23
 
24
+ $source = WP_PARSI_DIR . 'languages/*';
25
+ $destination = WP_CONTENT_DIR . '/languages/';
26
+ $files = glob( $source );
27
 
28
+ foreach( $files as $file )
29
+ @ copy( $file, $destination . basename( $file ) );*/
30
+
31
+ update_option('wpp_settings', array());
32
  }
includes/parsidate.php CHANGED
@@ -11,311 +11,326 @@ Reza Gholampanahi for convert function*/
11
 
12
  class bn_parsidate
13
  {
14
- protected static $instance;
15
- public $persian_month_names = array('','فروردین','اردیبهشت','خرداد','تیر','مرداد','شهریور','مهر','آبان','آذر','دی','بهمن','اسفند');
16
- public $persian_short_month_names = array('','فرو','ارد','خرد','تیر','مرد','شهر','مهر','آبا','آذر','دی','بهم','اسف');
17
- public $sesson = array('بهار','تابستان','پاییز','زمستان');
18
 
19
- public $persian_day_names = array('یکشنبه','دوشنبه','سه شنبه','چهارشنبه','پنجشنبه','جمعه','شنبه');
20
- public $persian_day_small = array('ی','د','س','چ','پ','ج','ش');
21
 
22
- public $j_days_in_month = array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);
23
- private $j_days_sum_month = array(0,0,31, 62, 93, 124, 155, 186, 216, 246, 276, 306, 336);
24
 
25
- private $g_days_sum_month = array(0,0,31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);
26
 
27
 
28
- /**
29
- * Constructor
30
- */
31
- function __construct(){
32
- if($this->IsLeapYear($this->persian_date("Y",time(),"eng"))){
33
- $this->j_days_in_month[11] = 30;
34
- }
35
- }
 
36
 
37
- /**
38
- * bn_parsidate::getInstance()
39
- * create instance of bn_parsidate class
40
- *
41
- * @return instance
42
- */
43
- public static function getInstance()
44
- {
45
- if (!isset(self::$instance))
46
- self::$instance = new self();
47
- return self::$instance;
48
- }
 
 
49
 
50
- /**
51
- * bn_parsidate::IsLeapYear()
52
- * check year is leap
53
- *
54
- * @param mixed $year
55
- * @return boolean
56
- */
57
- private function IsLeapYear($year)
58
- {
59
- if((($year%4)==0 && ($year%100)!=0)||(($year%400)==0)&&($year%100)==0)
60
- return true;
61
- else
62
- return false;
63
- }
64
 
65
- /**
66
- * bn_parsidate::persian_to_gregorian()
67
- * convert persian date to gregorian date
68
- *
69
- * @param mixed $jy
70
- * @param mixed $jm
71
- * @param mixed $jd
72
- * @return array
73
- */
74
- public function persian_to_gregorian($jy,$jm,$jd)
75
- {
76
- $doyj = ($jm-2>-1?$this->j_days_sum_month[(int)$jm]+$jd:$jd);
77
- $d4 = ($jy+1)%4;
78
- $d33 = (int)((($jy-55)%132)*.0305);
79
- $a = ($d33!=3 and $d4<=$d33)?287:286;
80
- $b = (($d33==1 or $d33==2) and ($d33==$d4 or $d4==1))?78:(($d33==3 and $d4==0)?80:79);
81
- if((int)(($jy-19)/63)==20)
82
- {$a--;$b++;}
83
- if($doyj<=$a){
84
- $gy = $jy+621; $gd=$doyj+$b;
85
- }else{
86
- $gy = $jy+622; $gd=$doyj-$a;
87
- }
88
- foreach(array(0,31,($gy%4==0)?29:28,31,30,31,30,31,31,30,31,30,31) as $gm=>$days){
89
- if($gd<=$days)break;
90
- $gd-=$days;
91
- }
92
- return array($gy,$gm,$gd);
93
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
- /**
96
- * bn_parsidate::gregorian_to_persian()
97
- * convert gregorian date to persian date
98
- *
99
- * @param mixed $gy
100
- * @param mixed $gm
101
- * @param mixed $gd
102
- * @return array
103
- */
104
- function gregorian_to_persian($gy,$gm,$gd)
105
- {
106
- $dayofyear = $this->g_days_sum_month[(int)$gm]+$gd;
107
- if(self::IsLeapYear($gy) and $gm>2)
108
- $dayofyear++;
109
- $d_33 = (int)((($gy-16)%132)*0.0305);
110
- $leap = $gy%4;
111
- $a = (($d_33==1 or $d_33==2) and ($d_33==$leap or $leap==1))?78:(($d_33==3 and $leap==0)?80:79);
112
- $b = ($d_33==3 or $d_33<($leap-1) or $leap==0)?286:287;
113
- if((int)(($gy-10)/63)==30)
114
- {$b--;$a++;}
115
- if($dayofyear>$a){
116
- $jy = $gy-621;
117
- $jd = $dayofyear-$a;
118
- }else{
119
- $jy = $gy-622;
120
- $jd = $dayofyear+$b;
121
- }
122
- for($i=0;$i<11 and $jd>$this->j_days_in_month[$i];$i++)
123
- $jd-= $this->j_days_in_month[$i];
124
- $jm = ++$i;
125
- return array($jy,strlen($jm)==1?'0'.$jm:$jm,strlen($jd)==1?'0'.$jd:$jd);
126
- }
127
-
128
- /**
129
- * bn_parsidate::trim_number()
130
- * convert english number to persian number
131
- * @param mixed $num
132
- * @param string $sp
133
- * @return string
134
- */
135
- public function trim_number($num,$sp='٫')
136
- {
137
- $eng = array('0','1','2','3','4','5','6','7','8','9','.');
138
- $per = array('۰','۱','۲','۳','۴','۵','۶','۷','۸','۹',$sp);
139
- $number = filter_var($num, FILTER_SANITIZE_NUMBER_INT);
140
- return empty($number)?str_replace($per,$eng,$num):str_replace($eng,$per,$num);
141
- }
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
 
144
- /**
145
- * Get day of the week shamsi/jalali
146
- * @author Parsa Kafi
147
- * @param int $wday
148
- * @return int
149
- */
150
- private function week_day($wday){
151
- if($wday == 6)
152
- return 0;
153
- else
154
- return ++$wday;
155
- }
 
 
156
 
157
- /**
158
- * bn_parsidate::persian_date()
159
- * convert gregorian datetime to persian datetime
160
- *
161
- * @param mixed $format
162
- * @param string $date
163
- * @param string $lang
164
- * @return datetime
165
- */
166
- public function persian_date($format,$date='now',$lang='per')
167
- {
168
- $j_days_in_month = array(31, 62, 93, 124, 155, 186, 216, 246, 276, 306, 336, 365);
169
- $timestamp =is_numeric($date) && (int)$date == $date?$date:strtotime($date);
170
 
171
- $date = getdate($timestamp);
172
- list($date['year'],$date['mon'],$date['mday'])=self::gregorian_to_persian($date['year'],$date['mon'],$date['mday']);
173
- $date['mon'] = (int)$date['mon'];
174
- $date['mday'] = (int)$date['mday'];
175
- $out = '';
176
- for($i=0;$i<strlen($format);$i++)
177
- {
178
- Switch($format[$i])
179
- {
180
- //day
181
- case 'd':
182
- $out.=($date['mday']<10)?'0'.$date['mday']:$date['mday'];
183
- break;
184
- case 'D':
185
- $out.=$this->persian_day_small[$date['wday']];
186
- break;
187
- case'l':
188
- $out.=$this->persian_day_names[$date['wday']];
189
- break;
190
- case 'j':
191
- $out.=$date['mday'];
192
- break;
193
- case'N':
194
- $out.=$this->week_day($date['wday'])+1;
195
- break;
196
- case'w':
197
- $out.=$this->week_day($date['wday']);
198
- break;
199
- case'z':
200
- $out.=$this->j_days_in_month[$date['mon']]+$date['mday'];
201
- break;
202
- //week
203
- case'W':
204
- $yday=$this->j_days_sum_month[$date['mon']-1]+$date['mday'];
205
- $out.=intval($yday/7);
206
- break;
207
- //month
208
- case'f':
209
- $mon=$date['mon'];
210
- switch($mon)
211
- {
212
- case($mon<4):
213
- $out.=$this->sesson[0];
214
- break;
215
- case($mon<7):
216
- $out.=$this->sesson[1];
217
- break;
218
- case($mon<10):
219
- $out.=$this->sesson[2];
220
- break;
221
- case($mon>9):
222
- $out.=$this->sesson[3];
223
- break;
224
- }
225
- break;
226
- case'F':
227
- $out.=$this->persian_month_names[(int)$date['mon']];
228
- break;
229
- case'm':
230
- $out.=($date['mon']<10)?'0'.$date['mon']:$date['mon'];
231
- break;
232
- case'M':
233
- $out.=$this->persian_short_month_names[(int)$date['mon']];
234
- break;
235
- case'n':
236
- $out.=$date['mon'];
237
- break;
238
- case'S':
239
- $out.='ام';
240
- break;
241
- case't':
242
- $out.=$this->j_days_in_month[(int)$date['mon']-1];
243
- break;
244
- //year
245
- case'L':
246
- $out.=(($date['year']%4)==0)?1:0;
247
- break;
248
- case'o':case'Y':
249
- $out.=$date['year'];
250
- break;
251
- case'y':
252
- $out.=substr($date['year'],2,2);
253
- break;
254
- //time
255
- case'a':
256
- $out.=($date['hours']<12)?'ق.ظ':'ب.ظ';
257
- break;
258
- case'A':
259
- $out.=($date['hours']<12)?'قبل از ظهر':'بعد از ظهر';
260
- break;
261
- case'B':
262
- $out.=(int)(1+($date['mon']/3));
263
- break;
264
- case'g':
265
- $out.=($date['hours']>12)?$date['hours']-12:$date['hours'];
266
- break;
267
- case'G':
268
- $out.=$date['hours'];
269
- break;
270
- case'h':
271
- $hour=($date['hours']>12)?$date['hours']-12:$date['hours'];
272
- $out.=($hour<10)?'0'.$hour:$hour;
273
- break;
274
- case'H':
275
- $out.=($date['hours']<10)?'0'.$date['hours']:$date['hours'];
276
- break;
277
- case'i':
278
- $out.=($date['minutes']<10)?'0'.$date['minutes']:$date['minutes'];
279
- break;
280
- case's':
281
- $out.=($date['seconds']<10)?'0'.$date['seconds']:$date['seconds'];
282
- break;
283
- //full date time
284
- case'c':
285
- $out=$date['year'].'/'.$date['mon'].'/'.$date['mday'].' '.$date['hours'].':'.(($date['minutes']<10)?'0'.$date['minutes']:$date['minutes']).':'.(($date['seconds']<10)?'0'.$date['seconds']:$date['seconds']);//2004-02-12T15:19:21+00:00
286
- break;
287
- case'r':
288
- $out=$this->persian_day_names[$date['wday']].','.$date['mday'].' '.$this->persian_month_names[(int)$date['mon']].' '.$date['year'].' '.$date['hours'].':'.(($date['minutes']<10)?'0'.$date['minutes']:$date['minutes']).':'.(($date['seconds']<10)?'0'.$date['seconds']:$date['seconds']) ;//Thu, 21 Dec 2000 16:01:07
289
- break;
290
- case'U':
291
- $out=$timestamp;
292
- break;
293
- //others
294
- case'e':case'I':case'i':case'O':case'P':case'T':case'Z':case'u':break;
295
- default:$out.=$format[$i];
296
- }
297
- }
298
- if($lang=='per')
299
- return self::trim_number($out);
300
- else
301
- return $out;
302
- }
303
 
304
- /**
305
- * bn_parsidate::gregurian_date()
306
- * convert persian datetime to gregorian datetime
307
- * @param mixed $format
308
- * @param mixed $persiandate
309
- * @return datetime
310
- */
311
- public function gregurian_date($format,$persiandate)
312
- {
313
- preg_match_all('!\d+!', $persiandate, $matches);
314
- $matches=$matches[0];
315
- list($year,$mon,$day)=self::persian_to_gregorian($matches[0],$matches[1],$matches[2]);
316
- return date($format,mktime((isset($matches[3])?$matches[3]:0),(isset($matches[4])?$matches[4]:0),(isset($matches[5])?$matches[5]:0),$mon,$day,$year));
317
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
318
  }
 
319
  /*
320
  * parsidate function
321
  */
@@ -328,11 +343,11 @@ class bn_parsidate
328
  * @param string $lang
329
  * @return datetime
330
  */
331
- function parsidate($input,$datetime='now',$lang='per')
332
  {
333
- $bndate =bn_parsidate::getInstance();
334
- $bndate = $bndate->persian_date($input,$datetime,$lang);
335
- return $bndate;
336
  }
337
 
338
  /**
@@ -343,9 +358,9 @@ function parsidate($input,$datetime='now',$lang='per')
343
  * @param mixed $datetime
344
  * @return datetime
345
  */
346
- function gregdate($input,$datetime)
347
  {
348
- $bndate =bn_parsidate::getInstance();
349
- $bndate = $bndate->gregurian_date($input,$datetime);
350
- return $bndate;
351
  }
11
 
12
  class bn_parsidate
13
  {
14
+ protected static $instance;
15
+ public $persian_month_names = array('', 'فروردین', 'اردیبهشت', 'خرداد', 'تیر', 'مرداد', 'شهریور', 'مهر', 'آبان', 'آذر', 'دی', 'بهمن', 'اسفند');
16
+ public $persian_short_month_names = array('', 'فرو', 'ارد', 'خرد', 'تیر', 'مرد', 'شهر', 'مهر', 'آبا', 'آذر', 'دی', 'بهم', 'اسف');
17
+ public $sesson = array('بهار', 'تابستان', 'پاییز', 'زمستان');
18
 
19
+ public $persian_day_names = array('یکشنبه', 'دوشنبه', 'سه شنبه', 'چهارشنبه', 'پنجشنبه', 'جمعه', 'شنبه');
20
+ public $persian_day_small = array('ی', 'د', 'س', 'چ', 'پ', 'ج', 'ش');
21
 
22
+ public $j_days_in_month = array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);
23
+ private $j_days_sum_month = array(0, 0, 31, 62, 93, 124, 155, 186, 216, 246, 276, 306, 336);
24
 
25
+ private $g_days_sum_month = array(0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);
26
 
27
 
28
+ /**
29
+ * Constructor
30
+ */
31
+ function __construct()
32
+ {
33
+ if ($this->IsLeapYear($this->persian_date("Y", time(), "eng"))) {
34
+ $this->j_days_in_month[11] = 30;
35
+ }
36
+ }
37
 
38
+ /**
39
+ * bn_parsidate::IsLeapYear()
40
+ * check year is leap
41
+ *
42
+ * @param mixed $year
43
+ * @return boolean
44
+ */
45
+ private function IsLeapYear($year)
46
+ {
47
+ if ((($year % 4) == 0 && ($year % 100) != 0) || (($year % 400) == 0) && ($year % 100) == 0)
48
+ return true;
49
+ else
50
+ return false;
51
+ }
52
 
53
+ /**
54
+ * bn_parsidate::persian_date()
55
+ * convert gregorian datetime to persian datetime
56
+ *
57
+ * @param mixed $format
58
+ * @param string $date
59
+ * @param string $lang
60
+ * @return datetime
61
+ */
62
+ public function persian_date($format, $date = 'now', $lang = 'per')
63
+ {
64
+ $j_days_in_month = array(31, 62, 93, 124, 155, 186, 216, 246, 276, 306, 336, 365);
65
+ $timestamp = is_numeric($date) && (int)$date == $date ? $date : strtotime($date);
 
66
 
67
+ $date = getdate($timestamp);
68
+ list($date['year'], $date['mon'], $date['mday']) = self::gregorian_to_persian($date['year'], $date['mon'], $date['mday']);
69
+ $date['mon'] = (int)$date['mon'];
70
+ $date['mday'] = (int)$date['mday'];
71
+ $out = '';
72
+ for ($i = 0; $i < strlen($format); $i++) {
73
+ Switch ($format[$i]) {
74
+ //day
75
+ case 'd':
76
+ $out .= ($date['mday'] < 10) ? '0' . $date['mday'] : $date['mday'];
77
+ break;
78
+ case 'D':
79
+ $out .= $this->persian_day_small[$date['wday']];
80
+ break;
81
+ case'l':
82
+ $out .= $this->persian_day_names[$date['wday']];
83
+ break;
84
+ case 'j':
85
+ $out .= $date['mday'];
86
+ break;
87
+ case'N':
88
+ $out .= $this->week_day($date['wday']) + 1;
89
+ break;
90
+ case'w':
91
+ $out .= $this->week_day($date['wday']);
92
+ break;
93
+ case'z':
94
+ $out .= $this->j_days_in_month[$date['mon']] + $date['mday'];
95
+ break;
96
+ //week
97
+ case'W':
98
+ $yday = $this->j_days_sum_month[$date['mon'] - 1] + $date['mday'];
99
+ $out .= intval($yday / 7);
100
+ break;
101
+ //month
102
+ case'f':
103
+ $mon = $date['mon'];
104
+ switch ($mon) {
105
+ case($mon < 4):
106
+ $out .= $this->sesson[0];
107
+ break;
108
+ case($mon < 7):
109
+ $out .= $this->sesson[1];
110
+ break;
111
+ case($mon < 10):
112
+ $out .= $this->sesson[2];
113
+ break;
114
+ case($mon > 9):
115
+ $out .= $this->sesson[3];
116
+ break;
117
+ }
118
+ break;
119
+ case'F':
120
+ $out .= $this->persian_month_names[(int)$date['mon']];
121
+ break;
122
+ case'm':
123
+ $out .= ($date['mon'] < 10) ? '0' . $date['mon'] : $date['mon'];
124
+ break;
125
+ case'M':
126
+ $out .= $this->persian_short_month_names[(int)$date['mon']];
127
+ break;
128
+ case'n':
129
+ $out .= $date['mon'];
130
+ break;
131
+ case'S':
132
+ $out .= 'ام';
133
+ break;
134
+ case't':
135
+ $out .= $this->j_days_in_month[(int)$date['mon'] - 1];
136
+ break;
137
+ //year
138
+ case'L':
139
+ $out .= (($date['year'] % 4) == 0) ? 1 : 0;
140
+ break;
141
+ case'o':
142
+ case'Y':
143
+ $out .= $date['year'];
144
+ break;
145
+ case'y':
146
+ $out .= substr($date['year'], 2, 2);
147
+ break;
148
+ //time
149
+ case'a':
150
+ $out .= ($date['hours'] < 12) ? 'ق.ظ' : 'ب.ظ';
151
+ break;
152
+ case'A':
153
+ $out .= ($date['hours'] < 12) ? 'قبل از ظهر' : 'بعد از ظهر';
154
+ break;
155
+ case'B':
156
+ $out .= (int)(1 + ($date['mon'] / 3));
157
+ break;
158
+ case'g':
159
+ $out .= ($date['hours'] > 12) ? $date['hours'] - 12 : $date['hours'];
160
+ break;
161
+ case'G':
162
+ $out .= $date['hours'];
163
+ break;
164
+ case'h':
165
+ $hour = ($date['hours'] > 12) ? $date['hours'] - 12 : $date['hours'];
166
+ $out .= ($hour < 10) ? '0' . $hour : $hour;
167
+ break;
168
+ case'H':
169
+ $out .= ($date['hours'] < 10) ? '0' . $date['hours'] : $date['hours'];
170
+ break;
171
+ case'i':
172
+ $out .= ($date['minutes'] < 10) ? '0' . $date['minutes'] : $date['minutes'];
173
+ break;
174
+ case's':
175
+ $out .= ($date['seconds'] < 10) ? '0' . $date['seconds'] : $date['seconds'];
176
+ break;
177
+ //full date time
178
+ case'c':
179
+ $out = $date['year'] . '/' . $date['mon'] . '/' . $date['mday'] . ' ' . $date['hours'] . ':' . (($date['minutes'] < 10) ? '0' . $date['minutes'] : $date['minutes']) . ':' . (($date['seconds'] < 10) ? '0' . $date['seconds'] : $date['seconds']);//2004-02-12T15:19:21+00:00
180
+ break;
181
+ case'r':
182
+ $out = $this->persian_day_names[$date['wday']] . ',' . $date['mday'] . ' ' . $this->persian_month_names[(int)$date['mon']] . ' ' . $date['year'] . ' ' . $date['hours'] . ':' . (($date['minutes'] < 10) ? '0' . $date['minutes'] : $date['minutes']) . ':' . (($date['seconds'] < 10) ? '0' . $date['seconds'] : $date['seconds']);//Thu, 21 Dec 2000 16:01:07
183
+ break;
184
+ case'U':
185
+ $out = $timestamp;
186
+ break;
187
+ //others
188
+ case'e':
189
+ case'I':
190
+ case'i':
191
+ case'O':
192
+ case'P':
193
+ case'T':
194
+ case'Z':
195
+ case'u':
196
+ break;
197
+ default:
198
+ $out .= $format[$i];
199
+ }
200
+ }
201
+ if ($lang == 'per')
202
+ return self::trim_number($out);
203
+ else
204
+ return $out;
205
+ }
206
 
207
+ /**
208
+ * bn_parsidate::gregorian_to_persian()
209
+ * convert gregorian date to persian date
210
+ *
211
+ * @param mixed $gy
212
+ * @param mixed $gm
213
+ * @param mixed $gd
214
+ * @return array
215
+ */
216
+ function gregorian_to_persian($gy, $gm, $gd)
217
+ {
218
+ $dayofyear = $this->g_days_sum_month[(int)$gm] + $gd;
219
+ if (self::IsLeapYear($gy) and $gm > 2)
220
+ $dayofyear++;
221
+ $d_33 = (int)((($gy - 16) % 132) * 0.0305);
222
+ $leap = $gy % 4;
223
+ $a = (($d_33 == 1 or $d_33 == 2) and ($d_33 == $leap or $leap == 1)) ? 78 : (($d_33 == 3 and $leap == 0) ? 80 : 79);
224
+ $b = ($d_33 == 3 or $d_33 < ($leap - 1) or $leap == 0) ? 286 : 287;
225
+ if ((int)(($gy - 10) / 63) == 30) {
226
+ $b--;
227
+ $a++;
228
+ }
229
+ if ($dayofyear > $a) {
230
+ $jy = $gy - 621;
231
+ $jd = $dayofyear - $a;
232
+ } else {
233
+ $jy = $gy - 622;
234
+ $jd = $dayofyear + $b;
235
+ }
236
+ for ($i = 0; $i < 11 and $jd > $this->j_days_in_month[$i]; $i++)
237
+ $jd -= $this->j_days_in_month[$i];
238
+ $jm = ++$i;
239
+ return array($jy, strlen($jm) == 1 ? '0' . $jm : $jm, strlen($jd) == 1 ? '0' . $jd : $jd);
240
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
241
 
242
+ /**
243
+ * Get day of the week shamsi/jalali
244
+ * @author Parsa Kafi
245
+ * @param int $wday
246
+ * @return int
247
+ */
248
+ private function week_day($wday)
249
+ {
250
+ if ($wday == 6)
251
+ return 0;
252
+ else
253
+ return ++$wday;
254
+ }
255
 
256
+ /**
257
+ * bn_parsidate::trim_number()
258
+ * convert english number to persian number
259
+ * @param mixed $num
260
+ * @param string $sp
261
+ * @return string
262
+ */
263
+ public function trim_number($num, $sp = '٫')
264
+ {
265
+ $eng = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.');
266
+ $per = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹', $sp);
267
+ $number = filter_var($num, FILTER_SANITIZE_NUMBER_INT);
268
+ return empty($number) ? str_replace($per, $eng, $num) : str_replace($eng, $per, $num);
269
+ }
270
 
271
+ /**
272
+ * bn_parsidate::getInstance()
273
+ * create instance of bn_parsidate class
274
+ *
275
+ * @return instance
276
+ */
277
+ public static function getInstance()
278
+ {
279
+ if (!isset(self::$instance))
280
+ self::$instance = new self();
281
+ return self::$instance;
282
+ }
 
283
 
284
+ /**
285
+ * bn_parsidate::gregurian_date()
286
+ * convert persian datetime to gregorian datetime
287
+ * @param mixed $format
288
+ * @param mixed $persiandate
289
+ * @return datetime
290
+ */
291
+ public function gregurian_date($format, $persiandate)
292
+ {
293
+ preg_match_all('!\d+!', $persiandate, $matches);
294
+ $matches = $matches[0];
295
+ list($year, $mon, $day) = self::persian_to_gregorian($matches[0], $matches[1], $matches[2]);
296
+ return date($format, mktime((isset($matches[3]) ? $matches[3] : 0), (isset($matches[4]) ? $matches[4] : 0), (isset($matches[5]) ? $matches[5] : 0), $mon, $day, $year));
297
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
 
299
+ /**
300
+ * bn_parsidate::persian_to_gregorian()
301
+ * convert persian date to gregorian date
302
+ *
303
+ * @param mixed $jy
304
+ * @param mixed $jm
305
+ * @param mixed $jd
306
+ * @return array
307
+ */
308
+ public function persian_to_gregorian($jy, $jm, $jd)
309
+ {
310
+ $doyj = ($jm - 2 > -1 ? $this->j_days_sum_month[(int)$jm] + $jd : $jd);
311
+ $d4 = ($jy + 1) % 4;
312
+ $d33 = (int)((($jy - 55) % 132) * .0305);
313
+ $a = ($d33 != 3 and $d4 <= $d33) ? 287 : 286;
314
+ $b = (($d33 == 1 or $d33 == 2) and ($d33 == $d4 or $d4 == 1)) ? 78 : (($d33 == 3 and $d4 == 0) ? 80 : 79);
315
+ if ((int)(($jy - 19) / 63) == 20) {
316
+ $a--;
317
+ $b++;
318
+ }
319
+ if ($doyj <= $a) {
320
+ $gy = $jy + 621;
321
+ $gd = $doyj + $b;
322
+ } else {
323
+ $gy = $jy + 622;
324
+ $gd = $doyj - $a;
325
+ }
326
+ foreach (array(0, 31, ($gy % 4 == 0) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) as $gm => $days) {
327
+ if ($gd <= $days) break;
328
+ $gd -= $days;
329
+ }
330
+ return array($gy, $gm, $gd);
331
+ }
332
  }
333
+
334
  /*
335
  * parsidate function
336
  */
343
  * @param string $lang
344
  * @return datetime
345
  */
346
+ function parsidate($input, $datetime = 'now', $lang = 'per')
347
  {
348
+ $bndate = bn_parsidate::getInstance();
349
+ $bndate = $bndate->persian_date($input, $datetime, $lang);
350
+ return $bndate;
351
  }
352
 
353
  /**
358
  * @param mixed $datetime
359
  * @return datetime
360
  */
361
+ function gregdate($input, $datetime)
362
  {
363
+ $bndate = bn_parsidate::getInstance();
364
+ $bndate = $bndate->gregurian_date($input, $datetime);
365
+ return $bndate;
366
  }
includes/plugins/edd.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * Makes EDD compatible with WP-Parsidate plugin
4
  *
@@ -6,80 +7,84 @@
6
  * @subpackage Plugins/EDD
7
  * @author Ehsaan
8
  */
 
 
 
9
 
10
- class WPP_EDD {
11
- public static $instance = null;
12
-
13
- /**
14
- * Returns an instance of class
15
- *
16
- * @return WPP_WooCommerce
17
- */
18
- public static function getInstance() {
19
- if ( self::$instance == null )
20
- self::$instance = new WPP_EDD();
21
 
22
- return self::$instance;
23
- }
 
24
 
25
- /**
26
- * Hooks required tags
27
- */
28
- private function __construct() {
29
- global $wpp_settings;
30
- add_filter( 'wpp_plugins_compability_settings', array( $this, 'add_settings' ) );
31
 
32
- if ( isset( $wpp_settings['edd_prices'] ) && $wpp_settings['edd_prices'] != 'disable' ) {
33
- add_filter( 'edd_rial_currency_filter_after', 'per_number', 10, 2 );
34
- }
 
 
 
 
 
 
35
 
36
- if ( isset( $wpp_settings['edd_rial_fix'] ) && $wpp_settings['edd_rial_fix'] != 'disable' ) {
37
- add_filter( 'edd_rial_currency_filter_after', array( $this, 'rial_fix' ), 10, 2 );
38
- }
39
- }
40
 
41
- /**
42
- * RIAL fix for EDD
43
- */
44
- public function rial_fix( $price, $did ) {
45
- return str_replace( 'RIAL', 'ریال', $price );
46
- }
 
47
 
48
- /**
49
- * Adds settings for toggle fixing
50
- *
51
- * @param array $old_settings Old settings
52
- * @return array New settings
53
- */
54
- public function add_settings( $old_settings ) {
55
- $options = array(
56
- 'enable' => __( 'Enable', 'wp-parsidate' ),
57
- 'disable' => __( 'Disable', 'wp-parsidate' )
58
- );
59
- $settings = array(
60
- 'edd' => array(
61
- 'id' => 'edd',
62
- 'name' => __( 'Easy Digital Downloads', 'wp-parsidate' ),
63
- 'type' => 'header'
64
- ),
65
- 'edd_prices' => array(
66
- 'id' => 'edd_prices',
67
- 'name' => __( 'Fix prices', 'wp-parsidate' ),
68
- 'type' => 'radio',
69
- 'options' => $options,
70
- 'std' => 'disable'
71
- ),
72
- 'edd_rial_fix' => array(
73
- 'id' => 'edd_rial_fix',
74
- 'name' => __( 'Replace ریال with RIAL', 'wp-parsidate' ),
75
- 'type' => 'radio',
76
- 'options' => $options,
77
- 'std' => 'disable'
78
- )
79
- );
 
80
 
81
- return array_merge( $old_settings, $settings );
82
- }
83
  }
84
 
85
  return WPP_EDD::getInstance();
1
  <?php
2
+
3
  /**
4
  * Makes EDD compatible with WP-Parsidate plugin
5
  *
7
  * @subpackage Plugins/EDD
8
  * @author Ehsaan
9
  */
10
+ class WPP_EDD
11
+ {
12
+ public static $instance = null;
13
 
14
+ /**
15
+ * Hooks required tags
16
+ */
17
+ private function __construct()
18
+ {
19
+ global $wpp_settings;
20
+ add_filter('wpp_plugins_compability_settings', array($this, 'add_settings'));
 
 
 
 
21
 
22
+ if (isset($wpp_settings['edd_prices']) && $wpp_settings['edd_prices'] != 'disable') {
23
+ add_filter('edd_rial_currency_filter_after', 'per_number', 10, 2);
24
+ }
25
 
26
+ if (isset($wpp_settings['edd_rial_fix']) && $wpp_settings['edd_rial_fix'] != 'disable') {
27
+ add_filter('edd_rial_currency_filter_after', array($this, 'rial_fix'), 10, 2);
28
+ }
29
+ }
 
 
30
 
31
+ /**
32
+ * Returns an instance of class
33
+ *
34
+ * @return WPP_WooCommerce
35
+ */
36
+ public static function getInstance()
37
+ {
38
+ if (self::$instance == null)
39
+ self::$instance = new WPP_EDD();
40
 
41
+ return self::$instance;
42
+ }
 
 
43
 
44
+ /**
45
+ * RIAL fix for EDD
46
+ */
47
+ public function rial_fix($price, $did)
48
+ {
49
+ return str_replace('RIAL', 'ریال', $price);
50
+ }
51
 
52
+ /**
53
+ * Adds settings for toggle fixing
54
+ *
55
+ * @param array $old_settings Old settings
56
+ * @return array New settings
57
+ */
58
+ public function add_settings($old_settings)
59
+ {
60
+ $options = array(
61
+ 'enable' => __('Enable', 'wp-parsidate'),
62
+ 'disable' => __('Disable', 'wp-parsidate')
63
+ );
64
+ $settings = array(
65
+ 'edd' => array(
66
+ 'id' => 'edd',
67
+ 'name' => __('Easy Digital Downloads', 'wp-parsidate'),
68
+ 'type' => 'header'
69
+ ),
70
+ 'edd_prices' => array(
71
+ 'id' => 'edd_prices',
72
+ 'name' => __('Fix prices', 'wp-parsidate'),
73
+ 'type' => 'radio',
74
+ 'options' => $options,
75
+ 'std' => 'disable'
76
+ ),
77
+ 'edd_rial_fix' => array(
78
+ 'id' => 'edd_rial_fix',
79
+ 'name' => __('Replace ریال with RIAL', 'wp-parsidate'),
80
+ 'type' => 'radio',
81
+ 'options' => $options,
82
+ 'std' => 'disable'
83
+ )
84
+ );
85
 
86
+ return array_merge($old_settings, $settings);
87
+ }
88
  }
89
 
90
  return WPP_EDD::getInstance();
includes/plugins/woocommerce.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * Makes WooCommerce compatible with WP-Parsidate plugin
4
  *
@@ -7,63 +8,66 @@
7
  * @author Ehsaan
8
  * @author Farhan Nisi
9
  */
 
 
 
10
 
11
- class WPP_WooCommerce {
12
- public static $instance = null;
13
-
14
- /**
15
- * Returns an instance of class
16
- *
17
- * @return WPP_WooCommerce
18
- */
19
- public static function getInstance() {
20
- if ( self::$instance == null )
21
- self::$instance = new WPP_WooCommerce();
22
 
23
- return self::$instance;
24
- }
 
 
 
25
 
26
- /**
27
- * Hooks required tags
28
- */
29
- private function __construct() {
30
- global $wpp_settings;
31
- add_filter( 'wpp_plugins_compability_settings', array( $this, 'add_settings' ) );
 
 
 
32
 
33
- if ( isset( $wpp_settings['woo_per_price'] ) && $wpp_settings['woo_per_price'] != 'disable' ) {
34
- add_filter( 'woocommerce_sale_price_html', 'per_number' );
35
- add_filter( 'woocommerce_price_html', 'per_number' );
36
- }
37
- }
38
 
39
- /**
40
- * Adds settings for toggle fixing
41
- *
42
- * @param array $old_settings Old settings
43
- * @return array New settings
44
- */
45
- public function add_settings( $old_settings ) {
46
- $options = array(
47
- 'enable' => __( 'Enable', 'wp-parsidate' ),
48
- 'disable' => __( 'Disable', 'wp-parsidate' )
49
- );
50
- $settings = array(
51
- 'woocommerce' => array(
52
- 'id' => 'woocommerce',
53
- 'name' => __( 'WooCommerce', 'wp-parsidate' ),
54
- 'type' => 'header'
55
- ),
56
- 'woo_per_price' => array(
57
- 'id' => 'woo_per_price',
58
- 'name' => __( 'Fix prices', 'wp-parsidate' ),
59
- 'type' => 'radio',
60
- 'options' => $options,
61
- 'std' => 'disable'
62
- )
63
- );
 
64
 
65
- return array_merge( $old_settings, $settings );
66
- }
67
  }
68
 
69
  return WPP_WooCommerce::getInstance();
1
  <?php
2
+
3
  /**
4
  * Makes WooCommerce compatible with WP-Parsidate plugin
5
  *
8
  * @author Ehsaan
9
  * @author Farhan Nisi
10
  */
11
+ class WPP_WooCommerce
12
+ {
13
+ public static $instance = null;
14
 
15
+ /**
16
+ * Hooks required tags
17
+ */
18
+ private function __construct()
19
+ {
20
+ global $wpp_settings;
21
+ add_filter('wpp_plugins_compability_settings', array($this, 'add_settings'));
 
 
 
 
22
 
23
+ if (isset($wpp_settings['woo_per_price']) && $wpp_settings['woo_per_price'] != 'disable') {
24
+ add_filter('woocommerce_sale_price_html', 'per_number');
25
+ add_filter('woocommerce_price_html', 'per_number');
26
+ }
27
+ }
28
 
29
+ /**
30
+ * Returns an instance of class
31
+ *
32
+ * @return WPP_WooCommerce
33
+ */
34
+ public static function getInstance()
35
+ {
36
+ if (self::$instance == null)
37
+ self::$instance = new WPP_WooCommerce();
38
 
39
+ return self::$instance;
40
+ }
 
 
 
41
 
42
+ /**
43
+ * Adds settings for toggle fixing
44
+ *
45
+ * @param array $old_settings Old settings
46
+ * @return array New settings
47
+ */
48
+ public function add_settings($old_settings)
49
+ {
50
+ $options = array(
51
+ 'enable' => __('Enable', 'wp-parsidate'),
52
+ 'disable' => __('Disable', 'wp-parsidate')
53
+ );
54
+ $settings = array(
55
+ 'woocommerce' => array(
56
+ 'id' => 'woocommerce',
57
+ 'name' => __('WooCommerce', 'wp-parsidate'),
58
+ 'type' => 'header'
59
+ ),
60
+ 'woo_per_price' => array(
61
+ 'id' => 'woo_per_price',
62
+ 'name' => __('Fix prices', 'wp-parsidate'),
63
+ 'type' => 'radio',
64
+ 'options' => $options,
65
+ 'std' => 'disable'
66
+ )
67
+ );
68
 
69
+ return array_merge($old_settings, $settings);
70
+ }
71
  }
72
 
73
  return WPP_WooCommerce::getInstance();
includes/settings.php CHANGED
@@ -8,29 +8,30 @@
8
  * @package WP-Parsidate
9
  * @subpackage Admin/Settings
10
  */
11
- if ( ! defined( 'ABSPATH' ) ) exit; // No direct access allowed ;)
12
 
13
- add_action( 'admin_menu', 'wpp_add_settings_menu', 11 );
14
 
15
  /**
16
  * Add WP-Parsidate admin page settings
17
  * */
18
- function wpp_add_settings_menu() {
 
19
  global $wpp_settings;
20
 
21
- if ( $wpp_settings[ 'submenu_move' ] != 'disable' ) {
22
  add_submenu_page(
23
  'options-general.php',
24
- __( 'Parsi Settings', 'wp-parsidate' ),
25
- __( 'Parsi Settings', 'wp-parsidate' ),
26
  'manage_options',
27
  'wp-parsi-settings',
28
  'wpp_render_settings'
29
  );
30
  } else {
31
  add_menu_page(
32
- __('Parsi Settings','wp-parsidate') ,
33
- __('Parsi Settings','wp-parsidate') ,
34
  'manage_options',
35
  'wp-parsi-settings',
36
  'wpp_render_settings',
@@ -45,30 +46,31 @@ function wpp_add_settings_menu() {
45
  * @since 2.0
46
  * @return array Parsi Settings
47
  */
48
- function wp_parsi_get_settings() {
49
- $settings = get_option( 'wpp_settings' );
50
- if ( empty( $settings ) ) {
51
- update_option( 'wpp_settings', array(
52
- 'admin_lang' => 'enable',
53
- 'user_lang' => 'enable',
54
- 'submenu_move' => 'disable',
55
- 'persian_date' => 'disable',
56
- 'droidsans_editor' => 'enable',
57
- 'droidsans_admin' => 'enable',
58
- 'conv_title' => 'disable',
59
- 'conv_contents' => 'disable',
60
- 'conv_excerpt' => 'disable',
61
- 'conv_comments' => 'disable',
62
- 'conv_comment_count'=> 'disable',
63
- 'conv_dates' => 'disable',
64
- 'conv_cats' => 'disable',
65
- 'conv_arabic' => 'disable',
66
- 'conv_permalinks' => 'disable',
67
- 'news_source' => 'parsi'
68
- ) );
 
69
  }
70
 
71
- return apply_filters( 'wpp_get_settings', $settings );
72
  }
73
 
74
  /**
@@ -77,11 +79,12 @@ function wp_parsi_get_settings() {
77
  * @since 2.0
78
  * @return void
79
  */
80
- function wpp_register_settings() {
81
- if ( false == get_option( 'wpp_settings' ) )
82
- add_option( 'wpp_settings' );
 
83
 
84
- foreach( wpp_get_registered_settings() as $tab => $settings ) {
85
  add_settings_section(
86
  'wpp_settings_' . $tab,
87
  __return_null(),
@@ -89,31 +92,32 @@ function wpp_register_settings() {
89
  'wpp_settings_' . $tab
90
  );
91
 
92
- foreach( $settings as $option ) {
93
- $name = isset( $option['name'] ) ? $option['name'] : '';
94
 
95
  add_settings_field(
96
  'wpp_settings[' . $option['id'] . ']',
97
  $name,
98
- function_exists( 'wpp_' . $option['type'] . '_callback' ) ? 'wpp_' . $option['type'] . '_callback' : 'wpp_missing_callback',
99
  'wpp_settings_' . $tab,
100
  'wpp_settings_' . $tab,
101
  array(
102
- 'id' => isset( $option['id'] ) ? $option['id'] : null,
103
- 'desc' => ! empty( $option['desc'] ) ? $option['desc'] : '',
104
- 'name' => isset( $option['name'] ) ? $option['name'] : null,
105
  'section' => $tab,
106
- 'size' => isset( $option['size'] ) ? $option['size'] : null,
107
- 'options' => isset( $option['options'] ) ? $option['options'] : '',
108
- 'std' => isset( $option['std'] ) ? $option['std'] : ''
109
  )
110
  );
111
 
112
- register_setting( 'wpp_settings', 'wpp_settings', 'wpp_settings_sanitize' );
113
  }
114
  }
115
  }
116
- add_action( 'admin_init', 'wpp_register_settings' );
 
117
 
118
  /**
119
  * Gets settings tabs
@@ -121,13 +125,14 @@ add_action( 'admin_init', 'wpp_register_settings' );
121
  * @since 2.0
122
  * @return array Tabs list
123
  */
124
- function wpp_get_tabs() {
125
- $tabs = array(
126
- 'core' => sprintf( __( '%s Core', 'wp-parsidate' ), '<span class="dashicons dashicons-admin-site"></span>' ),
127
- 'conv' => sprintf( __( '%s Converts', 'wp-parsidate' ), '<span class="dashicons dashicons-admin-settings"></span>' ),
128
- 'plugins' => sprintf( __( '%s Plugins compability', 'wp-parsidate' ), '<span class="dashicons dashicons-admin-plugins"></span>' )
129
- );
130
- return $tabs;
 
131
  }
132
 
133
  /**
@@ -137,57 +142,58 @@ function wpp_get_tabs() {
137
  * @param array $input Settings input
138
  * @return array New settings
139
  */
140
- function wpp_settings_sanitize( $input = array() ) {
 
141
 
142
  global $wpp_settings;
143
 
144
- if( empty( $_POST['_wp_http_referer'] ) )
145
  return $input;
146
 
147
- parse_str( $_POST['_wp_http_referer'], $referrer );
148
 
149
- $settings = wpp_get_registered_settings();
150
- $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'core';
151
 
152
- $input = $input ? $input : array();
153
- $input = apply_filters( 'wpp_settings_' . $tab . '_sanitize', $input );
154
 
155
  // Loop through each setting being saved and pass it through a sanitization filter
156
- foreach( $input as $key => $value ) {
157
 
158
  // Get the setting type (checkbox, select, etc)
159
- $type = isset( $settings[ $tab ][ $key ][ 'type' ] ) ? $settings[ $tab ][ $key ][ 'type' ] : false;
160
 
161
- if( $type ) {
162
  // Field type specific filter
163
- $input[ $key ] = apply_filters( 'wpp_settings_sanitize_' . $type, $value, $key );
164
  }
165
 
166
  // General filter
167
- $input[ $key ] = apply_filters( 'wpp_settings_sanitize', $value, $key );
168
  }
169
 
170
 
171
  // Loop through the whitelist and unset any that are empty for the tab being saved
172
- if( ! empty( $settings[ $tab ] ) ) {
173
- foreach( $settings[ $tab ] as $key => $value ) {
174
 
175
  // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work
176
- if( is_numeric( $key ) ) {
177
  $key = $value['id'];
178
  }
179
 
180
- if( empty( $input[ $key ] ) ) {
181
- unset( $wpp_settings[ $key ] );
182
  }
183
 
184
  }
185
  }
186
 
187
  // Merge our new settings with the existing
188
- $output = array_merge( $wpp_settings, $input );
189
 
190
- add_settings_error( 'wpp-notices', '', __( 'Settings updated', 'wp-parsidate' ), 'updated' );
191
 
192
  return $output;
193
 
@@ -199,194 +205,199 @@ function wpp_settings_sanitize( $input = array() ) {
199
  * @since 2.0
200
  * @return array Fields
201
  */
202
- function wpp_get_registered_settings() {
 
203
  $options = array(
204
- 'enable' => __( 'Enable', 'wp-parsidate' ),
205
- 'disable' => __( 'Disable', 'wp-parsidate' )
206
  );
207
- $settings = apply_filters( 'wpp_registered_settings', array(
208
- 'core' => apply_filters( 'wpp_core_settings', array(
209
- 'admin_lang' => array(
210
- 'id' => 'admin_lang',
211
- 'name' => __( 'Change Locale in admin', 'wp-parsidate' ),
212
- 'type' => 'radio',
213
- 'options' => $options,
214
- 'std' => 'enable',
215
- 'desc' => __( 'This option change WordPress locale in Admin', 'wp-parsidate' )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
  ),
217
- 'user_lang' => array(
218
- 'id' => 'user_lang',
219
- 'name' => __( 'Change Locale in theme', 'wp-parsidate' ),
220
- 'type' => 'radio',
221
- 'options' => $options,
222
- 'std' => 'enable',
223
- 'desc' => __( 'This option change WordPress locale in theme', 'wp-parsidate' )
224
  ),
225
- 'persian_date' => array(
226
- 'id' => 'persian_date',
227
- 'name' => __( 'Shamsi date', 'wp-parsidate' ),
228
- 'type' => 'radio',
229
- 'options' => $options,
230
- 'std' => 'disable',
231
- 'desc' => __( 'By enabling this, Dates will convert to Shamsi (Jalali) dates', 'wp-parsidate' )
232
- ),
233
- 'submenu_move' => array(
234
- 'id' => 'submenu_move',
235
- 'name' => __( 'Move page to submenu?', 'wp-parsidate' ),
236
- 'type' => 'radio',
237
- 'options' => $options,
238
- 'std' => 'disable',
239
- 'desc' => __( 'With enabling this option, page item will be moved to Settings menu as submenu.', 'wp-parsidate' )
240
  ),
241
- ) ),
242
- 'conv' => apply_filters( 'wpp_conv_settings', array(
243
- 'conv_nums' => array(
244
- 'id' => 'conv_nums',
245
- 'name' => __( 'Persian digits', 'wp-parsidate' ),
246
- 'type' => 'header'
247
- ),
248
- 'conv_page_title' => array(
249
- 'id' => 'conv_page_title',
250
- 'name' => __( 'Page title', 'wp-parsidate' ),
251
- 'type' => 'radio',
252
- 'options' => $options,
253
- 'std' => 'disable'
254
- ),
255
- 'conv_title' => array(
256
- 'id' => 'conv_title',
257
- 'name' => __( 'Post title', 'wp-parsidate' ),
258
- 'type' => 'radio',
259
- 'options' => $options,
260
- 'std' => 'disable'
261
- ),
262
- 'conv_contents' => array(
263
- 'id' => 'conv_contents',
264
- 'name' => __( 'Post content', 'wp-parsidate' ),
265
- 'type' => 'radio',
266
- 'options' => $options,
267
- 'std' => 'enable'
268
- ),
269
- 'conv_excerpt' => array(
270
- 'id' => 'conv_excerpt',
271
- 'name' => __( 'Post excerpt', 'wp-parsidate' ),
272
- 'type' => 'radio',
273
- 'options' => $options,
274
- 'std' => 'disable'
275
- ),
276
- 'conv_comments' => array(
277
- 'id' => 'conv_comments',
278
- 'name' => __( 'Comments text', 'wp-parsidate' ),
279
- 'type' => 'radio',
280
- 'options' => $options,
281
- 'std' => 'disable'
282
- ),
283
- 'conv_comment_count'=> array(
284
- 'id' => 'conv_comment_count',
285
- 'name' => __( 'Comments count', 'wp-parsidate' ),
286
- 'type' => 'radio',
287
- 'options' => $options,
288
- 'std' => 'disable'
289
- ),
290
- 'conv_dates' => array(
291
- 'id' => 'conv_dates',
292
- 'name' => __( 'Dates', 'wp-parsidate' ),
293
- 'type' => 'radio',
294
- 'options' => $options,
295
- 'std' => 'disable'
296
- ),
297
- 'conv_cats' => array(
298
- 'id' => 'conv_cats',
299
- 'name' => __( 'Categories', 'wp-parsidate' ),
300
- 'type' => 'radio',
301
- 'options' => $options,
302
- 'std' => 'disable'
303
- ),
304
- 'sep' => array(
305
- 'id' => 'sep',
306
- 'type' => 'header'
307
  ),
308
- 'conv_arabic' => array(
309
- 'id' => 'conv_arabic',
310
- 'name' => __( 'Fix arabic characters', 'wp-parsidate' ),
311
- 'type' => 'radio',
312
- 'options' => $options,
313
- 'std' => 'disable',
314
- 'desc' => __( 'Fixes arabic characters caused by wrong keyboard layouts', 'wp-parsidate' )
315
  ),
316
- 'conv_permalinks' => array(
317
- 'id' => 'conv_permalinks',
318
- 'name' => __( 'Fix permalinks dates', 'wp-parsidate' ),
319
- 'type' => 'radio',
320
- 'options' => $options,
321
- 'std' => 'disable',
322
- 'desc' => __( 'By enabling this, dates in permalinks converted to Shamsi (Jalali) date', 'wp-parsidate' )
323
  ),
324
- 'sep_font' => array(
325
- 'id' => 'sep_font',
326
- 'type' => 'header'
 
 
 
327
  ),
328
- 'droidsans_admin' => array(
329
- 'id' => 'droidsans_admin',
330
- 'name' => __( 'Use Droid Sans font for admin side', 'wp-parsidate' ),
331
- 'type' => 'radio',
332
- 'options' => $options,
333
- 'std' => 'enable',
334
- 'desc' => __( 'Droid Sans Naskh and Roboto font families will be activated in admin side, if this is enabled', 'wp-parsidate' )
335
  ),
336
- 'droidsans_editor' => array(
337
- 'id' => 'droidsans_editor',
338
- 'name' => __( 'Use Droid Sans font for editors', 'wp-parsidate' ),
339
- 'type' => 'radio',
340
- 'options' => $options,
341
- 'std' => 'enable',
342
- 'desc' => __( 'Droid Sans Naskh and Roboto font families will be activated in all rich editors in back end.', 'wp-parsidate' )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
343
  )
344
- ) ),
345
- 'plugins' => apply_filters( 'wpp_plugins_compability_settings', array() )
346
- ) );
347
- return $settings;
348
  }
349
 
350
  /* Form Callbacks Made by EDD Development Team */
351
- function wpp_header_callback( $args ) {
 
352
  echo '<hr/>';
353
  }
354
 
355
- function wpp_checkbox_callback( $args ) {
 
356
  global $wpp_settings;
357
 
358
  $checked = isset($wpp_settings[$args['id']]) ? checked(1, $wpp_settings[$args['id']], false) : '';
359
  $html = '<input type="checkbox" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="1" ' . $checked . '/>';
360
- $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
361
 
362
  echo $html;
363
  }
364
 
365
- function wpp_multicheck_callback( $args ) {
366
- global $wpp_settings;
 
367
 
368
- $html = '';
369
- foreach( $args['options'] as $key => $value ) {
370
- $option_name = $args['id'] . '-' . $key;
371
- wpp_checkbox_callback( array(
372
- 'id' => $option_name,
373
- 'desc' => $value
374
- ) );
375
- echo '<br>';
376
- }
377
 
378
- echo $html;
379
  }
380
 
381
- function wpp_radio_callback( $args ) {
 
382
  global $wpp_settings;
383
 
384
- foreach ( $args['options'] as $key => $option ) :
385
  $checked = false;
386
 
387
- if ( isset( $wpp_settings[ $args['id'] ] ) && $wpp_settings[ $args['id'] ] == $key )
388
  $checked = true;
389
- elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpp_settings[ $args['id'] ] ) )
390
  $checked = true;
391
 
392
  echo '<input name="wpp_settings[' . $args['id'] . ']"" id="wpp_settings[' . $args['id'] . '][' . $key . ']" type="radio" value="' . $key . '" ' . checked(true, $checked, false) . '/>';
@@ -396,208 +407,219 @@ function wpp_radio_callback( $args ) {
396
  echo '<p class="description">' . $args['desc'] . '</p>';
397
  }
398
 
399
- function wpp_text_callback( $args ) {
 
400
  global $wpp_settings;
401
 
402
- if ( isset( $wpp_settings[ $args['id'] ] ) )
403
- $value = $wpp_settings[ $args['id'] ];
404
  else
405
- $value = isset( $args['std'] ) ? $args['std'] : '';
406
 
407
- $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
408
- $html = '<input type="text" class="' . $size . '-text" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
409
- $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
410
 
411
  echo $html;
412
  }
413
 
414
- function wpp_number_callback( $args ) {
 
415
  global $wpp_settings;
416
 
417
- if ( isset( $wpp_settings[ $args['id'] ] ) )
418
- $value = $wpp_settings[ $args['id'] ];
419
  else
420
- $value = isset( $args['std'] ) ? $args['std'] : '';
421
 
422
- $max = isset( $args['max'] ) ? $args['max'] : 999999;
423
- $min = isset( $args['min'] ) ? $args['min'] : 0;
424
- $step = isset( $args['step'] ) ? $args['step'] : 1;
425
 
426
- $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
427
- $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . $size . '-text" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
428
- $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
429
 
430
  echo $html;
431
  }
432
 
433
- function wpp_textarea_callback( $args ) {
 
434
  global $wpp_settings;
435
 
436
- if ( isset( $wpp_settings[ $args['id'] ] ) )
437
- $value = $wpp_settings[ $args['id'] ];
438
  else
439
- $value = isset( $args['std'] ) ? $args['std'] : '';
440
 
441
- $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
442
- $html = '<textarea class="large-text" cols="50" rows="5" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
443
- $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
444
 
445
  echo $html;
446
  }
447
 
448
- function wpp_password_callback( $args ) {
 
449
  global $wpp_settings;
450
 
451
- if ( isset( $wpp_settings[ $args['id'] ] ) )
452
- $value = $wpp_settings[ $args['id'] ];
453
  else
454
- $value = isset( $args['std'] ) ? $args['std'] : '';
455
 
456
- $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
457
- $html = '<input type="password" class="' . $size . '-text" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr( $value ) . '"/>';
458
- $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
459
 
460
  echo $html;
461
  }
462
 
463
- function wpp_missing_callback($args) {
 
464
  echo '&ndash;';
465
  return false;
466
  }
467
 
468
 
469
- function wpp_select_callback($args) {
 
470
  global $wpp_settings;
471
 
472
- if ( isset( $wpp_settings[ $args['id'] ] ) )
473
- $value = $wpp_settings[ $args['id'] ];
474
  else
475
- $value = isset( $args['std'] ) ? $args['std'] : '';
476
 
477
  $html = '<select id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']"/>';
478
 
479
- foreach ( $args['options'] as $option => $name ) :
480
- $selected = selected( $option, $value, false );
481
  $html .= '<option value="' . $option . '" ' . $selected . '>' . $name . '</option>';
482
  endforeach;
483
 
484
  $html .= '</select>';
485
- $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
486
 
487
  echo $html;
488
  }
489
 
490
- function wpp_color_select_callback( $args ) {
 
491
  global $wpp_settings;
492
 
493
- if ( isset( $wpp_settings[ $args['id'] ] ) )
494
- $value = $wpp_settings[ $args['id'] ];
495
  else
496
- $value = isset( $args['std'] ) ? $args['std'] : '';
497
 
498
  $html = '<select id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']"/>';
499
 
500
- foreach ( $args['options'] as $option => $color ) :
501
- $selected = selected( $option, $value, false );
502
  $html .= '<option value="' . $option . '" ' . $selected . '>' . $color['label'] . '</option>';
503
  endforeach;
504
 
505
  $html .= '</select>';
506
- $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
507
 
508
  echo $html;
509
  }
510
 
511
- function wpp_rich_editor_callback( $args ) {
 
512
  global $wpp_settings, $wp_version;
513
 
514
- if ( isset( $wpp_settings[ $args['id'] ] ) )
515
- $value = $wpp_settings[ $args['id'] ];
516
  else
517
- $value = isset( $args['std'] ) ? $args['std'] : '';
518
 
519
- if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
520
- $html = wp_editor( stripslashes( $value ), 'wpp_settings[' . $args['id'] . ']', array( 'textarea_name' => 'wpp_settings[' . $args['id'] . ']' ) );
521
  } else {
522
- $html = '<textarea class="large-text" rows="10" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
523
  }
524
 
525
- $html .= '<br/><label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
526
 
527
  echo $html;
528
  }
529
 
530
- function wpp_upload_callback( $args ) {
 
531
  global $wpp_settings;
532
 
533
- if ( isset( $wpp_settings[ $args['id'] ] ) )
534
  $value = $wpp_settings[$args['id']];
535
  else
536
  $value = isset($args['std']) ? $args['std'] : '';
537
 
538
- $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
539
- $html = '<input type="text" class="' . $size . '-text wpp_upload_field" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
540
- $html .= '<span>&nbsp;<input type="button" class="wpp_settings_upload_button button-secondary" value="' . __( 'Upload File', 'wpp' ) . '"/></span>';
541
- $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
542
 
543
  echo $html;
544
  }
545
 
546
- function wpp_color_callback( $args ) {
 
547
  global $wpp_settings;
548
 
549
- if ( isset( $wpp_settings[ $args['id'] ] ) )
550
- $value = $wpp_settings[ $args['id'] ];
551
  else
552
- $value = isset( $args['std'] ) ? $args['std'] : '';
553
 
554
- $default = isset( $args['std'] ) ? $args['std'] : '';
555
 
556
- $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
557
- $html = '<input type="text" class="wpp-color-picker" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />';
558
- $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
559
 
560
  echo $html;
561
  }
562
 
563
- function wpp_render_settings() {
 
564
  global $wpp_settings;
565
- $active_tab = isset( $_GET[ 'tab' ] ) && array_key_exists( $_GET['tab'], wpp_get_tabs() ) ? $_GET[ 'tab' ] : 'core';
566
 
567
  ob_start();
568
  ?>
569
- <div class="wrap wpp-settings-wrap">
570
- <h2><?php _e('Parsi Settings','wp-parsidate') ?></h2>
571
- <h2 class="nav-tab-wrapper">
572
  <?php
573
- foreach( wpp_get_tabs() as $tab_id => $tab_name ) {
574
 
575
- $tab_url = add_query_arg( array(
576
  'settings-updated' => false,
577
  'tab' => $tab_id
578
- ) );
579
 
580
  $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
581
 
582
- echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">';
583
- echo $tab_name;
584
  echo '</a>';
585
  }
586
  ?>
587
- </h2>
588
- <?php echo settings_errors( 'wpp-notices' ); ?>
589
- <div id="tab_container">
590
- <form method="post" action="options.php">
591
- <table class="form-table">
592
- <?php
593
- settings_fields( 'wpp_settings' );
594
- do_settings_fields( 'wpp_settings_' . $active_tab, 'wpp_settings_' . $active_tab );
595
- ?>
596
- </table>
597
  <?php submit_button(); ?>
598
- </form>
599
- </div><!-- #tab_container-->
600
- </div><!-- .wrap -->
601
  <?php
602
  echo ob_get_clean();
603
  }
8
  * @package WP-Parsidate
9
  * @subpackage Admin/Settings
10
  */
11
+ if (!defined('ABSPATH')) exit; // No direct access allowed ;)
12
 
13
+ add_action('admin_menu', 'wpp_add_settings_menu', 11);
14
 
15
  /**
16
  * Add WP-Parsidate admin page settings
17
  * */
18
+ function wpp_add_settings_menu()
19
+ {
20
  global $wpp_settings;
21
 
22
+ if ($wpp_settings['submenu_move'] != 'disable') {
23
  add_submenu_page(
24
  'options-general.php',
25
+ __('Parsi Settings', 'wp-parsidate'),
26
+ __('Parsi Settings', 'wp-parsidate'),
27
  'manage_options',
28
  'wp-parsi-settings',
29
  'wpp_render_settings'
30
  );
31
  } else {
32
  add_menu_page(
33
+ __('Parsi Settings', 'wp-parsidate'),
34
+ __('Parsi Settings', 'wp-parsidate'),
35
  'manage_options',
36
  'wp-parsi-settings',
37
  'wpp_render_settings',
46
  * @since 2.0
47
  * @return array Parsi Settings
48
  */
49
+ function wp_parsi_get_settings()
50
+ {
51
+ $settings = get_option('wpp_settings');
52
+ if (empty($settings)) {
53
+ update_option('wpp_settings', array(
54
+ 'admin_lang' => 'enable',
55
+ 'user_lang' => 'enable',
56
+ 'submenu_move' => 'disable',
57
+ 'persian_date' => 'disable',
58
+ 'droidsans_editor' => 'enable',
59
+ 'droidsans_admin' => 'enable',
60
+ 'conv_title' => 'disable',
61
+ 'conv_contents' => 'disable',
62
+ 'conv_excerpt' => 'disable',
63
+ 'conv_comments' => 'disable',
64
+ 'conv_comment_count' => 'disable',
65
+ 'conv_dates' => 'disable',
66
+ 'conv_cats' => 'disable',
67
+ 'conv_arabic' => 'disable',
68
+ 'conv_permalinks' => 'disable',
69
+ 'news_source' => 'parsi'
70
+ ));
71
  }
72
 
73
+ return apply_filters('wpp_get_settings', $settings);
74
  }
75
 
76
  /**
79
  * @since 2.0
80
  * @return void
81
  */
82
+ function wpp_register_settings()
83
+ {
84
+ if (false == get_option('wpp_settings'))
85
+ add_option('wpp_settings');
86
 
87
+ foreach (wpp_get_registered_settings() as $tab => $settings) {
88
  add_settings_section(
89
  'wpp_settings_' . $tab,
90
  __return_null(),
92
  'wpp_settings_' . $tab
93
  );
94
 
95
+ foreach ($settings as $option) {
96
+ $name = isset($option['name']) ? $option['name'] : '';
97
 
98
  add_settings_field(
99
  'wpp_settings[' . $option['id'] . ']',
100
  $name,
101
+ function_exists('wpp_' . $option['type'] . '_callback') ? 'wpp_' . $option['type'] . '_callback' : 'wpp_missing_callback',
102
  'wpp_settings_' . $tab,
103
  'wpp_settings_' . $tab,
104
  array(
105
+ 'id' => isset($option['id']) ? $option['id'] : null,
106
+ 'desc' => !empty($option['desc']) ? $option['desc'] : '',
107
+ 'name' => isset($option['name']) ? $option['name'] : null,
108
  'section' => $tab,
109
+ 'size' => isset($option['size']) ? $option['size'] : null,
110
+ 'options' => isset($option['options']) ? $option['options'] : '',
111
+ 'std' => isset($option['std']) ? $option['std'] : ''
112
  )
113
  );
114
 
115
+ register_setting('wpp_settings', 'wpp_settings', 'wpp_settings_sanitize');
116
  }
117
  }
118
  }
119
+
120
+ add_action('admin_init', 'wpp_register_settings');
121
 
122
  /**
123
  * Gets settings tabs
125
  * @since 2.0
126
  * @return array Tabs list
127
  */
128
+ function wpp_get_tabs()
129
+ {
130
+ $tabs = array(
131
+ 'core' => sprintf(__('%s Core', 'wp-parsidate'), '<span class="dashicons dashicons-admin-site"></span>'),
132
+ 'conv' => sprintf(__('%s Converts', 'wp-parsidate'), '<span class="dashicons dashicons-admin-settings"></span>'),
133
+ 'plugins' => sprintf(__('%s Plugins compability', 'wp-parsidate'), '<span class="dashicons dashicons-admin-plugins"></span>')
134
+ );
135
+ return $tabs;
136
  }
137
 
138
  /**
142
  * @param array $input Settings input
143
  * @return array New settings
144
  */
145
+ function wpp_settings_sanitize($input = array())
146
+ {
147
 
148
  global $wpp_settings;
149
 
150
+ if (empty($_POST['_wp_http_referer']))
151
  return $input;
152
 
153
+ parse_str($_POST['_wp_http_referer'], $referrer);
154
 
155
+ $settings = wpp_get_registered_settings();
156
+ $tab = isset($referrer['tab']) ? $referrer['tab'] : 'core';
157
 
158
+ $input = $input ? $input : array();
159
+ $input = apply_filters('wpp_settings_' . $tab . '_sanitize', $input);
160
 
161
  // Loop through each setting being saved and pass it through a sanitization filter
162
+ foreach ($input as $key => $value) {
163
 
164
  // Get the setting type (checkbox, select, etc)
165
+ $type = isset($settings[$tab][$key]['type']) ? $settings[$tab][$key]['type'] : false;
166
 
167
+ if ($type) {
168
  // Field type specific filter
169
+ $input[$key] = apply_filters('wpp_settings_sanitize_' . $type, $value, $key);
170
  }
171
 
172
  // General filter
173
+ $input[$key] = apply_filters('wpp_settings_sanitize', $value, $key);
174
  }
175
 
176
 
177
  // Loop through the whitelist and unset any that are empty for the tab being saved
178
+ if (!empty($settings[$tab])) {
179
+ foreach ($settings[$tab] as $key => $value) {
180
 
181
  // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work
182
+ if (is_numeric($key)) {
183
  $key = $value['id'];
184
  }
185
 
186
+ if (empty($input[$key])) {
187
+ unset($wpp_settings[$key]);
188
  }
189
 
190
  }
191
  }
192
 
193
  // Merge our new settings with the existing
194
+ $output = array_merge($wpp_settings, $input);
195
 
196
+ add_settings_error('wpp-notices', '', __('Settings updated', 'wp-parsidate'), 'updated');
197
 
198
  return $output;
199
 
205
  * @since 2.0
206
  * @return array Fields
207
  */
208
+ function wpp_get_registered_settings()
209
+ {
210
  $options = array(
211
+ 'enable' => __('Enable', 'wp-parsidate'),
212
+ 'disable' => __('Disable', 'wp-parsidate')
213
  );
214
+ $settings = apply_filters('wpp_registered_settings', array(
215
+ 'core' => apply_filters('wpp_core_settings', array(
216
+ 'admin_lang' => array(
217
+ 'id' => 'admin_lang',
218
+ 'name' => __('Change Locale in admin', 'wp-parsidate'),
219
+ 'type' => 'radio',
220
+ 'options' => $options,
221
+ 'std' => 'enable',
222
+ 'desc' => __('This option change WordPress locale in Admin', 'wp-parsidate')
223
+ ),
224
+ 'user_lang' => array(
225
+ 'id' => 'user_lang',
226
+ 'name' => __('Change Locale in theme', 'wp-parsidate'),
227
+ 'type' => 'radio',
228
+ 'options' => $options,
229
+ 'std' => 'enable',
230
+ 'desc' => __('This option change WordPress locale in theme', 'wp-parsidate')
231
+ ),
232
+ 'persian_date' => array(
233
+ 'id' => 'persian_date',
234
+ 'name' => __('Shamsi date', 'wp-parsidate'),
235
+ 'type' => 'radio',
236
+ 'options' => $options,
237
+ 'std' => 'disable',
238
+ 'desc' => __('By enabling this, Dates will convert to Shamsi (Jalali) dates', 'wp-parsidate')
239
+ ),
240
+ 'submenu_move' => array(
241
+ 'id' => 'submenu_move',
242
+ 'name' => __('Move page to submenu?', 'wp-parsidate'),
243
+ 'type' => 'radio',
244
+ 'options' => $options,
245
+ 'std' => 'disable',
246
+ 'desc' => __('With enabling this option, page item will be moved to Settings menu as submenu.', 'wp-parsidate')
247
+ ),
248
+ )),
249
+ 'conv' => apply_filters('wpp_conv_settings', array(
250
+ 'conv_nums' => array(
251
+ 'id' => 'conv_nums',
252
+ 'name' => __('Persian digits', 'wp-parsidate'),
253
+ 'type' => 'header'
254
+ ),
255
+ 'conv_page_title' => array(
256
+ 'id' => 'conv_page_title',
257
+ 'name' => __('Page title', 'wp-parsidate'),
258
+ 'type' => 'radio',
259
+ 'options' => $options,
260
+ 'std' => 'disable'
261
+ ),
262
+ 'conv_title' => array(
263
+ 'id' => 'conv_title',
264
+ 'name' => __('Post title', 'wp-parsidate'),
265
+ 'type' => 'radio',
266
+ 'options' => $options,
267
+ 'std' => 'disable'
268
  ),
269
+ 'conv_contents' => array(
270
+ 'id' => 'conv_contents',
271
+ 'name' => __('Post content', 'wp-parsidate'),
272
+ 'type' => 'radio',
273
+ 'options' => $options,
274
+ 'std' => 'enable'
 
275
  ),
276
+ 'conv_excerpt' => array(
277
+ 'id' => 'conv_excerpt',
278
+ 'name' => __('Post excerpt', 'wp-parsidate'),
279
+ 'type' => 'radio',
280
+ 'options' => $options,
281
+ 'std' => 'disable'
 
 
 
 
 
 
 
 
 
282
  ),
283
+ 'conv_comments' => array(
284
+ 'id' => 'conv_comments',
285
+ 'name' => __('Comments text', 'wp-parsidate'),
286
+ 'type' => 'radio',
287
+ 'options' => $options,
288
+ 'std' => 'disable'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
  ),
290
+ 'conv_comment_count' => array(
291
+ 'id' => 'conv_comment_count',
292
+ 'name' => __('Comments count', 'wp-parsidate'),
293
+ 'type' => 'radio',
294
+ 'options' => $options,
295
+ 'std' => 'disable'
 
296
  ),
297
+ 'conv_dates' => array(
298
+ 'id' => 'conv_dates',
299
+ 'name' => __('Dates', 'wp-parsidate'),
300
+ 'type' => 'radio',
301
+ 'options' => $options,
302
+ 'std' => 'disable'
 
303
  ),
304
+ 'conv_cats' => array(
305
+ 'id' => 'conv_cats',
306
+ 'name' => __('Categories', 'wp-parsidate'),
307
+ 'type' => 'radio',
308
+ 'options' => $options,
309
+ 'std' => 'disable'
310
  ),
311
+ 'sep' => array(
312
+ 'id' => 'sep',
313
+ 'type' => 'header'
 
 
 
 
314
  ),
315
+ 'conv_arabic' => array(
316
+ 'id' => 'conv_arabic',
317
+ 'name' => __('Fix arabic characters', 'wp-parsidate'),
318
+ 'type' => 'radio',
319
+ 'options' => $options,
320
+ 'std' => 'disable',
321
+ 'desc' => __('Fixes arabic characters caused by wrong keyboard layouts', 'wp-parsidate')
322
+ ),
323
+ 'conv_permalinks' => array(
324
+ 'id' => 'conv_permalinks',
325
+ 'name' => __('Fix permalinks dates', 'wp-parsidate'),
326
+ 'type' => 'radio',
327
+ 'options' => $options,
328
+ 'std' => 'disable',
329
+ 'desc' => __('By enabling this, dates in permalinks converted to Shamsi (Jalali) date', 'wp-parsidate')
330
+ ),
331
+ 'sep_font' => array(
332
+ 'id' => 'sep_font',
333
+ 'type' => 'header'
334
+ ),
335
+ 'droidsans_admin' => array(
336
+ 'id' => 'droidsans_admin',
337
+ 'name' => __('Use Droid Sans font for admin side', 'wp-parsidate'),
338
+ 'type' => 'radio',
339
+ 'options' => $options,
340
+ 'std' => 'enable',
341
+ 'desc' => __('Droid Sans Naskh and Roboto font families will be activated in admin side, if this is enabled', 'wp-parsidate')
342
+ ),
343
+ 'droidsans_editor' => array(
344
+ 'id' => 'droidsans_editor',
345
+ 'name' => __('Use Droid Sans font for editors', 'wp-parsidate'),
346
+ 'type' => 'radio',
347
+ 'options' => $options,
348
+ 'std' => 'enable',
349
+ 'desc' => __('Droid Sans Naskh and Roboto font families will be activated in all rich editors in back end.', 'wp-parsidate')
350
  )
351
+ )),
352
+ 'plugins' => apply_filters('wpp_plugins_compability_settings', array())
353
+ ));
354
+ return $settings;
355
  }
356
 
357
  /* Form Callbacks Made by EDD Development Team */
358
+ function wpp_header_callback($args)
359
+ {
360
  echo '<hr/>';
361
  }
362
 
363
+ function wpp_checkbox_callback($args)
364
+ {
365
  global $wpp_settings;
366
 
367
  $checked = isset($wpp_settings[$args['id']]) ? checked(1, $wpp_settings[$args['id']], false) : '';
368
  $html = '<input type="checkbox" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="1" ' . $checked . '/>';
369
+ $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
370
 
371
  echo $html;
372
  }
373
 
374
+ function wpp_multicheck_callback($args)
375
+ {
376
+ global $wpp_settings;
377
 
378
+ $html = '';
379
+ foreach ($args['options'] as $key => $value) {
380
+ $option_name = $args['id'] . '-' . $key;
381
+ wpp_checkbox_callback(array(
382
+ 'id' => $option_name,
383
+ 'desc' => $value
384
+ ));
385
+ echo '<br>';
386
+ }
387
 
388
+ echo $html;
389
  }
390
 
391
+ function wpp_radio_callback($args)
392
+ {
393
  global $wpp_settings;
394
 
395
+ foreach ($args['options'] as $key => $option) :
396
  $checked = false;
397
 
398
+ if (isset($wpp_settings[$args['id']]) && $wpp_settings[$args['id']] == $key)
399
  $checked = true;
400
+ elseif (isset($args['std']) && $args['std'] == $key && !isset($wpp_settings[$args['id']]))
401
  $checked = true;
402
 
403
  echo '<input name="wpp_settings[' . $args['id'] . ']"" id="wpp_settings[' . $args['id'] . '][' . $key . ']" type="radio" value="' . $key . '" ' . checked(true, $checked, false) . '/>';
407
  echo '<p class="description">' . $args['desc'] . '</p>';
408
  }
409
 
410
+ function wpp_text_callback($args)
411
+ {
412
  global $wpp_settings;
413
 
414
+ if (isset($wpp_settings[$args['id']]))
415
+ $value = $wpp_settings[$args['id']];
416
  else
417
+ $value = isset($args['std']) ? $args['std'] : '';
418
 
419
+ $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
420
+ $html = '<input type="text" class="' . $size . '-text" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '"/>';
421
+ $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
422
 
423
  echo $html;
424
  }
425
 
426
+ function wpp_number_callback($args)
427
+ {
428
  global $wpp_settings;
429
 
430
+ if (isset($wpp_settings[$args['id']]))
431
+ $value = $wpp_settings[$args['id']];
432
  else
433
+ $value = isset($args['std']) ? $args['std'] : '';
434
 
435
+ $max = isset($args['max']) ? $args['max'] : 999999;
436
+ $min = isset($args['min']) ? $args['min'] : 0;
437
+ $step = isset($args['step']) ? $args['step'] : 1;
438
 
439
+ $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
440
+ $html = '<input type="number" step="' . esc_attr($step) . '" max="' . esc_attr($max) . '" min="' . esc_attr($min) . '" class="' . $size . '-text" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '"/>';
441
+ $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
442
 
443
  echo $html;
444
  }
445
 
446
+ function wpp_textarea_callback($args)
447
+ {
448
  global $wpp_settings;
449
 
450
+ if (isset($wpp_settings[$args['id']]))
451
+ $value = $wpp_settings[$args['id']];
452
  else
453
+ $value = isset($args['std']) ? $args['std'] : '';
454
 
455
+ $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
456
+ $html = '<textarea class="large-text" cols="50" rows="5" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']">' . esc_textarea(stripslashes($value)) . '</textarea>';
457
+ $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
458
 
459
  echo $html;
460
  }
461
 
462
+ function wpp_password_callback($args)
463
+ {
464
  global $wpp_settings;
465
 
466
+ if (isset($wpp_settings[$args['id']]))
467
+ $value = $wpp_settings[$args['id']];
468
  else
469
+ $value = isset($args['std']) ? $args['std'] : '';
470
 
471
+ $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
472
+ $html = '<input type="password" class="' . $size . '-text" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr($value) . '"/>';
473
+ $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
474
 
475
  echo $html;
476
  }
477
 
478
+ function wpp_missing_callback($args)
479
+ {
480
  echo '&ndash;';
481
  return false;
482
  }
483
 
484
 
485
+ function wpp_select_callback($args)
486
+ {
487
  global $wpp_settings;
488
 
489
+ if (isset($wpp_settings[$args['id']]))
490
+ $value = $wpp_settings[$args['id']];
491
  else
492
+ $value = isset($args['std']) ? $args['std'] : '';
493
 
494
  $html = '<select id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']"/>';
495
 
496
+ foreach ($args['options'] as $option => $name) :
497
+ $selected = selected($option, $value, false);
498
  $html .= '<option value="' . $option . '" ' . $selected . '>' . $name . '</option>';
499
  endforeach;
500
 
501
  $html .= '</select>';
502
+ $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
503
 
504
  echo $html;
505
  }
506
 
507
+ function wpp_color_select_callback($args)
508
+ {
509
  global $wpp_settings;
510
 
511
+ if (isset($wpp_settings[$args['id']]))
512
+ $value = $wpp_settings[$args['id']];
513
  else
514
+ $value = isset($args['std']) ? $args['std'] : '';
515
 
516
  $html = '<select id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']"/>';
517
 
518
+ foreach ($args['options'] as $option => $color) :
519
+ $selected = selected($option, $value, false);
520
  $html .= '<option value="' . $option . '" ' . $selected . '>' . $color['label'] . '</option>';
521
  endforeach;
522
 
523
  $html .= '</select>';
524
+ $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
525
 
526
  echo $html;
527
  }
528
 
529
+ function wpp_rich_editor_callback($args)
530
+ {
531
  global $wpp_settings, $wp_version;
532
 
533
+ if (isset($wpp_settings[$args['id']]))
534
+ $value = $wpp_settings[$args['id']];
535
  else
536
+ $value = isset($args['std']) ? $args['std'] : '';
537
 
538
+ if ($wp_version >= 3.3 && function_exists('wp_editor')) {
539
+ $html = wp_editor(stripslashes($value), 'wpp_settings[' . $args['id'] . ']', array('textarea_name' => 'wpp_settings[' . $args['id'] . ']'));
540
  } else {
541
+ $html = '<textarea class="large-text" rows="10" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']">' . esc_textarea(stripslashes($value)) . '</textarea>';
542
  }
543
 
544
+ $html .= '<br/><label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
545
 
546
  echo $html;
547
  }
548
 
549
+ function wpp_upload_callback($args)
550
+ {
551
  global $wpp_settings;
552
 
553
+ if (isset($wpp_settings[$args['id']]))
554
  $value = $wpp_settings[$args['id']];
555
  else
556
  $value = isset($args['std']) ? $args['std'] : '';
557
 
558
+ $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
559
+ $html = '<input type="text" class="' . $size . '-text wpp_upload_field" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '"/>';
560
+ $html .= '<span>&nbsp;<input type="button" class="wpp_settings_upload_button button-secondary" value="' . __('Upload File', 'wpp') . '"/></span>';
561
+ $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
562
 
563
  echo $html;
564
  }
565
 
566
+ function wpp_color_callback($args)
567
+ {
568
  global $wpp_settings;
569
 
570
+ if (isset($wpp_settings[$args['id']]))
571
+ $value = $wpp_settings[$args['id']];
572
  else
573
+ $value = isset($args['std']) ? $args['std'] : '';
574
 
575
+ $default = isset($args['std']) ? $args['std'] : '';
576
 
577
+ $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
578
+ $html = '<input type="text" class="wpp-color-picker" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr($value) . '" data-default-color="' . esc_attr($default) . '" />';
579
+ $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
580
 
581
  echo $html;
582
  }
583
 
584
+ function wpp_render_settings()
585
+ {
586
  global $wpp_settings;
587
+ $active_tab = isset($_GET['tab']) && array_key_exists($_GET['tab'], wpp_get_tabs()) ? $_GET['tab'] : 'core';
588
 
589
  ob_start();
590
  ?>
591
+ <div class="wrap wpp-settings-wrap">
592
+ <h2><?php _e('Parsi Settings', 'wp-parsidate') ?></h2>
593
+ <h2 class="nav-tab-wrapper">
594
  <?php
595
+ foreach (wpp_get_tabs() as $tab_id => $tab_name) {
596
 
597
+ $tab_url = add_query_arg(array(
598
  'settings-updated' => false,
599
  'tab' => $tab_id
600
+ ));
601
 
602
  $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
603
 
604
+ echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">';
605
+ echo $tab_name;
606
  echo '</a>';
607
  }
608
  ?>
609
+ </h2>
610
+ <?php echo settings_errors('wpp-notices'); ?>
611
+ <div id="tab_container">
612
+ <form method="post" action="options.php">
613
+ <table class="form-table">
614
+ <?php
615
+ settings_fields('wpp_settings');
616
+ do_settings_fields('wpp_settings_' . $active_tab, 'wpp_settings_' . $active_tab);
617
+ ?>
618
+ </table>
619
  <?php submit_button(); ?>
620
+ </form>
621
+ </div><!-- #tab_container-->
622
+ </div><!-- .wrap -->
623
  <?php
624
  echo ob_get_clean();
625
  }
includes/widget/widget_archive.php CHANGED
@@ -30,7 +30,7 @@ class parsidate_archive extends WP_Widget
30
  <input style="width: 200px;" id="<?php echo $this->get_field_id('parsidate_archive_title'); ?>" name="<?php echo $this->get_field_name('parsidate_archive_title'); ?>" type="text" value="<?php echo (empty($instance['parsidate_archive_title'])? __('Jalali Date Archives','wp-parsidate') :$instance['parsidate_archive_title']) ?>" />
31
  <br />
32
  <label ><input type="radio" id="parsidate_archive_type1" name="<?php echo $this->get_field_name('parsidate_archive_type'); ?>" value="yearly" <?php checked($type,'yearly'); ?>/><label for="parsidate_archive_type1"><?php _e('Yearly','wp-parsidate') ?></label><br />
33
- <label ><input type="radio" id="parsidate_archive_type2" name="<?php echo $this->get_field_name('parsidate_archive_type'); ?>" value="monthly" <?php checked($type,'monthly'); ?>/><?php _e('Monthly','wp-parsidate') ?></label><br />
34
  <label ><input type="radio" id="parsidate_archive_type3" name="<?php echo $this->get_field_name('parsidate_archive_type'); ?>" value="daily" <?php checked($type,'daily'); ?>/><?php _e('Daily','wp-parsidate') ?></label><br />
35
  <br />
36
  <input type="checkbox" name="<?php echo $this->get_field_name('parsidate_archive_count'); ?>" id="<?php echo $this->get_field_id('parsidate_archive_count'); ?>" value="1" <?php checked($instance['parsidate_archive_count'],1,true); ?>/>
30
  <input style="width: 200px;" id="<?php echo $this->get_field_id('parsidate_archive_title'); ?>" name="<?php echo $this->get_field_name('parsidate_archive_title'); ?>" type="text" value="<?php echo (empty($instance['parsidate_archive_title'])? __('Jalali Date Archives','wp-parsidate') :$instance['parsidate_archive_title']) ?>" />
31
  <br />
32
  <label ><input type="radio" id="parsidate_archive_type1" name="<?php echo $this->get_field_name('parsidate_archive_type'); ?>" value="yearly" <?php checked($type,'yearly'); ?>/><label for="parsidate_archive_type1"><?php _e('Yearly','wp-parsidate') ?></label><br />
33
+ <label ><input type="radio" id="parsidate_archive_type2" name="<?php echo $this->get_field_name('parsidate_archive_type'); ?>" value="monthly" <?php checked($type,'monthly'); ?>/><?php _e('Monthly','wp-parsidate') ?></label><br />
34
  <label ><input type="radio" id="parsidate_archive_type3" name="<?php echo $this->get_field_name('parsidate_archive_type'); ?>" value="daily" <?php checked($type,'daily'); ?>/><?php _e('Daily','wp-parsidate') ?></label><br />
35
  <br />
36
  <input type="checkbox" name="<?php echo $this->get_field_name('parsidate_archive_count'); ?>" id="<?php echo $this->get_field_id('parsidate_archive_count'); ?>" value="1" <?php checked($instance['parsidate_archive_count'],1,true); ?>/>
includes/widget/widget_calendar.php CHANGED
@@ -1,44 +1,45 @@
1
  <?php
 
2
  /**
3
  * @author lord_viper
4
  * @copyright 2013
5
  */
6
-
7
  class parsidate_calendar extends WP_Widget
8
  {
9
- public function __construct()
10
- {
11
- global $wp_version;
12
- if ( version_compare( $wp_version , '4.3', '>=' ) )
13
- parent::__construct(false,__('Jalali Date Calender','wp-parsidate'),'description='.__('Jalali Date Calender','wp-parsidate'));
14
- else
15
- parent::WP_Widget(false,__('Jalali Date Calender','wp-parsidate'),'description='.__('Jalali Date Calender','wp-parsidate'));
16
- }
17
-
18
- public function form($instance)
19
- {
20
- ?>
21
  <p style="text-align:right; direction:rtl">
22
- <label><?php _e('Title:','wp-parsidate') ?></label>
23
- <input style="width: 200px;" id="<?php echo $this->get_field_id('parsidate_calendar_title'); ?>" name="<?php echo $this->get_field_name('parsidate_calendar_title'); ?>" type="text" value="<?php echo (empty($instance['parsidate_calendar_title'])? __('Jalali Date Calender','wp-parsidate') :$instance['parsidate_calendar_title']) ?>" />
24
  </p>
25
- <?php
26
- }
27
-
28
- public function update($new_instance, $old_instance )
29
- {
30
- $instance = $old_instance;
31
- $instance['parsidate_calendar_title'] = strip_tags($new_instance['parsidate_calendar_title']);
32
- return $instance;
33
- }
34
 
35
- public function widget($args ,$instance)
36
- {
37
- extract($args);
38
- $title = (empty($instance['parsidate_calendar_title']))?'':$instance['parsidate_calendar_title'];
39
- echo "$before_widget\n$before_title $title $after_title";
40
- wpp_get_calendar();
41
- echo $after_widget;
42
- }
 
 
 
 
 
 
 
43
  }
 
44
  ?>
1
  <?php
2
+
3
  /**
4
  * @author lord_viper
5
  * @copyright 2013
6
  */
 
7
  class parsidate_calendar extends WP_Widget
8
  {
9
+ public function __construct()
10
+ {
11
+ global $wp_version;
12
+ if (version_compare($wp_version, '4.3', '>='))
13
+ parent::__construct(false, __('Jalali Date Calender', 'wp-parsidate'), 'description=' . __('Jalali Date Calender', 'wp-parsidate'));
14
+ else
15
+ parent::WP_Widget(false, __('Jalali Date Calender', 'wp-parsidate'), 'description=' . __('Jalali Date Calender', 'wp-parsidate'));
16
+ }
17
+
18
+ public function form($instance)
19
+ {
20
+ ?>
21
  <p style="text-align:right; direction:rtl">
22
+ <label><?php _e('Title:', 'wp-parsidate') ?></label>
23
+ <input style="width: 200px;" id="<?php echo $this->get_field_id('parsidate_calendar_title'); ?>" name="<?php echo $this->get_field_name('parsidate_calendar_title'); ?>" type="text" value="<?php echo(empty($instance['parsidate_calendar_title']) ? __('Jalali Date Calender', 'wp-parsidate') : $instance['parsidate_calendar_title']) ?>"/>
24
  </p>
25
+ <?php
26
+ }
 
 
 
 
 
 
 
27
 
28
+ public function update($new_instance, $old_instance)
29
+ {
30
+ $instance = $old_instance;
31
+ $instance['parsidate_calendar_title'] = strip_tags($new_instance['parsidate_calendar_title']);
32
+ return $instance;
33
+ }
34
+
35
+ public function widget($args, $instance)
36
+ {
37
+ extract($args);
38
+ $title = (empty($instance['parsidate_calendar_title'])) ? '' : $instance['parsidate_calendar_title'];
39
+ echo "$before_widget\n$before_title $title $after_title";
40
+ wpp_get_calendar();
41
+ echo $after_widget;
42
+ }
43
  }
44
+
45
  ?>
readme.txt CHANGED
@@ -41,6 +41,9 @@ List of some features:
41
  4. 'Jalali Date Calender' in action
42
 
43
  == Changelog ==
 
 
 
44
  = 2.2.2 =
45
  * Fix error in PHP 7
46
 
41
  4. 'Jalali Date Calender' in action
42
 
43
  == Changelog ==
44
+ = 2.2.3 =
45
+ * Conflict timezone with wordpress default timezone [#issue](https://github.com/wordpress-parsi/wp-parsidate/issues/1)
46
+
47
  = 2.2.2 =
48
  * Fix error in PHP 7
49
 
wp-parsidate.php CHANGED
@@ -1,174 +1,176 @@
1
- <?php
2
- /**
3
- * Plugin Name: WP-Parsidate
4
- * Version: 2.2.2
5
- * Plugin URI: http://forum.wp-parsi.com/
6
- * Description: Persian package for WordPress, Adds full RTL and Shamsi (Jalali) support for: posts, comments, pages, archives, search, categories, permalinks and all admin sections and TinyMce editor, lists, quick editor. This package has Jalali archive widget.
7
- * Author: WP-Parsi Team
8
- * Author URI: http://wp-parsi.com/
9
- * Text Domain: wp-parsidate
10
- * Domain Path: parsi-languages
11
- *
12
- * WordPress Parsi Package, Adds Persian language & Jalali date support to your blog
13
- *
14
- * Developers:
15
- * Mobin Ghasempoor ( Senior programmer & Founder )
16
- * Morteza Geransayeh ( Senior programmer & Manager )
17
- * Ehsaan ( Programmer )
18
- * Farhan Nisi ( Programmer )
19
- * Parsa Kafi ( Programmer )
20
- * Saeed Fard ( Analyst )
21
- *
22
- * @author Mobin Ghasempoor
23
- * @author Morteza Geransayeh
24
- * @author Farhan Nisi
25
- * @author Ehsaan
26
- * @link http://wp-parsi.com/
27
- * @version 2.2
28
- * @license http://www.gnu.org/licenses/gpl-2.0.html GNU Public License v2.0
29
- * @package WP-Parsidate
30
- * @subpackage Core
31
- */
32
-
33
-
34
- if ( ! defined( 'ABSPATH' ) ) exit; // No direct access allowed
35
-
36
- final class WP_Parsidate {
37
- /**
38
- * @var WP_Parsidate Class instance
39
- */
40
- public static $instance = null;
41
-
42
- /**
43
- * Returns an instance of WP_Parsidate class, makes instance if not exists
44
- *
45
- * @since 2.0
46
- * @return WP_Parsidate Instance of WP_Parsidate
47
- */
48
- public static function get_instance() {
49
- if ( self::$instance == null )
50
- self::$instance = new WP_Parsidate();
51
-
52
- return self::$instance;
53
- }
54
-
55
- private function __construct() {
56
- $this->consts();
57
- $this->setup_vars();
58
- $this->include_files();
59
- add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'parsi_settings_link' ) );
60
- }
61
-
62
- /**
63
- * Add Setting Link To Install Plugin
64
- *
65
- * @param string $links
66
- * @return array
67
- */
68
- public static function parsi_settings_link( $links ) {
69
- $mylinks = array('<a href="'.menu_page_url('wp-parsi-settings',FALSE).'">'.__('settings','wp-parsidate').'</a>');
70
- return array_merge( $links, $mylinks );
71
- }
72
-
73
- /**
74
- * Sets up constants for plugin
75
- *
76
- * @since 2.0
77
- * @return void
78
- */
79
- private function consts() {
80
- if ( ! defined( 'WP_PARSI_ROOT' ) )
81
- define( 'WP_PARSI_ROOT', __FILE__ );
82
-
83
- if ( ! defined( 'WP_PARSI_DIR' ) )
84
- define( 'WP_PARSI_DIR', plugin_dir_path( WP_PARSI_ROOT ) );
85
-
86
- if ( ! defined( 'WP_PARSI_URL' ) )
87
- define( 'WP_PARSI_URL', plugin_dir_url( WP_PARSI_ROOT ) );
88
-
89
- if ( ! defined( 'WP_PARSI_VER' ) )
90
- define( 'WP_PARSI_VER', '2.2' );
91
- }
92
-
93
- /**
94
- * Includes files for plugin
95
- *
96
- * @since 2.0
97
- * @return void
98
- */
99
- public function include_files() {
100
- require_once( WP_PARSI_DIR . 'includes/settings.php' );
101
- global $wpp_settings;
102
- $wpp_settings = wp_parsi_get_settings();
103
-
104
- $files = array(
105
- 'parsidate',
106
- 'general',
107
- 'fixes-archive',
108
- 'fixes-permalinks',
109
- 'fixes-dates',
110
- 'fixes-misc',
111
- 'admin/styles-fix',
112
- 'admin/lists-fix',
113
- 'admin/other-fix',
114
- 'fixes-calendar',
115
- 'fixes-archives',
116
- 'plugins/woocommerce',
117
- 'plugins/edd',
118
- 'widget/widget_archive',
119
- 'widget/widget_calendar'
120
- );
121
-
122
- foreach( $files as $file )
123
- require_once( WP_PARSI_DIR . 'includes/' . $file . '.php' );
124
-
125
- if ( get_locale() == 'fa_IR' )
126
- load_textdomain( 'wp-parsidate', WP_PARSI_DIR . 'parsi-languages/fa_IR.mo' );
127
-
128
- add_action( 'widgets_init', array( $this, 'register_widget' ) );
129
- }
130
-
131
- /**
132
- * Sets up global variables
133
- *
134
- * @since 2.0
135
- * @return void
136
- */
137
- private function setup_vars() {
138
- global $persian_month_names, $timezone;
139
- $persian_month_names = array( '',
140
- 'فروردین',
141
- 'اردیبهشت',
142
- 'خرداد',
143
- 'تیر',
144
- 'مرداد',
145
- 'شهریور',
146
- 'مهر',
147
- 'آبان',
148
- 'آذر',
149
- 'دی',
150
- 'بهمن',
151
- 'اسفند'
152
- );
153
-
154
- $timezone = get_option( 'timezone_string' );
155
- if ( $timezone != '' )
156
- date_default_timezone_set( $timezone );
157
- else
158
- date_default_timezone_set( 'Asia/Tehran' );
159
- }
160
-
161
- /**
162
- * Register Plugin Widgets
163
- *
164
- * @since 2.0
165
- * @return boolean
166
- */
167
- public function register_widget() {
168
- register_widget('parsidate_archive');
169
- register_widget('parsidate_calendar');
170
- return true;
171
- }
172
- }
173
-
174
- return WP_Parsidate::get_instance();
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: WP-Parsidate
4
+ * Version: 2.2.3
5
+ * Plugin URI: http://forum.wp-parsi.com/
6
+ * Description: Persian package for WordPress, Adds full RTL and Shamsi (Jalali) support for: posts, comments, pages, archives, search, categories, permalinks and all admin sections and TinyMce editor, lists, quick editor. This package has Jalali archive widget.
7
+ * Author: WP-Parsi Team
8
+ * Author URI: http://wp-parsi.com/
9
+ * Text Domain: wp-parsidate
10
+ * Domain Path: parsi-languages
11
+ *
12
+ * WordPress Parsi Package, Adds Persian language & Jalali date support to your blog
13
+ *
14
+ * Developers:
15
+ * Mobin Ghasempoor ( Senior programmer & Founder )
16
+ * Morteza Geransayeh ( Senior programmer & Manager )
17
+ * Ehsaan ( Programmer )
18
+ * Farhan Nisi ( Programmer )
19
+ * Parsa Kafi ( Programmer )
20
+ * Saeed Fard ( Analyst )
21
+ *
22
+ * @author Mobin Ghasempoor
23
+ * @author Morteza Geransayeh
24
+ * @author Farhan Nisi
25
+ * @author Ehsaan
26
+ * @link http://wp-parsi.com/
27
+ * @version 2.2
28
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU Public License v2.0
29
+ * @package WP-Parsidate
30
+ * @subpackage Core
31
+ */
32
+
33
+
34
+ if (!defined('ABSPATH')) exit; // No direct access allowed
35
+
36
+ final class WP_Parsidate
37
+ {
38
+ /**
39
+ * @var WP_Parsidate Class instance
40
+ */
41
+ public static $instance = null;
42
+
43
+ private function __construct()
44
+ {
45
+ $this->consts();
46
+ $this->setup_vars();
47
+ $this->include_files();
48
+ add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'parsi_settings_link'));
49
+ }
50
+
51
+ /**
52
+ * Sets up constants for plugin
53
+ *
54
+ * @since 2.0
55
+ * @return void
56
+ */
57
+ private function consts()
58
+ {
59
+ if (!defined('WP_PARSI_ROOT'))
60
+ define('WP_PARSI_ROOT', __FILE__);
61
+
62
+ if (!defined('WP_PARSI_DIR'))
63
+ define('WP_PARSI_DIR', plugin_dir_path(WP_PARSI_ROOT));
64
+
65
+ if (!defined('WP_PARSI_URL'))
66
+ define('WP_PARSI_URL', plugin_dir_url(WP_PARSI_ROOT));
67
+
68
+ if (!defined('WP_PARSI_VER'))
69
+ define('WP_PARSI_VER', '2.2');
70
+ }
71
+
72
+ /**
73
+ * Sets up global variables
74
+ *
75
+ * @since 2.0
76
+ * @return void
77
+ */
78
+ private function setup_vars()
79
+ {
80
+ global $persian_month_names, $timezone;
81
+ $persian_month_names = array('',
82
+ 'فروردین',
83
+ 'اردیبهشت',
84
+ 'خرداد',
85
+ 'تیر',
86
+ 'مرداد',
87
+ 'شهریور',
88
+ 'مهر',
89
+ 'آبان',
90
+ 'آذر',
91
+ 'دی',
92
+ 'بهمن',
93
+ 'اسفند'
94
+ );
95
+ }
96
+
97
+ /**
98
+ * Includes files for plugin
99
+ *
100
+ * @since 2.0
101
+ * @return void
102
+ */
103
+ public function include_files()
104
+ {
105
+ require_once(WP_PARSI_DIR . 'includes/settings.php');
106
+ global $wpp_settings;
107
+ $wpp_settings = wp_parsi_get_settings();
108
+
109
+ $files = array(
110
+ 'parsidate',
111
+ 'general',
112
+ 'fixes-archive',
113
+ 'fixes-permalinks',
114
+ 'fixes-dates',
115
+ 'fixes-misc',
116
+ 'admin/styles-fix',
117
+ 'admin/lists-fix',
118
+ 'admin/other-fix',
119
+ 'fixes-calendar',
120
+ 'fixes-archives',
121
+ 'plugins/woocommerce',
122
+ 'plugins/edd',
123
+ 'widget/widget_archive',
124
+ 'widget/widget_calendar'
125
+ );
126
+
127
+ foreach ($files as $file)
128
+ require_once(WP_PARSI_DIR . 'includes/' . $file . '.php');
129
+
130
+ if (get_locale() == 'fa_IR')
131
+ load_textdomain('wp-parsidate', WP_PARSI_DIR . 'parsi-languages/fa_IR.mo');
132
+
133
+ add_action('widgets_init', array($this, 'register_widget'));
134
+ }
135
+
136
+ /**
137
+ * Returns an instance of WP_Parsidate class, makes instance if not exists
138
+ *
139
+ * @since 2.0
140
+ * @return WP_Parsidate Instance of WP_Parsidate
141
+ */
142
+ public static function get_instance()
143
+ {
144
+ if (self::$instance == null)
145
+ self::$instance = new WP_Parsidate();
146
+
147
+ return self::$instance;
148
+ }
149
+
150
+ /**
151
+ * Add Setting Link To Install Plugin
152
+ *
153
+ * @param string $links
154
+ * @return array
155
+ */
156
+ public static function parsi_settings_link($links)
157
+ {
158
+ $mylinks = array('<a href="' . menu_page_url('wp-parsi-settings', FALSE) . '">' . __('settings', 'wp-parsidate') . '</a>');
159
+ return array_merge($links, $mylinks);
160
+ }
161
+
162
+ /**
163
+ * Register Plugin Widgets
164
+ *
165
+ * @since 2.0
166
+ * @return boolean
167
+ */
168
+ public function register_widget()
169
+ {
170
+ register_widget('parsidate_archive');
171
+ register_widget('parsidate_calendar');
172
+ return true;
173
+ }
174
+ }
175
+
176
+ return WP_Parsidate::get_instance();