web/wp-includes/functions.php
branchwordpress
changeset 132 4d4862461b8d
parent 109 03b0d1493584
equal deleted inserted replaced
131:a4642baaf829 132:4d4862461b8d
   495 function update_option( $option_name, $newvalue ) {
   495 function update_option( $option_name, $newvalue ) {
   496 	global $wpdb;
   496 	global $wpdb;
   497 
   497 
   498 	wp_protect_special_option( $option_name );
   498 	wp_protect_special_option( $option_name );
   499 
   499 
   500 	$safe_option_name = $wpdb->escape( $option_name );
   500 	$safe_option_name = esc_sql( $option_name );
   501 	$newvalue = sanitize_option( $option_name, $newvalue );
   501 	$newvalue = sanitize_option( $option_name, $newvalue );
   502 
   502 
   503 	$oldvalue = get_option( $safe_option_name );
   503 	$oldvalue = get_option( $safe_option_name );
   504 
   504 
   505 	$newvalue = apply_filters( 'pre_update_option_' . $option_name, $newvalue, $oldvalue );
   505 	$newvalue = apply_filters( 'pre_update_option_' . $option_name, $newvalue, $oldvalue );
   520 	}
   520 	}
   521 
   521 
   522 	$_newvalue = $newvalue;
   522 	$_newvalue = $newvalue;
   523 	$newvalue = maybe_serialize( $newvalue );
   523 	$newvalue = maybe_serialize( $newvalue );
   524 
   524 
       
   525 	do_action( 'update_option', $option_name, $oldvalue, $newvalue );
   525 	$alloptions = wp_load_alloptions();
   526 	$alloptions = wp_load_alloptions();
   526 	if ( isset( $alloptions[$option_name] ) ) {
   527 	if ( isset( $alloptions[$option_name] ) ) {
   527 		$alloptions[$option_name] = $newvalue;
   528 		$alloptions[$option_name] = $newvalue;
   528 		wp_cache_set( 'alloptions', $alloptions, 'options' );
   529 		wp_cache_set( 'alloptions', $alloptions, 'options' );
   529 	} else {
   530 	} else {
   532 
   533 
   533 	$wpdb->update($wpdb->options, array('option_value' => $newvalue), array('option_name' => $option_name) );
   534 	$wpdb->update($wpdb->options, array('option_value' => $newvalue), array('option_name' => $option_name) );
   534 
   535 
   535 	if ( $wpdb->rows_affected == 1 ) {
   536 	if ( $wpdb->rows_affected == 1 ) {
   536 		do_action( "update_option_{$option_name}", $oldvalue, $_newvalue );
   537 		do_action( "update_option_{$option_name}", $oldvalue, $_newvalue );
       
   538 		do_action( 'updated_option', $option_name, $oldvalue, $_newvalue );
   537 		return true;
   539 		return true;
   538 	}
   540 	}
   539 	return false;
   541 	return false;
   540 }
   542 }
   541 
   543 
   569  */
   571  */
   570 function add_option( $name, $value = '', $deprecated = '', $autoload = 'yes' ) {
   572 function add_option( $name, $value = '', $deprecated = '', $autoload = 'yes' ) {
   571 	global $wpdb;
   573 	global $wpdb;
   572 
   574 
   573 	wp_protect_special_option( $name );
   575 	wp_protect_special_option( $name );
   574 	$safe_name = $wpdb->escape( $name );
   576 	$safe_name = esc_sql( $name );
   575 	$value = sanitize_option( $name, $value );
   577 	$value = sanitize_option( $name, $value );
   576 
   578 
   577 	// Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
   579 	// Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
   578 	$notoptions = wp_cache_get( 'notoptions', 'options' );
   580 	$notoptions = wp_cache_get( 'notoptions', 'options' );
   579 	if ( !is_array( $notoptions ) || !isset( $notoptions[$name] ) )
   581 	if ( !is_array( $notoptions ) || !isset( $notoptions[$name] ) )
   580 		if ( false !== get_option( $safe_name ) )
   582 		if ( false !== get_option( $safe_name ) )
   581 			return;
   583 			return;
   582 
   584 
   583 	$value = maybe_serialize( $value );
   585 	$value = maybe_serialize( $value );
   584 	$autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
   586 	$autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
   585 
   587 	do_action( 'add_option', $name, $value );
   586 	if ( 'yes' == $autoload ) {
   588 	if ( 'yes' == $autoload ) {
   587 		$alloptions = wp_load_alloptions();
   589 		$alloptions = wp_load_alloptions();
   588 		$alloptions[$name] = $value;
   590 		$alloptions[$name] = $value;
   589 		wp_cache_set( 'alloptions', $alloptions, 'options' );
   591 		wp_cache_set( 'alloptions', $alloptions, 'options' );
   590 	} else {
   592 	} else {
   596 	if ( is_array( $notoptions ) && isset( $notoptions[$name] ) ) {
   598 	if ( is_array( $notoptions ) && isset( $notoptions[$name] ) ) {
   597 		unset( $notoptions[$name] );
   599 		unset( $notoptions[$name] );
   598 		wp_cache_set( 'notoptions', $notoptions, 'options' );
   600 		wp_cache_set( 'notoptions', $notoptions, 'options' );
   599 	}
   601 	}
   600 
   602 
   601 	$wpdb->insert($wpdb->options, array('option_name' => $name, 'option_value' => $value, 'autoload' => $autoload) );
   603 	$wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $name, $value, $autoload ) );
   602 
   604 
   603 	do_action( "add_option_{$name}", $name, $value );
   605 	do_action( "add_option_{$name}", $name, $value );
       
   606 	do_action( 'added_option', $name, $value );
       
   607 	
   604 	return;
   608 	return;
   605 }
   609 }
   606 
   610 
   607 /**
   611 /**
   608  * Removes option by name and prevents removal of protected WordPress options.
   612  * Removes option by name and prevents removal of protected WordPress options.
   619 
   623 
   620 	wp_protect_special_option( $name );
   624 	wp_protect_special_option( $name );
   621 
   625 
   622 	// Get the ID, if no ID then return
   626 	// Get the ID, if no ID then return
   623 	// expected_slashed ($name)
   627 	// expected_slashed ($name)
   624 	$option = $wpdb->get_row( "SELECT option_id, autoload FROM $wpdb->options WHERE option_name = '$name'" );
   628 	$option = $wpdb->get_row( "SELECT autoload FROM $wpdb->options WHERE option_name = '$name'" );
   625 	if ( is_null($option) || !$option->option_id )
   629 	if ( is_null($option) )
   626 		return false;
   630 		return false;
       
   631 	do_action( 'delete_option', $name );
   627 	// expected_slashed ($name)
   632 	// expected_slashed ($name)
   628 	$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" );
   633 	$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" );
   629 	if ( 'yes' == $option->autoload ) {
   634 	if ( 'yes' == $option->autoload ) {
   630 		$alloptions = wp_load_alloptions();
   635 		$alloptions = wp_load_alloptions();
   631 		if ( isset( $alloptions[$name] ) ) {
   636 		if ( isset( $alloptions[$name] ) ) {
   633 			wp_cache_set( 'alloptions', $alloptions, 'options' );
   638 			wp_cache_set( 'alloptions', $alloptions, 'options' );
   634 		}
   639 		}
   635 	} else {
   640 	} else {
   636 		wp_cache_delete( $name, 'options' );
   641 		wp_cache_delete( $name, 'options' );
   637 	}
   642 	}
       
   643 	do_action( 'deleted_option', $name );
   638 	return true;
   644 	return true;
   639 }
   645 }
   640 
   646 
   641 /**
   647 /**
   642  * Delete a transient
   648  * Delete a transient
   652 	global $_wp_using_ext_object_cache, $wpdb;
   658 	global $_wp_using_ext_object_cache, $wpdb;
   653 
   659 
   654 	if ( $_wp_using_ext_object_cache ) {
   660 	if ( $_wp_using_ext_object_cache ) {
   655 		return wp_cache_delete($transient, 'transient');
   661 		return wp_cache_delete($transient, 'transient');
   656 	} else {
   662 	} else {
   657 		$transient = '_transient_' . $wpdb->escape($transient);
   663 		$transient = '_transient_' . esc_sql($transient);
   658 		return delete_option($transient);
   664 		return delete_option($transient);
   659 	}
   665 	}
   660 }
   666 }
   661 
   667 
   662 /**
   668 /**
   680 		return $pre;
   686 		return $pre;
   681 
   687 
   682 	if ( $_wp_using_ext_object_cache ) {
   688 	if ( $_wp_using_ext_object_cache ) {
   683 		$value = wp_cache_get($transient, 'transient');
   689 		$value = wp_cache_get($transient, 'transient');
   684 	} else {
   690 	} else {
   685 		$transient_option = '_transient_' . $wpdb->escape($transient);
   691 		$transient_option = '_transient_' . esc_sql($transient);
   686 		// If option is not in alloptions, it is not autoloaded and thus has a timeout
   692 		// If option is not in alloptions, it is not autoloaded and thus has a timeout
   687 		$alloptions = wp_load_alloptions();
   693 		$alloptions = wp_load_alloptions();
   688 		if ( !isset( $alloptions[$transient_option] ) ) {
   694 		if ( !isset( $alloptions[$transient_option] ) ) {
   689 			$transient_timeout = '_transient_timeout_' . $wpdb->escape($transient);
   695 			$transient_timeout = '_transient_timeout_' . esc_sql($transient);
   690 			if ( get_option($transient_timeout) < time() ) {
   696 			if ( get_option($transient_timeout) < time() ) {
   691 				delete_option($transient_option);
   697 				delete_option($transient_option);
   692 				delete_option($transient_timeout);
   698 				delete_option($transient_timeout);
   693 				return false;
   699 				return false;
   694 			}
   700 			}
   721 	if ( $_wp_using_ext_object_cache ) {
   727 	if ( $_wp_using_ext_object_cache ) {
   722 		return wp_cache_set($transient, $value, 'transient', $expiration);
   728 		return wp_cache_set($transient, $value, 'transient', $expiration);
   723 	} else {
   729 	} else {
   724 		$transient_timeout = '_transient_timeout_' . $transient;
   730 		$transient_timeout = '_transient_timeout_' . $transient;
   725 		$transient = '_transient_' . $transient;
   731 		$transient = '_transient_' . $transient;
   726 		$safe_transient = $wpdb->escape($transient);
   732 		$safe_transient = esc_sql($transient);
   727 		if ( false === get_option( $safe_transient ) ) {
   733 		if ( false === get_option( $safe_transient ) ) {
   728 			$autoload = 'yes';
   734 			$autoload = 'yes';
   729 			if ( 0 != $expiration ) {
   735 			if ( 0 != $expiration ) {
   730 				$autoload = 'no';
   736 				$autoload = 'no';
   731 				add_option($transient_timeout, time() + $expiration, '', 'no');
   737 				add_option($transient_timeout, time() + $expiration, '', 'no');
   963 
   969 
   964 	return $data;
   970 	return $data;
   965 }
   971 }
   966 
   972 
   967 /**
   973 /**
   968  * Strip HTML and put links at the bottom of stripped content.
       
   969  *
       
   970  * Searches for all of the links, strips them out of the content, and places
       
   971  * them at the bottom of the content with numbers.
       
   972  *
       
   973  * @since 0.71
       
   974  *
       
   975  * @param string $content Content to get links
       
   976  * @return string HTML stripped out of content with links at the bottom.
       
   977  */
       
   978 function make_url_footnote( $content ) {
       
   979 	preg_match_all( '/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches );
       
   980 	$links_summary = "\n";
       
   981 	for ( $i=0; $i<count($matches[0]); $i++ ) {
       
   982 		$link_match = $matches[0][$i];
       
   983 		$link_number = '['.($i+1).']';
       
   984 		$link_url = $matches[2][$i];
       
   985 		$link_text = $matches[4][$i];
       
   986 		$content = str_replace( $link_match, $link_text . ' ' . $link_number, $content );
       
   987 		$link_url = ( ( strtolower( substr( $link_url, 0, 7 ) ) != 'http://' ) && ( strtolower( substr( $link_url, 0, 8 ) ) != 'https://' ) ) ? get_option( 'home' ) . $link_url : $link_url;
       
   988 		$links_summary .= "\n" . $link_number . ' ' . $link_url;
       
   989 	}
       
   990 	$content  = strip_tags( $content );
       
   991 	$content .= $links_summary;
       
   992 	return $content;
       
   993 }
       
   994 
       
   995 /**
       
   996  * Retrieve post title from XMLRPC XML.
   974  * Retrieve post title from XMLRPC XML.
   997  *
   975  *
   998  * If the title element is not part of the XML, then the default post title from
   976  * If the title element is not part of the XML, then the default post title from
   999  * the $post_default_title will be used instead.
   977  * the $post_default_title will be used instead.
  1000  *
   978  *
  1161 	debug_fwrite( $log, 'Post contents:' );
  1139 	debug_fwrite( $log, 'Post contents:' );
  1162 	debug_fwrite( $log, $content . "\n" );
  1140 	debug_fwrite( $log, $content . "\n" );
  1163 
  1141 
  1164 	foreach ( $pung as $link_test ) {
  1142 	foreach ( $pung as $link_test ) {
  1165 		if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post
  1143 		if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post
  1166 			$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $link_test . '%') );
  1144 			$mid = $wpdb->get_col( $wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $link_test . '%') );
       
  1145 			do_action( 'delete_postmeta', $mid );
       
  1146 			$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE post_id IN(%s)", implode( ',', $mid ) ) );
       
  1147 			do_action( 'deleted_postmeta', $mid );
  1167 		}
  1148 		}
  1168 	}
  1149 	}
  1169 
  1150 
  1170 	foreach ( (array) $post_links_temp[0] as $link_test ) {
  1151 	foreach ( (array) $post_links_temp[0] as $link_test ) {
  1171 		if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already
  1152 		if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already
  1184 				$type = $headers['content-type'];
  1165 				$type = $headers['content-type'];
  1185 				$allowed_types = array( 'video', 'audio' );
  1166 				$allowed_types = array( 'video', 'audio' );
  1186 				if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
  1167 				if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
  1187 					$meta_value = "$url\n$len\n$type\n";
  1168 					$meta_value = "$url\n$len\n$type\n";
  1188 					$wpdb->insert($wpdb->postmeta, array('post_id' => $post_ID, 'meta_key' => 'enclosure', 'meta_value' => $meta_value) );
  1169 					$wpdb->insert($wpdb->postmeta, array('post_id' => $post_ID, 'meta_key' => 'enclosure', 'meta_value' => $meta_value) );
       
  1170 					do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, 'enclosure', $meta_value );
  1189 				}
  1171 				}
  1190 			}
  1172 			}
  1191 		}
  1173 		}
  1192 	}
  1174 	}
  1193 }
  1175 }
  1406 
  1388 
  1407 	foreach ( (array) $array as $k => $v ) {
  1389 	foreach ( (array) $array as $k => $v ) {
  1408 		if ( is_array( $v ) ) {
  1390 		if ( is_array( $v ) ) {
  1409 			$array[$k] = add_magic_quotes( $v );
  1391 			$array[$k] = add_magic_quotes( $v );
  1410 		} else {
  1392 		} else {
  1411 			$array[$k] = $wpdb->escape( $v );
  1393 			$array[$k] = esc_sql( $v );
  1412 		}
  1394 		}
  1413 	}
  1395 	}
  1414 	return $array;
  1396 	return $array;
  1415 }
  1397 }
  1416 
  1398 
  1769 	$wpdb->suppress_errors( $suppress );
  1751 	$wpdb->suppress_errors( $suppress );
  1770 
  1752 
  1771 	$installed = !empty( $installed );
  1753 	$installed = !empty( $installed );
  1772 	wp_cache_set( 'is_blog_installed', $installed );
  1754 	wp_cache_set( 'is_blog_installed', $installed );
  1773 
  1755 
  1774 	return $installed;
  1756 	if ( $installed )
       
  1757 		return true;
       
  1758 
       
  1759 	$suppress = $wpdb->suppress_errors();
       
  1760 	$tables = $wpdb->get_col('SHOW TABLES');
       
  1761 	$wpdb->suppress_errors( $suppress );
       
  1762 
       
  1763 	// Loop over the WP tables.  If none exist, then scratch install is allowed.
       
  1764 	// If one or more exist, suggest table repair since we got here because the options
       
  1765 	// table could not be accessed.
       
  1766 	foreach ($wpdb->tables as $table) {
       
  1767 		// If one of the WP tables exist, then we are in an insane state.
       
  1768 		if ( in_array($wpdb->prefix . $table, $tables) ) {
       
  1769 			// If visiting repair.php, return true and let it take over.
       
  1770 			if ( defined('WP_REPAIRING') )
       
  1771 				return true;
       
  1772 			// Die with a DB error.
       
  1773 			$wpdb->error = __('One or more database tables are unavailable.  The database may need to be <a href="maint/repair.php?referrer=is_blog_installed">repaired</a>.');
       
  1774 			dead_db();
       
  1775 		}
       
  1776 	}
       
  1777 
       
  1778 	wp_cache_set( 'is_blog_installed', false );
       
  1779 
       
  1780 	return false;
  1775 }
  1781 }
  1776 
  1782 
  1777 /**
  1783 /**
  1778  * Retrieve URL with nonce added to URL query.
  1784  * Retrieve URL with nonce added to URL query.
  1779  *
  1785  *
  2027  */
  2033  */
  2028 function wp_upload_dir( $time = null ) {
  2034 function wp_upload_dir( $time = null ) {
  2029 	$siteurl = get_option( 'siteurl' );
  2035 	$siteurl = get_option( 'siteurl' );
  2030 	$upload_path = get_option( 'upload_path' );
  2036 	$upload_path = get_option( 'upload_path' );
  2031 	$upload_path = trim($upload_path);
  2037 	$upload_path = trim($upload_path);
  2032 	if ( empty($upload_path) )
  2038 	if ( empty($upload_path) ) {
  2033 		$dir = WP_CONTENT_DIR . '/uploads';
  2039 		$dir = WP_CONTENT_DIR . '/uploads';
  2034 	else
  2040 	} else {
  2035 		$dir = $upload_path;
  2041 		$dir = $upload_path;
  2036 
  2042 		if ( 'wp-content/uploads' == $upload_path ) {
  2037 	// $dir is absolute, $path is (maybe) relative to ABSPATH
  2043 			$dir = WP_CONTENT_DIR . '/uploads';
  2038 	$dir = path_join( ABSPATH, $dir );
  2044 		} elseif ( 0 !== strpos($dir, ABSPATH) ) {
       
  2045 			// $dir is absolute, $upload_path is (maybe) relative to ABSPATH
       
  2046 			$dir = path_join( ABSPATH, $dir );
       
  2047 		}
       
  2048 	}
  2039 
  2049 
  2040 	if ( !$url = get_option( 'upload_url_path' ) ) {
  2050 	if ( !$url = get_option( 'upload_url_path' ) ) {
  2041 		if ( empty($upload_path) or ( $upload_path == $dir ) )
  2051 		if ( empty($upload_path) || ( 'wp-content/uploads' == $upload_path ) || ( $upload_path == $dir ) )
  2042 			$url = WP_CONTENT_URL . '/uploads';
  2052 			$url = WP_CONTENT_URL . '/uploads';
  2043 		else
  2053 		else
  2044 			$url = trailingslashit( $siteurl ) . $upload_path;
  2054 			$url = trailingslashit( $siteurl ) . $upload_path;
  2045 	}
  2055 	}
  2046 
  2056 
  2097 	// sanitize the file name before we begin processing
  2107 	// sanitize the file name before we begin processing
  2098 	$filename = sanitize_file_name($filename);
  2108 	$filename = sanitize_file_name($filename);
  2099 
  2109 
  2100 	// separate the filename into a name and extension
  2110 	// separate the filename into a name and extension
  2101 	$info = pathinfo($filename);
  2111 	$info = pathinfo($filename);
  2102 	$ext = !empty($info['extension']) ? $info['extension'] : '';
  2112 	$ext = !empty($info['extension']) ? '.' . $info['extension'] : '';
  2103 	$name = basename($filename, ".{$ext}");
  2113 	$name = basename($filename, $ext);
  2104 
  2114 
  2105 	// edge case: if file is named '.ext', treat as an empty name
  2115 	// edge case: if file is named '.ext', treat as an empty name
  2106 	if( $name === ".$ext" )
  2116 	if( $name === $ext )
  2107 		$name = '';
  2117 		$name = '';
  2108 
  2118 
  2109 	// Increment the file number until we have a unique file to save in $dir. Use $override['unique_filename_callback'] if supplied.
  2119 	// Increment the file number until we have a unique file to save in $dir. Use $override['unique_filename_callback'] if supplied.
  2110 	if ( $unique_filename_callback && function_exists( $unique_filename_callback ) ) {
  2120 	if ( $unique_filename_callback && function_exists( $unique_filename_callback ) ) {
  2111 		$filename = $unique_filename_callback( $dir, $name );
  2121 		$filename = $unique_filename_callback( $dir, $name );
  2112 	} else {
  2122 	} else {
  2113 		$number = '';
  2123 		$number = '';
  2114 
  2124 
  2115 		if ( !empty( $ext ) )
  2125 		// change '.ext' to lower case
  2116 			$ext = ".$ext";
  2126 		if ( $ext && strtolower($ext) != $ext ) {
       
  2127 			$ext2 = strtolower($ext);
       
  2128 			$filename2 = preg_replace( '|' . preg_quote($ext) . '$|', $ext2, $filename );
       
  2129 
       
  2130 			// check for both lower and upper case extension or image sub-sizes may be overwritten
       
  2131 			while ( file_exists($dir . "/$filename") || file_exists($dir . "/$filename2") ) {
       
  2132 				$new_number = $number + 1;
       
  2133 				$filename = str_replace( "$number$ext", "$new_number$ext", $filename );
       
  2134 				$filename2 = str_replace( "$number$ext2", "$new_number$ext2", $filename2 );
       
  2135 				$number = $new_number;
       
  2136 			}
       
  2137 			return $filename2;
       
  2138 		}
  2117 
  2139 
  2118 		while ( file_exists( $dir . "/$filename" ) ) {
  2140 		while ( file_exists( $dir . "/$filename" ) ) {
  2119 			if ( '' == "$number$ext" )
  2141 			if ( '' == "$number$ext" )
  2120 				$filename = $filename . ++$number . $ext;
  2142 				$filename = $filename . ++$number . $ext;
  2121 			else
  2143 			else
  2263 		'tif|tiff' => 'image/tiff',
  2285 		'tif|tiff' => 'image/tiff',
  2264 		'ico' => 'image/x-icon',
  2286 		'ico' => 'image/x-icon',
  2265 		'asf|asx|wax|wmv|wmx' => 'video/asf',
  2287 		'asf|asx|wax|wmv|wmx' => 'video/asf',
  2266 		'avi' => 'video/avi',
  2288 		'avi' => 'video/avi',
  2267 		'divx' => 'video/divx',
  2289 		'divx' => 'video/divx',
       
  2290 		'flv' => 'video/x-flv',
  2268 		'mov|qt' => 'video/quicktime',
  2291 		'mov|qt' => 'video/quicktime',
  2269 		'mpeg|mpg|mpe' => 'video/mpeg',
  2292 		'mpeg|mpg|mpe' => 'video/mpeg',
  2270 		'txt|c|cc|h' => 'text/plain',
  2293 		'txt|c|cc|h' => 'text/plain',
  2271 		'rtx' => 'text/richtext',
  2294 		'rtx' => 'text/richtext',
  2272 		'css' => 'text/css',
  2295 		'css' => 'text/css',
  2397 			} else {
  2420 			} else {
  2398 				return $trans[$verb][$noun][0];
  2421 				return $trans[$verb][$noun][0];
  2399 			}
  2422 			}
  2400 		}
  2423 		}
  2401 
  2424 
  2402 		return apply_filters( 'explain_nonce_' . $verb . '-' . $noun, __( 'Are you sure you want to do this?' ), $matches[4] );
  2425 		return apply_filters( 'explain_nonce_' . $verb . '-' . $noun, __( 'Are you sure you want to do this?' ), isset($matches[4]) ? $matches[4] : '' );
  2403 	} else {
  2426 	} else {
  2404 		return apply_filters( 'explain_nonce_' . $action, __( 'Are you sure you want to do this?' ) );
  2427 		return apply_filters( 'explain_nonce_' . $action, __( 'Are you sure you want to do this?' ) );
  2405 	}
  2428 	}
  2406 }
  2429 }
  2407 
  2430 
  2418  * @param string $action The nonce action.
  2441  * @param string $action The nonce action.
  2419  */
  2442  */
  2420 function wp_nonce_ays( $action ) {
  2443 function wp_nonce_ays( $action ) {
  2421 	$title = __( 'WordPress Failure Notice' );
  2444 	$title = __( 'WordPress Failure Notice' );
  2422 	$html = esc_html( wp_explain_nonce( $action ) );
  2445 	$html = esc_html( wp_explain_nonce( $action ) );
  2423 	if ( wp_get_referer() )
  2446 	if ( 'log-out' == $action )
       
  2447 		$html .= "</p><p>" . sprintf( __( "Do you really want to <a href='%s'>log out</a>?"), wp_logout_url() );
       
  2448 	elseif ( wp_get_referer() )
  2424 		$html .= "</p><p><a href='" . esc_url( remove_query_arg( 'updated', wp_get_referer() ) ) . "'>" . __( 'Please try again.' ) . "</a>";
  2449 		$html .= "</p><p><a href='" . esc_url( remove_query_arg( 'updated', wp_get_referer() ) ) . "'>" . __( 'Please try again.' ) . "</a>";
  2425 	elseif ( 'log-out' == $action )
  2450 
  2426 		$html .= "</p><p>" . sprintf( __( "Do you really want to <a href='%s'>log out</a>?"), wp_logout_url() );
  2451 	wp_die( $html, $title, array('response' => 403) );
  2427 
       
  2428 	wp_die( $html, $title);
       
  2429 }
  2452 }
  2430 
  2453 
  2431 /**
  2454 /**
  2432  * Kill WordPress execution and display HTML message with error message.
  2455  * Kill WordPress execution and display HTML message with error message.
  2433  *
  2456  *
  2501 	$text_direction = 'ltr';
  2524 	$text_direction = 'ltr';
  2502 	if ( isset($r['text_direction']) && $r['text_direction'] == 'rtl' ) $text_direction = 'rtl';
  2525 	if ( isset($r['text_direction']) && $r['text_direction'] == 'rtl' ) $text_direction = 'rtl';
  2503 	if ( ( $wp_locale ) && ( 'rtl' == $wp_locale->text_direction ) ) $text_direction = 'rtl';
  2526 	if ( ( $wp_locale ) && ( 'rtl' == $wp_locale->text_direction ) ) $text_direction = 'rtl';
  2504 ?>
  2527 ?>
  2505 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2528 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       
  2529 <!-- Ticket #11289, IE bug fix: always pad the error page with enough characters such that it is greater than 512 bytes, even after gzip compression abcdefghijklmnopqrstuvwxyz1234567890aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz11223344556677889900abacbcbdcdcededfefegfgfhghgihihjijikjkjlklkmlmlnmnmononpopoqpqprqrqsrsrtstsubcbcdcdedefefgfabcadefbghicjkldmnoepqrfstugvwxhyz1i234j567k890laabmbccnddeoeffpgghqhiirjjksklltmmnunoovppqwqrrxsstytuuzvvw0wxx1yyz2z113223434455666777889890091abc2def3ghi4jkl5mno6pqr7stu8vwx9yz11aab2bcc3dd4ee5ff6gg7hh8ii9j0jk1kl2lmm3nnoo4p5pq6qrr7ss8tt9uuvv0wwx1x2yyzz13aba4cbcb5dcdc6dedfef8egf9gfh0ghg1ihi2hji3jik4jkj5lkl6kml7mln8mnm9ono -->
  2506 <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) ) language_attributes(); ?>>
  2530 <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) ) language_attributes(); ?>>
  2507 <head>
  2531 <head>
  2508 	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  2532 	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  2509 	<title><?php echo $title ?></title>
  2533 	<title><?php echo $title ?></title>
  2510 	<link rel="stylesheet" href="<?php echo $admin_dir; ?>css/install.css" type="text/css" />
  2534 	<link rel="stylesheet" href="<?php echo $admin_dir; ?>css/install.css" type="text/css" />
  2515 </head>
  2539 </head>
  2516 <body id="error-page">
  2540 <body id="error-page">
  2517 <?php endif; ?>
  2541 <?php endif; ?>
  2518 	<?php echo $message; ?>
  2542 	<?php echo $message; ?>
  2519 </body>
  2543 </body>
  2520 <!-- Ticket #8942, IE bug fix: always pad the error page with enough characters such that it is greater than 512 bytes, even after gzip compression abcdefghijklmnopqrstuvwxyz1234567890aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz11223344556677889900abacbcbdcdcededfefegfgfhghgihihjijikjkjlklkmlmlnmnmononpopoqpqprqrqsrsrtstsubcbcdcdedefefgfabcadefbghicjkldmnoepqrfstugvwxhyz1i234j567k890laabmbccnddeoeffpgghqhiirjjksklltmmnunoovppqwqrrxsstytuuzvvw0wxx1yyz2z113223434455666777889890091abc2def3ghi4jkl5mno6pqr7stu8vwx9yz11aab2bcc3dd4ee5ff6gg7hh8ii9j0jk1kl2lmm3nnoo4p5pq6qrr7ss8tt9uuvv0wwx1x2yyzz13aba4cbcb5dcdc6dedfef8egf9gfh0ghg1ihi2hji3jik4jkj5lkl6kml7mln8mnm9ono -->
       
  2521 </html>
  2544 </html>
  2522 <?php
  2545 <?php
  2523 	die();
  2546 	die();
  2524 }
  2547 }
  2525 
  2548 
  2728 		return array_merge( $defaults, $r );
  2751 		return array_merge( $defaults, $r );
  2729 	return $r;
  2752 	return $r;
  2730 }
  2753 }
  2731 
  2754 
  2732 /**
  2755 /**
       
  2756  * Determines if default embed handlers should be loaded.
       
  2757  *
       
  2758  * Checks to make sure that the embeds library hasn't already been loaded. If
       
  2759  * it hasn't, then it will load the embeds library.
       
  2760  *
       
  2761  * @since 2.9
       
  2762  */
       
  2763 function wp_maybe_load_embeds() {
       
  2764 	if ( ! apply_filters('load_default_embeds', true) )
       
  2765 		return;
       
  2766 	require_once( ABSPATH . WPINC . '/default-embeds.php' );
       
  2767 }
       
  2768 
       
  2769 /**
  2733  * Determines if Widgets library should be loaded.
  2770  * Determines if Widgets library should be loaded.
  2734  *
  2771  *
  2735  * Checks to make sure that the widgets library hasn't already been loaded. If
  2772  * Checks to make sure that the widgets library hasn't already been loaded. If
  2736  * it hasn't, then it will load the widgets library and run an action hook.
  2773  * it hasn't, then it will load the widgets library and run an action hook.
  2737  *
  2774  *
  2905  *
  2942  *
  2906  * There is a hook deprecated_function_run that will be called that can be used
  2943  * There is a hook deprecated_function_run that will be called that can be used
  2907  * to get the backtrace up to what file and function called the deprecated
  2944  * to get the backtrace up to what file and function called the deprecated
  2908  * function.
  2945  * function.
  2909  *
  2946  *
  2910  * The current behavior is to trigger an user error if WP_DEBUG is defined and
  2947  * The current behavior is to trigger an user error if WP_DEBUG is true.
  2911  * is true.
       
  2912  *
  2948  *
  2913  * This function is to be used in every function in depreceated.php
  2949  * This function is to be used in every function in depreceated.php
  2914  *
  2950  *
  2915  * @package WordPress
  2951  * @package WordPress
  2916  * @package Debug
  2952  * @package Debug
  2927 function _deprecated_function($function, $version, $replacement=null) {
  2963 function _deprecated_function($function, $version, $replacement=null) {
  2928 
  2964 
  2929 	do_action('deprecated_function_run', $function, $replacement);
  2965 	do_action('deprecated_function_run', $function, $replacement);
  2930 
  2966 
  2931 	// Allow plugin to filter the output error trigger
  2967 	// Allow plugin to filter the output error trigger
  2932 	if( defined('WP_DEBUG') && ( true === WP_DEBUG ) && apply_filters( 'deprecated_function_trigger_error', true )) {
  2968 	if( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true )) {
  2933 		if( !is_null($replacement) )
  2969 		if( !is_null($replacement) )
  2934 			trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) );
  2970 			trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) );
  2935 		else
  2971 		else
  2936 			trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) );
  2972 			trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) );
  2937 	}
  2973 	}
  2942  *
  2978  *
  2943  * There is a hook deprecated_file_included that will be called that can be used
  2979  * There is a hook deprecated_file_included that will be called that can be used
  2944  * to get the backtrace up to what file and function included the deprecated
  2980  * to get the backtrace up to what file and function included the deprecated
  2945  * file.
  2981  * file.
  2946  *
  2982  *
  2947  * The current behavior is to trigger an user error if WP_DEBUG is defined and
  2983  * The current behavior is to trigger an user error if WP_DEBUG is true.
  2948  * is true.
       
  2949  *
  2984  *
  2950  * This function is to be used in every file that is depreceated
  2985  * This function is to be used in every file that is depreceated
  2951  *
  2986  *
  2952  * @package WordPress
  2987  * @package WordPress
  2953  * @package Debug
  2988  * @package Debug
  2964 function _deprecated_file($file, $version, $replacement=null) {
  2999 function _deprecated_file($file, $version, $replacement=null) {
  2965 
  3000 
  2966 	do_action('deprecated_file_included', $file, $replacement);
  3001 	do_action('deprecated_file_included', $file, $replacement);
  2967 
  3002 
  2968 	// Allow plugin to filter the output error trigger
  3003 	// Allow plugin to filter the output error trigger
  2969 	if( defined('WP_DEBUG') && ( true === WP_DEBUG ) && apply_filters( 'deprecated_file_trigger_error', true )) {
  3004 	if( WP_DEBUG && apply_filters( 'deprecated_file_trigger_error', true ) ) {
  2970 		if( !is_null($replacement) )
  3005 		if( !is_null($replacement) )
  2971 			trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $file, $version, $replacement ) );
  3006 			trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $file, $version, $replacement ) );
  2972 		else
  3007 		else
  2973 			trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $file, $version ) );
  3008 			trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $file, $version ) );
  2974 	}
  3009 	}
  3035 		return 1;
  3070 		return 1;
  3036 
  3071 
  3037 	if ( false !== strpos( $file, './' ))
  3072 	if ( false !== strpos( $file, './' ))
  3038 		return 1;
  3073 		return 1;
  3039 
  3074 
       
  3075 	if (!empty ( $allowed_files ) && (!in_array( $file, $allowed_files ) ) )
       
  3076 		return 3;
       
  3077 
  3040 	if (':' == substr( $file, 1, 1 ))
  3078 	if (':' == substr( $file, 1, 1 ))
  3041 		return 2;
  3079 		return 2;
  3042 
       
  3043 	if (!empty ( $allowed_files ) && (!in_array( $file, $allowed_files ) ) )
       
  3044 		return 3;
       
  3045 
  3080 
  3046 	return 0;
  3081 	return 0;
  3047 }
  3082 }
  3048 
  3083 
  3049 /**
  3084 /**
  3071  * @since 2.6.0
  3106  * @since 2.6.0
  3072  *
  3107  *
  3073  * @param string|bool $force Optional.
  3108  * @param string|bool $force Optional.
  3074  * @return bool True if forced, false if not forced.
  3109  * @return bool True if forced, false if not forced.
  3075  */
  3110  */
  3076 function force_ssl_login($force = '') {
  3111 function force_ssl_login( $force = null ) {
  3077 	static $forced;
  3112 	static $forced = false;
  3078 
  3113 
  3079 	if ( '' != $force ) {
  3114 	if ( !is_null( $force ) ) {
  3080 		$old_forced = $forced;
  3115 		$old_forced = $forced;
  3081 		$forced = $force;
  3116 		$forced = $force;
  3082 		return $old_forced;
  3117 		return $old_forced;
  3083 	}
  3118 	}
  3084 
  3119 
  3091  * @since 2.6.0
  3126  * @since 2.6.0
  3092  *
  3127  *
  3093  * @param string|bool $force
  3128  * @param string|bool $force
  3094  * @return bool True if forced, false if not forced.
  3129  * @return bool True if forced, false if not forced.
  3095  */
  3130  */
  3096 function force_ssl_admin($force = '') {
  3131 function force_ssl_admin( $force = null ) {
  3097 	static $forced;
  3132 	static $forced = false;
  3098 
  3133 
  3099 	if ( '' != $force ) {
  3134 	if ( !is_null( $force ) ) {
  3100 		$old_forced = $forced;
  3135 		$old_forced = $forced;
  3101 		$forced = $force;
  3136 		$forced = $force;
  3102 		return $old_forced;
  3137 		return $old_forced;
  3103 	}
  3138 	}
  3104 
  3139 
  3144 	$_wp_suspend_cache_invalidation = $suspend;
  3179 	$_wp_suspend_cache_invalidation = $suspend;
  3145 	return $current_suspend;
  3180 	return $current_suspend;
  3146 }
  3181 }
  3147 
  3182 
  3148 function get_site_option( $key, $default = false, $use_cache = true ) {
  3183 function get_site_option( $key, $default = false, $use_cache = true ) {
  3149 	return get_option($key, $default);
  3184 	// Allow plugins to short-circuit site options.
       
  3185  	$pre = apply_filters( 'pre_site_option_' . $key, false );
       
  3186  	if ( false !== $pre )
       
  3187  		return $pre;
       
  3188 
       
  3189  	$value = get_option($key, $default);
       
  3190 
       
  3191  	return apply_filters( 'site_option_' . $key, $value );
  3150 }
  3192 }
  3151 
  3193 
  3152 // expects $key, $value not to be SQL escaped
  3194 // expects $key, $value not to be SQL escaped
  3153 function add_site_option( $key, $value ) {
  3195 function add_site_option( $key, $value ) {
  3154 	return add_option($key, $value);
  3196 	$value = apply_filters( 'pre_add_site_option_' . $key, $value );
       
  3197 	$result =  add_option($key, $value);
       
  3198 	do_action( "add_site_option_{$key}", $key, $value );
       
  3199 	return $result;
       
  3200 }
       
  3201 
       
  3202 function delete_site_option( $key ) {
       
  3203 	$result = delete_option($key);
       
  3204 	do_action( "delete_site_option_{$key}", $key );
       
  3205 	return $result;
  3155 }
  3206 }
  3156 
  3207 
  3157 // expects $key, $value not to be SQL escaped
  3208 // expects $key, $value not to be SQL escaped
  3158 function update_site_option( $key, $value ) {
  3209 function update_site_option( $key, $value ) {
  3159 	return update_option($key, $value);
  3210 	$oldvalue = get_site_option( $key );
       
  3211 	$value = apply_filters( 'pre_update_site_option_' . $key, $value, $oldvalue );
       
  3212 	$result = update_option($key, $value);
       
  3213 	do_action( "update_site_option_{$key}", $key, $value );
       
  3214 	return $result;
       
  3215 }
       
  3216 
       
  3217 /**
       
  3218  * Delete a site transient
       
  3219  *
       
  3220  * @since 2.890
       
  3221  * @package WordPress
       
  3222  * @subpackage Transient
       
  3223  *
       
  3224  * @param string $transient Transient name. Expected to not be SQL-escaped
       
  3225  * @return bool true if successful, false otherwise
       
  3226  */
       
  3227 function delete_site_transient($transient) {
       
  3228 	global $_wp_using_ext_object_cache, $wpdb;
       
  3229 
       
  3230 	if ( $_wp_using_ext_object_cache ) {
       
  3231 		return wp_cache_delete($transient, 'site-transient');
       
  3232 	} else {
       
  3233 		$transient = '_site_transient_' . esc_sql($transient);
       
  3234 		return delete_site_option($transient);
       
  3235 	}
       
  3236 }
       
  3237 
       
  3238 /**
       
  3239  * Get the value of a site transient
       
  3240  *
       
  3241  * If the transient does not exist or does not have a value, then the return value
       
  3242  * will be false.
       
  3243  * 
       
  3244  * @since 2.9.0
       
  3245  * @package WordPress
       
  3246  * @subpackage Transient
       
  3247  *
       
  3248  * @param string $transient Transient name. Expected to not be SQL-escaped
       
  3249  * @return mixed Value of transient
       
  3250  */
       
  3251 function get_site_transient($transient) {
       
  3252 	global $_wp_using_ext_object_cache, $wpdb;
       
  3253 
       
  3254 	$pre = apply_filters( 'pre_site_transient_' . $transient, false );
       
  3255 	if ( false !== $pre )
       
  3256 		return $pre;
       
  3257 
       
  3258 	if ( $_wp_using_ext_object_cache ) {
       
  3259 		$value = wp_cache_get($transient, 'site-transient');
       
  3260 	} else {
       
  3261 		$transient_option = '_site_transient_' . esc_sql($transient);
       
  3262 		$transient_timeout = '_site_transient_timeout_' . esc_sql($transient);
       
  3263 		if ( get_site_option($transient_timeout) < time() ) {
       
  3264 			delete_site_option($transient_option);
       
  3265 			delete_site_option($transient_timeout);
       
  3266 			return false;
       
  3267 		}
       
  3268 
       
  3269 		$value = get_site_option($transient_option);
       
  3270 	}
       
  3271 
       
  3272 	return apply_filters('site_transient_' . $transient, $value);
       
  3273 }
       
  3274 
       
  3275 /**
       
  3276  * Set/update the value of a site transient
       
  3277  *
       
  3278  * You do not need to serialize values, if the value needs to be serialize, then
       
  3279  * it will be serialized before it is set.
       
  3280  *
       
  3281  * @since 2.9.0
       
  3282  * @package WordPress
       
  3283  * @subpackage Transient
       
  3284  *
       
  3285  * @param string $transient Transient name. Expected to not be SQL-escaped
       
  3286  * @param mixed $value Transient value.
       
  3287  * @param int $expiration Time until expiration in seconds, default 0
       
  3288  * @return bool False if value was not set and true if value was set.
       
  3289  */
       
  3290 function set_site_transient($transient, $value, $expiration = 0) {
       
  3291 	global $_wp_using_ext_object_cache, $wpdb;
       
  3292 
       
  3293 	if ( $_wp_using_ext_object_cache ) {
       
  3294 		return wp_cache_set($transient, $value, 'site-transient', $expiration);
       
  3295 	} else {
       
  3296 		$transient_timeout = '_site_transient_timeout_' . $transient;
       
  3297 		$transient = '_site_transient_' . $transient;
       
  3298 		$safe_transient = esc_sql($transient);
       
  3299 		if ( false === get_site_option( $safe_transient ) ) {
       
  3300 			if ( 0 != $expiration )
       
  3301 				add_site_option($transient_timeout, time() + $expiration);
       
  3302 			return add_site_option($transient, $value);
       
  3303 		} else {
       
  3304 			if ( 0 != $expiration )
       
  3305 				update_site_option($transient_timeout, time() + $expiration);
       
  3306 			return update_site_option($transient, $value);
       
  3307 		}
       
  3308 	}
  3160 }
  3309 }
  3161 
  3310 
  3162 /**
  3311 /**
  3163  * gmt_offset modification for smart timezone handling
  3312  * gmt_offset modification for smart timezone handling
  3164  *
  3313  *
  3242  *
  3391  *
  3243  */
  3392  */
  3244 function wp_timezone_choice( $selected_zone ) {
  3393 function wp_timezone_choice( $selected_zone ) {
  3245 	static $mo_loaded = false;
  3394 	static $mo_loaded = false;
  3246 
  3395 
  3247 	$continents = array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific', 'Etc' );
  3396 	$continents = array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific');
  3248 
  3397 
  3249 	// Load translations for continents and cities
  3398 	// Load translations for continents and cities
  3250 	if ( !$mo_loaded ) {
  3399 	if ( !$mo_loaded ) {
  3251 		$locale = get_locale();
  3400 		$locale = get_locale();
  3252 		$mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
  3401 		$mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
  3256 
  3405 
  3257 	$zonen = array();
  3406 	$zonen = array();
  3258 	foreach ( timezone_identifiers_list() as $zone ) {
  3407 	foreach ( timezone_identifiers_list() as $zone ) {
  3259 		$zone = explode( '/', $zone );
  3408 		$zone = explode( '/', $zone );
  3260 		if ( !in_array( $zone[0], $continents ) ) {
  3409 		if ( !in_array( $zone[0], $continents ) ) {
  3261 			continue;
       
  3262 		}
       
  3263 		if ( 'Etc' === $zone[0] && in_array( $zone[1], array( 'UCT', 'GMT', 'GMT0', 'GMT+0', 'GMT-0', 'Greenwich', 'Universal', 'Zulu' ) ) ) {
       
  3264 			continue;
  3410 			continue;
  3265 		}
  3411 		}
  3266 
  3412 
  3267 		// This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
  3413 		// This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
  3268 		$exists = array(
  3414 		$exists = array(
  3298 		if ( empty( $zone['city'] ) ) {
  3444 		if ( empty( $zone['city'] ) ) {
  3299 			// It's at the continent level (generally won't happen)
  3445 			// It's at the continent level (generally won't happen)
  3300 			$display = $zone['t_continent'];
  3446 			$display = $zone['t_continent'];
  3301 		} else {
  3447 		} else {
  3302 			// It's inside a continent group
  3448 			// It's inside a continent group
  3303 			
  3449 
  3304 			// Continent optgroup
  3450 			// Continent optgroup
  3305 			if ( !isset( $zonen[$key - 1] ) || $zonen[$key - 1]['continent'] !== $zone['continent'] ) {
  3451 			if ( !isset( $zonen[$key - 1] ) || $zonen[$key - 1]['continent'] !== $zone['continent'] ) {
  3306 				$label = ( 'Etc' === $zone['continent'] ) ? __( 'Manual offsets' ) : $zone['t_continent'];
  3452 				$label = $zone['t_continent'];
  3307 				$structure[] = '<optgroup label="'. esc_attr( $label ) .'">';
  3453 				$structure[] = '<optgroup label="'. esc_attr( $label ) .'">';
  3308 			}
  3454 			}
  3309 			
  3455 
  3310 			// Add the city to the value
  3456 			// Add the city to the value
  3311 			$value[] = $zone['city'];
  3457 			$value[] = $zone['city'];
  3312 			if ( 'Etc' === $zone['continent'] ) {
  3458 
  3313 				if ( 'UTC' === $zone['city'] ) {
  3459 			$display = $zone['t_city'];
  3314 					$display = '';
  3460 			if ( !empty( $zone['subcity'] ) ) {
  3315 				} else {
  3461 				// Add the subcity to the value
  3316 					$display = str_replace( 'GMT', '', $zone['city'] );
  3462 				$value[] = $zone['subcity'];
  3317 					$display = strtr( $display, '+-', '-+' ) . ':00';
  3463 				$display .= ' - ' . $zone['t_subcity'];
  3318 				}
       
  3319 				$display = sprintf( __( 'UTC %s' ), $display );
       
  3320 			} else {
       
  3321 				$display = $zone['t_city'];
       
  3322 				if ( !empty( $zone['subcity'] ) ) {
       
  3323 					// Add the subcity to the value
       
  3324 					$value[] = $zone['subcity'];
       
  3325 					$display .= ' - ' . $zone['t_subcity'];
       
  3326 				}
       
  3327 			}
  3464 			}
  3328 		}
  3465 		}
  3329 
  3466 
  3330 		// Build the value
  3467 		// Build the value
  3331 		$value = join( '/', $value );
  3468 		$value = join( '/', $value );
  3332 		$selected = '';
  3469 		$selected = '';
  3333 		if ( $value === $selected_zone ) {
  3470 		if ( $value === $selected_zone ) {
  3334 			$selected = 'selected="selected" ';
  3471 			$selected = 'selected="selected" ';
  3335 		}
  3472 		}
  3336 		$structure[] = '<option ' . $selected . 'value="' . esc_attr( $value ) . '">' . esc_html( $display ) . "</option>";
  3473 		$structure[] = '<option ' . $selected . 'value="' . esc_attr( $value ) . '">' . esc_html( $display ) . "</option>";
  3337 		
  3474 
  3338 		// Close continent optgroup
  3475 		// Close continent optgroup
  3339 		if ( !empty( $zone['city'] ) && ( !isset($zonen[$key + 1]) || (isset( $zonen[$key + 1] ) && $zonen[$key + 1]['continent'] !== $zone['continent']) ) ) {
  3476 		if ( !empty( $zone['city'] ) && ( !isset($zonen[$key + 1]) || (isset( $zonen[$key + 1] ) && $zonen[$key + 1]['continent'] !== $zone['continent']) ) ) {
  3340 			$structure[] = '</optgroup>';
  3477 			$structure[] = '</optgroup>';
  3341 		}
  3478 		}
  3342 	}
  3479 	}
  3343 
  3480 
       
  3481 	// Do UTC
       
  3482 	$structure[] = '<optgroup label="'. esc_attr__( 'UTC' ) .'">';
       
  3483 	$selected = '';
       
  3484 	if ( 'UTC' === $selected_zone )
       
  3485 		$selected = 'selected="selected" ';
       
  3486 	$structure[] = '<option ' . $selected . 'value="' . esc_attr( 'UTC' ) . '">' . __('UTC') . '</option>';
       
  3487 	$structure[] = '</optgroup>';
       
  3488 
       
  3489 	// Do manual UTC offsets
       
  3490 	$structure[] = '<optgroup label="'. esc_attr__( 'Manual Offsets' ) .'">';
       
  3491 	$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,
       
  3492 		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);
       
  3493 	foreach ( $offset_range as $offset ) {
       
  3494 		if ( 0 <= $offset )
       
  3495 			$offset_name = '+' . $offset;
       
  3496 		else
       
  3497 			$offset_name = (string) $offset;
       
  3498 
       
  3499 		$offset_value = $offset_name;
       
  3500 		$offset_name = str_replace(array('.25','.5','.75'), array(':15',':30',':45'), $offset_name);
       
  3501 		$offset_name = 'UTC' . $offset_name;
       
  3502 		$offset_value = 'UTC' . $offset_value;
       
  3503 		$selected = '';
       
  3504 		if ( $offset_value === $selected_zone )
       
  3505 			$selected = 'selected="selected" ';
       
  3506 		$structure[] = '<option ' . $selected . 'value="' . esc_attr( $offset_value ) . '">' . esc_html( $offset_name ) . "</option>";
       
  3507 		
       
  3508 	}
       
  3509 	$structure[] = '</optgroup>';
       
  3510 
  3344 	return join( "\n", $structure );
  3511 	return join( "\n", $structure );
  3345 }
  3512 }
  3346 
       
  3347 
       
  3348 
  3513 
  3349 /**
  3514 /**
  3350  * Strip close comment and close php tags from file headers used by WP
  3515  * Strip close comment and close php tags from file headers used by WP
  3351  * See http://core.trac.wordpress.org/ticket/8497
  3516  * See http://core.trac.wordpress.org/ticket/8497
  3352  *
  3517  *
  3353  * @since 2.8
  3518  * @since 2.8
  3354 **/
  3519 **/
  3355 function _cleanup_header_comment($str) {
  3520 function _cleanup_header_comment($str) {
  3356 	return trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $str));
  3521 	return trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $str));
  3357 }
  3522 }
       
  3523 
       
  3524 /**
       
  3525  * Permanently deletes posts, pages, attachments, and comments which have been in the trash for EMPTY_TRASH_DAYS.
       
  3526  *
       
  3527  * @since 2.9.0
       
  3528  *
       
  3529  * @return void
       
  3530  */
       
  3531 function wp_scheduled_delete() {
       
  3532 	global $wpdb;
       
  3533 
       
  3534 	$delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS);
       
  3535 
       
  3536 	$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);
       
  3537 
       
  3538 	foreach ( (array) $posts_to_delete as $post ) {
       
  3539 		$post_id = (int) $post['post_id'];
       
  3540 		if ( !$post_id )
       
  3541 			continue;
       
  3542 
       
  3543 		$del_post = get_post($post_id);
       
  3544 
       
  3545 		if ( !$del_post || 'trash' != $del_post->post_status ) {
       
  3546 			delete_post_meta($post_id, '_wp_trash_meta_status');
       
  3547 			delete_post_meta($post_id, '_wp_trash_meta_time');
       
  3548 		} else {
       
  3549 			wp_delete_post($post_id);
       
  3550 		}
       
  3551 	}
       
  3552 
       
  3553 	$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);
       
  3554 
       
  3555 	foreach ( (array) $comments_to_delete as $comment ) {
       
  3556 		$comment_id = (int) $comment['comment_id'];
       
  3557 		if ( !$comment_id )
       
  3558 			continue;
       
  3559 
       
  3560 		$del_comment = get_comment($comment_id);
       
  3561 
       
  3562 		if ( !$del_comment || 'trash' != $del_comment->comment_approved ) {
       
  3563 			delete_comment_meta($comment_id, '_wp_trash_meta_time');
       
  3564 			delete_comment_meta($comment_id, '_wp_trash_meta_status');
       
  3565 		} else {
       
  3566 			wp_delete_comment($comment_id);
       
  3567 		}
       
  3568 	}
       
  3569 }
       
  3570 
       
  3571 /**
       
  3572  * Parse the file contents to retrieve its metadata.
       
  3573  *
       
  3574  * Searches for metadata for a file, such as a plugin or theme.  Each piece of 
       
  3575  * metadata must be on its own line. For a field spanning multple lines, it
       
  3576  * must not have any newlines or only parts of it will be displayed.
       
  3577  *
       
  3578  * Some users have issues with opening large files and manipulating the contents
       
  3579  * for want is usually the first 1kiB or 2kiB. This function stops pulling in
       
  3580  * the file contents when it has all of the required data.
       
  3581  *
       
  3582  * The first 8kiB of the file will be pulled in and if the file data is not
       
  3583  * within that first 8kiB, then the author should correct their plugin file
       
  3584  * and move the data headers to the top.
       
  3585  *
       
  3586  * The file is assumed to have permissions to allow for scripts to read
       
  3587  * the file. This is not checked however and the file is only opened for
       
  3588  * reading.
       
  3589  *
       
  3590  * @since 2.9.0
       
  3591  *
       
  3592  * @param string $file Path to the file
       
  3593  * @param bool $markup If the returned data should have HTML markup applied
       
  3594  * @param string $context If specified adds filter hook "extra_<$context>_headers" 
       
  3595  */
       
  3596 function get_file_data( $file, $default_headers, $context = '' ) {
       
  3597 	// We don't need to write to the file, so just open for reading.
       
  3598 	$fp = fopen( $file, 'r' );
       
  3599 
       
  3600 	// Pull only the first 8kiB of the file in.
       
  3601 	$file_data = fread( $fp, 8192 );
       
  3602 
       
  3603 	// PHP will close file handle, but we are good citizens.
       
  3604 	fclose( $fp );
       
  3605 
       
  3606 	if( $context != '' ) {
       
  3607 		$extra_headers = apply_filters( "extra_$context".'_headers', array() );
       
  3608 
       
  3609 		$extra_headers = array_flip( $extra_headers );
       
  3610 		foreach( $extra_headers as $key=>$value ) {
       
  3611 			$extra_headers[$key] = $key;
       
  3612 		}
       
  3613 		$all_headers = array_merge($extra_headers, $default_headers);
       
  3614 	} else {
       
  3615 		$all_headers = $default_headers;
       
  3616 	}
       
  3617 
       
  3618 	
       
  3619 	foreach ( $all_headers as $field => $regex ) {
       
  3620 		preg_match( '/' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, ${$field});
       
  3621 		if ( !empty( ${$field} ) )
       
  3622 			${$field} = _cleanup_header_comment( ${$field}[1] );
       
  3623 		else
       
  3624 			${$field} = '';
       
  3625 	}
       
  3626 
       
  3627 	$file_data = compact( array_keys( $all_headers ) );
       
  3628 	
       
  3629 	return $file_data;
       
  3630 }
       
  3631 /*
       
  3632  * Used internally to tidy up the search terms
       
  3633  * 
       
  3634  * @private
       
  3635  * @since 2.9.0
       
  3636  */
       
  3637 function _search_terms_tidy($t) {
       
  3638 	return trim($t, "\"\'\n\r ");
       
  3639 }
  3358 ?>
  3640 ?>