Make WordPress Core


Ignore:
Timestamp:
07/02/2008 11:07:56 PM (18 years ago)
Author:
mdawaffe
Message:

crazyhorse: merge with log:trunk@8151:8240

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/crazyhorse/wp-includes/functions.php

    r8103 r8242  
    100100}
    101101
    102 
     102/**
     103 * Retrieve the date in localized format, based on timestamp.
     104 *
     105 * If the locale specifies the locale month and weekday, then the locale will
     106 * take over the format for the date. If it isn't, then the date format string
     107 * will be used instead.
     108 *
     109 * @since 0.71
     110 *
     111 * @param string $dateformatstring Format to display the date
     112 * @param int $unixtimestamp Unix timestamp
     113 * @return string The date, translated if locale specifies it.
     114 */
    103115function date_i18n( $dateformatstring, $unixtimestamp ) {
    104116    global $wp_locale;
    105117    $i = $unixtimestamp;
     118    // Sanity check for PHP 5.1.0-
     119    if ( -1 == $i )
     120        $i = false;
     121   
    106122    if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) {
    107123        $datemonth = $wp_locale->get_month( date( 'm', $i ) );
     
    277293}
    278294
    279 /* Options functions */
    280 
    281295/**
    282296 * Retrieve option value based on setting name.
    283297 *
    284  * {@internal Missing Long Description}}
     298 * If the option does not exist or does not have a value, then the return value
     299 * will be false. This is useful to check whether you need to install an option
     300 * and is commonly used during installation of plugin options and to test
     301 * whether upgrading is required.
     302 *
     303 * You can "short-circuit" the retrieval of the option from the database for
     304 * your plugin or core options that aren't protected. You can do so by hooking
     305 * into the 'pre_option_$option' with the $option being replaced by the option
     306 * name. You should not try to override special options, but you will not be
     307 * prevented from doing so.
     308 *
     309 * There is a second filter called 'option_$option' with the $option being
     310 * replaced with the option name. This gives the value as the only parameter.
    285311 *
    286312 * @since 1.5.0
    287313 * @package WordPress
    288314 * @subpackage Option
     315 * @uses apply_filters() Calls 'pre_option_$optionname' false to allow
     316 *      overwriting the option value in a plugin.
     317 * @uses apply_filters() Calls 'option_$optionname' with the option name value.
    289318 *
    290319 * @param string $setting Name of option to retrieve. Should already be SQL-escaped
     
    371400}
    372401
     402/**
     403 * Retrieve all autoload options or all options, if no autoloaded ones exist.
     404 *
     405 * This is different from wp_load_alloptions(), in this that function does not
     406 * cache all options and will retrieve all options from the database every time
     407 * it is called.
     408 *
     409 * @since 1.0.0
     410 * @package WordPress
     411 * @subpackage Option
     412 * @uses apply_filters() Calls 'pre_option_$optionname' hook with option value as parameter.
     413 * @uses apply_filters() Calls 'all_options' on options list.
     414 *
     415 * @return array List of all options.
     416 */
    373417function get_alloptions() {
    374418    global $wpdb, $wp_queries;
     
    381425        // "When trying to design a foolproof system,
    382426        //  never underestimate the ingenuity of the fools :)" -- Dougal
    383         if ( in_array( $option->option_name, array( 'siteurl', 'home', 'category_base' ) ) )
     427        if ( in_array( $option->option_name, array( 'siteurl', 'home', 'category_base', 'tag_base' ) ) )
    384428            $option->option_value = untrailingslashit( $option->option_value );
    385429        $value = maybe_unserialize( $option->option_value );
     
    389433}
    390434
    391 
     435/**
     436 * Loads and caches all autoloaded options, if available or all options.
     437 *
     438 * This is different from get_alloptions(), in that this function will cache the
     439 * options and will return the cached options when called again.
     440 *
     441 * @since 2.2.0
     442 * @package WordPress
     443 * @subpackage Option
     444 *
     445 * @return array List all options.
     446 */
    392447function wp_load_alloptions() {
    393448    global $wpdb;
     
    408463}
    409464
    410 
    411 // expects $option_name to NOT be SQL-escaped
     465/**
     466 * Update the value of an option that was already added.
     467 *
     468 * If the option does not exist, then the option will be added with the option
     469 * value, but you will not be able to set whether it is autoloaded. If you want
     470 * to set whether an option autoloaded, then you need to use the add_option().
     471 *
     472 * When the option is updated, then the filter named
     473 * 'update_option_$option_name', with the $option_name as the $option_name
     474 * parameter value, will be called. The hook should accept two parameters, the
     475 * first is the old parameter and the second is the new parameter.
     476 *
     477 * @since 1.0.0
     478 * @package WordPress
     479 * @subpackage Option
     480 *
     481 * @param string $option_name Option name. Expected to not be SQL-escaped
     482 * @param mixed $newvalue Option value.
     483 * @return bool False if value was not updated and true if value was updated.
     484 */
    412485function update_option( $option_name, $newvalue ) {
    413486    global $wpdb;
     
    453526}
    454527
    455 
    456 // thx Alex Stapleton, http://alex.vort-x.net/blog/
    457 // expects $name to NOT be SQL-escaped
     528/**
     529 * Add a new option.
     530 *
     531 * You can create options without values and then add values later. Does not
     532 * check whether the option has already been added, but does check that you
     533 * aren't adding a protected WordPress option. Care should be taken to not name
     534 * options, the same as the ones which are protected and to not add options
     535 * that were already added.
     536 *
     537 * The filter named 'add_option_$optionname', with the $optionname being
     538 * replaced with the option's name, will be called. The hook should accept two
     539 * parameters, the first is the option name, and the second is the value.
     540 *
     541 * @package WordPress
     542 * @subpackage Option
     543 * @since 1.0.0
     544 * @link http://alex.vort-x.net/blog/ Thanks Alex Stapleton
     545 *
     546 * @param string $name Option name to add. Expects to NOT be SQL escaped.
     547 * @param mixed $value Optional. Option value, can be anything.
     548 * @param mixed $deprecated Optional. Description. Not used anymore.
     549 * @param bool $autoload Optional. Default is enabled. Whether to load the option when WordPress starts up.
     550 * @return null returns when finished.
     551 */
    458552function add_option( $name, $value = '', $deprecated = '', $autoload = 'yes' ) {
    459553    global $wpdb;
     
    489583    $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES (%s, %s, %s)", $name, $value, $autoload ) );
    490584
    491     do_action( "add_option_{$name}", $name, $value ); 
     585    do_action( "add_option_{$name}", $name, $value );
    492586    return;
    493587}
    494588
    495 
     589/**
     590 * Removes option by name and prevents removal of protected WordPress options.
     591 *
     592 * @package WordPress
     593 * @subpackage Option
     594 * @since unknown
     595 *
     596 * @param string $name Option name to remove.
     597 * @return bool True, if succeed. False, if failure.
     598 */
    496599function delete_option( $name ) {
    497600    global $wpdb;
     
    518621}
    519622
    520 
     623/**
     624 * Serialize data, if needed.
     625 *
     626 * @param mixed $data Data that might be serialized.
     627 * @return mixed A scalar data
     628 */
    521629function maybe_serialize( $data ) {
    522630    if ( is_string( $data ) )
     
    582690}
    583691
    584 
     692/**
     693 * Open the file handle for debugging.
     694 *
     695 * This function is used for XMLRPC feature, but it is general purpose enough
     696 * to be used in anywhere.
     697 *
     698 * @see fopen() for mode options.
     699 * @package WordPress
     700 * @subpackage Debug
     701 * @since unknown
     702 * @uses $debug Used for whether debugging is enabled.
     703 *
     704 * @param string $filename File path to debug file.
     705 * @param string $mode Same as fopen() mode parameter.
     706 * @return bool|resource File handle. False on failure.
     707 */
    585708function debug_fopen( $filename, $mode ) {
    586709    global $debug;
     
    593716}
    594717
    595 
     718/**
     719 * Write contents to the file used for debugging.
     720 *
     721 * Technically, this can be used to write to any file handle when the global
     722 * $debug is set to 1 or true.
     723 *
     724 * @package WordPress
     725 * @subpackage Debug
     726 * @since unknown
     727 * @uses $debug Used for whether debugging is enabled.
     728 *
     729 * @param resource $fp File handle for debugging file.
     730 * @param string $string Content to write to debug file.
     731 */
    596732function debug_fwrite( $fp, $string ) {
    597733    global $debug;
     
    600736}
    601737
    602 
     738/**
     739 * Close the debugging file handle.
     740 *
     741 * Technically, this can be used to close any file handle when the global $debug
     742 * is set to 1 or true.
     743 *
     744 * @package WordPress
     745 * @subpackage Debug
     746 * @since unknown
     747 * @uses $debug Used for whether debugging is enabled.
     748 *
     749 * @param resource $fp Debug File handle.
     750 */
    603751function debug_fclose( $fp ) {
    604752    global $debug;
     
    769917}
    770918
    771 
     919/**
     920 * Build URL query based on an associative and, or indexed array.
     921 *
     922 * This is a convenient function for easily building url queries. It sets the
     923 * separator to '&' and uses _http_build_query() function.
     924 *
     925 * @see _http_build_query() Used to build the query
     926 * @link http://us2.php.net/manual/en/function.http-build-query.php more on what
     927 *      http_build_query() does.
     928 *
     929 * @since unknown
     930 *
     931 * @param array $data URL-encode key/value pairs.
     932 * @return string URL encoded string
     933 */
    772934function build_query( $data ) {
    773935    return _http_build_query( $data, NULL, '&', '', false );
     
    775937
    776938/**
    777  * Retrieve a modified query string.
    778  *
    779  * {@internal Missing Long Description}}
    780  *
    781  * Adding a single key & value or an associative array.
    782  * Setting a key value to emptystring removes the key.
    783  * Omitting oldquery_or_uri uses the $_SERVER value.
     939 * Retrieve a modified URL query string.
     940 *
     941 * You can rebuild the URL and append a new query variable to the URL query by
     942 * using this function. You can also retrieve the full URL with query data.
     943 *
     944 * Adding a single key & value or an associative array. Setting a key value to
     945 * emptystring removes the key. Omitting oldquery_or_uri uses the $_SERVER
     946 * value.
    784947 *
    785948 * @since 1.5.0
     
    8941057}
    8951058
     1059/**
     1060 * HTTP request for URI to retrieve content.
     1061 *
     1062 * Tries to retrieve the HTTP content with fopen first and then using cURL, if
     1063 * fopen can't be used.
     1064 *
     1065 * @since unknown
     1066 *
     1067 * @param string $uri URI/URL of web page to retrieve.
     1068 * @return string HTTP content.
     1069 */
    8961070function wp_remote_fopen( $uri ) {
    8971071    $timeout = 10;
     
    10051179}
    10061180
    1007 
     1181/**
     1182 * Set HTTP status header.
     1183 *
     1184 * @since unknown
     1185 * @uses apply_filters() Calls 'status_header' on status header string, HTTP
     1186 *      HTTP code, HTTP code description, and protocol string as separate
     1187 *      parameters.
     1188 *
     1189 * @param int $header HTTP status code
     1190 * @return null Does not return anything.
     1191 */
    10081192function status_header( $header ) {
    10091193    $text = get_status_header_desc( $header );
     
    13011485    // $dir is absolute, $path is (maybe) relative to ABSPATH
    13021486    $dir = path_join( ABSPATH, $upload_path );
    1303     $path = str_replace( ABSPATH, '', trim( $upload_path ) );
    13041487
    13051488    if ( !$url = get_option( 'upload_url_path' ) )
    1306         $url = trailingslashit( $siteurl ) . $path;
     1489        $url = WP_CONTENT_URL . '/uploads';
    13071490
    13081491    if ( defined('UPLOADS') ) {
     
    13101493        $url = trailingslashit( $siteurl ) . UPLOADS;
    13111494    }
    1312 
     1495   
    13131496    $subdir = '';
    13141497    if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
     
    17911974}
    17921975
    1793 
    17941976/**
    17951977 * Load the correct database class file.
     
    18091991        require_once( ABSPATH . WPINC . '/wp-db.php' );
    18101992}
    1811 
    18121993
    18131994/**
     
    18582039}
    18592040
    1860 
    18612041/**
    18622042 * Converts value to positive integer.
     
    18702050    return abs( intval( $maybeint ) );
    18712051}
    1872 
    18732052
    18742053/**
     
    19042083    return false;
    19052084}
    1906 
    19072085
    19082086/**
     
    19222100}
    19232101
    1924 
    19252102/**
    19262103 * Marks a function as deprecated and informs when it has been used.
     
    19602137}
    19612138
    1962 
    19632139/**
    19642140 * Marks a file as deprecated and informs when it has been used.
     
    19982174}
    19992175
    2000 
    20012176/**
    20022177 * Is the server running earlier than 1.5.0 version of lighttpd
     
    20112186    return  'lighttpd' == $server_parts[0] && -1 == version_compare( $server_parts[1], '1.5.0' );
    20122187}
    2013 
    20142188
    20152189/**
     
    20422216}
    20432217
    2044 
    20452218/**
    20462219 * File validates against allowed set of defined rules.
     
    20732246}
    20742247
    2075 
    20762248/**
    20772249 * Determine if SSL is used.
     
    20842256    return ( 'on' == strtolower($_SERVER['HTTPS']) ) ? true : false;
    20852257}
    2086 
    20872258
    20882259/**
     
    21062277}
    21072278
    2108 
    21092279/**
    21102280 * Whether to force SSL used for the Administration Panels.
     
    21272297}
    21282298
     2299/**
     2300 * Guess the URL for the site.
     2301 *
     2302 * Will remove wp-admin links to retrieve only return URLs not in the wp-admin
     2303 * directory.
     2304 *
     2305 * @since 2.6
     2306 *
     2307 * @return string
     2308 */
     2309function wp_guess_url() {
     2310    if ( defined('WP_SITEURL') && '' != WP_SITEURL ) {
     2311        $url = WP_SITEURL;
     2312    } else {
     2313        $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
     2314        $url = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
     2315    }
     2316    return $url;
     2317}
     2318
    21292319?>
Note: See TracChangeset for help on using the changeset viewer.