Make WordPress Core

Changeset 6223


Ignore:
Timestamp:
10/11/2007 05:46:57 AM (18 years ago)
Author:
markjaquith
Message:

Code cleanup and standardization for functions.php

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r6222 r6223  
    11<?php
    22
    3 function mysql2date($dateformatstring, $mysqlstring, $translate = true) {
     3function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) {
    44    global $wp_locale;
    55    $m = $mysqlstring;
    6     if ( empty($m) ) {
     6    if ( empty( $m ) )
    77        return false;
    8     }
    98    $i = mktime(
    109        (int) substr( $m, 11, 2 ), (int) substr( $m, 14, 2 ), (int) substr( $m, 17, 2 ),
     
    1817        $i = 0;
    1918
    20     if ( !empty($wp_locale->month) && !empty($wp_locale->weekday) && $translate ) {
    21         $datemonth = $wp_locale->get_month(date('m', $i));
    22         $datemonth_abbrev = $wp_locale->get_month_abbrev($datemonth);
    23         $dateweekday = $wp_locale->get_weekday(date('w', $i));
    24         $dateweekday_abbrev = $wp_locale->get_weekday_abbrev($dateweekday);
    25         $datemeridiem = $wp_locale->get_meridiem(date('a', $i));
    26         $datemeridiem_capital = $wp_locale->get_meridiem(date('A', $i));
    27         $dateformatstring = ' '.$dateformatstring;
    28         $dateformatstring = preg_replace("/([^\\\])D/", "\\1".backslashit($dateweekday_abbrev), $dateformatstring);
    29         $dateformatstring = preg_replace("/([^\\\])F/", "\\1".backslashit($datemonth), $dateformatstring);
    30         $dateformatstring = preg_replace("/([^\\\])l/", "\\1".backslashit($dateweekday), $dateformatstring);
    31         $dateformatstring = preg_replace("/([^\\\])M/", "\\1".backslashit($datemonth_abbrev), $dateformatstring);
    32         $dateformatstring = preg_replace("/([^\\\])a/", "\\1".backslashit($datemeridiem), $dateformatstring);
    33         $dateformatstring = preg_replace("/([^\\\])A/", "\\1".backslashit($datemeridiem_capital), $dateformatstring);
    34 
    35         $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring)-1);
    36     }
    37     $j = @date($dateformatstring, $i);
    38     if ( !$j ) {
    39     // for debug purposes
    40     //  echo $i." ".$mysqlstring;
    41     }
     19    if ( !empty( $wp_locale->month ) && !empty( $wp_locale->weekday ) && $translate ) {
     20        $datemonth = $wp_locale->get_month( date( 'm', $i ) );
     21        $datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth );
     22        $dateweekday = $wp_locale->get_weekday( date( 'w', $i ) );
     23        $dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday );
     24        $datemeridiem = $wp_locale->get_meridiem( date( 'a', $i ) );
     25        $datemeridiem_capital = $wp_locale->get_meridiem( date( 'A', $i ) );
     26        $dateformatstring = ' ' . $dateformatstring;
     27        $dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring );
     28        $dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring );
     29        $dateformatstring = preg_replace( "/([^\\\])l/", "\\1" . backslashit( $dateweekday ), $dateformatstring );
     30        $dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring );
     31        $dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring );
     32        $dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring );
     33
     34        $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
     35    }
     36    $j = @date( $dateformatstring, $i );
     37
     38    /*
     39    if ( !$j ) // for debug purposes
     40        echo $i." ".$mysqlstring;
     41    */
     42
    4243    return $j;
    4344}
    4445
    45 function current_time($type, $gmt = 0) {
    46     switch ($type) {
     46
     47function current_time( $type, $gmt = 0 ) {
     48    switch ( $type ) {
    4749        case 'mysql':
    48             if ( $gmt ) $d = gmdate('Y-m-d H:i:s');
    49             else $d = gmdate('Y-m-d H:i:s', (time() + (get_option('gmt_offset') * 3600)));
    50             return $d;
     50            return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) );
    5151            break;
    5252        case 'timestamp':
    53             if ( $gmt ) $d = time();
    54             else $d = time() + (get_option('gmt_offset') * 3600);
    55             return $d;
     53            return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * 3600 );
    5654            break;
    5755    }
    5856}
    5957
    60 function date_i18n($dateformatstring, $unixtimestamp) {
     58
     59function date_i18n( $dateformatstring, $unixtimestamp ) {
    6160    global $wp_locale;
    6261    $i = $unixtimestamp;
    63     if ( (!empty($wp_locale->month)) && (!empty($wp_locale->weekday)) ) {
    64         $datemonth = $wp_locale->get_month(date('m', $i));
    65         $datemonth_abbrev = $wp_locale->get_month_abbrev($datemonth);
    66         $dateweekday = $wp_locale->get_weekday(date('w', $i));
    67         $dateweekday_abbrev = $wp_locale->get_weekday_abbrev($dateweekday);
    68         $datemeridiem = $wp_locale->get_meridiem(date('a', $i));
    69         $datemeridiem_capital = $wp_locale->get_meridiem(date('A', $i));
     62    if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) {
     63        $datemonth = $wp_locale->get_month( date( 'm', $i ) );
     64        $datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth );
     65        $dateweekday = $wp_locale->get_weekday( date( 'w', $i ) );
     66        $dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday );
     67        $datemeridiem = $wp_locale->get_meridiem( date( 'a', $i ) );
     68        $datemeridiem_capital = $wp_locale->get_meridiem( date( 'A', $i ) );
    7069        $dateformatstring = ' '.$dateformatstring;
    71         $dateformatstring = preg_replace("/([^\\\])D/", "\\1".backslashit($dateweekday_abbrev), $dateformatstring);
    72         $dateformatstring = preg_replace("/([^\\\])F/", "\\1".backslashit($datemonth), $dateformatstring);
    73         $dateformatstring = preg_replace("/([^\\\])l/", "\\1".backslashit($dateweekday), $dateformatstring);
    74         $dateformatstring = preg_replace("/([^\\\])M/", "\\1".backslashit($datemonth_abbrev), $dateformatstring);
    75         $dateformatstring = preg_replace("/([^\\\])a/", "\\1".backslashit($datemeridiem), $dateformatstring);
    76         $dateformatstring = preg_replace("/([^\\\])A/", "\\1".backslashit($datemeridiem_capital), $dateformatstring);
    77 
    78         $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring)-1);
    79     }
    80     $j = @date($dateformatstring, $i);
     70        $dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring );
     71        $dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring );
     72        $dateformatstring = preg_replace( "/([^\\\])l/", "\\1" . backslashit( $dateweekday ), $dateformatstring );
     73        $dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring );
     74        $dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring );
     75        $dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring );
     76
     77        $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
     78    }
     79    $j = @date( $dateformatstring, $i );
    8180    return $j;
    8281}
    8382
    84 function number_format_i18n($number, $decimals = null) {
     83
     84function number_format_i18n( $number, $decimals = null ) {
    8585    global $wp_locale;
    8686    // let the user override the precision only
    87     $decimals = is_null($decimals)? $wp_locale->number_format['decimals'] : intval($decimals);
    88 
    89     return number_format($number, $decimals, $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep']);
    90 }
    91 
    92 function size_format($bytes, $decimals = null) {
     87    $decimals = ( is_null( $decimals ) ) ? $wp_locale->number_format['decimals'] : intval( $decimals );
     88
     89    return number_format( $number, $decimals, $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] );
     90}
     91
     92
     93function size_format( $bytes, $decimals = null ) {
    9394    // technically the correct unit names for powers of 1024 are KiB, MiB etc
    9495    // see http://en.wikipedia.org/wiki/Byte
    9596    $quant = array(
    96         'TB' => pow(1024, 4),
    97         'GB' => pow(1024, 3),
    98         'MB' => pow(1024, 2),
    99         'kB' => pow(1024, 1),
    100         'B'  => pow(1024, 0),
     97        // ========================= Origin ====
     98        'TB' => 1099511627776,  // pow( 1024, 4)
     99        'GB' => 1073741824,     // pow( 1024, 3)
     100        'MB' => 1048576,        // pow( 1024, 2)
     101        'kB' => 1024,           // pow( 1024, 1)
     102        'B ' => 1,              // pow( 1024, 0)
    101103    );
    102104
    103     foreach ($quant as $unit => $mag)
    104         if ( intval($bytes) >= $mag )
    105             return number_format_i18n($bytes / $mag, $decimals) . ' ' . $unit;
    106 }
    107 
    108 function get_weekstartend($mysqlstring, $start_of_week) {
    109     $my = substr($mysqlstring,0,4);
    110     $mm = substr($mysqlstring,8,2);
    111     $md = substr($mysqlstring,5,2);
    112     $day = mktime(0,0,0, $md, $mm, $my);
    113     $weekday = date('w',$day);
     105    foreach ( $quant as $unit => $mag )
     106        if ( intval( $bytes ) >= $mag )
     107            return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;
     108}
     109
     110
     111function get_weekstartend( $mysqlstring, $start_of_week ) {
     112    $my = substr( $mysqlstring, 0, 4 );
     113    $mm = substr( $mysqlstring, 8, 2 );
     114    $md = substr( $mysqlstring, 5, 2 );
     115    $day = mktime( 0, 0, 0, $md, $mm, $my );
     116    $weekday = date( 'w', $day );
    114117    $i = 86400;
    115118
    116     if ( $weekday < get_option('start_of_week') )
    117         $weekday = 7 - (get_option('start_of_week') - $weekday);
    118 
    119     while ($weekday > get_option('start_of_week')) {
    120         $weekday = date('w',$day);
    121         if ( $weekday < get_option('start_of_week') )
    122             $weekday = 7 - (get_option('start_of_week') - $weekday);
     119    if ( $weekday < get_option( 'start_of_week' ) )
     120        $weekday = 7 - ( get_option( 'start_of_week' ) - $weekday );
     121
     122    while ( $weekday > get_option( 'start_of_week' ) ) {
     123        $weekday = date( 'w', $day );
     124        if ( $weekday < get_option( 'start_of_week' ) )
     125            $weekday = 7 - ( get_option( 'start_of_week' ) - $weekday );
    123126
    124127        $day = $day - 86400;
     
    126129    }
    127130    $week['start'] = $day + 86400 - $i;
    128     // $week['end'] = $day - $i + 691199;
    129131    $week['end'] = $week['start'] + 604799;
    130132    return $week;
    131133}
    132134
    133 function maybe_unserialize($original) {
    134     if ( is_serialized($original) ) // don't attempt to unserialize data that wasn't serialized going in
    135         if ( false !== $gm = @ unserialize($original) )
     135
     136function maybe_unserialize( $original ) {
     137    if ( is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in
     138        if ( false !== $gm = @unserialize( $original ) )
    136139            return $gm;
    137140    return $original;
    138141}
    139142
    140 function is_serialized($data) {
     143
     144function is_serialized( $data ) {
    141145    // if it isn't a string, it isn't serialized
    142     if ( !is_string($data) )
     146    if ( !is_string( $data ) )
    143147        return false;
    144     $data = trim($data);
     148    $data = trim( $data );
    145149    if ( 'N;' == $data )
    146150        return true;
    147     if ( !preg_match('/^([adObis]):/', $data, $badions) )
     151    if ( !preg_match( '/^([adObis]):/', $data, $badions ) )
    148152        return false;
    149     switch ( $badions[1] ) :
    150     case 'a' :
    151     case 'O' :
    152     case 's' :
    153         if ( preg_match("/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data) )
    154             return true;
    155         break;
    156     case 'b' :
    157     case 'i' :
    158     case 'd' :
    159         if ( preg_match("/^{$badions[1]}:[0-9.E-]+;\$/", $data) )
    160             return true;
    161         break;
    162     endswitch;
     153    switch ( $badions[1] ) {
     154        case 'a' :
     155        case 'O' :
     156        case 's' :
     157            if ( preg_match( "/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data ) )
     158                return true;
     159            break;
     160        case 'b' :
     161        case 'i' :
     162        case 'd' :
     163            if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) )
     164                return true;
     165            break;
     166    }
    163167    return false;
    164168}
    165169
    166 function is_serialized_string($data) {
     170
     171function is_serialized_string( $data ) {
    167172    // if it isn't a string, it isn't a serialized string
    168     if ( !is_string($data) )
     173    if ( !is_string( $data ) )
    169174        return false;
    170     $data = trim($data);
    171     if ( preg_match('/^s:[0-9]+:.*;$/s',$data) ) // this should fetch all serialized strings
     175    $data = trim( $data );
     176    if ( preg_match( '/^s:[0-9]+:.*;$/s', $data ) ) // this should fetch all serialized strings
    172177        return true;
    173178    return false;
    174179}
    175180
     181
    176182/* Options functions */
    177183
    178184// expects $setting to already be SQL-escaped
    179 function get_option($setting) {
     185function get_option( $setting ) {
    180186    global $wpdb;
    181187
     
    186192
    187193    // prevent non-existent options from triggering multiple queries
    188     $notoptions = wp_cache_get('notoptions', 'options');
    189     if ( isset($notoptions[$setting]) )
     194    $notoptions = wp_cache_get( 'notoptions', 'options' );
     195    if ( isset( $notoptions[$setting] ) )
    190196        return false;
    191197
    192198    $alloptions = wp_load_alloptions();
    193199
    194     if ( isset($alloptions[$setting]) ) {
     200    if ( isset( $alloptions[$setting] ) ) {
    195201        $value = $alloptions[$setting];
    196202    } else {
    197         $value = wp_cache_get($setting, 'options');
     203        $value = wp_cache_get( $setting, 'options' );
    198204
    199205        if ( false === $value ) {
    200             if ( defined('WP_INSTALLING') )
     206            if ( defined( 'WP_INSTALLING' ) )
    201207                $wpdb->hide_errors();
    202208            // expected_slashed ($setting)
    203             $row = $wpdb->get_row("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1");
    204             if ( defined('WP_INSTALLING') )
     209            $row = $wpdb->get_row( "SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1" );
     210            if ( defined( 'WP_INSTALLING' ) )
    205211                $wpdb->show_errors();
    206212
    207             if( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
     213            if ( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
    208214                $value = $row->option_value;
    209                 wp_cache_add($setting, $value, 'options');
     215                wp_cache_add( $setting, $value, 'options' );
    210216            } else { // option does not exist, so we must cache its non-existence
    211217                $notoptions[$setting] = true;
    212                 wp_cache_set('notoptions', $notoptions, 'options');
     218                wp_cache_set( 'notoptions', $notoptions, 'options' );
    213219                return false;
    214220            }
     
    218224    // If home is not set use siteurl.
    219225    if ( 'home' == $setting && '' == $value )
    220         return get_option('siteurl');
    221 
    222     if ( in_array($setting, array('siteurl', 'home', 'category_base', 'tag_base')) )
    223         $value = untrailingslashit($value);
    224 
    225     return apply_filters( 'option_' . $setting, maybe_unserialize($value) );
    226 }
    227 
    228 function wp_protect_special_option($option) {
    229     $protected = array('alloptions', 'notoptions');
    230     if ( in_array($option, $protected) )
    231         die(sprintf(__('%s is a protected WP option and may not be modified'), wp_specialchars($option)));
    232 }
    233 
    234 function form_option($option) {
    235     echo attribute_escape(get_option($option));
     226        return get_option( 'siteurl' );
     227
     228    if ( in_array( $setting, array('siteurl', 'home', 'category_base', 'tag_base') ) )
     229        $value = untrailingslashit( $value );
     230
     231    return apply_filters( 'option_' . $setting, maybe_unserialize( $value ) );
     232}
     233
     234
     235function wp_protect_special_option( $option ) {
     236    $protected = array( 'alloptions', 'notoptions' );
     237    if ( in_array( $option, $protected ) )
     238        die( sprintf( __( '%s is a protected WP option and may not be modified' ), wp_specialchars( $option ) ) );
     239}
     240
     241function form_option( $option ) {
     242    echo attribute_escape (get_option( $option ) );
    236243}
    237244
     
    239246    global $wpdb, $wp_queries;
    240247    $wpdb->hide_errors();
    241     if ( !$options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'") ) {
    242         $options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options");
    243     }
     248    if ( !$options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) )
     249        $options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
    244250    $wpdb->show_errors();
    245251
    246     foreach ($options as $option) {
     252    foreach ( $options as $option ) {
    247253        // "When trying to design a foolproof system,
    248254        //  never underestimate the ingenuity of the fools :)" -- Dougal
    249         if ( 'siteurl' == $option->option_name )
    250             $option->option_value = preg_replace('|/+$|', '', $option->option_value);
    251         if ( 'home' == $option->option_name )
    252             $option->option_value = preg_replace('|/+$|', '', $option->option_value);
    253         if ( 'category_base' == $option->option_name )
    254             $option->option_value = preg_replace('|/+$|', '', $option->option_value);
    255         $value = maybe_unserialize($option->option_value);
    256         $all_options->{$option->option_name} = apply_filters('pre_option_' . $option->option_name, $value);
    257     }
    258     return apply_filters('all_options', $all_options);
    259 }
     255        if ( in_array( $option->option_name, array( 'siteurl', 'home', 'category_base' ) ) )
     256            $option->option_value = untrailingslashit( $option->option_value );
     257        $value = maybe_unserialize( $option->option_value );
     258        $all_options->{$option->option_name} = apply_filters( 'pre_option_' . $option->option_name, $value );
     259    }
     260    return apply_filters( 'all_options', $all_options );
     261}
     262
    260263
    261264function wp_load_alloptions() {
    262265    global $wpdb;
    263266
    264     $alloptions = wp_cache_get('alloptions', 'options');
     267    $alloptions = wp_cache_get( 'alloptions', 'options' );
    265268
    266269    if ( !$alloptions ) {
    267270        $wpdb->hide_errors();
    268         if ( !$alloptions_db = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'") )
    269             $alloptions_db = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options");
     271        if ( !$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) )
     272            $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
    270273        $wpdb->show_errors();
    271274        $alloptions = array();
    272275        foreach ( (array) $alloptions_db as $o )
    273276            $alloptions[$o->option_name] = $o->option_value;
    274         wp_cache_add('alloptions', $alloptions, 'options');
     277        wp_cache_add( 'alloptions', $alloptions, 'options' );
    275278    }
    276279    return $alloptions;
    277280}
    278281
     282
    279283// expects $option_name to NOT be SQL-escaped
    280 function update_option($option_name, $newvalue) {
     284function update_option( $option_name, $newvalue ) {
    281285    global $wpdb;
    282286
    283     wp_protect_special_option($option_name);
    284 
    285     $safe_option_name = $wpdb->escape($option_name);
    286     $newvalue = sanitize_option($option_name, $newvalue);
    287 
    288     if ( is_string($newvalue) )
    289         $newvalue = trim($newvalue);
     287    wp_protect_special_option( $option_name );
     288
     289    $safe_option_name = $wpdb->escape( $option_name );
     290    $newvalue = sanitize_option( $option_name, $newvalue );
     291
     292    // Likely legacy -- can we drop this?
     293    if ( is_string( $newvalue ) )
     294        $newvalue = trim( $newvalue );
    290295
    291296    // If the new and old values are the same, no need to update.
    292     $oldvalue = get_option($safe_option_name);
    293     if ( $newvalue === $oldvalue ) {
     297    $oldvalue = get_option( $safe_option_name );
     298    if ( $newvalue === $oldvalue )
    294299        return false;
    295     }
    296300
    297301    if ( false === $oldvalue ) {
    298         add_option($option_name, $newvalue);
     302        add_option( $option_name, $newvalue );
    299303        return true;
    300304    }
    301305
    302     $notoptions = wp_cache_get('notoptions', 'options');
    303     if ( is_array($notoptions) && isset($notoptions[$option_name]) ) {
    304         unset($notoptions[$option_name]);
    305         wp_cache_set('notoptions', $notoptions, 'options');
     306    $notoptions = wp_cache_get( 'notoptions', 'options' );
     307    if ( is_array( $notoptions ) && isset( $notoptions[$option_name] ) ) {
     308        unset( $notoptions[$option_name] );
     309        wp_cache_set( 'notoptions', $notoptions, 'options' );
    306310    }
    307311
    308312    $_newvalue = $newvalue;
    309     $newvalue = maybe_serialize($newvalue);
     313    $newvalue = maybe_serialize( $newvalue );
    310314
    311315    $alloptions = wp_load_alloptions();
    312     if ( isset($alloptions[$option_name]) ) {
     316    if ( isset( $alloptions[$option_name] ) ) {
    313317        $alloptions[$option_name] = $newvalue;
    314         wp_cache_set('alloptions', $alloptions, 'options');
     318        wp_cache_set( 'alloptions', $alloptions, 'options' );
    315319    } else {
    316         wp_cache_set($option_name, $newvalue, 'options');
    317     }
    318 
    319     $wpdb->query($wpdb->prepare("UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s", $newvalue, $option_name));
     320        wp_cache_set( $option_name, $newvalue, 'options' );
     321    }
     322
     323    $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s", $newvalue, $option_name ) );
    320324    if ( $wpdb->rows_affected == 1 ) {
    321         do_action("update_option_{$option_name}", $oldvalue, $_newvalue);
     325        do_action( "update_option_{$option_name}", $oldvalue, $_newvalue );
    322326        return true;
    323327    }
    324328    return false;
    325329}
     330
    326331
    327332// thx Alex Stapleton, http://alex.vort-x.net/blog/
    328333// expects $name to NOT be SQL-escaped
    329 function add_option($name, $value = '', $deprecated = '', $autoload = 'yes') {
     334function add_option( $name, $value = '', $deprecated = '', $autoload = 'yes' ) {
    330335    global $wpdb;
    331336
    332     wp_protect_special_option($name);
    333     $safe_name = $wpdb->escape($name);
     337    wp_protect_special_option( $name );
     338    $safe_name = $wpdb->escape( $name );
    334339
    335340    // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
    336     $notoptions = wp_cache_get('notoptions', 'options');
    337     if ( !is_array($notoptions) || !isset($notoptions[$name]) )
    338         if ( false !== get_option($safe_name) )
     341    $notoptions = wp_cache_get( 'notoptions', 'options' );
     342    if ( !is_array( $notoptions ) || !isset( $notoptions[$name] ) )
     343        if ( false !== get_option( $safe_name ) )
    339344            return;
    340345
    341     $value = maybe_serialize($value);
     346    $value = maybe_serialize( $value );
    342347    $autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
    343348
     
    345350        $alloptions = wp_load_alloptions();
    346351        $alloptions[$name] = $value;
    347         wp_cache_set('alloptions', $alloptions, 'options');
     352        wp_cache_set( 'alloptions', $alloptions, 'options' );
    348353    } else {
    349         wp_cache_set($name, $value, 'options');
     354        wp_cache_set( $name, $value, 'options' );
    350355    }
    351356
    352357    // This option exists now
    353     $notoptions = wp_cache_get('notoptions', 'options'); // yes, again... we need it to be fresh
    354     if ( is_array($notoptions) && isset($notoptions[$name]) ) {
    355         unset($notoptions[$name]);
    356         wp_cache_set('notoptions', $notoptions, 'options');
    357     }
    358 
    359     $wpdb->query($wpdb->prepare("INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES (%s, %s, %s)", $name, $value, $autoload));
     358    $notoptions = wp_cache_get( 'notoptions', 'options' ); // yes, again... we need it to be fresh
     359    if ( is_array( $notoptions ) && isset( $notoptions[$name] ) ) {
     360        unset( $notoptions[$name] );
     361        wp_cache_set( 'notoptions', $notoptions, 'options' );
     362    }
     363
     364    $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES (%s, %s, %s)", $name, $value, $autoload ) );
    360365
    361366    return;
    362367}
    363368
    364 function delete_option($name) {
     369
     370function delete_option( $name ) {
    365371    global $wpdb;
    366372
    367     wp_protect_special_option($name);
     373    wp_protect_special_option( $name );
    368374
    369375    // Get the ID, if no ID then return
    370376    // expected_slashed ($name)
    371     $option = $wpdb->get_row("SELECT option_id, autoload FROM $wpdb->options WHERE option_name = '$name'");
    372     if ( !$option->option_id ) return false;
     377    $option = $wpdb->get_row( "SELECT option_id, autoload FROM $wpdb->options WHERE option_name = '$name'" );
     378    if ( !$option->option_id )
     379        return false;
    373380    // expected_slashed ($name)
    374     $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = '$name'");
     381    $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" );
    375382    if ( 'yes' == $option->autoload ) {
    376383        $alloptions = wp_load_alloptions();
    377         if ( isset($alloptions[$name]) ) {
    378             unset($alloptions[$name]);
    379             wp_cache_set('alloptions', $alloptions, 'options');
     384        if ( isset( $alloptions[$name] ) ) {
     385            unset( $alloptions[$name] );
     386            wp_cache_set( 'alloptions', $alloptions, 'options' );
    380387        }
    381388    } else {
    382         wp_cache_delete($name, 'options');
     389        wp_cache_delete( $name, 'options' );
    383390    }
    384391    return true;
    385392}
    386393
    387 function maybe_serialize($data) {
    388     if ( is_string($data) )
    389         $data = trim($data);
    390     elseif ( is_array($data) || is_object($data) )
    391         return serialize($data);
    392     if ( is_serialized($data) )
    393         return serialize($data);
     394
     395function maybe_serialize( $data ) {
     396    if ( is_string( $data ) )
     397        $data = trim( $data );
     398    elseif ( is_array( $data ) || is_object( $data ) )
     399        return serialize( $data );
     400    if ( is_serialized( $data ) )
     401        return serialize( $data );
    394402    return $data;
    395403}
    396404
     405
    397406function gzip_compression() {
    398     if ( !get_option( 'gzipcompression' ) ) {
     407    if ( !get_option( 'gzipcompression' ) || ini_get( 'zlib.output_compression' ) == 'On' || ini_get( 'zlib.output_compression_level' ) > 0  || ini_get( 'output_handler' ) == 'ob_gzhandler' || !extension_loaded( 'zlib' ) )
    399408        return false;
    400     }
    401 
    402     if ( ( ini_get( 'zlib.output_compression' ) == 'On' || ini_get( 'zlib.output_compression_level' ) > 0 ) || ini_get( 'output_handler' ) == 'ob_gzhandler' ) {
    403         return false;
    404     }
    405 
    406     if ( extension_loaded( 'zlib' ) ) {
    407         ob_start( 'ob_gzhandler' );
    408     }
    409 }
    410 
    411 function make_url_footnote($content) {
    412     preg_match_all('/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches);
     409    ob_start( 'ob_gzhandler' );
     410}
     411
     412
     413function make_url_footnote( $content ) {
     414    preg_match_all( '/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches );
    413415    $j = 0;
    414     for ($i=0; $i<count($matches[0]); $i++) {
    415         $links_summary = (!$j) ? "\n" : $links_summary;
     416    for ( $i=0; $i<count($matches[0]); $i++ ) {
     417        $links_summary = ( !$j ) ? "\n" : $links_summary;
    416418        $j++;
    417419        $link_match = $matches[0][$i];
     
    419421        $link_url = $matches[2][$i];
    420422        $link_text = $matches[4][$i];
    421         $content = str_replace($link_match, $link_text.' '.$link_number, $content);
    422         $link_url = ((strtolower(substr($link_url,0,7)) != 'http://') && (strtolower(substr($link_url,0,8)) != 'https://')) ? get_option('home') . $link_url : $link_url;
    423         $links_summary .= "\n".$link_number.' '.$link_url;
    424     }
    425     $content = strip_tags($content);
     423        $content = str_replace( $link_match, $link_text . ' ' . $link_number, $content );
     424        $link_url = ( ( strtolower( substr( $link_url, 0, 7 ) ) != 'http://' ) && ( strtolower( substr( $link_url, 0, 8 ) ) != 'https://' ) ) ? get_option( 'home' ) . $link_url : $link_url;
     425        $links_summary .= "\n" . $link_number . ' ' . $link_url;
     426    }
     427    $content  = strip_tags( $content );
    426428    $content .= $links_summary;
    427429    return $content;
     
    429431
    430432
    431 function xmlrpc_getposttitle($content) {
     433function xmlrpc_getposttitle( $content ) {
    432434    global $post_default_title;
    433     if ( preg_match('/<title>(.+?)<\/title>/is', $content, $matchtitle) ) {
     435    if ( preg_match( '/<title>(.+?)<\/title>/is', $content, $matchtitle ) ) {
    434436        $post_title = $matchtitle[0];
    435         $post_title = preg_replace('/<title>/si', '', $post_title);
    436         $post_title = preg_replace('/<\/title>/si', '', $post_title);
     437        $post_title = preg_replace( '/<title>/si', '', $post_title );
     438        $post_title = preg_replace( '/<\/title>/si', '', $post_title );
    437439    } else {
    438440        $post_title = $post_default_title;
     
    441443}
    442444
    443 function xmlrpc_getpostcategory($content) {
     445
     446function xmlrpc_getpostcategory( $content ) {
    444447    global $post_default_category;
    445     if ( preg_match('/<category>(.+?)<\/category>/is', $content, $matchcat) ) {
    446         $post_category = trim($matchcat[1], ',');
    447         $post_category = explode(',', $post_category);
     448    if ( preg_match( '/<category>(.+?)<\/category>/is', $content, $matchcat ) ) {
     449        $post_category = trim( $matchcat[1], ',' );
     450        $post_category = explode( ',', $post_category );
    448451    } else {
    449452        $post_category = $post_default_category;
     
    452455}
    453456
    454 function xmlrpc_removepostdata($content) {
    455     $content = preg_replace('/<title>(.+?)<\/title>/si', '', $content);
    456     $content = preg_replace('/<category>(.+?)<\/category>/si', '', $content);
    457     $content = trim($content);
     457
     458function xmlrpc_removepostdata( $content ) {
     459    $content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content );
     460    $content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content );
     461    $content = trim( $content );
    458462    return $content;
    459463}
    460464
    461 function debug_fopen($filename, $mode) {
     465
     466function debug_fopen( $filename, $mode ) {
    462467    global $debug;
    463     if ( $debug == 1 ) {
    464         $fp = fopen($filename, $mode);
     468    if ( 1 == $debug ) {
     469        $fp = fopen( $filename, $mode );
    465470        return $fp;
    466471    } else {
     
    469474}
    470475
    471 function debug_fwrite($fp, $string) {
     476
     477function debug_fwrite( $fp, $string ) {
    472478    global $debug;
    473     if ( $debug == 1 ) {
    474         fwrite($fp, $string);
    475     }
    476 }
    477 
    478 function debug_fclose($fp) {
     479    if ( 1 == $debug )
     480        fwrite( $fp, $string );
     481}
     482
     483
     484function debug_fclose( $fp ) {
    479485    global $debug;
    480     if ( $debug == 1 ) {
    481         fclose($fp);
    482     }
     486    if ( 1 == $debug )
     487        fclose( $fp );
    483488}
    484489
    485490function do_enclose( $content, $post_ID ) {
    486491    global $wp_version, $wpdb;
    487     include_once (ABSPATH . WPINC . '/class-IXR.php');
    488 
    489     $log = debug_fopen(ABSPATH . 'enclosures.log', 'a');
     492    include_once( ABSPATH . WPINC . '/class-IXR.php' );
     493
     494    $log = debug_fopen( ABSPATH . 'enclosures.log', 'a' );
    490495    $post_links = array();
    491     debug_fwrite($log, 'BEGIN '.date('YmdHis', time())."\n");
     496    debug_fwrite( $log, 'BEGIN ' . date( 'YmdHis', time() ) . "\n" );
    492497
    493498    $pung = get_enclosed( $post_ID );
     
    498503    $any = $ltrs . $gunk . $punc;
    499504
    500     preg_match_all("{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp);
    501 
    502     debug_fwrite($log, 'Post contents:');
    503     debug_fwrite($log, $content."\n");
    504 
    505     foreach($post_links_temp[0] as $link_test) :
    506         if ( !in_array($link_test, $pung) ) : // If we haven't pung it already
    507             $test = parse_url($link_test);
    508             if ( isset($test['query']) )
     505    preg_match_all( "{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp );
     506
     507    debug_fwrite( $log, 'Post contents:' );
     508    debug_fwrite( $log, $content . "\n" );
     509
     510    foreach ( $post_links_temp[0] as $link_test ) {
     511        if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already
     512            $test = parse_url( $link_test );
     513            if ( isset( $test['query'] ) )
    509514                $post_links[] = $link_test;
    510             elseif (($test['path'] != '/') && ($test['path'] != ''))
     515            elseif ( $test['path'] != '/' && $test['path'] != '' )
    511516                $post_links[] = $link_test;
    512         endif;
    513     endforeach;
    514 
    515     foreach ($post_links as $url) :
    516         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.'%')) ) {
     517        }
     518    }
     519
     520    foreach ( $post_links as $url ) {
     521        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 . '%' ) ) ) {
    517522            if ( $headers = wp_get_http_headers( $url) ) {
    518523                $len = (int) $headers['content-length'];
     
    521526                if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
    522527                    $meta_value = "$url\n$len\n$type\n";
    523                     $wpdb->query($wpdb->prepare("INSERT INTO `$wpdb->postmeta` ( `post_id` , `meta_key` , `meta_value` )
    524                     VALUES ( %d, 'enclosure' , %s)", $post_ID, $meta_value));
     528                    $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->postmeta` ( `post_id` , `meta_key` , `meta_value` )
     529                    VALUES ( %d, 'enclosure' , %s)", $post_ID, $meta_value ) );
    525530                }
    526531            }
    527532        }
    528     endforeach;
    529 }
     533    }
     534}
     535
    530536
    531537function wp_get_http_headers( $url, $red = 1 ) {
     
    537543
    538544    $parts = parse_url( $url );
    539     $file = $parts['path'] . ($parts['query'] ? '?'.$parts['query'] : '');
     545    $file = $parts['path'] . ( ( $parts['query'] ) ? '?' . $parts['query'] : '' );
    540546    $host = $parts['host'];
    541547    if ( !isset( $parts['port'] ) )
     
    544550    $head = "HEAD $file HTTP/1.1\r\nHOST: $host\r\nUser-Agent: WordPress/" . $wp_version . "\r\n\r\n";
    545551
    546     $fp = @fsockopen($host, $parts['port'], $err_num, $err_msg, 3);
     552    $fp = @fsockopen( $host, $parts['port'], $err_num, $err_msg, 3 );
    547553    if ( !$fp )
    548554        return false;
     
    553559        $response .= fgets( $fp, 2048 );
    554560    fclose( $fp );
    555     preg_match_all('/(.*?): (.*)\r/', $response, $matches);
    556     $count = count($matches[1]);
    557     for ( $i = 0; $i < $count; $i++) {
    558         $key = strtolower($matches[1][$i]);
     561    preg_match_all( '/(.*?): (.*)\r/', $response, $matches );
     562    $count = count( $matches[1] );
     563    for ( $i = 0; $i < $count; $i++ ) {
     564        $key = strtolower( $matches[1][$i] );
    559565        $headers["$key"] = $matches[2][$i];
    560566    }
    561567
    562     preg_match('/.*([0-9]{3}).*/', $response, $return);
     568    preg_match( '/.*([0-9]{3}).*/', $response, $return );
    563569    $headers['response'] = $return[1]; // HTTP response code eg 204, 200, 404
    564570
    565571        $code = $headers['response'];
    566         if ( ('302' == $code || '301' == $code) && isset($headers['location']) )
     572        if ( ( '302' == $code || '301' == $code ) && isset( $headers['location'] ) )
    567573                return wp_get_http_headers( $headers['location'], ++$red );
    568574
    569575    return $headers;
    570576}
     577
    571578
    572579function is_new_day() {
    573580    global $day, $previousday;
    574     if ( $day != $previousday ) {
    575         return(1);
    576     } else {
    577         return(0);
    578     }
    579 }
    580 
    581 function build_query($data) {
    582     return _http_build_query($data, NULL, '&', '', false);
    583 }
     581    if ( $day != $previousday )
     582        return 1;
     583    else
     584        return 0;
     585}
     586
     587
     588function build_query( $data ) {
     589    return _http_build_query( $data, NULL, '&', '', false );
     590}
     591
    584592
    585593/*
     
    595603function add_query_arg() {
    596604    $ret = '';
    597     if ( is_array(func_get_arg(0)) ) {
    598         if ( @func_num_args() < 2 || false === @func_get_arg(1) )
     605    if ( is_array( func_get_arg(0) ) ) {
     606        if ( @func_num_args() < 2 || false === @func_get_arg( 1 ) )
    599607            $uri = $_SERVER['REQUEST_URI'];
    600608        else
    601             $uri = @func_get_arg(1);
     609            $uri = @func_get_arg( 1 );
    602610    } else {
    603         if ( @func_num_args() < 3 || false === @func_get_arg(2) )
     611        if ( @func_num_args() < 3 || false === @func_get_arg( 2 ) )
    604612            $uri = $_SERVER['REQUEST_URI'];
    605613        else
    606             $uri = @func_get_arg(2);
    607     }
    608 
    609     if ( $frag = strstr($uri, '#') )
    610         $uri = substr($uri, 0, -strlen($frag));
     614            $uri = @func_get_arg( 2 );
     615    }
     616
     617    if ( $frag = strstr( $uri, '#' ) )
     618        $uri = substr( $uri, 0, -strlen( $frag ) );
    611619    else
    612620        $frag = '';
    613621
    614     if ( preg_match('|^https?://|i', $uri, $matches) ) {
     622    if ( preg_match( '|^https?://|i', $uri, $matches ) ) {
    615623        $protocol = $matches[0];
    616         $uri = substr($uri, strlen($protocol));
     624        $uri = substr( $uri, strlen( $protocol ) );
    617625    } else {
    618626        $protocol = '';
    619627    }
    620628
    621     if (strpos($uri, '?') !== false) {
    622         $parts = explode('?', $uri, 2);
    623         if ( 1 == count($parts) ) {
     629    if ( strpos( $uri, '?' ) !== false ) {
     630        $parts = explode( '?', $uri, 2 );
     631        if ( 1 == count( $parts ) ) {
    624632            $base = '?';
    625633            $query = $parts[0];
     
    628636            $query = $parts[1];
    629637        }
    630     } elseif (!empty($protocol) || strpos($uri, '=') === false ) {
     638    } elseif ( !empty( $protocol ) || strpos( $uri, '=' ) === false ) {
    631639        $base = $uri . '?';
    632640        $query = '';
     
    636644    }
    637645
    638     wp_parse_str($query, $qs);
    639     $qs = urlencode_deep($qs); // this re-URL-encodes things that were already in the query string
    640     if ( is_array(func_get_arg(0)) ) {
    641         $kayvees = func_get_arg(0);
    642         $qs = array_merge($qs, $kayvees);
     646    wp_parse_str( $query, $qs );
     647    $qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string
     648    if ( is_array( func_get_arg( 0 ) ) ) {
     649        $kayvees = func_get_arg( 0 );
     650        $qs = array_merge( $qs, $kayvees );
    643651    } else {
    644         $qs[func_get_arg(0)] = func_get_arg(1);
     652        $qs[func_get_arg( 0 )] = func_get_arg( 1 );
    645653    }
    646654
    647655    foreach ( $qs as $k => $v ) {
    648656        if ( $v === false )
    649             unset($qs[$k]);
    650     }
    651 
    652     $ret = build_query($qs);
    653     $ret = trim($ret, '?');
    654     $ret = preg_replace('#=(&|$)#', '$1', $ret);
     657            unset( $qs[$k] );
     658    }
     659
     660    $ret = build_query( $qs );
     661    $ret = trim( $ret, '?' );
     662    $ret = preg_replace( '#=(&|$)#', '$1', $ret );
    655663    $ret = $protocol . $base . $ret . $frag;
    656     $ret = rtrim($ret, '?');
     664    $ret = rtrim( $ret, '?' );
    657665    return $ret;
    658666}
     667
    659668
    660669/*
     
    668677*/
    669678
    670 function remove_query_arg($key, $query=FALSE) {
    671     if ( is_array($key) ) { // removing multiple keys
     679function remove_query_arg( $key, $query=FALSE ) {
     680    if ( is_array( $key ) ) { // removing multiple keys
    672681        foreach ( (array) $key as $k )
    673             $query = add_query_arg($k, FALSE, $query);
     682            $query = add_query_arg( $k, FALSE, $query );
    674683        return $query;
    675684    }
    676     return add_query_arg($key, FALSE, $query);
    677 }
    678 
    679 function add_magic_quotes($array) {
     685    return add_query_arg( $key, FALSE, $query );
     686}
     687
     688
     689function add_magic_quotes( $array ) {
    680690    global $wpdb;
    681691
    682     foreach ($array as $k => $v) {
    683         if ( is_array($v) ) {
    684             $array[$k] = add_magic_quotes($v);
     692    foreach ( $array as $k => $v ) {
     693        if ( is_array( $v ) ) {
     694            $array[$k] = add_magic_quotes( $v );
    685695        } else {
    686             $array[$k] = $wpdb->escape($v);
     696            $array[$k] = $wpdb->escape( $v );
    687697        }
    688698    }
     
    692702function wp_remote_fopen( $uri ) {
    693703    $timeout = 10;
    694     $parsed_url = @parse_url($uri);
    695 
    696     if ( !$parsed_url || !is_array($parsed_url) )
     704    $parsed_url = @parse_url( $uri );
     705
     706    if ( !$parsed_url || !is_array( $parsed_url ) )
    697707        return false;
    698708
    699     if ( !isset($parsed_url['scheme']) || !in_array($parsed_url['scheme'], array('http','https')) )
     709    if ( !isset( $parsed_url['scheme'] ) || !in_array( $parsed_url['scheme'], array( 'http','https' ) ) )
    700710        $uri = 'http://' . $uri;
    701711
    702     if ( ini_get('allow_url_fopen') ) {
     712    if ( ini_get( 'allow_url_fopen' ) ) {
    703713        $fp = @fopen( $uri, 'r' );
    704714        if ( !$fp )
     
    707717        //stream_set_timeout($fp, $timeout); // Requires php 4.3
    708718        $linea = '';
    709         while( $remote_read = fread($fp, 4096) )
     719        while ( $remote_read = fread( $fp, 4096 ) )
    710720            $linea .= $remote_read;
    711         fclose($fp);
     721        fclose( $fp );
    712722        return $linea;
    713     } else if ( function_exists('curl_init') ) {
     723    } elseif ( function_exists( 'curl_init' ) ) {
    714724        $handle = curl_init();
    715         curl_setopt ($handle, CURLOPT_URL, $uri);
    716         curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 1);
    717         curl_setopt ($handle, CURLOPT_RETURNTRANSFER, 1);
    718         curl_setopt ($handle, CURLOPT_TIMEOUT, $timeout);
    719         $buffer = curl_exec($handle);
    720         curl_close($handle);
     725        curl_setopt( $handle, CURLOPT_URL, $uri);
     726        curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, 1 );
     727        curl_setopt( $handle, CURLOPT_RETURNTRANSFER, 1 );
     728        curl_setopt( $handle, CURLOPT_TIMEOUT, $timeout );
     729        $buffer = curl_exec( $handle );
     730        curl_close( $handle );
    721731        return $buffer;
    722732    } else {
     
    725735}
    726736
    727 function wp($query_vars = '') {
     737
     738function wp( $query_vars = '' ) {
    728739    global $wp;
    729 
    730     $wp->main($query_vars);
    731 }
     740    $wp->main( $query_vars );
     741}
     742
    732743
    733744function get_status_header_desc( $code ) {
    734745    global $wp_header_to_desc;
    735746
    736     $code = (int) $code;
    737 
    738     if ( !isset($wp_header_to_desc) ) {
     747    $code = absint( $code );
     748
     749    if ( !isset( $wp_header_to_desc ) ) {
    739750        $wp_header_to_desc = array(
    740751            100 => 'Continue',
     
    784795    }
    785796
    786     if ( isset( $wp_header_to_desc[$code] ) ) {
     797    if ( isset( $wp_header_to_desc[$code] ) )
    787798        return $wp_header_to_desc[$code];
    788     } else {
     799    else
    789800        return '';
    790     }
    791 }
     801}
     802
    792803
    793804function status_header( $header ) {
     
    798809
    799810    $protocol = $_SERVER["SERVER_PROTOCOL"];
    800     if ( ('HTTP/1.1' != $protocol) && ('HTTP/1.0' != $protocol) )
     811    if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol )
    801812        $protocol = 'HTTP/1.0';
    802813    $status_header = "$protocol $header $text";
    803     if ( function_exists('apply_filters') )
    804         $status_header = apply_filters('status_header', $status_header, $header, $text, $protocol);
    805 
    806     if ( version_compare( phpversion(), '4.3.0', '>=' ) ) {
     814    if ( function_exists( 'apply_filters' ) )
     815        $status_header = apply_filters( 'status_header', $status_header, $header, $text, $protocol );
     816
     817    if ( version_compare( phpversion(), '4.3.0', '>=' ) )
    807818        return @header( $status_header, true, $header );
    808     } else {
     819    else
    809820        return @header( $status_header );
    810     }
    811 }
     821}
     822
    812823
    813824function nocache_headers() {
    814     @ header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
    815     @ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
    816     @ header('Cache-Control: no-cache, must-revalidate, max-age=0');
    817     @ header('Pragma: no-cache');
    818 }
     825    // why are these @-silenced when other header calls aren't?
     826    @header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
     827    @header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
     828    @header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
     829    @header( 'Pragma: no-cache' );
     830}
     831
    819832
    820833function cache_javascript_headers() {
    821834    $expiresOffset = 864000; // 10 days
    822     header("Content-Type: text/javascript; charset=" . get_bloginfo('charset'));
    823     header("Vary: Accept-Encoding"); // Handle proxies
    824     header("Expires: " . gmdate("D, d M Y H:i:s", time() + $expiresOffset) . " GMT");
    825 }
     835    header( "Content-Type: text/javascript; charset=" . get_bloginfo( 'charset' ) );
     836    header( "Vary: Accept-Encoding" ); // Handle proxies
     837    header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . " GMT" );
     838}
     839
    826840
    827841function get_num_queries() {
     
    830844}
    831845
     846
    832847function bool_from_yn( $yn ) {
    833848    return ( strtolower( $yn ) == 'y' );
    834849}
    835850
     851
    836852function do_feed() {
    837853    global $wp_query;
    838854
    839     $feed = get_query_var('feed');
     855    $feed = get_query_var( 'feed' );
    840856
    841857    // Remove the pad, if present.
    842     $feed = preg_replace('/^_+/', '', $feed);
     858    $feed = preg_replace( '/^_+/', '', $feed );
    843859
    844860    if ( $feed == '' || $feed == 'feed' )
     
    846862
    847863    $hook = 'do_feed_' . $feed;
    848     do_action($hook, $wp_query->is_comment_feed);
    849 }
     864    do_action( $hook, $wp_query->is_comment_feed );
     865}
     866
    850867
    851868function do_feed_rdf() {
    852     load_template(ABSPATH . WPINC . '/feed-rdf.php');
    853 }
     869    load_template( ABSPATH . WPINC . '/feed-rdf.php' );
     870}
     871
    854872
    855873function do_feed_rss() {
    856     load_template(ABSPATH . WPINC . '/feed-rss.php');
    857 }
    858 
    859 function do_feed_rss2($for_comments) {
    860     if ( $for_comments ) {
    861         load_template(ABSPATH . WPINC . '/feed-rss2-comments.php');
    862     } else {
    863         load_template(ABSPATH . WPINC . '/feed-rss2.php');
    864     }
    865 }
    866 
    867 function do_feed_atom($for_comments) {
    868     if ($for_comments) {
    869         load_template(ABSPATH . WPINC . '/feed-atom-comments.php');
    870     } else {
    871         load_template(ABSPATH . WPINC . '/feed-atom.php');
    872     }
     874    load_template( ABSPATH . WPINC . '/feed-rss.php' );
     875}
     876
     877
     878function do_feed_rss2( $for_comments ) {
     879    if ( $for_comments )
     880        load_template( ABSPATH . WPINC . '/feed-rss2-comments.php' );
     881    else
     882        load_template( ABSPATH . WPINC . '/feed-rss2.php' );
     883}
     884
     885
     886function do_feed_atom( $for_comments ) {
     887    if ($for_comments)
     888        load_template( ABSPATH . WPINC . '/feed-atom-comments.php');
     889    else
     890        load_template( ABSPATH . WPINC . '/feed-atom.php' );
    873891}
    874892
    875893function do_robots() {
    876     header('Content-Type: text/plain; charset=utf-8');
    877 
    878     do_action('do_robotstxt');
    879 
    880     if ( '0' == get_option('blog_public') ) {
     894    header( 'Content-Type: text/plain; charset=utf-8' );
     895
     896    do_action( 'do_robotstxt' );
     897
     898    if ( '0' == get_option( 'blog_public' ) ) {
    881899        echo "User-agent: *\n";
    882900        echo "Disallow: /\n";
     
    887905}
    888906
     907
    889908function is_blog_installed() {
    890909    global $wpdb;
    891910    $wpdb->hide_errors();
    892     $installed = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'");
     911    $installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" );
    893912    $wpdb->show_errors();
    894913
    895     $install_status = !empty( $installed ) ? TRUE : FALSE;
    896     return $install_status;
    897 }
    898 
    899 function wp_nonce_url($actionurl, $action = -1) {
    900     $actionurl = str_replace('&amp;', '&', $actionurl);
    901     return wp_specialchars(add_query_arg('_wpnonce', wp_create_nonce($action), $actionurl));
    902 }
    903 
    904 function wp_nonce_field($action = -1, $name = "_wpnonce", $referer = true) {
    905     $name = attribute_escape($name);
    906     echo '<input type="hidden" name="' . $name . '" value="' . wp_create_nonce($action) . '" />';
     914    return !empty( $installed );
     915}
     916
     917
     918function wp_nonce_url( $actionurl, $action = -1 ) {
     919    $actionurl = str_replace( '&amp;', '&', $actionurl );
     920    return wp_specialchars( add_query_arg( '_wpnonce', wp_create_nonce( $action ), $actionurl ) );
     921}
     922
     923
     924function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true ) {
     925    $name = attribute_escape( $name );
     926    echo '<input type="hidden" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />';
    907927    if ( $referer )
    908928        wp_referer_field();
    909929}
    910930
     931
    911932function wp_referer_field() {
    912     $ref = attribute_escape($_SERVER['REQUEST_URI']);
     933    $ref = attribute_escape( $_SERVER['REQUEST_URI'] );
    913934    echo '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />';
    914935    if ( wp_get_original_referer() ) {
    915         $original_ref = attribute_escape(stripslashes(wp_get_original_referer()));
     936        $original_ref = attribute_escape( stripslashes( wp_get_original_referer() ) );
    916937        echo '<input type="hidden" name="_wp_original_http_referer" value="'. $original_ref . '" />';
    917938    }
    918939}
    919940
     941
    920942function wp_original_referer_field() {
    921     echo '<input type="hidden" name="_wp_original_http_referer" value="' . attribute_escape(stripslashes($_SERVER['REQUEST_URI'])) . '" />';
    922 }
     943    echo '<input type="hidden" name="_wp_original_http_referer" value="' . attribute_escape( stripslashes( $_SERVER['REQUEST_URI'] ) ) . '" />';
     944}
     945
    923946
    924947function wp_get_referer() {
    925     foreach ( array($_REQUEST['_wp_http_referer'], $_SERVER['HTTP_REFERER']) as $ref )
    926         if ( !empty($ref) )
     948    foreach ( array( $_REQUEST['_wp_http_referer'], $_SERVER['HTTP_REFERER'] ) as $ref )
     949        if ( !empty( $ref ) )
    927950            return $ref;
    928951    return false;
    929952}
    930953
     954
    931955function wp_get_original_referer() {
    932     if ( !empty($_REQUEST['_wp_original_http_referer']) )
     956    if ( !empty( $_REQUEST['_wp_original_http_referer'] ) )
    933957        return $_REQUEST['_wp_original_http_referer'];
    934958    return false;
    935959}
    936960
    937 function wp_mkdir_p($target) {
     961
     962function wp_mkdir_p( $target ) {
    938963    // from php.net/mkdir user contributed notes
    939     if (file_exists($target)) {
    940         if (! @ is_dir($target))
     964    if ( file_exists( $target ) )
     965        return @is_dir( $target );
     966
     967    // Attempting to create the directory may clutter up our display.
     968    if ( @mkdir( $target ) ) {
     969        $stat = @stat( dirname( $target ) );
     970        $dir_perms = $stat['mode'] & 0007777;  // Get the permission bits.
     971        @chmod( $target, $dir_perms );
     972        return true;
     973    } elseif ( is_dir( dirname( $target ) ) ) {
    941974            return false;
    942         else
    943             return true;
    944     }
    945 
    946     // Attempting to create the directory may clutter up our display.
    947     if (@ mkdir($target)) {
    948         $stat = @ stat(dirname($target));
    949         $dir_perms = $stat['mode'] & 0007777;  // Get the permission bits.
    950         @ chmod($target, $dir_perms);
    951         return true;
    952     } else {
    953         if ( is_dir(dirname($target)) )
    954             return false;
    955975    }
    956976
    957977    // If the above failed, attempt to create the parent node, then try again.
    958     if (wp_mkdir_p(dirname($target)))
    959         return wp_mkdir_p($target);
     978    if ( wp_mkdir_p( dirname( $target ) ) )
     979        return wp_mkdir_p( $target );
    960980
    961981    return false;
    962982}
     983
    963984
    964985// Returns an array containing the current upload directory's path and url, or an error message.
    965986function wp_upload_dir() {
    966     $siteurl = get_option('siteurl');
     987    $siteurl = get_option( 'siteurl' );
    967988    //prepend ABSPATH to $dir and $siteurl to $url if they're not already there
    968     $path = str_replace(ABSPATH, '', trim(get_option('upload_path')));
     989    $path = str_replace( ABSPATH, '', trim( get_option( 'upload_path' ) ) );
    969990    $dir = ABSPATH . $path;
    970     $url = trailingslashit($siteurl) . $path;
    971 
    972     if ( $dir == ABSPATH ) { //the option was empty
     991    $url = trailingslashit( $siteurl ) . $path;
     992
     993    if ( $dir == ABSPATH ) // the option was empty
    973994        $dir = ABSPATH . 'wp-content/uploads';
    974     }
    975995
    976996    if ( defined('UPLOADS') ) {
    977997        $dir = ABSPATH . UPLOADS;
    978         $url = trailingslashit($siteurl) . UPLOADS;
    979     }
    980 
    981     if ( get_option('uploads_use_yearmonth_folders')) {
     998        $url = trailingslashit( $siteurl ) . UPLOADS;
     999    }
     1000
     1001    if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
    9821002        // Generate the yearly and monthly dirs
    9831003        $time = current_time( 'mysql' );
     
    9901010    // Make sure we have an uploads dir
    9911011    if ( ! wp_mkdir_p( $dir ) ) {
    992         $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), $dir);
    993         return array('error' => $message);
    994     }
    995 
    996         $uploads = array('path' => $dir, 'url' => $url, 'error' => false);
    997     return apply_filters('upload_dir', $uploads);
    998 }
    999 
    1000 function wp_upload_bits($name, $type, $bits) {
    1001     if ( empty($name) )
    1002         return array('error' => __("Empty filename"));
    1003 
    1004     $wp_filetype = wp_check_filetype($name);
     1012        $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $dir );
     1013        return array( 'error' => $message );
     1014    }
     1015
     1016        $uploads = array( 'path' => $dir, 'url' => $url, 'error' => false );
     1017    return apply_filters( 'upload_dir', $uploads );
     1018}
     1019
     1020function wp_upload_bits( $name, $type, $bits ) {
     1021    if ( empty( $name ) )
     1022        return array( 'error' => __( "Empty filename" ) );
     1023
     1024    $wp_filetype = wp_check_filetype( $name );
    10051025    if ( !$wp_filetype['ext'] )
    1006         return array('error' => __("Invalid file type"));
     1026        return array( 'error' => __( "Invalid file type" ) );
    10071027
    10081028    $upload = wp_upload_dir();
     
    10131033    $number = '';
    10141034    $filename = $name;
    1015     $path_parts = pathinfo($filename);
     1035    $path_parts = pathinfo( $filename );
    10161036    $ext = $path_parts['extension'];
    1017     if ( empty($ext) )
     1037    if ( empty( $ext ) )
    10181038        $ext = '';
    10191039    else
    10201040        $ext = ".$ext";
    1021     while ( file_exists($upload['path'] . "/$filename") ) {
     1041    while ( file_exists( $upload['path'] . "/$filename" ) ) {
    10221042        if ( '' == "$number$ext" )
    10231043            $filename = $filename . ++$number . $ext;
    10241044        else
    1025             $filename = str_replace("$number$ext", ++$number . $ext, $filename);
     1045            $filename = str_replace( "$number$ext", ++$number . $ext, $filename );
    10261046    }
    10271047
    10281048    $new_file = $upload['path'] . "/$filename";
    1029     if ( ! wp_mkdir_p( dirname($new_file) ) ) {
    1030         $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), dirname($new_file));
    1031         return array('error' => $message);
    1032     }
    1033 
    1034     $ifp = @ fopen($new_file, 'wb');
     1049    if ( ! wp_mkdir_p( dirname( $new_file ) ) ) {
     1050        $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), dirname( $new_file ) );
     1051        return array( 'error' => $message );
     1052    }
     1053
     1054    $ifp = @ fopen( $new_file, 'wb' );
    10351055    if ( ! $ifp )
    1036         return array('error' => sprintf(__('Could not write file %s'), $new_file));
    1037 
    1038     $success = @ fwrite($ifp, $bits);
    1039     fclose($ifp);
     1056        return array( 'error' => sprintf( __( 'Could not write file %s' ), $new_file ) );
     1057
     1058    $success = @fwrite( $ifp, $bits );
     1059    fclose( $ifp );
    10401060    // Set correct file permissions
    1041     $stat = @ stat(dirname($new_file));
     1061    $stat = @ stat( dirname( $new_file ) );
    10421062    $perms = $stat['mode'] & 0007777;
    10431063    $perms = $perms & 0000666;
    1044     @ chmod($new_file, $perms);
     1064    @ chmod( $new_file, $perms );
    10451065
    10461066    // Compute the URL
    10471067    $url = $upload['url'] . "/$filename";
    10481068
    1049     return array('file' => $new_file, 'url' => $url, 'error' => false);
    1050 }
    1051 
    1052 function wp_check_filetype($filename, $mimes = null) {
     1069    return array( 'file' => $new_file, 'url' => $url, 'error' => false );
     1070}
     1071
     1072
     1073function wp_check_filetype( $filename, $mimes = null ) {
    10531074    // Accepted MIME types are set here as PCRE unless provided.
    1054     $mimes = is_array($mimes) ? $mimes : apply_filters('upload_mimes', array (
     1075    $mimes = ( is_array( $mimes ) ) ? $mimes : apply_filters( 'upload_mimes', array(
    10551076        'jpg|jpeg|jpe' => 'image/jpeg',
    10561077        'gif' => 'image/gif',
     
    10961117        'odb' => 'application/vnd.oasis.opendocument.database',
    10971118        'odf' => 'application/vnd.oasis.opendocument.formula',
    1098 
    1099     ));
     1119        )
     1120    );
    11001121
    11011122    $type = false;
    11021123    $ext = false;
    11031124
    1104     foreach ($mimes as $ext_preg => $mime_match) {
     1125    foreach ( $mimes as $ext_preg => $mime_match ) {
    11051126        $ext_preg = '!\.(' . $ext_preg . ')$!i';
    1106         if ( preg_match($ext_preg, $filename, $ext_matches) ) {
     1127        if ( preg_match( $ext_preg, $filename, $ext_matches ) ) {
    11071128            $type = $mime_match;
    11081129            $ext = $ext_matches[1];
     
    11111132    }
    11121133
    1113     return compact('ext', 'type');
    1114 }
    1115 
    1116 function wp_explain_nonce($action) {
    1117     if ( $action !== -1 && preg_match('/([a-z]+)-([a-z]+)(_(.+))?/', $action, $matches) ) {
     1134    return compact( 'ext', 'type' );
     1135}
     1136
     1137function wp_explain_nonce( $action ) {
     1138    if ( $action !== -1 && preg_match( '/([a-z]+)-([a-z]+)(_(.+))?/', $action, $matches ) ) {
    11181139        $verb = $matches[1];
    11191140        $noun = $matches[2];
    11201141
    11211142        $trans = array();
    1122         $trans['update']['attachment'] = array(__('Are you sure you want to edit this attachment: &quot;%s&quot;?'), 'get_the_title');
    1123 
    1124         $trans['add']['category'] = array(__('Are you sure you want to add this category?'), false);
    1125         $trans['delete']['category'] = array(__('Are you sure you want to delete this category: &quot;%s&quot;?'), 'get_catname');
    1126         $trans['update']['category'] = array(__('Are you sure you want to edit this category: &quot;%s&quot;?'), 'get_catname');
    1127 
    1128         $trans['delete']['comment'] = array(__('Are you sure you want to delete this comment: &quot;%s&quot;?'), 'use_id');
    1129         $trans['unapprove']['comment'] = array(__('Are you sure you want to unapprove this comment: &quot;%s&quot;?'), 'use_id');
    1130         $trans['approve']['comment'] = array(__('Are you sure you want to approve this comment: &quot;%s&quot;?'), 'use_id');
    1131         $trans['update']['comment'] = array(__('Are you sure you want to edit this comment: &quot;%s&quot;?'), 'use_id');
    1132         $trans['bulk']['comments'] = array(__('Are you sure you want to bulk modify comments?'), false);
    1133         $trans['moderate']['comments'] = array(__('Are you sure you want to moderate comments?'), false);
    1134 
    1135         $trans['add']['bookmark'] = array(__('Are you sure you want to add this link?'), false);
    1136         $trans['delete']['bookmark'] = array(__('Are you sure you want to delete this link: &quot;%s&quot;?'), 'use_id');
    1137         $trans['update']['bookmark'] = array(__('Are you sure you want to edit this link: &quot;%s&quot;?'), 'use_id');
    1138         $trans['bulk']['bookmarks'] = array(__('Are you sure you want to bulk modify links?'), false);
    1139 
    1140         $trans['add']['page'] = array(__('Are you sure you want to add this page?'), false);
    1141         $trans['delete']['page'] = array(__('Are you sure you want to delete this page: &quot;%s&quot;?'), 'get_the_title');
    1142         $trans['update']['page'] = array(__('Are you sure you want to edit this page: &quot;%s&quot;?'), 'get_the_title');
    1143 
    1144         $trans['edit']['plugin'] = array(__('Are you sure you want to edit this plugin file: &quot;%s&quot;?'), 'use_id');
    1145         $trans['activate']['plugin'] = array(__('Are you sure you want to activate this plugin: &quot;%s&quot;?'), 'use_id');
    1146         $trans['deactivate']['plugin'] = array(__('Are you sure you want to deactivate this plugin: &quot;%s&quot;?'), 'use_id');
    1147 
    1148         $trans['add']['post'] = array(__('Are you sure you want to add this post?'), false);
    1149         $trans['delete']['post'] = array(__('Are you sure you want to delete this post: &quot;%s&quot;?'), 'get_the_title');
    1150         $trans['update']['post'] = array(__('Are you sure you want to edit this post: &quot;%s&quot;?'), 'get_the_title');
    1151 
    1152         $trans['add']['user'] = array(__('Are you sure you want to add this user?'), false);
    1153         $trans['delete']['users'] = array(__('Are you sure you want to delete users?'), false);
    1154         $trans['bulk']['users'] = array(__('Are you sure you want to bulk modify users?'), false);
    1155         $trans['update']['user'] = array(__('Are you sure you want to edit this user: &quot;%s&quot;?'), 'get_author_name');
    1156         $trans['update']['profile'] = array(__('Are you sure you want to modify the profile for: &quot;%s&quot;?'), 'get_author_name');
    1157 
    1158         $trans['update']['options'] = array(__('Are you sure you want to edit your settings?'), false);
    1159         $trans['update']['permalink'] = array(__('Are you sure you want to change your permalink structure to: %s?'), 'use_id');
    1160         $trans['edit']['file'] = array(__('Are you sure you want to edit this file: &quot;%s&quot;?'), 'use_id');
    1161         $trans['edit']['theme'] = array(__('Are you sure you want to edit this theme file: &quot;%s&quot;?'), 'use_id');
    1162         $trans['switch']['theme'] = array(__('Are you sure you want to switch to this theme: &quot;%s&quot;?'), 'use_id');
    1163 
    1164         if ( isset($trans[$verb][$noun]) ) {
    1165             if ( !empty($trans[$verb][$noun][1]) ) {
     1143        $trans['update']['attachment'] = array( __( 'Are you sure you want to edit this attachment: &quot;%s&quot;?' ), 'get_the_title' );
     1144
     1145        $trans['add']['category']      = array( __( 'Are you sure you want to add this category?' ), false );
     1146        $trans['delete']['category']   = array( __( 'Are you sure you want to delete this category: &quot;%s&quot;?' ), 'get_catname' );
     1147        $trans['update']['category']   = array( __( 'Are you sure you want to edit this category: &quot;%s&quot;?' ), 'get_catname' );
     1148
     1149        $trans['delete']['comment']    = array( __( 'Are you sure you want to delete this comment: &quot;%s&quot;?' ), 'use_id' );
     1150        $trans['unapprove']['comment'] = array( __( 'Are you sure you want to unapprove this comment: &quot;%s&quot;?' ), 'use_id' );
     1151        $trans['approve']['comment']   = array( __( 'Are you sure you want to approve this comment: &quot;%s&quot;?' ), 'use_id' );
     1152        $trans['update']['comment']    = array( __( 'Are you sure you want to edit this comment: &quot;%s&quot;?' ), 'use_id' );
     1153        $trans['bulk']['comments']     = array( __( 'Are you sure you want to bulk modify comments?' ), false );
     1154        $trans['moderate']['comments'] = array( __( 'Are you sure you want to moderate comments?' ), false );
     1155
     1156        $trans['add']['bookmark']      = array( __( 'Are you sure you want to add this link?' ), false );
     1157        $trans['delete']['bookmark']   = array( __( 'Are you sure you want to delete this link: &quot;%s&quot;?' ), 'use_id' );
     1158        $trans['update']['bookmark']   = array( __( 'Are you sure you want to edit this link: &quot;%s&quot;?' ), 'use_id' );
     1159        $trans['bulk']['bookmarks']    = array( __( 'Are you sure you want to bulk modify links?' ), false );
     1160
     1161        $trans['add']['page']          = array( __( 'Are you sure you want to add this page?' ), false );
     1162        $trans['delete']['page']       = array( __( 'Are you sure you want to delete this page: &quot;%s&quot;?' ), 'get_the_title' );
     1163        $trans['update']['page']       = array( __( 'Are you sure you want to edit this page: &quot;%s&quot;?' ), 'get_the_title' );
     1164
     1165        $trans['edit']['plugin']       = array( __( 'Are you sure you want to edit this plugin file: &quot;%s&quot;?' ), 'use_id' );
     1166        $trans['activate']['plugin']   = array( __( 'Are you sure you want to activate this plugin: &quot;%s&quot;?' ), 'use_id' );
     1167        $trans['deactivate']['plugin'] = array( __( 'Are you sure you want to deactivate this plugin: &quot;%s&quot;?' ), 'use_id' );
     1168
     1169        $trans['add']['post']          = array( __( 'Are you sure you want to add this post?' ), false );
     1170        $trans['delete']['post']       = array( __( 'Are you sure you want to delete this post: &quot;%s&quot;?' ), 'get_the_title' );
     1171        $trans['update']['post']       = array( __( 'Are you sure you want to edit this post: &quot;%s&quot;?' ), 'get_the_title' );
     1172
     1173        $trans['add']['user']          = array( __( 'Are you sure you want to add this user?' ), false );
     1174        $trans['delete']['users']      = array( __( 'Are you sure you want to delete users?' ), false );
     1175        $trans['bulk']['users']        = array( __( 'Are you sure you want to bulk modify users?' ), false );
     1176        $trans['update']['user']       = array( __( 'Are you sure you want to edit this user: &quot;%s&quot;?' ), 'get_author_name' );
     1177        $trans['update']['profile']    = array( __( 'Are you sure you want to modify the profile for: &quot;%s&quot;?' ), 'get_author_name' );
     1178
     1179        $trans['update']['options']    = array( __( 'Are you sure you want to edit your settings?' ), false );
     1180        $trans['update']['permalink']  = array( __( 'Are you sure you want to change your permalink structure to: %s?' ), 'use_id' );
     1181        $trans['edit']['file']         = array( __( 'Are you sure you want to edit this file: &quot;%s&quot;?' ), 'use_id' );
     1182        $trans['edit']['theme']        = array( __( 'Are you sure you want to edit this theme file: &quot;%s&quot;?' ), 'use_id' );
     1183        $trans['switch']['theme']      = array( __( 'Are you sure you want to switch to this theme: &quot;%s&quot;?' ), 'use_id' );
     1184
     1185        if ( isset( $trans[$verb][$noun] ) ) {
     1186            if ( !empty( $trans[$verb][$noun][1] ) ) {
    11661187                $lookup = $trans[$verb][$noun][1];
    11671188                $object = $matches[4];
    11681189                if ( 'use_id' != $lookup )
    1169                     $object = call_user_func($lookup, $object);
    1170                 return sprintf($trans[$verb][$noun][0], $object);
     1190                    $object = call_user_func( $lookup, $object );
     1191                return sprintf( $trans[$verb][$noun][0], $object );
    11711192            } else {
    11721193                return $trans[$verb][$noun][0];
     
    11751196    }
    11761197
    1177     return apply_filters( 'explain_nonce_' . $verb . '-' . $noun, __('Are you sure you want to do this?'), $matches[4] );
    1178 }
    1179 
    1180 function wp_nonce_ays($action) {
     1198    return apply_filters( 'explain_nonce_' . $verb . '-' . $noun, __( 'Are you sure you want to do this?' ), $matches[4] );
     1199}
     1200
     1201
     1202function wp_nonce_ays( $action ) {
    11811203    global $pagenow, $menu, $submenu, $parent_file, $submenu_file;
    11821204
    1183     $adminurl = get_option('siteurl') . '/wp-admin';
     1205    $adminurl = get_option( 'siteurl' ) . '/wp-admin';
    11841206    if ( wp_get_referer() )
    1185         $adminurl = clean_url(wp_get_referer());
    1186 
    1187     $title = __('WordPress Confirmation');
     1207        $adminurl = clean_url( wp_get_referer() );
     1208
     1209    $title = __( 'WordPress Confirmation' );
    11881210    // Remove extra layer of slashes.
    1189     $_POST   = stripslashes_deep($_POST );
     1211    $_POST   = stripslashes_deep( $_POST );
    11901212    if ( $_POST ) {
    1191         $q = http_build_query($_POST);
    1192         $q = explode( ini_get('arg_separator.output'), $q);
    1193         $html .= "\t<form method='post' action='" . attribute_escape($pagenow) . "'>\n";
     1213        $q = http_build_query( $_POST );
     1214        $q = explode( ini_get( 'arg_separator.output' ), $q);
     1215        $html .= "\t<form method='post' action='" . attribute_escape( $pagenow ) . "'>\n";
    11941216        foreach ( (array) $q as $a ) {
    1195             $v = substr(strstr($a, '='), 1);
    1196             $k = substr($a, 0, -(strlen($v)+1));
    1197             $html .= "\t\t<input type='hidden' name='" . attribute_escape(urldecode($k)) . "' value='" . attribute_escape(urldecode($v)) . "' />\n";
     1217            $v = substr( strstr( $a, '=' ), 1 );
     1218            $k = substr( $a, 0, -( strlen( $v ) + 1 ) );
     1219            $html .= "\t\t<input type='hidden' name='" . attribute_escape( urldecode( $k ) ) . "' value='" . attribute_escape( urldecode( $v ) ) . "' />\n";
    11981220        }
    1199         $html .= "\t\t<input type='hidden' name='_wpnonce' value='" . wp_create_nonce($action) . "' />\n";
    1200         $html .= "\t\t<div id='message' class='confirm fade'>\n\t\t<p>" . wp_specialchars(wp_explain_nonce($action)) . "</p>\n\t\t<p><a href='$adminurl'>" . __('No') . "</a> <input type='submit' value='" . __('Yes') . "' /></p>\n\t\t</div>\n\t</form>\n";
     1221        $html .= "\t\t<input type='hidden' name='_wpnonce' value='" . wp_create_nonce( $action ) . "' />\n";
     1222        $html .= "\t\t<div id='message' class='confirm fade'>\n\t\t<p>" . wp_specialchars( wp_explain_nonce( $action ) ) . "</p>\n\t\t<p><a href='$adminurl'>" . __( 'No' ) . "</a> <input type='submit' value='" . __( 'Yes' ) . "' /></p>\n\t\t</div>\n\t</form>\n";
    12011223    } else {
    1202         $html .= "\t<div id='message' class='confirm fade'>\n\t<p>" . wp_specialchars(wp_explain_nonce($action)) . "</p>\n\t<p><a href='$adminurl'>" . __('No') . "</a> <a href='" . clean_url(add_query_arg( '_wpnonce', wp_create_nonce($action), $_SERVER['REQUEST_URI'] )) . "'>" . __('Yes') . "</a></p>\n\t</div>\n";
     1224        $html .= "\t<div id='message' class='confirm fade'>\n\t<p>" . wp_specialchars( wp_explain_nonce( $action ) ) . "</p>\n\t<p><a href='$adminurl'>" . __( 'No' ) . "</a> <a href='" . clean_url( add_query_arg( '_wpnonce', wp_create_nonce( $action ), $_SERVER['REQUEST_URI'] ) ) . "'>" . __( 'Yes' ) . "</a></p>\n\t</div>\n";
    12031225    }
    12041226    $html .= "</body>\n</html>";
    1205     wp_die($html, $title);
    1206 }
     1227    wp_die( $html, $title );
     1228}
     1229
    12071230
    12081231function wp_die( $message, $title = '' ) {
     
    12101233
    12111234    if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) {
    1212         if ( empty($title) ) {
     1235        if ( empty( $title ) ) {
    12131236            $error_data = $message->get_error_data();
    1214             if ( is_array($error_data) && isset($error_data['title']) )
     1237            if ( is_array( $error_data ) && isset( $error_data['title'] ) )
    12151238                $title = $error_data['title'];
    12161239        }
    12171240        $errors = $message->get_error_messages();
    1218         switch ( count($errors) ) :
     1241        switch ( count( $errors ) ) :
    12191242        case 0 :
    12201243            $message = '';
     
    12271250            break;
    12281251        endswitch;
    1229     } elseif ( is_string($message) ) {
     1252    } elseif ( is_string( $message ) ) {
    12301253        $message = "<p>$message</p>";
    12311254    }
    12321255
    1233     if ( defined('WP_SITEURL') && '' != WP_SITEURL )
    1234         $admin_dir = WP_SITEURL.'/wp-admin/';
    1235     elseif (function_exists('get_bloginfo') && '' != get_bloginfo('wpurl'))
    1236         $admin_dir = get_bloginfo('wpurl').'/wp-admin/';
    1237     elseif (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false)
     1256    if ( defined( 'WP_SITEURL' ) && '' != WP_SITEURL )
     1257        $admin_dir = WP_SITEURL . '/wp-admin/';
     1258    elseif ( function_exists( 'get_bloginfo' ) && '' != get_bloginfo( 'wpurl' ) )
     1259        $admin_dir = get_bloginfo( 'wpurl' ) . '/wp-admin/';
     1260    elseif ( strpos( $_SERVER['PHP_SELF'], 'wp-admin' ) !== false )
    12381261        $admin_dir = '';
    12391262    else
    12401263        $admin_dir = 'wp-admin/';
    12411264
    1242     if ( !function_exists('did_action') || !did_action('admin_head') ) :
     1265    if ( !function_exists( 'did_action' ) || !did_action( 'admin_head' ) ) :
    12431266    if( !headers_sent() ){
    1244         status_header(500);
     1267        status_header( 500 );
    12451268        nocache_headers();
    1246         header('Content-Type: text/html; charset=utf-8');
    1247     }
    1248 
    1249     if ( empty($title) ){
    1250         if( function_exists('__') )
    1251             $title = __('WordPress &rsaquo; Error');
     1269        header( 'Content-Type: text/html; charset=utf-8' );
     1270    }
     1271
     1272    if ( empty($title) ) {
     1273        if ( function_exists( '__' ) )
     1274            $title = __( 'WordPress &rsaquo; Error' );
    12521275        else
    12531276            $title = 'WordPress &rsaquo; Error';
     
    12561279?>
    12571280<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    1258 <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists('language_attributes') ) language_attributes(); ?>>
     1281<html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) ) language_attributes(); ?>>
    12591282<head>
    12601283    <title><?php echo $title ?></title>
     
    12621285    <link rel="stylesheet" href="<?php echo $admin_dir; ?>css/install.css" type="text/css" />
    12631286<?php
    1264 if ( ( $wp_locale ) && ('rtl' == $wp_locale->text_direction) ) : ?>
     1287if ( ( $wp_locale ) && ( 'rtl' == $wp_locale->text_direction ) ) : ?>
    12651288    <link rel="stylesheet" href="<?php echo $admin_dir; ?>css/install-rtl.css" type="text/css" />
    12661289<?php endif; ?>
     
    12771300}
    12781301
    1279 function _config_wp_home($url = '') {
     1302
     1303function _config_wp_home( $url = '' ) {
    12801304    if ( defined( 'WP_HOME' ) )
    12811305        return WP_HOME;
    1282     else return $url;
    1283 }
    1284 
    1285 function _config_wp_siteurl($url = '') {
     1306    return $url;
     1307}
     1308
     1309
     1310function _config_wp_siteurl( $url = '' ) {
    12861311    if ( defined( 'WP_SITEURL' ) )
    12871312        return WP_SITEURL;
    1288     else return $url;
    1289 }
     1313    return $url;
     1314}
     1315
    12901316
    12911317function _mce_set_direction() {
    12921318    global $wp_locale;
    12931319
    1294     if ('rtl' == $wp_locale->text_direction) {
     1320    if ( 'rtl' == $wp_locale->text_direction ) {
    12951321        echo 'directionality : "rtl" ,';
    12961322        echo 'theme_advanced_toolbar_align : "right" ,';
     
    12981324}
    12991325
    1300 function _mce_load_rtl_plugin($input) {
     1326
     1327function _mce_load_rtl_plugin( $input ) {
    13011328    global $wp_locale;
    13021329
    1303     if ('rtl' == $wp_locale->text_direction)
     1330    if ( 'rtl' == $wp_locale->text_direction )
    13041331        $input[] = 'directionality';
    13051332
     
    13071334}
    13081335
    1309 function _mce_add_direction_buttons($input) {
     1336
     1337function _mce_add_direction_buttons( $input ) {
    13101338    global $wp_locale;
    13111339
    1312     if ('rtl' == $wp_locale->text_direction) {
    1313         $new_buttons = array('separator', 'ltr', 'rtl');
    1314         $input = array_merge($input, $new_buttons);
     1340    if ( 'rtl' == $wp_locale->text_direction ) {
     1341        $new_buttons = array( 'separator', 'ltr', 'rtl' );
     1342        $input = array_merge( $input, $new_buttons );
    13151343    }
    13161344
    13171345    return $input;
    13181346}
     1347
    13191348
    13201349function smilies_init() {
     
    13221351
    13231352    // don't bother setting up smilies if they are disabled
    1324     if ( !get_option('use_smilies') )
     1353    if ( !get_option( 'use_smilies' ) )
    13251354        return;
    13261355
    1327     if (!isset($wpsmiliestrans)) {
     1356    if ( !isset( $wpsmiliestrans ) ) {
    13281357        $wpsmiliestrans = array(
    13291358        ':mrgreen:' => 'icon_mrgreen.gif',
     
    13741403    }
    13751404
    1376     $siteurl = get_option('siteurl');
     1405    $siteurl = get_option( 'siteurl' );
    13771406    foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
    1378         $wp_smiliessearch[] = '/(\s|^)'.preg_quote($smiley, '/').'(\s|$)/';
    1379         $smiley_masked = htmlspecialchars(trim($smiley), ENT_QUOTES);
     1407        $wp_smiliessearch[] = '/(\s|^)' . preg_quote( $smiley, '/' ) . '(\s|$)/';
     1408        $smiley_masked = attribute_escape( trim( $smiley ) );
    13801409        $wp_smiliesreplace[] = " <img src='$siteurl/wp-includes/images/smilies/$img' alt='$smiley_masked' class='wp-smiley' /> ";
    13811410    }
    13821411}
    13831412
     1413
    13841414function wp_parse_args( $args, $defaults = '' ) {
    1385     if ( is_object($args) )
    1386         $r = get_object_vars($args);
    1387     else if ( is_array( $args ) )
     1415    if ( is_object( $args ) )
     1416        $r = get_object_vars( $args );
     1417    elseif ( is_array( $args ) )
    13881418        $r =& $args;
    13891419    else
     
    13921422    if ( is_array( $defaults ) )
    13931423        return array_merge( $defaults, $r );
    1394     else
    1395         return $r;
    1396 }
     1424    return $r;
     1425}
     1426
    13971427
    13981428function wp_maybe_load_widgets() {
    13991429    if ( !function_exists( 'dynamic_sidebar' ) ) {
    1400         require_once ABSPATH . WPINC . '/widgets.php';
     1430        require_once( ABSPATH . WPINC . '/widgets.php' );
    14011431        add_action( '_admin_menu', 'wp_widgets_add_menu' );
    14021432    }
    14031433}
     1434
    14041435
    14051436function wp_widgets_add_menu() {
    14061437    global $submenu;
    14071438    $submenu['themes.php'][7] = array( __( 'Widgets' ), 'switch_themes', 'widgets.php' );
    1408     ksort($submenu['themes.php'], SORT_NUMERIC);
    1409 }
     1439    ksort( $submenu['themes.php'], SORT_NUMERIC );
     1440}
     1441
    14101442
    14111443// For PHP 5.2, make sure all output buffers are flushed
    14121444// before our singletons our destroyed.
    1413 function wp_ob_end_flush_all()
    1414 {
     1445function wp_ob_end_flush_all() {
    14151446    while ( @ob_end_flush() );
    14161447}
     1448
    14171449
    14181450/*
     
    14241456 * @global $wpdb
    14251457 */
    1426 function require_wp_db()
    1427 {
     1458function require_wp_db() {
    14281459    global $wpdb;
    1429     if ( file_exists(ABSPATH . 'wp-content/db.php') )
    1430         require_once (ABSPATH . 'wp-content/db.php');
     1460    if ( file_exists( ABSPATH . 'wp-content/db.php' ) )
     1461        require_once( ABSPATH . 'wp-content/db.php' );
    14311462    else
    1432         require_once (ABSPATH . WPINC . '/wp-db.php');
    1433 }
     1463        require_once( ABSPATH . WPINC . '/wp-db.php' );
     1464}
     1465
    14341466
    14351467/**
     
    14381470 * @return int an absolute integer
    14391471 */
    1440 function absint($maybeint) {
    1441     return abs(intval($maybeint));
     1472function absint( $maybeint ) {
     1473    return abs( intval( $maybeint ) );
    14421474}
    14431475
Note: See TracChangeset for help on using the changeset viewer.