changeset 194 | 32102edaa81b |
parent 136 | bde1974c263b |
child 204 | 09a1c134465b |
193:2f6f6f7551ca | 194:32102edaa81b |
---|---|
3 * Main WordPress API |
3 * Main WordPress API |
4 * |
4 * |
5 * @package WordPress |
5 * @package WordPress |
6 */ |
6 */ |
7 |
7 |
8 /** |
8 require( ABSPATH . WPINC . '/option.php' ); |
9 * Converts MySQL DATETIME field to user specified date format. |
9 |
10 * |
10 /** |
11 * If $dateformatstring has 'G' value, then gmmktime() function will be used to |
11 * Converts given date string into a different format. |
12 * make the time. If $dateformatstring is set to 'U', then mktime() function |
12 * |
13 * will be used to make the time. |
13 * $format should be either a PHP date format string, e.g. 'U' for a Unix |
14 * |
14 * timestamp, or 'G' for a Unix timestamp assuming that $date is GMT. |
15 * The $translate will only be used, if it is set to true and it is by default |
15 * |
16 * and if the $wp_locale object has the month and weekday set. |
16 * If $translate is true then the given date and format string will |
17 * be passed to date_i18n() for translation. |
|
17 * |
18 * |
18 * @since 0.71 |
19 * @since 0.71 |
19 * |
20 * |
20 * @param string $dateformatstring Either 'G', 'U', or php date format. |
21 * @param string $format Format of the date to return. |
21 * @param string $mysqlstring Time from mysql DATETIME field. |
22 * @param string $date Date string to convert. |
22 * @param bool $translate Optional. Default is true. Will switch format to locale. |
23 * @param bool $translate Whether the return date should be translated. Default is true. |
23 * @return string Date formated by $dateformatstring or locale (if available). |
24 * @return string|int Formatted date string, or Unix timestamp. |
24 */ |
25 */ |
25 function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) { |
26 function mysql2date( $format, $date, $translate = true ) { |
26 global $wp_locale; |
27 if ( empty( $date ) ) |
27 $m = $mysqlstring; |
|
28 if ( empty( $m ) ) |
|
29 return false; |
28 return false; |
30 |
29 |
31 if( 'G' == $dateformatstring ) { |
30 if ( 'G' == $format ) |
32 return strtotime( $m . ' +0000' ); |
31 return strtotime( $date . ' +0000' ); |
33 } |
32 |
34 |
33 $i = strtotime( $date ); |
35 $i = strtotime( $m ); |
34 |
36 |
35 if ( 'U' == $format ) |
37 if( 'U' == $dateformatstring ) |
|
38 return $i; |
36 return $i; |
39 |
37 |
40 if ( $translate) |
38 if ( $translate ) |
41 return date_i18n( $dateformatstring, $i ); |
39 return date_i18n( $format, $i ); |
42 else |
40 else |
43 return date( $dateformatstring, $i ); |
41 return date( $format, $i ); |
44 } |
42 } |
45 |
43 |
46 /** |
44 /** |
47 * Retrieve the current time based on specified type. |
45 * Retrieve the current time based on specified type. |
48 * |
46 * |
84 * @return string The date, translated if locale specifies it. |
82 * @return string The date, translated if locale specifies it. |
85 */ |
83 */ |
86 function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) { |
84 function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) { |
87 global $wp_locale; |
85 global $wp_locale; |
88 $i = $unixtimestamp; |
86 $i = $unixtimestamp; |
89 // Sanity check for PHP 5.1.0- |
87 |
90 if ( false === $i || intval($i) < 0 ) { |
88 if ( false === $i ) { |
91 if ( ! $gmt ) |
89 if ( ! $gmt ) |
92 $i = current_time( 'timestamp' ); |
90 $i = current_time( 'timestamp' ); |
93 else |
91 else |
94 $i = time(); |
92 $i = time(); |
95 // we should not let date() interfere with our |
93 // we should not let date() interfere with our |
118 $dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring ); |
116 $dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring ); |
119 $dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring ); |
117 $dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring ); |
120 |
118 |
121 $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 ); |
119 $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 ); |
122 } |
120 } |
121 $timezone_formats = array( 'P', 'I', 'O', 'T', 'Z', 'e' ); |
|
122 $timezone_formats_re = implode( '|', $timezone_formats ); |
|
123 if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) ) { |
|
124 $timezone_string = get_option( 'timezone_string' ); |
|
125 if ( $timezone_string ) { |
|
126 $timezone_object = timezone_open( $timezone_string ); |
|
127 $date_object = date_create( null, $timezone_object ); |
|
128 foreach( $timezone_formats as $timezone_format ) { |
|
129 if ( false !== strpos( $dateformatstring, $timezone_format ) ) { |
|
130 $formatted = date_format( $date_object, $timezone_format ); |
|
131 $dateformatstring = ' '.$dateformatstring; |
|
132 $dateformatstring = preg_replace( "/([^\\\])$timezone_format/", "\\1" . backslashit( $formatted ), $dateformatstring ); |
|
133 $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 ); |
|
134 } |
|
135 } |
|
136 } |
|
137 } |
|
123 $j = @$datefunc( $dateformatstring, $i ); |
138 $j = @$datefunc( $dateformatstring, $i ); |
124 // allow plugins to redo this entirely for languages with untypical grammars |
139 // allow plugins to redo this entirely for languages with untypical grammars |
125 $j = apply_filters('date_i18n', $j, $req_format, $i, $gmt); |
140 $j = apply_filters('date_i18n', $j, $req_format, $i, $gmt); |
126 return $j; |
141 return $j; |
127 } |
142 } |
128 |
143 |
129 /** |
144 /** |
130 * Convert number to format based on the locale. |
145 * Convert integer number to format based on the locale. |
131 * |
146 * |
132 * @since 2.3.0 |
147 * @since 2.3.0 |
133 * |
148 * |
134 * @param mixed $number The number to convert based on locale. |
149 * @param int $number The number to convert based on locale. |
135 * @param int $decimals Precision of the number of decimal places. |
150 * @param int $decimals Precision of the number of decimal places. |
136 * @return string Converted number in string format. |
151 * @return string Converted number in string format. |
137 */ |
152 */ |
138 function number_format_i18n( $number, $decimals = null ) { |
153 function number_format_i18n( $number, $decimals = 0 ) { |
139 global $wp_locale; |
154 global $wp_locale; |
140 // let the user override the precision only |
155 $formatted = number_format( $number, absint( $decimals ), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] ); |
141 $decimals = ( is_null( $decimals ) ) ? $wp_locale->number_format['decimals'] : intval( $decimals ); |
156 return apply_filters( 'number_format_i18n', $formatted ); |
142 |
|
143 $num = number_format( $number, $decimals, $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] ); |
|
144 |
|
145 // let the user translate digits from latin to localized language |
|
146 return apply_filters( 'number_format_i18n', $num ); |
|
147 } |
157 } |
148 |
158 |
149 /** |
159 /** |
150 * Convert number of bytes largest unit bytes will fit into. |
160 * Convert number of bytes largest unit bytes will fit into. |
151 * |
161 * |
162 * @link http://en.wikipedia.org/wiki/Byte |
172 * @link http://en.wikipedia.org/wiki/Byte |
163 * |
173 * |
164 * @since 2.3.0 |
174 * @since 2.3.0 |
165 * |
175 * |
166 * @param int|string $bytes Number of bytes. Note max integer size for integers. |
176 * @param int|string $bytes Number of bytes. Note max integer size for integers. |
167 * @param int $decimals Precision of number of decimal places. |
177 * @param int $decimals Precision of number of decimal places. Deprecated. |
168 * @return bool|string False on failure. Number string on success. |
178 * @return bool|string False on failure. Number string on success. |
169 */ |
179 */ |
170 function size_format( $bytes, $decimals = null ) { |
180 function size_format( $bytes, $decimals = 0 ) { |
171 $quant = array( |
181 $quant = array( |
172 // ========================= Origin ==== |
182 // ========================= Origin ==== |
173 'TB' => 1099511627776, // pow( 1024, 4) |
183 'TB' => 1099511627776, // pow( 1024, 4) |
174 'GB' => 1073741824, // pow( 1024, 3) |
184 'GB' => 1073741824, // pow( 1024, 3) |
175 'MB' => 1048576, // pow( 1024, 2) |
185 'MB' => 1048576, // pow( 1024, 2) |
176 'kB' => 1024, // pow( 1024, 1) |
186 'kB' => 1024, // pow( 1024, 1) |
177 'B ' => 1, // pow( 1024, 0) |
187 'B ' => 1, // pow( 1024, 0) |
178 ); |
188 ); |
179 |
|
180 foreach ( $quant as $unit => $mag ) |
189 foreach ( $quant as $unit => $mag ) |
181 if ( doubleval($bytes) >= $mag ) |
190 if ( doubleval($bytes) >= $mag ) |
182 return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit; |
191 return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit; |
183 |
192 |
184 return false; |
193 return false; |
197 $my = substr( $mysqlstring, 0, 4 ); // Mysql string Year |
206 $my = substr( $mysqlstring, 0, 4 ); // Mysql string Year |
198 $mm = substr( $mysqlstring, 8, 2 ); // Mysql string Month |
207 $mm = substr( $mysqlstring, 8, 2 ); // Mysql string Month |
199 $md = substr( $mysqlstring, 5, 2 ); // Mysql string day |
208 $md = substr( $mysqlstring, 5, 2 ); // Mysql string day |
200 $day = mktime( 0, 0, 0, $md, $mm, $my ); // The timestamp for mysqlstring day. |
209 $day = mktime( 0, 0, 0, $md, $mm, $my ); // The timestamp for mysqlstring day. |
201 $weekday = date( 'w', $day ); // The day of the week from the timestamp |
210 $weekday = date( 'w', $day ); // The day of the week from the timestamp |
202 $i = 86400; // One day |
211 if ( !is_numeric($start_of_week) ) |
203 if( !is_numeric($start_of_week) ) |
|
204 $start_of_week = get_option( 'start_of_week' ); |
212 $start_of_week = get_option( 'start_of_week' ); |
205 |
213 |
206 if ( $weekday < $start_of_week ) |
214 if ( $weekday < $start_of_week ) |
207 $weekday = 7 - $start_of_week - $weekday; |
215 $weekday += 7; |
208 |
216 |
209 while ( $weekday > $start_of_week ) { |
217 $start = $day - 86400 * ( $weekday - $start_of_week ); // The most recent week start day on or before $day |
210 $weekday = date( 'w', $day ); |
218 $end = $start + 604799; // $start + 7 days - 1 second |
211 if ( $weekday < $start_of_week ) |
219 return compact( 'start', 'end' ); |
212 $weekday = 7 - $start_of_week - $weekday; |
|
213 |
|
214 $day -= 86400; |
|
215 $i = 0; |
|
216 } |
|
217 $week['start'] = $day + 86400 - $i; |
|
218 $week['end'] = $week['start'] + 604799; |
|
219 return $week; |
|
220 } |
220 } |
221 |
221 |
222 /** |
222 /** |
223 * Unserialize value only if it was serialized. |
223 * Unserialize value only if it was serialized. |
224 * |
224 * |
244 * @param mixed $data Value to check to see if was serialized. |
244 * @param mixed $data Value to check to see if was serialized. |
245 * @return bool False if not serialized and true if it was. |
245 * @return bool False if not serialized and true if it was. |
246 */ |
246 */ |
247 function is_serialized( $data ) { |
247 function is_serialized( $data ) { |
248 // if it isn't a string, it isn't serialized |
248 // if it isn't a string, it isn't serialized |
249 if ( !is_string( $data ) ) |
249 if ( ! is_string( $data ) ) |
250 return false; |
250 return false; |
251 $data = trim( $data ); |
251 $data = trim( $data ); |
252 if ( 'N;' == $data ) |
252 if ( 'N;' == $data ) |
253 return true; |
253 return true; |
254 if ( !preg_match( '/^([adObis]):/', $data, $badions ) ) |
254 $length = strlen( $data ); |
255 if ( $length < 4 ) |
|
255 return false; |
256 return false; |
256 switch ( $badions[1] ) { |
257 if ( ':' !== $data[1] ) |
258 return false; |
|
259 $lastc = $data[$length-1]; |
|
260 if ( ';' !== $lastc && '}' !== $lastc ) |
|
261 return false; |
|
262 $token = $data[0]; |
|
263 switch ( $token ) { |
|
264 case 's' : |
|
265 if ( '"' !== $data[$length-2] ) |
|
266 return false; |
|
257 case 'a' : |
267 case 'a' : |
258 case 'O' : |
268 case 'O' : |
259 case 's' : |
269 return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data ); |
260 if ( preg_match( "/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data ) ) |
|
261 return true; |
|
262 break; |
|
263 case 'b' : |
270 case 'b' : |
264 case 'i' : |
271 case 'i' : |
265 case 'd' : |
272 case 'd' : |
266 if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) ) |
273 return (bool) preg_match( "/^{$token}:[0-9.E-]+;\$/", $data ); |
267 return true; |
|
268 break; |
|
269 } |
274 } |
270 return false; |
275 return false; |
271 } |
276 } |
272 |
277 |
273 /** |
278 /** |
281 function is_serialized_string( $data ) { |
286 function is_serialized_string( $data ) { |
282 // if it isn't a string, it isn't a serialized string |
287 // if it isn't a string, it isn't a serialized string |
283 if ( !is_string( $data ) ) |
288 if ( !is_string( $data ) ) |
284 return false; |
289 return false; |
285 $data = trim( $data ); |
290 $data = trim( $data ); |
286 if ( preg_match( '/^s:[0-9]+:.*;$/s', $data ) ) // this should fetch all serialized strings |
291 $length = strlen( $data ); |
292 if ( $length < 4 ) |
|
293 return false; |
|
294 elseif ( ':' !== $data[1] ) |
|
295 return false; |
|
296 elseif ( ';' !== $data[$length-1] ) |
|
297 return false; |
|
298 elseif ( $data[0] !== 's' ) |
|
299 return false; |
|
300 elseif ( '"' !== $data[$length-2] ) |
|
301 return false; |
|
302 else |
|
287 return true; |
303 return true; |
288 return false; |
|
289 } |
|
290 |
|
291 /** |
|
292 * Retrieve option value based on setting name. |
|
293 * |
|
294 * If the option does not exist or does not have a value, then the return value |
|
295 * will be false. This is useful to check whether you need to install an option |
|
296 * and is commonly used during installation of plugin options and to test |
|
297 * whether upgrading is required. |
|
298 * |
|
299 * You can "short-circuit" the retrieval of the option from the database for |
|
300 * your plugin or core options that aren't protected. You can do so by hooking |
|
301 * into the 'pre_option_$option' with the $option being replaced by the option |
|
302 * name. You should not try to override special options, but you will not be |
|
303 * prevented from doing so. |
|
304 * |
|
305 * There is a second filter called 'option_$option' with the $option being |
|
306 * replaced with the option name. This gives the value as the only parameter. |
|
307 * |
|
308 * If the option was serialized, when the option was added and, or updated, then |
|
309 * it will be unserialized, when it is returned. |
|
310 * |
|
311 * @since 1.5.0 |
|
312 * @package WordPress |
|
313 * @subpackage Option |
|
314 * @uses apply_filters() Calls 'pre_option_$optionname' false to allow |
|
315 * overwriting the option value in a plugin. |
|
316 * @uses apply_filters() Calls 'option_$optionname' with the option name value. |
|
317 * |
|
318 * @param string $setting Name of option to retrieve. Should already be SQL-escaped |
|
319 * @return mixed Value set for the option. |
|
320 */ |
|
321 function get_option( $setting, $default = false ) { |
|
322 global $wpdb; |
|
323 |
|
324 // Allow plugins to short-circuit options. |
|
325 $pre = apply_filters( 'pre_option_' . $setting, false ); |
|
326 if ( false !== $pre ) |
|
327 return $pre; |
|
328 |
|
329 // prevent non-existent options from triggering multiple queries |
|
330 $notoptions = wp_cache_get( 'notoptions', 'options' ); |
|
331 if ( isset( $notoptions[$setting] ) ) |
|
332 return $default; |
|
333 |
|
334 $alloptions = wp_load_alloptions(); |
|
335 |
|
336 if ( isset( $alloptions[$setting] ) ) { |
|
337 $value = $alloptions[$setting]; |
|
338 } else { |
|
339 $value = wp_cache_get( $setting, 'options' ); |
|
340 |
|
341 if ( false === $value ) { |
|
342 if ( defined( 'WP_INSTALLING' ) ) |
|
343 $suppress = $wpdb->suppress_errors(); |
|
344 // expected_slashed ($setting) |
|
345 $row = $wpdb->get_row( "SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1" ); |
|
346 if ( defined( 'WP_INSTALLING' ) ) |
|
347 $wpdb->suppress_errors($suppress); |
|
348 |
|
349 if ( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values |
|
350 $value = $row->option_value; |
|
351 wp_cache_add( $setting, $value, 'options' ); |
|
352 } else { // option does not exist, so we must cache its non-existence |
|
353 $notoptions[$setting] = true; |
|
354 wp_cache_set( 'notoptions', $notoptions, 'options' ); |
|
355 return $default; |
|
356 } |
|
357 } |
|
358 } |
|
359 |
|
360 // If home is not set use siteurl. |
|
361 if ( 'home' == $setting && '' == $value ) |
|
362 return get_option( 'siteurl' ); |
|
363 |
|
364 if ( in_array( $setting, array('siteurl', 'home', 'category_base', 'tag_base') ) ) |
|
365 $value = untrailingslashit( $value ); |
|
366 |
|
367 return apply_filters( 'option_' . $setting, maybe_unserialize( $value ) ); |
|
368 } |
|
369 |
|
370 /** |
|
371 * Protect WordPress special option from being modified. |
|
372 * |
|
373 * Will die if $option is in protected list. Protected options are 'alloptions' |
|
374 * and 'notoptions' options. |
|
375 * |
|
376 * @since 2.2.0 |
|
377 * @package WordPress |
|
378 * @subpackage Option |
|
379 * |
|
380 * @param string $option Option name. |
|
381 */ |
|
382 function wp_protect_special_option( $option ) { |
|
383 $protected = array( 'alloptions', 'notoptions' ); |
|
384 if ( in_array( $option, $protected ) ) |
|
385 die( sprintf( __( '%s is a protected WP option and may not be modified' ), esc_html( $option ) ) ); |
|
386 } |
|
387 |
|
388 /** |
|
389 * Print option value after sanitizing for forms. |
|
390 * |
|
391 * @uses attr Sanitizes value. |
|
392 * @since 1.5.0 |
|
393 * @package WordPress |
|
394 * @subpackage Option |
|
395 * |
|
396 * @param string $option Option name. |
|
397 */ |
|
398 function form_option( $option ) { |
|
399 echo esc_attr(get_option( $option ) ); |
|
400 } |
|
401 |
|
402 /** |
|
403 * Retrieve all autoload options or all options, if no autoloaded ones exist. |
|
404 * |
|
405 * This is different from wp_load_alloptions() in that this function does not |
|
406 * cache its results and will retrieve all options from the database every time |
|
407 * |
|
408 * it is called. |
|
409 * |
|
410 * @since 1.0.0 |
|
411 * @package WordPress |
|
412 * @subpackage Option |
|
413 * @uses apply_filters() Calls 'pre_option_$optionname' hook with option value as parameter. |
|
414 * @uses apply_filters() Calls 'all_options' on options list. |
|
415 * |
|
416 * @return array List of all options. |
|
417 */ |
|
418 function get_alloptions() { |
|
419 global $wpdb; |
|
420 $show = $wpdb->hide_errors(); |
|
421 if ( !$options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) ) |
|
422 $options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" ); |
|
423 $wpdb->show_errors($show); |
|
424 |
|
425 foreach ( (array) $options as $option ) { |
|
426 // "When trying to design a foolproof system, |
|
427 // never underestimate the ingenuity of the fools :)" -- Dougal |
|
428 if ( in_array( $option->option_name, array( 'siteurl', 'home', 'category_base', 'tag_base' ) ) ) |
|
429 $option->option_value = untrailingslashit( $option->option_value ); |
|
430 $value = maybe_unserialize( $option->option_value ); |
|
431 $all_options->{$option->option_name} = apply_filters( 'pre_option_' . $option->option_name, $value ); |
|
432 } |
|
433 return apply_filters( 'all_options', $all_options ); |
|
434 } |
|
435 |
|
436 /** |
|
437 * Loads and caches all autoloaded options, if available or all options. |
|
438 * |
|
439 * This is different from get_alloptions(), in that this function will cache the |
|
440 * options and will return the cached options when called again. |
|
441 * |
|
442 * @since 2.2.0 |
|
443 * @package WordPress |
|
444 * @subpackage Option |
|
445 * |
|
446 * @return array List all options. |
|
447 */ |
|
448 function wp_load_alloptions() { |
|
449 global $wpdb; |
|
450 |
|
451 $alloptions = wp_cache_get( 'alloptions', 'options' ); |
|
452 |
|
453 if ( !$alloptions ) { |
|
454 $suppress = $wpdb->suppress_errors(); |
|
455 if ( !$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) ) |
|
456 $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" ); |
|
457 $wpdb->suppress_errors($suppress); |
|
458 $alloptions = array(); |
|
459 foreach ( (array) $alloptions_db as $o ) |
|
460 $alloptions[$o->option_name] = $o->option_value; |
|
461 wp_cache_add( 'alloptions', $alloptions, 'options' ); |
|
462 } |
|
463 return $alloptions; |
|
464 } |
|
465 |
|
466 /** |
|
467 * Update the value of an option that was already added. |
|
468 * |
|
469 * You do not need to serialize values, if the value needs to be serialize, then |
|
470 * it will be serialized before it is inserted into the database. Remember, |
|
471 * resources can not be serialized or added as an option. |
|
472 * |
|
473 * If the option does not exist, then the option will be added with the option |
|
474 * value, but you will not be able to set whether it is autoloaded. If you want |
|
475 * to set whether an option autoloaded, then you need to use the add_option(). |
|
476 * |
|
477 * Before the option is updated, then the filter named |
|
478 * 'pre_update_option_$option_name', with the $option_name as the $option_name |
|
479 * parameter value, will be called. The hook should accept two parameters, the |
|
480 * first is the new value and the second is the old value. Whatever is |
|
481 * returned will be used as the new value. |
|
482 * |
|
483 * After the value has been updated the action named 'update_option_$option_name' |
|
484 * will be called. This action receives two parameters the first being the old |
|
485 * value and the second the new value. |
|
486 * |
|
487 * @since 1.0.0 |
|
488 * @package WordPress |
|
489 * @subpackage Option |
|
490 * |
|
491 * @param string $option_name Option name. Expected to not be SQL-escaped |
|
492 * @param mixed $newvalue Option value. |
|
493 * @return bool False if value was not updated and true if value was updated. |
|
494 */ |
|
495 function update_option( $option_name, $newvalue ) { |
|
496 global $wpdb; |
|
497 |
|
498 wp_protect_special_option( $option_name ); |
|
499 |
|
500 $safe_option_name = esc_sql( $option_name ); |
|
501 $newvalue = sanitize_option( $option_name, $newvalue ); |
|
502 |
|
503 $oldvalue = get_option( $safe_option_name ); |
|
504 |
|
505 $newvalue = apply_filters( 'pre_update_option_' . $option_name, $newvalue, $oldvalue ); |
|
506 |
|
507 // If the new and old values are the same, no need to update. |
|
508 if ( $newvalue === $oldvalue ) |
|
509 return false; |
|
510 |
|
511 if ( false === $oldvalue ) { |
|
512 add_option( $option_name, $newvalue ); |
|
513 return true; |
|
514 } |
|
515 |
|
516 $notoptions = wp_cache_get( 'notoptions', 'options' ); |
|
517 if ( is_array( $notoptions ) && isset( $notoptions[$option_name] ) ) { |
|
518 unset( $notoptions[$option_name] ); |
|
519 wp_cache_set( 'notoptions', $notoptions, 'options' ); |
|
520 } |
|
521 |
|
522 $_newvalue = $newvalue; |
|
523 $newvalue = maybe_serialize( $newvalue ); |
|
524 |
|
525 do_action( 'update_option', $option_name, $oldvalue, $newvalue ); |
|
526 $alloptions = wp_load_alloptions(); |
|
527 if ( isset( $alloptions[$option_name] ) ) { |
|
528 $alloptions[$option_name] = $newvalue; |
|
529 wp_cache_set( 'alloptions', $alloptions, 'options' ); |
|
530 } else { |
|
531 wp_cache_set( $option_name, $newvalue, 'options' ); |
|
532 } |
|
533 |
|
534 $wpdb->update($wpdb->options, array('option_value' => $newvalue), array('option_name' => $option_name) ); |
|
535 |
|
536 if ( $wpdb->rows_affected == 1 ) { |
|
537 do_action( "update_option_{$option_name}", $oldvalue, $_newvalue ); |
|
538 do_action( 'updated_option', $option_name, $oldvalue, $_newvalue ); |
|
539 return true; |
|
540 } |
|
541 return false; |
|
542 } |
|
543 |
|
544 /** |
|
545 * Add a new option. |
|
546 * |
|
547 * You do not need to serialize values, if the value needs to be serialize, then |
|
548 * it will be serialized before it is inserted into the database. Remember, |
|
549 * resources can not be serialized or added as an option. |
|
550 * |
|
551 * You can create options without values and then add values later. Does not |
|
552 * check whether the option has already been added, but does check that you |
|
553 * aren't adding a protected WordPress option. Care should be taken to not name |
|
554 * options, the same as the ones which are protected and to not add options |
|
555 * that were already added. |
|
556 * |
|
557 * The filter named 'add_option_$optionname', with the $optionname being |
|
558 * replaced with the option's name, will be called. The hook should accept two |
|
559 * parameters, the first is the option name, and the second is the value. |
|
560 * |
|
561 * @package WordPress |
|
562 * @subpackage Option |
|
563 * @since 1.0.0 |
|
564 * @link http://alex.vort-x.net/blog/ Thanks Alex Stapleton |
|
565 * |
|
566 * @param string $name Option name to add. Expects to NOT be SQL escaped. |
|
567 * @param mixed $value Optional. Option value, can be anything. |
|
568 * @param mixed $deprecated Optional. Description. Not used anymore. |
|
569 * @param bool $autoload Optional. Default is enabled. Whether to load the option when WordPress starts up. |
|
570 * @return null returns when finished. |
|
571 */ |
|
572 function add_option( $name, $value = '', $deprecated = '', $autoload = 'yes' ) { |
|
573 global $wpdb; |
|
574 |
|
575 wp_protect_special_option( $name ); |
|
576 $safe_name = esc_sql( $name ); |
|
577 $value = sanitize_option( $name, $value ); |
|
578 |
|
579 // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query |
|
580 $notoptions = wp_cache_get( 'notoptions', 'options' ); |
|
581 if ( !is_array( $notoptions ) || !isset( $notoptions[$name] ) ) |
|
582 if ( false !== get_option( $safe_name ) ) |
|
583 return; |
|
584 |
|
585 $value = maybe_serialize( $value ); |
|
586 $autoload = ( 'no' === $autoload ) ? 'no' : 'yes'; |
|
587 do_action( 'add_option', $name, $value ); |
|
588 if ( 'yes' == $autoload ) { |
|
589 $alloptions = wp_load_alloptions(); |
|
590 $alloptions[$name] = $value; |
|
591 wp_cache_set( 'alloptions', $alloptions, 'options' ); |
|
592 } else { |
|
593 wp_cache_set( $name, $value, 'options' ); |
|
594 } |
|
595 |
|
596 // This option exists now |
|
597 $notoptions = wp_cache_get( 'notoptions', 'options' ); // yes, again... we need it to be fresh |
|
598 if ( is_array( $notoptions ) && isset( $notoptions[$name] ) ) { |
|
599 unset( $notoptions[$name] ); |
|
600 wp_cache_set( 'notoptions', $notoptions, 'options' ); |
|
601 } |
|
602 |
|
603 $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $name, $value, $autoload ) ); |
|
604 |
|
605 do_action( "add_option_{$name}", $name, $value ); |
|
606 do_action( 'added_option', $name, $value ); |
|
607 |
|
608 return; |
|
609 } |
|
610 |
|
611 /** |
|
612 * Removes option by name and prevents removal of protected WordPress options. |
|
613 * |
|
614 * @package WordPress |
|
615 * @subpackage Option |
|
616 * @since 1.2.0 |
|
617 * |
|
618 * @param string $name Option name to remove. |
|
619 * @return bool True, if succeed. False, if failure. |
|
620 */ |
|
621 function delete_option( $name ) { |
|
622 global $wpdb; |
|
623 |
|
624 wp_protect_special_option( $name ); |
|
625 |
|
626 // Get the ID, if no ID then return |
|
627 // expected_slashed ($name) |
|
628 $option = $wpdb->get_row( "SELECT autoload FROM $wpdb->options WHERE option_name = '$name'" ); |
|
629 if ( is_null($option) ) |
|
630 return false; |
|
631 do_action( 'delete_option', $name ); |
|
632 // expected_slashed ($name) |
|
633 $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" ); |
|
634 if ( 'yes' == $option->autoload ) { |
|
635 $alloptions = wp_load_alloptions(); |
|
636 if ( isset( $alloptions[$name] ) ) { |
|
637 unset( $alloptions[$name] ); |
|
638 wp_cache_set( 'alloptions', $alloptions, 'options' ); |
|
639 } |
|
640 } else { |
|
641 wp_cache_delete( $name, 'options' ); |
|
642 } |
|
643 do_action( 'deleted_option', $name ); |
|
644 return true; |
|
645 } |
|
646 |
|
647 /** |
|
648 * Delete a transient |
|
649 * |
|
650 * @since 2.8.0 |
|
651 * @package WordPress |
|
652 * @subpackage Transient |
|
653 * |
|
654 * @param string $transient Transient name. Expected to not be SQL-escaped |
|
655 * @return bool true if successful, false otherwise |
|
656 */ |
|
657 function delete_transient($transient) { |
|
658 global $_wp_using_ext_object_cache, $wpdb; |
|
659 |
|
660 if ( $_wp_using_ext_object_cache ) { |
|
661 return wp_cache_delete($transient, 'transient'); |
|
662 } else { |
|
663 $transient = '_transient_' . esc_sql($transient); |
|
664 return delete_option($transient); |
|
665 } |
|
666 } |
|
667 |
|
668 /** |
|
669 * Get the value of a transient |
|
670 * |
|
671 * If the transient does not exist or does not have a value, then the return value |
|
672 * will be false. |
|
673 * |
|
674 * @since 2.8.0 |
|
675 * @package WordPress |
|
676 * @subpackage Transient |
|
677 * |
|
678 * @param string $transient Transient name. Expected to not be SQL-escaped |
|
679 * @return mixed Value of transient |
|
680 */ |
|
681 function get_transient($transient) { |
|
682 global $_wp_using_ext_object_cache, $wpdb; |
|
683 |
|
684 $pre = apply_filters( 'pre_transient_' . $transient, false ); |
|
685 if ( false !== $pre ) |
|
686 return $pre; |
|
687 |
|
688 if ( $_wp_using_ext_object_cache ) { |
|
689 $value = wp_cache_get($transient, 'transient'); |
|
690 } else { |
|
691 $transient_option = '_transient_' . esc_sql($transient); |
|
692 // If option is not in alloptions, it is not autoloaded and thus has a timeout |
|
693 $alloptions = wp_load_alloptions(); |
|
694 if ( !isset( $alloptions[$transient_option] ) ) { |
|
695 $transient_timeout = '_transient_timeout_' . esc_sql($transient); |
|
696 if ( get_option($transient_timeout) < time() ) { |
|
697 delete_option($transient_option); |
|
698 delete_option($transient_timeout); |
|
699 return false; |
|
700 } |
|
701 } |
|
702 |
|
703 $value = get_option($transient_option); |
|
704 } |
|
705 |
|
706 return apply_filters('transient_' . $transient, $value); |
|
707 } |
|
708 |
|
709 /** |
|
710 * Set/update the value of a transient |
|
711 * |
|
712 * You do not need to serialize values, if the value needs to be serialize, then |
|
713 * it will be serialized before it is set. |
|
714 * |
|
715 * @since 2.8.0 |
|
716 * @package WordPress |
|
717 * @subpackage Transient |
|
718 * |
|
719 * @param string $transient Transient name. Expected to not be SQL-escaped |
|
720 * @param mixed $value Transient value. |
|
721 * @param int $expiration Time until expiration in seconds, default 0 |
|
722 * @return bool False if value was not set and true if value was set. |
|
723 */ |
|
724 function set_transient($transient, $value, $expiration = 0) { |
|
725 global $_wp_using_ext_object_cache, $wpdb; |
|
726 |
|
727 if ( $_wp_using_ext_object_cache ) { |
|
728 return wp_cache_set($transient, $value, 'transient', $expiration); |
|
729 } else { |
|
730 $transient_timeout = '_transient_timeout_' . $transient; |
|
731 $transient = '_transient_' . $transient; |
|
732 $safe_transient = esc_sql($transient); |
|
733 if ( false === get_option( $safe_transient ) ) { |
|
734 $autoload = 'yes'; |
|
735 if ( 0 != $expiration ) { |
|
736 $autoload = 'no'; |
|
737 add_option($transient_timeout, time() + $expiration, '', 'no'); |
|
738 } |
|
739 return add_option($transient, $value, '', $autoload); |
|
740 } else { |
|
741 if ( 0 != $expiration ) |
|
742 update_option($transient_timeout, time() + $expiration); |
|
743 return update_option($transient, $value); |
|
744 } |
|
745 } |
|
746 } |
|
747 |
|
748 /** |
|
749 * Saves and restores user interface settings stored in a cookie. |
|
750 * |
|
751 * Checks if the current user-settings cookie is updated and stores it. When no |
|
752 * cookie exists (different browser used), adds the last saved cookie restoring |
|
753 * the settings. |
|
754 * |
|
755 * @package WordPress |
|
756 * @subpackage Option |
|
757 * @since 2.7.0 |
|
758 */ |
|
759 function wp_user_settings() { |
|
760 |
|
761 if ( ! is_admin() ) |
|
762 return; |
|
763 |
|
764 if ( defined('DOING_AJAX') ) |
|
765 return; |
|
766 |
|
767 if ( ! $user = wp_get_current_user() ) |
|
768 return; |
|
769 |
|
770 $settings = get_user_option( 'user-settings', $user->ID, false ); |
|
771 |
|
772 if ( isset( $_COOKIE['wp-settings-' . $user->ID] ) ) { |
|
773 $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user->ID] ); |
|
774 |
|
775 if ( ! empty( $cookie ) && strpos( $cookie, '=' ) ) { |
|
776 if ( $cookie == $settings ) |
|
777 return; |
|
778 |
|
779 $last_time = (int) get_user_option( 'user-settings-time', $user->ID, false ); |
|
780 $saved = isset( $_COOKIE['wp-settings-time-' . $user->ID]) ? preg_replace( '/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user->ID] ) : 0; |
|
781 |
|
782 if ( $saved > $last_time ) { |
|
783 update_user_option( $user->ID, 'user-settings', $cookie, false ); |
|
784 update_user_option( $user->ID, 'user-settings-time', time() - 5, false ); |
|
785 return; |
|
786 } |
|
787 } |
|
788 } |
|
789 |
|
790 setcookie( 'wp-settings-' . $user->ID, $settings, time() + 31536000, SITECOOKIEPATH ); |
|
791 setcookie( 'wp-settings-time-' . $user->ID, time(), time() + 31536000, SITECOOKIEPATH ); |
|
792 $_COOKIE['wp-settings-' . $user->ID] = $settings; |
|
793 } |
|
794 |
|
795 /** |
|
796 * Retrieve user interface setting value based on setting name. |
|
797 * |
|
798 * @package WordPress |
|
799 * @subpackage Option |
|
800 * @since 2.7.0 |
|
801 * |
|
802 * @param string $name The name of the setting. |
|
803 * @param string $default Optional default value to return when $name is not set. |
|
804 * @return mixed the last saved user setting or the default value/false if it doesn't exist. |
|
805 */ |
|
806 function get_user_setting( $name, $default = false ) { |
|
807 |
|
808 $all = get_all_user_settings(); |
|
809 |
|
810 return isset($all[$name]) ? $all[$name] : $default; |
|
811 } |
|
812 |
|
813 /** |
|
814 * Add or update user interface setting. |
|
815 * |
|
816 * Both $name and $value can contain only ASCII letters, numbers and underscores. |
|
817 * This function has to be used before any output has started as it calls setcookie(). |
|
818 * |
|
819 * @package WordPress |
|
820 * @subpackage Option |
|
821 * @since 2.8.0 |
|
822 * |
|
823 * @param string $name The name of the setting. |
|
824 * @param string $value The value for the setting. |
|
825 * @return bool true if set successfully/false if not. |
|
826 */ |
|
827 function set_user_setting( $name, $value ) { |
|
828 |
|
829 if ( headers_sent() ) |
|
830 return false; |
|
831 |
|
832 $all = get_all_user_settings(); |
|
833 $name = preg_replace( '/[^A-Za-z0-9_]+/', '', $name ); |
|
834 |
|
835 if ( empty($name) ) |
|
836 return false; |
|
837 |
|
838 $all[$name] = $value; |
|
839 |
|
840 return wp_set_all_user_settings($all); |
|
841 } |
|
842 |
|
843 /** |
|
844 * Delete user interface settings. |
|
845 * |
|
846 * Deleting settings would reset them to the defaults. |
|
847 * This function has to be used before any output has started as it calls setcookie(). |
|
848 * |
|
849 * @package WordPress |
|
850 * @subpackage Option |
|
851 * @since 2.7.0 |
|
852 * |
|
853 * @param mixed $names The name or array of names of the setting to be deleted. |
|
854 * @return bool true if deleted successfully/false if not. |
|
855 */ |
|
856 function delete_user_setting( $names ) { |
|
857 |
|
858 if ( headers_sent() ) |
|
859 return false; |
|
860 |
|
861 $all = get_all_user_settings(); |
|
862 $names = (array) $names; |
|
863 |
|
864 foreach ( $names as $name ) { |
|
865 if ( isset($all[$name]) ) { |
|
866 unset($all[$name]); |
|
867 $deleted = true; |
|
868 } |
|
869 } |
|
870 |
|
871 if ( isset($deleted) ) |
|
872 return wp_set_all_user_settings($all); |
|
873 |
|
874 return false; |
|
875 } |
|
876 |
|
877 /** |
|
878 * Retrieve all user interface settings. |
|
879 * |
|
880 * @package WordPress |
|
881 * @subpackage Option |
|
882 * @since 2.7.0 |
|
883 * |
|
884 * @return array the last saved user settings or empty array. |
|
885 */ |
|
886 function get_all_user_settings() { |
|
887 global $_updated_user_settings; |
|
888 |
|
889 if ( ! $user = wp_get_current_user() ) |
|
890 return array(); |
|
891 |
|
892 if ( isset($_updated_user_settings) && is_array($_updated_user_settings) ) |
|
893 return $_updated_user_settings; |
|
894 |
|
895 $all = array(); |
|
896 if ( isset($_COOKIE['wp-settings-' . $user->ID]) ) { |
|
897 $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user->ID] ); |
|
898 |
|
899 if ( $cookie && strpos($cookie, '=') ) // the '=' cannot be 1st char |
|
900 parse_str($cookie, $all); |
|
901 |
|
902 } else { |
|
903 $option = get_user_option('user-settings', $user->ID); |
|
904 if ( $option && is_string($option) ) |
|
905 parse_str( $option, $all ); |
|
906 } |
|
907 |
|
908 return $all; |
|
909 } |
|
910 |
|
911 /** |
|
912 * Private. Set all user interface settings. |
|
913 * |
|
914 * @package WordPress |
|
915 * @subpackage Option |
|
916 * @since 2.8.0 |
|
917 * |
|
918 */ |
|
919 function wp_set_all_user_settings($all) { |
|
920 global $_updated_user_settings; |
|
921 |
|
922 if ( ! $user = wp_get_current_user() ) |
|
923 return false; |
|
924 |
|
925 $_updated_user_settings = $all; |
|
926 $settings = ''; |
|
927 foreach ( $all as $k => $v ) { |
|
928 $v = preg_replace( '/[^A-Za-z0-9_]+/', '', $v ); |
|
929 $settings .= $k . '=' . $v . '&'; |
|
930 } |
|
931 |
|
932 $settings = rtrim($settings, '&'); |
|
933 |
|
934 update_user_option( $user->ID, 'user-settings', $settings, false ); |
|
935 update_user_option( $user->ID, 'user-settings-time', time(), false ); |
|
936 |
|
937 return true; |
|
938 } |
|
939 |
|
940 /** |
|
941 * Delete the user settings of the current user. |
|
942 * |
|
943 * @package WordPress |
|
944 * @subpackage Option |
|
945 * @since 2.7.0 |
|
946 */ |
|
947 function delete_all_user_settings() { |
|
948 if ( ! $user = wp_get_current_user() ) |
|
949 return; |
|
950 |
|
951 update_user_option( $user->ID, 'user-settings', '', false ); |
|
952 setcookie('wp-settings-' . $user->ID, ' ', time() - 31536000, SITECOOKIEPATH); |
|
953 } |
304 } |
954 |
305 |
955 /** |
306 /** |
956 * Serialize data, if needed. |
307 * Serialize data, if needed. |
957 * |
308 * |
962 */ |
313 */ |
963 function maybe_serialize( $data ) { |
314 function maybe_serialize( $data ) { |
964 if ( is_array( $data ) || is_object( $data ) ) |
315 if ( is_array( $data ) || is_object( $data ) ) |
965 return serialize( $data ); |
316 return serialize( $data ); |
966 |
317 |
318 // Double serialization is required for backward compatibility. |
|
319 // See http://core.trac.wordpress.org/ticket/12930 |
|
967 if ( is_serialized( $data ) ) |
320 if ( is_serialized( $data ) ) |
968 return serialize( $data ); |
321 return serialize( $data ); |
969 |
322 |
970 return $data; |
323 return $data; |
971 } |
324 } |
1038 $content = trim( $content ); |
391 $content = trim( $content ); |
1039 return $content; |
392 return $content; |
1040 } |
393 } |
1041 |
394 |
1042 /** |
395 /** |
1043 * Open the file handle for debugging. |
|
1044 * |
|
1045 * This function is used for XMLRPC feature, but it is general purpose enough |
|
1046 * to be used in anywhere. |
|
1047 * |
|
1048 * @see fopen() for mode options. |
|
1049 * @package WordPress |
|
1050 * @subpackage Debug |
|
1051 * @since 0.71 |
|
1052 * @uses $debug Used for whether debugging is enabled. |
|
1053 * |
|
1054 * @param string $filename File path to debug file. |
|
1055 * @param string $mode Same as fopen() mode parameter. |
|
1056 * @return bool|resource File handle. False on failure. |
|
1057 */ |
|
1058 function debug_fopen( $filename, $mode ) { |
|
1059 global $debug; |
|
1060 if ( 1 == $debug ) { |
|
1061 $fp = fopen( $filename, $mode ); |
|
1062 return $fp; |
|
1063 } else { |
|
1064 return false; |
|
1065 } |
|
1066 } |
|
1067 |
|
1068 /** |
|
1069 * Write contents to the file used for debugging. |
|
1070 * |
|
1071 * Technically, this can be used to write to any file handle when the global |
|
1072 * $debug is set to 1 or true. |
|
1073 * |
|
1074 * @package WordPress |
|
1075 * @subpackage Debug |
|
1076 * @since 0.71 |
|
1077 * @uses $debug Used for whether debugging is enabled. |
|
1078 * |
|
1079 * @param resource $fp File handle for debugging file. |
|
1080 * @param string $string Content to write to debug file. |
|
1081 */ |
|
1082 function debug_fwrite( $fp, $string ) { |
|
1083 global $debug; |
|
1084 if ( 1 == $debug ) |
|
1085 fwrite( $fp, $string ); |
|
1086 } |
|
1087 |
|
1088 /** |
|
1089 * Close the debugging file handle. |
|
1090 * |
|
1091 * Technically, this can be used to close any file handle when the global $debug |
|
1092 * is set to 1 or true. |
|
1093 * |
|
1094 * @package WordPress |
|
1095 * @subpackage Debug |
|
1096 * @since 0.71 |
|
1097 * @uses $debug Used for whether debugging is enabled. |
|
1098 * |
|
1099 * @param resource $fp Debug File handle. |
|
1100 */ |
|
1101 function debug_fclose( $fp ) { |
|
1102 global $debug; |
|
1103 if ( 1 == $debug ) |
|
1104 fclose( $fp ); |
|
1105 } |
|
1106 |
|
1107 /** |
|
1108 * Check content for video and audio links to add as enclosures. |
396 * Check content for video and audio links to add as enclosures. |
1109 * |
397 * |
1110 * Will not add enclosures that have already been added and will |
398 * Will not add enclosures that have already been added and will |
1111 * remove enclosures that are no longer in the post. This is called as |
399 * remove enclosures that are no longer in the post. This is called as |
1112 * pingbacks and trackbacks. |
400 * pingbacks and trackbacks. |
1119 * @param string $content Post Content |
407 * @param string $content Post Content |
1120 * @param int $post_ID Post ID |
408 * @param int $post_ID Post ID |
1121 */ |
409 */ |
1122 function do_enclose( $content, $post_ID ) { |
410 function do_enclose( $content, $post_ID ) { |
1123 global $wpdb; |
411 global $wpdb; |
412 |
|
413 //TODO: Tidy this ghetto code up and make the debug code optional |
|
1124 include_once( ABSPATH . WPINC . '/class-IXR.php' ); |
414 include_once( ABSPATH . WPINC . '/class-IXR.php' ); |
1125 |
415 |
1126 $log = debug_fopen( ABSPATH . 'enclosures.log', 'a' ); |
|
1127 $post_links = array(); |
416 $post_links = array(); |
1128 debug_fwrite( $log, 'BEGIN ' . date( 'YmdHis', time() ) . "\n" ); |
|
1129 |
417 |
1130 $pung = get_enclosed( $post_ID ); |
418 $pung = get_enclosed( $post_ID ); |
1131 |
419 |
1132 $ltrs = '\w'; |
420 $ltrs = '\w'; |
1133 $gunk = '/#~:.?+=&%@!\-'; |
421 $gunk = '/#~:.?+=&%@!\-'; |
1134 $punc = '.:?\-'; |
422 $punc = '.:?\-'; |
1135 $any = $ltrs . $gunk . $punc; |
423 $any = $ltrs . $gunk . $punc; |
1136 |
424 |
1137 preg_match_all( "{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp ); |
425 preg_match_all( "{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp ); |
1138 |
426 |
1139 debug_fwrite( $log, 'Post contents:' ); |
|
1140 debug_fwrite( $log, $content . "\n" ); |
|
1141 |
|
1142 foreach ( $pung as $link_test ) { |
427 foreach ( $pung as $link_test ) { |
1143 if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post |
428 if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post |
1144 $mid = $wpdb->get_col( $wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $link_test . '%') ); |
429 $mids = $wpdb->get_col( $wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, like_escape( $link_test ) . '%') ); |
1145 do_action( 'delete_postmeta', $mid ); |
430 foreach ( $mids as $mid ) |
1146 $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE post_id IN(%s)", implode( ',', $mid ) ) ); |
431 delete_metadata_by_mid( 'post', $mid ); |
1147 do_action( 'deleted_postmeta', $mid ); |
|
1148 } |
432 } |
1149 } |
433 } |
1150 |
434 |
1151 foreach ( (array) $post_links_temp[0] as $link_test ) { |
435 foreach ( (array) $post_links_temp[0] as $link_test ) { |
1152 if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already |
436 if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already |
1153 $test = parse_url( $link_test ); |
437 $test = @parse_url( $link_test ); |
438 if ( false === $test ) |
|
439 continue; |
|
1154 if ( isset( $test['query'] ) ) |
440 if ( isset( $test['query'] ) ) |
1155 $post_links[] = $link_test; |
441 $post_links[] = $link_test; |
1156 elseif ( $test['path'] != '/' && $test['path'] != '' ) |
442 elseif ( isset($test['path']) && ( $test['path'] != '/' ) && ($test['path'] != '' ) ) |
1157 $post_links[] = $link_test; |
443 $post_links[] = $link_test; |
1158 } |
444 } |
1159 } |
445 } |
1160 |
446 |
1161 foreach ( (array) $post_links as $url ) { |
447 foreach ( (array) $post_links as $url ) { |
1162 if ( $url != '' && !$wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $url . '%' ) ) ) { |
448 if ( $url != '' && !$wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, like_escape( $url ) . '%' ) ) ) { |
449 |
|
1163 if ( $headers = wp_get_http_headers( $url) ) { |
450 if ( $headers = wp_get_http_headers( $url) ) { |
1164 $len = (int) $headers['content-length']; |
451 $len = isset( $headers['content-length'] ) ? (int) $headers['content-length'] : 0; |
1165 $type = $headers['content-type']; |
452 $type = isset( $headers['content-type'] ) ? $headers['content-type'] : ''; |
1166 $allowed_types = array( 'video', 'audio' ); |
453 $allowed_types = array( 'video', 'audio' ); |
454 |
|
455 // Check to see if we can figure out the mime type from |
|
456 // the extension |
|
457 $url_parts = @parse_url( $url ); |
|
458 if ( false !== $url_parts ) { |
|
459 $extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION ); |
|
460 if ( !empty( $extension ) ) { |
|
461 foreach ( get_allowed_mime_types( ) as $exts => $mime ) { |
|
462 if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) { |
|
463 $type = $mime; |
|
464 break; |
|
465 } |
|
466 } |
|
467 } |
|
468 } |
|
469 |
|
1167 if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) { |
470 if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) { |
1168 $meta_value = "$url\n$len\n$type\n"; |
471 add_post_meta( $post_ID, 'enclosure', "$url\n$len\n$mime\n" ); |
1169 $wpdb->insert($wpdb->postmeta, array('post_id' => $post_ID, 'meta_key' => 'enclosure', 'meta_value' => $meta_value) ); |
|
1170 do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, 'enclosure', $meta_value ); |
|
1171 } |
472 } |
1172 } |
473 } |
1173 } |
474 } |
1174 } |
475 } |
1175 } |
476 } |
1182 * |
483 * |
1183 * @since 2.5.0 |
484 * @since 2.5.0 |
1184 * |
485 * |
1185 * @param string $url URL to fetch. |
486 * @param string $url URL to fetch. |
1186 * @param string|bool $file_path Optional. File path to write request to. |
487 * @param string|bool $file_path Optional. File path to write request to. |
1187 * @param bool $deprecated Deprecated. Not used. |
488 * @param int $red (private) The number of Redirects followed, Upon 5 being hit, returns false. |
1188 * @return bool|string False on failure and string of headers if HEAD request. |
489 * @return bool|string False on failure and string of headers if HEAD request. |
1189 */ |
490 */ |
1190 function wp_get_http( $url, $file_path = false, $deprecated = false ) { |
491 function wp_get_http( $url, $file_path = false, $red = 1 ) { |
1191 @set_time_limit( 60 ); |
492 @set_time_limit( 60 ); |
493 |
|
494 if ( $red > 5 ) |
|
495 return false; |
|
1192 |
496 |
1193 $options = array(); |
497 $options = array(); |
1194 $options['redirection'] = 5; |
498 $options['redirection'] = 5; |
1195 |
499 |
1196 if ( false == $file_path ) |
500 if ( false == $file_path ) |
1202 |
506 |
1203 if ( is_wp_error( $response ) ) |
507 if ( is_wp_error( $response ) ) |
1204 return false; |
508 return false; |
1205 |
509 |
1206 $headers = wp_remote_retrieve_headers( $response ); |
510 $headers = wp_remote_retrieve_headers( $response ); |
1207 $headers['response'] = $response['response']['code']; |
511 $headers['response'] = wp_remote_retrieve_response_code( $response ); |
512 |
|
513 // WP_HTTP no longer follows redirects for HEAD requests. |
|
514 if ( 'HEAD' == $options['method'] && in_array($headers['response'], array(301, 302)) && isset( $headers['location'] ) ) { |
|
515 return wp_get_http( $headers['location'], $file_path, ++$red ); |
|
516 } |
|
1208 |
517 |
1209 if ( false == $file_path ) |
518 if ( false == $file_path ) |
1210 return $headers; |
519 return $headers; |
1211 |
520 |
1212 // GET request - write it to the supplied filename |
521 // GET request - write it to the supplied filename |
1213 $out_fp = fopen($file_path, 'w'); |
522 $out_fp = fopen($file_path, 'w'); |
1214 if ( !$out_fp ) |
523 if ( !$out_fp ) |
1215 return $headers; |
524 return $headers; |
1216 |
525 |
1217 fwrite( $out_fp, $response['body']); |
526 fwrite( $out_fp, wp_remote_retrieve_body( $response ) ); |
1218 fclose($out_fp); |
527 fclose($out_fp); |
528 clearstatcache(); |
|
1219 |
529 |
1220 return $headers; |
530 return $headers; |
1221 } |
531 } |
1222 |
532 |
1223 /** |
533 /** |
1228 * @param string $url |
538 * @param string $url |
1229 * @param bool $deprecated Not Used. |
539 * @param bool $deprecated Not Used. |
1230 * @return bool|string False on failure, headers on success. |
540 * @return bool|string False on failure, headers on success. |
1231 */ |
541 */ |
1232 function wp_get_http_headers( $url, $deprecated = false ) { |
542 function wp_get_http_headers( $url, $deprecated = false ) { |
543 if ( !empty( $deprecated ) ) |
|
544 _deprecated_argument( __FUNCTION__, '2.7' ); |
|
545 |
|
1233 $response = wp_remote_head( $url ); |
546 $response = wp_remote_head( $url ); |
1234 |
547 |
1235 if ( is_wp_error( $response ) ) |
548 if ( is_wp_error( $response ) ) |
1236 return false; |
549 return false; |
1237 |
550 |
1246 * @uses $previousday Previous day |
559 * @uses $previousday Previous day |
1247 * |
560 * |
1248 * @return int 1 when new day, 0 if not a new day. |
561 * @return int 1 when new day, 0 if not a new day. |
1249 */ |
562 */ |
1250 function is_new_day() { |
563 function is_new_day() { |
1251 global $day, $previousday; |
564 global $currentday, $previousday; |
1252 if ( $day != $previousday ) |
565 if ( $currentday != $previousday ) |
1253 return 1; |
566 return 1; |
1254 else |
567 else |
1255 return 0; |
568 return 0; |
1256 } |
569 } |
1257 |
570 |
1272 */ |
585 */ |
1273 function build_query( $data ) { |
586 function build_query( $data ) { |
1274 return _http_build_query( $data, null, '&', '', false ); |
587 return _http_build_query( $data, null, '&', '', false ); |
1275 } |
588 } |
1276 |
589 |
590 // from php.net (modified by Mark Jaquith to behave like the native PHP5 function) |
|
591 function _http_build_query($data, $prefix=null, $sep=null, $key='', $urlencode=true) { |
|
592 $ret = array(); |
|
593 |
|
594 foreach ( (array) $data as $k => $v ) { |
|
595 if ( $urlencode) |
|
596 $k = urlencode($k); |
|
597 if ( is_int($k) && $prefix != null ) |
|
598 $k = $prefix.$k; |
|
599 if ( !empty($key) ) |
|
600 $k = $key . '%5B' . $k . '%5D'; |
|
601 if ( $v === null ) |
|
602 continue; |
|
603 elseif ( $v === FALSE ) |
|
604 $v = '0'; |
|
605 |
|
606 if ( is_array($v) || is_object($v) ) |
|
607 array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode)); |
|
608 elseif ( $urlencode ) |
|
609 array_push($ret, $k.'='.urlencode($v)); |
|
610 else |
|
611 array_push($ret, $k.'='.$v); |
|
612 } |
|
613 |
|
614 if ( null === $sep ) |
|
615 $sep = ini_get('arg_separator.output'); |
|
616 |
|
617 return implode($sep, $ret); |
|
618 } |
|
619 |
|
1277 /** |
620 /** |
1278 * Retrieve a modified URL query string. |
621 * Retrieve a modified URL query string. |
1279 * |
622 * |
1280 * You can rebuild the URL and append a new query variable to the URL query by |
623 * You can rebuild the URL and append a new query variable to the URL query by |
1281 * using this function. You can also retrieve the full URL with query data. |
624 * using this function. You can also retrieve the full URL with query data. |
1282 * |
625 * |
1283 * Adding a single key & value or an associative array. Setting a key value to |
626 * Adding a single key & value or an associative array. Setting a key value to |
1284 * emptystring removes the key. Omitting oldquery_or_uri uses the $_SERVER |
627 * an empty string removes the key. Omitting oldquery_or_uri uses the $_SERVER |
1285 * value. |
628 * value. Additional values provided are expected to be encoded appropriately |
629 * with urlencode() or rawurlencode(). |
|
1286 * |
630 * |
1287 * @since 1.5.0 |
631 * @since 1.5.0 |
1288 * |
632 * |
1289 * @param mixed $param1 Either newkey or an associative_array |
633 * @param mixed $param1 Either newkey or an associative_array |
1290 * @param mixed $param2 Either newvalue or oldquery or uri |
634 * @param mixed $param2 Either newvalue or oldquery or uri |
1375 } |
719 } |
1376 |
720 |
1377 /** |
721 /** |
1378 * Walks the array while sanitizing the contents. |
722 * Walks the array while sanitizing the contents. |
1379 * |
723 * |
1380 * @uses $wpdb Used to sanitize values |
|
1381 * @since 0.71 |
724 * @since 0.71 |
1382 * |
725 * |
1383 * @param array $array Array to used to walk while sanitizing contents. |
726 * @param array $array Array to used to walk while sanitizing contents. |
1384 * @return array Sanitized $array. |
727 * @return array Sanitized $array. |
1385 */ |
728 */ |
1386 function add_magic_quotes( $array ) { |
729 function add_magic_quotes( $array ) { |
1387 global $wpdb; |
|
1388 |
|
1389 foreach ( (array) $array as $k => $v ) { |
730 foreach ( (array) $array as $k => $v ) { |
1390 if ( is_array( $v ) ) { |
731 if ( is_array( $v ) ) { |
1391 $array[$k] = add_magic_quotes( $v ); |
732 $array[$k] = add_magic_quotes( $v ); |
1392 } else { |
733 } else { |
1393 $array[$k] = esc_sql( $v ); |
734 $array[$k] = addslashes( $v ); |
1394 } |
735 } |
1395 } |
736 } |
1396 return $array; |
737 return $array; |
1397 } |
738 } |
1398 |
739 |
1417 $response = wp_remote_get( $uri, $options ); |
758 $response = wp_remote_get( $uri, $options ); |
1418 |
759 |
1419 if ( is_wp_error( $response ) ) |
760 if ( is_wp_error( $response ) ) |
1420 return false; |
761 return false; |
1421 |
762 |
1422 return $response['body']; |
763 return wp_remote_retrieve_body( $response ); |
1423 } |
764 } |
1424 |
765 |
1425 /** |
766 /** |
1426 * Setup the WordPress query. |
767 * Set up the WordPress query. |
1427 * |
768 * |
1428 * @since 2.0.0 |
769 * @since 2.0.0 |
1429 * |
770 * |
1430 * @param string $query_vars Default WP_Query arguments. |
771 * @param string $query_vars Default WP_Query arguments. |
1431 */ |
772 */ |
1432 function wp( $query_vars = '' ) { |
773 function wp( $query_vars = '' ) { |
1433 global $wp, $wp_query, $wp_the_query; |
774 global $wp, $wp_query, $wp_the_query; |
1434 $wp->main( $query_vars ); |
775 $wp->main( $query_vars ); |
1435 |
776 |
1436 if( !isset($wp_the_query) ) |
777 if ( !isset($wp_the_query) ) |
1437 $wp_the_query = $wp_query; |
778 $wp_the_query = $wp_query; |
1438 } |
779 } |
1439 |
780 |
1440 /** |
781 /** |
1441 * Retrieve the description for the HTTP status. |
782 * Retrieve the description for the HTTP status. |
1523 * @uses apply_filters() Calls 'status_header' on status header string, HTTP |
864 * @uses apply_filters() Calls 'status_header' on status header string, HTTP |
1524 * HTTP code, HTTP code description, and protocol string as separate |
865 * HTTP code, HTTP code description, and protocol string as separate |
1525 * parameters. |
866 * parameters. |
1526 * |
867 * |
1527 * @param int $header HTTP status code |
868 * @param int $header HTTP status code |
1528 * @return null Does not return anything. |
869 * @return unknown |
1529 */ |
870 */ |
1530 function status_header( $header ) { |
871 function status_header( $header ) { |
1531 $text = get_status_header_desc( $header ); |
872 $text = get_status_header_desc( $header ); |
1532 |
873 |
1533 if ( empty( $text ) ) |
874 if ( empty( $text ) ) |
1547 * Gets the header information to prevent caching. |
888 * Gets the header information to prevent caching. |
1548 * |
889 * |
1549 * The several different headers cover the different ways cache prevention is handled |
890 * The several different headers cover the different ways cache prevention is handled |
1550 * by different browsers |
891 * by different browsers |
1551 * |
892 * |
1552 * @since 2.8 |
893 * @since 2.8.0 |
1553 * |
894 * |
1554 * @uses apply_filters() |
895 * @uses apply_filters() |
1555 * @return array The associative array of header names and field values. |
896 * @return array The associative array of header names and field values. |
1556 */ |
897 */ |
1557 function wp_get_nocache_headers() { |
898 function wp_get_nocache_headers() { |
1561 'Cache-Control' => 'no-cache, must-revalidate, max-age=0', |
902 'Cache-Control' => 'no-cache, must-revalidate, max-age=0', |
1562 'Pragma' => 'no-cache', |
903 'Pragma' => 'no-cache', |
1563 ); |
904 ); |
1564 |
905 |
1565 if ( function_exists('apply_filters') ) { |
906 if ( function_exists('apply_filters') ) { |
1566 $headers = apply_filters('nocache_headers', $headers); |
907 $headers = (array) apply_filters('nocache_headers', $headers); |
1567 } |
908 } |
1568 return $headers; |
909 return $headers; |
1569 } |
910 } |
1570 |
911 |
1571 /** |
912 /** |
1577 * @since 2.0.0 |
918 * @since 2.0.0 |
1578 * @uses wp_get_nocache_headers() |
919 * @uses wp_get_nocache_headers() |
1579 */ |
920 */ |
1580 function nocache_headers() { |
921 function nocache_headers() { |
1581 $headers = wp_get_nocache_headers(); |
922 $headers = wp_get_nocache_headers(); |
1582 foreach( (array) $headers as $name => $field_value ) |
923 foreach( $headers as $name => $field_value ) |
1583 @header("{$name}: {$field_value}"); |
924 @header("{$name}: {$field_value}"); |
1584 } |
925 } |
1585 |
926 |
1586 /** |
927 /** |
1587 * Set the headers for caching for 10 days with JavaScript content type. |
928 * Set the headers for caching for 10 days with JavaScript content type. |
1642 if ( $feed == '' || $feed == 'feed' ) |
983 if ( $feed == '' || $feed == 'feed' ) |
1643 $feed = get_default_feed(); |
984 $feed = get_default_feed(); |
1644 |
985 |
1645 $hook = 'do_feed_' . $feed; |
986 $hook = 'do_feed_' . $feed; |
1646 if ( !has_action($hook) ) { |
987 if ( !has_action($hook) ) { |
1647 $message = sprintf( __( 'ERROR: %s is not a valid feed template' ), esc_html($feed)); |
988 $message = sprintf( __( 'ERROR: %s is not a valid feed template.' ), esc_html($feed)); |
1648 wp_die($message); |
989 wp_die( $message, '', array( 'response' => 404 ) ); |
1649 } |
990 } |
1650 |
991 |
1651 do_action( $hook, $wp_query->is_comment_feed ); |
992 do_action( $hook, $wp_query->is_comment_feed ); |
1652 } |
993 } |
1653 |
994 |
1659 function do_feed_rdf() { |
1000 function do_feed_rdf() { |
1660 load_template( ABSPATH . WPINC . '/feed-rdf.php' ); |
1001 load_template( ABSPATH . WPINC . '/feed-rdf.php' ); |
1661 } |
1002 } |
1662 |
1003 |
1663 /** |
1004 /** |
1664 * Load the RSS 1.0 Feed Template |
1005 * Load the RSS 1.0 Feed Template. |
1665 * |
1006 * |
1666 * @since 2.1.0 |
1007 * @since 2.1.0 |
1667 */ |
1008 */ |
1668 function do_feed_rss() { |
1009 function do_feed_rss() { |
1669 load_template( ABSPATH . WPINC . '/feed-rss.php' ); |
1010 load_template( ABSPATH . WPINC . '/feed-rss.php' ); |
1696 else |
1037 else |
1697 load_template( ABSPATH . WPINC . '/feed-atom.php' ); |
1038 load_template( ABSPATH . WPINC . '/feed-atom.php' ); |
1698 } |
1039 } |
1699 |
1040 |
1700 /** |
1041 /** |
1701 * Display the robot.txt file content. |
1042 * Display the robots.txt file content. |
1702 * |
1043 * |
1703 * The echo content should be with usage of the permalinks or for creating the |
1044 * The echo content should be with usage of the permalinks or for creating the |
1704 * robot.txt file. |
1045 * robots.txt file. |
1705 * |
1046 * |
1706 * @since 2.1.0 |
1047 * @since 2.1.0 |
1707 * @uses do_action() Calls 'do_robotstxt' hook for displaying robot.txt rules. |
1048 * @uses do_action() Calls 'do_robotstxt' hook for displaying robots.txt rules. |
1708 */ |
1049 */ |
1709 function do_robots() { |
1050 function do_robots() { |
1710 header( 'Content-Type: text/plain; charset=utf-8' ); |
1051 header( 'Content-Type: text/plain; charset=utf-8' ); |
1711 |
1052 |
1712 do_action( 'do_robotstxt' ); |
1053 do_action( 'do_robotstxt' ); |
1713 |
1054 |
1714 if ( '0' == get_option( 'blog_public' ) ) { |
1055 $output = "User-agent: *\n"; |
1715 echo "User-agent: *\n"; |
1056 $public = get_option( 'blog_public' ); |
1716 echo "Disallow: /\n"; |
1057 if ( '0' == $public ) { |
1058 $output .= "Disallow: /\n"; |
|
1717 } else { |
1059 } else { |
1718 echo "User-agent: *\n"; |
1060 $site_url = parse_url( site_url() ); |
1719 echo "Disallow:\n"; |
1061 $path = ( !empty( $site_url['path'] ) ) ? $site_url['path'] : ''; |
1720 } |
1062 $output .= "Disallow: $path/wp-admin/\n"; |
1063 $output .= "Disallow: $path/wp-includes/\n"; |
|
1064 } |
|
1065 |
|
1066 echo apply_filters('robots_txt', $output, $public); |
|
1721 } |
1067 } |
1722 |
1068 |
1723 /** |
1069 /** |
1724 * Test whether blog is already installed. |
1070 * Test whether blog is already installed. |
1725 * |
1071 * |
1740 // Check cache first. If options table goes away and we have true cached, oh well. |
1086 // Check cache first. If options table goes away and we have true cached, oh well. |
1741 if ( wp_cache_get( 'is_blog_installed' ) ) |
1087 if ( wp_cache_get( 'is_blog_installed' ) ) |
1742 return true; |
1088 return true; |
1743 |
1089 |
1744 $suppress = $wpdb->suppress_errors(); |
1090 $suppress = $wpdb->suppress_errors(); |
1745 $alloptions = wp_load_alloptions(); |
1091 if ( ! defined( 'WP_INSTALLING' ) ) { |
1092 $alloptions = wp_load_alloptions(); |
|
1093 } |
|
1746 // If siteurl is not set to autoload, check it specifically |
1094 // If siteurl is not set to autoload, check it specifically |
1747 if ( !isset( $alloptions['siteurl'] ) ) |
1095 if ( !isset( $alloptions['siteurl'] ) ) |
1748 $installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" ); |
1096 $installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" ); |
1749 else |
1097 else |
1750 $installed = $alloptions['siteurl']; |
1098 $installed = $alloptions['siteurl']; |
1754 wp_cache_set( 'is_blog_installed', $installed ); |
1102 wp_cache_set( 'is_blog_installed', $installed ); |
1755 |
1103 |
1756 if ( $installed ) |
1104 if ( $installed ) |
1757 return true; |
1105 return true; |
1758 |
1106 |
1107 // If visiting repair.php, return true and let it take over. |
|
1108 if ( defined( 'WP_REPAIRING' ) ) |
|
1109 return true; |
|
1110 |
|
1759 $suppress = $wpdb->suppress_errors(); |
1111 $suppress = $wpdb->suppress_errors(); |
1760 $tables = $wpdb->get_col('SHOW TABLES'); |
1112 |
1761 $wpdb->suppress_errors( $suppress ); |
1113 // Loop over the WP tables. If none exist, then scratch install is allowed. |
1762 |
|
1763 // Loop over the WP tables. If none exist, then scratch install is allowed. |
|
1764 // If one or more exist, suggest table repair since we got here because the options |
1114 // If one or more exist, suggest table repair since we got here because the options |
1765 // table could not be accessed. |
1115 // table could not be accessed. |
1766 foreach ($wpdb->tables as $table) { |
1116 $wp_tables = $wpdb->tables(); |
1767 // If one of the WP tables exist, then we are in an insane state. |
1117 foreach ( $wp_tables as $table ) { |
1768 if ( in_array($wpdb->prefix . $table, $tables) ) { |
1118 // The existence of custom user tables shouldn't suggest an insane state or prevent a clean install. |
1769 // If visiting repair.php, return true and let it take over. |
1119 if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table ) |
1770 if ( defined('WP_REPAIRING') ) |
1120 continue; |
1771 return true; |
1121 if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table ) |
1772 // Die with a DB error. |
1122 continue; |
1773 $wpdb->error = __('One or more database tables are unavailable. The database may need to be <a href="maint/repair.php?referrer=is_blog_installed">repaired</a>.'); |
1123 |
1774 dead_db(); |
1124 if ( ! $wpdb->get_results( "DESCRIBE $table;" ) ) |
1775 } |
1125 continue; |
1776 } |
1126 |
1127 // One or more tables exist. We are insane. |
|
1128 |
|
1129 wp_load_translations_early(); |
|
1130 |
|
1131 // Die with a DB error. |
|
1132 $wpdb->error = sprintf( __( 'One or more database tables are unavailable. The database may need to be <a href="%s">repaired</a>.' ), 'maint/repair.php?referrer=is_blog_installed' ); |
|
1133 dead_db(); |
|
1134 } |
|
1135 |
|
1136 $wpdb->suppress_errors( $suppress ); |
|
1777 |
1137 |
1778 wp_cache_set( 'is_blog_installed', false ); |
1138 wp_cache_set( 'is_blog_installed', false ); |
1779 |
1139 |
1780 return false; |
1140 return false; |
1781 } |
1141 } |
1801 * |
1161 * |
1802 * The nonce field is used to validate that the contents of the form came from |
1162 * The nonce field is used to validate that the contents of the form came from |
1803 * the location on the current site and not somewhere else. The nonce does not |
1163 * the location on the current site and not somewhere else. The nonce does not |
1804 * offer absolute protection, but should protect against most cases. It is very |
1164 * offer absolute protection, but should protect against most cases. It is very |
1805 * important to use nonce field in forms. |
1165 * important to use nonce field in forms. |
1806 * |
|
1807 * If you set $echo to true and set $referer to true, then you will need to |
|
1808 * retrieve the {@link wp_referer_field() wp referer field}. If you have the |
|
1809 * $referer set to true and are echoing the nonce field, it will also echo the |
|
1810 * referer field. |
|
1811 * |
1166 * |
1812 * The $action and $name are optional, but if you want to have better security, |
1167 * The $action and $name are optional, but if you want to have better security, |
1813 * it is strongly suggested to set those two parameters. It is easier to just |
1168 * it is strongly suggested to set those two parameters. It is easier to just |
1814 * call the function without any parameters, because validation of the nonce |
1169 * call the function without any parameters, because validation of the nonce |
1815 * doesn't require any parameters, but since crackers know what the default is |
1170 * doesn't require any parameters, but since crackers know what the default is |
1830 * @return string Nonce field. |
1185 * @return string Nonce field. |
1831 */ |
1186 */ |
1832 function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = true ) { |
1187 function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = true ) { |
1833 $name = esc_attr( $name ); |
1188 $name = esc_attr( $name ); |
1834 $nonce_field = '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />'; |
1189 $nonce_field = '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />'; |
1190 |
|
1191 if ( $referer ) |
|
1192 $nonce_field .= wp_referer_field( false ); |
|
1193 |
|
1835 if ( $echo ) |
1194 if ( $echo ) |
1836 echo $nonce_field; |
1195 echo $nonce_field; |
1837 |
|
1838 if ( $referer ) |
|
1839 wp_referer_field( $echo, 'previous' ); |
|
1840 |
1196 |
1841 return $nonce_field; |
1197 return $nonce_field; |
1842 } |
1198 } |
1843 |
1199 |
1844 /** |
1200 /** |
1852 * @since 2.0.4 |
1208 * @since 2.0.4 |
1853 * |
1209 * |
1854 * @param bool $echo Whether to echo or return the referer field. |
1210 * @param bool $echo Whether to echo or return the referer field. |
1855 * @return string Referer field. |
1211 * @return string Referer field. |
1856 */ |
1212 */ |
1857 function wp_referer_field( $echo = true) { |
1213 function wp_referer_field( $echo = true ) { |
1858 $ref = esc_attr( $_SERVER['REQUEST_URI'] ); |
1214 $ref = esc_attr( $_SERVER['REQUEST_URI'] ); |
1859 $referer_field = '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />'; |
1215 $referer_field = '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />'; |
1860 |
1216 |
1861 if ( $echo ) |
1217 if ( $echo ) |
1862 echo $referer_field; |
1218 echo $referer_field; |
1886 echo $orig_referer_field; |
1242 echo $orig_referer_field; |
1887 return $orig_referer_field; |
1243 return $orig_referer_field; |
1888 } |
1244 } |
1889 |
1245 |
1890 /** |
1246 /** |
1891 * Retrieve referer from '_wp_http_referer', HTTP referer, or current page respectively. |
1247 * Retrieve referer from '_wp_http_referer' or HTTP referer. If it's the same |
1248 * as the current request URL, will return false. |
|
1892 * |
1249 * |
1893 * @package WordPress |
1250 * @package WordPress |
1894 * @subpackage Security |
1251 * @subpackage Security |
1895 * @since 2.0.4 |
1252 * @since 2.0.4 |
1896 * |
1253 * |
1897 * @return string|bool False on failure. Referer URL on success. |
1254 * @return string|bool False on failure. Referer URL on success. |
1898 */ |
1255 */ |
1899 function wp_get_referer() { |
1256 function wp_get_referer() { |
1900 $ref = ''; |
1257 $ref = false; |
1901 if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) |
1258 if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) |
1902 $ref = $_REQUEST['_wp_http_referer']; |
1259 $ref = $_REQUEST['_wp_http_referer']; |
1903 else if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) |
1260 else if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) |
1904 $ref = $_SERVER['HTTP_REFERER']; |
1261 $ref = $_SERVER['HTTP_REFERER']; |
1905 |
1262 |
1906 if ( $ref !== $_SERVER['REQUEST_URI'] ) |
1263 if ( $ref && $ref !== $_SERVER['REQUEST_URI'] ) |
1907 return $ref; |
1264 return $ref; |
1908 return false; |
1265 return false; |
1909 } |
1266 } |
1910 |
1267 |
1911 /** |
1268 /** |
1929 * Will attempt to set permissions on folders. |
1286 * Will attempt to set permissions on folders. |
1930 * |
1287 * |
1931 * @since 2.0.1 |
1288 * @since 2.0.1 |
1932 * |
1289 * |
1933 * @param string $target Full path to attempt to create. |
1290 * @param string $target Full path to attempt to create. |
1934 * @return bool Whether the path was created or not. True if path already exists. |
1291 * @return bool Whether the path was created. True if path already exists. |
1935 */ |
1292 */ |
1936 function wp_mkdir_p( $target ) { |
1293 function wp_mkdir_p( $target ) { |
1937 // from php.net/mkdir user contributed notes |
1294 // from php.net/mkdir user contributed notes |
1938 $target = str_replace( '//', '/', $target ); |
1295 $target = str_replace( '//', '/', $target ); |
1296 |
|
1297 // safe mode fails with a trailing slash under certain PHP versions. |
|
1298 $target = rtrim($target, '/'); // Use rtrim() instead of untrailingslashit to avoid formatting.php dependency. |
|
1299 if ( empty($target) ) |
|
1300 $target = '/'; |
|
1301 |
|
1939 if ( file_exists( $target ) ) |
1302 if ( file_exists( $target ) ) |
1940 return @is_dir( $target ); |
1303 return @is_dir( $target ); |
1941 |
1304 |
1942 // Attempting to create the directory may clutter up our display. |
1305 // Attempting to create the directory may clutter up our display. |
1943 if ( @mkdir( $target ) ) { |
1306 if ( @mkdir( $target ) ) { |
1967 function path_is_absolute( $path ) { |
1330 function path_is_absolute( $path ) { |
1968 // this is definitive if true but fails if $path does not exist or contains a symbolic link |
1331 // this is definitive if true but fails if $path does not exist or contains a symbolic link |
1969 if ( realpath($path) == $path ) |
1332 if ( realpath($path) == $path ) |
1970 return true; |
1333 return true; |
1971 |
1334 |
1972 if ( strlen($path) == 0 || $path{0} == '.' ) |
1335 if ( strlen($path) == 0 || $path[0] == '.' ) |
1973 return false; |
1336 return false; |
1974 |
1337 |
1975 // windows allows absolute paths like this |
1338 // windows allows absolute paths like this |
1976 if ( preg_match('#^[a-zA-Z]:\\\\#', $path) ) |
1339 if ( preg_match('#^[a-zA-Z]:\\\\#', $path) ) |
1977 return true; |
1340 return true; |
1978 |
1341 |
1979 // a path starting with / or \ is absolute; anything else is relative |
1342 // a path starting with / or \ is absolute; anything else is relative |
1980 return (bool) preg_match('#^[/\\\\]#', $path); |
1343 return ( $path[0] == '/' || $path[0] == '\\' ); |
1981 } |
1344 } |
1982 |
1345 |
1983 /** |
1346 /** |
1984 * Join two filesystem paths together (e.g. 'give me $path relative to $base'). |
1347 * Join two filesystem paths together (e.g. 'give me $path relative to $base'). |
1985 * |
1348 * |
1994 function path_join( $base, $path ) { |
1357 function path_join( $base, $path ) { |
1995 if ( path_is_absolute($path) ) |
1358 if ( path_is_absolute($path) ) |
1996 return $path; |
1359 return $path; |
1997 |
1360 |
1998 return rtrim($base, '/') . '/' . ltrim($path, '/'); |
1361 return rtrim($base, '/') . '/' . ltrim($path, '/'); |
1362 } |
|
1363 |
|
1364 /** |
|
1365 * Determines a writable directory for temporary files. |
|
1366 * Function's preference is to WP_CONTENT_DIR followed by the return value of <code>sys_get_temp_dir()</code>, before finally defaulting to /tmp/ |
|
1367 * |
|
1368 * In the event that this function does not find a writable location, It may be overridden by the <code>WP_TEMP_DIR</code> constant in your <code>wp-config.php</code> file. |
|
1369 * |
|
1370 * @since 2.5.0 |
|
1371 * |
|
1372 * @return string Writable temporary directory |
|
1373 */ |
|
1374 function get_temp_dir() { |
|
1375 static $temp; |
|
1376 if ( defined('WP_TEMP_DIR') ) |
|
1377 return trailingslashit(WP_TEMP_DIR); |
|
1378 |
|
1379 if ( $temp ) |
|
1380 return trailingslashit($temp); |
|
1381 |
|
1382 $temp = WP_CONTENT_DIR . '/'; |
|
1383 if ( is_dir($temp) && @is_writable($temp) ) |
|
1384 return $temp; |
|
1385 |
|
1386 if ( function_exists('sys_get_temp_dir') ) { |
|
1387 $temp = sys_get_temp_dir(); |
|
1388 if ( @is_writable($temp) ) |
|
1389 return trailingslashit($temp); |
|
1390 } |
|
1391 |
|
1392 $temp = ini_get('upload_tmp_dir'); |
|
1393 if ( is_dir($temp) && @is_writable($temp) ) |
|
1394 return trailingslashit($temp); |
|
1395 |
|
1396 $temp = '/tmp/'; |
|
1397 return $temp; |
|
1999 } |
1398 } |
2000 |
1399 |
2001 /** |
1400 /** |
2002 * Get an array containing the current upload directory's path and url. |
1401 * Get an array containing the current upload directory's path and url. |
2003 * |
1402 * |
2030 * |
1429 * |
2031 * @param string $time Optional. Time formatted in 'yyyy/mm'. |
1430 * @param string $time Optional. Time formatted in 'yyyy/mm'. |
2032 * @return array See above for description. |
1431 * @return array See above for description. |
2033 */ |
1432 */ |
2034 function wp_upload_dir( $time = null ) { |
1433 function wp_upload_dir( $time = null ) { |
1434 global $switched; |
|
2035 $siteurl = get_option( 'siteurl' ); |
1435 $siteurl = get_option( 'siteurl' ); |
2036 $upload_path = get_option( 'upload_path' ); |
1436 $upload_path = get_option( 'upload_path' ); |
2037 $upload_path = trim($upload_path); |
1437 $upload_path = trim($upload_path); |
1438 $main_override = is_multisite() && defined( 'MULTISITE' ) && is_main_site(); |
|
2038 if ( empty($upload_path) ) { |
1439 if ( empty($upload_path) ) { |
2039 $dir = WP_CONTENT_DIR . '/uploads'; |
1440 $dir = WP_CONTENT_DIR . '/uploads'; |
2040 } else { |
1441 } else { |
2041 $dir = $upload_path; |
1442 $dir = $upload_path; |
2042 if ( 'wp-content/uploads' == $upload_path ) { |
1443 if ( 'wp-content/uploads' == $upload_path ) { |
2052 $url = WP_CONTENT_URL . '/uploads'; |
1453 $url = WP_CONTENT_URL . '/uploads'; |
2053 else |
1454 else |
2054 $url = trailingslashit( $siteurl ) . $upload_path; |
1455 $url = trailingslashit( $siteurl ) . $upload_path; |
2055 } |
1456 } |
2056 |
1457 |
2057 if ( defined('UPLOADS') ) { |
1458 if ( defined('UPLOADS') && !$main_override && ( !isset( $switched ) || $switched === false ) ) { |
2058 $dir = ABSPATH . UPLOADS; |
1459 $dir = ABSPATH . UPLOADS; |
2059 $url = trailingslashit( $siteurl ) . UPLOADS; |
1460 $url = trailingslashit( $siteurl ) . UPLOADS; |
1461 } |
|
1462 |
|
1463 if ( is_multisite() && !$main_override && ( !isset( $switched ) || $switched === false ) ) { |
|
1464 if ( defined( 'BLOGUPLOADDIR' ) ) |
|
1465 $dir = untrailingslashit(BLOGUPLOADDIR); |
|
1466 $url = str_replace( UPLOADS, 'files', $url ); |
|
2060 } |
1467 } |
2061 |
1468 |
2062 $bdir = $dir; |
1469 $bdir = $dir; |
2063 $burl = $url; |
1470 $burl = $url; |
2064 |
1471 |
2077 |
1484 |
2078 $uploads = apply_filters( 'upload_dir', array( 'path' => $dir, 'url' => $url, 'subdir' => $subdir, 'basedir' => $bdir, 'baseurl' => $burl, 'error' => false ) ); |
1485 $uploads = apply_filters( 'upload_dir', array( 'path' => $dir, 'url' => $url, 'subdir' => $subdir, 'basedir' => $bdir, 'baseurl' => $burl, 'error' => false ) ); |
2079 |
1486 |
2080 // Make sure we have an uploads dir |
1487 // Make sure we have an uploads dir |
2081 if ( ! wp_mkdir_p( $uploads['path'] ) ) { |
1488 if ( ! wp_mkdir_p( $uploads['path'] ) ) { |
2082 $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $uploads['path'] ); |
1489 if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) |
1490 $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir']; |
|
1491 else |
|
1492 $error_path = basename( $uploads['basedir'] ) . $uploads['subdir']; |
|
1493 |
|
1494 $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $error_path ); |
|
2083 return array( 'error' => $message ); |
1495 return array( 'error' => $message ); |
2084 } |
1496 } |
2085 |
1497 |
2086 return $uploads; |
1498 return $uploads; |
2087 } |
1499 } |
2091 * |
1503 * |
2092 * If the filename is not unique, then a number will be added to the filename |
1504 * If the filename is not unique, then a number will be added to the filename |
2093 * before the extension, and will continue adding numbers until the filename is |
1505 * before the extension, and will continue adding numbers until the filename is |
2094 * unique. |
1506 * unique. |
2095 * |
1507 * |
2096 * The callback must accept two parameters, the first one is the directory and |
1508 * The callback is passed three parameters, the first one is the directory, the |
2097 * the second is the filename. The callback must be a function. |
1509 * second is the filename, and the third is the extension. |
2098 * |
1510 * |
2099 * @since 2.5 |
1511 * @since 2.5.0 |
2100 * |
1512 * |
2101 * @param string $dir |
1513 * @param string $dir |
2102 * @param string $filename |
1514 * @param string $filename |
2103 * @param string $unique_filename_callback Function name, must be a function. |
1515 * @param mixed $unique_filename_callback Callback. |
2104 * @return string New filename, if given wasn't unique. |
1516 * @return string New filename, if given wasn't unique. |
2105 */ |
1517 */ |
2106 function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) { |
1518 function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) { |
2107 // sanitize the file name before we begin processing |
1519 // sanitize the file name before we begin processing |
2108 $filename = sanitize_file_name($filename); |
1520 $filename = sanitize_file_name($filename); |
2111 $info = pathinfo($filename); |
1523 $info = pathinfo($filename); |
2112 $ext = !empty($info['extension']) ? '.' . $info['extension'] : ''; |
1524 $ext = !empty($info['extension']) ? '.' . $info['extension'] : ''; |
2113 $name = basename($filename, $ext); |
1525 $name = basename($filename, $ext); |
2114 |
1526 |
2115 // edge case: if file is named '.ext', treat as an empty name |
1527 // edge case: if file is named '.ext', treat as an empty name |
2116 if( $name === $ext ) |
1528 if ( $name === $ext ) |
2117 $name = ''; |
1529 $name = ''; |
2118 |
1530 |
2119 // Increment the file number until we have a unique file to save in $dir. Use $override['unique_filename_callback'] if supplied. |
1531 // Increment the file number until we have a unique file to save in $dir. Use callback if supplied. |
2120 if ( $unique_filename_callback && function_exists( $unique_filename_callback ) ) { |
1532 if ( $unique_filename_callback && is_callable( $unique_filename_callback ) ) { |
2121 $filename = $unique_filename_callback( $dir, $name ); |
1533 $filename = call_user_func( $unique_filename_callback, $dir, $name, $ext ); |
2122 } else { |
1534 } else { |
2123 $number = ''; |
1535 $number = ''; |
2124 |
1536 |
2125 // change '.ext' to lower case |
1537 // change '.ext' to lower case |
2126 if ( $ext && strtolower($ext) != $ext ) { |
1538 if ( $ext && strtolower($ext) != $ext ) { |
2164 * The permissions will be set on the new file automatically by this function. |
1576 * The permissions will be set on the new file automatically by this function. |
2165 * |
1577 * |
2166 * @since 2.0.0 |
1578 * @since 2.0.0 |
2167 * |
1579 * |
2168 * @param string $name |
1580 * @param string $name |
2169 * @param null $deprecated Not used. Set to null. |
1581 * @param null $deprecated Never used. Set to null. |
2170 * @param mixed $bits File content |
1582 * @param mixed $bits File content |
2171 * @param string $time Optional. Time formatted in 'yyyy/mm'. |
1583 * @param string $time Optional. Time formatted in 'yyyy/mm'. |
2172 * @return array |
1584 * @return array |
2173 */ |
1585 */ |
2174 function wp_upload_bits( $name, $deprecated, $bits, $time = null ) { |
1586 function wp_upload_bits( $name, $deprecated, $bits, $time = null ) { |
1587 if ( !empty( $deprecated ) ) |
|
1588 _deprecated_argument( __FUNCTION__, '2.0' ); |
|
1589 |
|
2175 if ( empty( $name ) ) |
1590 if ( empty( $name ) ) |
2176 return array( 'error' => __( 'Empty filename' ) ); |
1591 return array( 'error' => __( 'Empty filename' ) ); |
2177 |
1592 |
2178 $wp_filetype = wp_check_filetype( $name ); |
1593 $wp_filetype = wp_check_filetype( $name ); |
2179 if ( !$wp_filetype['ext'] ) |
1594 if ( !$wp_filetype['ext'] ) |
2182 $upload = wp_upload_dir( $time ); |
1597 $upload = wp_upload_dir( $time ); |
2183 |
1598 |
2184 if ( $upload['error'] !== false ) |
1599 if ( $upload['error'] !== false ) |
2185 return $upload; |
1600 return $upload; |
2186 |
1601 |
1602 $upload_bits_error = apply_filters( 'wp_upload_bits', array( 'name' => $name, 'bits' => $bits, 'time' => $time ) ); |
|
1603 if ( !is_array( $upload_bits_error ) ) { |
|
1604 $upload[ 'error' ] = $upload_bits_error; |
|
1605 return $upload; |
|
1606 } |
|
1607 |
|
2187 $filename = wp_unique_filename( $upload['path'], $name ); |
1608 $filename = wp_unique_filename( $upload['path'], $name ); |
2188 |
1609 |
2189 $new_file = $upload['path'] . "/$filename"; |
1610 $new_file = $upload['path'] . "/$filename"; |
2190 if ( ! wp_mkdir_p( dirname( $new_file ) ) ) { |
1611 if ( ! wp_mkdir_p( dirname( $new_file ) ) ) { |
2191 $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), dirname( $new_file ) ); |
1612 if ( 0 === strpos( $upload['basedir'], ABSPATH ) ) |
1613 $error_path = str_replace( ABSPATH, '', $upload['basedir'] ) . $upload['subdir']; |
|
1614 else |
|
1615 $error_path = basename( $upload['basedir'] ) . $upload['subdir']; |
|
1616 |
|
1617 $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $error_path ); |
|
2192 return array( 'error' => $message ); |
1618 return array( 'error' => $message ); |
2193 } |
1619 } |
2194 |
1620 |
2195 $ifp = @ fopen( $new_file, 'wb' ); |
1621 $ifp = @ fopen( $new_file, 'wb' ); |
2196 if ( ! $ifp ) |
1622 if ( ! $ifp ) |
2197 return array( 'error' => sprintf( __( 'Could not write file %s' ), $new_file ) ); |
1623 return array( 'error' => sprintf( __( 'Could not write file %s' ), $new_file ) ); |
2198 |
1624 |
2199 @fwrite( $ifp, $bits ); |
1625 @fwrite( $ifp, $bits ); |
2200 fclose( $ifp ); |
1626 fclose( $ifp ); |
1627 clearstatcache(); |
|
1628 |
|
2201 // Set correct file permissions |
1629 // Set correct file permissions |
2202 $stat = @ stat( dirname( $new_file ) ); |
1630 $stat = @ stat( dirname( $new_file ) ); |
2203 $perms = $stat['mode'] & 0007777; |
1631 $perms = $stat['mode'] & 0007777; |
2204 $perms = $perms & 0000666; |
1632 $perms = $perms & 0000666; |
2205 @ chmod( $new_file, $perms ); |
1633 @ chmod( $new_file, $perms ); |
1634 clearstatcache(); |
|
2206 |
1635 |
2207 // Compute the URL |
1636 // Compute the URL |
2208 $url = $upload['url'] . "/$filename"; |
1637 $url = $upload['url'] . "/$filename"; |
2209 |
1638 |
2210 return array( 'file' => $new_file, 'url' => $url, 'error' => false ); |
1639 return array( 'file' => $new_file, 'url' => $url, 'error' => false ); |
2219 * |
1648 * |
2220 * @param string $ext The extension to search. |
1649 * @param string $ext The extension to search. |
2221 * @return string|null The file type, example: audio, video, document, spreadsheet, etc. Null if not found. |
1650 * @return string|null The file type, example: audio, video, document, spreadsheet, etc. Null if not found. |
2222 */ |
1651 */ |
2223 function wp_ext2type( $ext ) { |
1652 function wp_ext2type( $ext ) { |
2224 $ext2type = apply_filters('ext2type', array( |
1653 $ext2type = apply_filters( 'ext2type', array( |
2225 'audio' => array('aac','ac3','aif','aiff','mp1','mp2','mp3','m3a','m4a','m4b','ogg','ram','wav','wma'), |
1654 'audio' => array( 'aac', 'ac3', 'aif', 'aiff', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ), |
2226 'video' => array('asf','avi','divx','dv','mov','mpg','mpeg','mp4','mpv','ogm','qt','rm','vob','wmv', 'm4v'), |
1655 'video' => array( 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv' ), |
2227 'document' => array('doc','docx','pages','odt','rtf','pdf'), |
1656 'document' => array( 'doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'rtf', 'wp', 'wpd' ), |
2228 'spreadsheet' => array('xls','xlsx','numbers','ods'), |
1657 'spreadsheet' => array( 'numbers', 'ods', 'xls', 'xlsx', 'xlsb', 'xlsm' ), |
2229 'interactive' => array('ppt','pptx','key','odp','swf'), |
1658 'interactive' => array( 'key', 'ppt', 'pptx', 'pptm', 'odp', 'swf' ), |
2230 'text' => array('txt'), |
1659 'text' => array( 'asc', 'csv', 'tsv', 'txt' ), |
2231 'archive' => array('tar','bz2','gz','cab','dmg','rar','sea','sit','sqx','zip'), |
1660 'archive' => array( 'bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip', '7z' ), |
2232 'code' => array('css','html','php','js'), |
1661 'code' => array( 'css', 'htm', 'html', 'php', 'js' ), |
2233 )); |
1662 )); |
2234 foreach ( $ext2type as $type => $exts ) |
1663 foreach ( $ext2type as $type => $exts ) |
2235 if ( in_array($ext, $exts) ) |
1664 if ( in_array( $ext, $exts ) ) |
2236 return $type; |
1665 return $type; |
2237 } |
1666 } |
2238 |
1667 |
2239 /** |
1668 /** |
2240 * Retrieve the file type from the file name. |
1669 * Retrieve the file type from the file name. |
2261 break; |
1690 break; |
2262 } |
1691 } |
2263 } |
1692 } |
2264 |
1693 |
2265 return compact( 'ext', 'type' ); |
1694 return compact( 'ext', 'type' ); |
1695 } |
|
1696 |
|
1697 /** |
|
1698 * Attempt to determine the real file type of a file. |
|
1699 * If unable to, the file name extension will be used to determine type. |
|
1700 * |
|
1701 * If it's determined that the extension does not match the file's real type, |
|
1702 * then the "proper_filename" value will be set with a proper filename and extension. |
|
1703 * |
|
1704 * Currently this function only supports validating images known to getimagesize(). |
|
1705 * |
|
1706 * @since 3.0.0 |
|
1707 * |
|
1708 * @param string $file Full path to the image. |
|
1709 * @param string $filename The filename of the image (may differ from $file due to $file being in a tmp directory) |
|
1710 * @param array $mimes Optional. Key is the file extension with value as the mime type. |
|
1711 * @return array Values for the extension, MIME, and either a corrected filename or false if original $filename is valid |
|
1712 */ |
|
1713 function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { |
|
1714 |
|
1715 $proper_filename = false; |
|
1716 |
|
1717 // Do basic extension validation and MIME mapping |
|
1718 $wp_filetype = wp_check_filetype( $filename, $mimes ); |
|
1719 extract( $wp_filetype ); |
|
1720 |
|
1721 // We can't do any further validation without a file to work with |
|
1722 if ( ! file_exists( $file ) ) |
|
1723 return compact( 'ext', 'type', 'proper_filename' ); |
|
1724 |
|
1725 // We're able to validate images using GD |
|
1726 if ( $type && 0 === strpos( $type, 'image/' ) && function_exists('getimagesize') ) { |
|
1727 |
|
1728 // Attempt to figure out what type of image it actually is |
|
1729 $imgstats = @getimagesize( $file ); |
|
1730 |
|
1731 // If getimagesize() knows what kind of image it really is and if the real MIME doesn't match the claimed MIME |
|
1732 if ( !empty($imgstats['mime']) && $imgstats['mime'] != $type ) { |
|
1733 // This is a simplified array of MIMEs that getimagesize() can detect and their extensions |
|
1734 // You shouldn't need to use this filter, but it's here just in case |
|
1735 $mime_to_ext = apply_filters( 'getimagesize_mimes_to_exts', array( |
|
1736 'image/jpeg' => 'jpg', |
|
1737 'image/png' => 'png', |
|
1738 'image/gif' => 'gif', |
|
1739 'image/bmp' => 'bmp', |
|
1740 'image/tiff' => 'tif', |
|
1741 ) ); |
|
1742 |
|
1743 // Replace whatever is after the last period in the filename with the correct extension |
|
1744 if ( ! empty( $mime_to_ext[ $imgstats['mime'] ] ) ) { |
|
1745 $filename_parts = explode( '.', $filename ); |
|
1746 array_pop( $filename_parts ); |
|
1747 $filename_parts[] = $mime_to_ext[ $imgstats['mime'] ]; |
|
1748 $new_filename = implode( '.', $filename_parts ); |
|
1749 |
|
1750 if ( $new_filename != $filename ) |
|
1751 $proper_filename = $new_filename; // Mark that it changed |
|
1752 |
|
1753 // Redefine the extension / MIME |
|
1754 $wp_filetype = wp_check_filetype( $new_filename, $mimes ); |
|
1755 extract( $wp_filetype ); |
|
1756 } |
|
1757 } |
|
1758 } |
|
1759 |
|
1760 // Let plugins try and validate other types of files |
|
1761 // Should return an array in the style of array( 'ext' => $ext, 'type' => $type, 'proper_filename' => $proper_filename ) |
|
1762 return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes ); |
|
2266 } |
1763 } |
2267 |
1764 |
2268 /** |
1765 /** |
2269 * Retrieve list of allowed mime types and file extensions. |
1766 * Retrieve list of allowed mime types and file extensions. |
2270 * |
1767 * |
2288 'avi' => 'video/avi', |
1785 'avi' => 'video/avi', |
2289 'divx' => 'video/divx', |
1786 'divx' => 'video/divx', |
2290 'flv' => 'video/x-flv', |
1787 'flv' => 'video/x-flv', |
2291 'mov|qt' => 'video/quicktime', |
1788 'mov|qt' => 'video/quicktime', |
2292 'mpeg|mpg|mpe' => 'video/mpeg', |
1789 'mpeg|mpg|mpe' => 'video/mpeg', |
2293 'txt|c|cc|h' => 'text/plain', |
1790 'txt|asc|c|cc|h' => 'text/plain', |
1791 'csv' => 'text/csv', |
|
1792 'tsv' => 'text/tab-separated-values', |
|
1793 'ics' => 'text/calendar', |
|
2294 'rtx' => 'text/richtext', |
1794 'rtx' => 'text/richtext', |
2295 'css' => 'text/css', |
1795 'css' => 'text/css', |
2296 'htm|html' => 'text/html', |
1796 'htm|html' => 'text/html', |
2297 'mp3|m4a' => 'audio/mpeg', |
1797 'mp3|m4a|m4b' => 'audio/mpeg', |
2298 'mp4|m4v' => 'video/mp4', |
1798 'mp4|m4v' => 'video/mp4', |
2299 'ra|ram' => 'audio/x-realaudio', |
1799 'ra|ram' => 'audio/x-realaudio', |
2300 'wav' => 'audio/wav', |
1800 'wav' => 'audio/wav', |
2301 'ogg' => 'audio/ogg', |
1801 'ogg|oga' => 'audio/ogg', |
1802 'ogv' => 'video/ogg', |
|
2302 'mid|midi' => 'audio/midi', |
1803 'mid|midi' => 'audio/midi', |
2303 'wma' => 'audio/wma', |
1804 'wma' => 'audio/wma', |
1805 'mka' => 'audio/x-matroska', |
|
1806 'mkv' => 'video/x-matroska', |
|
2304 'rtf' => 'application/rtf', |
1807 'rtf' => 'application/rtf', |
2305 'js' => 'application/javascript', |
1808 'js' => 'application/javascript', |
2306 'pdf' => 'application/pdf', |
1809 'pdf' => 'application/pdf', |
2307 'doc|docx' => 'application/msword', |
1810 'doc|docx' => 'application/msword', |
2308 'pot|pps|ppt|pptx' => 'application/vnd.ms-powerpoint', |
1811 'pot|pps|ppt|pptx|ppam|pptm|sldm|ppsm|potm' => 'application/vnd.ms-powerpoint', |
2309 'wri' => 'application/vnd.ms-write', |
1812 'wri' => 'application/vnd.ms-write', |
2310 'xla|xls|xlsx|xlt|xlw' => 'application/vnd.ms-excel', |
1813 'xla|xls|xlsx|xlt|xlw|xlam|xlsb|xlsm|xltm' => 'application/vnd.ms-excel', |
2311 'mdb' => 'application/vnd.ms-access', |
1814 'mdb' => 'application/vnd.ms-access', |
2312 'mpp' => 'application/vnd.ms-project', |
1815 'mpp' => 'application/vnd.ms-project', |
1816 'docm|dotm' => 'application/vnd.ms-word', |
|
1817 'pptx|sldx|ppsx|potx' => 'application/vnd.openxmlformats-officedocument.presentationml', |
|
1818 'xlsx|xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml', |
|
1819 'docx|dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml', |
|
1820 'onetoc|onetoc2|onetmp|onepkg' => 'application/onenote', |
|
2313 'swf' => 'application/x-shockwave-flash', |
1821 'swf' => 'application/x-shockwave-flash', |
2314 'class' => 'application/java', |
1822 'class' => 'application/java', |
2315 'tar' => 'application/x-tar', |
1823 'tar' => 'application/x-tar', |
2316 'zip' => 'application/zip', |
1824 'zip' => 'application/zip', |
2317 'gz|gzip' => 'application/x-gzip', |
1825 'gz|gzip' => 'application/x-gzip', |
1826 'rar' => 'application/rar', |
|
1827 '7z' => 'application/x-7z-compressed', |
|
2318 'exe' => 'application/x-msdownload', |
1828 'exe' => 'application/x-msdownload', |
2319 // openoffice formats |
1829 // openoffice formats |
2320 'odt' => 'application/vnd.oasis.opendocument.text', |
1830 'odt' => 'application/vnd.oasis.opendocument.text', |
2321 'odp' => 'application/vnd.oasis.opendocument.presentation', |
1831 'odp' => 'application/vnd.oasis.opendocument.presentation', |
2322 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
1832 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
2323 'odg' => 'application/vnd.oasis.opendocument.graphics', |
1833 'odg' => 'application/vnd.oasis.opendocument.graphics', |
2324 'odc' => 'application/vnd.oasis.opendocument.chart', |
1834 'odc' => 'application/vnd.oasis.opendocument.chart', |
2325 'odb' => 'application/vnd.oasis.opendocument.database', |
1835 'odb' => 'application/vnd.oasis.opendocument.database', |
2326 'odf' => 'application/vnd.oasis.opendocument.formula', |
1836 'odf' => 'application/vnd.oasis.opendocument.formula', |
1837 // wordperfect formats |
|
1838 'wp|wpd' => 'application/wordperfect', |
|
2327 ) ); |
1839 ) ); |
2328 } |
1840 } |
2329 |
1841 |
2330 return $mimes; |
1842 return $mimes; |
2331 } |
1843 } |
2332 |
1844 |
2333 /** |
1845 /** |
2334 * Retrieve nonce action "Are you sure" message. |
1846 * Retrieve nonce action "Are you sure" message. |
2335 * |
1847 * |
2336 * The action is split by verb and noun. The action format is as follows: |
1848 * Deprecated in 3.4.1 and 3.5.0. Backported to 3.3.3. |
2337 * verb-action_extra. The verb is before the first dash and has the format of |
1849 * |
2338 * letters and no spaces and numbers. The noun is after the dash and before the |
1850 * @since 2.0.4 |
2339 * underscore, if an underscore exists. The noun is also only letters. |
1851 * @deprecated 3.4.1 |
2340 * |
1852 * @deprecated Use wp_nonce_ays() |
2341 * The filter will be called for any action, which is not defined by WordPress. |
1853 * @see wp_nonce_ays() |
2342 * You may use the filter for your plugin to explain nonce actions to the user, |
1854 * |
2343 * when they get the "Are you sure?" message. The filter is in the format of |
1855 * @param string $action Nonce action. |
2344 * 'explain_nonce_$verb-$noun' with the $verb replaced by the found verb and the |
1856 * @return string Are you sure message. |
2345 * $noun replaced by the found noun. The two parameters that are given to the |
1857 */ |
2346 * hook are the localized "Are you sure you want to do this?" message with the |
1858 function wp_explain_nonce( $action ) { |
2347 * extra text (the text after the underscore). |
1859 _deprecated_function( __FUNCTION__, '3.4.1', 'wp_nonce_ays()' ); |
1860 return __( 'Are you sure you want to do this?' ); |
|
1861 } |
|
1862 |
|
1863 /** |
|
1864 * Display "Are You Sure" message to confirm the action being taken. |
|
1865 * |
|
1866 * If the action has the nonce explain message, then it will be displayed along |
|
1867 * with the "Are you sure?" message. |
|
2348 * |
1868 * |
2349 * @package WordPress |
1869 * @package WordPress |
2350 * @subpackage Security |
1870 * @subpackage Security |
2351 * @since 2.0.4 |
1871 * @since 2.0.4 |
2352 * |
1872 * |
2353 * @param string $action Nonce action. |
|
2354 * @return string Are you sure message. |
|
2355 */ |
|
2356 function wp_explain_nonce( $action ) { |
|
2357 if ( $action !== -1 && preg_match( '/([a-z]+)-([a-z]+)(_(.+))?/', $action, $matches ) ) { |
|
2358 $verb = $matches[1]; |
|
2359 $noun = $matches[2]; |
|
2360 |
|
2361 $trans = array(); |
|
2362 $trans['update']['attachment'] = array( __( 'Your attempt to edit this attachment: “%s” has failed.' ), 'get_the_title' ); |
|
2363 |
|
2364 $trans['add']['category'] = array( __( 'Your attempt to add this category has failed.' ), false ); |
|
2365 $trans['delete']['category'] = array( __( 'Your attempt to delete this category: “%s” has failed.' ), 'get_cat_name' ); |
|
2366 $trans['update']['category'] = array( __( 'Your attempt to edit this category: “%s” has failed.' ), 'get_cat_name' ); |
|
2367 |
|
2368 $trans['delete']['comment'] = array( __( 'Your attempt to delete this comment: “%s” has failed.' ), 'use_id' ); |
|
2369 $trans['unapprove']['comment'] = array( __( 'Your attempt to unapprove this comment: “%s” has failed.' ), 'use_id' ); |
|
2370 $trans['approve']['comment'] = array( __( 'Your attempt to approve this comment: “%s” has failed.' ), 'use_id' ); |
|
2371 $trans['update']['comment'] = array( __( 'Your attempt to edit this comment: “%s” has failed.' ), 'use_id' ); |
|
2372 $trans['bulk']['comments'] = array( __( 'Your attempt to bulk modify comments has failed.' ), false ); |
|
2373 $trans['moderate']['comments'] = array( __( 'Your attempt to moderate comments has failed.' ), false ); |
|
2374 |
|
2375 $trans['add']['bookmark'] = array( __( 'Your attempt to add this link has failed.' ), false ); |
|
2376 $trans['delete']['bookmark'] = array( __( 'Your attempt to delete this link: “%s” has failed.' ), 'use_id' ); |
|
2377 $trans['update']['bookmark'] = array( __( 'Your attempt to edit this link: “%s” has failed.' ), 'use_id' ); |
|
2378 $trans['bulk']['bookmarks'] = array( __( 'Your attempt to bulk modify links has failed.' ), false ); |
|
2379 |
|
2380 $trans['add']['page'] = array( __( 'Your attempt to add this page has failed.' ), false ); |
|
2381 $trans['delete']['page'] = array( __( 'Your attempt to delete this page: “%s” has failed.' ), 'get_the_title' ); |
|
2382 $trans['update']['page'] = array( __( 'Your attempt to edit this page: “%s” has failed.' ), 'get_the_title' ); |
|
2383 |
|
2384 $trans['edit']['plugin'] = array( __( 'Your attempt to edit this plugin file: “%s” has failed.' ), 'use_id' ); |
|
2385 $trans['activate']['plugin'] = array( __( 'Your attempt to activate this plugin: “%s” has failed.' ), 'use_id' ); |
|
2386 $trans['deactivate']['plugin'] = array( __( 'Your attempt to deactivate this plugin: “%s” has failed.' ), 'use_id' ); |
|
2387 $trans['upgrade']['plugin'] = array( __( 'Your attempt to upgrade this plugin: “%s” has failed.' ), 'use_id' ); |
|
2388 |
|
2389 $trans['add']['post'] = array( __( 'Your attempt to add this post has failed.' ), false ); |
|
2390 $trans['delete']['post'] = array( __( 'Your attempt to delete this post: “%s” has failed.' ), 'get_the_title' ); |
|
2391 $trans['update']['post'] = array( __( 'Your attempt to edit this post: “%s” has failed.' ), 'get_the_title' ); |
|
2392 |
|
2393 $trans['add']['user'] = array( __( 'Your attempt to add this user has failed.' ), false ); |
|
2394 $trans['delete']['users'] = array( __( 'Your attempt to delete users has failed.' ), false ); |
|
2395 $trans['bulk']['users'] = array( __( 'Your attempt to bulk modify users has failed.' ), false ); |
|
2396 $trans['update']['user'] = array( __( 'Your attempt to edit this user: “%s” has failed.' ), 'get_the_author_meta', 'display_name' ); |
|
2397 $trans['update']['profile'] = array( __( 'Your attempt to modify the profile for: “%s” has failed.' ), 'get_the_author_meta', 'display_name' ); |
|
2398 |
|
2399 $trans['update']['options'] = array( __( 'Your attempt to edit your settings has failed.' ), false ); |
|
2400 $trans['update']['permalink'] = array( __( 'Your attempt to change your permalink structure to: %s has failed.' ), 'use_id' ); |
|
2401 $trans['edit']['file'] = array( __( 'Your attempt to edit this file: “%s” has failed.' ), 'use_id' ); |
|
2402 $trans['edit']['theme'] = array( __( 'Your attempt to edit this theme file: “%s” has failed.' ), 'use_id' ); |
|
2403 $trans['switch']['theme'] = array( __( 'Your attempt to switch to this theme: “%s” has failed.' ), 'use_id' ); |
|
2404 |
|
2405 $trans['log']['out'] = array( sprintf( __( 'You are attempting to log out of %s' ), get_bloginfo( 'sitename' ) ), false ); |
|
2406 |
|
2407 if ( isset( $trans[$verb][$noun] ) ) { |
|
2408 if ( !empty( $trans[$verb][$noun][1] ) ) { |
|
2409 $lookup = $trans[$verb][$noun][1]; |
|
2410 if ( isset($trans[$verb][$noun][2]) ) |
|
2411 $lookup_value = $trans[$verb][$noun][2]; |
|
2412 $object = $matches[4]; |
|
2413 if ( 'use_id' != $lookup ) { |
|
2414 if ( isset( $lookup_value ) ) |
|
2415 $object = call_user_func( $lookup, $lookup_value, $object ); |
|
2416 else |
|
2417 $object = call_user_func( $lookup, $object ); |
|
2418 } |
|
2419 return sprintf( $trans[$verb][$noun][0], esc_html($object) ); |
|
2420 } else { |
|
2421 return $trans[$verb][$noun][0]; |
|
2422 } |
|
2423 } |
|
2424 |
|
2425 return apply_filters( 'explain_nonce_' . $verb . '-' . $noun, __( 'Are you sure you want to do this?' ), isset($matches[4]) ? $matches[4] : '' ); |
|
2426 } else { |
|
2427 return apply_filters( 'explain_nonce_' . $action, __( 'Are you sure you want to do this?' ) ); |
|
2428 } |
|
2429 } |
|
2430 |
|
2431 /** |
|
2432 * Display "Are You Sure" message to confirm the action being taken. |
|
2433 * |
|
2434 * If the action has the nonce explain message, then it will be displayed along |
|
2435 * with the "Are you sure?" message. |
|
2436 * |
|
2437 * @package WordPress |
|
2438 * @subpackage Security |
|
2439 * @since 2.0.4 |
|
2440 * |
|
2441 * @param string $action The nonce action. |
1873 * @param string $action The nonce action. |
2442 */ |
1874 */ |
2443 function wp_nonce_ays( $action ) { |
1875 function wp_nonce_ays( $action ) { |
2444 $title = __( 'WordPress Failure Notice' ); |
1876 $title = __( 'WordPress Failure Notice' ); |
2445 $html = esc_html( wp_explain_nonce( $action ) ); |
1877 if ( 'log-out' == $action ) { |
2446 if ( 'log-out' == $action ) |
1878 $html = sprintf( __( 'You are attempting to log out of %s' ), get_bloginfo( 'name' ) ) . '</p><p>'; |
2447 $html .= "</p><p>" . sprintf( __( "Do you really want to <a href='%s'>log out</a>?"), wp_logout_url() ); |
1879 $html .= sprintf( __( "Do you really want to <a href='%s'>log out</a>?"), wp_logout_url() ); |
2448 elseif ( wp_get_referer() ) |
1880 } else { |
2449 $html .= "</p><p><a href='" . esc_url( remove_query_arg( 'updated', wp_get_referer() ) ) . "'>" . __( 'Please try again.' ) . "</a>"; |
1881 $html = __( 'Are you sure you want to do this?' ); |
1882 if ( wp_get_referer() ) |
|
1883 $html .= "</p><p><a href='" . esc_url( remove_query_arg( 'updated', wp_get_referer() ) ) . "'>" . __( 'Please try again.' ) . "</a>"; |
|
1884 } |
|
2450 |
1885 |
2451 wp_die( $html, $title, array('response' => 403) ); |
1886 wp_die( $html, $title, array('response' => 403) ); |
2452 } |
1887 } |
2453 |
1888 |
2454 /** |
1889 /** |
2455 * Kill WordPress execution and display HTML message with error message. |
1890 * Kill WordPress execution and display HTML message with error message. |
2456 * |
1891 * |
2457 * Call this function complements the die() PHP function. The difference is that |
1892 * This function complements the die() PHP function. The difference is that |
2458 * HTML will be displayed to the user. It is recommended to use this function |
1893 * HTML will be displayed to the user. It is recommended to use this function |
2459 * only, when the execution should not continue any further. It is not |
1894 * only, when the execution should not continue any further. It is not |
2460 * recommended to call this function very often and try to handle as many errors |
1895 * recommended to call this function very often and try to handle as many errors |
2461 * as possible siliently. |
1896 * as possible silently. |
2462 * |
1897 * |
2463 * @since 2.0.4 |
1898 * @since 2.0.4 |
2464 * |
1899 * |
2465 * @param string $message Error message. |
1900 * @param string $message Error message. |
2466 * @param string $title Error title. |
1901 * @param string $title Error title. |
2467 * @param string|array $args Optional arguements to control behaviour. |
1902 * @param string|array $args Optional arguments to control behavior. |
2468 */ |
1903 */ |
2469 function wp_die( $message, $title = '', $args = array() ) { |
1904 function wp_die( $message = '', $title = '', $args = array() ) { |
2470 global $wp_locale; |
1905 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
2471 |
1906 $function = apply_filters( 'wp_die_ajax_handler', '_ajax_wp_die_handler' ); |
1907 elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) |
|
1908 $function = apply_filters( 'wp_die_xmlrpc_handler', '_xmlrpc_wp_die_handler' ); |
|
1909 elseif ( defined( 'APP_REQUEST' ) && APP_REQUEST ) |
|
1910 $function = apply_filters( 'wp_die_app_handler', '_scalar_wp_die_handler' ); |
|
1911 else |
|
1912 $function = apply_filters( 'wp_die_handler', '_default_wp_die_handler' ); |
|
1913 |
|
1914 call_user_func( $function, $message, $title, $args ); |
|
1915 } |
|
1916 |
|
1917 /** |
|
1918 * Kill WordPress execution and display HTML message with error message. |
|
1919 * |
|
1920 * This is the default handler for wp_die if you want a custom one for your |
|
1921 * site then you can overload using the wp_die_handler filter in wp_die |
|
1922 * |
|
1923 * @since 3.0.0 |
|
1924 * @access private |
|
1925 * |
|
1926 * @param string $message Error message. |
|
1927 * @param string $title Error title. |
|
1928 * @param string|array $args Optional arguments to control behavior. |
|
1929 */ |
|
1930 function _default_wp_die_handler( $message, $title = '', $args = array() ) { |
|
2472 $defaults = array( 'response' => 500 ); |
1931 $defaults = array( 'response' => 500 ); |
2473 $r = wp_parse_args($args, $defaults); |
1932 $r = wp_parse_args($args, $defaults); |
2474 |
1933 |
2475 $have_gettext = function_exists('__'); |
1934 $have_gettext = function_exists('__'); |
2476 |
1935 |
2496 $message = "<p>$message</p>"; |
1955 $message = "<p>$message</p>"; |
2497 } |
1956 } |
2498 |
1957 |
2499 if ( isset( $r['back_link'] ) && $r['back_link'] ) { |
1958 if ( isset( $r['back_link'] ) && $r['back_link'] ) { |
2500 $back_text = $have_gettext? __('« Back') : '« Back'; |
1959 $back_text = $have_gettext? __('« Back') : '« Back'; |
2501 $message .= "\n<p><a href='javascript:history.back()'>$back_text</p>"; |
1960 $message .= "\n<p><a href='javascript:history.back()'>$back_text</a></p>"; |
2502 } |
1961 } |
2503 |
1962 |
2504 if ( defined( 'WP_SITEURL' ) && '' != WP_SITEURL ) |
1963 if ( ! did_action( 'admin_head' ) ) : |
2505 $admin_dir = WP_SITEURL . '/wp-admin/'; |
1964 if ( !headers_sent() ) { |
2506 elseif ( function_exists( 'get_bloginfo' ) && '' != get_bloginfo( 'wpurl' ) ) |
1965 status_header( $r['response'] ); |
2507 $admin_dir = get_bloginfo( 'wpurl' ) . '/wp-admin/'; |
1966 nocache_headers(); |
2508 elseif ( strpos( $_SERVER['PHP_SELF'], 'wp-admin' ) !== false ) |
1967 header( 'Content-Type: text/html; charset=utf-8' ); |
2509 $admin_dir = ''; |
1968 } |
2510 else |
1969 |
2511 $admin_dir = 'wp-admin/'; |
1970 if ( empty($title) ) |
2512 |
1971 $title = $have_gettext ? __('WordPress › Error') : 'WordPress › Error'; |
2513 if ( !function_exists( 'did_action' ) || !did_action( 'admin_head' ) ) : |
1972 |
2514 if( !headers_sent() ){ |
1973 $text_direction = 'ltr'; |
2515 status_header( $r['response'] ); |
1974 if ( isset($r['text_direction']) && 'rtl' == $r['text_direction'] ) |
2516 nocache_headers(); |
1975 $text_direction = 'rtl'; |
2517 header( 'Content-Type: text/html; charset=utf-8' ); |
1976 elseif ( function_exists( 'is_rtl' ) && is_rtl() ) |
2518 } |
1977 $text_direction = 'rtl'; |
2519 |
|
2520 if ( empty($title) ) { |
|
2521 $title = $have_gettext? __('WordPress › Error') : 'WordPress › Error'; |
|
2522 } |
|
2523 |
|
2524 $text_direction = 'ltr'; |
|
2525 if ( isset($r['text_direction']) && $r['text_direction'] == 'rtl' ) $text_direction = 'rtl'; |
|
2526 if ( ( $wp_locale ) && ( 'rtl' == $wp_locale->text_direction ) ) $text_direction = 'rtl'; |
|
2527 ?> |
1978 ?> |
2528 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
1979 <!DOCTYPE html> |
2529 <!-- Ticket #11289, IE bug fix: always pad the error page with enough characters such that it is greater than 512 bytes, even after gzip compression abcdefghijklmnopqrstuvwxyz1234567890aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz11223344556677889900abacbcbdcdcededfefegfgfhghgihihjijikjkjlklkmlmlnmnmononpopoqpqprqrqsrsrtstsubcbcdcdedefefgfabcadefbghicjkldmnoepqrfstugvwxhyz1i234j567k890laabmbccnddeoeffpgghqhiirjjksklltmmnunoovppqwqrrxsstytuuzvvw0wxx1yyz2z113223434455666777889890091abc2def3ghi4jkl5mno6pqr7stu8vwx9yz11aab2bcc3dd4ee5ff6gg7hh8ii9j0jk1kl2lmm3nnoo4p5pq6qrr7ss8tt9uuvv0wwx1x2yyzz13aba4cbcb5dcdc6dedfef8egf9gfh0ghg1ihi2hji3jik4jkj5lkl6kml7mln8mnm9ono --> |
1980 <!-- Ticket #11289, IE bug fix: always pad the error page with enough characters such that it is greater than 512 bytes, even after gzip compression abcdefghijklmnopqrstuvwxyz1234567890aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz11223344556677889900abacbcbdcdcededfefegfgfhghgihihjijikjkjlklkmlmlnmnmononpopoqpqprqrqsrsrtstsubcbcdcdedefefgfabcadefbghicjkldmnoepqrfstugvwxhyz1i234j567k890laabmbccnddeoeffpgghqhiirjjksklltmmnunoovppqwqrrxsstytuuzvvw0wxx1yyz2z113223434455666777889890091abc2def3ghi4jkl5mno6pqr7stu8vwx9yz11aab2bcc3dd4ee5ff6gg7hh8ii9j0jk1kl2lmm3nnoo4p5pq6qrr7ss8tt9uuvv0wwx1x2yyzz13aba4cbcb5dcdc6dedfef8egf9gfh0ghg1ihi2hji3jik4jkj5lkl6kml7mln8mnm9ono |
2530 <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) ) language_attributes(); ?>> |
1981 --> |
1982 <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) && function_exists( 'is_rtl' ) ) language_attributes(); else echo "dir='$text_direction'"; ?>> |
|
2531 <head> |
1983 <head> |
2532 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
1984 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
2533 <title><?php echo $title ?></title> |
1985 <title><?php echo $title ?></title> |
2534 <link rel="stylesheet" href="<?php echo $admin_dir; ?>css/install.css" type="text/css" /> |
1986 <style type="text/css"> |
2535 <?php |
1987 html { |
2536 if ( 'rtl' == $text_direction ) : ?> |
1988 background: #f9f9f9; |
2537 <link rel="stylesheet" href="<?php echo $admin_dir; ?>css/install-rtl.css" type="text/css" /> |
1989 } |
2538 <?php endif; ?> |
1990 body { |
1991 background: #fff; |
|
1992 color: #333; |
|
1993 font-family: sans-serif; |
|
1994 margin: 2em auto; |
|
1995 padding: 1em 2em; |
|
1996 -webkit-border-radius: 3px; |
|
1997 border-radius: 3px; |
|
1998 border: 1px solid #dfdfdf; |
|
1999 max-width: 700px; |
|
2000 } |
|
2001 h1 { |
|
2002 border-bottom: 1px solid #dadada; |
|
2003 clear: both; |
|
2004 color: #666; |
|
2005 font: 24px Georgia, "Times New Roman", Times, serif; |
|
2006 margin: 30px 0 0 0; |
|
2007 padding: 0; |
|
2008 padding-bottom: 7px; |
|
2009 } |
|
2010 #error-page { |
|
2011 margin-top: 50px; |
|
2012 } |
|
2013 #error-page p { |
|
2014 font-size: 14px; |
|
2015 line-height: 1.5; |
|
2016 margin: 25px 0 20px; |
|
2017 } |
|
2018 #error-page code { |
|
2019 font-family: Consolas, Monaco, monospace; |
|
2020 } |
|
2021 ul li { |
|
2022 margin-bottom: 10px; |
|
2023 font-size: 14px ; |
|
2024 } |
|
2025 a { |
|
2026 color: #21759B; |
|
2027 text-decoration: none; |
|
2028 } |
|
2029 a:hover { |
|
2030 color: #D54E21; |
|
2031 } |
|
2032 |
|
2033 .button { |
|
2034 font-family: sans-serif; |
|
2035 text-decoration: none; |
|
2036 font-size: 14px !important; |
|
2037 line-height: 16px; |
|
2038 padding: 6px 12px; |
|
2039 cursor: pointer; |
|
2040 border: 1px solid #bbb; |
|
2041 color: #464646; |
|
2042 -webkit-border-radius: 15px; |
|
2043 border-radius: 15px; |
|
2044 -moz-box-sizing: content-box; |
|
2045 -webkit-box-sizing: content-box; |
|
2046 box-sizing: content-box; |
|
2047 background-color: #f5f5f5; |
|
2048 background-image: -ms-linear-gradient(top, #ffffff, #f2f2f2); |
|
2049 background-image: -moz-linear-gradient(top, #ffffff, #f2f2f2); |
|
2050 background-image: -o-linear-gradient(top, #ffffff, #f2f2f2); |
|
2051 background-image: -webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#f2f2f2)); |
|
2052 background-image: -webkit-linear-gradient(top, #ffffff, #f2f2f2); |
|
2053 background-image: linear-gradient(top, #ffffff, #f2f2f2); |
|
2054 } |
|
2055 |
|
2056 .button:hover { |
|
2057 color: #000; |
|
2058 border-color: #666; |
|
2059 } |
|
2060 |
|
2061 .button:active { |
|
2062 background-image: -ms-linear-gradient(top, #f2f2f2, #ffffff); |
|
2063 background-image: -moz-linear-gradient(top, #f2f2f2, #ffffff); |
|
2064 background-image: -o-linear-gradient(top, #f2f2f2, #ffffff); |
|
2065 background-image: -webkit-gradient(linear, left top, left bottom, from(#f2f2f2), to(#ffffff)); |
|
2066 background-image: -webkit-linear-gradient(top, #f2f2f2, #ffffff); |
|
2067 background-image: linear-gradient(top, #f2f2f2, #ffffff); |
|
2068 } |
|
2069 |
|
2070 <?php if ( 'rtl' == $text_direction ) : ?> |
|
2071 body { font-family: Tahoma, Arial; } |
|
2072 <?php endif; ?> |
|
2073 </style> |
|
2539 </head> |
2074 </head> |
2540 <body id="error-page"> |
2075 <body id="error-page"> |
2541 <?php endif; ?> |
2076 <?php endif; // ! did_action( 'admin_head' ) ?> |
2542 <?php echo $message; ?> |
2077 <?php echo $message; ?> |
2543 </body> |
2078 </body> |
2544 </html> |
2079 </html> |
2545 <?php |
2080 <?php |
2546 die(); |
2081 die(); |
2547 } |
2082 } |
2548 |
2083 |
2549 /** |
2084 /** |
2085 * Kill WordPress execution and display XML message with error message. |
|
2086 * |
|
2087 * This is the handler for wp_die when processing XMLRPC requests. |
|
2088 * |
|
2089 * @since 3.2.0 |
|
2090 * @access private |
|
2091 * |
|
2092 * @param string $message Error message. |
|
2093 * @param string $title Error title. |
|
2094 * @param string|array $args Optional arguments to control behavior. |
|
2095 */ |
|
2096 function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) { |
|
2097 global $wp_xmlrpc_server; |
|
2098 $defaults = array( 'response' => 500 ); |
|
2099 |
|
2100 $r = wp_parse_args($args, $defaults); |
|
2101 |
|
2102 if ( $wp_xmlrpc_server ) { |
|
2103 $error = new IXR_Error( $r['response'] , $message); |
|
2104 $wp_xmlrpc_server->output( $error->getXml() ); |
|
2105 } |
|
2106 die(); |
|
2107 } |
|
2108 |
|
2109 /** |
|
2110 * Kill WordPress ajax execution. |
|
2111 * |
|
2112 * This is the handler for wp_die when processing Ajax requests. |
|
2113 * |
|
2114 * @since 3.4.0 |
|
2115 * @access private |
|
2116 * |
|
2117 * @param string $message Optional. Response to print. |
|
2118 */ |
|
2119 function _ajax_wp_die_handler( $message = '' ) { |
|
2120 if ( is_scalar( $message ) ) |
|
2121 die( (string) $message ); |
|
2122 die( '0' ); |
|
2123 } |
|
2124 |
|
2125 /** |
|
2126 * Kill WordPress execution. |
|
2127 * |
|
2128 * This is the handler for wp_die when processing APP requests. |
|
2129 * |
|
2130 * @since 3.4.0 |
|
2131 * @access private |
|
2132 * |
|
2133 * @param string $message Optional. Response to print. |
|
2134 */ |
|
2135 function _scalar_wp_die_handler( $message = '' ) { |
|
2136 if ( is_scalar( $message ) ) |
|
2137 die( (string) $message ); |
|
2138 die(); |
|
2139 } |
|
2140 |
|
2141 /** |
|
2550 * Retrieve the WordPress home page URL. |
2142 * Retrieve the WordPress home page URL. |
2551 * |
2143 * |
2552 * If the constant named 'WP_HOME' exists, then it willl be used and returned by |
2144 * If the constant named 'WP_HOME' exists, then it will be used and returned by |
2553 * the function. This can be used to counter the redirection on your local |
2145 * the function. This can be used to counter the redirection on your local |
2554 * development environment. |
2146 * development environment. |
2555 * |
2147 * |
2556 * @access private |
2148 * @access private |
2557 * @package WordPress |
2149 * @package WordPress |
2560 * @param string $url URL for the home location |
2152 * @param string $url URL for the home location |
2561 * @return string Homepage location. |
2153 * @return string Homepage location. |
2562 */ |
2154 */ |
2563 function _config_wp_home( $url = '' ) { |
2155 function _config_wp_home( $url = '' ) { |
2564 if ( defined( 'WP_HOME' ) ) |
2156 if ( defined( 'WP_HOME' ) ) |
2565 return WP_HOME; |
2157 return untrailingslashit( WP_HOME ); |
2566 return $url; |
2158 return $url; |
2567 } |
2159 } |
2568 |
2160 |
2569 /** |
2161 /** |
2570 * Retrieve the WordPress site URL. |
2162 * Retrieve the WordPress site URL. |
2580 * @param string $url URL to set the WordPress site location. |
2172 * @param string $url URL to set the WordPress site location. |
2581 * @return string The WordPress Site URL |
2173 * @return string The WordPress Site URL |
2582 */ |
2174 */ |
2583 function _config_wp_siteurl( $url = '' ) { |
2175 function _config_wp_siteurl( $url = '' ) { |
2584 if ( defined( 'WP_SITEURL' ) ) |
2176 if ( defined( 'WP_SITEURL' ) ) |
2585 return WP_SITEURL; |
2177 return untrailingslashit( WP_SITEURL ); |
2586 return $url; |
2178 return $url; |
2587 } |
2179 } |
2588 |
2180 |
2589 /** |
2181 /** |
2590 * Set the localized direction for MCE plugin. |
2182 * Set the localized direction for MCE plugin. |
2602 * |
2194 * |
2603 * @param array $input MCE plugin array. |
2195 * @param array $input MCE plugin array. |
2604 * @return array Direction set for 'rtl', if needed by locale. |
2196 * @return array Direction set for 'rtl', if needed by locale. |
2605 */ |
2197 */ |
2606 function _mce_set_direction( $input ) { |
2198 function _mce_set_direction( $input ) { |
2607 global $wp_locale; |
2199 if ( is_rtl() ) { |
2608 |
|
2609 if ( 'rtl' == $wp_locale->text_direction ) { |
|
2610 $input['directionality'] = 'rtl'; |
2200 $input['directionality'] = 'rtl'; |
2611 $input['plugins'] .= ',directionality'; |
2201 $input['plugins'] .= ',directionality'; |
2612 $input['theme_advanced_buttons1'] .= ',ltr'; |
2202 $input['theme_advanced_buttons1'] .= ',ltr'; |
2613 } |
2203 } |
2614 |
2204 |
2615 return $input; |
2205 return $input; |
2616 } |
2206 } |
2617 |
|
2618 |
2207 |
2619 /** |
2208 /** |
2620 * Convert smiley code to the icon graphic file equivalent. |
2209 * Convert smiley code to the icon graphic file equivalent. |
2621 * |
2210 * |
2622 * You can turn off smilies, by going to the write setting screen and unchecking |
2211 * You can turn off smilies, by going to the write setting screen and unchecking |
2675 ':-P' => 'icon_razz.gif', |
2264 ':-P' => 'icon_razz.gif', |
2676 ':-o' => 'icon_surprised.gif', |
2265 ':-o' => 'icon_surprised.gif', |
2677 ':-x' => 'icon_mad.gif', |
2266 ':-x' => 'icon_mad.gif', |
2678 ':-|' => 'icon_neutral.gif', |
2267 ':-|' => 'icon_neutral.gif', |
2679 ';-)' => 'icon_wink.gif', |
2268 ';-)' => 'icon_wink.gif', |
2680 '8)' => 'icon_cool.gif', |
2269 // This one transformation breaks regular text with frequency. |
2270 // '8)' => 'icon_cool.gif', |
|
2681 '8O' => 'icon_eek.gif', |
2271 '8O' => 'icon_eek.gif', |
2682 ':(' => 'icon_sad.gif', |
2272 ':(' => 'icon_sad.gif', |
2683 ':)' => 'icon_smile.gif', |
2273 ':)' => 'icon_smile.gif', |
2684 ':?' => 'icon_confused.gif', |
2274 ':?' => 'icon_confused.gif', |
2685 ':D' => 'icon_biggrin.gif', |
2275 ':D' => 'icon_biggrin.gif', |
2751 return array_merge( $defaults, $r ); |
2341 return array_merge( $defaults, $r ); |
2752 return $r; |
2342 return $r; |
2753 } |
2343 } |
2754 |
2344 |
2755 /** |
2345 /** |
2756 * Determines if default embed handlers should be loaded. |
2346 * Clean up an array, comma- or space-separated list of IDs. |
2757 * |
2347 * |
2758 * Checks to make sure that the embeds library hasn't already been loaded. If |
2348 * @since 3.0.0 |
2759 * it hasn't, then it will load the embeds library. |
2349 * |
2760 * |
2350 * @param array|string $list |
2761 * @since 2.9 |
2351 * @return array Sanitized array of IDs |
2762 */ |
2352 */ |
2763 function wp_maybe_load_embeds() { |
2353 function wp_parse_id_list( $list ) { |
2764 if ( ! apply_filters('load_default_embeds', true) ) |
2354 if ( !is_array($list) ) |
2765 return; |
2355 $list = preg_split('/[\s,]+/', $list); |
2766 require_once( ABSPATH . WPINC . '/default-embeds.php' ); |
2356 |
2357 return array_unique(array_map('absint', $list)); |
|
2358 } |
|
2359 |
|
2360 /** |
|
2361 * Extract a slice of an array, given a list of keys. |
|
2362 * |
|
2363 * @since 3.1.0 |
|
2364 * |
|
2365 * @param array $array The original array |
|
2366 * @param array $keys The list of keys |
|
2367 * @return array The array slice |
|
2368 */ |
|
2369 function wp_array_slice_assoc( $array, $keys ) { |
|
2370 $slice = array(); |
|
2371 foreach ( $keys as $key ) |
|
2372 if ( isset( $array[ $key ] ) ) |
|
2373 $slice[ $key ] = $array[ $key ]; |
|
2374 |
|
2375 return $slice; |
|
2376 } |
|
2377 |
|
2378 /** |
|
2379 * Filters a list of objects, based on a set of key => value arguments. |
|
2380 * |
|
2381 * @since 3.0.0 |
|
2382 * |
|
2383 * @param array $list An array of objects to filter |
|
2384 * @param array $args An array of key => value arguments to match against each object |
|
2385 * @param string $operator The logical operation to perform. 'or' means only one element |
|
2386 * from the array needs to match; 'and' means all elements must match. The default is 'and'. |
|
2387 * @param bool|string $field A field from the object to place instead of the entire object |
|
2388 * @return array A list of objects or object fields |
|
2389 */ |
|
2390 function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) { |
|
2391 if ( ! is_array( $list ) ) |
|
2392 return array(); |
|
2393 |
|
2394 $list = wp_list_filter( $list, $args, $operator ); |
|
2395 |
|
2396 if ( $field ) |
|
2397 $list = wp_list_pluck( $list, $field ); |
|
2398 |
|
2399 return $list; |
|
2400 } |
|
2401 |
|
2402 /** |
|
2403 * Filters a list of objects, based on a set of key => value arguments. |
|
2404 * |
|
2405 * @since 3.1.0 |
|
2406 * |
|
2407 * @param array $list An array of objects to filter |
|
2408 * @param array $args An array of key => value arguments to match against each object |
|
2409 * @param string $operator The logical operation to perform: |
|
2410 * 'AND' means all elements from the array must match; |
|
2411 * 'OR' means only one element needs to match; |
|
2412 * 'NOT' means no elements may match. |
|
2413 * The default is 'AND'. |
|
2414 * @return array |
|
2415 */ |
|
2416 function wp_list_filter( $list, $args = array(), $operator = 'AND' ) { |
|
2417 if ( ! is_array( $list ) ) |
|
2418 return array(); |
|
2419 |
|
2420 if ( empty( $args ) ) |
|
2421 return $list; |
|
2422 |
|
2423 $operator = strtoupper( $operator ); |
|
2424 $count = count( $args ); |
|
2425 $filtered = array(); |
|
2426 |
|
2427 foreach ( $list as $key => $obj ) { |
|
2428 $to_match = (array) $obj; |
|
2429 |
|
2430 $matched = 0; |
|
2431 foreach ( $args as $m_key => $m_value ) { |
|
2432 if ( $m_value == $to_match[ $m_key ] ) |
|
2433 $matched++; |
|
2434 } |
|
2435 |
|
2436 if ( ( 'AND' == $operator && $matched == $count ) |
|
2437 || ( 'OR' == $operator && $matched > 0 ) |
|
2438 || ( 'NOT' == $operator && 0 == $matched ) ) { |
|
2439 $filtered[$key] = $obj; |
|
2440 } |
|
2441 } |
|
2442 |
|
2443 return $filtered; |
|
2444 } |
|
2445 |
|
2446 /** |
|
2447 * Pluck a certain field out of each object in a list. |
|
2448 * |
|
2449 * @since 3.1.0 |
|
2450 * |
|
2451 * @param array $list A list of objects or arrays |
|
2452 * @param int|string $field A field from the object to place instead of the entire object |
|
2453 * @return array |
|
2454 */ |
|
2455 function wp_list_pluck( $list, $field ) { |
|
2456 foreach ( $list as $key => $value ) { |
|
2457 if ( is_object( $value ) ) |
|
2458 $list[ $key ] = $value->$field; |
|
2459 else |
|
2460 $list[ $key ] = $value[ $field ]; |
|
2461 } |
|
2462 |
|
2463 return $list; |
|
2767 } |
2464 } |
2768 |
2465 |
2769 /** |
2466 /** |
2770 * Determines if Widgets library should be loaded. |
2467 * Determines if Widgets library should be loaded. |
2771 * |
2468 * |
2788 * @since 2.2.0 |
2485 * @since 2.2.0 |
2789 * @uses $submenu The administration submenu list. |
2486 * @uses $submenu The administration submenu list. |
2790 */ |
2487 */ |
2791 function wp_widgets_add_menu() { |
2488 function wp_widgets_add_menu() { |
2792 global $submenu; |
2489 global $submenu; |
2793 $submenu['themes.php'][7] = array( __( 'Widgets' ), 'switch_themes', 'widgets.php' ); |
2490 $submenu['themes.php'][7] = array( __( 'Widgets' ), 'edit_theme_options', 'widgets.php' ); |
2794 ksort( $submenu['themes.php'], SORT_NUMERIC ); |
2491 ksort( $submenu['themes.php'], SORT_NUMERIC ); |
2795 } |
2492 } |
2796 |
2493 |
2797 /** |
2494 /** |
2798 * Flush all output buffers for PHP 5.2. |
2495 * Flush all output buffers for PHP 5.2. |
2806 for ($i=0; $i<$levels; $i++) |
2503 for ($i=0; $i<$levels; $i++) |
2807 ob_end_flush(); |
2504 ob_end_flush(); |
2808 } |
2505 } |
2809 |
2506 |
2810 /** |
2507 /** |
2811 * Load the correct database class file. |
|
2812 * |
|
2813 * This function is used to load the database class file either at runtime or by |
|
2814 * wp-admin/setup-config.php We must globalise $wpdb to ensure that it is |
|
2815 * defined globally by the inline code in wp-db.php. |
|
2816 * |
|
2817 * @since 2.5.0 |
|
2818 * @global $wpdb WordPress Database Object |
|
2819 */ |
|
2820 function require_wp_db() { |
|
2821 global $wpdb; |
|
2822 if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) |
|
2823 require_once( WP_CONTENT_DIR . '/db.php' ); |
|
2824 else |
|
2825 require_once( ABSPATH . WPINC . '/wp-db.php' ); |
|
2826 } |
|
2827 |
|
2828 /** |
|
2829 * Load custom DB error or display WordPress DB error. |
2508 * Load custom DB error or display WordPress DB error. |
2830 * |
2509 * |
2831 * If a file exists in the wp-content directory named db-error.php, then it will |
2510 * If a file exists in the wp-content directory named db-error.php, then it will |
2832 * be loaded instead of displaying the WordPress DB error. If it is not found, |
2511 * be loaded instead of displaying the WordPress DB error. If it is not found, |
2833 * then the WordPress DB error will be displayed instead. |
2512 * then the WordPress DB error will be displayed instead. |
2857 |
2536 |
2858 // Otherwise, be terse. |
2537 // Otherwise, be terse. |
2859 status_header( 500 ); |
2538 status_header( 500 ); |
2860 nocache_headers(); |
2539 nocache_headers(); |
2861 header( 'Content-Type: text/html; charset=utf-8' ); |
2540 header( 'Content-Type: text/html; charset=utf-8' ); |
2541 |
|
2542 wp_load_translations_early(); |
|
2862 ?> |
2543 ?> |
2863 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
2544 <!DOCTYPE html> |
2864 <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) ) language_attributes(); ?>> |
2545 <html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>> |
2865 <head> |
2546 <head> |
2866 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
2547 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
2867 <title>Database Error</title> |
2548 <title><?php _e( 'Database Error' ); ?></title> |
2868 |
2549 |
2869 </head> |
2550 </head> |
2870 <body> |
2551 <body> |
2871 <h1>Error establishing a database connection</h1> |
2552 <h1><?php _e( 'Error establishing a database connection' ); ?></h1> |
2872 </body> |
2553 </body> |
2873 </html> |
2554 </html> |
2874 <?php |
2555 <?php |
2875 die(); |
2556 die(); |
2876 } |
2557 } |
2878 /** |
2559 /** |
2879 * Converts value to nonnegative integer. |
2560 * Converts value to nonnegative integer. |
2880 * |
2561 * |
2881 * @since 2.5.0 |
2562 * @since 2.5.0 |
2882 * |
2563 * |
2883 * @param mixed $maybeint Data you wish to have convered to an nonnegative integer |
2564 * @param mixed $maybeint Data you wish to have converted to a nonnegative integer |
2884 * @return int An nonnegative integer |
2565 * @return int An nonnegative integer |
2885 */ |
2566 */ |
2886 function absint( $maybeint ) { |
2567 function absint( $maybeint ) { |
2887 return abs( intval( $maybeint ) ); |
2568 return abs( intval( $maybeint ) ); |
2888 } |
2569 } |
2893 * Determines if blog can be accessed over SSL by using cURL to access the site |
2574 * Determines if blog can be accessed over SSL by using cURL to access the site |
2894 * using the https in the siteurl. Requires cURL extension to work correctly. |
2575 * using the https in the siteurl. Requires cURL extension to work correctly. |
2895 * |
2576 * |
2896 * @since 2.5.0 |
2577 * @since 2.5.0 |
2897 * |
2578 * |
2898 * @return bool Whether or not SSL access is available |
2579 * @param string $url |
2580 * @return bool Whether SSL access is available |
|
2899 */ |
2581 */ |
2900 function url_is_accessable_via_ssl($url) |
2582 function url_is_accessable_via_ssl($url) |
2901 { |
2583 { |
2902 if (in_array('curl', get_loaded_extensions())) { |
2584 if (in_array('curl', get_loaded_extensions())) { |
2903 $ssl = preg_replace( '/^http:\/\//', 'https://', $url ); |
2585 $ssl = preg_replace( '/^http:\/\//', 'https://', $url ); |
2920 } |
2602 } |
2921 return false; |
2603 return false; |
2922 } |
2604 } |
2923 |
2605 |
2924 /** |
2606 /** |
2925 * Secure URL, if available or the given URL. |
|
2926 * |
|
2927 * @since 2.5.0 |
|
2928 * |
|
2929 * @param string $url Complete URL path with transport. |
|
2930 * @return string Secure or regular URL path. |
|
2931 */ |
|
2932 function atom_service_url_filter($url) |
|
2933 { |
|
2934 if ( url_is_accessable_via_ssl($url) ) |
|
2935 return preg_replace( '/^http:\/\//', 'https://', $url ); |
|
2936 else |
|
2937 return $url; |
|
2938 } |
|
2939 |
|
2940 /** |
|
2941 * Marks a function as deprecated and informs when it has been used. |
2607 * Marks a function as deprecated and informs when it has been used. |
2942 * |
2608 * |
2943 * There is a hook deprecated_function_run that will be called that can be used |
2609 * There is a hook deprecated_function_run that will be called that can be used |
2944 * to get the backtrace up to what file and function called the deprecated |
2610 * to get the backtrace up to what file and function called the deprecated |
2945 * function. |
2611 * function. |
2946 * |
2612 * |
2947 * The current behavior is to trigger an user error if WP_DEBUG is true. |
2613 * The current behavior is to trigger a user error if WP_DEBUG is true. |
2948 * |
2614 * |
2949 * This function is to be used in every function in depreceated.php |
2615 * This function is to be used in every function that is deprecated. |
2950 * |
2616 * |
2951 * @package WordPress |
2617 * @package WordPress |
2952 * @package Debug |
2618 * @subpackage Debug |
2953 * @since 2.5.0 |
2619 * @since 2.5.0 |
2954 * @access private |
2620 * @access private |
2955 * |
2621 * |
2956 * @uses do_action() Calls 'deprecated_function_run' and passes the function name and what to use instead. |
2622 * @uses do_action() Calls 'deprecated_function_run' and passes the function name, what to use instead, |
2957 * @uses apply_filters() Calls 'deprecated_function_trigger_error' and expects boolean value of true to do trigger or false to not trigger error. |
2623 * and the version the function was deprecated in. |
2624 * @uses apply_filters() Calls 'deprecated_function_trigger_error' and expects boolean value of true to do |
|
2625 * trigger or false to not trigger error. |
|
2958 * |
2626 * |
2959 * @param string $function The function that was called |
2627 * @param string $function The function that was called |
2960 * @param string $version The version of WordPress that deprecated the function |
2628 * @param string $version The version of WordPress that deprecated the function |
2961 * @param string $replacement Optional. The function that should have been called |
2629 * @param string $replacement Optional. The function that should have been called |
2962 */ |
2630 */ |
2963 function _deprecated_function($function, $version, $replacement=null) { |
2631 function _deprecated_function( $function, $version, $replacement = null ) { |
2964 |
2632 |
2965 do_action('deprecated_function_run', $function, $replacement); |
2633 do_action( 'deprecated_function_run', $function, $replacement, $version ); |
2966 |
2634 |
2967 // Allow plugin to filter the output error trigger |
2635 // Allow plugin to filter the output error trigger |
2968 if( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true )) { |
2636 if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) { |
2969 if( !is_null($replacement) ) |
2637 if ( ! is_null($replacement) ) |
2970 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) ); |
2638 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) ); |
2971 else |
2639 else |
2972 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) ); |
2640 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) ); |
2973 } |
2641 } |
2974 } |
2642 } |
2978 * |
2646 * |
2979 * There is a hook deprecated_file_included that will be called that can be used |
2647 * There is a hook deprecated_file_included that will be called that can be used |
2980 * to get the backtrace up to what file and function included the deprecated |
2648 * to get the backtrace up to what file and function included the deprecated |
2981 * file. |
2649 * file. |
2982 * |
2650 * |
2983 * The current behavior is to trigger an user error if WP_DEBUG is true. |
2651 * The current behavior is to trigger a user error if WP_DEBUG is true. |
2984 * |
2652 * |
2985 * This function is to be used in every file that is depreceated |
2653 * This function is to be used in every file that is deprecated. |
2986 * |
2654 * |
2987 * @package WordPress |
2655 * @package WordPress |
2988 * @package Debug |
2656 * @subpackage Debug |
2989 * @since 2.5.0 |
2657 * @since 2.5.0 |
2990 * @access private |
2658 * @access private |
2991 * |
2659 * |
2992 * @uses do_action() Calls 'deprecated_file_included' and passes the file name and what to use instead. |
2660 * @uses do_action() Calls 'deprecated_file_included' and passes the file name, what to use instead, |
2993 * @uses apply_filters() Calls 'deprecated_file_trigger_error' and expects boolean value of true to do trigger or false to not trigger error. |
2661 * the version in which the file was deprecated, and any message regarding the change. |
2662 * @uses apply_filters() Calls 'deprecated_file_trigger_error' and expects boolean value of true to do |
|
2663 * trigger or false to not trigger error. |
|
2994 * |
2664 * |
2995 * @param string $file The file that was included |
2665 * @param string $file The file that was included |
2996 * @param string $version The version of WordPress that deprecated the function |
2666 * @param string $version The version of WordPress that deprecated the file |
2997 * @param string $replacement Optional. The function that should have been called |
2667 * @param string $replacement Optional. The file that should have been included based on ABSPATH |
2998 */ |
2668 * @param string $message Optional. A message regarding the change |
2999 function _deprecated_file($file, $version, $replacement=null) { |
2669 */ |
3000 |
2670 function _deprecated_file( $file, $version, $replacement = null, $message = '' ) { |
3001 do_action('deprecated_file_included', $file, $replacement); |
2671 |
2672 do_action( 'deprecated_file_included', $file, $replacement, $version, $message ); |
|
3002 |
2673 |
3003 // Allow plugin to filter the output error trigger |
2674 // Allow plugin to filter the output error trigger |
3004 if( WP_DEBUG && apply_filters( 'deprecated_file_trigger_error', true ) ) { |
2675 if ( WP_DEBUG && apply_filters( 'deprecated_file_trigger_error', true ) ) { |
3005 if( !is_null($replacement) ) |
2676 $message = empty( $message ) ? '' : ' ' . $message; |
3006 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $file, $version, $replacement ) ); |
2677 if ( ! is_null( $replacement ) ) |
2678 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $file, $version, $replacement ) . $message ); |
|
3007 else |
2679 else |
3008 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $file, $version ) ); |
2680 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $file, $version ) . $message ); |
3009 } |
2681 } |
3010 } |
2682 } |
3011 |
2683 /** |
3012 /** |
2684 * Marks a function argument as deprecated and informs when it has been used. |
3013 * Is the server running earlier than 1.5.0 version of lighttpd |
2685 * |
2686 * This function is to be used whenever a deprecated function argument is used. |
|
2687 * Before this function is called, the argument must be checked for whether it was |
|
2688 * used by comparing it to its default value or evaluating whether it is empty. |
|
2689 * For example: |
|
2690 * <code> |
|
2691 * if ( !empty($deprecated) ) |
|
2692 * _deprecated_argument( __FUNCTION__, '3.0' ); |
|
2693 * </code> |
|
2694 * |
|
2695 * There is a hook deprecated_argument_run that will be called that can be used |
|
2696 * to get the backtrace up to what file and function used the deprecated |
|
2697 * argument. |
|
2698 * |
|
2699 * The current behavior is to trigger a user error if WP_DEBUG is true. |
|
2700 * |
|
2701 * @package WordPress |
|
2702 * @subpackage Debug |
|
2703 * @since 3.0.0 |
|
2704 * @access private |
|
2705 * |
|
2706 * @uses do_action() Calls 'deprecated_argument_run' and passes the function name, a message on the change, |
|
2707 * and the version in which the argument was deprecated. |
|
2708 * @uses apply_filters() Calls 'deprecated_argument_trigger_error' and expects boolean value of true to do |
|
2709 * trigger or false to not trigger error. |
|
2710 * |
|
2711 * @param string $function The function that was called |
|
2712 * @param string $version The version of WordPress that deprecated the argument used |
|
2713 * @param string $message Optional. A message regarding the change. |
|
2714 */ |
|
2715 function _deprecated_argument( $function, $version, $message = null ) { |
|
2716 |
|
2717 do_action( 'deprecated_argument_run', $function, $message, $version ); |
|
2718 |
|
2719 // Allow plugin to filter the output error trigger |
|
2720 if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) { |
|
2721 if ( ! is_null( $message ) ) |
|
2722 trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s'), $function, $version, $message ) ); |
|
2723 else |
|
2724 trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) ); |
|
2725 } |
|
2726 } |
|
2727 |
|
2728 /** |
|
2729 * Marks something as being incorrectly called. |
|
2730 * |
|
2731 * There is a hook doing_it_wrong_run that will be called that can be used |
|
2732 * to get the backtrace up to what file and function called the deprecated |
|
2733 * function. |
|
2734 * |
|
2735 * The current behavior is to trigger a user error if WP_DEBUG is true. |
|
2736 * |
|
2737 * @package WordPress |
|
2738 * @subpackage Debug |
|
2739 * @since 3.1.0 |
|
2740 * @access private |
|
2741 * |
|
2742 * @uses do_action() Calls 'doing_it_wrong_run' and passes the function arguments. |
|
2743 * @uses apply_filters() Calls 'doing_it_wrong_trigger_error' and expects boolean value of true to do |
|
2744 * trigger or false to not trigger error. |
|
2745 * |
|
2746 * @param string $function The function that was called. |
|
2747 * @param string $message A message explaining what has been done incorrectly. |
|
2748 * @param string $version The version of WordPress where the message was added. |
|
2749 */ |
|
2750 function _doing_it_wrong( $function, $message, $version ) { |
|
2751 |
|
2752 do_action( 'doing_it_wrong_run', $function, $message, $version ); |
|
2753 |
|
2754 // Allow plugin to filter the output error trigger |
|
2755 if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true ) ) { |
|
2756 $version = is_null( $version ) ? '' : sprintf( __( '(This message was added in version %s.)' ), $version ); |
|
2757 $message .= ' ' . __( 'Please see <a href="http://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information.' ); |
|
2758 trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) ); |
|
2759 } |
|
2760 } |
|
2761 |
|
2762 /** |
|
2763 * Is the server running earlier than 1.5.0 version of lighttpd? |
|
3014 * |
2764 * |
3015 * @since 2.5.0 |
2765 * @since 2.5.0 |
3016 * |
2766 * |
3017 * @return bool Whether the server is running lighttpd < 1.5.0 |
2767 * @return bool Whether the server is running lighttpd < 1.5.0 |
3018 */ |
2768 */ |
3021 $server_parts[1] = isset( $server_parts[1] )? $server_parts[1] : ''; |
2771 $server_parts[1] = isset( $server_parts[1] )? $server_parts[1] : ''; |
3022 return 'lighttpd' == $server_parts[0] && -1 == version_compare( $server_parts[1], '1.5.0' ); |
2772 return 'lighttpd' == $server_parts[0] && -1 == version_compare( $server_parts[1], '1.5.0' ); |
3023 } |
2773 } |
3024 |
2774 |
3025 /** |
2775 /** |
3026 * Does the specified module exist in the apache config? |
2776 * Does the specified module exist in the Apache config? |
3027 * |
2777 * |
3028 * @since 2.5.0 |
2778 * @since 2.5.0 |
3029 * |
2779 * |
3030 * @param string $mod e.g. mod_rewrite |
2780 * @param string $mod e.g. mod_rewrite |
3031 * @param bool $default The default return value if the module is not found |
2781 * @param bool $default The default return value if the module is not found |
3050 } |
2800 } |
3051 return $default; |
2801 return $default; |
3052 } |
2802 } |
3053 |
2803 |
3054 /** |
2804 /** |
2805 * Check if IIS 7 supports pretty permalinks. |
|
2806 * |
|
2807 * @since 2.8.0 |
|
2808 * |
|
2809 * @return bool |
|
2810 */ |
|
2811 function iis7_supports_permalinks() { |
|
2812 global $is_iis7; |
|
2813 |
|
2814 $supports_permalinks = false; |
|
2815 if ( $is_iis7 ) { |
|
2816 /* First we check if the DOMDocument class exists. If it does not exist, |
|
2817 * which is the case for PHP 4.X, then we cannot easily update the xml configuration file, |
|
2818 * hence we just bail out and tell user that pretty permalinks cannot be used. |
|
2819 * This is not a big issue because PHP 4.X is going to be deprecated and for IIS it |
|
2820 * is recommended to use PHP 5.X NTS. |
|
2821 * Next we check if the URL Rewrite Module 1.1 is loaded and enabled for the web site. When |
|
2822 * URL Rewrite 1.1 is loaded it always sets a server variable called 'IIS_UrlRewriteModule'. |
|
2823 * Lastly we make sure that PHP is running via FastCGI. This is important because if it runs |
|
2824 * via ISAPI then pretty permalinks will not work. |
|
2825 */ |
|
2826 $supports_permalinks = class_exists('DOMDocument') && isset($_SERVER['IIS_UrlRewriteModule']) && ( php_sapi_name() == 'cgi-fcgi' ); |
|
2827 } |
|
2828 |
|
2829 return apply_filters('iis7_supports_permalinks', $supports_permalinks); |
|
2830 } |
|
2831 |
|
2832 /** |
|
3055 * File validates against allowed set of defined rules. |
2833 * File validates against allowed set of defined rules. |
3056 * |
2834 * |
3057 * A return value of '1' means that the $file contains either '..' or './'. A |
2835 * A return value of '1' means that the $file contains either '..' or './'. A |
3058 * return value of '2' means that the $file contains ':' after the first |
2836 * return value of '2' means that the $file contains ':' after the first |
3059 * character. A return value of '3' means that the file is not in the allowed |
2837 * character. A return value of '3' means that the file is not in the allowed |
3064 * @param string $file File path. |
2842 * @param string $file File path. |
3065 * @param array $allowed_files List of allowed files. |
2843 * @param array $allowed_files List of allowed files. |
3066 * @return int 0 means nothing is wrong, greater than 0 means something was wrong. |
2844 * @return int 0 means nothing is wrong, greater than 0 means something was wrong. |
3067 */ |
2845 */ |
3068 function validate_file( $file, $allowed_files = '' ) { |
2846 function validate_file( $file, $allowed_files = '' ) { |
3069 if ( false !== strpos( $file, '..' )) |
2847 if ( false !== strpos( $file, '..' ) ) |
3070 return 1; |
2848 return 1; |
3071 |
2849 |
3072 if ( false !== strpos( $file, './' )) |
2850 if ( false !== strpos( $file, './' ) ) |
3073 return 1; |
2851 return 1; |
3074 |
2852 |
3075 if (!empty ( $allowed_files ) && (!in_array( $file, $allowed_files ) ) ) |
2853 if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files ) ) |
3076 return 3; |
2854 return 3; |
3077 |
2855 |
3078 if (':' == substr( $file, 1, 1 )) |
2856 if (':' == substr( $file, 1, 1 ) ) |
3079 return 2; |
2857 return 2; |
3080 |
2858 |
3081 return 0; |
2859 return 0; |
3082 } |
2860 } |
3083 |
2861 |
3119 |
2897 |
3120 return $forced; |
2898 return $forced; |
3121 } |
2899 } |
3122 |
2900 |
3123 /** |
2901 /** |
3124 * Whether to force SSL used for the Administration Panels. |
2902 * Whether to force SSL used for the Administration Screens. |
3125 * |
2903 * |
3126 * @since 2.6.0 |
2904 * @since 2.6.0 |
3127 * |
2905 * |
3128 * @param string|bool $force |
2906 * @param string|bool $force |
3129 * @return bool True if forced, false if not forced. |
2907 * @return bool True if forced, false if not forced. |
3152 */ |
2930 */ |
3153 function wp_guess_url() { |
2931 function wp_guess_url() { |
3154 if ( defined('WP_SITEURL') && '' != WP_SITEURL ) { |
2932 if ( defined('WP_SITEURL') && '' != WP_SITEURL ) { |
3155 $url = WP_SITEURL; |
2933 $url = WP_SITEURL; |
3156 } else { |
2934 } else { |
3157 $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://'; |
2935 $schema = is_ssl() ? 'https://' : 'http://'; |
3158 $url = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); |
2936 $url = preg_replace('#/(wp-admin/.*|wp-login.php)#i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); |
3159 } |
2937 } |
3160 return $url; |
2938 return rtrim($url, '/'); |
2939 } |
|
2940 |
|
2941 /** |
|
2942 * Temporarily suspend cache additions. |
|
2943 * |
|
2944 * Stops more data being added to the cache, but still allows cache retrieval. |
|
2945 * This is useful for actions, such as imports, when a lot of data would otherwise |
|
2946 * be almost uselessly added to the cache. |
|
2947 * |
|
2948 * Suspension lasts for a single page load at most. Remember to call this |
|
2949 * function again if you wish to re-enable cache adds earlier. |
|
2950 * |
|
2951 * @since 3.3.0 |
|
2952 * |
|
2953 * @param bool $suspend Optional. Suspends additions if true, re-enables them if false. |
|
2954 * @return bool The current suspend setting |
|
2955 */ |
|
2956 function wp_suspend_cache_addition( $suspend = null ) { |
|
2957 static $_suspend = false; |
|
2958 |
|
2959 if ( is_bool( $suspend ) ) |
|
2960 $_suspend = $suspend; |
|
2961 |
|
2962 return $_suspend; |
|
3161 } |
2963 } |
3162 |
2964 |
3163 /** |
2965 /** |
3164 * Suspend cache invalidation. |
2966 * Suspend cache invalidation. |
3165 * |
2967 * |
3166 * Turns cache invalidation on and off. Useful during imports where you don't wont to do invalidations |
2968 * Turns cache invalidation on and off. Useful during imports where you don't wont to do invalidations |
3167 * every time a post is inserted. Callers must be sure that what they are doing won't lead to an inconsistent |
2969 * every time a post is inserted. Callers must be sure that what they are doing won't lead to an inconsistent |
3168 * cache when invalidation is suspended. |
2970 * cache when invalidation is suspended. |
3169 * |
2971 * |
3170 * @since 2.7.0 |
2972 * @since 2.7.0 |
3171 * |
2973 * |
3172 * @param bool $suspend Whether to suspend or enable cache invalidation |
2974 * @param bool $suspend Whether to suspend or enable cache invalidation |
3178 $current_suspend = $_wp_suspend_cache_invalidation; |
2980 $current_suspend = $_wp_suspend_cache_invalidation; |
3179 $_wp_suspend_cache_invalidation = $suspend; |
2981 $_wp_suspend_cache_invalidation = $suspend; |
3180 return $current_suspend; |
2982 return $current_suspend; |
3181 } |
2983 } |
3182 |
2984 |
3183 function get_site_option( $key, $default = false, $use_cache = true ) { |
2985 /** |
3184 // Allow plugins to short-circuit site options. |
2986 * Is main site? |
3185 $pre = apply_filters( 'pre_site_option_' . $key, false ); |
2987 * |
3186 if ( false !== $pre ) |
2988 * |
3187 return $pre; |
2989 * @since 3.0.0 |
3188 |
|
3189 $value = get_option($key, $default); |
|
3190 |
|
3191 return apply_filters( 'site_option_' . $key, $value ); |
|
3192 } |
|
3193 |
|
3194 // expects $key, $value not to be SQL escaped |
|
3195 function add_site_option( $key, $value ) { |
|
3196 $value = apply_filters( 'pre_add_site_option_' . $key, $value ); |
|
3197 $result = add_option($key, $value); |
|
3198 do_action( "add_site_option_{$key}", $key, $value ); |
|
3199 return $result; |
|
3200 } |
|
3201 |
|
3202 function delete_site_option( $key ) { |
|
3203 $result = delete_option($key); |
|
3204 do_action( "delete_site_option_{$key}", $key ); |
|
3205 return $result; |
|
3206 } |
|
3207 |
|
3208 // expects $key, $value not to be SQL escaped |
|
3209 function update_site_option( $key, $value ) { |
|
3210 $oldvalue = get_site_option( $key ); |
|
3211 $value = apply_filters( 'pre_update_site_option_' . $key, $value, $oldvalue ); |
|
3212 $result = update_option($key, $value); |
|
3213 do_action( "update_site_option_{$key}", $key, $value ); |
|
3214 return $result; |
|
3215 } |
|
3216 |
|
3217 /** |
|
3218 * Delete a site transient |
|
3219 * |
|
3220 * @since 2.890 |
|
3221 * @package WordPress |
2990 * @package WordPress |
3222 * @subpackage Transient |
2991 * |
3223 * |
2992 * @param int $blog_id optional blog id to test (default current blog) |
3224 * @param string $transient Transient name. Expected to not be SQL-escaped |
2993 * @return bool True if not multisite or $blog_id is main site |
3225 * @return bool true if successful, false otherwise |
2994 */ |
3226 */ |
2995 function is_main_site( $blog_id = '' ) { |
3227 function delete_site_transient($transient) { |
2996 global $current_site, $current_blog; |
3228 global $_wp_using_ext_object_cache, $wpdb; |
2997 |
3229 |
2998 if ( !is_multisite() ) |
3230 if ( $_wp_using_ext_object_cache ) { |
2999 return true; |
3231 return wp_cache_delete($transient, 'site-transient'); |
3000 |
3232 } else { |
3001 if ( !$blog_id ) |
3233 $transient = '_site_transient_' . esc_sql($transient); |
3002 $blog_id = $current_blog->blog_id; |
3234 return delete_site_option($transient); |
3003 |
3235 } |
3004 return $blog_id == $current_site->blog_id; |
3236 } |
3005 } |
3237 |
3006 |
3238 /** |
3007 /** |
3239 * Get the value of a site transient |
3008 * Whether global terms are enabled. |
3240 * |
3009 * |
3241 * If the transient does not exist or does not have a value, then the return value |
3010 * |
3242 * will be false. |
3011 * @since 3.0.0 |
3243 * |
|
3244 * @since 2.9.0 |
|
3245 * @package WordPress |
3012 * @package WordPress |
3246 * @subpackage Transient |
3013 * |
3247 * |
3014 * @return bool True if multisite and global terms enabled |
3248 * @param string $transient Transient name. Expected to not be SQL-escaped |
3015 */ |
3249 * @return mixed Value of transient |
3016 function global_terms_enabled() { |
3250 */ |
3017 if ( ! is_multisite() ) |
3251 function get_site_transient($transient) { |
3018 return false; |
3252 global $_wp_using_ext_object_cache, $wpdb; |
3019 |
3253 |
3020 static $global_terms = null; |
3254 $pre = apply_filters( 'pre_site_transient_' . $transient, false ); |
3021 if ( is_null( $global_terms ) ) { |
3255 if ( false !== $pre ) |
3022 $filter = apply_filters( 'global_terms_enabled', null ); |
3256 return $pre; |
3023 if ( ! is_null( $filter ) ) |
3257 |
3024 $global_terms = (bool) $filter; |
3258 if ( $_wp_using_ext_object_cache ) { |
3025 else |
3259 $value = wp_cache_get($transient, 'site-transient'); |
3026 $global_terms = (bool) get_site_option( 'global_terms_enabled', false ); |
3260 } else { |
3027 } |
3261 $transient_option = '_site_transient_' . esc_sql($transient); |
3028 return $global_terms; |
3262 $transient_timeout = '_site_transient_timeout_' . esc_sql($transient); |
3029 } |
3263 if ( get_site_option($transient_timeout) < time() ) { |
3030 |
3264 delete_site_option($transient_option); |
3031 /** |
3265 delete_site_option($transient_timeout); |
3032 * gmt_offset modification for smart timezone handling. |
3266 return false; |
3033 * |
3267 } |
3034 * Overrides the gmt_offset option if we have a timezone_string available. |
3268 |
3035 * |
3269 $value = get_site_option($transient_option); |
3036 * @since 2.8.0 |
3270 } |
3037 * |
3271 |
3038 * @return float|bool |
3272 return apply_filters('site_transient_' . $transient, $value); |
|
3273 } |
|
3274 |
|
3275 /** |
|
3276 * Set/update the value of a site transient |
|
3277 * |
|
3278 * You do not need to serialize values, if the value needs to be serialize, then |
|
3279 * it will be serialized before it is set. |
|
3280 * |
|
3281 * @since 2.9.0 |
|
3282 * @package WordPress |
|
3283 * @subpackage Transient |
|
3284 * |
|
3285 * @param string $transient Transient name. Expected to not be SQL-escaped |
|
3286 * @param mixed $value Transient value. |
|
3287 * @param int $expiration Time until expiration in seconds, default 0 |
|
3288 * @return bool False if value was not set and true if value was set. |
|
3289 */ |
|
3290 function set_site_transient($transient, $value, $expiration = 0) { |
|
3291 global $_wp_using_ext_object_cache, $wpdb; |
|
3292 |
|
3293 if ( $_wp_using_ext_object_cache ) { |
|
3294 return wp_cache_set($transient, $value, 'site-transient', $expiration); |
|
3295 } else { |
|
3296 $transient_timeout = '_site_transient_timeout_' . $transient; |
|
3297 $transient = '_site_transient_' . $transient; |
|
3298 $safe_transient = esc_sql($transient); |
|
3299 if ( false === get_site_option( $safe_transient ) ) { |
|
3300 if ( 0 != $expiration ) |
|
3301 add_site_option($transient_timeout, time() + $expiration); |
|
3302 return add_site_option($transient, $value); |
|
3303 } else { |
|
3304 if ( 0 != $expiration ) |
|
3305 update_site_option($transient_timeout, time() + $expiration); |
|
3306 return update_site_option($transient, $value); |
|
3307 } |
|
3308 } |
|
3309 } |
|
3310 |
|
3311 /** |
|
3312 * gmt_offset modification for smart timezone handling |
|
3313 * |
|
3314 * Overrides the gmt_offset option if we have a timezone_string available |
|
3315 */ |
3039 */ |
3316 function wp_timezone_override_offset() { |
3040 function wp_timezone_override_offset() { |
3317 if ( !wp_timezone_supported() ) { |
|
3318 return false; |
|
3319 } |
|
3320 if ( !$timezone_string = get_option( 'timezone_string' ) ) { |
3041 if ( !$timezone_string = get_option( 'timezone_string' ) ) { |
3321 return false; |
3042 return false; |
3322 } |
3043 } |
3323 |
3044 |
3324 @date_default_timezone_set( $timezone_string ); |
|
3325 $timezone_object = timezone_open( $timezone_string ); |
3045 $timezone_object = timezone_open( $timezone_string ); |
3326 $datetime_object = date_create(); |
3046 $datetime_object = date_create(); |
3327 if ( false === $timezone_object || false === $datetime_object ) { |
3047 if ( false === $timezone_object || false === $datetime_object ) { |
3328 return false; |
3048 return false; |
3329 } |
3049 } |
3330 return round( timezone_offset_get( $timezone_object, $datetime_object ) / 3600, 2 ); |
3050 return round( timezone_offset_get( $timezone_object, $datetime_object ) / 3600, 2 ); |
3331 } |
3051 } |
3332 |
3052 |
3333 /** |
3053 /** |
3334 * Check for PHP timezone support |
3054 * {@internal Missing Short Description}} |
3335 */ |
3055 * |
3336 function wp_timezone_supported() { |
3056 * @since 2.9.0 |
3337 $support = false; |
3057 * |
3338 if ( |
3058 * @param unknown_type $a |
3339 function_exists( 'date_default_timezone_set' ) && |
3059 * @param unknown_type $b |
3340 function_exists( 'timezone_identifiers_list' ) && |
3060 * @return int |
3341 function_exists( 'timezone_open' ) && |
3061 */ |
3342 function_exists( 'timezone_offset_get' ) |
|
3343 ) { |
|
3344 $support = true; |
|
3345 } |
|
3346 return apply_filters( 'timezone_support', $support ); |
|
3347 } |
|
3348 |
|
3349 function _wp_timezone_choice_usort_callback( $a, $b ) { |
3062 function _wp_timezone_choice_usort_callback( $a, $b ) { |
3350 // Don't use translated versions of Etc |
3063 // Don't use translated versions of Etc |
3351 if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) { |
3064 if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) { |
3352 // Make the order of these more like the old dropdown |
3065 // Make the order of these more like the old dropdown |
3353 if ( 'GMT+' === substr( $a['city'], 0, 4 ) && 'GMT+' === substr( $b['city'], 0, 4 ) ) { |
3066 if ( 'GMT+' === substr( $a['city'], 0, 4 ) && 'GMT+' === substr( $b['city'], 0, 4 ) ) { |
3383 return strnatcasecmp( $a['t_continent'], $b['t_continent'] ); |
3096 return strnatcasecmp( $a['t_continent'], $b['t_continent'] ); |
3384 } |
3097 } |
3385 } |
3098 } |
3386 |
3099 |
3387 /** |
3100 /** |
3388 * Gives a nicely formatted list of timezone strings // temporary! Not in final |
3101 * Gives a nicely formatted list of timezone strings. // temporary! Not in final |
3389 * |
3102 * |
3390 * @param $selected_zone string Selected Zone |
3103 * @since 2.9.0 |
3391 * |
3104 * |
3105 * @param string $selected_zone Selected Zone |
|
3106 * @return string |
|
3392 */ |
3107 */ |
3393 function wp_timezone_choice( $selected_zone ) { |
3108 function wp_timezone_choice( $selected_zone ) { |
3394 static $mo_loaded = false; |
3109 static $mo_loaded = false; |
3395 |
3110 |
3396 $continents = array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific'); |
3111 $continents = array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific'); |
3410 continue; |
3125 continue; |
3411 } |
3126 } |
3412 |
3127 |
3413 // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
3128 // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
3414 $exists = array( |
3129 $exists = array( |
3415 0 => ( isset( $zone[0] ) && $zone[0] ) ? true : false, |
3130 0 => ( isset( $zone[0] ) && $zone[0] ), |
3416 1 => ( isset( $zone[1] ) && $zone[1] ) ? true : false, |
3131 1 => ( isset( $zone[1] ) && $zone[1] ), |
3417 2 => ( isset( $zone[2] ) && $zone[2] ) ? true : false |
3132 2 => ( isset( $zone[2] ) && $zone[2] ), |
3418 ); |
3133 ); |
3419 $exists[3] = ( $exists[0] && 'Etc' !== $zone[0] ) ? true : false; |
3134 $exists[3] = ( $exists[0] && 'Etc' !== $zone[0] ); |
3420 $exists[4] = ( $exists[1] && $exists[3] ) ? true : false; |
3135 $exists[4] = ( $exists[1] && $exists[3] ); |
3421 $exists[5] = ( $exists[2] && $exists[3] ) ? true : false; |
3136 $exists[5] = ( $exists[2] && $exists[3] ); |
3422 |
3137 |
3423 $zonen[] = array( |
3138 $zonen[] = array( |
3424 'continent' => ( $exists[0] ? $zone[0] : '' ), |
3139 'continent' => ( $exists[0] ? $zone[0] : '' ), |
3425 'city' => ( $exists[1] ? $zone[1] : '' ), |
3140 'city' => ( $exists[1] ? $zone[1] : '' ), |
3426 'subcity' => ( $exists[2] ? $zone[2] : '' ), |
3141 'subcity' => ( $exists[2] ? $zone[2] : '' ), |
3502 $offset_value = 'UTC' . $offset_value; |
3217 $offset_value = 'UTC' . $offset_value; |
3503 $selected = ''; |
3218 $selected = ''; |
3504 if ( $offset_value === $selected_zone ) |
3219 if ( $offset_value === $selected_zone ) |
3505 $selected = 'selected="selected" '; |
3220 $selected = 'selected="selected" '; |
3506 $structure[] = '<option ' . $selected . 'value="' . esc_attr( $offset_value ) . '">' . esc_html( $offset_name ) . "</option>"; |
3221 $structure[] = '<option ' . $selected . 'value="' . esc_attr( $offset_value ) . '">' . esc_html( $offset_name ) . "</option>"; |
3507 |
3222 |
3508 } |
3223 } |
3509 $structure[] = '</optgroup>'; |
3224 $structure[] = '</optgroup>'; |
3510 |
3225 |
3511 return join( "\n", $structure ); |
3226 return join( "\n", $structure ); |
3512 } |
3227 } |
3513 |
3228 |
3514 /** |
3229 /** |
3515 * Strip close comment and close php tags from file headers used by WP |
3230 * Strip close comment and close php tags from file headers used by WP. |
3516 * See http://core.trac.wordpress.org/ticket/8497 |
3231 * See http://core.trac.wordpress.org/ticket/8497 |
3517 * |
3232 * |
3518 * @since 2.8 |
3233 * @since 2.8.0 |
3519 **/ |
3234 * |
3235 * @param string $str |
|
3236 * @return string |
|
3237 */ |
|
3520 function _cleanup_header_comment($str) { |
3238 function _cleanup_header_comment($str) { |
3521 return trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $str)); |
3239 return trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $str)); |
3522 } |
3240 } |
3523 |
3241 |
3524 /** |
3242 /** |
3525 * Permanently deletes posts, pages, attachments, and comments which have been in the trash for EMPTY_TRASH_DAYS. |
3243 * Permanently deletes posts, pages, attachments, and comments which have been in the trash for EMPTY_TRASH_DAYS. |
3526 * |
3244 * |
3527 * @since 2.9.0 |
3245 * @since 2.9.0 |
3528 * |
|
3529 * @return void |
|
3530 */ |
3246 */ |
3531 function wp_scheduled_delete() { |
3247 function wp_scheduled_delete() { |
3532 global $wpdb; |
3248 global $wpdb; |
3533 |
3249 |
3534 $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS); |
3250 $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS); |
3567 } |
3283 } |
3568 } |
3284 } |
3569 } |
3285 } |
3570 |
3286 |
3571 /** |
3287 /** |
3572 * Parse the file contents to retrieve its metadata. |
3288 * Retrieve metadata from a file. |
3573 * |
3289 * |
3574 * Searches for metadata for a file, such as a plugin or theme. Each piece of |
3290 * Searches for metadata in the first 8kiB of a file, such as a plugin or theme. |
3575 * metadata must be on its own line. For a field spanning multple lines, it |
3291 * Each piece of metadata must be on its own line. Fields can not span multiple |
3576 * must not have any newlines or only parts of it will be displayed. |
3292 * lines, the value will get cut at the end of the first line. |
3577 * |
3293 * |
3578 * Some users have issues with opening large files and manipulating the contents |
3294 * If the file data is not within that first 8kiB, then the author should correct |
3579 * for want is usually the first 1kiB or 2kiB. This function stops pulling in |
3295 * their plugin file and move the data headers to the top. |
3580 * the file contents when it has all of the required data. |
3296 * |
3581 * |
3297 * @see http://codex.wordpress.org/File_Header |
3582 * The first 8kiB of the file will be pulled in and if the file data is not |
|
3583 * within that first 8kiB, then the author should correct their plugin file |
|
3584 * and move the data headers to the top. |
|
3585 * |
|
3586 * The file is assumed to have permissions to allow for scripts to read |
|
3587 * the file. This is not checked however and the file is only opened for |
|
3588 * reading. |
|
3589 * |
3298 * |
3590 * @since 2.9.0 |
3299 * @since 2.9.0 |
3591 * |
|
3592 * @param string $file Path to the file |
3300 * @param string $file Path to the file |
3593 * @param bool $markup If the returned data should have HTML markup applied |
3301 * @param array $default_headers List of headers, in the format array('HeaderKey' => 'Header Name') |
3594 * @param string $context If specified adds filter hook "extra_<$context>_headers" |
3302 * @param string $context If specified adds filter hook "extra_{$context}_headers" |
3595 */ |
3303 */ |
3596 function get_file_data( $file, $default_headers, $context = '' ) { |
3304 function get_file_data( $file, $default_headers, $context = '' ) { |
3597 // We don't need to write to the file, so just open for reading. |
3305 // We don't need to write to the file, so just open for reading. |
3598 $fp = fopen( $file, 'r' ); |
3306 $fp = fopen( $file, 'r' ); |
3599 |
3307 |
3601 $file_data = fread( $fp, 8192 ); |
3309 $file_data = fread( $fp, 8192 ); |
3602 |
3310 |
3603 // PHP will close file handle, but we are good citizens. |
3311 // PHP will close file handle, but we are good citizens. |
3604 fclose( $fp ); |
3312 fclose( $fp ); |
3605 |
3313 |
3606 if( $context != '' ) { |
3314 // Make sure we catch CR-only line endings. |
3607 $extra_headers = apply_filters( "extra_$context".'_headers', array() ); |
3315 $file_data = str_replace( "\r", "\n", $file_data ); |
3608 |
3316 |
3609 $extra_headers = array_flip( $extra_headers ); |
3317 if ( $context && $extra_headers = apply_filters( "extra_{$context}_headers", array() ) ) { |
3610 foreach( $extra_headers as $key=>$value ) { |
3318 $extra_headers = array_combine( $extra_headers, $extra_headers ); // keys equal values |
3611 $extra_headers[$key] = $key; |
3319 $all_headers = array_merge( $extra_headers, (array) $default_headers ); |
3612 } |
|
3613 $all_headers = array_merge($extra_headers, $default_headers); |
|
3614 } else { |
3320 } else { |
3615 $all_headers = $default_headers; |
3321 $all_headers = $default_headers; |
3616 } |
3322 } |
3617 |
3323 |
3618 |
|
3619 foreach ( $all_headers as $field => $regex ) { |
3324 foreach ( $all_headers as $field => $regex ) { |
3620 preg_match( '/' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, ${$field}); |
3325 if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] ) |
3621 if ( !empty( ${$field} ) ) |
3326 $all_headers[ $field ] = _cleanup_header_comment( $match[1] ); |
3622 ${$field} = _cleanup_header_comment( ${$field}[1] ); |
|
3623 else |
3327 else |
3624 ${$field} = ''; |
3328 $all_headers[ $field ] = ''; |
3625 } |
3329 } |
3626 |
3330 |
3627 $file_data = compact( array_keys( $all_headers ) ); |
3331 return $all_headers; |
3628 |
3332 } |
3629 return $file_data; |
3333 |
3630 } |
3334 /** |
3631 /* |
3335 * Used internally to tidy up the search terms. |
3632 * Used internally to tidy up the search terms |
3336 * |
3633 * |
3337 * @access private |
3634 * @private |
|
3635 * @since 2.9.0 |
3338 * @since 2.9.0 |
3339 * |
|
3340 * @param string $t |
|
3341 * @return string |
|
3636 */ |
3342 */ |
3637 function _search_terms_tidy($t) { |
3343 function _search_terms_tidy($t) { |
3638 return trim($t, "\"\'\n\r "); |
3344 return trim($t, "\"'\n\r "); |
3639 } |
3345 } |
3640 ?> |
3346 |
3347 /** |
|
3348 * Returns true. |
|
3349 * |
|
3350 * Useful for returning true to filters easily. |
|
3351 * |
|
3352 * @since 3.0.0 |
|
3353 * @see __return_false() |
|
3354 * @return bool true |
|
3355 */ |
|
3356 function __return_true() { |
|
3357 return true; |
|
3358 } |
|
3359 |
|
3360 /** |
|
3361 * Returns false. |
|
3362 * |
|
3363 * Useful for returning false to filters easily. |
|
3364 * |
|
3365 * @since 3.0.0 |
|
3366 * @see __return_true() |
|
3367 * @return bool false |
|
3368 */ |
|
3369 function __return_false() { |
|
3370 return false; |
|
3371 } |
|
3372 |
|
3373 /** |
|
3374 * Returns 0. |
|
3375 * |
|
3376 * Useful for returning 0 to filters easily. |
|
3377 * |
|
3378 * @since 3.0.0 |
|
3379 * @see __return_zero() |
|
3380 * @return int 0 |
|
3381 */ |
|
3382 function __return_zero() { |
|
3383 return 0; |
|
3384 } |
|
3385 |
|
3386 /** |
|
3387 * Returns an empty array. |
|
3388 * |
|
3389 * Useful for returning an empty array to filters easily. |
|
3390 * |
|
3391 * @since 3.0.0 |
|
3392 * @see __return_zero() |
|
3393 * @return array Empty array |
|
3394 */ |
|
3395 function __return_empty_array() { |
|
3396 return array(); |
|
3397 } |
|
3398 |
|
3399 /** |
|
3400 * Returns null. |
|
3401 * |
|
3402 * Useful for returning null to filters easily. |
|
3403 * |
|
3404 * @since 3.4.0 |
|
3405 * @return null |
|
3406 */ |
|
3407 function __return_null() { |
|
3408 return null; |
|
3409 } |
|
3410 |
|
3411 /** |
|
3412 * Send a HTTP header to disable content type sniffing in browsers which support it. |
|
3413 * |
|
3414 * @link http://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx |
|
3415 * @link http://src.chromium.org/viewvc/chrome?view=rev&revision=6985 |
|
3416 * |
|
3417 * @since 3.0.0 |
|
3418 * @return none |
|
3419 */ |
|
3420 function send_nosniff_header() { |
|
3421 @header( 'X-Content-Type-Options: nosniff' ); |
|
3422 } |
|
3423 |
|
3424 /** |
|
3425 * Returns a MySQL expression for selecting the week number based on the start_of_week option. |
|
3426 * |
|
3427 * @internal |
|
3428 * @since 3.0.0 |
|
3429 * @param string $column |
|
3430 * @return string |
|
3431 */ |
|
3432 function _wp_mysql_week( $column ) { |
|
3433 switch ( $start_of_week = (int) get_option( 'start_of_week' ) ) { |
|
3434 default : |
|
3435 case 0 : |
|
3436 return "WEEK( $column, 0 )"; |
|
3437 case 1 : |
|
3438 return "WEEK( $column, 1 )"; |
|
3439 case 2 : |
|
3440 case 3 : |
|
3441 case 4 : |
|
3442 case 5 : |
|
3443 case 6 : |
|
3444 return "WEEK( DATE_SUB( $column, INTERVAL $start_of_week DAY ), 0 )"; |
|
3445 } |
|
3446 } |
|
3447 |
|
3448 /** |
|
3449 * Finds hierarchy loops using a callback function that maps object IDs to parent IDs. |
|
3450 * |
|
3451 * @since 3.1.0 |
|
3452 * @access private |
|
3453 * |
|
3454 * @param callback $callback function that accepts ( ID, $callback_args ) and outputs parent_ID |
|
3455 * @param int $start The ID to start the loop check at |
|
3456 * @param int $start_parent the parent_ID of $start to use instead of calling $callback( $start ). Use null to always use $callback |
|
3457 * @param array $callback_args optional additional arguments to send to $callback |
|
3458 * @return array IDs of all members of loop |
|
3459 */ |
|
3460 function wp_find_hierarchy_loop( $callback, $start, $start_parent, $callback_args = array() ) { |
|
3461 $override = is_null( $start_parent ) ? array() : array( $start => $start_parent ); |
|
3462 |
|
3463 if ( !$arbitrary_loop_member = wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override, $callback_args ) ) |
|
3464 return array(); |
|
3465 |
|
3466 return wp_find_hierarchy_loop_tortoise_hare( $callback, $arbitrary_loop_member, $override, $callback_args, true ); |
|
3467 } |
|
3468 |
|
3469 /** |
|
3470 * Uses the "The Tortoise and the Hare" algorithm to detect loops. |
|
3471 * |
|
3472 * For every step of the algorithm, the hare takes two steps and the tortoise one. |
|
3473 * If the hare ever laps the tortoise, there must be a loop. |
|
3474 * |
|
3475 * @since 3.1.0 |
|
3476 * @access private |
|
3477 * |
|
3478 * @param callback $callback function that accepts ( ID, callback_arg, ... ) and outputs parent_ID |
|
3479 * @param int $start The ID to start the loop check at |
|
3480 * @param array $override an array of ( ID => parent_ID, ... ) to use instead of $callback |
|
3481 * @param array $callback_args optional additional arguments to send to $callback |
|
3482 * @param bool $_return_loop Return loop members or just detect presence of loop? |
|
3483 * Only set to true if you already know the given $start is part of a loop |
|
3484 * (otherwise the returned array might include branches) |
|
3485 * @return mixed scalar ID of some arbitrary member of the loop, or array of IDs of all members of loop if $_return_loop |
|
3486 */ |
|
3487 function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = array(), $callback_args = array(), $_return_loop = false ) { |
|
3488 $tortoise = $hare = $evanescent_hare = $start; |
|
3489 $return = array(); |
|
3490 |
|
3491 // Set evanescent_hare to one past hare |
|
3492 // Increment hare two steps |
|
3493 while ( |
|
3494 $tortoise |
|
3495 && |
|
3496 ( $evanescent_hare = isset( $override[$hare] ) ? $override[$hare] : call_user_func_array( $callback, array_merge( array( $hare ), $callback_args ) ) ) |
|
3497 && |
|
3498 ( $hare = isset( $override[$evanescent_hare] ) ? $override[$evanescent_hare] : call_user_func_array( $callback, array_merge( array( $evanescent_hare ), $callback_args ) ) ) |
|
3499 ) { |
|
3500 if ( $_return_loop ) |
|
3501 $return[$tortoise] = $return[$evanescent_hare] = $return[$hare] = true; |
|
3502 |
|
3503 // tortoise got lapped - must be a loop |
|
3504 if ( $tortoise == $evanescent_hare || $tortoise == $hare ) |
|
3505 return $_return_loop ? $return : $tortoise; |
|
3506 |
|
3507 // Increment tortoise by one step |
|
3508 $tortoise = isset( $override[$tortoise] ) ? $override[$tortoise] : call_user_func_array( $callback, array_merge( array( $tortoise ), $callback_args ) ); |
|
3509 } |
|
3510 |
|
3511 return false; |
|
3512 } |
|
3513 |
|
3514 /** |
|
3515 * Send a HTTP header to limit rendering of pages to same origin iframes. |
|
3516 * |
|
3517 * @link https://developer.mozilla.org/en/the_x-frame-options_response_header |
|
3518 * |
|
3519 * @since 3.1.3 |
|
3520 * @return none |
|
3521 */ |
|
3522 function send_frame_options_header() { |
|
3523 @header( 'X-Frame-Options: SAMEORIGIN' ); |
|
3524 } |
|
3525 |
|
3526 /** |
|
3527 * Retrieve a list of protocols to allow in HTML attributes. |
|
3528 * |
|
3529 * @since 3.3.0 |
|
3530 * @see wp_kses() |
|
3531 * @see esc_url() |
|
3532 * |
|
3533 * @return array Array of allowed protocols |
|
3534 */ |
|
3535 function wp_allowed_protocols() { |
|
3536 static $protocols; |
|
3537 |
|
3538 if ( empty( $protocols ) ) { |
|
3539 $protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn' ); |
|
3540 $protocols = apply_filters( 'kses_allowed_protocols', $protocols ); |
|
3541 } |
|
3542 |
|
3543 return $protocols; |
|
3544 } |
|
3545 |
|
3546 /** |
|
3547 * Return a comma separated string of functions that have been called to get to the current point in code. |
|
3548 * |
|
3549 * @link http://core.trac.wordpress.org/ticket/19589 |
|
3550 * @since 3.4 |
|
3551 * |
|
3552 * @param string $ignore_class A class to ignore all function calls within - useful when you want to just give info about the callee |
|
3553 * @param int $skip_frames A number of stack frames to skip - useful for unwinding back to the source of the issue |
|
3554 * @param bool $pretty Whether or not you want a comma separated string or raw array returned |
|
3555 * @return string|array Either a string containing a reversed comma separated trace or an array of individual calls. |
|
3556 */ |
|
3557 function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) { |
|
3558 if ( version_compare( PHP_VERSION, '5.2.5', '>=' ) ) |
|
3559 $trace = debug_backtrace( false ); |
|
3560 else |
|
3561 $trace = debug_backtrace(); |
|
3562 |
|
3563 $caller = array(); |
|
3564 $check_class = ! is_null( $ignore_class ); |
|
3565 $skip_frames++; // skip this function |
|
3566 |
|
3567 foreach ( $trace as $call ) { |
|
3568 if ( $skip_frames > 0 ) { |
|
3569 $skip_frames--; |
|
3570 } elseif ( isset( $call['class'] ) ) { |
|
3571 if ( $check_class && $ignore_class == $call['class'] ) |
|
3572 continue; // Filter out calls |
|
3573 |
|
3574 $caller[] = "{$call['class']}{$call['type']}{$call['function']}"; |
|
3575 } else { |
|
3576 if ( in_array( $call['function'], array( 'do_action', 'apply_filters' ) ) ) { |
|
3577 $caller[] = "{$call['function']}('{$call['args'][0]}')"; |
|
3578 } elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ) ) ) { |
|
3579 $caller[] = $call['function'] . "('" . str_replace( array( WP_CONTENT_DIR, ABSPATH ) , '', $call['args'][0] ) . "')"; |
|
3580 } else { |
|
3581 $caller[] = $call['function']; |
|
3582 } |
|
3583 } |
|
3584 } |
|
3585 if ( $pretty ) |
|
3586 return join( ', ', array_reverse( $caller ) ); |
|
3587 else |
|
3588 return $caller; |
|
3589 } |
|
3590 |
|
3591 /** |
|
3592 * Retrieve ids that are not already present in the cache |
|
3593 * |
|
3594 * @since 3.4.0 |
|
3595 * |
|
3596 * @param array $object_ids ID list |
|
3597 * @param string $cache_key The cache bucket to check against |
|
3598 * |
|
3599 * @return array |
|
3600 */ |
|
3601 function _get_non_cached_ids( $object_ids, $cache_key ) { |
|
3602 $clean = array(); |
|
3603 foreach ( $object_ids as $id ) { |
|
3604 $id = (int) $id; |
|
3605 if ( !wp_cache_get( $id, $cache_key ) ) { |
|
3606 $clean[] = $id; |
|
3607 } |
|
3608 } |
|
3609 |
|
3610 return $clean; |
|
3611 } |
|
3612 |
|
3613 /** |
|
3614 * Test if the current device has the capability to upload files. |
|
3615 * |
|
3616 * @since 3.4.0 |
|
3617 * @access private |
|
3618 * |
|
3619 * @return bool true|false |
|
3620 */ |
|
3621 function _device_can_upload() { |
|
3622 if ( ! wp_is_mobile() ) |
|
3623 return true; |
|
3624 |
|
3625 $ua = $_SERVER['HTTP_USER_AGENT']; |
|
3626 |
|
3627 if ( strpos($ua, 'iPhone') !== false |
|
3628 || strpos($ua, 'iPad') !== false |
|
3629 || strpos($ua, 'iPod') !== false ) { |
|
3630 return preg_match( '#OS ([\d_]+) like Mac OS X#', $ua, $version ) && version_compare( $version[1], '6', '>=' ); |
|
3631 } else { |
|
3632 return true; |
|
3633 } |
|
3634 } |
|
3635 |