1 | <?php |
---|
2 | /** |
---|
3 | * Plugin Name: #9730 Test Plugin |
---|
4 | * Plugin URI: http://core.trac.wordpress.org/ticket/9730 |
---|
5 | * Description: Test Plugin to test the <a href="http://core.trac.wordpress.org/changeset/10897">date_i18n hook</a>. |
---|
6 | * Author: hakre |
---|
7 | * Version: 0.1 |
---|
8 | * Author URI: http://codex.wordpress.org/User:Hakre |
---|
9 | */ |
---|
10 | class plugin9730Test { |
---|
11 | |
---|
12 | public function __construct() { |
---|
13 | add_filter('date_i18n', array($this, 'date_i18n'), 10, 4); |
---|
14 | } |
---|
15 | |
---|
16 | /** date_i18n sample callback |
---|
17 | * |
---|
18 | * format timestamps according to the moodate standard. that is persian number in the year |
---|
19 | * I felt like a timeless beauty. |
---|
20 | * |
---|
21 | * @param string $date input date. unfiltered value provided by WP |
---|
22 | * @param string $req_format required format string. @see http://php.net/manual/en/function.date.php |
---|
23 | * @param int $unixtimestamp input timestamp (UTC value). |
---|
24 | * @param bool $gmt Whether to convert to GMT for time. Optional, default is false. |
---|
25 | * @return unknown_type |
---|
26 | */ |
---|
27 | public function date_i18n($date, $req_format, $unixtimestamp, $gmt) { |
---|
28 | |
---|
29 | $mood_year = 'in the year I felt like a timeless beauty.'; |
---|
30 | |
---|
31 | $datefunc = $gmt? 'gmdate' : 'date'; |
---|
32 | |
---|
33 | $format = $req_format; |
---|
34 | $format = preg_replace( "/([^\\\])[yY]/", "\\1" . backslashit( $mood_year ), $format ); |
---|
35 | $date = $datefunc($format, $unixtimestamp); |
---|
36 | $date = $this->do_latin_to_persian($date); |
---|
37 | |
---|
38 | return $date; |
---|
39 | } |
---|
40 | |
---|
41 | /** Converts Latin digits to Persian ones |
---|
42 | * |
---|
43 | * some functions to play with. |
---|
44 | * |
---|
45 | * @see #7753 |
---|
46 | * @param string $number |
---|
47 | * @return string |
---|
48 | */ |
---|
49 | function do_latin_to_persian($number) { |
---|
50 | $latin = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); |
---|
51 | $persian = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'); |
---|
52 | return str_replace($latin, $persian, $number); |
---|
53 | } |
---|
54 | } |
---|
55 | $plugin9730Test = new plugin9730Test(); |
---|
56 | ?> |
---|