- * @package WordPress
- * @subpackage Option
- * @since 2.7.0
- */
-function delete_all_user_settings() {
- if ( ! $user = wp_get_current_user() )
- return;
-
- update_user_option( $user->ID, 'user-settings', '', false );
- setcookie('wp-settings-' . $user->ID, ' ', time() - 31536000, SITECOOKIEPATH);
-}
-
-/**
- * Serialize data, if needed.
- *
- * @since 2.0.5
- *
- * @param mixed $data Data that might be serialized.
- * @return mixed A scalar data
- */
-function maybe_serialize( $data ) {
- if ( is_array( $data ) || is_object( $data ) )
- return serialize( $data );
-
- if ( is_serialized( $data ) )
- return serialize( $data );
-
- return $data;
-}
-
-/**
- * Retrieve post title from XMLRPC XML.
- *
- * If the title element is not part of the XML, then the default post title from
- * the $post_default_title will be used instead.
- *
- * @package WordPress
- * @subpackage XMLRPC
- * @since 0.71
- *
- * @global string $post_default_title Default XMLRPC post title.
- *
- * @param string $content XMLRPC XML Request content
- * @return string Post title
- */
-function xmlrpc_getposttitle( $content ) {
- global $post_default_title;
- if ( preg_match( '/<title>(.+?)<\/title>/is', $content, $matchtitle ) ) {
- $post_title = $matchtitle[1];
- } else {
- $post_title = $post_default_title;
- }
- return $post_title;
-}
-
-/**
- * Retrieve the post category or categories from XMLRPC XML.
- *
- * If the category element is not found, then the default post category will be
- * used. The return type then would be what $post_default_category. If the
- * category is found, then it will always be an array.
- *
- * @package WordPress
- * @subpackage XMLRPC
- * @since 0.71
- *
- * @global string $post_default_category Default XMLRPC post category.
- *
- * @param string $content XMLRPC XML Request content
- * @return string|array List of categories or category name.
- */
-function xmlrpc_getpostcategory( $content ) {
- global $post_default_category;
- if ( preg_match( '/<category>(.+?)<\/category>/is', $content, $matchcat ) ) {
- $post_category = trim( $matchcat[1], ',' );
- $post_category = explode( ',', $post_category );
- } else {
- $post_category = $post_default_category;
- }
- return $post_category;
-}
-
-/**
- * XMLRPC XML content without title and category elements.
- *
- * @package WordPress
- * @subpackage XMLRPC
- * @since 0.71
- *
- * @param string $content XMLRPC XML Request content
- * @return string XMLRPC XML Request content without title and category elements.
- */
-function xmlrpc_removepostdata( $content ) {
- $content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content );
- $content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content );
- $content = trim( $content );
- return $content;
-}
-
-/**
- * Open the file handle for debugging.
- *
- * This function is used for XMLRPC feature, but it is general purpose enough
- * to be used in anywhere.
- *
- * @see fopen() for mode options.
- * @package WordPress
- * @subpackage Debug
- * @since 0.71
- * @uses $debug Used for whether debugging is enabled.
- *
- * @param string $filename File path to debug file.
- * @param string $mode Same as fopen() mode parameter.
- * @return bool|resource File handle. False on failure.
- */
-function debug_fopen( $filename, $mode ) {
- global $debug;
- if ( 1 == $debug ) {
- $fp = fopen( $filename, $mode );
- return $fp;
- } else {
- return false;
- }
-}
-
-/**
- * Write contents to the file used for debugging.
- *
- * Technically, this can be used to write to any file handle when the global
- * $debug is set to 1 or true.
- *
- * @package WordPress
- * @subpackage Debug
- * @since 0.71
- * @uses $debug Used for whether debugging is enabled.
- *
- * @param resource $fp File handle for debugging file.
- * @param string $string Content to write to debug file.
- */
-function debug_fwrite( $fp, $string ) {
- global $debug;
- if ( 1 == $debug )
- fwrite( $fp, $string );
-}
-
-/**
- * Close the debugging file handle.
- *
- * Technically, this can be used to close any file handle when the global $debug
- * is set to 1 or true.
- *
- * @package WordPress
- * @subpackage Debug
- * @since 0.71
- * @uses $debug Used for whether debugging is enabled.
- *
- * @param resource $fp Debug File handle.
- */
-function debug_fclose( $fp ) {
- global $debug;
- if ( 1 == $debug )
- fclose( $fp );
-}
-
-/**
- * Check content for video and audio links to add as enclosures.
- *
- * Will not add enclosures that have already been added and will
- * remove enclosures that are no longer in the post. This is called as
- * pingbacks and trackbacks.
- *
- * @package WordPress
- * @since 1.5.0
- *
- * @uses $wpdb
- *
- * @param string $content Post Content
- * @param int $post_ID Post ID
- */
-function do_enclose( $content, $post_ID ) {
- global $wpdb;
- include_once( ABSPATH . WPINC . '/class-IXR.php' );
-
- $log = debug_fopen( ABSPATH . 'enclosures.log', 'a' );
- $post_links = array();
- debug_fwrite( $log, 'BEGIN ' . date( 'YmdHis', time() ) . "\n" );
-
- $pung = get_enclosed( $post_ID );
-
- $ltrs = '\w';
- $gunk = '/#~:.?+=&%@!\-';
- $punc = '.:?\-';
- $any = $ltrs . $gunk . $punc;
-
- preg_match_all( "{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp );
-
- debug_fwrite( $log, 'Post contents:' );
- debug_fwrite( $log, $content . "\n" );
-
- foreach ( $pung as $link_test ) {
- if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post
- $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 . '%') );
- do_action( 'delete_postmeta', $mid );
- $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id IN(%s)", implode( ',', $mid ) ) );
- do_action( 'deleted_postmeta', $mid );
- }
- }
-
- foreach ( (array) $post_links_temp[0] as $link_test ) {
- if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already
- $test = @parse_url( $link_test );
- if ( false === $test )
- continue;
- if ( isset( $test['query'] ) )
- $post_links[] = $link_test;
- elseif ( $test['path'] != '/' && $test['path'] != '' )
- $post_links[] = $link_test;
- }
- }
-
- foreach ( (array) $post_links as $url ) {
- if ( $url != '' && !$wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $url . '%' ) ) ) {
-
- if ( $headers = wp_get_http_headers( $url) ) {
- $len = (int) $headers['content-length'];
- $type = $headers['content-type'];
- $allowed_types = array( 'video', 'audio' );
-
- // Check to see if we can figure out the mime type from
- // the extension
- $url_parts = @parse_url( $url );
- if ( false !== $url_parts ) {
- $extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION );
- if ( !empty( $extension ) ) {
- foreach ( get_allowed_mime_types( ) as $exts => $mime ) {
- if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) {
- $type = $mime;
- break;
- }
- }
- }
- }
-
- if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
- $meta_value = "$url\n$len\n$type\n";
- $wpdb->insert($wpdb->postmeta, array('post_id' => $post_ID, 'meta_key' => 'enclosure', 'meta_value' => $meta_value) );
- do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, 'enclosure', $meta_value );
- }
- }
- }
- }
-}
-
-/**
- * Perform a HTTP HEAD or GET request.
- *
- * If $file_path is a writable filename, this will do a GET request and write
- * the file to that path.
- *
- * @since 2.5.0
- *
- * @param string $url URL to fetch.
- * @param string|bool $file_path Optional. File path to write request to.
- * @param int $red (private) The number of Redirects followed, Upon 5 being hit, returns false.
- * @return bool|string False on failure and string of headers if HEAD request.
- */
-function wp_get_http( $url, $file_path = false, $red = 1 ) {
- @set_time_limit( 60 );
-
- if ( $red > 5 )
- return false;
-
- $options = array();
- $options['redirection'] = 5;
-
- if ( false == $file_path )
- $options['method'] = 'HEAD';
- else
- $options['method'] = 'GET';
-
- $response = wp_remote_request($url, $options);
-
- if ( is_wp_error( $response ) )
- return false;
-
- $headers = wp_remote_retrieve_headers( $response );
- $headers['response'] = $response['response']['code'];
-
- // WP_HTTP no longer follows redirects for HEAD requests.
- if ( 'HEAD' == $options['method'] && in_array($headers['response'], array(301, 302)) && isset( $headers['location'] ) ) {
- return wp_get_http( $headers['location'], $file_path, ++$red );
- }
-
- if ( false == $file_path )
- return $headers;
-
- // GET request - write it to the supplied filename
- $out_fp = fopen($file_path, 'w');
- if ( !$out_fp )
- return $headers;
-
- fwrite( $out_fp, $response['body']);
- fclose($out_fp);
- clearstatcache();
-
- return $headers;
-}
-
-/**
- * Retrieve HTTP Headers from URL.
- *
- * @since 1.5.1
- *
- * @param string $url
- * @param bool $deprecated Not Used.
- * @return bool|string False on failure, headers on success.
- */
-function wp_get_http_headers( $url, $deprecated = false ) {
- if ( !empty( $deprecated ) )
- _deprecated_argument( __FUNCTION__, '2.7' );
-
- $response = wp_remote_head( $url );
-
- if ( is_wp_error( $response ) )
- return false;
-
- return wp_remote_retrieve_headers( $response );
-}
-
-/**
- * Whether today is a new day.
- *
- * @since 0.71
- * @uses $day Today
- * @uses $previousday Previous day
- *
- * @return int 1 when new day, 0 if not a new day.
- */
-function is_new_day() {
- global $day, $previousday;
- if ( $day != $previousday )
- return 1;
- else
- return 0;
-}
-
-/**
- * Build URL query based on an associative and, or indexed array.
- *
- * This is a convenient function for easily building url queries. It sets the
- * separator to '&' and uses _http_build_query() function.
- *
- * @see _http_build_query() Used to build the query
- * @link http://us2.php.net/manual/en/function.http-build-query.php more on what
- * http_build_query() does.
- *
- * @since 2.3.0
- *
- * @param array $data URL-encode key/value pairs.
- * @return string URL encoded string
- */
-function build_query( $data ) {
- return _http_build_query( $data, null, '&', '', false );
-}
-
-/**
- * Retrieve a modified URL query string.
- *
- * You can rebuild the URL and append a new query variable to the URL query by
- * using this function. You can also retrieve the full URL with query data.
- *
- * Adding a single key & value or an associative array. Setting a key value to
- * emptystring removes the key. Omitting oldquery_or_uri uses the $_SERVER
- * value.
- *
- * @since 1.5.0
- *
- * @param mixed $param1 Either newkey or an associative_array
- * @param mixed $param2 Either newvalue or oldquery or uri
- * @param mixed $param3 Optional. Old query or uri
- * @return string New URL query string.
- */
-function add_query_arg() {
- $ret = '';
- if ( is_array( func_get_arg(0) ) ) {
- if ( @func_num_args() < 2 || false === @func_get_arg( 1 ) )
- $uri = $_SERVER['REQUEST_URI'];
- else
- $uri = @func_get_arg( 1 );
- } else {
- if ( @func_num_args() < 3 || false === @func_get_arg( 2 ) )
- $uri = $_SERVER['REQUEST_URI'];
- else
- $uri = @func_get_arg( 2 );
- }
-
- if ( $frag = strstr( $uri, '#' ) )
- $uri = substr( $uri, 0, -strlen( $frag ) );
- else
- $frag = '';
-
- if ( preg_match( '|^https?://|i', $uri, $matches ) ) {
- $protocol = $matches[0];
- $uri = substr( $uri, strlen( $protocol ) );
- } else {
- $protocol = '';
- }
-
- if ( strpos( $uri, '?' ) !== false ) {
- $parts = explode( '?', $uri, 2 );
- if ( 1 == count( $parts ) ) {
- $base = '?';
- $query = $parts[0];
- } else {
- $base = $parts[0] . '?';
- $query = $parts[1];
- }
- } elseif ( !empty( $protocol ) || strpos( $uri, '=' ) === false ) {
- $base = $uri . '?';
- $query = '';
- } else {
- $base = '';
- $query = $uri;
- }
-
- wp_parse_str( $query, $qs );
- $qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string
- if ( is_array( func_get_arg( 0 ) ) ) {
- $kayvees = func_get_arg( 0 );
- $qs = array_merge( $qs, $kayvees );
- } else {
- $qs[func_get_arg( 0 )] = func_get_arg( 1 );
- }
-
- foreach ( (array) $qs as $k => $v ) {
- if ( $v === false )
- unset( $qs[$k] );
- }
-
- $ret = build_query( $qs );
- $ret = trim( $ret, '?' );
- $ret = preg_replace( '#=(&|$)#', '$1', $ret );
- $ret = $protocol . $base . $ret . $frag;
- $ret = rtrim( $ret, '?' );
- return $ret;
-}
-
-/**
- * Removes an item or list from the query string.
- *
- * @since 1.5.0
- *
- * @param string|array $key Query key or keys to remove.
- * @param bool $query When false uses the $_SERVER value.
- * @return string New URL query string.
- */
-function remove_query_arg( $key, $query=false ) {
- if ( is_array( $key ) ) { // removing multiple keys
- foreach ( $key as $k )
- $query = add_query_arg( $k, false, $query );
- return $query;
- }
- return add_query_arg( $key, false, $query );
-}
-
-/**
- * Walks the array while sanitizing the contents.
- *
- * @since 0.71
- *
- * @param array $array Array to used to walk while sanitizing contents.
- * @return array Sanitized $array.
- */
-function add_magic_quotes( $array ) {
- foreach ( (array) $array as $k => $v ) {
- if ( is_array( $v ) ) {
- $array[$k] = add_magic_quotes( $v );
- } else {
- $array[$k] = addslashes( $v );
- }
- }
- return $array;
-}
-
-/**
- * HTTP request for URI to retrieve content.
- *
- * @since 1.5.1
- * @uses wp_remote_get()
- *
- * @param string $uri URI/URL of web page to retrieve.
- * @return bool|string HTTP content. False on failure.
- */
-function wp_remote_fopen( $uri ) {
- $parsed_url = @parse_url( $uri );
-
- if ( !$parsed_url || !is_array( $parsed_url ) )
- return false;
-
- $options = array();
- $options['timeout'] = 10;
-
- $response = wp_remote_get( $uri, $options );
-
- if ( is_wp_error( $response ) )
- return false;
-
- return $response['body'];
-}
-
-/**
- * Set up the WordPress query.
- *
- * @since 2.0.0
- *
- * @param string $query_vars Default WP_Query arguments.
- */
-function wp( $query_vars = '' ) {
- global $wp, $wp_query, $wp_the_query;
- $wp->main( $query_vars );
-
- if ( !isset($wp_the_query) )
- $wp_the_query = $wp_query;
-}
-
-/**
- * Retrieve the description for the HTTP status.
- *
- * @since 2.3.0
- *
- * @param int $code HTTP status code.
- * @return string Empty string if not found, or description if found.
- */
-function get_status_header_desc( $code ) {
- global $wp_header_to_desc;
-
- $code = absint( $code );
-
- if ( !isset( $wp_header_to_desc ) ) {
- $wp_header_to_desc = array(
- 100 => 'Continue',
- 101 => 'Switching Protocols',
- 102 => 'Processing',
-
- 200 => 'OK',
- 201 => 'Created',
- 202 => 'Accepted',
- 203 => 'Non-Authoritative Information',
- 204 => 'No Content',
- 205 => 'Reset Content',
- 206 => 'Partial Content',
- 207 => 'Multi-Status',
- 226 => 'IM Used',
-
- 300 => 'Multiple Choices',
- 301 => 'Moved Permanently',
- 302 => 'Found',
- 303 => 'See Other',
- 304 => 'Not Modified',
- 305 => 'Use Proxy',
- 306 => 'Reserved',
- 307 => 'Temporary Redirect',
-
- 400 => 'Bad Request',
- 401 => 'Unauthorized',
- 402 => 'Payment Required',
- 403 => 'Forbidden',
- 404 => 'Not Found',
- 405 => 'Method Not Allowed',
- 406 => 'Not Acceptable',
- 407 => 'Proxy Authentication Required',
- 408 => 'Request Timeout',
- 409 => 'Conflict',
- 410 => 'Gone',
- 411 => 'Length Required',
- 412 => 'Precondition Failed',
- 413 => 'Request Entity Too Large',
- 414 => 'Request-URI Too Long',
- 415 => 'Unsupported Media Type',
- 416 => 'Requested Range Not Satisfiable',
- 417 => 'Expectation Failed',
- 422 => 'Unprocessable Entity',
- 423 => 'Locked',
- 424 => 'Failed Dependency',
- 426 => 'Upgrade Required',
-
- 500 => 'Internal Server Error',
- 501 => 'Not Implemented',
- 502 => 'Bad Gateway',
- 503 => 'Service Unavailable',
- 504 => 'Gateway Timeout',
- 505 => 'HTTP Version Not Supported',
- 506 => 'Variant Also Negotiates',
- 507 => 'Insufficient Storage',
- 510 => 'Not Extended'
- );
- }
-
- if ( isset( $wp_header_to_desc[$code] ) )
- return $wp_header_to_desc[$code];
- else
- return '';
-}
-
-/**
- * Set HTTP status header.
- *
- * @since 2.0.0
- * @uses apply_filters() Calls 'status_header' on status header string, HTTP
- * HTTP code, HTTP code description, and protocol string as separate
- * parameters.
- *
- * @param int $header HTTP status code
- * @return unknown
- */
-function status_header( $header ) {
- $text = get_status_header_desc( $header );
-
- if ( empty( $text ) )
- return false;
-
- $protocol = $_SERVER["SERVER_PROTOCOL"];
- if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol )
- $protocol = 'HTTP/1.0';
- $status_header = "$protocol $header $text";
- if ( function_exists( 'apply_filters' ) )
- $status_header = apply_filters( 'status_header', $status_header, $header, $text, $protocol );
-
- return @header( $status_header, true, $header );
-}
-
-/**
- * Gets the header information to prevent caching.