wp-parsidate
Last commit date
css
12 years ago
js
12 years ago
languages
12 years ago
lib
12 years ago
admin.php
12 years ago
index.php
12 years ago
readme.txt
12 years ago
screenshot-1.png
12 years ago
screenshot-2.png
12 years ago
widegets.php
12 years ago
wp-parsidate.php
12 years ago
wp-parsidate.php
648 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | Plugin Name: WP-Parsidate |
| 5 | Version: 1.3.3 |
| 6 | Author: Mobin Ghasempoor |
| 7 | Author URI: http://wp-parsi.com/ |
| 8 | Plugin URI: http://forum.wp-parsi.com/ |
| 9 | Description: Persian package builder for WordPress, Full RTL and Shamsi(Jalali) date in: posts, comments, pages, archives, search, categories, permalinks and all admin sections such as tinymce editor, posts lists, post quick edit, comments lists, comments quick edit, pages lists, pages quick edit. This package already has Shamsi(Jalali) archie widget. |
| 10 | */ |
| 11 | |
| 12 | /* |
| 13 | Special thanks to : |
| 14 | Wordpress Parsi admins and moderators (Parsa Kafi, Mohsen Ghiasi, Saeed Fard, Abdolmajed Shahbakhsh, Morteza Rocky and Mostafa Soufi, Seyed Vahid Rezaei) |
| 15 | Wordpress Parsi forum members for great support(forum.wp-parsi.com) |
| 16 | */ |
| 17 | |
| 18 | define('wp_parsipath', dirname(__file__)); |
| 19 | define('wp_contentpath',dirname(dirname(wp_parsipath))); |
| 20 | global $timezone,$persian_month_names; |
| 21 | $persian_month_names = array('','فروردین','اردیبهشت','خرداد','تیر','� |
| 22 | رداد','شهریور','� |
| 23 | هر','آبان','آذر','دی','به� |
| 24 | ن','اسفند'); |
| 25 | |
| 26 | @define('WP_MEMORY_LIMIT', '64M'); |
| 27 | $timezone = get_option('timezone_string'); |
| 28 | if(empty($timezone)) |
| 29 | $timezone='Asia/Tehran'; |
| 30 | date_default_timezone_set($timezone); |
| 31 | |
| 32 | include_once (join(DIRECTORY_SEPARATOR,array(wp_parsipath,'lib','parsidate.php'))); |
| 33 | include_once (join(DIRECTORY_SEPARATOR,array(wp_parsipath,'lib','functions.php'))); |
| 34 | include_once (join(DIRECTORY_SEPARATOR,array(wp_parsipath,'widegets.php'))); |
| 35 | include_once (join(DIRECTORY_SEPARATOR,array(wp_parsipath,'admin.php'))); |
| 36 | register_activation_hook( __FILE__,'parsidate_plugin_install'); |
| 37 | |
| 38 | function parsidate_plugin_install() |
| 39 | { |
| 40 | if (!is_dir(join(DIRECTORY_SEPARATOR,array(wp_contentpath,'languages')))) |
| 41 | mkdir(join(DIRECTORY_SEPARATOR,array(wp_contentpath,'languages'))); |
| 42 | |
| 43 | $source = join(DIRECTORY_SEPARATOR,array(wp_parsipath,'languages','*')); |
| 44 | $destination = join(DIRECTORY_SEPARATOR,array(wp_contentpath,'languages')); |
| 45 | $files = glob($source); |
| 46 | |
| 47 | foreach($files as $sfile) |
| 48 | { |
| 49 | @copy($sfile, $destination.DIRECTORY_SEPARATOR.basename($sfile)); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | if(isset($_POST['wp_parsidate_save'])) |
| 54 | { |
| 55 | $val['sep_fixdate'] = $_POST['sep_fixdate']; |
| 56 | $val['sep_persian'] = $_POST['sep_persian']; |
| 57 | $val['sep_titlenum'] = (isset($_POST['sep_titlenum']) ?'checked':''); |
| 58 | $val['sep_postnum'] = (isset($_POST['sep_postnum']) ?'checked':''); |
| 59 | $val['sep_commentnum'] = (isset($_POST['sep_commentnum'])?'checked':''); |
| 60 | $val['sep_commentcnt'] = (isset($_POST['sep_commentcnt'])?'checked':''); |
| 61 | $val['sep_datesnum'] = (isset($_POST['sep_datesnum']) ?'checked':''); |
| 62 | $val['sep_catnum'] = (isset($_POST['sep_catnum']) ?'checked':''); |
| 63 | $val['sep_excnum'] = (isset($_POST['sep_excnum']) ?'checked':''); |
| 64 | $val['sep_fixarabic'] = $_POST['sep_fixarabic']; |
| 65 | $val['sep_fixurl'] = $_POST['sep_fixurl']; |
| 66 | $val['sep_planet'] = $_POST['sep_planet']; |
| 67 | |
| 68 | update_option('parsidate_option',$val); |
| 69 | } |
| 70 | |
| 71 | global $val; |
| 72 | |
| 73 | $val = get_option('parsidate_option'); |
| 74 | |
| 75 | if(empty($val)) |
| 76 | { |
| 77 | $val['sep_fixdate'] = 'بلی'; |
| 78 | $val['sep_persian'] = 'بلی'; |
| 79 | $val['sep_titlenum'] = ''; |
| 80 | $val['sep_postnum'] = ''; |
| 81 | $val['sep_commentnum'] = ''; |
| 82 | $val['sep_commentcnt'] = ''; |
| 83 | $val['sep_datesnum'] = ''; |
| 84 | $val['sep_catnum'] = ''; |
| 85 | $val['sep_fixarabic'] = 'بلی'; |
| 86 | $val['sep_fixurl'] = 'بلی'; |
| 87 | $val['sep_planet'] = 0; |
| 88 | $val['sep_excnum'] = ''; |
| 89 | } |
| 90 | |
| 91 | if($val['sep_persian']=='بلی') |
| 92 | add_filter('locale','new_locale'); |
| 93 | |
| 94 | function new_locale() |
| 95 | { |
| 96 | return 'fa_IR'; |
| 97 | } |
| 98 | /* |
| 99 | * admin config page |
| 100 | */ |
| 101 | add_action('admin_menu', 'add_persiandate_menu'); |
| 102 | |
| 103 | function add_persiandate_menu() |
| 104 | { |
| 105 | add_menu_page('تنظی� |
| 106 | ات پارسی', 'تنظی� |
| 107 | ات پارسی', 'add_users', 'parsi_plugin_page','parsi_plugin_page', ''); |
| 108 | } |
| 109 | |
| 110 | /* |
| 111 | * fix theme editor rtl |
| 112 | */ |
| 113 | add_action( 'admin_print_styles-plugin-editor.php', 'theme_editor_add_init', 11 ); |
| 114 | add_action( 'admin_print_styles-theme-editor.php', 'theme_editor_add_init', 11 ); |
| 115 | function theme_editor_add_init(){ |
| 116 | wp_enqueue_style("functions", plugins_url(basename(wp_parsipath)."/css/admin.css"), false, "1.0", "all"); |
| 117 | } |
| 118 | |
| 119 | |
| 120 | /* |
| 121 | * fix tiny mce rtl |
| 122 | */ |
| 123 | add_filter('init', 'wpb_mce_set_font',1000); |
| 124 | |
| 125 | function wpb_mce_set_font($input) |
| 126 | { |
| 127 | add_editor_style( plugins_url(basename(wp_parsipath).'/css/editor.css') ); |
| 128 | } |
| 129 | |
| 130 | |
| 131 | /* |
| 132 | * hooks and filters for persian date |
| 133 | */ |
| 134 | |
| 135 | if($val['sep_fixdate']=='بلی') |
| 136 | { |
| 137 | if(!detect_rss()) |
| 138 | { |
| 139 | add_filter('the_time', 'add_ptime',1001,2); |
| 140 | add_filter('the_date', 'add_pdate',1001,2); |
| 141 | add_action('date_i18n', 'add_pi18n',1001,3);//revision |
| 142 | add_filter('get_comment_time', 'add_ctime',1001,2); |
| 143 | add_filter('get_comment_date', 'add_cdate',1001,2); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | function add_ptime($time,$format='') |
| 148 | { |
| 149 | global $post,$val; |
| 150 | if(empty($format)) |
| 151 | $format=get_option('time_format'); |
| 152 | if(empty($val['sep_datesnum'])) |
| 153 | return parsidate($format,$post->post_date,'eng'); |
| 154 | else |
| 155 | return parsidate($format,$post->post_date); |
| 156 | } |
| 157 | |
| 158 | function add_pdate($time,$format='') |
| 159 | { |
| 160 | global $post,$val; |
| 161 | if(empty($format)) |
| 162 | $format=get_option('date_format'); |
| 163 | if(empty($val['sep_datesnum'])) |
| 164 | return parsidate($format,$post->post_date,'eng'); |
| 165 | else |
| 166 | return parsidate($format,$post->post_date); |
| 167 | } |
| 168 | |
| 169 | function add_ctime($time,$format='') |
| 170 | { |
| 171 | global $comment,$val; |
| 172 | if(empty($format)) |
| 173 | $format=get_option('time_format'); |
| 174 | if(empty($val['sep_datesnum'])) |
| 175 | return parsidate($format,$comment->comment_date,'eng'); |
| 176 | else |
| 177 | return parsidate($format,$comment->comment_date); |
| 178 | } |
| 179 | |
| 180 | function add_cdate($time,$format='') |
| 181 | { |
| 182 | global $comment,$val; |
| 183 | if(empty($format)) |
| 184 | $format=get_option('date_format'); |
| 185 | if(empty($val['sep_datesnum'])) |
| 186 | return parsidate($format,$comment->comment_date,'eng'); |
| 187 | else |
| 188 | return parsidate($format,$comment->comment_date); |
| 189 | } |
| 190 | |
| 191 | function add_pi18n($dateformatstring,$unixtimestamp,$gmt) |
| 192 | { |
| 193 | global $val; |
| 194 | if(empty($val['sep_datesnum'])) |
| 195 | return parsidate($unixtimestamp,$gmt,'eng'); |
| 196 | else |
| 197 | return parsidate($unixtimestamp,$gmt); |
| 198 | } |
| 199 | /* |
| 200 | * fix persian numbers |
| 201 | */ |
| 202 | if(!empty($val['sep_postnum'])) |
| 203 | add_filter('the_content', 'fixnumber'); |
| 204 | if(!empty($val['sep_titlenum'])) |
| 205 | add_filter('the_title', 'fixnumber'); |
| 206 | if(!empty($val['sep_commentnum'])) |
| 207 | add_filter('comment_text', 'fixnumber'); |
| 208 | if(!empty($val['sep_commentcnt'])) |
| 209 | add_filter('comments_number', 'fixnumber'); |
| 210 | if(!empty($val['sep_catnum'])) |
| 211 | add_filter('wp_list_categories', 'fixnumber'); |
| 212 | if(!empty($val['sep_excnum'])) |
| 213 | add_filter('the_excerpt', 'fixnumber'); |
| 214 | |
| 215 | /* |
| 216 | * fix arabic characters |
| 217 | */ |
| 218 | if($val['sep_fixarabic']=='بلی') |
| 219 | { |
| 220 | add_filter('the_content', 'fixarabic'); |
| 221 | add_filter('the_title', 'fixarabic'); |
| 222 | add_filter('comment_text', 'fixarabic'); |
| 223 | add_filter('wp_list_categories', 'fixarabic'); |
| 224 | add_filter('the_excerpt', 'fixarabic'); |
| 225 | } |
| 226 | /* |
| 227 | *fix archive title |
| 228 | */ |
| 229 | add_filter( 'wp_title', 'wp_pdtitle', 1001,3); |
| 230 | |
| 231 | function wp_pdtitle($title, $sep,$seplocation) |
| 232 | { |
| 233 | global $persian_month_names,$wp_query; |
| 234 | $query=$wp_query->query; |
| 235 | |
| 236 | if(!is_archive() or (is_archive() and !isset($query['monthnum']) )) |
| 237 | return $title; |
| 238 | if($seplocation=='right') |
| 239 | $query = array_reverse($query); |
| 240 | $query['name']=get_option('blogname'); |
| 241 | $query['monthnum']=$persian_month_names[intval($query['monthnum'])]; |
| 242 | return fixnumber(implode(" $sep ",$query)); |
| 243 | } |
| 244 | /* |
| 245 | * fix persian permalink |
| 246 | */ |
| 247 | if ($val['sep_fixurl']=='بلی') |
| 248 | { |
| 249 | add_filter("post_link","get_pdpermalink",10,3); |
| 250 | add_action( 'pre_get_posts','wppd_pre_get_posts'); |
| 251 | add_filter( 'posts_where' , 'wppd_posts_where'); |
| 252 | } |
| 253 | |
| 254 | function get_pdpermalink($perma, $post,$leavename = false) |
| 255 | { |
| 256 | if(empty($post->ID)) |
| 257 | return false; |
| 258 | if ( $post->post_type == 'page' || $post->post_status == 'static') |
| 259 | return get_page_link($post->ID); |
| 260 | elseif ( $post->post_type == 'attachment' ) |
| 261 | return get_attachment_link( $post->ID); |
| 262 | elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false)))) |
| 263 | return get_post_permalink($post->ID); |
| 264 | $permalink = get_option('permalink_structure'); |
| 265 | preg_match_all('/%([^\/]*)%/',$permalink,$rewritecode); |
| 266 | $rewritecode = $rewritecode[0]; |
| 267 | if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft'))) |
| 268 | { |
| 269 | if($leavename) |
| 270 | $rewritecode=array_diff($rewritecode,array('%postname%','%pagename%')); |
| 271 | |
| 272 | $date= explode(" ",parsidate('Y m d H i s',$post->post_date,'eng')); |
| 273 | $out=array(); |
| 274 | foreach($rewritecode as $rewrite) |
| 275 | { |
| 276 | switch($rewrite) |
| 277 | { |
| 278 | case'%year%': |
| 279 | $out[] = $date[0]; |
| 280 | break; |
| 281 | case'%monthnum%': |
| 282 | $out[] = $date[1]; |
| 283 | break; |
| 284 | case'%day%': |
| 285 | $out[] = $date[2]; |
| 286 | break; |
| 287 | case'%hour%': |
| 288 | $out[] = $date[3]; |
| 289 | break; |
| 290 | case'%minute%': |
| 291 | $out[] = $date[4]; |
| 292 | break; |
| 293 | case'%second%': |
| 294 | $out[] = $date[5]; |
| 295 | break; |
| 296 | case'%postname%': |
| 297 | $out[] = $post->post_name; |
| 298 | break; |
| 299 | case'%post_id%': |
| 300 | $out[] = $post->ID; |
| 301 | break; |
| 302 | case'%category%': |
| 303 | $category=''; |
| 304 | $cats = get_the_category($post->ID); |
| 305 | if ($cats) |
| 306 | { |
| 307 | usort($cats, '_usort_terms_by_ID'); |
| 308 | $category = $cats[0]->slug; |
| 309 | if ( $parent = $cats[0]->parent ) |
| 310 | $category = get_category_parents($parent, false, '/', true) . $category; |
| 311 | } |
| 312 | if (empty($category)) |
| 313 | { |
| 314 | $default_category = get_term( get_option('default_category'),'category'); |
| 315 | $category = is_wp_error( $default_category ) ? '' : $default_category->slug; |
| 316 | } |
| 317 | $out[] = $category; |
| 318 | break; |
| 319 | case'%author%': |
| 320 | $authordata = get_userdata($post->post_author); |
| 321 | $out[] = $authordata->user_nicename; |
| 322 | break; |
| 323 | case'%pagename%': |
| 324 | $out[] = $post->post_name; |
| 325 | break; |
| 326 | default:unset($rewritecode[array_search($rewrite,$rewritecode)]); |
| 327 | } |
| 328 | } |
| 329 | $permalink = home_url( str_replace($rewritecode, $out, $permalink)); |
| 330 | return user_trailingslashit($permalink, 'single'); |
| 331 | } |
| 332 | else |
| 333 | return home_url("?p=$post->ID"); |
| 334 | } |
| 335 | |
| 336 | function wppd_pre_get_posts( $query ) |
| 337 | { |
| 338 | global $wpdb; |
| 339 | $permalink = $query->query; |
| 340 | $year = ''; |
| 341 | $monthnum = ''; |
| 342 | $day = ''; |
| 343 | if(isset($permalink['year'])) |
| 344 | $year=$permalink['year']; |
| 345 | if(isset($permalink['monthnum'])) |
| 346 | $monthnum=$permalink['monthnum']; |
| 347 | if(isset($permalink['day'])) |
| 348 | $day=$permalink['day']; |
| 349 | if(!empty($year)||!empty($monthnum)||!empty($day)) |
| 350 | { |
| 351 | $cnt = ''; |
| 352 | $post_id = ''; |
| 353 | $name = ''; |
| 354 | $out = false; |
| 355 | if(isset($permalink['name'])) |
| 356 | { |
| 357 | $name = $permalink['name']; |
| 358 | $var = $wpdb->get_var("select post_date from {$wpdb->prefix}posts where post_name='$name' order by id"); |
| 359 | $per = parsidate('Y-m-d',$var,'eng'); |
| 360 | update_option('options',$per); |
| 361 | $per = explode('-',$per); |
| 362 | $out = true; |
| 363 | if(!empty($year)) |
| 364 | if($year != $per[0]) |
| 365 | $out = false; |
| 366 | if($out and !empty($monthnum)) |
| 367 | if($monthnum!=$per[1]) |
| 368 | $out = false; |
| 369 | if($out and !empty($day)) |
| 370 | if($day != $per[2]) |
| 371 | $out = false; |
| 372 | } |
| 373 | elseif($permalink['post_id']) |
| 374 | { |
| 375 | $out = true; |
| 376 | $post_id = $permalink['post_id']; |
| 377 | $var = $wpdb->get_var("select post_date from {$wpdb->prefix}wp_posts where ID=$post_id"); |
| 378 | } |
| 379 | elseif(!empty($year)and!empty($monthnum)and!empty($day)) |
| 380 | { |
| 381 | $out = true; |
| 382 | $var = gregdate('Y-m-d',"$year-$monthnum-$day"); |
| 383 | } |
| 384 | |
| 385 | if($out) |
| 386 | { |
| 387 | preg_match_all('!\d+!', $var, $matches); |
| 388 | $var=$matches[0]; |
| 389 | $query->set( 'year', $var[0]); |
| 390 | $query->set( 'monthnum', $var[1]); |
| 391 | $query->set( 'day', $var[2]); |
| 392 | } |
| 393 | return $query; |
| 394 | } |
| 395 | else |
| 396 | return $query; |
| 397 | } |
| 398 | |
| 399 | function wppd_posts_where($where) |
| 400 | { |
| 401 | global $wp_query, $wpdb,$pagenow; |
| 402 | if(empty($wp_query->query_vars)) |
| 403 | return $where; |
| 404 | $j_days_in_month = array('',31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29); |
| 405 | $m = $wp_query->query_vars['m']; |
| 406 | $hour = $wp_query->query_vars['hour']; |
| 407 | $minute = $wp_query->query_vars['minute']; |
| 408 | $second = $wp_query->query_vars['second']; |
| 409 | $year = $wp_query->query_vars['year']; |
| 410 | $month = $wp_query->query_vars['monthnum']; |
| 411 | $day = $wp_query->query_vars['day']; |
| 412 | |
| 413 | if(!empty($m)) |
| 414 | { |
| 415 | $len = strlen($m); |
| 416 | $year = substr($m, 0,4); |
| 417 | if($len>5) |
| 418 | $month = substr($m, 4, 2); |
| 419 | if($len>7) |
| 420 | $day = substr($m, 6, 2); |
| 421 | if($len>9) |
| 422 | $hour = substr($m, 8, 2); |
| 423 | if($len>11) |
| 424 | $minute = substr($m, 10, 2); |
| 425 | if($len>13) |
| 426 | $second = substr($m, 12, 2); |
| 427 | } |
| 428 | |
| 429 | if(empty($year)|| $year>1700) |
| 430 | return $where; |
| 431 | |
| 432 | $stamon = 1; |
| 433 | $staday = 1; |
| 434 | $stahou = '00'; |
| 435 | $stamin = '00'; |
| 436 | $stasec = '00'; |
| 437 | $endmon = 1; |
| 438 | $endday = 1; |
| 439 | $endhou = '00'; |
| 440 | $endmin = '00'; |
| 441 | $endsec = '00'; |
| 442 | |
| 443 | $stayear=$year; |
| 444 | $endyear=$year+1; |
| 445 | if($month!='') |
| 446 | { |
| 447 | $stamon = $month; |
| 448 | $endmon = ($month==12?1:$month+1); |
| 449 | $endyear = ($endmon==1?$stayear+1:$stayear); |
| 450 | } |
| 451 | if($day!='') |
| 452 | { |
| 453 | $staday = $day; |
| 454 | $endday = ($day==$j_days_in_month[$month]?1:$day+1); |
| 455 | $endmon = ($endday==1?$stamon+1:$stamon); |
| 456 | } |
| 457 | if($hour!='') |
| 458 | { |
| 459 | $stahou = $hour; |
| 460 | $endhou = ($hour==24?'00':$hour+1); |
| 461 | $endday = ($endhou=='00'?$staday+1:$staday); |
| 462 | } |
| 463 | if($minute!='') |
| 464 | { |
| 465 | $stamin=$minute; |
| 466 | $endmin=($minute==59?'00':$minute+1); |
| 467 | $endhou=($endmin=='00'?$stahou+1:$stahou); |
| 468 | } |
| 469 | if($second!='') |
| 470 | { |
| 471 | $stasec=$second; |
| 472 | $endsec=($second==59?'00':$second+1); |
| 473 | $endmin=($endsec=='00'?$stamin+1:$stamin); |
| 474 | } |
| 475 | $stadate = "$stayear-$stamon-$staday"; |
| 476 | $enddate = "$endyear-$endmon-$endday"; |
| 477 | $stadate = gregdate('Y-m-d',$stadate); |
| 478 | $enddate = gregdate('Y-m-d',$enddate); |
| 479 | $stadate.=" $stahou:$stamin:$stasec"; |
| 480 | $enddate.=" $endhou:$endmin:$endsec"; |
| 481 | $paterns = array('/YEAR\((.*?)post_date\s*\)\s*=\s*[0-9\']*/', |
| 482 | '/DAYOFMONTH\((.*?)post_date\s*\)\s*=\s*[0-9\']*/', |
| 483 | '/MONTH\((.*?)post_date\s*\)\s*=\s*[0-9\']*/', |
| 484 | '/HOUR\((.*?)post_date\s*\)\s*=\s*[0-9\']*/', |
| 485 | '/MINUTE\((.*?)post_date\s*\)\s*=\s*[0-9\']*/', |
| 486 | '/SECOND\((.*?)post_date\s*\)\s*=\s*[0-9\']*/'); |
| 487 | foreach($paterns as $ptn) |
| 488 | { |
| 489 | $where = preg_replace($ptn,'1=1',$where); |
| 490 | } |
| 491 | $prefixp = "{$wpdb->posts}."; |
| 492 | $prefixp = (strpos($where, $prefixp) === false) ? '' : $prefixp; |
| 493 | $where .= " AND {$prefixp}post_date >= '$stadate' AND {$prefixp}post_date < '$enddate' "; |
| 494 | return $where; |
| 495 | } |
| 496 | /* |
| 497 | * fix admin edit section |
| 498 | */ |
| 499 | add_action('admin_footer','parsidate_js',1); |
| 500 | |
| 501 | function parsidate_js() |
| 502 | { |
| 503 | $dirname=basename(dirname(__file__)); |
| 504 | echo "<script type='text/javascript' src='".plugins_url()."/$dirname/js/parsidate.js'></script>"; |
| 505 | } |
| 506 | /* |
| 507 | * fix search dropdownlist admin edit.php |
| 508 | */ |
| 509 | add_action('load-edit.php', 'wppd_admin_init'); |
| 510 | |
| 511 | function wppd_admin_init() |
| 512 | { |
| 513 | add_action('restrict_manage_posts','wppd_restrict_manage_posts'); |
| 514 | add_filter('posts_where', 'wp_admin_posts_where'); |
| 515 | } |
| 516 | |
| 517 | function wp_admin_posts_where($where) |
| 518 | { |
| 519 | global $wp_query; |
| 520 | if( isset($_GET['mfa']) and $_GET['mfa'] != '0' ) |
| 521 | { |
| 522 | $wp_query->query_vars['m'] = $_GET['mfa']; |
| 523 | $where = wppd_posts_where($where); |
| 524 | } |
| 525 | return $where; |
| 526 | } |
| 527 | |
| 528 | function wppd_restrict_manage_posts() |
| 529 | { |
| 530 | global $post_type, $wpdb,$persian_month_names; |
| 531 | $list = $wpdb->get_col("SELECT DISTINCT date( post_date ) AS date |
| 532 | FROM $wpdb->posts |
| 533 | WHERE post_type = '$post_type' AND post_status <> 'auto-draft' AND date( post_date )<>'0000-00-00' |
| 534 | ORDER BY post_date DESC"); |
| 535 | if ( empty($list)) |
| 536 | return; |
| 537 | $m = isset( $_GET['mfa'] ) ? (int) $_GET['mfa'] : 0; |
| 538 | |
| 539 | echo '<select name="mfa">'; |
| 540 | echo "<option ".selected( $m, 0 ,false)." value='0'>".__( 'دیدن ه� |
| 541 | ه تاریخ ها' )."</option>\n"; |
| 542 | foreach ( $list as $date ) |
| 543 | { |
| 544 | $date = parsidate('Ym',$date,'eng'); |
| 545 | $year = substr($date,0,4); |
| 546 | $month = substr($date,4,2); |
| 547 | $month=$persian_month_names[intval($month)]; |
| 548 | if($predate != $date) |
| 549 | echo "<option %s value='$date'".selected( $m, $date, false ).">$month ".fixnumber($year)."</option>\n"; |
| 550 | $predate = $date; |
| 551 | } |
| 552 | echo '</select>'; |
| 553 | } |
| 554 | //___________________________________________________persian archives _______________________________________________ |
| 555 | function wp_get_parchives($args='') |
| 556 | { |
| 557 | global $wpdb, $wp_locale,$persian_month_names; |
| 558 | $defaults = array( |
| 559 | 'type' => 'monthly', 'limit' => '', |
| 560 | 'format' => 'html', 'before' => '', |
| 561 | 'after' => '', 'show_post_count' => false, |
| 562 | 'echo' => 1, 'order' => 'DESC'); |
| 563 | |
| 564 | $r = wp_parse_args( $args, $defaults ); |
| 565 | extract( $r, EXTR_SKIP ); |
| 566 | $archive_link_m =home_url("'?m='"); |
| 567 | |
| 568 | $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"); |
| 569 | if(!empty($results)) |
| 570 | { |
| 571 | if($type=='yearly') |
| 572 | { |
| 573 | $old_date=parsidate('Y',$results[0]->date,'eng'); |
| 574 | $count=$results[0]->count; |
| 575 | $c=count($results); |
| 576 | for($i=1;$i<$c;$i++) |
| 577 | { |
| 578 | $dt=$results[$i]; |
| 579 | $date=parsidate('Y',$dt->date,'eng'); |
| 580 | if($date==$old_date) |
| 581 | $count+=$dt->count; |
| 582 | else |
| 583 | { |
| 584 | echo_yarchive($old_date,$format,$before,$count,$show_post_count); |
| 585 | $old_date=$date; |
| 586 | $count=$dt->count; |
| 587 | } |
| 588 | } |
| 589 | echo_yarchive($old_date,$format,$before,$count,$show_post_count); |
| 590 | } |
| 591 | elseif($type=='monthly') |
| 592 | { |
| 593 | $old_date=parsidate('Ym',$results[0]->date,'eng'); |
| 594 | $count=$results[0]->count; |
| 595 | $c=count($results); |
| 596 | for($i=1;$i<$c;$i++) |
| 597 | { |
| 598 | $dt=$results[$i]; |
| 599 | $date=parsidate('Ym',$dt->date,'eng'); |
| 600 | if($date==$old_date) |
| 601 | $count+=$dt->count; |
| 602 | else |
| 603 | { |
| 604 | echo_marchive($old_date,$format,$before,$count,$show_post_count); |
| 605 | $old_date=$date; |
| 606 | $count=$dt->count; |
| 607 | } |
| 608 | } |
| 609 | echo_marchive($old_date,$format,$before,$count,$show_post_count); |
| 610 | } |
| 611 | elseif($type=='daily') |
| 612 | { |
| 613 | foreach($results as $row) |
| 614 | { |
| 615 | $date = parsidate('Y,m,d',$row->date,'eng'); |
| 616 | $date=explode(',',$date); |
| 617 | if($show_post_count) |
| 618 | $count=' ('.fixnumber($row->count).')'; |
| 619 | else |
| 620 | $count = ''; |
| 621 | $text = fixnumber($date[2]).' '.$persian_month_names[intval($date[1])].' '.fixnumber($date[0]); |
| 622 | echo get_archives_link(get_day_link($date[0],$date[1],$date[2]),$text,$format, $before, $count); |
| 623 | } |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | function echo_yarchive($year,$format,$before,$count,$show_post_count) |
| 629 | { |
| 630 | if($show_post_count) |
| 631 | $count=' ('.fixnumber($count).')'; |
| 632 | else |
| 633 | $count=''; |
| 634 | echo get_archives_link(get_year_link($year),fixnumber($year), $format, $before,$count); |
| 635 | } |
| 636 | |
| 637 | function echo_marchive($old_date,$format,$before,$count,$show_post_count) |
| 638 | { |
| 639 | global $persian_month_names; |
| 640 | $year=substr($old_date,0,4); |
| 641 | $month=substr($old_date,4,2); |
| 642 | if($show_post_count) |
| 643 | $count=' ('.fixnumber($count).')'; |
| 644 | else |
| 645 | $count=''; |
| 646 | echo get_archives_link(get_month_link($year,$month),$persian_month_names[intval($month)].' '.fixnumber($year), $format, $before,$count); |
| 647 | } |
| 648 | ?> |