- if ( $_wp_using_ext_object_cache ) {
- $value = wp_cache_get($transient, 'transient');
- } else {
- $transient_option = '_transient_' . esc_sql($transient);
- // If option is not in alloptions, it is not autoloaded and thus has a timeout
- $alloptions = wp_load_alloptions();
- if ( !isset( $alloptions[$transient_option] ) ) {
- $transient_timeout = '_transient_timeout_' . esc_sql($transient);
- if ( get_option($transient_timeout) < time() ) {
- delete_option($transient_option);
- delete_option($transient_timeout);
- return false;
- }
- }
-
- $value = get_option($transient_option);
- }
-
- return apply_filters('transient_' . $transient, $value);
-}
-
-/**
- * Set/update the value of a transient
- *
- * You do not need to serialize values, if the value needs to be serialize, then
- * it will be serialized before it is set.
- *
- * @since 2.8.0
- * @package WordPress
- * @subpackage Transient
- *
- * @param string $transient Transient name. Expected to not be SQL-escaped
- * @param mixed $value Transient value.
- * @param int $expiration Time until expiration in seconds, default 0
- * @return bool False if value was not set and true if value was set.
- */
-function set_transient($transient, $value, $expiration = 0) {
- global $_wp_using_ext_object_cache, $wpdb;
-
- if ( $_wp_using_ext_object_cache ) {
- return wp_cache_set($transient, $value, 'transient', $expiration);
- } else {
- $transient_timeout = '_transient_timeout_' . $transient;
- $transient = '_transient_' . $transient;
- $safe_transient = esc_sql($transient);
- if ( false === get_option( $safe_transient ) ) {
- $autoload = 'yes';
- if ( 0 != $expiration ) {
- $autoload = 'no';
- add_option($transient_timeout, time() + $expiration, '', 'no');
- }
- return add_option($transient, $value, '', $autoload);
- } else {
- if ( 0 != $expiration )
- update_option($transient_timeout, time() + $expiration);
- return update_option($transient, $value);
- }
- }
-}
-
-/**
- * Saves and restores user interface settings stored in a cookie.
- *
- * Checks if the current user-settings cookie is updated and stores it. When no
- * cookie exists (different browser used), adds the last saved cookie restoring
- * the settings.
- *
- * @package WordPress
- * @subpackage Option
- * @since 2.7.0
- */
-function wp_user_settings() {
-
- if ( ! is_admin() )
- return;
-
- if ( defined('DOING_AJAX') )
- return;
-
- if ( ! $user = wp_get_current_user() )
- return;
-
- $settings = get_user_option( 'user-settings', $user->ID, false );
-
- if ( isset( $_COOKIE['wp-settings-' . $user->ID] ) ) {
- $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user->ID] );
-
- if ( ! empty( $cookie ) && strpos( $cookie, '=' ) ) {
- if ( $cookie == $settings )
- return;
-
- $last_time = (int) get_user_option( 'user-settings-time', $user->ID, false );
- $saved = isset( $_COOKIE['wp-settings-time-' . $user->ID]) ? preg_replace( '/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user->ID] ) : 0;
-
- if ( $saved > $last_time ) {
- update_user_option( $user->ID, 'user-settings', $cookie, false );
- update_user_option( $user->ID, 'user-settings-time', time() - 5, false );
- return;
- }
- }
- }
-
- setcookie( 'wp-settings-' . $user->ID, $settings, time() + 31536000, SITECOOKIEPATH );
- setcookie( 'wp-settings-time-' . $user->ID, time(), time() + 31536000, SITECOOKIEPATH );
- $_COOKIE['wp-settings-' . $user->ID] = $settings;
-}
-
-/**
- * Retrieve user interface setting value based on setting name.
- *
- * @package WordPress
- * @subpackage Option
- * @since 2.7.0
- *
- * @param string $name The name of the setting.
- * @param string $default Optional default value to return when $name is not set.
- * @return mixed the last saved user setting or the default value/false if it doesn't exist.
- */
-function get_user_setting( $name, $default = false ) {
-
- $all = get_all_user_settings();
-
- return isset($all[$name]) ? $all[$name] : $default;
-}
-
-/**
- * Add or update user interface setting.
- *
- * Both $name and $value can contain only ASCII letters, numbers and underscores.
- * This function has to be used before any output has started as it calls setcookie().
- *
- * @package WordPress
- * @subpackage Option
- * @since 2.8.0
- *
- * @param string $name The name of the setting.
- * @param string $value The value for the setting.
- * @return bool true if set successfully/false if not.
- */
-function set_user_setting( $name, $value ) {
-
- if ( headers_sent() )
- return false;
-
- $all = get_all_user_settings();
- $name = preg_replace( '/[^A-Za-z0-9_]+/', '', $name );
-
- if ( empty($name) )
- return false;
-
- $all[$name] = $value;
-
- return wp_set_all_user_settings($all);
-}
-
-/**
- * Delete user interface settings.
- *
- * Deleting settings would reset them to the defaults.
- * This function has to be used before any output has started as it calls setcookie().
- *
- * @package WordPress
- * @subpackage Option
- * @since 2.7.0
- *
- * @param mixed $names The name or array of names of the setting to be deleted.
- * @return bool true if deleted successfully/false if not.
- */
-function delete_user_setting( $names ) {
-
- if ( headers_sent() )
- return false;
-
- $all = get_all_user_settings();
- $names = (array) $names;
-
- foreach ( $names as $name ) {
- if ( isset($all[$name]) ) {
- unset($all[$name]);
- $deleted = true;
- }
- }
-
- if ( isset($deleted) )
- return wp_set_all_user_settings($all);
-
- return false;
-}
-
-/**
- * Retrieve all user interface settings.
- *
- * @package WordPress
- * @subpackage Option
- * @since 2.7.0
- *
- * @return array the last saved user settings or empty array.
- */
-function get_all_user_settings() {
- global $_updated_user_settings;
-
- if ( ! $user = wp_get_current_user() )
- return array();
-
- if ( isset($_updated_user_settings) && is_array($_updated_user_settings) )
- return $_updated_user_settings;
-
- $all = array();
- if ( isset($_COOKIE['wp-settings-' . $user->ID]) ) {
- $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user->ID] );
-
- if ( $cookie && strpos($cookie, '=') ) // the '=' cannot be 1st char
- parse_str($cookie, $all);
-
- } else {
- $option = get_user_option('user-settings', $user->ID);
- if ( $option && is_string($option) )
- parse_str( $option, $all );
- }
-
- return $all;
-}
-
-/**
- * Private. Set all user interface settings.
- *
- * @package WordPress
- * @subpackage Option
- * @since 2.8.0
- *
- */
-function wp_set_all_user_settings($all) {
- global $_updated_user_settings;
-
- if ( ! $user = wp_get_current_user() )
- return false;
-
- $_updated_user_settings = $all;
- $settings = '';
- foreach ( $all as $k => $v ) {
- $v = preg_replace( '/[^A-Za-z0-9_]+/', '', $v );
- $settings .= $k . '=' . $v . '&';
- }
-
- $settings = rtrim($settings, '&');
-
- update_user_option( $user->ID, 'user-settings', $settings, false );
- update_user_option( $user->ID, 'user-settings-time', time(), false );
-
- return true;
-}
-
-/**
- * Delete the user settings of the current user.
- *
- * @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 post_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 ( isset( $test['query'] ) )
- $post_links[] = $link_test;
- elseif ( $test['path'] != '/' && $test['path'] != '' )
- $post_links[] = $link_test;
- }
- }