PluginProbe ʕ •ᴥ•ʔ
پارسی دیت – Parsi Date / 4.0.0
پارسی دیت – Parsi Date v4.0.0
6.1 5.1.6 5.1.7 5.1.8 5.1.8.2 6.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.0.0-alpha 2.1 2.1.1 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0.1 2.3.0.2 2.3.1 2.3.2 2.3.3 2.3.4 3.0.1 3.0.2 3.0.3 4.0.0 4.0.1 4.0.2 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5
wp-parsidate / includes / fixes-dates.php
wp-parsidate / includes Last commit date
admin 4 years ago plugins 4 years ago widget 4 years ago fixes-archive.php 4 years ago fixes-archives.php 4 years ago fixes-calendar.php 4 years ago fixes-dates.php 4 years ago fixes-misc.php 4 years ago fixes-permalinks.php 4 years ago general.php 4 years ago install.php 4 years ago parsidate.php 4 years ago settings.php 4 years ago
fixes-dates.php
216 lines
1 <?php
2
3 defined( 'ABSPATH' ) or exit( 'No direct script access allowed' );
4
5 /**
6 * Fixes dates and convert them to Jalali date.
7 *
8 * @author Mobin Ghasempoor
9 * @package WP-Parsidate
10 * @subpackage Fixes/Dates
11 */
12
13 global $wpp_settings;
14
15 if ( get_locale() == 'fa_IR' && wpp_is_active( 'persian_date' ) ) {
16 add_filter( 'the_time', 'wpp_fix_post_time', 10, 2 );
17 add_filter( 'the_date', 'wpp_fix_post_date', 10, 2 );
18 add_filter( 'get_the_time', 'wpp_fix_post_date', 10, 2 );
19 add_filter( 'get_the_date', 'wpp_fix_post_date', 100, 2 );
20 add_filter( 'get_comment_time', 'wpp_fix_comment_time', 10, 2 );
21 add_filter( 'get_comment_date', 'wpp_fix_comment_date', 10, 2 );
22 //add_filter('get_post_modified_time', 'wpp_fix_post_modified_time', 10, 3);
23 add_filter( 'date_i18n', 'wpp_fix_i18n', 10, 4 );
24 add_filter( 'wp_date', 'wpp_fix_i18n', 10, 4 );
25 }
26
27 /**
28 * Fixes post date and returns to Jalali format
29 *
30 * @param string $time Post time
31 * @param string $format Date format
32 *
33 * @return string Formatted date
34 */
35 function wpp_fix_post_date( $time, $format = '' ) {
36 global $post;
37
38 // It seems some plugin like acf does not exist $post.
39 if ( empty( $post ) ) {
40 return $time;
41 }
42
43 if ( empty( $format ) ) {
44 $format = get_option( 'date_format' );
45 }
46
47 if ( ! disable_wpp() ) {
48 return date( $format, strtotime( $post->post_modified ) );
49 }
50
51 return parsidate( $format, date( 'Y-m-d', strtotime( $post->post_date ) ), ! wpp_is_active( 'conv_dates' ) ? 'eng' : 'per' );
52 }
53
54 /**
55 * Fixes post date and returns to Jalali format
56 *
57 * @param string $time Post time
58 * @param string $format Date format
59 * @param bool $gmt retrieve the GMT time. Default false.
60 *
61 * @return string Formatted date
62 * @author Parsa Kafi
63 */
64 function wpp_fix_post_modified_time( $time, $format, $gmt ) {
65 if ( ! disable_wpp() ) {
66 return $time;
67 }
68
69 return parsidate( $format, $time, ! wpp_is_active( 'conv_dates' ) ? 'eng' : 'per' );
70 }
71
72 /**
73 * Fixes post time and returns to Jalali format
74 *
75 * @param string $time Post time
76 * @param string $format Date format
77 *
78 * @return string Formatted date
79 */
80 function wpp_fix_post_time( $time, $format = '' ) {
81 global $post;
82
83 if ( empty( $post ) ) {
84 return $time;
85 }
86
87 if ( empty( $format ) ) {
88 $format = get_option( 'time_format' );
89 }
90 if ( ! disable_wpp() ) {
91 return date( $format, strtotime( $post->post_date ) );
92 }
93
94 return parsidate( $format, $post->post_date, wpp_is_active( 'conv_dates' ) ? 'eng' : 'per' );
95 }
96
97 /**
98 * Fixes comment time and returns to Jalali format
99 *
100 * @param string $time Comment time
101 * @param string $format Date format
102 *
103 * @return string Formatted date
104 */
105 function wpp_fix_comment_time( $time, $format = '' ) {
106 global $comment;
107
108 if ( empty( $comment ) ) {
109 return $time;
110 }
111
112 if ( empty( $format ) ) {
113 $format = get_option( 'time_format' );
114 }
115 if ( ! disable_wpp() ) {
116 return date( $format, strtotime( $comment->comment_date ) );
117 }
118
119 return parsidate( $format, $comment->comment_date, ! wpp_is_active( 'conv_dates' ) ? 'eng' : 'per' );
120 }
121
122 /**
123 * Fixes comment date and returns in Jalali format
124 *
125 * @param string $time Comment time
126 * @param string $format Date format
127 *
128 * @return string Formatted date
129 */
130 function wpp_fix_comment_date( $time, $format = '' ) {
131 global $comment;
132
133 if ( empty( $comment ) ) {
134 return $time;
135 }
136
137 if ( empty( $format ) ) {
138 $format = get_option( 'date_format' );
139 }
140 if ( ! disable_wpp() ) {
141 return date( $format, strtotime( $comment->comment_date ) );
142 }
143
144 return parsidate( $format, $comment->comment_date, ! wpp_is_active( 'conv_dates' ) ? 'eng' : 'per' );
145 }
146
147 /**
148 * Fixes i18n date formatting and convert them to Jalali
149 *
150 * @param string $date Formatted date string.
151 * @param string $format Format to display the date.
152 * @param int $timestamp A sum of Unix timestamp and timezone offset in seconds.
153 * Might be without offset if input omitted timestamp but requested GMT.
154 * @param bool $gmt Whether to use GMT timezone. Only applies if timestamp was not provided.
155 * Default false.
156 *
157 * @return string Formatted time
158 */
159 function wpp_fix_i18n( $date, $format, $timestamp, $gmt ) {
160 global $post;
161 $post_id = ! empty( $post ) ? $post->ID : null;
162
163 if ( ! disable_wpp() ) {
164 return $format;
165 }
166
167 if ( $post_id != null && get_post_type( $post_id ) == 'shop_order' && isset( $_GET['post'] ) ) // TODO: Remove after implement convert date for woocommerce
168 {
169 return $date;
170 } else {
171 return parsidate( $format, $timestamp, ! wpp_is_active( 'conv_dates' ) ? 'eng' : 'per' );
172 }
173 }
174
175 /**
176 * Convert date to Jalali
177 *
178 * @param $date
179 * @param $format
180 * @param $timestamp
181 * @param $timezone
182 *
183 * @return int|mixed|string
184 */
185 function wpp_fix_wp_date( $date, $format, $timestamp, $timezone ) {
186 if ( ! disable_wpp() ) {
187 return $format;
188 }
189
190 return parsidate( $format, $timestamp, ! wpp_is_active( 'conv_dates' ) ? 'eng' : 'per' );
191 }
192
193 function array_key_exists_r( $needle, $haystack, $value = null ) {
194 $result = array_key_exists( $needle, $haystack );
195
196 if ( $result ) {
197 if ( $value != null && $haystack[ $needle ] ) {
198 return 1;
199 }
200
201 return true;
202 }
203
204 foreach ( $haystack as $v ) {
205 if ( is_array( $v ) || is_object( $v ) ) {
206 $result = array_key_exists_r( $needle, $v );
207 }
208
209 if ( $result ) {
210 return $result;
211 }
212 }
213
214 return $result;
215 }
216