Changeset 1133053
- Timestamp:
- 04/12/2015 08:25:43 AM (11 years ago)
- Location:
- wp-farsi
- Files:
-
- 5 added
- 3 edited
-
tags/2.3.3 (added)
-
tags/2.3.3/index.php (added)
-
tags/2.3.3/license.html (added)
-
tags/2.3.3/pdate.php (added)
-
tags/2.3.3/wp-farsi.php (added)
-
trunk/pdate.php (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/wp-farsi.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-farsi/trunk/pdate.php
r1107737 r1133053 1 1 <?php 2 2 # https://github.com/vahid-sohrabloo/Pdate 3 function wpfa_date($c,$d=NULL){ $e=array(0,31,31,31,31,31,31,30,30,30,30,30,29);$f=array('شنبه','یکشنبه','دوشنبه','سه شنبه','چهارشنبه','پنج شنبه','جمعه');$g=array('','فروردین','اردیبهشت','خرداد','تیر','مرداد','شهریور','مهر','آبان','آذر','دی','بهمن','اسفند');if(!$d){$d=time();}list($h,$j,$k,$l)=explode('-',date('Y-m-d-w',$d));list($m,$n,$o)=gregorian2jalali($h,$j,$k);$p=($l+1);if($p>=7){$p=0;}if($c=='\\'){$c='//';}$q=strlen($c);$r=0;$s='';while($r<$q){$t=$c{$r};if($t=='\\'){$s.=$c{++$r};$r++;continue;}switch($t){case 'd':$s.=(($o<10)?('0'.$o):$o);break;case 'D':$s.=substr($f[$p],0,2);break;case 'j':$s.=$o;break;case 'l':$s.=$f[$p];break;case 'N':$s.=$p+1;break;case 'w':$s.=$p;break;case 'z':$s.=_DayOfYear($n,$o);break;case 'S':$s.='م';break;case 'W':$s.=ceil(_DayOfYear($n,$o)/7);break;case 'F':$s.=$g[$n];break;case 'm':$s.=(($n<10)?('0'.$n):$n);break;case 'M':$s.=substr($g[$n],0,6);break;case 'n':$s.=$n;break;case 't':$s.=((_isKabise($m)&&($n==12))?30:$e[$n]);break;case 'L':$s.=(int)_isKabise($m);break;case 'Y':case 'o':$s.=$m;break;case 'y':$s.=substr($m,2);break;case 'a':case 'A':if(date('a',$d)=='am'){$s.=(($t=='a')?'ق.ظ':'قبل از ظهر');}else{$s.=(($t=='a')?'ب.ظ':'بعد از ظهر');}break;case 'B':case 'g':case 'G':case 'h':case 'H':case 's':case 'u':case 'i':case 'e':case 'I':case 'O':case 'P':case 'T':case 'Z':$s.=date($t,$d);break;case 'c':$s.=($m.'-'.$n.'-'.$o.' '.date('H:i:s P',$d));break;case 'r':$s.=(substr($f[$p],0,2).'، '.$o.' '.substr($g[$n],0,6).' '.$m.' '.date('H::i:s P',$d));break;case 'U':$s.=$d;break;default:$s.=$t;}$r++;}return $s;}function _DayOfYear($n,$o){$e=array(0,31,31,31,31,31,31,30,30,30,30,30,29);$u=0;for($r=1;$r<$n;$r++){$u+=$e[$r];}return($u+$o);}function _isKabise($v){$w=($v%33);if(($w==1)or($w==5)or($w==9)or($w==13)or($w==17)or($w==22)or($w==26)or($w==30)){return 1;}return 0;}function _div($x,$y){return (int)($x/$y);}function gregorian2jalali($z,$aa,$bb){$cc=array(31,28,31,30,31,30,31,31,30,31,30,31);$dd=array(31,31,31,31,31,31,30,30,30,30,30,29);$ee=$z-1600;$ff=$aa-1;$gg=(365*$ee+_div($ee+3,4)-_div($ee+99,100)+_div($ee+399,400));for($r=0;$r<$ff;++$r){$gg+=$cc[$r];}if($ff>1&&(($ee%4==0&&$ee%100!=0)||($ee%400==0)))$gg++;$gg+=$bb-1;$hh=$gg-79;$ii=_div($hh,12053);$hh=$hh%12053;$jj=(979+33*$ii+4*_div($hh,1461));$hh%=1461;if($hh>=366){$jj+=_div($hh-1,365);$hh=($hh-1)%365;}for($r=0;($r<11&&$hh>=$dd[$r]);++$r){$hh-=$dd[$r];}return array($jj,$r+1,$hh+1);}function jalali2gregorian($kk,$ll,$mm){$cc=array(31,28,31,30,31,30,31,31,30,31,30,31);$dd=array(31,31,31,31,31,31,30,30,30,30,30,29);$jj=$kk-979;$nn=$ll-1;$hh=(365*$jj+_div($jj,33)*8+_div($jj%33+3,4));for($r=0;$r<$nn;++$r){$hh+=$dd[$r];}$hh+=$mm-1;$gg=$hh+79;$ee=(1600+400*_div($gg,146097));$gg=$gg%146097;$oo=1;if($gg>=36525){$gg--;$ee+=(100*_div($gg,36524));$gg=$gg%36524;if($gg>=365){$gg++;}else{$oo=0;}}$ee+=(4*_div($gg,1461));$gg%=1461;if($gg>=366){$oo=0;$gg--;$ee+=_div($gg,365);$gg=($gg%365);}for($r=0;$gg>=($cc[$r]+($r==1&&$oo));$r++){$gg-=($cc[$r]+($r==1&&$oo));}return array($ee,$r+1,$gg+1);}3 function wpfa_date($c,$d=NULL){static $e=array(0,31,31,31,31,31,31,30,30,30,30,30,29);static $f=array('شنبه','یکشنبه','دوشنبه','سه شنبه','چهارشنبه','پنج شنبه','جمعه');static $g=array('','فروردین','اردیبهشت','خرداد','تیر','مرداد','شهریور','مهر','آبان','آذر','دی','بهمن','اسفند');if(!$d){$d=time();}list($h,$j,$k,$l)=explode('-',date('Y-m-d-w',$d));list($m,$n,$o)=gregorian2jalali($h,$j,$k);$p=($l+1);if($p>=7){$p=0;}if($c=='\\'){$c='//';}$q=strlen($c);$r=0;$s='';while($r<$q){$t=$c{$r};if($t=='\\'){$s.=$c{++$r};$r++;continue;}switch($t){case 'd':$s.=(($o<10)?('0'.$o):$o);break;case 'D':$s.=substr($f[$p],0,2);break;case 'j':$s.=$o;break;case 'l':$s.=$f[$p];break;case 'N':$s.=$p+1;break;case 'w':$s.=$p;break;case 'z':$s.=_DayOfYear($n,$o);break;case 'S':$s.='م';break;case 'W':$s.=ceil(_DayOfYear($n,$o)/7);break;case 'F':$s.=$g[$n];break;case 'm':$s.=(($n<10)?('0'.$n):$n);break;case 'M':$s.=substr($g[$n],0,6);break;case 'n':$s.=$n;break;case 't':$s.=((_isKabise($m)&&($n==12))?30:$e[$n]);break;case 'L':$s.=(int)_isKabise($m);break;case 'Y':case 'o':$s.=$m;break;case 'y':$s.=substr($m,2);break;case 'a':case 'A':if(date('a',$d)=='am'){$s.=(($t=='a')?'ق.ظ':'قبل از ظهر');}else{$s.=(($t=='a')?'ب.ظ':'بعد از ظهر');}break;case 'B':case 'g':case 'G':case 'h':case 'H':case 's':case 'u':case 'i':case 'e':case 'I':case 'O':case 'P':case 'T':case 'Z':$s.=date($t,$d);break;case 'c':$s.=($m.'-'.$n.'-'.$o.' '.date('H:i:s P',$d));break;case 'r':$s.=(substr($f[$p],0,2).'، '.$o.' '.substr($g[$n],0,6).' '.$m.' '.date('H::i:s P',$d));break;case 'U':$s.=$d;break;default:$s.=$t;}$r++;}return $s;}function _DayOfYear($n,$o){static $e=array(0,31,31,31,31,31,31,30,30,30,30,30,29);$u=0;for($r=1;$r<$n;$r++){$u+=$e[$r];}return($u+$o);}function _isKabise($v){$w=($v%33);if(($w==1)or($w==5)or($w==9)or($w==13)or($w==17)or($w==22)or($w==26)or($w==30)){return 1;}return 0;}function _div($x,$y){return (int)($x/$y);}function gregorian2jalali($z,$aa,$bb){static $cc=array(31,28,31,30,31,30,31,31,30,31,30,31);static $dd=array(31,31,31,31,31,31,30,30,30,30,30,29);$ee=$z-1600;$ff=$aa-1;$gg=(365*$ee+_div($ee+3,4)-_div($ee+99,100)+_div($ee+399,400));for($r=0;$r<$ff;++$r){$gg+=$cc[$r];}if($ff>1&&(($ee%4==0&&$ee%100!=0)||($ee%400==0)))$gg++;$gg+=$bb-1;$hh=$gg-79;$ii=_div($hh,12053);$hh=$hh%12053;$jj=(979+33*$ii+4*_div($hh,1461));$hh%=1461;if($hh>=366){$jj+=_div($hh-1,365);$hh=($hh-1)%365;}for($r=0;($r<11&&$hh>=$dd[$r]);++$r){$hh-=$dd[$r];}return array($jj,$r+1,$hh+1);}function jalali2gregorian($kk,$ll,$mm){static $cc=array(31,28,31,30,31,30,31,31,30,31,30,31);static $dd=array(31,31,31,31,31,31,30,30,30,30,30,29);$jj=$kk-979;$nn=$ll-1;$hh=(365*$jj+_div($jj,33)*8+_div($jj%33+3,4));for($r=0;$r<$nn;++$r){$hh+=$dd[$r];}$hh+=$mm-1;$gg=$hh+79;$ee=(1600+400*_div($gg,146097));$gg=$gg%146097;$oo=1;if($gg>=36525){$gg--;$ee+=(100*_div($gg,36524));$gg=$gg%36524;if($gg>=365){$gg++;}else{$oo=0;}}$ee+=(4*_div($gg,1461));$gg%=1461;if($gg>=366){$oo=0;$gg--;$ee+=_div($gg,365);$gg=($gg%365);}for($r=0;$gg>=($cc[$r]+($r==1&&$oo));$r++){$gg-=($cc[$r]+($r==1&&$oo));}return array($ee,$r+1,$gg+1);} -
wp-farsi/trunk/readme.txt
r1121207 r1133053 44 44 == Changelog == 45 45 46 = 2.3.3 = 47 * Improved filter date 48 * Improved Patch func 49 * Added load order 50 * Fixed Pdate lib 51 * Fixed bugs 52 46 53 = 2.0.1 = 47 54 * Tiny modification -
wp-farsi/trunk/wp-farsi.php
r1121207 r1133053 3 3 Plugin Name: WP-Farsi 4 4 Plugin URI: http://wordpress.org/extend/plugins/wp-farsi 5 Description: افزونه مبدل تاریخ میلادی به شمسی، مکمل وسازگار با افزونههای مشابه.5 Description: افزونه مبدل تاریخ میلادی وردپرس به خورشیدی، فارسی ساز، مبدل اعداد انگلیسی به فارسی، رفع مشکل هاست با زبان و تاریخ، سازگار با افزونههای مشابه. 6 6 Author: Ali.Dbg 7 7 Author URI: https://github.com/alidbg/wp-farsi 8 Version: 2. 0.18 Version: 2.3.3 9 9 License: GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html) 10 10 */ 11 11 12 defined('ABSPATH') ||exit;12 defined('ABSPATH') or exit; 13 13 define('WPFA_NUMS', get_option('wpfa_nums')); 14 15 if (extension_loaded('mbstring')) {16 mb_internal_encoding('UTF-8');17 mb_language('neutral');18 mb_http_output('UTF-8');19 } elseif (function_exists('ini_set')) {20 ini_set('default_charset', 'UTF-8');21 ini_set('date.timezone', 'UTC');22 }23 24 14 require_once plugin_dir_path(__FILE__) . 'pdate.php'; 25 26 function numbers_fa($str = '') {27 return str_replace(range(0, 9), preg_split("//u", "۰۱۲۳۴۵۶۷۸۹", 10, 1), $str);28 }29 15 30 16 function wpfa_activate() { … … 32 18 update_option('start_of_week', '6'); 33 19 update_option('timezone_string', 'Asia/Tehran'); 34 if(WPFA_NUMS === false) add_option('wpfa_nums', 'on'); 35 $l = ABSPATH . 'wp-admin/includes/translation-install.php'; 36 if (file_exists($l)) {require_once($l);wp_download_language_pack('fa_IR');} 20 if (WPFA_NUMS === false) add_option('wpfa_nums', 'on'); 21 $inc = ABSPATH . 'wp-admin/includes/translation-install.php'; 22 if (file_exists($inc)){ 23 require_once($inc); 24 wp_download_language_pack('fa_IR'); 25 } 37 26 } 38 27 39 function wpfa_init() { 40 global $wp_locale; 41 $wp_locale->number_format['thousands_sep'] = ","; 42 $wp_locale->number_format['decimal_point'] = "."; 43 if (isset($_POST['aa'], $_POST['mm'], $_POST['jj'])) 44 list($_POST['aa'], $_POST['mm'], $_POST['jj']) = jalali2gregorian(zeroise(intval($_POST['aa']), 4), zeroise(intval($_POST['mm']), 2), zeroise(intval($_POST['jj']), 2)); 28 function wpfa_load_first(){ 29 $plugins = get_option('active_plugins'); 30 $path = plugin_basename(__FILE__); 31 if (is_array($plugins) and $plugins[0] !== $path) { 32 $key = array_search($path, $plugins); 33 array_splice($plugins, $key, 1); 34 array_unshift($plugins, $path); 35 update_option('active_plugins', $plugins); 36 } 45 37 } 46 38 47 39 function wpfa_patch_func($patch = false) { 48 $f = ABSPATH . 'wp-includes/functions.php'; 49 if (!is_writable($f)) return; 50 $re = "/(else\\s+return\\s+(date.*[(]))/"; 51 $src = file_get_contents($f); 52 if (preg_match($re, $src, $match) === 1){ 53 if ($match[2] === "date(" && $patch) 54 file_put_contents($f, str_replace($match[1], "else\n\t\treturn date_i18n(", $src)); 55 elseif ($match[2] === "date_i18n(" && !$patch) 56 file_put_contents($f, str_replace($match[1], "else\n\t\treturn date(", $src)); 57 } 40 $file = ABSPATH . 'wp-includes/functions.php'; 41 if (!is_writable($file)) return; 42 $src = file_get_contents($file); 43 if (preg_match_all('/else\s+return\s+(date.*)[(]/', $src, $match) === 1) 44 file_put_contents($file, str_replace($match[0][0], (rtrim($match[1][0]) === "date" && $patch ? "else\n\t\treturn date_i18n(" : "else\n\t\treturn date("), $src)); 58 45 } 59 46 60 function timestampdiv() { ?>61 <script type='text/javascript'>62 var c = ("۰,۱,۲,۳,۴,۵,۶,۷,۸,۹,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec").split(",");63 var d = ("0,1,2,3,4,5,6,7,8,9,فرو,ارد,خرد,تیر,مرد,شهر,مهر,آبا,آذر,دی,بهم,اسف").split(",");64 jQuery(document).ready(function(){47 function timestampdiv() { 48 ?><script type='text/javascript'> 49 var c = ("۰,۱,۲,۳,۴,۵,۶,۷,۸,۹,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec").split(","); 50 var d = ("0,1,2,3,4,5,6,7,8,9,فرو,ارد,خرد,تیر,مرد,شهر,مهر,آبا,آذر,دی,بهم,اسف").split(","); 51 jQuery(document).ready(function(){ 65 52 jQuery("#timestampdiv,.timestamp-wrap,.inline-edit-date,.jj,.mm,.aa,.hh,.mn,.ss").html(function(a,b){ 66 53 jQuery.each(c,function(a,c){b=b.replace(new RegExp(c,'g'),d[a])});return b}); 67 jQuery("#mm option[value='"+jQuery('#hidden_mm').val()+"']").attr("selected","selected") 68 }); 69 </script> 70 <?php 54 jQuery("#mm option[value='"+jQuery('#hidden_mm').val()+"']").attr("selected","selected")}); 55 </script><?php 56 } 57 58 function numbers_fa( $string ) { 59 static $en_nums = array('0','1','2','3','4','5','6','7','8','9'); 60 static $fa_nums = array('۰','۱','۲','۳','۴','۵','۶','۷','۸','۹'); 61 return str_replace($en_nums, $fa_nums, $string); 71 62 } 72 63 … … 77 68 } 78 69 79 function wpfa_date_i18n( $g = '', $f = '', $t = '') {80 $d = wpfa_date($f, intval($t));70 function wpfa_date_i18n( $g, $f, $t ) { 71 $d = wpfa_date($f, intval($t)); 81 72 return WPFA_NUMS === "on" ? numbers_fa($d) : $d; 82 }83 84 function wpfa_load() {85 foreach (array(86 'date_i18n', 'get_post_time', 'get_comment_date', 'get_comment_time', 'get_the_date', 'the_date', 'get_the_time', 'the_time',87 'get_the_modified_date', 'the_modified_date', 'get_the_modified_time', 'the_modified_time', 'get_post_modified_time', 'number_format_i18n'88 ) as $i) remove_all_filters($i);89 add_filter('date_i18n', 'wpfa_date_i18n', 10, 3);90 if (WPFA_NUMS === "on") add_filter('number_format_i18n', 'numbers_fa');91 if (mysql2date("Y m", "2014 12", true) !== mysql2date("Y m", "2014 12", false)) wpfa_patch_func(true);92 73 } 93 74 … … 99 80 } 100 81 101 register_activation_hook(__FILE__, 'wpfa_activate'); 102 register_deactivation_hook(__FILE__, 'wpfa_patch_func'); 82 function wpfa_apply_filters() { 83 ini_set('default_charset', 'UTF-8'); 84 ini_set('date.timezone', 'UTC'); 85 if (extension_loaded('mbstring')) { 86 mb_internal_encoding('UTF-8'); 87 mb_language('neutral'); 88 mb_http_output('UTF-8'); 89 } 90 foreach (array( 91 'date_i18n', 'get_post_time', 'get_comment_date', 'get_comment_time', 'get_the_date', 'the_date', 'get_the_time', 'the_time', 92 'get_the_modified_date', 'the_modified_date', 'get_the_modified_time', 'the_modified_time', 'get_post_modified_time', 'number_format_i18n' 93 ) as $i) remove_all_filters($i); 94 add_filter('date_i18n', 'wpfa_date_i18n', 10, 3); 95 if (WPFA_NUMS === "on") 96 add_filter('number_format_i18n', 'numbers_fa'); 97 } 98 99 function wpfa_init() { 100 global $wp_locale; 101 $wp_locale->number_format['thousands_sep'] = ","; 102 $wp_locale->number_format['decimal_point'] = "."; 103 if (isset($_POST['aa'], $_POST['mm'], $_POST['jj'])) 104 list($_POST['aa'], $_POST['mm'], $_POST['jj']) = jalali2gregorian(zeroise(intval($_POST['aa']), 4), zeroise(intval($_POST['mm']), 2), zeroise(intval($_POST['jj']), 2)); 105 wpfa_load_first(); 106 if (numbers_fa(mysql2date("Y", "2015", 0)) !== "۱۳۹۴") 107 wpfa_patch_func(true); 108 } 109 110 wpfa_apply_filters(); 103 111 add_action('init', 'wpfa_init'); 104 112 add_action('admin_init', 'wpfa_nums'); 105 113 add_action('admin_footer', 'timestampdiv'); 106 add_action('wp_print_scripts', 'dreg_jsfa', 98); 107 add_action('plugins_loaded', 'wpfa_load', 98); 114 add_action('wp_print_scripts', 'dreg_jsfa', 900); 115 add_action('wp_loaded', 'wpfa_apply_filters', 900); 116 register_activation_hook(__FILE__, 'wpfa_activate'); 117 register_deactivation_hook(__FILE__, 'wpfa_patch_func');
Note: See TracChangeset
for help on using the changeset viewer.