-
Notifications
You must be signed in to change notification settings - Fork 0
/
hacks.php
336 lines (293 loc) · 12.2 KB
/
hacks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<?php
/* -------------------------------------
* MISSING WORDPRESS FUNCTIONS
* ------------------------------------- */
/**
* Retrieve the date that the last page was published.
*
* The server timezone is the default and is the difference between GMT and
* server time. The 'blog' value is the date when the last post was posted. The
* 'gmt' is when the last post was posted in GMT formatted date.
*
* Variation of get_lastpostdate defined in wp-includes/post.php since 0.71
*
* @uses apply_filters() Calls 'get_lastpagedate' filter
*
* @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
* @return string The date of the last post.
if( !function_exists('get_lastpagedate') ) {
function get_lastpagedate($timezone = 'server') {
return apply_filters( 'get_lastpagedate', _get_time( $timezone, 'date', 'page' ), $timezone );
}
} */
/**
* Retrieve last page modified date depending on timezone.
*
* The server timezone is the default and is the difference between GMT and
* server time. The 'blog' value is just when the last post was modified. The
* 'gmt' is when the last post was modified in GMT time.
*
* Variation of get_lastpostmodified defined in wp-includes/post.php since 1.2.0
*
* @uses apply_filters() Calls 'get_lastpagemodified' filter
*
* @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
* @return string The date the post was last modified.
if( !function_exists('get_lastpagemodified') ) {
function get_lastpagemodified($timezone = 'server') {
$lastpagemodified = _get_time( $timezone, 'modified', 'page' );
$lastpagedate = get_lastpagedate($timezone);
if ( $lastpagedate > $lastpagemodified )
$lastpagemodified = $lastpagedate;
return apply_filters( 'get_lastpagemodified', $lastpagemodified, $timezone );
}
} */
/**
* Retrieve the date that the first post was published.
*
* The server timezone is the default and is the difference between GMT and
* server time. The 'blog' value is the date when the last post was posted. The
* 'gmt' is when the last post was posted in GMT formatted date.
*
* Reverse of get_lastpostdate defined in wp-includes/post.php since 0.71
*
* @uses apply_filters() Calls 'get_firstpostdate' filter
*
* @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
* @return string The date of the last post.
if( !function_exists('get_firstpostdate') ) {
function get_firstpostdate($timezone = 'server') {
return apply_filters( 'get_firstpostdate', _get_time( $timezone, 'date', 'post', 'first' ), $timezone );
}
} */
/**
* Retrieve the date that the first page was published.
*
* The server timezone is the default and is the difference between GMT and
* server time. The 'blog' value is the date when the last post was posted. The
* 'gmt' is when the last post was posted in GMT formatted date.
*
* Adaptation of get_firstpostdate defined in this file
*
* @uses apply_filters() Calls 'get_firstpagedate' filter
*
* @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
* @return string The date of the last post.
if( !function_exists('get_firstpagedate') ) {
function get_firstpagedate($timezone = 'server') {
return apply_filters( 'get_firstpagedate', _get_time( $timezone, 'date', 'page', 'first' ), $timezone );
}
} */
/**
* Retrieve first post modified date depending on timezone.
*
* The server timezone is the default and is the difference between GMT and
* server time. The 'blog' value is the date when the last post was posted. The
* 'gmt' is when the last post was posted in GMT formatted date.
*
* Reverse of get_lastpostmodified defined in wp-includes/post.php since WP 1.2.0
*
* @uses apply_filters() Calls 'get_firstpostmodified' filter
*
* @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
* @return string The date of the oldest modified post.
if( !function_exists('get_firstpostmodified') ) {
function get_firstpostmodified($timezone = 'server') {
$firstpostmodified = _get_time( $timezone, 'modified', 'post', 'first' );
$firstpostdate = get_firstpostdate($timezone);
if ( $firstpostdate > $firstpostmodified )
$firstpostmodified = $firstpostdate;
return apply_filters( 'get_firstpostmodified', $firstpostmodified, $timezone );
}
} */
/**
* Retrieve first page modified date depending on timezone.
*
* The server timezone is the default and is the difference between GMT and
* server time. The 'blog' value is the date when the last post was posted. The
* 'gmt' is when the last post was posted in GMT formatted date.
*
* Variation of get_firstpostmodified defined in this file
*
* @uses apply_filters() Calls 'get_firstpagemodified' filter
*
* @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
* @return string The date of the oldest modified page.
if( !function_exists('get_firstpagemodified') ) {
function get_firstpagemodified($timezone = 'server') {
$firstpagemodified = _get_time( $timezone, 'modified', 'page', 'first' );
$firstpagedate = get_firstpagedate($timezone);
if ( $firstpagedate > $firstpagemodified )
$firstpagemodified = $firstpagedate;
return apply_filters( 'get_firstpagemodified', $firstpagemodified, $timezone );
}
} */
/**
* Retrieve the date that the first post/page was published.
*
* The server timezone is the default and is the difference between GMT and
* server time. The 'blog' value is the date when the last post was posted. The
* 'gmt' is when the last post was posted in GMT formatted date.
*
* @uses apply_filters() Calls 'get_firstdate' filter
*
* @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
* @param string $post_type Post type to check.
* @return string The date of the last post.
*/
if( !function_exists('get_firstdate') ) {
function get_firstdate($timezone = 'server', $post_type = 'any') {
return apply_filters( 'get_firstdate', _get_time( $timezone, 'date', $post_type, 'first' ), $timezone );
}
}
/**
* Retrieve first post/page modified date depending on timezone.
*
* The server timezone is the default and is the difference between GMT and
* server time. The 'blog' value is the date when the last post was posted. The
* 'gmt' is when the last post was posted in GMT formatted date.
*
* @uses apply_filters() Calls 'get_firstmodified' filter
*
* @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
* @return string The date of the oldest modified post or page.
if( !function_exists('get_firstmodified') ) {
function get_firstmodified($timezone = 'server') {
$firstmodified = _get_time( $timezone, 'modified', 'any', 'first' );
$firstdate = get_firstdate($timezone);
if ( $firstdate > $firstmodified )
$firstmodified = $firstdate;
return apply_filters( 'get_firstmodified', $firstmodified, $timezone );
}
} */
/**
* Retrieve the date that the last post/page was published.
*
* The server timezone is the default and is the difference between GMT and
* server time. The 'blog' value is the date when the last post was posted. The
* 'gmt' is when the last post was posted in GMT formatted date.
*
* @uses apply_filters() Calls 'get_lastdate' filter
*
* @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
* @return string The date of the last post.
*/
if( !function_exists('get_lastdate') ) {
function get_lastdate($timezone = 'server', $post_type = 'any', $m = false) {
return apply_filters( 'get_lastdate', _get_time( $timezone, 'date', $post_type, 'last', $m ), $timezone );
}
}
/**
* Retrieve last post/page modified date depending on timezone.
*
* The server timezone is the default and is the difference between GMT and
* server time. The 'blog' value is the date when the last post was posted. The
* 'gmt' is when the last post was posted in GMT formatted date.
*
* @uses apply_filters() Calls 'get_lastmodified' filter
*
* @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
* @return string The date of the oldest modified post.
*/
if( !function_exists('get_lastmodified') ) {
function get_lastmodified($timezone = 'server', $post_type = 'any', $m = false) {
//$lastmodified = _get_time( $timezone, 'modified', $post_type, 'last', $m );
//$lastdate = get_lastdate($timezone, $post_type, $m);
//if ( $lastdate > $lastmodified )
// $lastmodified = $lastdate;
return apply_filters( 'get_lastmodified', _get_time( $timezone, 'modified', $post_type, 'last', $m ), $timezone );
}
}
/**
* Retrieve first or last post type date data based on timezone.
* Variation of function _get_last_post_time
*
* @access private
*
* @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
* @param string $field Field to check. Can be 'date' or 'modified'.
* @param string $post_type Post type to check. Defaults to 'any'.
* @param string $which Which to check. Can be 'first' or 'last'. Defaults to 'last'.
* @return string The date.
*/
if( !function_exists('_get_time') ) {
function _get_time( $timezone, $field, $post_type = 'any', $which = 'last', $m = 0 ) {
global $wpdb;
if ( !in_array( $field, array( 'date', 'modified' ) ) )
return false;
$timezone = strtolower( $timezone );
$order = ( $which == 'last' ) ? 'DESC' : 'ASC';
$key = ( $post_type == 'any' ) ? "{$which}post{$field}{$m}:$timezone" : "{$which}posttype{$post_type}{$field}{$m}:$timezone";
$date = wp_cache_get( $key, 'timeinfo' );
if ( !$date ) {
$add_seconds_server = date('Z');
if ( $post_type == 'any' ) {
$post_types = get_post_types( array( 'public' => true ) );
array_walk( $post_types, array( &$wpdb, 'escape_by_ref' ) );
$post_types = "'" . implode( "', '", $post_types ) . "'";
} elseif ( is_array($post_type) ) {
$types = get_post_types( array( 'public' => true ) );
foreach ( $post_type as $type )
if ( !in_array( $type, $types ) )
return false;
array_walk( $post_type, array( &$wpdb, 'escape_by_ref' ) );
$post_types = "'" . implode( "', '", $post_type ) . "'";
} else {
if ( !in_array( $post_type, get_post_types( array( 'public' => true ) ) ) )
return false;
$post_types = "'" . addslashes($post_type) . "'";
}
$where = "$wpdb->posts.post_status='publish' AND $wpdb->posts.post_type IN ({$post_types}) AND $wpdb->posts.post_date_gmt ";
// If a month is specified in the querystring, load that month
$m = preg_replace('|[^0-9]|', '', $m);
if ( !empty($m) ) {
$where .= " AND YEAR($wpdb->posts.post_date)=" . substr($m, 0, 4);
if ( strlen($m) > 5 )
$where .= " AND MONTH($wpdb->posts.post_date)=" . substr($m, 4, 2);
}
switch ( $timezone ) {
case 'gmt':
$date = $wpdb->get_var("SELECT post_{$field}_gmt FROM $wpdb->posts WHERE $where ORDER BY $wpdb->posts.post_{$field}_gmt {$order} LIMIT 1");
break;
case 'blog':
$date = $wpdb->get_var("SELECT post_{$field} FROM $wpdb->posts WHERE $where ORDER BY $wpdb->posts.post_{$field}_gmt {$order} LIMIT 1");
break;
case 'server':
$date = $wpdb->get_var("SELECT DATE_ADD(post_{$field}_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE $where ORDER BY $wpdb->posts.post_{$field}_gmt {$order} LIMIT 1");
break;
}
if ( $date )
wp_cache_set( $key, $date, 'timeinfo' );
}
return $date;
}
}
/* By gunter [dot] sammet [at] gmail [dot] com http://www.php.net/manual/en/function.htmlentities.php#88169 */
$entity_custom_from = false;
$entity_custom_to = false;
function html_entity_decode_encode_rss($data) {
global $entity_custom_from, $entity_custom_to;
if(!is_array($entity_custom_from) || !is_array($entity_custom_to)) {
$array_position = 0;
foreach (get_html_translation_table(HTML_ENTITIES) as $key => $value) {
switch ($value) {
case ' ':
break;
case '>':
case '<':
case '"':
case ''':
case '&':
$entity_custom_from[$array_position] = $key;
$entity_custom_to[$array_position] = $value;
$array_position++;
break;
default:
$entity_custom_from[$array_position] = $value;
$entity_custom_to[$array_position] = $key;
$array_position++;
}
}
}
return str_replace($entity_custom_from, $entity_custom_to, $data);
}