wp/wp-includes/functions.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Main WordPress API
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
require( ABSPATH . WPINC . '/option.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    11
 * Convert given date string into a different format.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * $format should be either a PHP date format string, e.g. 'U' for a Unix
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * timestamp, or 'G' for a Unix timestamp assuming that $date is GMT.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * If $translate is true then the given date and format string will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 * be passed to date_i18n() for translation.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    21
 * @param string $format    Format of the date to return.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    22
 * @param string $date      Date string to convert.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    23
 * @param bool   $translate Whether the return date should be translated. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
 * @return string|int|bool Formatted date string or Unix timestamp. False if $date is empty.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
function mysql2date( $format, $date, $translate = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
	if ( empty( $date ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	if ( 'G' == $format )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
		return strtotime( $date . ' +0000' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
	$i = strtotime( $date );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
	if ( 'U' == $format )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
		return $i;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	if ( $translate )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
		return date_i18n( $format, $i );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
		return date( $format, $i );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
 * Retrieve the current time based on specified type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
 * The 'mysql' type will return the time in the format for MySQL DATETIME field.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
 * The 'timestamp' type will return the current timestamp.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    49
 * Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d').
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
 * If $gmt is set to either '1' or 'true', then both types will use GMT time.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
 * if $gmt is false, the output is adjusted with the GMT offset in the WordPress option.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    56
 * @param string   $type Type of time to retrieve. Accepts 'mysql', 'timestamp', or PHP date
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    57
 *                       format string (e.g. 'Y-m-d').
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    58
 * @param int|bool $gmt  Optional. Whether to use GMT timezone. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    59
 * @return int|string Integer if $type is 'timestamp', string otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
function current_time( $type, $gmt = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	switch ( $type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
		case 'mysql':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
			return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
		case 'timestamp':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
			return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
		default:
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
			return ( $gmt ) ? date( $type ) : date( $type, time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
 * Retrieve the date in localized format, based on timestamp.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
 * If the locale specifies the locale month and weekday, then the locale will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
 * take over the format for the date. If it isn't, then the date format string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
 * will be used instead.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
 * @param string   $dateformatstring Format to display the date.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
 * @param bool|int $unixtimestamp    Optional. Unix timestamp. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    83
 * @param bool     $gmt              Optional. Whether to use GMT timezone. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
 * @return string The date, translated if locale specifies it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	global $wp_locale;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
	$i = $unixtimestamp;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
	if ( false === $i ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
		if ( ! $gmt )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
			$i = current_time( 'timestamp' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
			$i = time();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
		// we should not let date() interfere with our
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
		// specially computed timestamp
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
		$gmt = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   101
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   102
	 * Store original value for language with untypical grammars.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   103
	 * See https://core.trac.wordpress.org/ticket/9396
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   104
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
	$req_format = $dateformatstring;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
	$datefunc = $gmt? 'gmdate' : 'date';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
	if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
		$datemonth = $wp_locale->get_month( $datefunc( 'm', $i ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
		$datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
		$dateweekday = $wp_locale->get_weekday( $datefunc( 'w', $i ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
		$dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
		$datemeridiem = $wp_locale->get_meridiem( $datefunc( 'a', $i ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
		$datemeridiem_capital = $wp_locale->get_meridiem( $datefunc( 'A', $i ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
		$dateformatstring = ' '.$dateformatstring;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
		$dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
		$dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
		$dateformatstring = preg_replace( "/([^\\\])l/", "\\1" . backslashit( $dateweekday ), $dateformatstring );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
		$dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
		$dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
		$dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
		$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
	$timezone_formats = array( 'P', 'I', 'O', 'T', 'Z', 'e' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
	$timezone_formats_re = implode( '|', $timezone_formats );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
	if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
		$timezone_string = get_option( 'timezone_string' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
		if ( $timezone_string ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
			$timezone_object = timezone_open( $timezone_string );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
			$date_object = date_create( null, $timezone_object );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
			foreach( $timezone_formats as $timezone_format ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
				if ( false !== strpos( $dateformatstring, $timezone_format ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
					$formatted = date_format( $date_object, $timezone_format );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
					$dateformatstring = ' '.$dateformatstring;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
					$dateformatstring = preg_replace( "/([^\\\])$timezone_format/", "\\1" . backslashit( $formatted ), $dateformatstring );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
					$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
	$j = @$datefunc( $dateformatstring, $i );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   144
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   145
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   146
	 * Filter the date formatted based on the locale.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   147
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   148
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   150
	 * @param string $j          Formatted date string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   151
	 * @param string $req_format Format to display the date.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
	 * @param int    $i          Unix timestamp.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   153
	 * @param bool   $gmt        Whether to convert to GMT for time. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
	$j = apply_filters( 'date_i18n', $j, $req_format, $i, $gmt );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
	return $j;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
 * Convert integer number to format based on the locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   164
 * @param int $number   The number to convert based on locale.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   165
 * @param int $decimals Optional. Precision of the number of decimal places. Default 0.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
 * @return string Converted number in string format.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
function number_format_i18n( $number, $decimals = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
	global $wp_locale;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
	$formatted = number_format( $number, absint( $decimals ), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   171
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   172
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   173
	 * Filter the number formatted based on the locale.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
	 * @since  2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   176
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   177
	 * @param string $formatted Converted number in string format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   178
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
	return apply_filters( 'number_format_i18n', $formatted );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
 * Convert number of bytes largest unit bytes will fit into.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   185
 * It is easier to read 1 kB than 1024 bytes and 1 MB than 1048576 bytes. Converts
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
 * number of bytes to human readable number by taking the number of that unit
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
 * that the bytes will go into it. Supports TB value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
 * Please note that integers in PHP are limited to 32 bits, unless they are on
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
 * 64 bit architecture, then they have 64 bit size. If you need to place the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
 * larger size then what PHP integer type will hold, then use a string. It will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
 * be converted to a double, which should always have 64 bit length.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
 * Technically the correct unit names for powers of 1024 are KiB, MiB etc.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   198
 * @param int|string $bytes    Number of bytes. Note max integer size for integers.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
 * @param int        $decimals Optional. Precision of number of decimal places. Default 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   200
 * @return string|false False on failure. Number string on success.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
function size_format( $bytes, $decimals = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
	$quant = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
		// ========================= Origin ====
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
		'TB' => 1099511627776,  // pow( 1024, 4)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
		'GB' => 1073741824,     // pow( 1024, 3)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
		'MB' => 1048576,        // pow( 1024, 2)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
		'kB' => 1024,           // pow( 1024, 1)
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   209
		'B'  => 1,              // pow( 1024, 0)
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
	);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   211
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   212
	foreach ( $quant as $unit => $mag ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   213
		if ( doubleval( $bytes ) >= $mag ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
			return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   215
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   216
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   222
 * Get the week start and end from the datetime or date string from MySQL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   226
 * @param string     $mysqlstring   Date or datetime field type from MySQL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
 * @param int|string $start_of_week Optional. Start of the week as an integer. Default empty string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
 * @return array Keys are 'start' and 'end'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
function get_weekstartend( $mysqlstring, $start_of_week = '' ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   231
	// MySQL string year.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   232
	$my = substr( $mysqlstring, 0, 4 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   233
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   234
	// MySQL string month.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   235
	$mm = substr( $mysqlstring, 8, 2 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   236
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   237
	// MySQL string day.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   238
	$md = substr( $mysqlstring, 5, 2 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   239
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   240
	// The timestamp for MySQL string day.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   241
	$day = mktime( 0, 0, 0, $md, $mm, $my );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   242
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   243
	// The day of the week from the timestamp.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   244
	$weekday = date( 'w', $day );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   245
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
	if ( !is_numeric($start_of_week) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
		$start_of_week = get_option( 'start_of_week' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
	if ( $weekday < $start_of_week )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
		$weekday += 7;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   252
	// The most recent week start day on or before $day.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   253
	$start = $day - DAY_IN_SECONDS * ( $weekday - $start_of_week );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   254
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   255
	// $start + 7 days - 1 second.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   256
	$end = $start + 7 * DAY_IN_SECONDS - 1;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
	return compact( 'start', 'end' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
 * Unserialize value only if it was serialized.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
 * @param string $original Maybe unserialized original, if is needed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
 * @return mixed Unserialized data can be any type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
function maybe_unserialize( $original ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
	if ( is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
		return @unserialize( $original );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
	return $original;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
 * Check value to find if it was serialized.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
 * If $data is not an string, then returned value will always be false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
 * Serialized data is always a string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
 * @since 2.0.5
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   282
 * @param string $data   Value to check to see if was serialized.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   283
 * @param bool   $strict Optional. Whether to be strict about the end of the string. Default true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
 * @return bool False if not serialized and true if it was.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
function is_serialized( $data, $strict = true ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   287
	// if it isn't a string, it isn't serialized.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   288
	if ( ! is_string( $data ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
	$data = trim( $data );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
 	if ( 'N;' == $data ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
		return true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   294
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   295
	if ( strlen( $data ) < 4 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   297
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   298
	if ( ':' !== $data[1] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   300
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
	if ( $strict ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   302
		$lastc = substr( $data, -1 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   303
		if ( ';' !== $lastc && '}' !== $lastc ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
			return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   305
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
		$semicolon = strpos( $data, ';' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
		$brace     = strpos( $data, '}' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
		// Either ; or } must exist.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
		if ( false === $semicolon && false === $brace )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
		// But neither must be in the first X characters.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
		if ( false !== $semicolon && $semicolon < 3 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
		if ( false !== $brace && $brace < 4 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
	$token = $data[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
	switch ( $token ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
		case 's' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
			if ( $strict ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   322
				if ( '"' !== substr( $data, -2, 1 ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
					return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   324
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
			} elseif ( false === strpos( $data, '"' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
			// or else fall through
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
		case 'a' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
		case 'O' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
			return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
		case 'b' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
		case 'i' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
		case 'd' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
			$end = $strict ? '$' : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
			return (bool) preg_match( "/^{$token}:[0-9.E-]+;$end/", $data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
 * Check whether serialized data is of string type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
 * @since 2.0.5
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   346
 * @param string $data Serialized data.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
 * @return bool False if not a serialized string, true if it is.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
function is_serialized_string( $data ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   350
	// if it isn't a string, it isn't a serialized string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   351
	if ( ! is_string( $data ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   353
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
	$data = trim( $data );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   355
	if ( strlen( $data ) < 4 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   357
	} elseif ( ':' !== $data[1] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   359
	} elseif ( ';' !== substr( $data, -1 ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   361
	} elseif ( $data[0] !== 's' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   363
	} elseif ( '"' !== substr( $data, -2, 1 ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
		return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   365
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
		return true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   367
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
 * Serialize data, if needed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
 * @since 2.0.5
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   375
 * @param string|array|object $data Data that might be serialized.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
 * @return mixed A scalar data
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
function maybe_serialize( $data ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
	if ( is_array( $data ) || is_object( $data ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
		return serialize( $data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
	// Double serialization is required for backward compatibility.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   383
	// See https://core.trac.wordpress.org/ticket/12930
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
	if ( is_serialized( $data, false ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
		return serialize( $data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
	return $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
 * Retrieve post title from XMLRPC XML.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
 * If the title element is not part of the XML, then the default post title from
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
 * the $post_default_title will be used instead.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   398
 * @global string $post_default_title Default XML-RPC post title.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
 * @param string $content XMLRPC XML Request content
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
 * @return string Post title
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
function xmlrpc_getposttitle( $content ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
	global $post_default_title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
	if ( preg_match( '/<title>(.+?)<\/title>/is', $content, $matchtitle ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
		$post_title = $matchtitle[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
		$post_title = $post_default_title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
	return $post_title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
 * Retrieve the post category or categories from XMLRPC XML.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
 * If the category element is not found, then the default post category will be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
 * used. The return type then would be what $post_default_category. If the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
 * category is found, then it will always be an array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   422
 * @global string $post_default_category Default XML-RPC post category.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
 * @param string $content XMLRPC XML Request content
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
 * @return string|array List of categories or category name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
function xmlrpc_getpostcategory( $content ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
	global $post_default_category;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
	if ( preg_match( '/<category>(.+?)<\/category>/is', $content, $matchcat ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
		$post_category = trim( $matchcat[1], ',' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
		$post_category = explode( ',', $post_category );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
		$post_category = $post_default_category;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
	return $post_category;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
 * XMLRPC XML content without title and category elements.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   443
 * @param string $content XML-RPC XML Request content.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
 * @return string XMLRPC XML Request content without title and category elements.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
function xmlrpc_removepostdata( $content ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
	$content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
	$content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
	$content = trim( $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
	return $content;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   454
 * Use RegEx to extract URLs from arbitrary content.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   458
 * @param string $content Content to extract URLs from.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   459
 * @return array URLs found in passed string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
function wp_extract_urls( $content ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
	preg_match_all(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   463
		"#([\"']?)("
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   464
			. "(?:([\w-]+:)?//?)"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   465
			. "[^\s()<>]+"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   466
			. "[.]"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   467
			. "(?:"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   468
				. "\([\w\d]+\)|"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   469
				. "(?:"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   470
					. "[^`!()\[\]{};:'\".,<>«»“”‘’\s]|"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   471
					. "(?:[:]\d+)?/?"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   472
				. ")+"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   473
			. ")"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   474
		. ")\\1#",
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
		$content,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
		$post_links
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
	$post_links = array_unique( array_map( 'html_entity_decode', $post_links[2] ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
	return array_values( $post_links );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
 * Check content for video and audio links to add as enclosures.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
 * Will not add enclosures that have already been added and will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
 * remove enclosures that are no longer in the post. This is called as
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
 * pingbacks and trackbacks.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   493
 * @see $wpdb
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   494
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   495
 * @param string $content Post Content.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   496
 * @param int $post_ID Post ID.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
function do_enclose( $content, $post_ID ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
	//TODO: Tidy this ghetto code up and make the debug code optional
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
	include_once( ABSPATH . WPINC . '/class-IXR.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
	$post_links = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
	$pung = get_enclosed( $post_ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
	$post_links_temp = wp_extract_urls( $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
	foreach ( $pung as $link_test ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
		if ( ! in_array( $link_test, $post_links_temp ) ) { // link no longer in post
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   512
			$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, $wpdb->esc_like( $link_test ) . '%') );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
			foreach ( $mids as $mid )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
				delete_metadata_by_mid( 'post', $mid );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
	foreach ( (array) $post_links_temp as $link_test ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
		if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
			$test = @parse_url( $link_test );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
			if ( false === $test )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
			if ( isset( $test['query'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
				$post_links[] = $link_test;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
			elseif ( isset($test['path']) && ( $test['path'] != '/' ) &&  ($test['path'] != '' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
				$post_links[] = $link_test;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
	foreach ( (array) $post_links as $url ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   531
		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, $wpdb->esc_like( $url ) . '%' ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
			if ( $headers = wp_get_http_headers( $url) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
				$len = isset( $headers['content-length'] ) ? (int) $headers['content-length'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
				$type = isset( $headers['content-type'] ) ? $headers['content-type'] : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
				$allowed_types = array( 'video', 'audio' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
				// Check to see if we can figure out the mime type from
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
				// the extension
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
				$url_parts = @parse_url( $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
				if ( false !== $url_parts ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
					$extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
					if ( !empty( $extension ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
						foreach ( wp_get_mime_types() as $exts => $mime ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
							if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
								$type = $mime;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
								break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
							}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
				if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
					add_post_meta( $post_ID, 'enclosure', "$url\n$len\n$mime\n" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
 * Perform a HTTP HEAD or GET request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
 * If $file_path is a writable filename, this will do a GET request and write
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
 * the file to that path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   569
 * @param string      $url       URL to fetch.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   570
 * @param string|bool $file_path Optional. File path to write request to. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   571
 * @param int         $red       Optional. The number of Redirects followed, Upon 5 being hit,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   572
 *                               returns false. Default 1.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
 * @return bool|string False on failure and string of headers if HEAD request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
function wp_get_http( $url, $file_path = false, $red = 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
	@set_time_limit( 60 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
	if ( $red > 5 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
	$options = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
	$options['redirection'] = 5;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
	if ( false == $file_path )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
		$options['method'] = 'HEAD';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
		$options['method'] = 'GET';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
	$response = wp_safe_remote_request( $url, $options );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
	if ( is_wp_error( $response ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
	$headers = wp_remote_retrieve_headers( $response );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
	$headers['response'] = wp_remote_retrieve_response_code( $response );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
	// WP_HTTP no longer follows redirects for HEAD requests.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
	if ( 'HEAD' == $options['method'] && in_array($headers['response'], array(301, 302)) && isset( $headers['location'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
		return wp_get_http( $headers['location'], $file_path, ++$red );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
	if ( false == $file_path )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
		return $headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
	// GET request - write it to the supplied filename
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
	$out_fp = fopen($file_path, 'w');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
	if ( !$out_fp )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
		return $headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
	fwrite( $out_fp,  wp_remote_retrieve_body( $response ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
	fclose($out_fp);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
	clearstatcache();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
	return $headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
 * Retrieve HTTP Headers from URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
 * @since 1.5.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   622
 * @param string $url        URL to retrieve HTTP headers from.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   623
 * @param bool   $deprecated Not Used.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
 * @return bool|string False on failure, headers on success.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
function wp_get_http_headers( $url, $deprecated = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
	if ( !empty( $deprecated ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
		_deprecated_argument( __FUNCTION__, '2.7' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
	$response = wp_safe_remote_head( $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
	if ( is_wp_error( $response ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
	return wp_remote_retrieve_headers( $response );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   639
 * Whether the publish date of the current post in the loop is different from the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   640
 * publish date of the previous post in the loop.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
 * @since 0.71
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   643
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   644
 * @global string $currentday  The day of the current post in the loop.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   645
 * @global string $previousday The day of the previous post in the loop.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
 * @return int 1 when new day, 0 if not a new day.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
function is_new_day() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
	global $currentday, $previousday;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
	if ( $currentday != $previousday )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
		return 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
		return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
 * Build URL query based on an associative and, or indexed array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
 * This is a convenient function for easily building url queries. It sets the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
 * separator to '&' and uses _http_build_query() function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   663
 * @since 2.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   664
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
 * @see _http_build_query() Used to build the query
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   666
 * @see http://us2.php.net/manual/en/function.http-build-query.php for more on what
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
 *		http_build_query() does.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
 * @param array $data URL-encode key/value pairs.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   670
 * @return string URL-encoded string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
function build_query( $data ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
	return _http_build_query( $data, null, '&', '', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   676
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   677
 * From php.net (modified by Mark Jaquith to behave like the native PHP5 function).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   678
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   679
 * @since 3.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   680
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   681
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   682
 * @see http://us1.php.net/manual/en/function.http-build-query.php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   683
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   684
 * @param array|object  $data       An array or object of data. Converted to array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   685
 * @param string        $prefix     Optional. Numeric index. If set, start parameter numbering with it.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   686
 *                                  Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   687
 * @param string        $sep        Optional. Argument separator; defaults to 'arg_separator.output'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   688
 *                                  Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   689
 * @param string        $key        Optional. Used to prefix key name. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   690
 * @param bool          $urlencode  Optional. Whether to use urlencode() in the result. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   691
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   692
 * @return string The query string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   693
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   694
function _http_build_query( $data, $prefix = null, $sep = null, $key = '', $urlencode = true ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
	$ret = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
	foreach ( (array) $data as $k => $v ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
		if ( $urlencode)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
			$k = urlencode($k);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
		if ( is_int($k) && $prefix != null )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
			$k = $prefix.$k;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
		if ( !empty($key) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
			$k = $key . '%5B' . $k . '%5D';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
		if ( $v === null )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
			continue;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   706
		elseif ( $v === false )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
			$v = '0';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
		if ( is_array($v) || is_object($v) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
			array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
		elseif ( $urlencode )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
			array_push($ret, $k.'='.urlencode($v));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
			array_push($ret, $k.'='.$v);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
	if ( null === $sep )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
		$sep = ini_get('arg_separator.output');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
	return implode($sep, $ret);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
 * Retrieve a modified URL query string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
 * You can rebuild the URL and append a new query variable to the URL query by
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
 * using this function. You can also retrieve the full URL with query data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
 * Adding a single key & value or an associative array. Setting a key value to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
 * an empty string removes the key. Omitting oldquery_or_uri uses the $_SERVER
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
 * value. Additional values provided are expected to be encoded appropriately
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
 * with urlencode() or rawurlencode().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   736
 * @param string|array $param1 Either newkey or an associative_array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   737
 * @param string       $param2 Either newvalue or oldquery or URI.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   738
 * @param string       $param3 Optional. Old query or URI.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
 * @return string New URL query string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
function add_query_arg() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
	$args = func_get_args();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
	if ( is_array( $args[0] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
		if ( count( $args ) < 2 || false === $args[1] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
			$uri = $_SERVER['REQUEST_URI'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
			$uri = $args[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
		if ( count( $args ) < 3 || false === $args[2] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
			$uri = $_SERVER['REQUEST_URI'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
			$uri = $args[2];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
	if ( $frag = strstr( $uri, '#' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
		$uri = substr( $uri, 0, -strlen( $frag ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
		$frag = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
	if ( 0 === stripos( $uri, 'http://' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
		$protocol = 'http://';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
		$uri = substr( $uri, 7 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
	} elseif ( 0 === stripos( $uri, 'https://' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
		$protocol = 'https://';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
		$uri = substr( $uri, 8 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
		$protocol = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
	if ( strpos( $uri, '?' ) !== false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
		list( $base, $query ) = explode( '?', $uri, 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
		$base .= '?';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
	} elseif ( $protocol || strpos( $uri, '=' ) === false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
		$base = $uri . '?';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
		$query = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
		$base = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
		$query = $uri;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
	wp_parse_str( $query, $qs );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
	$qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
	if ( is_array( $args[0] ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   784
		foreach ( $args[0] as $k => $v ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   785
			$qs[ $k ] = $v;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   786
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
		$qs[ $args[0] ] = $args[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
	foreach ( $qs as $k => $v ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
		if ( $v === false )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
			unset( $qs[$k] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
	$ret = build_query( $qs );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
	$ret = trim( $ret, '?' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
	$ret = preg_replace( '#=(&|$)#', '$1', $ret );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
	$ret = $protocol . $base . $ret . $frag;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
	$ret = rtrim( $ret, '?' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
	return $ret;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
 * Removes an item or list from the query string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   809
 * @param string|array $key   Query key or keys to remove.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   810
 * @param bool|string  $query Optional. When false uses the $_SERVER value. Default false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
 * @return string New URL query string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   813
function remove_query_arg( $key, $query = false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
	if ( is_array( $key ) ) { // removing multiple keys
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
		foreach ( $key as $k )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
			$query = add_query_arg( $k, false, $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
		return $query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
	return add_query_arg( $key, false, $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   822
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
 * Walks the array while sanitizing the contents.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
 * @param array $array Array to walk while sanitizing contents.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
 * @return array Sanitized $array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
function add_magic_quotes( $array ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
	foreach ( (array) $array as $k => $v ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
		if ( is_array( $v ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
			$array[$k] = add_magic_quotes( $v );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
			$array[$k] = addslashes( $v );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   836
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
	return $array;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
 * HTTP request for URI to retrieve content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
 * @since 1.5.1
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   845
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   846
 * @see wp_safe_remote_get()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
 * @param string $uri URI/URL of web page to retrieve.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   849
 * @return false|string HTTP content. False on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
function wp_remote_fopen( $uri ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
	$parsed_url = @parse_url( $uri );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
	if ( !$parsed_url || !is_array( $parsed_url ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
	$options = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
	$options['timeout'] = 10;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
	$response = wp_safe_remote_get( $uri, $options );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
	if ( is_wp_error( $response ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
	return wp_remote_retrieve_body( $response );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
 * Set up the WordPress query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   872
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   873
 * @param string|array $query_vars Default WP_Query arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
function wp( $query_vars = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
	global $wp, $wp_query, $wp_the_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
	$wp->main( $query_vars );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
	if ( !isset($wp_the_query) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
		$wp_the_query = $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
 * Retrieve the description for the HTTP status.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
 * @param int $code HTTP status code.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
 * @return string Empty string if not found, or description if found.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
function get_status_header_desc( $code ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
	global $wp_header_to_desc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
	$code = absint( $code );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
	if ( !isset( $wp_header_to_desc ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
		$wp_header_to_desc = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
			100 => 'Continue',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
			101 => 'Switching Protocols',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
			102 => 'Processing',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
			200 => 'OK',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
			201 => 'Created',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   904
			202 => 'Accepted',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   905
			203 => 'Non-Authoritative Information',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
			204 => 'No Content',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
			205 => 'Reset Content',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
			206 => 'Partial Content',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
			207 => 'Multi-Status',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
			226 => 'IM Used',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
			300 => 'Multiple Choices',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
			301 => 'Moved Permanently',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
			302 => 'Found',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
			303 => 'See Other',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
			304 => 'Not Modified',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
			305 => 'Use Proxy',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
			306 => 'Reserved',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
			307 => 'Temporary Redirect',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
			400 => 'Bad Request',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
			401 => 'Unauthorized',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
			402 => 'Payment Required',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
			403 => 'Forbidden',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
			404 => 'Not Found',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
			405 => 'Method Not Allowed',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
			406 => 'Not Acceptable',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
			407 => 'Proxy Authentication Required',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
			408 => 'Request Timeout',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
			409 => 'Conflict',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
			410 => 'Gone',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
			411 => 'Length Required',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
			412 => 'Precondition Failed',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
			413 => 'Request Entity Too Large',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
			414 => 'Request-URI Too Long',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
			415 => 'Unsupported Media Type',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
			416 => 'Requested Range Not Satisfiable',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
			417 => 'Expectation Failed',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   939
			418 => 'I\'m a teapot',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
			422 => 'Unprocessable Entity',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
			423 => 'Locked',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
			424 => 'Failed Dependency',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
			426 => 'Upgrade Required',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   944
			428 => 'Precondition Required',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   945
			429 => 'Too Many Requests',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   946
			431 => 'Request Header Fields Too Large',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
			500 => 'Internal Server Error',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
			501 => 'Not Implemented',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
			502 => 'Bad Gateway',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
			503 => 'Service Unavailable',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
			504 => 'Gateway Timeout',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
			505 => 'HTTP Version Not Supported',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
			506 => 'Variant Also Negotiates',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
			507 => 'Insufficient Storage',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   956
			510 => 'Not Extended',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   957
			511 => 'Network Authentication Required',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
	if ( isset( $wp_header_to_desc[$code] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
		return $wp_header_to_desc[$code];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
		return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
 * Set HTTP status header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
 * @since 2.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   971
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   972
 * @see get_status_header_desc()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   973
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   974
 * @param int $code HTTP status code.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   976
function status_header( $code ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   977
	$description = get_status_header_desc( $code );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   978
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   979
	if ( empty( $description ) )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   980
		return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   981
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   982
	$protocol = $_SERVER['SERVER_PROTOCOL'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
	if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
		$protocol = 'HTTP/1.0';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   985
	$status_header = "$protocol $code $description";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   986
	if ( function_exists( 'apply_filters' ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   987
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   988
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   989
		 * Filter an HTTP status header.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   990
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   991
		 * @since 2.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   992
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   993
		 * @param string $status_header HTTP status header.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   994
		 * @param int    $code          HTTP status code.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   995
		 * @param string $description   Description for the status code.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   996
		 * @param string $protocol      Server protocol.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   997
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   998
		$status_header = apply_filters( 'status_header', $status_header, $code, $description, $protocol );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   999
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1000
	@header( $status_header, true, $code );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1004
 * Get the header information to prevent caching.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1005
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1006
 * The several different headers cover the different ways cache prevention
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1007
 * is handled by different browsers
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
 * @return array The associative array of header names and field values.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1012
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1013
function wp_get_nocache_headers() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
	$headers = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1015
		'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
		'Cache-Control' => 'no-cache, must-revalidate, max-age=0',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
		'Pragma' => 'no-cache',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
	if ( function_exists('apply_filters') ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1021
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1022
		 * Filter the cache-controlling headers.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1023
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1024
		 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1025
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1026
		 * @see wp_get_nocache_headers()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1027
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1028
		 * @param array $headers {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1029
		 *     Header names and field values.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1030
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1031
		 *     @type string $Expires       Expires header.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1032
		 *     @type string $Cache-Control Cache-Control header.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1033
		 *     @type string $Pragma        Pragma header.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1034
		 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1035
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1036
		$headers = (array) apply_filters( 'nocache_headers', $headers );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1037
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1038
	$headers['Last-Modified'] = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1039
	return $headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1040
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1041
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1042
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1043
 * Set the headers to prevent caching for the different browsers.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1044
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1045
 * Different browsers support different nocache headers, so several
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1046
 * headers must be sent so that all of them get the point that no
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1047
 * caching should occur.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1048
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1049
 * @since 2.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1050
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1051
 * @see wp_get_nocache_headers()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1052
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1053
function nocache_headers() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1054
	$headers = wp_get_nocache_headers();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1055
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1056
	unset( $headers['Last-Modified'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1057
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1058
	// In PHP 5.3+, make sure we are not sending a Last-Modified header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
	if ( function_exists( 'header_remove' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1060
		@header_remove( 'Last-Modified' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1061
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1062
		// In PHP 5.2, send an empty Last-Modified header, but only as a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1063
		// last resort to override a header already sent. #WP23021
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1064
		foreach ( headers_list() as $header ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1065
			if ( 0 === stripos( $header, 'Last-Modified' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1066
				$headers['Last-Modified'] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1067
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1068
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1069
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1070
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1071
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1072
	foreach( $headers as $name => $field_value )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1073
		@header("{$name}: {$field_value}");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1074
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1075
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1076
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1077
 * Set the headers for caching for 10 days with JavaScript content type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1078
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1079
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1080
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1081
function cache_javascript_headers() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1082
	$expiresOffset = 10 * DAY_IN_SECONDS;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1083
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1084
	header( "Content-Type: text/javascript; charset=" . get_bloginfo( 'charset' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1085
	header( "Vary: Accept-Encoding" ); // Handle proxies
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1086
	header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . " GMT" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1087
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1088
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1089
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1090
 * Retrieve the number of database queries during the WordPress execution.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1091
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1092
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1093
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1094
 * @global wpdb $wpdb WordPress database abstraction object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1095
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1096
 * @return int Number of database queries.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1097
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1098
function get_num_queries() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1099
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1100
	return $wpdb->num_queries;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1101
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1102
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1104
 * Whether input is yes or no.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1105
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1106
 * Must be 'y' to be true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1107
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1108
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1109
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1110
 * @param string $yn Character string containing either 'y' (yes) or 'n' (no).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1111
 * @return bool True if yes, false on anything else.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1112
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1113
function bool_from_yn( $yn ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1114
	return ( strtolower( $yn ) == 'y' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1115
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1116
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1117
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1118
 * Load the feed template from the use of an action hook.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1119
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1120
 * If the feed action does not have a hook, then the function will die with a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
 * message telling the visitor that the feed is not valid.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1122
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1123
 * It is better to only have one hook for each feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1124
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1125
 * @since 2.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1126
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1127
 * @uses $wp_query Used to tell if the use a comment feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1128
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1129
function do_feed() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1130
	global $wp_query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1131
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1132
	$feed = get_query_var( 'feed' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1133
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1134
	// Remove the pad, if present.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1135
	$feed = preg_replace( '/^_+/', '', $feed );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1137
	if ( $feed == '' || $feed == 'feed' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1138
		$feed = get_default_feed();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1139
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1140
	$hook = 'do_feed_' . $feed;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1141
	if ( ! has_action( $hook ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1142
		wp_die( __( 'ERROR: This is not a valid feed template.' ), '', array( 'response' => 404 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1143
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1144
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1145
	 * Fires once the given feed is loaded.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1146
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1147
	 * The dynamic hook name, $hook, refers to the feed name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1148
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1149
	 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1150
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1151
	 * @param bool $is_comment_feed Whether the feed is a comment feed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1152
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1153
	do_action( $hook, $wp_query->is_comment_feed );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1154
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1155
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1156
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
 * Load the RDF RSS 0.91 Feed template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
 * @since 2.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1160
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1161
 * @see load_template()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1162
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
function do_feed_rdf() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1164
	load_template( ABSPATH . WPINC . '/feed-rdf.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1165
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1167
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1168
 * Load the RSS 1.0 Feed Template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1169
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
 * @since 2.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1171
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1172
 * @see load_template()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1173
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1174
function do_feed_rss() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1175
	load_template( ABSPATH . WPINC . '/feed-rss.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1176
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1177
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1179
 * Load either the RSS2 comment feed or the RSS2 posts feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1181
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1182
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1183
 * @see load_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1184
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
 * @param bool $for_comments True for the comment feed, false for normal feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1186
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1187
function do_feed_rss2( $for_comments ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1188
	if ( $for_comments )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1189
		load_template( ABSPATH . WPINC . '/feed-rss2-comments.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1190
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
		load_template( ABSPATH . WPINC . '/feed-rss2.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1192
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1194
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
 * Load either Atom comment feed or Atom posts feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1197
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1199
 * @see load_template()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1200
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1201
 * @param bool $for_comments True for the comment feed, false for normal feed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1202
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1203
function do_feed_atom( $for_comments ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1204
	if ($for_comments)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1205
		load_template( ABSPATH . WPINC . '/feed-atom-comments.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1206
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1207
		load_template( ABSPATH . WPINC . '/feed-atom.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1209
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1210
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1211
 * Display the robots.txt file content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1212
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1213
 * The echo content should be with usage of the permalinks or for creating the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1214
 * robots.txt file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1215
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1216
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1217
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1218
function do_robots() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1219
	header( 'Content-Type: text/plain; charset=utf-8' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1220
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1221
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1222
	 * Fires when displaying the robots.txt file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1223
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1224
	 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1225
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1226
	do_action( 'do_robotstxt' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1227
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1228
	$output = "User-agent: *\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1229
	$public = get_option( 'blog_public' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1230
	if ( '0' == $public ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1231
		$output .= "Disallow: /\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1232
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1233
		$site_url = parse_url( site_url() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1234
		$path = ( !empty( $site_url['path'] ) ) ? $site_url['path'] : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1235
		$output .= "Disallow: $path/wp-admin/\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1236
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1237
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1238
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1239
	 * Filter the robots.txt output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1240
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1241
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1242
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1243
	 * @param string $output Robots.txt output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1244
	 * @param bool   $public Whether the site is considered "public".
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1245
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1246
	echo apply_filters( 'robots_txt', $output, $public );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1247
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1248
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1249
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1250
 * Test whether blog is already installed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1252
 * The cache will be checked first. If you have a cache plugin, which saves
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1253
 * the cache values, then this will work. If you use the default WordPress
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1254
 * cache, and the database goes away, then you might have problems.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1255
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1256
 * Checks for the 'siteurl' option for whether WordPress is installed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1257
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1258
 * @since 2.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1259
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1260
 * @global wpdb $wpdb WordPress database abstraction object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1261
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1262
 * @return bool Whether the blog is already installed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1263
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1264
function is_blog_installed() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1265
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1266
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1267
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1268
	 * Check cache first. If options table goes away and we have true
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1269
	 * cached, oh well.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1270
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1271
	if ( wp_cache_get( 'is_blog_installed' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1272
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1273
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1274
	$suppress = $wpdb->suppress_errors();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1275
	if ( ! defined( 'WP_INSTALLING' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1276
		$alloptions = wp_load_alloptions();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1277
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1278
	// If siteurl is not set to autoload, check it specifically
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1279
	if ( !isset( $alloptions['siteurl'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1280
		$installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1281
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1282
		$installed = $alloptions['siteurl'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1283
	$wpdb->suppress_errors( $suppress );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1284
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1285
	$installed = !empty( $installed );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1286
	wp_cache_set( 'is_blog_installed', $installed );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1287
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1288
	if ( $installed )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1289
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1290
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1291
	// If visiting repair.php, return true and let it take over.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1292
	if ( defined( 'WP_REPAIRING' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1293
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1294
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1295
	$suppress = $wpdb->suppress_errors();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1296
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1297
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1298
	 * Loop over the WP tables. If none exist, then scratch install is allowed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1299
	 * If one or more exist, suggest table repair since we got here because the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1300
	 * options table could not be accessed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1301
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1302
	$wp_tables = $wpdb->tables();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1303
	foreach ( $wp_tables as $table ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1304
		// The existence of custom user tables shouldn't suggest an insane state or prevent a clean install.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1305
		if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1306
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1307
		if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1308
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1309
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1310
		if ( ! $wpdb->get_results( "DESCRIBE $table;" ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1311
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1313
		// One or more tables exist. We are insane.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1314
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
		wp_load_translations_early();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1316
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1317
		// Die with a DB error.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
		$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' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
		dead_db();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1320
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1321
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1322
	$wpdb->suppress_errors( $suppress );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1323
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1324
	wp_cache_set( 'is_blog_installed', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1325
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1326
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1327
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1328
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1329
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1330
 * Retrieve URL with nonce added to URL query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1331
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1332
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1333
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1334
 * @param string     $actionurl URL to add nonce action.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1335
 * @param int|string $action    Optional. Nonce action name. Default -1.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1336
 * @param string     $name      Optional. Nonce name. Default '_wpnonce'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1337
 * @return string Escaped URL with nonce action added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1338
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1339
function wp_nonce_url( $actionurl, $action = -1, $name = '_wpnonce' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1340
	$actionurl = str_replace( '&amp;', '&', $actionurl );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1341
	return esc_html( add_query_arg( $name, wp_create_nonce( $action ), $actionurl ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1342
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1343
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1344
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1345
 * Retrieve or display nonce hidden field for forms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1346
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1347
 * The nonce field is used to validate that the contents of the form came from
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1348
 * the location on the current site and not somewhere else. The nonce does not
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1349
 * offer absolute protection, but should protect against most cases. It is very
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1350
 * important to use nonce field in forms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1351
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1352
 * The $action and $name are optional, but if you want to have better security,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1353
 * it is strongly suggested to set those two parameters. It is easier to just
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1354
 * call the function without any parameters, because validation of the nonce
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1355
 * doesn't require any parameters, but since crackers know what the default is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1356
 * it won't be difficult for them to find a way around your nonce and cause
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1357
 * damage.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1359
 * The input name will be whatever $name value you gave. The input value will be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1360
 * the nonce creation value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1361
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1362
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1363
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1364
 * @param int|string $action  Optional. Action name. Default -1.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1365
 * @param string     $name    Optional. Nonce name. Default '_wpnonce'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1366
 * @param bool       $referer Optional. Whether to set the referer field for validation. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1367
 * @param bool       $echo    Optional. Whether to display or return hidden form field. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1368
 * @return string Nonce field HTML markup.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1369
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1370
function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
	$name = esc_attr( $name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1372
	$nonce_field = '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1373
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1374
	if ( $referer )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1375
		$nonce_field .= wp_referer_field( false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1376
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1377
	if ( $echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1378
		echo $nonce_field;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1379
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1380
	return $nonce_field;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1381
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1382
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1383
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1384
 * Retrieve or display referer hidden field for forms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1385
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1386
 * The referer link is the current Request URI from the server super global. The
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1387
 * input name is '_wp_http_referer', in case you wanted to check manually.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1388
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1389
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1390
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1391
 * @param bool $echo Optional. Whether to echo or return the referer field. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1392
 * @return string Referer field HTML markup.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1393
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1394
function wp_referer_field( $echo = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1395
	$referer_field = '<input type="hidden" name="_wp_http_referer" value="'. esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '" />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1396
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1397
	if ( $echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1398
		echo $referer_field;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1399
	return $referer_field;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1400
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1401
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1402
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1403
 * Retrieve or display original referer hidden field for forms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1404
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1405
 * The input name is '_wp_original_http_referer' and will be either the same
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1406
 * value of wp_referer_field(), if that was posted already or it will be the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1407
 * current page, if it doesn't exist.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1408
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1409
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1410
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1411
 * @param bool   $echo         Optional. Whether to echo the original http referer. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1412
 * @param string $jump_back_to Optional. Can be 'previous' or page you want to jump back to.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1413
 *                             Default 'current'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1414
 * @return string Original referer field.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1415
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1416
function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1417
	if ( ! $ref = wp_get_original_referer() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1418
		$ref = 'previous' == $jump_back_to ? wp_get_referer() : wp_unslash( $_SERVER['REQUEST_URI'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1419
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1420
	$orig_referer_field = '<input type="hidden" name="_wp_original_http_referer" value="' . esc_attr( $ref ) . '" />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1421
	if ( $echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1422
		echo $orig_referer_field;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1423
	return $orig_referer_field;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1424
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1425
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1426
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1427
 * Retrieve referer from '_wp_http_referer' or HTTP referer.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1428
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1429
 * If it's the same as the current request URL, will return false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1430
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1431
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1432
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1433
 * @return false|string False on failure. Referer URL on success.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1434
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1435
function wp_get_referer() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1436
	if ( ! function_exists( 'wp_validate_redirect' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1437
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1438
	$ref = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1439
	if ( ! empty( $_REQUEST['_wp_http_referer'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1440
		$ref = wp_unslash( $_REQUEST['_wp_http_referer'] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1441
	elseif ( ! empty( $_SERVER['HTTP_REFERER'] ) )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1442
		$ref = wp_unslash( $_SERVER['HTTP_REFERER'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1443
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1444
	if ( $ref && $ref !== wp_unslash( $_SERVER['REQUEST_URI'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1445
		return wp_validate_redirect( $ref, false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1446
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1447
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1448
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1449
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1450
 * Retrieve original referer that was posted, if it exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1451
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1452
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1453
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1454
 * @return string|false False if no original referer or original referer if set.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1455
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1456
function wp_get_original_referer() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1457
	if ( ! empty( $_REQUEST['_wp_original_http_referer'] ) && function_exists( 'wp_validate_redirect' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1458
		return wp_validate_redirect( wp_unslash( $_REQUEST['_wp_original_http_referer'] ), false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1459
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1460
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1461
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1462
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1463
 * Recursive directory creation based on full path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1464
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1465
 * Will attempt to set permissions on folders.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1466
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1467
 * @since 2.0.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1468
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1469
 * @param string $target Full path to attempt to create.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1470
 * @return bool Whether the path was created. True if path already exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1471
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1472
function wp_mkdir_p( $target ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1473
	$wrapper = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1474
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1475
	// Strip the protocol.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1476
	if( wp_is_stream( $target ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1477
		list( $wrapper, $target ) = explode( '://', $target, 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1478
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1479
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1480
	// From php.net/mkdir user contributed notes.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1481
	$target = str_replace( '//', '/', $target );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1482
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1483
	// Put the wrapper back on the target.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1484
	if( $wrapper !== null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1485
		$target = $wrapper . '://' . $target;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1486
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1487
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1488
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1489
	 * Safe mode fails with a trailing slash under certain PHP versions.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1490
	 * Use rtrim() instead of untrailingslashit to avoid formatting.php dependency.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1491
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1492
	$target = rtrim($target, '/');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1493
	if ( empty($target) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1494
		$target = '/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1495
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1496
	if ( file_exists( $target ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1497
		return @is_dir( $target );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1498
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1499
	// We need to find the permissions of the parent folder that exists and inherit that.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1500
	$target_parent = dirname( $target );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1501
	while ( '.' != $target_parent && ! is_dir( $target_parent ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1502
		$target_parent = dirname( $target_parent );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1503
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1504
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1505
	// Get the permission bits.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1506
	if ( $stat = @stat( $target_parent ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1507
		$dir_perms = $stat['mode'] & 0007777;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1508
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1509
		$dir_perms = 0777;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1510
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1511
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1512
	if ( @mkdir( $target, $dir_perms, true ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1513
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1514
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1515
		 * If a umask is set that modifies $dir_perms, we'll have to re-set
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1516
		 * the $dir_perms correctly with chmod()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1517
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1518
		if ( $dir_perms != ( $dir_perms & ~umask() ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1519
			$folder_parts = explode( '/', substr( $target, strlen( $target_parent ) + 1 ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1520
			for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1521
				@chmod( $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1522
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1523
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1524
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1525
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1526
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1527
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1528
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1529
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1530
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1531
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1532
 * Test if a give filesystem path is absolute.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1533
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1534
 * For example, '/foo/bar', or 'c:\windows'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1535
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1536
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1537
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1538
 * @param string $path File path.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1539
 * @return bool True if path is absolute, false is not absolute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1540
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1541
function path_is_absolute( $path ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1542
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1543
	 * This is definitive if true but fails if $path does not exist or contains
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1544
	 * a symbolic link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1545
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1546
	if ( realpath($path) == $path )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1547
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1548
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1549
	if ( strlen($path) == 0 || $path[0] == '.' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1550
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1551
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1552
	// Windows allows absolute paths like this.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1553
	if ( preg_match('#^[a-zA-Z]:\\\\#', $path) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1554
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1555
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1556
	// A path starting with / or \ is absolute; anything else is relative.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1557
	return ( $path[0] == '/' || $path[0] == '\\' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1558
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1559
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1560
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1561
 * Join two filesystem paths together.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1562
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1563
 * For example, 'give me $path relative to $base'. If the $path is absolute,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1564
 * then it the full path is returned.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1565
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1566
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1567
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1568
 * @param string $base Base path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1569
 * @param string $path Path relative to $base.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1570
 * @return string The path with the base or absolute path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1571
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1572
function path_join( $base, $path ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1573
	if ( path_is_absolute($path) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1574
		return $path;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1575
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1576
	return rtrim($base, '/') . '/' . ltrim($path, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1577
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1578
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1579
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1580
 * Normalize a filesystem path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1581
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1582
 * Replaces backslashes with forward slashes for Windows systems, and ensures
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1583
 * no duplicate slashes exist.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1584
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1585
 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1586
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1587
 * @param string $path Path to normalize.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1588
 * @return string Normalized path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1589
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1590
function wp_normalize_path( $path ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1591
	$path = str_replace( '\\', '/', $path );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1592
	$path = preg_replace( '|/+|','/', $path );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1593
	return $path;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1594
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1595
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1596
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1597
 * Determine a writable directory for temporary files.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1598
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1599
 * Function's preference is the return value of sys_get_temp_dir(),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1600
 * followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1601
 * before finally defaulting to /tmp/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1602
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1603
 * In the event that this function does not find a writable location,
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1604
 * It may be overridden by the WP_TEMP_DIR constant in your wp-config.php file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1605
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1606
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1607
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1608
 * @return string Writable temporary directory.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1609
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1610
function get_temp_dir() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1611
	static $temp;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1612
	if ( defined('WP_TEMP_DIR') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1613
		return trailingslashit(WP_TEMP_DIR);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1614
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1615
	if ( $temp )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1616
		return trailingslashit( $temp );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1617
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1618
	if ( function_exists('sys_get_temp_dir') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1619
		$temp = sys_get_temp_dir();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1620
		if ( @is_dir( $temp ) && wp_is_writable( $temp ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1621
			return trailingslashit( $temp );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1622
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1623
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1624
	$temp = ini_get('upload_tmp_dir');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1625
	if ( @is_dir( $temp ) && wp_is_writable( $temp ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1626
		return trailingslashit( $temp );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1627
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1628
	$temp = WP_CONTENT_DIR . '/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1629
	if ( is_dir( $temp ) && wp_is_writable( $temp ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1630
		return $temp;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1631
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1632
	$temp = '/tmp/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1633
	return $temp;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1634
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1635
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1636
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1637
 * Determine if a directory is writable.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1638
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1639
 * This function is used to work around certain ACL issues in PHP primarily
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1640
 * affecting Windows Servers.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1641
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1642
 * @since 3.6.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1643
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1644
 * @see win_is_writable()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1645
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1646
 * @param string $path Path to check for write-ability.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1647
 * @return bool Whether the path is writable.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1648
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1649
function wp_is_writable( $path ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1650
	if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1651
		return win_is_writable( $path );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1652
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1653
		return @is_writable( $path );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1654
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1655
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1656
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1657
 * Workaround for Windows bug in is_writable() function
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1658
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1659
 * PHP has issues with Windows ACL's for determine if a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1660
 * directory is writable or not, this works around them by
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1661
 * checking the ability to open files rather than relying
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1662
 * upon PHP to interprate the OS ACL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1663
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1664
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1665
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1666
 * @see http://bugs.php.net/bug.php?id=27609
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1667
 * @see http://bugs.php.net/bug.php?id=30931
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1668
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1669
 * @param string $path Windows path to check for write-ability.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1670
 * @return bool Whether the path is writable.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1671
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1672
function win_is_writable( $path ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1673
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1674
	if ( $path[strlen( $path ) - 1] == '/' ) { // if it looks like a directory, check a random file within the directory
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1675
		return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1676
	} elseif ( is_dir( $path ) ) { // If it's a directory (and not a file) check a random file within the directory
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1677
		return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1678
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1679
	// check tmp file for read/write capabilities
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1680
	$should_delete_tmp_file = !file_exists( $path );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1681
	$f = @fopen( $path, 'a' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1682
	if ( $f === false )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1683
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1684
	fclose( $f );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1685
	if ( $should_delete_tmp_file )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1686
		unlink( $path );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1687
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1688
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1689
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1690
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1691
 * Get an array containing the current upload directory's path and url.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1692
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1693
 * Checks the 'upload_path' option, which should be from the web root folder,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1694
 * and if it isn't empty it will be used. If it is empty, then the path will be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1695
 * 'WP_CONTENT_DIR/uploads'. If the 'UPLOADS' constant is defined, then it will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1696
 * override the 'upload_path' option and 'WP_CONTENT_DIR/uploads' path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1697
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1698
 * The upload URL path is set either by the 'upload_url_path' option or by using
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1699
 * the 'WP_CONTENT_URL' constant and appending '/uploads' to the path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1700
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1701
 * If the 'uploads_use_yearmonth_folders' is set to true (checkbox if checked in
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1702
 * the administration settings panel), then the time will be used. The format
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1703
 * will be year first and then month.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1704
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1705
 * If the path couldn't be created, then an error will be returned with the key
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1706
 * 'error' containing the error message. The error suggests that the parent
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1707
 * directory is not writable by the server.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1708
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1709
 * On success, the returned array will have many indices:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1710
 * 'path' - base directory and sub directory or full path to upload directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1711
 * 'url' - base url and sub directory or absolute URL to upload directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1712
 * 'subdir' - sub directory if uploads use year/month folders option is on.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1713
 * 'basedir' - path without subdir.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1714
 * 'baseurl' - URL path without subdir.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1715
 * 'error' - set to false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1716
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1717
 * @since 2.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1718
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1719
 * @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1720
 * @return array See above for description.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1721
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1722
function wp_upload_dir( $time = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1723
	$siteurl = get_option( 'siteurl' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1724
	$upload_path = trim( get_option( 'upload_path' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1725
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1726
	if ( empty( $upload_path ) || 'wp-content/uploads' == $upload_path ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1727
		$dir = WP_CONTENT_DIR . '/uploads';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1728
	} elseif ( 0 !== strpos( $upload_path, ABSPATH ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1729
		// $dir is absolute, $upload_path is (maybe) relative to ABSPATH
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1730
		$dir = path_join( ABSPATH, $upload_path );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1731
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1732
		$dir = $upload_path;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1733
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1734
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1735
	if ( !$url = get_option( 'upload_url_path' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1736
		if ( empty($upload_path) || ( 'wp-content/uploads' == $upload_path ) || ( $upload_path == $dir ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1737
			$url = WP_CONTENT_URL . '/uploads';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1738
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1739
			$url = trailingslashit( $siteurl ) . $upload_path;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1740
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1741
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1742
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1743
	 * Honor the value of UPLOADS. This happens as long as ms-files rewriting is disabled.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1744
	 * We also sometimes obey UPLOADS when rewriting is enabled -- see the next block.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1745
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1746
	if ( defined( 'UPLOADS' ) && ! ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1747
		$dir = ABSPATH . UPLOADS;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1748
		$url = trailingslashit( $siteurl ) . UPLOADS;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1749
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1750
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1751
	// If multisite (and if not the main site in a post-MU network)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1752
	if ( is_multisite() && ! ( is_main_network() && is_main_site() && defined( 'MULTISITE' ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1753
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1754
		if ( ! get_site_option( 'ms_files_rewriting' ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1755
			/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1756
			 * If ms-files rewriting is disabled (networks created post-3.5), it is fairly
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1757
			 * straightforward: Append sites/%d if we're not on the main site (for post-MU
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1758
			 * networks). (The extra directory prevents a four-digit ID from conflicting with
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1759
			 * a year-based directory for the main site. But if a MU-era network has disabled
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1760
			 * ms-files rewriting manually, they don't need the extra directory, as they never
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1761
			 * had wp-content/uploads for the main site.)
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1762
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1763
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1764
			if ( defined( 'MULTISITE' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1765
				$ms_dir = '/sites/' . get_current_blog_id();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1766
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1767
				$ms_dir = '/' . get_current_blog_id();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1768
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1769
			$dir .= $ms_dir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1770
			$url .= $ms_dir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1771
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1772
		} elseif ( defined( 'UPLOADS' ) && ! ms_is_switched() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1773
			/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1774
			 * Handle the old-form ms-files.php rewriting if the network still has that enabled.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1775
			 * When ms-files rewriting is enabled, then we only listen to UPLOADS when:
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1776
			 * 1) We are not on the main site in a post-MU network, as wp-content/uploads is used
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1777
			 *    there, and
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1778
			 * 2) We are not switched, as ms_upload_constants() hardcodes these constants to reflect
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1779
			 *    the original blog ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1780
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1781
			 * Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1782
			 * (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1783
			 * as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1784
			 * rewriting in multisite, the resulting URL is /files. (#WP22702 for background.)
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1785
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1786
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1787
			if ( defined( 'BLOGUPLOADDIR' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1788
				$dir = untrailingslashit( BLOGUPLOADDIR );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1789
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1790
				$dir = ABSPATH . UPLOADS;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1791
			$url = trailingslashit( $siteurl ) . 'files';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1792
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1793
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1794
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1795
	$basedir = $dir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1796
	$baseurl = $url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1797
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1798
	$subdir = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1799
	if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1800
		// Generate the yearly and monthly dirs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1801
		if ( !$time )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1802
			$time = current_time( 'mysql' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1803
		$y = substr( $time, 0, 4 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1804
		$m = substr( $time, 5, 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1805
		$subdir = "/$y/$m";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1806
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1807
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1808
	$dir .= $subdir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1809
	$url .= $subdir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1810
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1811
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1812
	 * Filter the uploads directory data.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1813
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1814
	 * @since 2.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1815
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1816
	 * @param array $uploads Array of upload directory data with keys of 'path',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1817
	 *                       'url', 'subdir, 'basedir', and 'error'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1818
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1819
	$uploads = apply_filters( 'upload_dir',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1820
		array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1821
			'path'    => $dir,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1822
			'url'     => $url,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1823
			'subdir'  => $subdir,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1824
			'basedir' => $basedir,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1825
			'baseurl' => $baseurl,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1826
			'error'   => false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1827
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1828
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1829
	// Make sure we have an uploads directory.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1830
	if ( ! wp_mkdir_p( $uploads['path'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1831
		if ( 0 === strpos( $uploads['basedir'], ABSPATH ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1832
			$error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1833
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1834
			$error_path = basename( $uploads['basedir'] ) . $uploads['subdir'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1835
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1836
		$message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $error_path );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1837
		$uploads['error'] = $message;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1838
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1839
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1840
	return $uploads;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1841
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1842
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1843
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1844
 * Get a filename that is sanitized and unique for the given directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1845
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1846
 * If the filename is not unique, then a number will be added to the filename
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1847
 * before the extension, and will continue adding numbers until the filename is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1848
 * unique.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1849
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1850
 * The callback is passed three parameters, the first one is the directory, the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1851
 * second is the filename, and the third is the extension.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1852
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1853
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1854
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1855
 * @param string   $dir                      Directory.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1856
 * @param string   $filename                 File name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1857
 * @param callback $unique_filename_callback Callback. Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1858
 * @return string New filename, if given wasn't unique.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1859
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1860
function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1861
	// Sanitize the file name before we begin processing.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1862
	$filename = sanitize_file_name($filename);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1863
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1864
	// Separate the filename into a name and extension.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1865
	$info = pathinfo($filename);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1866
	$ext = !empty($info['extension']) ? '.' . $info['extension'] : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1867
	$name = basename($filename, $ext);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1868
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1869
	// Edge case: if file is named '.ext', treat as an empty name.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1870
	if ( $name === $ext )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1871
		$name = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1872
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1873
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1874
	 * Increment the file number until we have a unique file to save in $dir.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1875
	 * Use callback if supplied.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1876
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1877
	if ( $unique_filename_callback && is_callable( $unique_filename_callback ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1878
		$filename = call_user_func( $unique_filename_callback, $dir, $name, $ext );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1879
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1880
		$number = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1881
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1882
		// Change '.ext' to lower case.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1883
		if ( $ext && strtolower($ext) != $ext ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1884
			$ext2 = strtolower($ext);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1885
			$filename2 = preg_replace( '|' . preg_quote($ext) . '$|', $ext2, $filename );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1886
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1887
			// Check for both lower and upper case extension or image sub-sizes may be overwritten.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1888
			while ( file_exists($dir . "/$filename") || file_exists($dir . "/$filename2") ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1889
				$new_number = $number + 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1890
				$filename = str_replace( "$number$ext", "$new_number$ext", $filename );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1891
				$filename2 = str_replace( "$number$ext2", "$new_number$ext2", $filename2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1892
				$number = $new_number;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1893
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1894
			return $filename2;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1895
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1896
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1897
		while ( file_exists( $dir . "/$filename" ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1898
			if ( '' == "$number$ext" )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1899
				$filename = $filename . ++$number . $ext;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1900
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1901
				$filename = str_replace( "$number$ext", ++$number . $ext, $filename );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1902
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1903
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1904
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1905
	return $filename;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1906
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1907
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1908
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1909
 * Create a file in the upload folder with given content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1910
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1911
 * If there is an error, then the key 'error' will exist with the error message.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1912
 * If success, then the key 'file' will have the unique file path, the 'url' key
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1913
 * will have the link to the new file. and the 'error' key will be set to false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1914
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1915
 * This function will not move an uploaded file to the upload folder. It will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1916
 * create a new file with the content in $bits parameter. If you move the upload
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1917
 * file, read the content of the uploaded file, and then you can give the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1918
 * filename and content to this function, which will add it to the upload
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1919
 * folder.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1920
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1921
 * The permissions will be set on the new file automatically by this function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1922
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1923
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1924
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1925
 * @param string       $name       Filename.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1926
 * @param null|string  $deprecated Never used. Set to null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1927
 * @param mixed        $bits       File content
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1928
 * @param string       $time       Optional. Time formatted in 'yyyy/mm'. Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1929
 * @return array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1930
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1931
function wp_upload_bits( $name, $deprecated, $bits, $time = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1932
	if ( !empty( $deprecated ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1933
		_deprecated_argument( __FUNCTION__, '2.0' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1934
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1935
	if ( empty( $name ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1936
		return array( 'error' => __( 'Empty filename' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1937
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1938
	$wp_filetype = wp_check_filetype( $name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1939
	if ( ! $wp_filetype['ext'] && ! current_user_can( 'unfiltered_upload' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1940
		return array( 'error' => __( 'Invalid file type' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1941
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1942
	$upload = wp_upload_dir( $time );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1943
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1944
	if ( $upload['error'] !== false )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1945
		return $upload;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1946
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1947
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1948
	 * Filter whether to treat the upload bits as an error.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1949
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1950
	 * Passing a non-array to the filter will effectively short-circuit preparing
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1951
	 * the upload bits, returning that value instead.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1952
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1953
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1954
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1955
	 * @param mixed $upload_bits_error An array of upload bits data, or a non-array error to return.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1956
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1957
	$upload_bits_error = apply_filters( 'wp_upload_bits', array( 'name' => $name, 'bits' => $bits, 'time' => $time ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1958
	if ( !is_array( $upload_bits_error ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1959
		$upload[ 'error' ] = $upload_bits_error;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1960
		return $upload;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1961
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1962
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1963
	$filename = wp_unique_filename( $upload['path'], $name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1964
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1965
	$new_file = $upload['path'] . "/$filename";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1966
	if ( ! wp_mkdir_p( dirname( $new_file ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1967
		if ( 0 === strpos( $upload['basedir'], ABSPATH ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1968
			$error_path = str_replace( ABSPATH, '', $upload['basedir'] ) . $upload['subdir'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1969
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1970
			$error_path = basename( $upload['basedir'] ) . $upload['subdir'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1971
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1972
		$message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $error_path );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1973
		return array( 'error' => $message );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1974
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1975
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1976
	$ifp = @ fopen( $new_file, 'wb' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1977
	if ( ! $ifp )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1978
		return array( 'error' => sprintf( __( 'Could not write file %s' ), $new_file ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1979
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1980
	@fwrite( $ifp, $bits );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1981
	fclose( $ifp );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1982
	clearstatcache();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1983
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1984
	// Set correct file permissions
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1985
	$stat = @ stat( dirname( $new_file ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1986
	$perms = $stat['mode'] & 0007777;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1987
	$perms = $perms & 0000666;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1988
	@ chmod( $new_file, $perms );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1989
	clearstatcache();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1990
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1991
	// Compute the URL
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1992
	$url = $upload['url'] . "/$filename";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1993
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1994
	return array( 'file' => $new_file, 'url' => $url, 'error' => false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1995
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1996
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1997
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1998
 * Retrieve the file type based on the extension name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1999
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2000
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2001
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2002
 * @param string $ext The extension to search.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2003
 * @return string|null The file type, example: audio, video, document, spreadsheet, etc.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2004
 *                     Null if not found.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2005
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2006
function wp_ext2type( $ext ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2007
	$ext = strtolower( $ext );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2008
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2009
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2010
	 * Filter file type based on the extension name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2011
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2012
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2013
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2014
	 * @see wp_ext2type()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2015
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2016
	 * @param array $ext2type Multi-dimensional array with extensions for a default set
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2017
	 *                        of file types.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2018
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2019
	$ext2type = apply_filters( 'ext2type', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2020
		'image'       => array( 'jpg', 'jpeg', 'jpe',  'gif',  'png',  'bmp',   'tif',  'tiff', 'ico' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2021
		'audio'       => array( 'aac', 'ac3',  'aif',  'aiff', 'm3a',  'm4a',   'm4b',  'mka',  'mp1',  'mp2',  'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2022
		'video'       => array( '3g2',  '3gp', '3gpp', 'asf', 'avi',  'divx', 'dv',   'flv',  'm4v',   'mkv',  'mov',  'mp4',  'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt',  'rm', 'vob', 'wmv' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2023
		'document'    => array( 'doc', 'docx', 'docm', 'dotm', 'odt',  'pages', 'pdf',  'xps',  'oxps', 'rtf',  'wp', 'wpd', 'psd', 'xcf' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2024
		'spreadsheet' => array( 'numbers',     'ods',  'xls',  'xlsx', 'xlsm',  'xlsb' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2025
		'interactive' => array( 'swf', 'key',  'ppt',  'pptx', 'pptm', 'pps',   'ppsx', 'ppsm', 'sldx', 'sldm', 'odp' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2026
		'text'        => array( 'asc', 'csv',  'tsv',  'txt' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2027
		'archive'     => array( 'bz2', 'cab',  'dmg',  'gz',   'rar',  'sea',   'sit',  'sqx',  'tar',  'tgz',  'zip', '7z' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2028
		'code'        => array( 'css', 'htm',  'html', 'php',  'js' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2029
	) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2030
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2031
	foreach ( $ext2type as $type => $exts )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2032
		if ( in_array( $ext, $exts ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2033
			return $type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2034
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2035
	return null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2036
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2037
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2038
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2039
 * Retrieve the file type from the file name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2040
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2041
 * You can optionally define the mime array, if needed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2042
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2043
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2044
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2045
 * @param string $filename File name or path.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2046
 * @param array  $mimes    Optional. Key is the file extension with value as the mime type.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2047
 * @return array Values with extension first and mime type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2048
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2049
function wp_check_filetype( $filename, $mimes = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2050
	if ( empty($mimes) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2051
		$mimes = get_allowed_mime_types();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2052
	$type = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2053
	$ext = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2054
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2055
	foreach ( $mimes as $ext_preg => $mime_match ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2056
		$ext_preg = '!\.(' . $ext_preg . ')$!i';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2057
		if ( preg_match( $ext_preg, $filename, $ext_matches ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2058
			$type = $mime_match;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2059
			$ext = $ext_matches[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2060
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2061
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2062
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2063
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2064
	return compact( 'ext', 'type' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2065
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2066
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2067
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2068
 * Attempt to determine the real file type of a file.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2069
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2070
 * If unable to, the file name extension will be used to determine type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2071
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2072
 * If it's determined that the extension does not match the file's real type,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2073
 * then the "proper_filename" value will be set with a proper filename and extension.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2074
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2075
 * Currently this function only supports validating images known to getimagesize().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2076
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2077
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2078
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2079
 * @param string $file     Full path to the file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2080
 * @param string $filename The name of the file (may differ from $file due to $file being
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2081
 *                         in a tmp directory).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2082
 * @param array   $mimes   Optional. Key is the file extension with value as the mime type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2083
 * @return array Values for the extension, MIME, and either a corrected filename or false
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2084
 *               if original $filename is valid.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2085
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2086
function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2087
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2088
	$proper_filename = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2089
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2090
	// Do basic extension validation and MIME mapping
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2091
	$wp_filetype = wp_check_filetype( $filename, $mimes );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2092
	$ext = $wp_filetype['ext'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2093
	$type = $wp_filetype['type'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2094
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2095
	// We can't do any further validation without a file to work with
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2096
	if ( ! file_exists( $file ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2097
		return compact( 'ext', 'type', 'proper_filename' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2098
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2099
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2100
	// We're able to validate images using GD
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2101
	if ( $type && 0 === strpos( $type, 'image/' ) && function_exists('getimagesize') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2102
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2103
		// Attempt to figure out what type of image it actually is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2104
		$imgstats = @getimagesize( $file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2105
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2106
		// If getimagesize() knows what kind of image it really is and if the real MIME doesn't match the claimed MIME
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2107
		if ( !empty($imgstats['mime']) && $imgstats['mime'] != $type ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2108
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2109
			 * Filter the list mapping image mime types to their respective extensions.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2110
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2111
			 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2112
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2113
			 * @param  array $mime_to_ext Array of image mime types and their matching extensions.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2114
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2115
			$mime_to_ext = apply_filters( 'getimagesize_mimes_to_exts', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2116
				'image/jpeg' => 'jpg',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2117
				'image/png'  => 'png',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2118
				'image/gif'  => 'gif',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2119
				'image/bmp'  => 'bmp',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2120
				'image/tiff' => 'tif',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2121
			) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2122
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2123
			// Replace whatever is after the last period in the filename with the correct extension
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2124
			if ( ! empty( $mime_to_ext[ $imgstats['mime'] ] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2125
				$filename_parts = explode( '.', $filename );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2126
				array_pop( $filename_parts );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2127
				$filename_parts[] = $mime_to_ext[ $imgstats['mime'] ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2128
				$new_filename = implode( '.', $filename_parts );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2129
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2130
				if ( $new_filename != $filename ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2131
					$proper_filename = $new_filename; // Mark that it changed
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2132
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2133
				// Redefine the extension / MIME
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2134
				$wp_filetype = wp_check_filetype( $new_filename, $mimes );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2135
				$ext = $wp_filetype['ext'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2136
				$type = $wp_filetype['type'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2137
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2138
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2139
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2140
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2141
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2142
	 * Filter the "real" file type of the given file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2143
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2144
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2145
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2146
	 * @param array  $wp_check_filetype_and_ext File data array containing 'ext', 'type', and
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2147
	 *                                          'proper_filename' keys.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2148
	 * @param string $file                      Full path to the file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2149
	 * @param string $filename                  The name of the file (may differ from $file due to
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2150
	 *                                          $file being in a tmp directory).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2151
	 * @param array  $mimes                     Key is the file extension with value as the mime type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2152
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2153
	return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2154
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2155
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2156
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2157
 * Retrieve list of mime types and file extensions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2158
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2159
 * @since 3.5.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2160
 * @since 4.2.0 Support was added for GIMP (xcf) files.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2161
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2162
 * @return array Array of mime types keyed by the file extension regex corresponding to those types.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2163
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2164
function wp_get_mime_types() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2165
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2166
	 * Filter the list of mime types and file extensions.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2167
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2168
	 * This filter should be used to add, not remove, mime types. To remove
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2169
	 * mime types, use the 'upload_mimes' filter.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2170
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2171
	 * @since 3.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2172
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2173
	 * @param array $wp_get_mime_types Mime types keyed by the file extension regex
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2174
	 *                                 corresponding to those types.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2175
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2176
	return apply_filters( 'mime_types', array(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2177
	// Image formats.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2178
	'jpg|jpeg|jpe' => 'image/jpeg',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2179
	'gif' => 'image/gif',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2180
	'png' => 'image/png',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2181
	'bmp' => 'image/bmp',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2182
	'tiff|tif' => 'image/tiff',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2183
	'ico' => 'image/x-icon',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2184
	// Video formats.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2185
	'asf|asx' => 'video/x-ms-asf',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2186
	'wmv' => 'video/x-ms-wmv',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2187
	'wmx' => 'video/x-ms-wmx',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2188
	'wm' => 'video/x-ms-wm',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2189
	'avi' => 'video/avi',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2190
	'divx' => 'video/divx',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2191
	'flv' => 'video/x-flv',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2192
	'mov|qt' => 'video/quicktime',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2193
	'mpeg|mpg|mpe' => 'video/mpeg',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2194
	'mp4|m4v' => 'video/mp4',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2195
	'ogv' => 'video/ogg',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2196
	'webm' => 'video/webm',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2197
	'mkv' => 'video/x-matroska',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2198
	'3gp|3gpp' => 'video/3gpp', // Can also be audio
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2199
	'3g2|3gp2' => 'video/3gpp2', // Can also be audio
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2200
	// Text formats.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2201
	'txt|asc|c|cc|h|srt' => 'text/plain',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2202
	'csv' => 'text/csv',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2203
	'tsv' => 'text/tab-separated-values',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2204
	'ics' => 'text/calendar',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2205
	'rtx' => 'text/richtext',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2206
	'css' => 'text/css',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2207
	'htm|html' => 'text/html',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2208
	'vtt' => 'text/vtt',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2209
	'dfxp' => 'application/ttaf+xml',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2210
	// Audio formats.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2211
	'mp3|m4a|m4b' => 'audio/mpeg',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2212
	'ra|ram' => 'audio/x-realaudio',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2213
	'wav' => 'audio/wav',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2214
	'ogg|oga' => 'audio/ogg',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2215
	'mid|midi' => 'audio/midi',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2216
	'wma' => 'audio/x-ms-wma',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2217
	'wax' => 'audio/x-ms-wax',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2218
	'mka' => 'audio/x-matroska',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2219
	// Misc application formats.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2220
	'rtf' => 'application/rtf',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2221
	'js' => 'application/javascript',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2222
	'pdf' => 'application/pdf',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2223
	'swf' => 'application/x-shockwave-flash',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2224
	'class' => 'application/java',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2225
	'tar' => 'application/x-tar',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2226
	'zip' => 'application/zip',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2227
	'gz|gzip' => 'application/x-gzip',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2228
	'rar' => 'application/rar',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2229
	'7z' => 'application/x-7z-compressed',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2230
	'exe' => 'application/x-msdownload',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2231
	'psd' => 'application/octet-stream',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2232
	'xcf' => 'application/octet-stream',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2233
	// MS Office formats.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2234
	'doc' => 'application/msword',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2235
	'pot|pps|ppt' => 'application/vnd.ms-powerpoint',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2236
	'wri' => 'application/vnd.ms-write',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2237
	'xla|xls|xlt|xlw' => 'application/vnd.ms-excel',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2238
	'mdb' => 'application/vnd.ms-access',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2239
	'mpp' => 'application/vnd.ms-project',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2240
	'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2241
	'docm' => 'application/vnd.ms-word.document.macroEnabled.12',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2242
	'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2243
	'dotm' => 'application/vnd.ms-word.template.macroEnabled.12',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2244
	'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2245
	'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2246
	'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2247
	'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2248
	'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2249
	'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2250
	'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2251
	'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2252
	'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2253
	'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2254
	'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2255
	'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2256
	'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2257
	'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2258
	'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2259
	'onetoc|onetoc2|onetmp|onepkg' => 'application/onenote',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2260
	'oxps' => 'application/oxps',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2261
	'xps' => 'application/vnd.ms-xpsdocument',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2262
	// OpenOffice formats.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2263
	'odt' => 'application/vnd.oasis.opendocument.text',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2264
	'odp' => 'application/vnd.oasis.opendocument.presentation',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2265
	'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2266
	'odg' => 'application/vnd.oasis.opendocument.graphics',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2267
	'odc' => 'application/vnd.oasis.opendocument.chart',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2268
	'odb' => 'application/vnd.oasis.opendocument.database',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2269
	'odf' => 'application/vnd.oasis.opendocument.formula',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2270
	// WordPerfect formats.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2271
	'wp|wpd' => 'application/wordperfect',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2272
	// iWork formats.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2273
	'key' => 'application/vnd.apple.keynote',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2274
	'numbers' => 'application/vnd.apple.numbers',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2275
	'pages' => 'application/vnd.apple.pages',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2276
	) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2277
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2278
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2279
 * Retrieve list of allowed mime types and file extensions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2280
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2281
 * @since 2.8.6
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2282
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2283
 * @param int|WP_User $user Optional. User to check. Defaults to current user.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2284
 * @return array Array of mime types keyed by the file extension regex corresponding
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2285
 *               to those types.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2286
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2287
function get_allowed_mime_types( $user = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2288
	$t = wp_get_mime_types();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2289
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2290
	unset( $t['swf'], $t['exe'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2291
	if ( function_exists( 'current_user_can' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2292
		$unfiltered = $user ? user_can( $user, 'unfiltered_html' ) : current_user_can( 'unfiltered_html' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2293
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2294
	if ( empty( $unfiltered ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2295
		unset( $t['htm|html'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2296
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2297
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2298
	 * Filter list of allowed mime types and file extensions.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2299
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2300
	 * @since 2.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2301
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2302
	 * @param array            $t    Mime types keyed by the file extension regex corresponding to
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2303
	 *                               those types. 'swf' and 'exe' removed from full list. 'htm|html' also
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2304
	 *                               removed depending on '$user' capabilities.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2305
	 * @param int|WP_User|null $user User ID, User object or null if not provided (indicates current user).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2306
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2307
	return apply_filters( 'upload_mimes', $t, $user );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2308
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2309
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2310
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2311
 * Display "Are You Sure" message to confirm the action being taken.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2312
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2313
 * If the action has the nonce explain message, then it will be displayed
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2314
 * along with the "Are you sure?" message.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2315
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2316
 * @since 2.0.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2317
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2318
 * @param string $action The nonce action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2319
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2320
function wp_nonce_ays( $action ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2321
	if ( 'log-out' == $action ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2322
		$html = sprintf( __( 'You are attempting to log out of %s' ), get_bloginfo( 'name' ) ) . '</p><p>';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2323
		$redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2324
		$html .= sprintf( __( "Do you really want to <a href='%s'>log out</a>?"), wp_logout_url( $redirect_to ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2325
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2326
		$html = __( 'Are you sure you want to do this?' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2327
		if ( wp_get_referer() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2328
			$html .= "</p><p><a href='" . esc_url( remove_query_arg( 'updated', wp_get_referer() ) ) . "'>" . __( 'Please try again.' ) . "</a>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2329
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2330
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2331
	wp_die( $html, __( 'WordPress Failure Notice' ), 403 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2332
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2333
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2334
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2335
 * Kill WordPress execution and display HTML message with error message.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2336
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2337
 * This function complements the `die()` PHP function. The difference is that
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2338
 * HTML will be displayed to the user. It is recommended to use this function
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2339
 * only when the execution should not continue any further. It is not recommended
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2340
 * to call this function very often, and try to handle as many errors as possible
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2341
 * silently or more gracefully.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2342
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2343
 * As a shorthand, the desired HTTP response code may be passed as an integer to
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2344
 * the `$title` parameter (the default title would apply) or the `$args` parameter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2345
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2346
 * @since 2.0.4
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2347
 * @since 4.1.0 The `$title` and `$args` parameters were changed to optionally accept
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2348
 *              an integer to be used as the response code.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2349
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2350
 * @param string|WP_Error  $message Optional. Error message. If this is a {@see WP_Error} object,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2351
 *                                  the error's messages are used. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2352
 * @param string|int       $title   Optional. Error title. If `$message` is a `WP_Error` object,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2353
 *                                  error data with the key 'title' may be used to specify the title.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2354
 *                                  If `$title` is an integer, then it is treated as the response
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2355
 *                                  code. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2356
 * @param string|array|int $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2357
 *     Optional. Arguments to control behavior. If `$args` is an integer, then it is treated
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2358
 *     as the response code. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2359
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2360
 *     @type int    $response       The HTTP response code. Default 500.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2361
 *     @type bool   $back_link      Whether to include a link to go back. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2362
 *     @type string $text_direction The text direction. This is only useful internally, when WordPress
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2363
 *                                  is still loading and the site's locale is not set up yet. Accepts 'rtl'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2364
 *                                  Default is the value of {@see is_rtl()}.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2365
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2366
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2367
function wp_die( $message = '', $title = '', $args = array() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2368
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2369
	if ( is_int( $args ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2370
		$args = array( 'response' => $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2371
	} elseif ( is_int( $title ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2372
		$args  = array( 'response' => $title );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2373
		$title = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2374
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2375
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2376
	if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2377
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2378
		 * Filter callback for killing WordPress execution for AJAX requests.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2379
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2380
		 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2381
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2382
		 * @param callback $function Callback function name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2383
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2384
		$function = apply_filters( 'wp_die_ajax_handler', '_ajax_wp_die_handler' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2385
	} elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2386
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2387
		 * Filter callback for killing WordPress execution for XML-RPC requests.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2388
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2389
		 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2390
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2391
		 * @param callback $function Callback function name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2392
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2393
		$function = apply_filters( 'wp_die_xmlrpc_handler', '_xmlrpc_wp_die_handler' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2394
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2395
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2396
		 * Filter callback for killing WordPress execution for all non-AJAX, non-XML-RPC requests.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2397
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2398
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2399
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2400
		 * @param callback $function Callback function name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2401
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2402
		$function = apply_filters( 'wp_die_handler', '_default_wp_die_handler' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2403
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2404
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2405
	call_user_func( $function, $message, $title, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2406
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2407
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2408
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2409
 * Kill WordPress execution and display HTML message with error message.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2410
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2411
 * This is the default handler for wp_die if you want a custom one for your
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2412
 * site then you can overload using the wp_die_handler filter in wp_die
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2413
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2414
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2415
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2416
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2417
 * @param string       $message Error message.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2418
 * @param string       $title   Optional. Error title. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2419
 * @param string|array $args    Optional. Arguments to control behavior. Default empty array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2420
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2421
function _default_wp_die_handler( $message, $title = '', $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2422
	$defaults = array( 'response' => 500 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2423
	$r = wp_parse_args($args, $defaults);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2424
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2425
	$have_gettext = function_exists('__');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2426
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2427
	if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2428
		if ( empty( $title ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2429
			$error_data = $message->get_error_data();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2430
			if ( is_array( $error_data ) && isset( $error_data['title'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2431
				$title = $error_data['title'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2432
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2433
		$errors = $message->get_error_messages();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2434
		switch ( count( $errors ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2435
		case 0 :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2436
			$message = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2437
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2438
		case 1 :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2439
			$message = "<p>{$errors[0]}</p>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2440
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2441
		default :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2442
			$message = "<ul>\n\t\t<li>" . join( "</li>\n\t\t<li>", $errors ) . "</li>\n\t</ul>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2443
			break;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2444
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2445
	} elseif ( is_string( $message ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2446
		$message = "<p>$message</p>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2447
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2448
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2449
	if ( isset( $r['back_link'] ) && $r['back_link'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2450
		$back_text = $have_gettext? __('&laquo; Back') : '&laquo; Back';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2451
		$message .= "\n<p><a href='javascript:history.back()'>$back_text</a></p>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2452
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2453
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2454
	if ( ! did_action( 'admin_head' ) ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2455
		if ( !headers_sent() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2456
			status_header( $r['response'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2457
			nocache_headers();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2458
			header( 'Content-Type: text/html; charset=utf-8' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2459
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2460
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2461
		if ( empty($title) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2462
			$title = $have_gettext ? __('WordPress &rsaquo; Error') : 'WordPress &rsaquo; Error';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2463
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2464
		$text_direction = 'ltr';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2465
		if ( isset($r['text_direction']) && 'rtl' == $r['text_direction'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2466
			$text_direction = 'rtl';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2467
		elseif ( function_exists( 'is_rtl' ) && is_rtl() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2468
			$text_direction = 'rtl';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2469
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2470
<!DOCTYPE html>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2471
<!-- 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
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2472
-->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2473
<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'"; ?>>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2474
<head>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2475
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2476
	<title><?php echo $title ?></title>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2477
	<style type="text/css">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2478
		html {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2479
			background: #f1f1f1;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2480
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2481
		body {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2482
			background: #fff;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2483
			color: #444;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2484
			font-family: "Open Sans", sans-serif;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2485
			margin: 2em auto;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2486
			padding: 1em 2em;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2487
			max-width: 700px;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2488
			-webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.13);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2489
			box-shadow: 0 1px 3px rgba(0,0,0,0.13);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2490
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2491
		h1 {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2492
			border-bottom: 1px solid #dadada;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2493
			clear: both;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2494
			color: #666;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2495
			font: 24px "Open Sans", sans-serif;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2496
			margin: 30px 0 0 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2497
			padding: 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2498
			padding-bottom: 7px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2499
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2500
		#error-page {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2501
			margin-top: 50px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2502
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2503
		#error-page p {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2504
			font-size: 14px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2505
			line-height: 1.5;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2506
			margin: 25px 0 20px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2507
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2508
		#error-page code {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2509
			font-family: Consolas, Monaco, monospace;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2510
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2511
		ul li {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2512
			margin-bottom: 10px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2513
			font-size: 14px ;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2514
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2515
		a {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2516
			color: #21759B;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2517
			text-decoration: none;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2518
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2519
		a:hover {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2520
			color: #D54E21;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2521
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2522
		.button {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2523
			background: #f7f7f7;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2524
			border: 1px solid #cccccc;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2525
			color: #555;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2526
			display: inline-block;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2527
			text-decoration: none;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2528
			font-size: 13px;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2529
			line-height: 26px;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2530
			height: 28px;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2531
			margin: 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2532
			padding: 0 10px 1px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2533
			cursor: pointer;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2534
			-webkit-border-radius: 3px;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2535
			-webkit-appearance: none;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2536
			border-radius: 3px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2537
			white-space: nowrap;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2538
			-webkit-box-sizing: border-box;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2539
			-moz-box-sizing:    border-box;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2540
			box-sizing:         border-box;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2541
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2542
			-webkit-box-shadow: inset 0 1px 0 #fff, 0 1px 0 rgba(0,0,0,.08);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2543
			box-shadow: inset 0 1px 0 #fff, 0 1px 0 rgba(0,0,0,.08);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2544
		 	vertical-align: top;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2545
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2546
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2547
		.button.button-large {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2548
			height: 29px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2549
			line-height: 28px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2550
			padding: 0 12px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2551
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2552
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2553
		.button:hover,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2554
		.button:focus {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2555
			background: #fafafa;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2556
			border-color: #999;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2557
			color: #222;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2558
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2559
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2560
		.button:focus  {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2561
			-webkit-box-shadow: 1px 1px 1px rgba(0,0,0,.2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2562
			box-shadow: 1px 1px 1px rgba(0,0,0,.2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2563
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2564
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2565
		.button:active {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2566
			background: #eee;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2567
			border-color: #999;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2568
			color: #333;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2569
			-webkit-box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2570
		 	box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2571
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2572
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2573
		<?php if ( 'rtl' == $text_direction ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2574
		body { font-family: Tahoma, Arial; }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2575
		<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2576
	</style>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2577
</head>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2578
<body id="error-page">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2579
<?php endif; // ! did_action( 'admin_head' ) ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2580
	<?php echo $message; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2581
</body>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2582
</html>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2583
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2584
	die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2585
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2586
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2587
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2588
 * Kill WordPress execution and display XML message with error message.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2589
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2590
 * This is the handler for wp_die when processing XMLRPC requests.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2591
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2592
 * @since 3.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2593
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2594
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2595
 * @param string       $message Error message.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2596
 * @param string       $title   Optional. Error title. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2597
 * @param string|array $args    Optional. Arguments to control behavior. Default empty array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2598
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2599
function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2600
	global $wp_xmlrpc_server;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2601
	$defaults = array( 'response' => 500 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2602
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2603
	$r = wp_parse_args($args, $defaults);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2604
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2605
	if ( $wp_xmlrpc_server ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2606
		$error = new IXR_Error( $r['response'] , $message);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2607
		$wp_xmlrpc_server->output( $error->getXml() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2608
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2609
	die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2610
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2611
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2612
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2613
 * Kill WordPress ajax execution.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2614
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2615
 * This is the handler for wp_die when processing Ajax requests.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2616
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2617
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2618
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2619
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2620
 * @param string $message Optional. Response to print. Default empty.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2621
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2622
function _ajax_wp_die_handler( $message = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2623
	if ( is_scalar( $message ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2624
		die( (string) $message );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2625
	die( '0' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2626
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2627
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2628
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2629
 * Kill WordPress execution.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2630
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2631
 * This is the handler for wp_die when processing APP requests.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2632
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2633
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2634
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2635
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2636
 * @param string $message Optional. Response to print. Default empty.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2637
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2638
function _scalar_wp_die_handler( $message = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2639
	if ( is_scalar( $message ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2640
		die( (string) $message );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2641
	die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2642
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2643
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2644
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2645
 * Encode a variable into JSON, with some sanity checks.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2646
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2647
 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2648
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2649
 * @param mixed $data    Variable (usually an array or object) to encode as JSON.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2650
 * @param int   $options Optional. Options to be passed to json_encode(). Default 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2651
 * @param int   $depth   Optional. Maximum depth to walk through $data. Must be
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2652
 *                       greater than 0. Default 512.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2653
 * @return bool|string The JSON encoded string, or false if it cannot be encoded.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2654
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2655
function wp_json_encode( $data, $options = 0, $depth = 512 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2656
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2657
	 * json_encode() has had extra params added over the years.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2658
	 * $options was added in 5.3, and $depth in 5.5.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2659
	 * We need to make sure we call it with the correct arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2660
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2661
	if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2662
		$args = array( $data, $options, $depth );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2663
	} elseif ( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2664
		$args = array( $data, $options );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2665
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2666
		$args = array( $data );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2667
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2668
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2669
	$json = call_user_func_array( 'json_encode', $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2670
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2671
	// If json_encode() was successful, no need to do more sanity checking.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2672
	// ... unless we're in an old version of PHP, and json_encode() returned
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2673
	// a string containing 'null'. Then we need to do more sanity checking.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2674
	if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) )  {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2675
		return $json;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2676
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2677
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2678
	try {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2679
		$args[0] = _wp_json_sanity_check( $data, $depth );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2680
	} catch ( Exception $e ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2681
		return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2682
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2683
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2684
	return call_user_func_array( 'json_encode', $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2685
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2686
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2687
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2688
 * Perform sanity checks on data that shall be encoded to JSON.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2689
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2690
 * @ignore
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2691
 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2692
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2693
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2694
 * @see wp_json_encode()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2695
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2696
 * @param mixed $data  Variable (usually an array or object) to encode as JSON.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2697
 * @param int   $depth Maximum depth to walk through $data. Must be greater than 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2698
 * @return mixed The sanitized data that shall be encoded to JSON.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2699
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2700
function _wp_json_sanity_check( $data, $depth ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2701
	if ( $depth < 0 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2702
		throw new Exception( 'Reached depth limit' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2703
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2704
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2705
	if ( is_array( $data ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2706
		$output = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2707
		foreach ( $data as $id => $el ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2708
			// Don't forget to sanitize the ID!
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2709
			if ( is_string( $id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2710
				$clean_id = _wp_json_convert_string( $id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2711
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2712
				$clean_id = $id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2713
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2714
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2715
			// Check the element type, so that we're only recursing if we really have to.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2716
			if ( is_array( $el ) || is_object( $el ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2717
				$output[ $clean_id ] = _wp_json_sanity_check( $el, $depth - 1 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2718
			} elseif ( is_string( $el ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2719
				$output[ $clean_id ] = _wp_json_convert_string( $el );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2720
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2721
				$output[ $clean_id ] = $el;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2722
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2723
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2724
	} elseif ( is_object( $data ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2725
		$output = new stdClass;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2726
		foreach ( $data as $id => $el ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2727
			if ( is_string( $id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2728
				$clean_id = _wp_json_convert_string( $id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2729
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2730
				$clean_id = $id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2731
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2732
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2733
			if ( is_array( $el ) || is_object( $el ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2734
				$output->$clean_id = _wp_json_sanity_check( $el, $depth - 1 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2735
			} elseif ( is_string( $el ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2736
				$output->$clean_id = _wp_json_convert_string( $el );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2737
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2738
				$output->$clean_id = $el;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2739
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2740
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2741
	} elseif ( is_string( $data ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2742
		return _wp_json_convert_string( $data );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2743
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2744
		return $data;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2745
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2746
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2747
	return $output;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2748
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2749
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2750
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2751
 * Convert a string to UTF-8, so that it can be safely encoded to JSON.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2752
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2753
 * @ignore
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2754
 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2755
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2756
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2757
 * @see _wp_json_sanity_check()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2758
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2759
 * @param string $string The string which is to be converted.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2760
 * @return string The checked string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2761
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2762
function _wp_json_convert_string( $string ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2763
	static $use_mb = null;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2764
	if ( is_null( $use_mb ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2765
		$use_mb = function_exists( 'mb_convert_encoding' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2766
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2767
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2768
	if ( $use_mb ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2769
		$encoding = mb_detect_encoding( $string, mb_detect_order(), true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2770
		if ( $encoding ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2771
			return mb_convert_encoding( $string, 'UTF-8', $encoding );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2772
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2773
			return mb_convert_encoding( $string, 'UTF-8', 'UTF-8' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2774
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2775
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2776
		return wp_check_invalid_utf8( $string, true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2777
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2778
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2779
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2780
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2781
 * Send a JSON response back to an Ajax request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2782
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2783
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2784
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2785
 * @param mixed $response Variable (usually an array or object) to encode as JSON,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2786
 *                        then print and die.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2787
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2788
function wp_send_json( $response ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2789
	@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2790
	echo wp_json_encode( $response );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2791
	if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2792
		wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2793
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2794
		die;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2795
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2796
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2797
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2798
 * Send a JSON response back to an Ajax request, indicating success.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2799
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2800
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2801
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2802
 * @param mixed $data Data to encode as JSON, then print and die.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2803
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2804
function wp_send_json_success( $data = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2805
	$response = array( 'success' => true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2806
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2807
	if ( isset( $data ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2808
		$response['data'] = $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2809
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2810
	wp_send_json( $response );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2811
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2812
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2813
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2814
 * Send a JSON response back to an Ajax request, indicating failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2815
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2816
 * If the `$data` parameter is a {@see WP_Error} object, the errors
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2817
 * within the object are processed and output as an array of error
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2818
 * codes and corresponding messages. All other types are output
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2819
 * without further processing.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2820
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2821
 * @since 3.5.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2822
 * @since 4.1.0 The `$data` parameter is now processed if a {@see WP_Error}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2823
 *              object is passed in.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2824
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2825
 * @param mixed $data Data to encode as JSON, then print and die.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2826
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2827
function wp_send_json_error( $data = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2828
	$response = array( 'success' => false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2829
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2830
	if ( isset( $data ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2831
		if ( is_wp_error( $data ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2832
			$result = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2833
			foreach ( $data->errors as $code => $messages ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2834
				foreach ( $messages as $message ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2835
					$result[] = array( 'code' => $code, 'message' => $message );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2836
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2837
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2838
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2839
			$response['data'] = $result;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2840
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2841
			$response['data'] = $data;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2842
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2843
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2844
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2845
	wp_send_json( $response );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2846
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2847
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2848
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2849
 * Retrieve the WordPress home page URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2850
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2851
 * If the constant named 'WP_HOME' exists, then it will be used and returned
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2852
 * by the function. This can be used to counter the redirection on your local
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2853
 * development environment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2854
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2855
 * @since 2.2.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2856
 * @access private
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2857
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2858
 * @see WP_HOME
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2859
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2860
 * @param string $url URL for the home location.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2861
 * @return string Homepage location.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2862
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2863
function _config_wp_home( $url = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2864
	if ( defined( 'WP_HOME' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2865
		return untrailingslashit( WP_HOME );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2866
	return $url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2867
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2868
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2869
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2870
 * Retrieve the WordPress site URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2871
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2872
 * If the constant named 'WP_SITEURL' is defined, then the value in that
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2873
 * constant will always be returned. This can be used for debugging a site
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2874
 * on your localhost while not having to change the database to your URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2875
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2876
 * @since 2.2.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2877
 * @access private
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2878
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2879
 * @see WP_SITEURL
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2880
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2881
 * @param string $url URL to set the WordPress site location.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2882
 * @return string The WordPress Site URL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2883
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2884
function _config_wp_siteurl( $url = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2885
	if ( defined( 'WP_SITEURL' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2886
		return untrailingslashit( WP_SITEURL );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2887
	return $url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2888
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2889
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2890
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2891
 * Set the localized direction for MCE plugin.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2892
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2893
 * Will only set the direction to 'rtl', if the WordPress locale has
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2894
 * the text direction set to 'rtl'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2895
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2896
 * Fills in the 'directionality' setting, enables the 'directionality'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2897
 * plugin, and adds the 'ltr' button to 'toolbar1', formerly
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2898
 * 'theme_advanced_buttons1' array keys. These keys are then returned
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2899
 * in the $input (TinyMCE settings) array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2900
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2901
 * @since 2.1.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2902
 * @access private
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2903
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2904
 * @param array $input MCE settings array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2905
 * @return array Direction set for 'rtl', if needed by locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2906
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2907
function _mce_set_direction( $input ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2908
	if ( is_rtl() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2909
		$input['directionality'] = 'rtl';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2910
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2911
		if ( ! empty( $input['plugins'] ) && strpos( $input['plugins'], 'directionality' ) === false ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2912
			$input['plugins'] .= ',directionality';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2913
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2914
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2915
		if ( ! empty( $input['toolbar1'] ) && ! preg_match( '/\bltr\b/', $input['toolbar1'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2916
			$input['toolbar1'] .= ',ltr';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2917
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2918
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2919
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2920
	return $input;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2921
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2922
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2923
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2924
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2925
 * Convert smiley code to the icon graphic file equivalent.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2926
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2927
 * You can turn off smilies, by going to the write setting screen and unchecking
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2928
 * the box, or by setting 'use_smilies' option to false or removing the option.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2929
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2930
 * Plugins may override the default smiley list by setting the $wpsmiliestrans
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2931
 * to an array, with the key the code the blogger types in and the value the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2932
 * image file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2933
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2934
 * The $wp_smiliessearch global is for the regular expression and is set each
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2935
 * time the function is called.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2936
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2937
 * The full list of smilies can be found in the function and won't be listed in
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2938
 * the description. Probably should create a Codex page for it, so that it is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2939
 * available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2940
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2941
 * @global array $wpsmiliestrans
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2942
 * @global array $wp_smiliessearch
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2943
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2944
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2945
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2946
function smilies_init() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2947
	global $wpsmiliestrans, $wp_smiliessearch;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2948
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2949
	// don't bother setting up smilies if they are disabled
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2950
	if ( !get_option( 'use_smilies' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2951
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2952
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2953
	if ( !isset( $wpsmiliestrans ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2954
		$wpsmiliestrans = array(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2955
		':mrgreen:' => 'mrgreen.png',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2956
		':neutral:' => "\xf0\x9f\x98\x90",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2957
		':twisted:' => "\xf0\x9f\x98\x88",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2958
		  ':arrow:' => "\xe2\x9e\xa1",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2959
		  ':shock:' => "\xf0\x9f\x98\xaf",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2960
		  ':smile:' => 'simple-smile.png',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2961
		    ':???:' => "\xf0\x9f\x98\x95",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2962
		   ':cool:' => "\xf0\x9f\x98\x8e",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2963
		   ':evil:' => "\xf0\x9f\x91\xbf",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2964
		   ':grin:' => "\xf0\x9f\x98\x80",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2965
		   ':idea:' => "\xf0\x9f\x92\xa1",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2966
		   ':oops:' => "\xf0\x9f\x98\xb3",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2967
		   ':razz:' => "\xf0\x9f\x98\x9b",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2968
		   ':roll:' => 'rolleyes.png',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2969
		   ':wink:' => "\xf0\x9f\x98\x89",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2970
		    ':cry:' => "\xf0\x9f\x98\xa5",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2971
		    ':eek:' => "\xf0\x9f\x98\xae",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2972
		    ':lol:' => "\xf0\x9f\x98\x86",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2973
		    ':mad:' => "\xf0\x9f\x98\xa1",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2974
		    ':sad:' => 'frownie.png',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2975
		      '8-)' => "\xf0\x9f\x98\x8e",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2976
		      '8-O' => "\xf0\x9f\x98\xaf",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2977
		      ':-(' => 'frownie.png',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2978
		      ':-)' => 'simple-smile.png',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2979
		      ':-?' => "\xf0\x9f\x98\x95",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2980
		      ':-D' => "\xf0\x9f\x98\x80",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2981
		      ':-P' => "\xf0\x9f\x98\x9b",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2982
		      ':-o' => "\xf0\x9f\x98\xae",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2983
		      ':-x' => "\xf0\x9f\x98\xa1",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2984
		      ':-|' => "\xf0\x9f\x98\x90",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2985
		      ';-)' => "\xf0\x9f\x98\x89",
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2986
		// This one transformation breaks regular text with frequency.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2987
		//     '8)' => "\xf0\x9f\x98\x8e",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2988
		       '8O' => "\xf0\x9f\x98\xaf",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2989
		       ':(' => 'frownie.png',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2990
		       ':)' => 'simple-smile.png',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2991
		       ':?' => "\xf0\x9f\x98\x95",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2992
		       ':D' => "\xf0\x9f\x98\x80",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2993
		       ':P' => "\xf0\x9f\x98\x9b",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2994
		       ':o' => "\xf0\x9f\x98\xae",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2995
		       ':x' => "\xf0\x9f\x98\xa1",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2996
		       ':|' => "\xf0\x9f\x98\x90",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2997
		       ';)' => "\xf0\x9f\x98\x89",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2998
		      ':!:' => "\xe2\x9d\x97",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2999
		      ':?:' => "\xe2\x9d\x93",
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3000
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3001
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3002
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3003
	if (count($wpsmiliestrans) == 0) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3004
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3005
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3006
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3007
	/*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3008
	 * NOTE: we sort the smilies in reverse key order. This is to make sure
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3009
	 * we match the longest possible smilie (:???: vs :?) as the regular
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3010
	 * expression used below is first-match
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3011
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3012
	krsort($wpsmiliestrans);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3013
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3014
	$spaces = wp_spaces_regexp();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3015
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3016
	// Begin first "subpattern"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3017
	$wp_smiliessearch = '/(?<=' . $spaces . '|^)';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3018
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3019
	$subchar = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3020
	foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3021
		$firstchar = substr($smiley, 0, 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3022
		$rest = substr($smiley, 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3023
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3024
		// new subpattern?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3025
		if ($firstchar != $subchar) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3026
			if ($subchar != '') {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3027
				$wp_smiliessearch .= ')(?=' . $spaces . '|$)';  // End previous "subpattern"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3028
				$wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern"
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3029
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3030
			$subchar = $firstchar;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3031
			$wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3032
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3033
			$wp_smiliessearch .= '|';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3034
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3035
		$wp_smiliessearch .= preg_quote($rest, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3036
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3037
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3038
	$wp_smiliessearch .= ')(?=' . $spaces . '|$)/m';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3039
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3040
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3041
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3042
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3043
 * Merge user defined arguments into defaults array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3044
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3045
 * This function is used throughout WordPress to allow for both string or array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3046
 * to be merged into another array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3047
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3048
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3049
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3050
 * @param string|array $args     Value to merge with $defaults
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3051
 * @param array        $defaults Optional. Array that serves as the defaults. Default empty.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3052
 * @return array Merged user defined values with defaults.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3053
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3054
function wp_parse_args( $args, $defaults = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3055
	if ( is_object( $args ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3056
		$r = get_object_vars( $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3057
	elseif ( is_array( $args ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3058
		$r =& $args;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3059
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3060
		wp_parse_str( $args, $r );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3061
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3062
	if ( is_array( $defaults ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3063
		return array_merge( $defaults, $r );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3064
	return $r;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3065
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3066
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3067
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3068
 * Clean up an array, comma- or space-separated list of IDs.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3069
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3070
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3071
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3072
 * @param array|string $list List of ids.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3073
 * @return array Sanitized array of IDs.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3074
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3075
function wp_parse_id_list( $list ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3076
	if ( !is_array($list) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3077
		$list = preg_split('/[\s,]+/', $list);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3078
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3079
	return array_unique(array_map('absint', $list));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3080
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3081
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3082
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3083
 * Extract a slice of an array, given a list of keys.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3084
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3085
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3086
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3087
 * @param array $array The original array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3088
 * @param array $keys  The list of keys.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3089
 * @return array The array slice.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3090
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3091
function wp_array_slice_assoc( $array, $keys ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3092
	$slice = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3093
	foreach ( $keys as $key )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3094
		if ( isset( $array[ $key ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3095
			$slice[ $key ] = $array[ $key ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3096
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3097
	return $slice;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3098
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3099
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3100
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3101
 * Filters a list of objects, based on a set of key => value arguments.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3102
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3103
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3104
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3105
 * @param array       $list     An array of objects to filter
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3106
 * @param array       $args     Optional. An array of key => value arguments to match
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3107
 *                              against each object. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3108
 * @param string      $operator Optional. The logical operation to perform. 'or' means
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3109
 *                              only one element from the array needs to match; 'and'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3110
 *                              means all elements must match. Default 'and'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3111
 * @param bool|string $field    A field from the object to place instead of the entire object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3112
 *                              Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3113
 * @return array A list of objects or object fields.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3114
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3115
function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3116
	if ( ! is_array( $list ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3117
		return array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3118
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3119
	$list = wp_list_filter( $list, $args, $operator );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3120
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3121
	if ( $field )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3122
		$list = wp_list_pluck( $list, $field );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3123
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3124
	return $list;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3125
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3126
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3127
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3128
 * Filters a list of objects, based on a set of key => value arguments.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3129
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3130
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3131
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3132
 * @param array  $list     An array of objects to filter.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3133
 * @param array  $args     Optional. An array of key => value arguments to match
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3134
 *                         against each object. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3135
 * @param string $operator Optional. The logical operation to perform. 'AND' means
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3136
 *                         all elements from the array must match. 'OR' means only
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3137
 *                         one element needs to match. 'NOT' means no elements may
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3138
 *                         match. Default 'AND'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3139
 * @return array Array of found values.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3140
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3141
function wp_list_filter( $list, $args = array(), $operator = 'AND' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3142
	if ( ! is_array( $list ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3143
		return array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3144
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3145
	if ( empty( $args ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3146
		return $list;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3147
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3148
	$operator = strtoupper( $operator );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3149
	$count = count( $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3150
	$filtered = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3151
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3152
	foreach ( $list as $key => $obj ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3153
		$to_match = (array) $obj;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3154
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3155
		$matched = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3156
		foreach ( $args as $m_key => $m_value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3157
			if ( array_key_exists( $m_key, $to_match ) && $m_value == $to_match[ $m_key ] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3158
				$matched++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3159
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3160
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3161
		if ( ( 'AND' == $operator && $matched == $count )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3162
		  || ( 'OR' == $operator && $matched > 0 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3163
		  || ( 'NOT' == $operator && 0 == $matched ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3164
			$filtered[$key] = $obj;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3165
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3166
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3167
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3168
	return $filtered;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3169
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3170
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3171
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3172
 * Pluck a certain field out of each object in a list.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3173
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3174
 * This has the same functionality and prototype of
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3175
 * array_column() (PHP 5.5) but also supports objects.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3176
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3177
 * @since 3.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3178
 * @since 4.0.0 $index_key parameter added.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3179
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3180
 * @param array      $list      List of objects or arrays
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3181
 * @param int|string $field     Field from the object to place instead of the entire object
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3182
 * @param int|string $index_key Optional. Field from the object to use as keys for the new array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3183
 *                              Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3184
 * @return array Array of found values. If `$index_key` is set, an array of found values with keys
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3185
 *               corresponding to `$index_key`. If `$index_key` is null, array keys from the original
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3186
 *               `$list` will be preserved in the results.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3187
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3188
function wp_list_pluck( $list, $field, $index_key = null ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3189
	if ( ! $index_key ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3190
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3191
		 * This is simple. Could at some point wrap array_column()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3192
		 * if we knew we had an array of arrays.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3193
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3194
		foreach ( $list as $key => $value ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3195
			if ( is_object( $value ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3196
				$list[ $key ] = $value->$field;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3197
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3198
				$list[ $key ] = $value[ $field ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3199
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3200
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3201
		return $list;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3202
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3203
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3204
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3205
	 * When index_key is not set for a particular item, push the value
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3206
	 * to the end of the stack. This is how array_column() behaves.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3207
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3208
	$newlist = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3209
	foreach ( $list as $value ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3210
		if ( is_object( $value ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3211
			if ( isset( $value->$index_key ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3212
				$newlist[ $value->$index_key ] = $value->$field;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3213
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3214
				$newlist[] = $value->$field;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3215
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3216
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3217
			if ( isset( $value[ $index_key ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3218
				$newlist[ $value[ $index_key ] ] = $value[ $field ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3219
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3220
				$newlist[] = $value[ $field ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3221
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3222
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3223
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3224
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3225
	return $newlist;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3226
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3227
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3228
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3229
 * Determines if Widgets library should be loaded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3230
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3231
 * Checks to make sure that the widgets library hasn't already been loaded.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3232
 * If it hasn't, then it will load the widgets library and run an action hook.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3233
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3234
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3235
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3236
function wp_maybe_load_widgets() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3237
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3238
	 * Filter whether to load the Widgets library.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3239
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3240
	 * Passing a falsey value to the filter will effectively short-circuit
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3241
	 * the Widgets library from loading.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3242
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3243
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3244
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3245
	 * @param bool $wp_maybe_load_widgets Whether to load the Widgets library.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3246
	 *                                    Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3247
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3248
	if ( ! apply_filters( 'load_default_widgets', true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3249
		return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3250
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3251
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3252
	require_once( ABSPATH . WPINC . '/default-widgets.php' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3253
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3254
	add_action( '_admin_menu', 'wp_widgets_add_menu' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3255
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3256
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3257
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3258
 * Append the Widgets menu to the themes main menu.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3259
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3260
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3261
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3262
function wp_widgets_add_menu() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3263
	global $submenu;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3264
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3265
	if ( ! current_theme_supports( 'widgets' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3266
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3267
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3268
	$submenu['themes.php'][7] = array( __( 'Widgets' ), 'edit_theme_options', 'widgets.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3269
	ksort( $submenu['themes.php'], SORT_NUMERIC );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3270
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3271
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3272
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3273
 * Flush all output buffers for PHP 5.2.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3274
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3275
 * Make sure all output buffers are flushed before our singletons are destroyed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3276
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3277
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3278
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3279
function wp_ob_end_flush_all() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3280
	$levels = ob_get_level();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3281
	for ($i=0; $i<$levels; $i++)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3282
		ob_end_flush();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3283
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3284
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3285
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3286
 * Load custom DB error or display WordPress DB error.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3287
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3288
 * If a file exists in the wp-content directory named db-error.php, then it will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3289
 * be loaded instead of displaying the WordPress DB error. If it is not found,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3290
 * then the WordPress DB error will be displayed instead.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3291
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3292
 * The WordPress DB error sets the HTTP status header to 500 to try to prevent
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3293
 * search engines from caching the message. Custom DB messages should do the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3294
 * same.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3295
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3296
 * This function was backported to WordPress 2.3.2, but originally was added
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3297
 * in WordPress 2.5.0.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3298
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3299
 * @since 2.3.2
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3300
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3301
 * @global wpdb $wpdb WordPress database abstraction object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3302
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3303
function dead_db() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3304
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3305
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3306
	wp_load_translations_early();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3307
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3308
	// Load custom DB error template, if present.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3309
	if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3310
		require_once( WP_CONTENT_DIR . '/db-error.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3311
		die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3312
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3313
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3314
	// If installing or in the admin, provide the verbose message.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3315
	if ( defined('WP_INSTALLING') || defined('WP_ADMIN') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3316
		wp_die($wpdb->error);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3317
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3318
	// Otherwise, be terse.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3319
	status_header( 500 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3320
	nocache_headers();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3321
	header( 'Content-Type: text/html; charset=utf-8' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3322
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3323
<!DOCTYPE html>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3324
<html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3325
<head>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3326
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3327
	<title><?php _e( 'Database Error' ); ?></title>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3328
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3329
</head>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3330
<body>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3331
	<h1><?php _e( 'Error establishing a database connection' ); ?></h1>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3332
</body>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3333
</html>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3334
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3335
	die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3336
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3337
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3338
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3339
 * Convert a value to non-negative integer.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3340
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3341
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3342
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3343
 * @param mixed $maybeint Data you wish to have converted to a non-negative integer.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3344
 * @return int A non-negative integer.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3345
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3346
function absint( $maybeint ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3347
	return abs( intval( $maybeint ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3348
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3349
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3350
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3351
 * Mark a function as deprecated and inform when it has been used.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3352
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3353
 * There is a hook deprecated_function_run that will be called that can be used
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3354
 * to get the backtrace up to what file and function called the deprecated
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3355
 * function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3356
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3357
 * The current behavior is to trigger a user error if WP_DEBUG is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3358
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3359
 * This function is to be used in every function that is deprecated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3360
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3361
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3362
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3363
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3364
 * @param string $function    The function that was called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3365
 * @param string $version     The version of WordPress that deprecated the function.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3366
 * @param string $replacement Optional. The function that should have been called. Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3367
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3368
function _deprecated_function( $function, $version, $replacement = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3369
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3370
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3371
	 * Fires when a deprecated function is called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3372
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3373
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3374
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3375
	 * @param string $function    The function that was called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3376
	 * @param string $replacement The function that should have been called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3377
	 * @param string $version     The version of WordPress that deprecated the function.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3378
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3379
	do_action( 'deprecated_function_run', $function, $replacement, $version );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3380
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3381
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3382
	 * Filter whether to trigger an error for deprecated functions.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3383
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3384
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3385
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3386
	 * @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3387
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3388
	if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3389
		if ( function_exists( '__' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3390
			if ( ! is_null( $replacement ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3391
				trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3392
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3393
				trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3394
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3395
			if ( ! is_null( $replacement ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3396
				trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function, $version, $replacement ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3397
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3398
				trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3399
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3400
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3401
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3402
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3403
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3404
 * Mark a file as deprecated and inform when it has been used.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3405
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3406
 * There is a hook deprecated_file_included that will be called that can be used
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3407
 * to get the backtrace up to what file and function included the deprecated
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3408
 * file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3409
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3410
 * The current behavior is to trigger a user error if WP_DEBUG is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3411
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3412
 * This function is to be used in every file that is deprecated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3413
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3414
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3415
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3416
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3417
 * @param string $file        The file that was included.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3418
 * @param string $version     The version of WordPress that deprecated the file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3419
 * @param string $replacement Optional. The file that should have been included based on ABSPATH.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3420
 *                            Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3421
 * @param string $message     Optional. A message regarding the change. Default empty.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3422
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3423
function _deprecated_file( $file, $version, $replacement = null, $message = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3424
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3425
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3426
	 * Fires when a deprecated file is called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3427
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3428
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3429
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3430
	 * @param string $file        The file that was called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3431
	 * @param string $replacement The file that should have been included based on ABSPATH.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3432
	 * @param string $version     The version of WordPress that deprecated the file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3433
	 * @param string $message     A message regarding the change.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3434
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3435
	do_action( 'deprecated_file_included', $file, $replacement, $version, $message );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3436
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3437
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3438
	 * Filter whether to trigger an error for deprecated files.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3439
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3440
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3441
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3442
	 * @param bool $trigger Whether to trigger the error for deprecated files. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3443
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3444
	if ( WP_DEBUG && apply_filters( 'deprecated_file_trigger_error', true ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3445
		$message = empty( $message ) ? '' : ' ' . $message;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3446
		if ( function_exists( '__' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3447
			if ( ! is_null( $replacement ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3448
				trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $file, $version, $replacement ) . $message );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3449
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3450
				trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $file, $version ) . $message );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3451
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3452
			if ( ! is_null( $replacement ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3453
				trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $file, $version, $replacement ) . $message );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3454
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3455
				trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $file, $version ) . $message );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3456
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3457
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3458
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3459
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3460
 * Mark a function argument as deprecated and inform when it has been used.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3461
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3462
 * This function is to be used whenever a deprecated function argument is used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3463
 * Before this function is called, the argument must be checked for whether it was
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3464
 * used by comparing it to its default value or evaluating whether it is empty.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3465
 * For example:
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3466
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3467
 *     if ( ! empty( $deprecated ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3468
 *         _deprecated_argument( __FUNCTION__, '3.0' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3469
 *     }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3470
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3471
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3472
 * There is a hook deprecated_argument_run that will be called that can be used
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3473
 * to get the backtrace up to what file and function used the deprecated
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3474
 * argument.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3475
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3476
 * The current behavior is to trigger a user error if WP_DEBUG is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3477
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3478
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3479
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3480
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3481
 * @param string $function The function that was called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3482
 * @param string $version  The version of WordPress that deprecated the argument used.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3483
 * @param string $message  Optional. A message regarding the change. Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3484
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3485
function _deprecated_argument( $function, $version, $message = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3486
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3487
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3488
	 * Fires when a deprecated argument is called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3489
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3490
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3491
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3492
	 * @param string $function The function that was called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3493
	 * @param string $message  A message regarding the change.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3494
	 * @param string $version  The version of WordPress that deprecated the argument used.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3495
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3496
	do_action( 'deprecated_argument_run', $function, $message, $version );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3497
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3498
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3499
	 * Filter whether to trigger an error for deprecated arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3500
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3501
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3502
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3503
	 * @param bool $trigger Whether to trigger the error for deprecated arguments. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3504
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3505
	if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3506
		if ( function_exists( '__' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3507
			if ( ! is_null( $message ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3508
				trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s'), $function, $version, $message ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3509
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3510
				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 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3511
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3512
			if ( ! is_null( $message ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3513
				trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s', $function, $version, $message ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3514
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3515
				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 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3516
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3517
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3518
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3519
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3520
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3521
 * Mark something as being incorrectly called.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3522
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3523
 * There is a hook doing_it_wrong_run that will be called that can be used
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3524
 * to get the backtrace up to what file and function called the deprecated
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3525
 * function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3526
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3527
 * The current behavior is to trigger a user error if WP_DEBUG is true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3528
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3529
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3530
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3531
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3532
 * @param string $function The function that was called.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3533
 * @param string $message  A message explaining what has been done incorrectly.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3534
 * @param string $version  The version of WordPress where the message was added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3535
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3536
function _doing_it_wrong( $function, $message, $version ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3537
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3538
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3539
	 * Fires when the given function is being used incorrectly.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3540
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3541
	 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3542
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3543
	 * @param string $function The function that was called.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3544
	 * @param string $message  A message explaining what has been done incorrectly.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3545
	 * @param string $version  The version of WordPress where the message was added.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3546
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3547
	do_action( 'doing_it_wrong_run', $function, $message, $version );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3548
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3549
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3550
	 * Filter whether to trigger an error for _doing_it_wrong() calls.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3551
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3552
	 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3553
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3554
	 * @param bool $trigger Whether to trigger the error for _doing_it_wrong() calls. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3555
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3556
	if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3557
		if ( function_exists( '__' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3558
			$version = is_null( $version ) ? '' : sprintf( __( '(This message was added in version %s.)' ), $version );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3559
			$message .= ' ' . __( 'Please see <a href="https://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information.' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3560
			trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3561
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3562
			$version = is_null( $version ) ? '' : sprintf( '(This message was added in version %s.)', $version );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3563
			$message .= ' Please see <a href="https://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information.';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3564
			trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3565
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3566
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3567
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3568
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3569
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3570
 * Is the server running earlier than 1.5.0 version of lighttpd?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3571
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3572
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3573
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3574
 * @return bool Whether the server is running lighttpd < 1.5.0.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3575
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3576
function is_lighttpd_before_150() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3577
	$server_parts = explode( '/', isset( $_SERVER['SERVER_SOFTWARE'] )? $_SERVER['SERVER_SOFTWARE'] : '' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3578
	$server_parts[1] = isset( $server_parts[1] )? $server_parts[1] : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3579
	return  'lighttpd' == $server_parts[0] && -1 == version_compare( $server_parts[1], '1.5.0' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3580
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3581
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3582
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3583
 * Does the specified module exist in the Apache config?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3584
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3585
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3586
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3587
 * @param string $mod     The module, e.g. mod_rewrite.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3588
 * @param bool   $default Optional. The default return value if the module is not found. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3589
 * @return bool Whether the specified module is loaded.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3590
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3591
function apache_mod_loaded($mod, $default = false) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3592
	global $is_apache;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3593
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3594
	if ( !$is_apache )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3595
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3596
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3597
	if ( function_exists( 'apache_get_modules' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3598
		$mods = apache_get_modules();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3599
		if ( in_array($mod, $mods) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3600
			return true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3601
	} elseif ( function_exists( 'phpinfo' ) && false === strpos( ini_get( 'disable_functions' ), 'phpinfo' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3602
			ob_start();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3603
			phpinfo(8);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3604
			$phpinfo = ob_get_clean();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3605
			if ( false !== strpos($phpinfo, $mod) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3606
				return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3607
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3608
	return $default;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3609
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3610
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3611
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3612
 * Check if IIS 7+ supports pretty permalinks.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3613
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3614
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3615
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3616
 * @return bool Whether IIS7 supports permalinks.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3617
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3618
function iis7_supports_permalinks() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3619
	global $is_iis7;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3620
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3621
	$supports_permalinks = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3622
	if ( $is_iis7 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3623
		/* First we check if the DOMDocument class exists. If it does not exist, then we cannot
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3624
		 * easily update the xml configuration file, hence we just bail out and tell user that
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3625
		 * pretty permalinks cannot be used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3626
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3627
		 * Next we check if the URL Rewrite Module 1.1 is loaded and enabled for the web site. When
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3628
		 * URL Rewrite 1.1 is loaded it always sets a server variable called 'IIS_UrlRewriteModule'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3629
		 * Lastly we make sure that PHP is running via FastCGI. This is important because if it runs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3630
		 * via ISAPI then pretty permalinks will not work.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3631
		 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3632
		$supports_permalinks = class_exists('DOMDocument') && isset($_SERVER['IIS_UrlRewriteModule']) && ( PHP_SAPI == 'cgi-fcgi' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3633
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3634
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3635
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3636
	 * Filter whether IIS 7+ supports pretty permalinks.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3637
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3638
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3639
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3640
	 * @param bool $supports_permalinks Whether IIS7 supports permalinks. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3641
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3642
	return apply_filters( 'iis7_supports_permalinks', $supports_permalinks );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3643
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3644
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3645
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3646
 * File validates against allowed set of defined rules.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3647
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3648
 * A return value of '1' means that the $file contains either '..' or './'. A
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3649
 * return value of '2' means that the $file contains ':' after the first
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3650
 * character. A return value of '3' means that the file is not in the allowed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3651
 * files list.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3652
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3653
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3654
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3655
 * @param string $file File path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3656
 * @param array $allowed_files List of allowed files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3657
 * @return int 0 means nothing is wrong, greater than 0 means something was wrong.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3658
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3659
function validate_file( $file, $allowed_files = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3660
	if ( false !== strpos( $file, '..' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3661
		return 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3662
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3663
	if ( false !== strpos( $file, './' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3664
		return 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3665
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3666
	if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3667
		return 3;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3668
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3669
	if (':' == substr( $file, 1, 1 ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3670
		return 2;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3671
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3672
	return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3673
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3674
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3675
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3676
 * Determine if SSL is used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3677
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3678
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3679
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3680
 * @return bool True if SSL, false if not used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3681
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3682
function is_ssl() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3683
	if ( isset($_SERVER['HTTPS']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3684
		if ( 'on' == strtolower($_SERVER['HTTPS']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3685
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3686
		if ( '1' == $_SERVER['HTTPS'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3687
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3688
	} elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3689
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3690
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3691
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3692
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3693
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3694
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3695
 * Whether SSL login should be forced.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3696
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3697
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3698
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3699
 * @see force_ssl_admin()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3700
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3701
 * @param string|bool $force Optional Whether to force SSL login. Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3702
 * @return bool True if forced, false if not forced.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3703
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3704
function force_ssl_login( $force = null ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3705
	return force_ssl_admin( $force );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3706
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3707
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3708
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3709
 * Whether to force SSL used for the Administration Screens.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3710
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3711
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3712
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3713
 * @param string|bool $force Optional. Whether to force SSL in admin screens. Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3714
 * @return bool True if forced, false if not forced.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3715
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3716
function force_ssl_admin( $force = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3717
	static $forced = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3718
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3719
	if ( !is_null( $force ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3720
		$old_forced = $forced;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3721
		$forced = $force;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3722
		return $old_forced;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3723
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3724
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3725
	return $forced;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3726
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3727
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3728
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3729
 * Guess the URL for the site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3730
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3731
 * Will remove wp-admin links to retrieve only return URLs not in the wp-admin
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3732
 * directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3733
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3734
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3735
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3736
 * @return string The guessed URL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3737
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3738
function wp_guess_url() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3739
	if ( defined('WP_SITEURL') && '' != WP_SITEURL ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3740
		$url = WP_SITEURL;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3741
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3742
		$abspath_fix = str_replace( '\\', '/', ABSPATH );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3743
		$script_filename_dir = dirname( $_SERVER['SCRIPT_FILENAME'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3744
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3745
		// The request is for the admin
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3746
		if ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) !== false || strpos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3747
			$path = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $_SERVER['REQUEST_URI'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3748
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3749
		// The request is for a file in ABSPATH
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3750
		} elseif ( $script_filename_dir . '/' == $abspath_fix ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3751
			// Strip off any file/query params in the path
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3752
			$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3753
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3754
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3755
			if ( false !== strpos( $_SERVER['SCRIPT_FILENAME'], $abspath_fix ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3756
				// Request is hitting a file inside ABSPATH
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3757
				$directory = str_replace( ABSPATH, '', $script_filename_dir );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3758
				// Strip off the sub directory, and any file/query paramss
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3759
				$path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3760
			} elseif ( false !== strpos( $abspath_fix, $script_filename_dir ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3761
				// Request is hitting a file above ABSPATH
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3762
				$subdirectory = substr( $abspath_fix, strpos( $abspath_fix, $script_filename_dir ) + strlen( $script_filename_dir ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3763
				// Strip off any file/query params from the path, appending the sub directory to the install
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3764
				$path = preg_replace( '#/[^/]*$#i', '' , $_SERVER['REQUEST_URI'] ) . $subdirectory;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3765
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3766
				$path = $_SERVER['REQUEST_URI'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3767
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3768
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3769
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3770
		$schema = is_ssl() ? 'https://' : 'http://'; // set_url_scheme() is not defined yet
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3771
		$url = $schema . $_SERVER['HTTP_HOST'] . $path;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3772
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3773
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3774
	return rtrim($url, '/');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3775
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3776
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3777
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3778
 * Temporarily suspend cache additions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3779
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3780
 * Stops more data being added to the cache, but still allows cache retrieval.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3781
 * This is useful for actions, such as imports, when a lot of data would otherwise
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3782
 * be almost uselessly added to the cache.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3783
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3784
 * Suspension lasts for a single page load at most. Remember to call this
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3785
 * function again if you wish to re-enable cache adds earlier.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3786
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3787
 * @since 3.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3788
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3789
 * @param bool $suspend Optional. Suspends additions if true, re-enables them if false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3790
 * @return bool The current suspend setting
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3791
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3792
function wp_suspend_cache_addition( $suspend = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3793
	static $_suspend = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3794
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3795
	if ( is_bool( $suspend ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3796
		$_suspend = $suspend;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3797
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3798
	return $_suspend;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3799
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3800
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3801
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3802
 * Suspend cache invalidation.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3803
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3804
 * Turns cache invalidation on and off. Useful during imports where you don't wont to do
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3805
 * invalidations every time a post is inserted. Callers must be sure that what they are
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3806
 * doing won't lead to an inconsistent cache when invalidation is suspended.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3807
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3808
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3809
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3810
 * @param bool $suspend Optional. Whether to suspend or enable cache invalidation. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3811
 * @return bool The current suspend setting.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3812
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3813
function wp_suspend_cache_invalidation( $suspend = true ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3814
	global $_wp_suspend_cache_invalidation;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3815
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3816
	$current_suspend = $_wp_suspend_cache_invalidation;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3817
	$_wp_suspend_cache_invalidation = $suspend;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3818
	return $current_suspend;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3819
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3820
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3821
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3822
 * Determine whether a site is the main site of the current network.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3823
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3824
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3825
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3826
 * @param int $site_id Optional. Site ID to test. Defaults to current site.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3827
 *                     Defaults to current site.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3828
 * @return bool True if $site_id is the main site of the network, or if not
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3829
 *              running Multisite.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3830
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3831
function is_main_site( $site_id = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3832
	// This is the current network's information; 'site' is old terminology.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3833
	global $current_site;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3834
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3835
	if ( ! is_multisite() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3836
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3837
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3838
	if ( ! $site_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3839
		$site_id = get_current_blog_id();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3840
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3841
	return (int) $site_id === (int) $current_site->blog_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3842
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3843
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3844
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3845
 * Determine whether a network is the main network of the Multisite install.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3846
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3847
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3848
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3849
 * @param int $network_id Optional. Network ID to test. Defaults to current network.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3850
 * @return bool True if $network_id is the main network, or if not running Multisite.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3851
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3852
function is_main_network( $network_id = null ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3853
	global $wpdb;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3854
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3855
	if ( ! is_multisite() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3856
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3857
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3858
	$current_network_id = (int) get_current_site()->id;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3859
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3860
	if ( ! $network_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3861
		$network_id = $current_network_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3862
	$network_id = (int) $network_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3863
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3864
	if ( defined( 'PRIMARY_NETWORK_ID' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3865
		return $network_id === (int) PRIMARY_NETWORK_ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3866
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3867
	if ( 1 === $current_network_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3868
		return $network_id === $current_network_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3869
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3870
	$primary_network_id = (int) wp_cache_get( 'primary_network_id', 'site-options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3871
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3872
	if ( $primary_network_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3873
		return $network_id === $primary_network_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3874
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3875
	$primary_network_id = (int) $wpdb->get_var( "SELECT id FROM $wpdb->site ORDER BY id LIMIT 1" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3876
	wp_cache_add( 'primary_network_id', $primary_network_id, 'site-options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3877
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3878
	return $network_id === $primary_network_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3879
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3880
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3881
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3882
 * Determine whether global terms are enabled.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3883
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3884
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3885
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3886
 * @return bool True if multisite and global terms enabled.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3887
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3888
function global_terms_enabled() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3889
	if ( ! is_multisite() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3890
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3891
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3892
	static $global_terms = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3893
	if ( is_null( $global_terms ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3894
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3895
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3896
		 * Filter whether global terms are enabled.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3897
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3898
		 * Passing a non-null value to the filter will effectively short-circuit the function,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3899
		 * returning the value of the 'global_terms_enabled' site option instead.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3900
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3901
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3902
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3903
		 * @param null $anbled Whether global terms are enabled.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3904
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3905
		$filter = apply_filters( 'global_terms_enabled', null );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3906
		if ( ! is_null( $filter ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3907
			$global_terms = (bool) $filter;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3908
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3909
			$global_terms = (bool) get_site_option( 'global_terms_enabled', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3910
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3911
	return $global_terms;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3912
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3913
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3914
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3915
 * gmt_offset modification for smart timezone handling.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3916
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3917
 * Overrides the gmt_offset option if we have a timezone_string available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3918
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3919
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3920
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3921
 * @return float|bool Timezone GMT offset, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3922
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3923
function wp_timezone_override_offset() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3924
	if ( !$timezone_string = get_option( 'timezone_string' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3925
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3926
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3927
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3928
	$timezone_object = timezone_open( $timezone_string );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3929
	$datetime_object = date_create();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3930
	if ( false === $timezone_object || false === $datetime_object ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3931
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3932
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3933
	return round( timezone_offset_get( $timezone_object, $datetime_object ) / HOUR_IN_SECONDS, 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3934
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3935
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3936
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3937
 * Sort-helper for timezones.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3938
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3939
 * @since 2.9.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3940
 * @access private
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3941
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3942
 * @param array $a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3943
 * @param array $b
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3944
 * @return int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3945
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3946
function _wp_timezone_choice_usort_callback( $a, $b ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3947
	// Don't use translated versions of Etc
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3948
	if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3949
		// Make the order of these more like the old dropdown
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3950
		if ( 'GMT+' === substr( $a['city'], 0, 4 ) && 'GMT+' === substr( $b['city'], 0, 4 ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3951
			return -1 * ( strnatcasecmp( $a['city'], $b['city'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3952
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3953
		if ( 'UTC' === $a['city'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3954
			if ( 'GMT+' === substr( $b['city'], 0, 4 ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3955
				return 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3956
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3957
			return -1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3958
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3959
		if ( 'UTC' === $b['city'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3960
			if ( 'GMT+' === substr( $a['city'], 0, 4 ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3961
				return -1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3962
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3963
			return 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3964
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3965
		return strnatcasecmp( $a['city'], $b['city'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3966
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3967
	if ( $a['t_continent'] == $b['t_continent'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3968
		if ( $a['t_city'] == $b['t_city'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3969
			return strnatcasecmp( $a['t_subcity'], $b['t_subcity'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3970
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3971
		return strnatcasecmp( $a['t_city'], $b['t_city'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3972
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3973
		// Force Etc to the bottom of the list
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3974
		if ( 'Etc' === $a['continent'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3975
			return 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3976
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3977
		if ( 'Etc' === $b['continent'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3978
			return -1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3979
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3980
		return strnatcasecmp( $a['t_continent'], $b['t_continent'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3981
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3982
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3983
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3984
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3985
 * Gives a nicely-formatted list of timezone strings.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3986
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3987
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3988
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3989
 * @param string $selected_zone Selected timezone.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3990
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3991
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3992
function wp_timezone_choice( $selected_zone ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3993
	static $mo_loaded = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3994
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3995
	$continents = array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3996
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3997
	// Load translations for continents and cities
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3998
	if ( !$mo_loaded ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3999
		$locale = get_locale();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4000
		$mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4001
		load_textdomain( 'continents-cities', $mofile );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4002
		$mo_loaded = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4003
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4004
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4005
	$zonen = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4006
	foreach ( timezone_identifiers_list() as $zone ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4007
		$zone = explode( '/', $zone );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4008
		if ( !in_array( $zone[0], $continents ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4009
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4010
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4011
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4012
		// This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4013
		$exists = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4014
			0 => ( isset( $zone[0] ) && $zone[0] ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4015
			1 => ( isset( $zone[1] ) && $zone[1] ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4016
			2 => ( isset( $zone[2] ) && $zone[2] ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4017
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4018
		$exists[3] = ( $exists[0] && 'Etc' !== $zone[0] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4019
		$exists[4] = ( $exists[1] && $exists[3] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4020
		$exists[5] = ( $exists[2] && $exists[3] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4021
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4022
		$zonen[] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4023
			'continent'   => ( $exists[0] ? $zone[0] : '' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4024
			'city'        => ( $exists[1] ? $zone[1] : '' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4025
			'subcity'     => ( $exists[2] ? $zone[2] : '' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4026
			't_continent' => ( $exists[3] ? translate( str_replace( '_', ' ', $zone[0] ), 'continents-cities' ) : '' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4027
			't_city'      => ( $exists[4] ? translate( str_replace( '_', ' ', $zone[1] ), 'continents-cities' ) : '' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4028
			't_subcity'   => ( $exists[5] ? translate( str_replace( '_', ' ', $zone[2] ), 'continents-cities' ) : '' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4029
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4030
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4031
	usort( $zonen, '_wp_timezone_choice_usort_callback' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4032
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4033
	$structure = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4034
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4035
	if ( empty( $selected_zone ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4036
		$structure[] = '<option selected="selected" value="">' . __( 'Select a city' ) . '</option>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4037
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4038
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4039
	foreach ( $zonen as $key => $zone ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4040
		// Build value in an array to join later
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4041
		$value = array( $zone['continent'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4042
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4043
		if ( empty( $zone['city'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4044
			// It's at the continent level (generally won't happen)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4045
			$display = $zone['t_continent'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4046
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4047
			// It's inside a continent group
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4048
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4049
			// Continent optgroup
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4050
			if ( !isset( $zonen[$key - 1] ) || $zonen[$key - 1]['continent'] !== $zone['continent'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4051
				$label = $zone['t_continent'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4052
				$structure[] = '<optgroup label="'. esc_attr( $label ) .'">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4053
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4054
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4055
			// Add the city to the value
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4056
			$value[] = $zone['city'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4057
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4058
			$display = $zone['t_city'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4059
			if ( !empty( $zone['subcity'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4060
				// Add the subcity to the value
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4061
				$value[] = $zone['subcity'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4062
				$display .= ' - ' . $zone['t_subcity'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4063
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4064
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4065
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4066
		// Build the value
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4067
		$value = join( '/', $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4068
		$selected = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4069
		if ( $value === $selected_zone ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4070
			$selected = 'selected="selected" ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4071
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4072
		$structure[] = '<option ' . $selected . 'value="' . esc_attr( $value ) . '">' . esc_html( $display ) . "</option>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4073
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4074
		// Close continent optgroup
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4075
		if ( !empty( $zone['city'] ) && ( !isset($zonen[$key + 1]) || (isset( $zonen[$key + 1] ) && $zonen[$key + 1]['continent'] !== $zone['continent']) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4076
			$structure[] = '</optgroup>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4077
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4078
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4079
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4080
	// Do UTC
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4081
	$structure[] = '<optgroup label="'. esc_attr__( 'UTC' ) .'">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4082
	$selected = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4083
	if ( 'UTC' === $selected_zone )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4084
		$selected = 'selected="selected" ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4085
	$structure[] = '<option ' . $selected . 'value="' . esc_attr( 'UTC' ) . '">' . __('UTC') . '</option>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4086
	$structure[] = '</optgroup>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4087
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4088
	// Do manual UTC offsets
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4089
	$structure[] = '<optgroup label="'. esc_attr__( 'Manual Offsets' ) .'">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4090
	$offset_range = array (-12, -11.5, -11, -10.5, -10, -9.5, -9, -8.5, -8, -7.5, -7, -6.5, -6, -5.5, -5, -4.5, -4, -3.5, -3, -2.5, -2, -1.5, -1, -0.5,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4091
		0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 5.75, 6, 6.5, 7, 7.5, 8, 8.5, 8.75, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.75, 13, 13.75, 14);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4092
	foreach ( $offset_range as $offset ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4093
		if ( 0 <= $offset )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4094
			$offset_name = '+' . $offset;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4095
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4096
			$offset_name = (string) $offset;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4097
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4098
		$offset_value = $offset_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4099
		$offset_name = str_replace(array('.25','.5','.75'), array(':15',':30',':45'), $offset_name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4100
		$offset_name = 'UTC' . $offset_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4101
		$offset_value = 'UTC' . $offset_value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4102
		$selected = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4103
		if ( $offset_value === $selected_zone )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4104
			$selected = 'selected="selected" ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4105
		$structure[] = '<option ' . $selected . 'value="' . esc_attr( $offset_value ) . '">' . esc_html( $offset_name ) . "</option>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4106
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4107
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4108
	$structure[] = '</optgroup>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4109
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4110
	return join( "\n", $structure );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4111
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4112
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4113
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4114
 * Strip close comment and close php tags from file headers used by WP.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4115
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4116
 * @since 2.8.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4117
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4118
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4119
 * @see https://core.trac.wordpress.org/ticket/8497
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4120
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4121
 * @param string $str Header comment to clean up.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4122
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4123
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4124
function _cleanup_header_comment( $str ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4125
	return trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $str));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4126
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4127
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4128
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4129
 * Permanently delete comments or posts of any type that have held a status
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4130
 * of 'trash' for the number of days defined in EMPTY_TRASH_DAYS.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4131
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4132
 * The default value of `EMPTY_TRASH_DAYS` is 30 (days).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4133
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4134
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4135
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4136
function wp_scheduled_delete() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4137
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4138
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4139
	$delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4140
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4141
	$posts_to_delete = $wpdb->get_results($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4142
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4143
	foreach ( (array) $posts_to_delete as $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4144
		$post_id = (int) $post['post_id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4145
		if ( !$post_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4146
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4147
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4148
		$del_post = get_post($post_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4149
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4150
		if ( !$del_post || 'trash' != $del_post->post_status ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4151
			delete_post_meta($post_id, '_wp_trash_meta_status');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4152
			delete_post_meta($post_id, '_wp_trash_meta_time');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4153
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4154
			wp_delete_post($post_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4155
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4156
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4157
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4158
	$comments_to_delete = $wpdb->get_results($wpdb->prepare("SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4159
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4160
	foreach ( (array) $comments_to_delete as $comment ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4161
		$comment_id = (int) $comment['comment_id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4162
		if ( !$comment_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4163
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4164
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4165
		$del_comment = get_comment($comment_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4166
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4167
		if ( !$del_comment || 'trash' != $del_comment->comment_approved ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4168
			delete_comment_meta($comment_id, '_wp_trash_meta_time');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4169
			delete_comment_meta($comment_id, '_wp_trash_meta_status');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4170
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4171
			wp_delete_comment($comment_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4172
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4173
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4174
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4175
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4176
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4177
 * Retrieve metadata from a file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4178
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4179
 * Searches for metadata in the first 8kiB of a file, such as a plugin or theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4180
 * Each piece of metadata must be on its own line. Fields can not span multiple
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4181
 * lines, the value will get cut at the end of the first line.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4182
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4183
 * If the file data is not within that first 8kiB, then the author should correct
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4184
 * their plugin file and move the data headers to the top.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4185
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4186
 * @link https://codex.wordpress.org/File_Header
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4187
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4188
 * @since 2.9.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4189
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4190
 * @param string $file            Path to the file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4191
 * @param array  $default_headers List of headers, in the format array('HeaderKey' => 'Header Name').
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4192
 * @param string $context         Optional. If specified adds filter hook "extra_{$context}_headers".
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4193
 *                                Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4194
 * @return array Array of file headers in `HeaderKey => Header Value` format.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4195
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4196
function get_file_data( $file, $default_headers, $context = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4197
	// We don't need to write to the file, so just open for reading.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4198
	$fp = fopen( $file, 'r' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4199
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4200
	// Pull only the first 8kiB of the file in.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4201
	$file_data = fread( $fp, 8192 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4203
	// PHP will close file handle, but we are good citizens.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4204
	fclose( $fp );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4205
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4206
	// Make sure we catch CR-only line endings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4207
	$file_data = str_replace( "\r", "\n", $file_data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4208
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4209
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4210
	 * Filter extra file headers by context.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4211
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4212
	 * The dynamic portion of the hook name, `$context`, refers to
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4213
	 * the context where extra headers might be loaded.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4214
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4215
	 * @since 2.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4216
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4217
	 * @param array $extra_context_headers Empty array by default.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4218
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4219
	if ( $context && $extra_headers = apply_filters( "extra_{$context}_headers", array() ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4220
		$extra_headers = array_combine( $extra_headers, $extra_headers ); // keys equal values
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4221
		$all_headers = array_merge( $extra_headers, (array) $default_headers );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4222
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4223
		$all_headers = $default_headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4224
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4225
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4226
	foreach ( $all_headers as $field => $regex ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4227
		if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4228
			$all_headers[ $field ] = _cleanup_header_comment( $match[1] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4229
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4230
			$all_headers[ $field ] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4231
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4232
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4233
	return $all_headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4234
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4235
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4236
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4237
 * Returns true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4238
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4239
 * Useful for returning true to filters easily.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4240
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4241
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4242
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4243
 * @see __return_false()
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4244
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4245
 * @return bool True.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4246
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4247
function __return_true() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4248
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4249
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4250
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4251
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4252
 * Returns false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4253
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4254
 * Useful for returning false to filters easily.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4255
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4256
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4257
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4258
 * @see __return_true()
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4259
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4260
 * @return bool False.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4261
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4262
function __return_false() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4263
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4264
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4265
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4266
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4267
 * Returns 0.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4268
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4269
 * Useful for returning 0 to filters easily.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4270
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4271
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4272
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4273
 * @return int 0.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4274
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4275
function __return_zero() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4276
	return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4277
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4278
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4279
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4280
 * Returns an empty array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4281
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4282
 * Useful for returning an empty array to filters easily.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4283
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4284
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4285
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4286
 * @return array Empty array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4287
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4288
function __return_empty_array() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4289
	return array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4290
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4291
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4292
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4293
 * Returns null.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4294
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4295
 * Useful for returning null to filters easily.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4296
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4297
 * @since 3.4.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4298
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4299
 * @return null Null value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4300
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4301
function __return_null() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4302
	return null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4303
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4304
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4305
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4306
 * Returns an empty string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4307
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4308
 * Useful for returning an empty string to filters easily.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4309
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4310
 * @since 3.7.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4311
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4312
 * @see __return_null()
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4313
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4314
 * @return string Empty string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4315
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4316
function __return_empty_string() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4317
	return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4318
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4319
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4320
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4321
 * Send a HTTP header to disable content type sniffing in browsers which support it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4322
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4323
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4324
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4325
 * @see http://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4326
 * @see http://src.chromium.org/viewvc/chrome?view=rev&revision=6985
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4327
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4328
function send_nosniff_header() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4329
	@header( 'X-Content-Type-Options: nosniff' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4330
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4331
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4332
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4333
 * Return a MySQL expression for selecting the week number based on the start_of_week option.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4334
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4335
 * @ignore
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4336
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4337
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4338
 * @param string $column Database column.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4339
 * @return string SQL clause.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4340
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4341
function _wp_mysql_week( $column ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4342
	switch ( $start_of_week = (int) get_option( 'start_of_week' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4343
	case 1 :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4344
		return "WEEK( $column, 1 )";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4345
	case 2 :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4346
	case 3 :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4347
	case 4 :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4348
	case 5 :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4349
	case 6 :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4350
		return "WEEK( DATE_SUB( $column, INTERVAL $start_of_week DAY ), 0 )";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4351
	case 0 :
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4352
	default :
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4353
		return "WEEK( $column, 0 )";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4354
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4355
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4356
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4357
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4358
 * Find hierarchy loops using a callback function that maps object IDs to parent IDs.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4359
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4360
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4361
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4362
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4363
 * @param callback $callback      Function that accepts ( ID, $callback_args ) and outputs parent_ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4364
 * @param int      $start         The ID to start the loop check at.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4365
 * @param int      $start_parent  The parent_ID of $start to use instead of calling $callback( $start ).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4366
 *                                Use null to always use $callback
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4367
 * @param array    $callback_args Optional. Additional arguments to send to $callback.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4368
 * @return array IDs of all members of loop.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4369
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4370
function wp_find_hierarchy_loop( $callback, $start, $start_parent, $callback_args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4371
	$override = is_null( $start_parent ) ? array() : array( $start => $start_parent );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4372
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4373
	if ( !$arbitrary_loop_member = wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override, $callback_args ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4374
		return array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4375
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4376
	return wp_find_hierarchy_loop_tortoise_hare( $callback, $arbitrary_loop_member, $override, $callback_args, true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4377
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4378
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4379
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4380
 * Use the "The Tortoise and the Hare" algorithm to detect loops.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4381
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4382
 * For every step of the algorithm, the hare takes two steps and the tortoise one.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4383
 * If the hare ever laps the tortoise, there must be a loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4384
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4385
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4386
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4387
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4388
 * @param callback $callback      Function that accepts ( ID, callback_arg, ... ) and outputs parent_ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4389
 * @param int      $start         The ID to start the loop check at.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4390
 * @param array    $override      Optional. An array of ( ID => parent_ID, ... ) to use instead of $callback.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4391
 *                                Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4392
 * @param array    $callback_args Optional. Additional arguments to send to $callback. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4393
 * @param bool     $_return_loop  Optional. Return loop members or just detect presence of loop? Only set
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4394
 *                                to true if you already know the given $start is part of a loop (otherwise
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4395
 *                                the returned array might include branches). Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4396
 * @return mixed Scalar ID of some arbitrary member of the loop, or array of IDs of all members of loop if
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4397
 *               $_return_loop
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4398
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4399
function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = array(), $callback_args = array(), $_return_loop = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4400
	$tortoise = $hare = $evanescent_hare = $start;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4401
	$return = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4402
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4403
	// Set evanescent_hare to one past hare
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4404
	// Increment hare two steps
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4405
	while (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4406
		$tortoise
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4407
	&&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4408
		( $evanescent_hare = isset( $override[$hare] ) ? $override[$hare] : call_user_func_array( $callback, array_merge( array( $hare ), $callback_args ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4409
	&&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4410
		( $hare = isset( $override[$evanescent_hare] ) ? $override[$evanescent_hare] : call_user_func_array( $callback, array_merge( array( $evanescent_hare ), $callback_args ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4411
	) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4412
		if ( $_return_loop )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4413
			$return[$tortoise] = $return[$evanescent_hare] = $return[$hare] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4414
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4415
		// tortoise got lapped - must be a loop
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4416
		if ( $tortoise == $evanescent_hare || $tortoise == $hare )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4417
			return $_return_loop ? $return : $tortoise;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4418
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4419
		// Increment tortoise by one step
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4420
		$tortoise = isset( $override[$tortoise] ) ? $override[$tortoise] : call_user_func_array( $callback, array_merge( array( $tortoise ), $callback_args ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4421
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4422
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4423
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4424
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4425
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4426
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4427
 * Send a HTTP header to limit rendering of pages to same origin iframes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4428
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4429
 * @since 3.1.3
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4430
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4431
 * @see https://developer.mozilla.org/en/the_x-frame-options_response_header
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4432
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4433
function send_frame_options_header() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4434
	@header( 'X-Frame-Options: SAMEORIGIN' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4435
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4436
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4437
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4438
 * Retrieve a list of protocols to allow in HTML attributes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4439
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4440
 * @since 3.3.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4441
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4442
 * @see wp_kses()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4443
 * @see esc_url()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4444
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4445
 * @return array Array of allowed protocols.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4446
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4447
function wp_allowed_protocols() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4448
	static $protocols;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4449
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4450
	if ( empty( $protocols ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4451
		$protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn', 'tel', 'fax', 'xmpp' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4452
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4453
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4454
		 * Filter the list of protocols allowed in HTML attributes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4455
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4456
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4457
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4458
		 * @param array $protocols Array of allowed protocols e.g. 'http', 'ftp', 'tel', and more.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4459
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4460
		$protocols = apply_filters( 'kses_allowed_protocols', $protocols );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4461
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4462
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4463
	return $protocols;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4464
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4465
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4466
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4467
 * Return a comma-separated string of functions that have been called to get
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4468
 * to the current point in code.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4469
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4470
 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4471
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4472
 * @see https://core.trac.wordpress.org/ticket/19589
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4473
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4474
 * @param string $ignore_class Optional. A class to ignore all function calls within - useful
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4475
 *                             when you want to just give info about the callee. Default null.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4476
 * @param int    $skip_frames  Optional. A number of stack frames to skip - useful for unwinding
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4477
 *                             back to the source of the issue. Default 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4478
 * @param bool   $pretty       Optional. Whether or not you want a comma separated string or raw
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4479
 *                             array returned. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4480
 * @return string|array Either a string containing a reversed comma separated trace or an array
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4481
 *                      of individual calls.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4482
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4483
function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4484
	if ( version_compare( PHP_VERSION, '5.2.5', '>=' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4485
		$trace = debug_backtrace( false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4486
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4487
		$trace = debug_backtrace();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4488
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4489
	$caller = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4490
	$check_class = ! is_null( $ignore_class );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4491
	$skip_frames++; // skip this function
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4492
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4493
	foreach ( $trace as $call ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4494
		if ( $skip_frames > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4495
			$skip_frames--;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4496
		} elseif ( isset( $call['class'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4497
			if ( $check_class && $ignore_class == $call['class'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4498
				continue; // Filter out calls
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4499
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4500
			$caller[] = "{$call['class']}{$call['type']}{$call['function']}";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4501
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4502
			if ( in_array( $call['function'], array( 'do_action', 'apply_filters' ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4503
				$caller[] = "{$call['function']}('{$call['args'][0]}')";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4504
			} elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4505
				$caller[] = $call['function'] . "('" . str_replace( array( WP_CONTENT_DIR, ABSPATH ) , '', $call['args'][0] ) . "')";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4506
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4507
				$caller[] = $call['function'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4508
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4509
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4510
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4511
	if ( $pretty )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4512
		return join( ', ', array_reverse( $caller ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4513
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4514
		return $caller;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4515
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4516
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4517
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4518
 * Retrieve ids that are not already present in the cache.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4519
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4520
 * @since 3.4.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4521
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4522
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4523
 * @param array  $object_ids ID list.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4524
 * @param string $cache_key  The cache bucket to check against.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4525
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4526
 * @return array List of ids not present in the cache.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4527
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4528
function _get_non_cached_ids( $object_ids, $cache_key ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4529
	$clean = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4530
	foreach ( $object_ids as $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4531
		$id = (int) $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4532
		if ( !wp_cache_get( $id, $cache_key ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4533
			$clean[] = $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4534
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4535
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4536
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4537
	return $clean;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4538
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4539
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4540
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4541
 * Test if the current device has the capability to upload files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4542
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4543
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4544
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4545
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4546
 * @return bool true|false Whether the device is able to upload files.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4547
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4548
function _device_can_upload() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4549
	if ( ! wp_is_mobile() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4550
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4551
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4552
	$ua = $_SERVER['HTTP_USER_AGENT'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4553
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4554
	if ( strpos($ua, 'iPhone') !== false
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4555
		|| strpos($ua, 'iPad') !== false
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4556
		|| strpos($ua, 'iPod') !== false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4557
			return preg_match( '#OS ([\d_]+) like Mac OS X#', $ua, $version ) && version_compare( $version[1], '6', '>=' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4558
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4559
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4560
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4561
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4562
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4563
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4564
 * Test if a given path is a stream URL
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4565
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4566
 * @param string $path The resource path or URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4567
 * @return bool True if the path is a stream URL.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4568
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4569
function wp_is_stream( $path ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4570
	$wrappers = stream_get_wrappers();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4571
	$wrappers_re = '(' . join('|', $wrappers) . ')';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4572
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4573
	return preg_match( "!^$wrappers_re://!", $path ) === 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4574
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4575
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4576
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4577
 * Test if the supplied date is valid for the Gregorian calendar.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4578
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4579
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4580
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4581
 * @see checkdate()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4582
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4583
 * @param  int    $month       Month number.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4584
 * @param  int    $day         Day number.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4585
 * @param  int    $year        Year number.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4586
 * @param  string $source_date The date to filter.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4587
 * @return bool True if valid date, false if not valid date.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4588
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4589
function wp_checkdate( $month, $day, $year, $source_date ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4590
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4591
	 * Filter whether the given date is valid for the Gregorian calendar.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4592
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4593
	 * @since 3.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4594
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4595
	 * @param bool   $checkdate   Whether the given date is valid.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4596
	 * @param string $source_date Date to check.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4597
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4598
	return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4599
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4600
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4601
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4602
 * Load the auth check for monitoring whether the user is still logged in.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4603
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4604
 * Can be disabled with remove_action( 'admin_enqueue_scripts', 'wp_auth_check_load' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4605
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4606
 * This is disabled for certain screens where a login screen could cause an
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4607
 * inconvenient interruption. A filter called wp_auth_check_load can be used
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4608
 * for fine-grained control.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4609
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4610
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4611
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4612
function wp_auth_check_load() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4613
	if ( ! is_admin() && ! is_user_logged_in() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4614
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4615
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4616
	if ( defined( 'IFRAME_REQUEST' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4617
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4618
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4619
	$screen = get_current_screen();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4620
	$hidden = array( 'update', 'update-network', 'update-core', 'update-core-network', 'upgrade', 'upgrade-network', 'network' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4621
	$show = ! in_array( $screen->id, $hidden );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4622
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4623
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4624
	 * Filter whether to load the authentication check.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4625
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4626
	 * Passing a falsey value to the filter will effectively short-circuit
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4627
	 * loading the authentication check.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4628
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4629
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4630
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4631
	 * @param bool      $show   Whether to load the authentication check.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4632
	 * @param WP_Screen $screen The current screen object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4633
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4634
	if ( apply_filters( 'wp_auth_check_load', $show, $screen ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4635
		wp_enqueue_style( 'wp-auth-check' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4636
		wp_enqueue_script( 'wp-auth-check' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4637
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4638
		add_action( 'admin_print_footer_scripts', 'wp_auth_check_html', 5 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4639
		add_action( 'wp_print_footer_scripts', 'wp_auth_check_html', 5 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4640
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4641
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4642
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4643
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4644
 * Output the HTML that shows the wp-login dialog when the user is no longer logged in.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4645
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4646
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4647
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4648
function wp_auth_check_html() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4649
	$login_url = wp_login_url();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4650
	$current_domain = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4651
	$same_domain = ( strpos( $login_url, $current_domain ) === 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4652
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4653
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4654
	 * Filter whether the authentication check originated at the same domain.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4655
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4656
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4657
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4658
	 * @param bool $same_domain Whether the authentication check originated at the same domain.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4659
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4660
	$same_domain = apply_filters( 'wp_auth_check_same_domain', $same_domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4661
	$wrap_class = $same_domain ? 'hidden' : 'hidden fallback';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4662
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4663
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4664
	<div id="wp-auth-check-wrap" class="<?php echo $wrap_class; ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4665
	<div id="wp-auth-check-bg"></div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4666
	<div id="wp-auth-check">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4667
	<div class="wp-auth-check-close" tabindex="0" title="<?php esc_attr_e('Close'); ?>"></div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4668
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4669
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4670
	if ( $same_domain ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4671
		?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4672
		<div id="wp-auth-check-form" data-src="<?php echo esc_url( add_query_arg( array( 'interim-login' => 1 ), $login_url ) ); ?>"></div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4673
		<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4674
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4675
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4676
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4677
	<div class="wp-auth-fallback">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4678
		<p><b class="wp-auth-fallback-expired" tabindex="0"><?php _e('Session expired'); ?></b></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4679
		<p><a href="<?php echo esc_url( $login_url ); ?>" target="_blank"><?php _e('Please log in again.'); ?></a>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4680
		<?php _e('The login page will open in a new window. After logging in you can close it and return to this page.'); ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4681
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4682
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4683
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4684
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4685
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4686
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4687
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4688
 * Check whether a user is still logged in, for the heartbeat.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4689
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4690
 * Send a result that shows a log-in box if the user is no longer logged in,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4691
 * or if their cookie is within the grace period.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4692
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4693
 * @since 3.6.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4694
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4695
 * @param array|object $response  The Heartbeat response object or array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4696
 * @return array|object $response The Heartbeat response object or array with 'wp-auth-check'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4697
 *                                value set.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4698
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4699
function wp_auth_check( $response ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4700
	$response['wp-auth-check'] = is_user_logged_in() && empty( $GLOBALS['login_grace_period'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4701
	return $response;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4702
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4703
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4704
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4705
 * Return RegEx body to liberally match an opening HTML tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4706
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4707
 * Matches an opening HTML tag that:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4708
 * 1. Is self-closing or
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4709
 * 2. Has no body but has a closing tag of the same name or
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4710
 * 3. Contains a body and a closing tag of the same name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4711
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4712
 * Note: this RegEx does not balance inner tags and does not attempt
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4713
 * to produce valid HTML
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4714
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4715
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4716
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4717
 * @param string $tag An HTML tag name. Example: 'video'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4718
 * @return string Tag RegEx.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4719
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4720
function get_tag_regex( $tag ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4721
	if ( empty( $tag ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4722
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4723
	return sprintf( '<%1$s[^<]*(?:>[\s\S]*<\/%1$s>|\s*\/>)', tag_escape( $tag ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4724
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4725
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4726
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4727
 * Retrieve a canonical form of the provided charset appropriate for passing to PHP
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4728
 * functions such as htmlspecialchars() and charset html attributes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4729
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4730
 * @since 3.6.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4731
 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4732
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4733
 * @see https://core.trac.wordpress.org/ticket/23688
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4734
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4735
 * @param string $charset A charset name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4736
 * @return string The canonical form of the charset.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4737
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4738
function _canonical_charset( $charset ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4739
	if ( 'UTF-8' === $charset || 'utf-8' === $charset || 'utf8' === $charset ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4740
		'UTF8' === $charset )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4741
		return 'UTF-8';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4742
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4743
	if ( 'ISO-8859-1' === $charset || 'iso-8859-1' === $charset ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4744
		'iso8859-1' === $charset || 'ISO8859-1' === $charset )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4745
		return 'ISO-8859-1';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4746
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4747
	return $charset;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4748
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4749
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4750
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4751
 * Set the mbstring internal encoding to a binary safe encoding when func_overload
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4752
 * is enabled.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4753
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4754
 * When mbstring.func_overload is in use for multi-byte encodings, the results from
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4755
 * strlen() and similar functions respect the utf8 characters, causing binary data
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4756
 * to return incorrect lengths.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4757
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4758
 * This function overrides the mbstring encoding to a binary-safe encoding, and
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4759
 * resets it to the users expected encoding afterwards through the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4760
 * `reset_mbstring_encoding` function.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4761
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4762
 * It is safe to recursively call this function, however each
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4763
 * `mbstring_binary_safe_encoding()` call must be followed up with an equal number
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4764
 * of `reset_mbstring_encoding()` calls.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4765
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4766
 * @since 3.7.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4767
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4768
 * @see reset_mbstring_encoding()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4769
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4770
 * @param bool $reset Optional. Whether to reset the encoding back to a previously-set encoding.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4771
 *                    Default false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4772
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4773
function mbstring_binary_safe_encoding( $reset = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4774
	static $encodings = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4775
	static $overloaded = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4776
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4777
	if ( is_null( $overloaded ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4778
		$overloaded = function_exists( 'mb_internal_encoding' ) && ( ini_get( 'mbstring.func_overload' ) & 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4779
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4780
	if ( false === $overloaded )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4781
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4782
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4783
	if ( ! $reset ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4784
		$encoding = mb_internal_encoding();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4785
		array_push( $encodings, $encoding );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4786
		mb_internal_encoding( 'ISO-8859-1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4787
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4788
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4789
	if ( $reset && $encodings ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4790
		$encoding = array_pop( $encodings );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4791
		mb_internal_encoding( $encoding );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4792
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4793
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4794
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4795
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4796
 * Reset the mbstring internal encoding to a users previously set encoding.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4797
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4798
 * @see mbstring_binary_safe_encoding()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4799
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4800
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4801
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4802
function reset_mbstring_encoding() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4803
	mbstring_binary_safe_encoding( true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4804
}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4805
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4806
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4807
 * Filter/validate a variable as a boolean.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4808
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4809
 * Alternative to `filter_var( $var, FILTER_VALIDATE_BOOLEAN )`.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4810
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4811
 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4812
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4813
 * @param mixed $var Boolean value to validate.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4814
 * @return bool Whether the value is validated.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4815
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4816
function wp_validate_boolean( $var ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4817
	if ( is_bool( $var ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4818
		return $var;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4819
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4820
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4821
	if ( is_string( $var ) && 'false' === strtolower( $var ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4822
		return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4823
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4824
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4825
	return (bool) $var;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4826
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4827
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4828
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4829
 * Delete a file
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4830
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4831
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4832
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4833
 * @param string $file The path to the file to delete.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4834
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4835
function wp_delete_file( $file ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4836
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4837
	 * Filter the path of the file to delete.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4838
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4839
	 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4840
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4841
	 * @param string $medium Path to the file to delete.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4842
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4843
	$delete = apply_filters( 'wp_delete_file', $file );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4844
	if ( ! empty( $delete ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4845
		@unlink( $delete );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4846
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4847
}