Changeset 6223
- Timestamp:
- 10/11/2007 05:46:57 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/wp-includes/functions.php (modified) (46 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r6222 r6223 1 1 <?php 2 2 3 function mysql2date( $dateformatstring, $mysqlstring, $translate = true) {3 function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) { 4 4 global $wp_locale; 5 5 $m = $mysqlstring; 6 if ( empty( $m) ) {6 if ( empty( $m ) ) 7 7 return false; 8 }9 8 $i = mktime( 10 9 (int) substr( $m, 11, 2 ), (int) substr( $m, 14, 2 ), (int) substr( $m, 17, 2 ), … … 18 17 $i = 0; 19 18 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 42 43 return $j; 43 44 } 44 45 45 function current_time($type, $gmt = 0) { 46 switch ($type) { 46 47 function current_time( $type, $gmt = 0 ) { 48 switch ( $type ) { 47 49 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 ) ) ); 51 51 break; 52 52 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 ); 56 54 break; 57 55 } 58 56 } 59 57 60 function date_i18n($dateformatstring, $unixtimestamp) { 58 59 function date_i18n( $dateformatstring, $unixtimestamp ) { 61 60 global $wp_locale; 62 61 $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 ) ); 70 69 $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 ); 81 80 return $j; 82 81 } 83 82 84 function number_format_i18n($number, $decimals = null) { 83 84 function number_format_i18n( $number, $decimals = null ) { 85 85 global $wp_locale; 86 86 // 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 93 function size_format( $bytes, $decimals = null ) { 93 94 // technically the correct unit names for powers of 1024 are KiB, MiB etc 94 95 // see http://en.wikipedia.org/wiki/Byte 95 96 $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) 101 103 ); 102 104 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 111 function 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 ); 114 117 $i = 86400; 115 118 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 ); 123 126 124 127 $day = $day - 86400; … … 126 129 } 127 130 $week['start'] = $day + 86400 - $i; 128 // $week['end'] = $day - $i + 691199;129 131 $week['end'] = $week['start'] + 604799; 130 132 return $week; 131 133 } 132 134 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 136 function 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 ) ) 136 139 return $gm; 137 140 return $original; 138 141 } 139 142 140 function is_serialized($data) { 143 144 function is_serialized( $data ) { 141 145 // if it isn't a string, it isn't serialized 142 if ( !is_string( $data) )146 if ( !is_string( $data ) ) 143 147 return false; 144 $data = trim( $data);148 $data = trim( $data ); 145 149 if ( 'N;' == $data ) 146 150 return true; 147 if ( !preg_match( '/^([adObis]):/', $data, $badions) )151 if ( !preg_match( '/^([adObis]):/', $data, $badions ) ) 148 152 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 } 163 167 return false; 164 168 } 165 169 166 function is_serialized_string($data) { 170 171 function is_serialized_string( $data ) { 167 172 // if it isn't a string, it isn't a serialized string 168 if ( !is_string( $data) )173 if ( !is_string( $data ) ) 169 174 return false; 170 $data = trim( $data);171 if ( preg_match( '/^s:[0-9]+:.*;$/s',$data) ) // this should fetch all serialized strings175 $data = trim( $data ); 176 if ( preg_match( '/^s:[0-9]+:.*;$/s', $data ) ) // this should fetch all serialized strings 172 177 return true; 173 178 return false; 174 179 } 175 180 181 176 182 /* Options functions */ 177 183 178 184 // expects $setting to already be SQL-escaped 179 function get_option( $setting) {185 function get_option( $setting ) { 180 186 global $wpdb; 181 187 … … 186 192 187 193 // 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] ) ) 190 196 return false; 191 197 192 198 $alloptions = wp_load_alloptions(); 193 199 194 if ( isset( $alloptions[$setting]) ) {200 if ( isset( $alloptions[$setting] ) ) { 195 201 $value = $alloptions[$setting]; 196 202 } else { 197 $value = wp_cache_get( $setting, 'options');203 $value = wp_cache_get( $setting, 'options' ); 198 204 199 205 if ( false === $value ) { 200 if ( defined( 'WP_INSTALLING') )206 if ( defined( 'WP_INSTALLING' ) ) 201 207 $wpdb->hide_errors(); 202 208 // 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' ) ) 205 211 $wpdb->show_errors(); 206 212 207 if ( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values213 if ( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values 208 214 $value = $row->option_value; 209 wp_cache_add( $setting, $value, 'options');215 wp_cache_add( $setting, $value, 'options' ); 210 216 } else { // option does not exist, so we must cache its non-existence 211 217 $notoptions[$setting] = true; 212 wp_cache_set( 'notoptions', $notoptions, 'options');218 wp_cache_set( 'notoptions', $notoptions, 'options' ); 213 219 return false; 214 220 } … … 218 224 // If home is not set use siteurl. 219 225 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 235 function 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 241 function form_option( $option ) { 242 echo attribute_escape (get_option( $option ) ); 236 243 } 237 244 … … 239 246 global $wpdb, $wp_queries; 240 247 $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" ); 244 250 $wpdb->show_errors(); 245 251 246 foreach ( $options as $option) {252 foreach ( $options as $option ) { 247 253 // "When trying to design a foolproof system, 248 254 // 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 260 263 261 264 function wp_load_alloptions() { 262 265 global $wpdb; 263 266 264 $alloptions = wp_cache_get( 'alloptions', 'options');267 $alloptions = wp_cache_get( 'alloptions', 'options' ); 265 268 266 269 if ( !$alloptions ) { 267 270 $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" ); 270 273 $wpdb->show_errors(); 271 274 $alloptions = array(); 272 275 foreach ( (array) $alloptions_db as $o ) 273 276 $alloptions[$o->option_name] = $o->option_value; 274 wp_cache_add( 'alloptions', $alloptions, 'options');277 wp_cache_add( 'alloptions', $alloptions, 'options' ); 275 278 } 276 279 return $alloptions; 277 280 } 278 281 282 279 283 // expects $option_name to NOT be SQL-escaped 280 function update_option( $option_name, $newvalue) {284 function update_option( $option_name, $newvalue ) { 281 285 global $wpdb; 282 286 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 ); 290 295 291 296 // 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 ) 294 299 return false; 295 }296 300 297 301 if ( false === $oldvalue ) { 298 add_option( $option_name, $newvalue);302 add_option( $option_name, $newvalue ); 299 303 return true; 300 304 } 301 305 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' ); 306 310 } 307 311 308 312 $_newvalue = $newvalue; 309 $newvalue = maybe_serialize( $newvalue);313 $newvalue = maybe_serialize( $newvalue ); 310 314 311 315 $alloptions = wp_load_alloptions(); 312 if ( isset( $alloptions[$option_name]) ) {316 if ( isset( $alloptions[$option_name] ) ) { 313 317 $alloptions[$option_name] = $newvalue; 314 wp_cache_set( 'alloptions', $alloptions, 'options');318 wp_cache_set( 'alloptions', $alloptions, 'options' ); 315 319 } 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 ) ); 320 324 if ( $wpdb->rows_affected == 1 ) { 321 do_action( "update_option_{$option_name}", $oldvalue, $_newvalue);325 do_action( "update_option_{$option_name}", $oldvalue, $_newvalue ); 322 326 return true; 323 327 } 324 328 return false; 325 329 } 330 326 331 327 332 // thx Alex Stapleton, http://alex.vort-x.net/blog/ 328 333 // expects $name to NOT be SQL-escaped 329 function add_option( $name, $value = '', $deprecated = '', $autoload = 'yes') {334 function add_option( $name, $value = '', $deprecated = '', $autoload = 'yes' ) { 330 335 global $wpdb; 331 336 332 wp_protect_special_option( $name);333 $safe_name = $wpdb->escape( $name);337 wp_protect_special_option( $name ); 338 $safe_name = $wpdb->escape( $name ); 334 339 335 340 // 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 ) ) 339 344 return; 340 345 341 $value = maybe_serialize( $value);346 $value = maybe_serialize( $value ); 342 347 $autoload = ( 'no' === $autoload ) ? 'no' : 'yes'; 343 348 … … 345 350 $alloptions = wp_load_alloptions(); 346 351 $alloptions[$name] = $value; 347 wp_cache_set( 'alloptions', $alloptions, 'options');352 wp_cache_set( 'alloptions', $alloptions, 'options' ); 348 353 } else { 349 wp_cache_set( $name, $value, 'options');354 wp_cache_set( $name, $value, 'options' ); 350 355 } 351 356 352 357 // This option exists now 353 $notoptions = wp_cache_get( 'notoptions', 'options'); // yes, again... we need it to be fresh354 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 ) ); 360 365 361 366 return; 362 367 } 363 368 364 function delete_option($name) { 369 370 function delete_option( $name ) { 365 371 global $wpdb; 366 372 367 wp_protect_special_option( $name);373 wp_protect_special_option( $name ); 368 374 369 375 // Get the ID, if no ID then return 370 376 // 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; 373 380 // 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'" ); 375 382 if ( 'yes' == $option->autoload ) { 376 383 $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' ); 380 387 } 381 388 } else { 382 wp_cache_delete( $name, 'options');389 wp_cache_delete( $name, 'options' ); 383 390 } 384 391 return true; 385 392 } 386 393 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 395 function 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 ); 394 402 return $data; 395 403 } 396 404 405 397 406 function 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' ) ) 399 408 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 413 function make_url_footnote( $content ) { 414 preg_match_all( '/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches ); 413 415 $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; 416 418 $j++; 417 419 $link_match = $matches[0][$i]; … … 419 421 $link_url = $matches[2][$i]; 420 422 $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 ); 426 428 $content .= $links_summary; 427 429 return $content; … … 429 431 430 432 431 function xmlrpc_getposttitle( $content) {433 function xmlrpc_getposttitle( $content ) { 432 434 global $post_default_title; 433 if ( preg_match( '/<title>(.+?)<\/title>/is', $content, $matchtitle) ) {435 if ( preg_match( '/<title>(.+?)<\/title>/is', $content, $matchtitle ) ) { 434 436 $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 ); 437 439 } else { 438 440 $post_title = $post_default_title; … … 441 443 } 442 444 443 function xmlrpc_getpostcategory($content) { 445 446 function xmlrpc_getpostcategory( $content ) { 444 447 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 ); 448 451 } else { 449 452 $post_category = $post_default_category; … … 452 455 } 453 456 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 458 function xmlrpc_removepostdata( $content ) { 459 $content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content ); 460 $content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content ); 461 $content = trim( $content ); 458 462 return $content; 459 463 } 460 464 461 function debug_fopen($filename, $mode) { 465 466 function debug_fopen( $filename, $mode ) { 462 467 global $debug; 463 if ( $debug == 1) {464 $fp = fopen( $filename, $mode);468 if ( 1 == $debug ) { 469 $fp = fopen( $filename, $mode ); 465 470 return $fp; 466 471 } else { … … 469 474 } 470 475 471 function debug_fwrite($fp, $string) { 476 477 function debug_fwrite( $fp, $string ) { 472 478 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 484 function debug_fclose( $fp ) { 479 485 global $debug; 480 if ( $debug == 1 ) { 481 fclose($fp); 482 } 486 if ( 1 == $debug ) 487 fclose( $fp ); 483 488 } 484 489 485 490 function do_enclose( $content, $post_ID ) { 486 491 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' ); 490 495 $post_links = array(); 491 debug_fwrite( $log, 'BEGIN '.date('YmdHis', time())."\n");496 debug_fwrite( $log, 'BEGIN ' . date( 'YmdHis', time() ) . "\n" ); 492 497 493 498 $pung = get_enclosed( $post_ID ); … … 498 503 $any = $ltrs . $gunk . $punc; 499 504 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 already507 $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'] ) ) 509 514 $post_links[] = $link_test; 510 elseif ( ($test['path'] != '/') && ($test['path'] != ''))515 elseif ( $test['path'] != '/' && $test['path'] != '' ) 511 516 $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 . '%' ) ) ) { 517 522 if ( $headers = wp_get_http_headers( $url) ) { 518 523 $len = (int) $headers['content-length']; … … 521 526 if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) { 522 527 $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 ) ); 525 530 } 526 531 } 527 532 } 528 endforeach; 529 } 533 } 534 } 535 530 536 531 537 function wp_get_http_headers( $url, $red = 1 ) { … … 537 543 538 544 $parts = parse_url( $url ); 539 $file = $parts['path'] . ( $parts['query'] ? '?'.$parts['query'] : '');545 $file = $parts['path'] . ( ( $parts['query'] ) ? '?' . $parts['query'] : '' ); 540 546 $host = $parts['host']; 541 547 if ( !isset( $parts['port'] ) ) … … 544 550 $head = "HEAD $file HTTP/1.1\r\nHOST: $host\r\nUser-Agent: WordPress/" . $wp_version . "\r\n\r\n"; 545 551 546 $fp = @fsockopen( $host, $parts['port'], $err_num, $err_msg, 3);552 $fp = @fsockopen( $host, $parts['port'], $err_num, $err_msg, 3 ); 547 553 if ( !$fp ) 548 554 return false; … … 553 559 $response .= fgets( $fp, 2048 ); 554 560 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] ); 559 565 $headers["$key"] = $matches[2][$i]; 560 566 } 561 567 562 preg_match( '/.*([0-9]{3}).*/', $response, $return);568 preg_match( '/.*([0-9]{3}).*/', $response, $return ); 563 569 $headers['response'] = $return[1]; // HTTP response code eg 204, 200, 404 564 570 565 571 $code = $headers['response']; 566 if ( ( '302' == $code || '301' == $code) && isset($headers['location']) )572 if ( ( '302' == $code || '301' == $code ) && isset( $headers['location'] ) ) 567 573 return wp_get_http_headers( $headers['location'], ++$red ); 568 574 569 575 return $headers; 570 576 } 577 571 578 572 579 function is_new_day() { 573 580 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 588 function build_query( $data ) { 589 return _http_build_query( $data, NULL, '&', '', false ); 590 } 591 584 592 585 593 /* … … 595 603 function add_query_arg() { 596 604 $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 ) ) 599 607 $uri = $_SERVER['REQUEST_URI']; 600 608 else 601 $uri = @func_get_arg( 1);609 $uri = @func_get_arg( 1 ); 602 610 } else { 603 if ( @func_num_args() < 3 || false === @func_get_arg( 2) )611 if ( @func_num_args() < 3 || false === @func_get_arg( 2 ) ) 604 612 $uri = $_SERVER['REQUEST_URI']; 605 613 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 ) ); 611 619 else 612 620 $frag = ''; 613 621 614 if ( preg_match( '|^https?://|i', $uri, $matches) ) {622 if ( preg_match( '|^https?://|i', $uri, $matches ) ) { 615 623 $protocol = $matches[0]; 616 $uri = substr( $uri, strlen($protocol));624 $uri = substr( $uri, strlen( $protocol ) ); 617 625 } else { 618 626 $protocol = ''; 619 627 } 620 628 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 ) ) { 624 632 $base = '?'; 625 633 $query = $parts[0]; … … 628 636 $query = $parts[1]; 629 637 } 630 } elseif ( !empty($protocol) || strpos($uri, '=') === false ) {638 } elseif ( !empty( $protocol ) || strpos( $uri, '=' ) === false ) { 631 639 $base = $uri . '?'; 632 640 $query = ''; … … 636 644 } 637 645 638 wp_parse_str( $query, $qs);639 $qs = urlencode_deep( $qs); // this re-URL-encodes things that were already in the query string640 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 ); 643 651 } else { 644 $qs[func_get_arg( 0)] = func_get_arg(1);652 $qs[func_get_arg( 0 )] = func_get_arg( 1 ); 645 653 } 646 654 647 655 foreach ( $qs as $k => $v ) { 648 656 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 ); 655 663 $ret = $protocol . $base . $ret . $frag; 656 $ret = rtrim( $ret, '?');664 $ret = rtrim( $ret, '?' ); 657 665 return $ret; 658 666 } 667 659 668 660 669 /* … … 668 677 */ 669 678 670 function remove_query_arg( $key, $query=FALSE) {671 if ( is_array( $key) ) { // removing multiple keys679 function remove_query_arg( $key, $query=FALSE ) { 680 if ( is_array( $key ) ) { // removing multiple keys 672 681 foreach ( (array) $key as $k ) 673 $query = add_query_arg( $k, FALSE, $query);682 $query = add_query_arg( $k, FALSE, $query ); 674 683 return $query; 675 684 } 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 689 function add_magic_quotes( $array ) { 680 690 global $wpdb; 681 691 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 ); 685 695 } else { 686 $array[$k] = $wpdb->escape( $v);696 $array[$k] = $wpdb->escape( $v ); 687 697 } 688 698 } … … 692 702 function wp_remote_fopen( $uri ) { 693 703 $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 ) ) 697 707 return false; 698 708 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' ) ) ) 700 710 $uri = 'http://' . $uri; 701 711 702 if ( ini_get( 'allow_url_fopen') ) {712 if ( ini_get( 'allow_url_fopen' ) ) { 703 713 $fp = @fopen( $uri, 'r' ); 704 714 if ( !$fp ) … … 707 717 //stream_set_timeout($fp, $timeout); // Requires php 4.3 708 718 $linea = ''; 709 while ( $remote_read = fread($fp, 4096) )719 while ( $remote_read = fread( $fp, 4096 ) ) 710 720 $linea .= $remote_read; 711 fclose( $fp);721 fclose( $fp ); 712 722 return $linea; 713 } else if ( function_exists('curl_init') ) {723 } elseif ( function_exists( 'curl_init' ) ) { 714 724 $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 ); 721 731 return $buffer; 722 732 } else { … … 725 735 } 726 736 727 function wp($query_vars = '') { 737 738 function wp( $query_vars = '' ) { 728 739 global $wp; 729 730 $wp->main($query_vars); 731 } 740 $wp->main( $query_vars ); 741 } 742 732 743 733 744 function get_status_header_desc( $code ) { 734 745 global $wp_header_to_desc; 735 746 736 $code = (int) $code;737 738 if ( !isset( $wp_header_to_desc) ) {747 $code = absint( $code ); 748 749 if ( !isset( $wp_header_to_desc ) ) { 739 750 $wp_header_to_desc = array( 740 751 100 => 'Continue', … … 784 795 } 785 796 786 if ( isset( $wp_header_to_desc[$code] ) ) {797 if ( isset( $wp_header_to_desc[$code] ) ) 787 798 return $wp_header_to_desc[$code]; 788 } else {799 else 789 800 return ''; 790 }791 } 801 } 802 792 803 793 804 function status_header( $header ) { … … 798 809 799 810 $protocol = $_SERVER["SERVER_PROTOCOL"]; 800 if ( ('HTTP/1.1' != $protocol) && ('HTTP/1.0' != $protocol))811 if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol ) 801 812 $protocol = 'HTTP/1.0'; 802 813 $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', '>=' ) ) 807 818 return @header( $status_header, true, $header ); 808 } else {819 else 809 820 return @header( $status_header ); 810 }811 } 821 } 822 812 823 813 824 function 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 819 832 820 833 function cache_javascript_headers() { 821 834 $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 826 840 827 841 function get_num_queries() { … … 830 844 } 831 845 846 832 847 function bool_from_yn( $yn ) { 833 848 return ( strtolower( $yn ) == 'y' ); 834 849 } 835 850 851 836 852 function do_feed() { 837 853 global $wp_query; 838 854 839 $feed = get_query_var( 'feed');855 $feed = get_query_var( 'feed' ); 840 856 841 857 // Remove the pad, if present. 842 $feed = preg_replace( '/^_+/', '', $feed);858 $feed = preg_replace( '/^_+/', '', $feed ); 843 859 844 860 if ( $feed == '' || $feed == 'feed' ) … … 846 862 847 863 $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 850 867 851 868 function do_feed_rdf() { 852 load_template(ABSPATH . WPINC . '/feed-rdf.php'); 853 } 869 load_template( ABSPATH . WPINC . '/feed-rdf.php' ); 870 } 871 854 872 855 873 function 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 878 function 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 886 function 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' ); 873 891 } 874 892 875 893 function 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' ) ) { 881 899 echo "User-agent: *\n"; 882 900 echo "Disallow: /\n"; … … 887 905 } 888 906 907 889 908 function is_blog_installed() { 890 909 global $wpdb; 891 910 $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'" ); 893 912 $wpdb->show_errors(); 894 913 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('&', '&', $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 918 function wp_nonce_url( $actionurl, $action = -1 ) { 919 $actionurl = str_replace( '&', '&', $actionurl ); 920 return wp_specialchars( add_query_arg( '_wpnonce', wp_create_nonce( $action ), $actionurl ) ); 921 } 922 923 924 function 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 ) . '" />'; 907 927 if ( $referer ) 908 928 wp_referer_field(); 909 929 } 910 930 931 911 932 function wp_referer_field() { 912 $ref = attribute_escape( $_SERVER['REQUEST_URI']);933 $ref = attribute_escape( $_SERVER['REQUEST_URI'] ); 913 934 echo '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />'; 914 935 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() ) ); 916 937 echo '<input type="hidden" name="_wp_original_http_referer" value="'. $original_ref . '" />'; 917 938 } 918 939 } 919 940 941 920 942 function 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 923 946 924 947 function 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 ) ) 927 950 return $ref; 928 951 return false; 929 952 } 930 953 954 931 955 function wp_get_original_referer() { 932 if ( !empty( $_REQUEST['_wp_original_http_referer']) )956 if ( !empty( $_REQUEST['_wp_original_http_referer'] ) ) 933 957 return $_REQUEST['_wp_original_http_referer']; 934 958 return false; 935 959 } 936 960 937 function wp_mkdir_p($target) { 961 962 function wp_mkdir_p( $target ) { 938 963 // 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 ) ) ) { 941 974 return false; 942 else943 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;955 975 } 956 976 957 977 // 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 ); 960 980 961 981 return false; 962 982 } 983 963 984 964 985 // Returns an array containing the current upload directory's path and url, or an error message. 965 986 function wp_upload_dir() { 966 $siteurl = get_option( 'siteurl');987 $siteurl = get_option( 'siteurl' ); 967 988 //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' ) ) ); 969 990 $dir = ABSPATH . $path; 970 $url = trailingslashit( $siteurl) . $path;971 972 if ( $dir == ABSPATH ) { //the option was empty991 $url = trailingslashit( $siteurl ) . $path; 992 993 if ( $dir == ABSPATH ) // the option was empty 973 994 $dir = ABSPATH . 'wp-content/uploads'; 974 }975 995 976 996 if ( defined('UPLOADS') ) { 977 997 $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' ) ) { 982 1002 // Generate the yearly and monthly dirs 983 1003 $time = current_time( 'mysql' ); … … 990 1010 // Make sure we have an uploads dir 991 1011 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 1020 function wp_upload_bits( $name, $type, $bits ) { 1021 if ( empty( $name ) ) 1022 return array( 'error' => __( "Empty filename" ) ); 1023 1024 $wp_filetype = wp_check_filetype( $name ); 1005 1025 if ( !$wp_filetype['ext'] ) 1006 return array( 'error' => __("Invalid file type"));1026 return array( 'error' => __( "Invalid file type" ) ); 1007 1027 1008 1028 $upload = wp_upload_dir(); … … 1013 1033 $number = ''; 1014 1034 $filename = $name; 1015 $path_parts = pathinfo( $filename);1035 $path_parts = pathinfo( $filename ); 1016 1036 $ext = $path_parts['extension']; 1017 if ( empty( $ext) )1037 if ( empty( $ext ) ) 1018 1038 $ext = ''; 1019 1039 else 1020 1040 $ext = ".$ext"; 1021 while ( file_exists( $upload['path'] . "/$filename") ) {1041 while ( file_exists( $upload['path'] . "/$filename" ) ) { 1022 1042 if ( '' == "$number$ext" ) 1023 1043 $filename = $filename . ++$number . $ext; 1024 1044 else 1025 $filename = str_replace( "$number$ext", ++$number . $ext, $filename);1045 $filename = str_replace( "$number$ext", ++$number . $ext, $filename ); 1026 1046 } 1027 1047 1028 1048 $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' ); 1035 1055 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 ); 1040 1060 // Set correct file permissions 1041 $stat = @ stat( dirname($new_file));1061 $stat = @ stat( dirname( $new_file ) ); 1042 1062 $perms = $stat['mode'] & 0007777; 1043 1063 $perms = $perms & 0000666; 1044 @ chmod( $new_file, $perms);1064 @ chmod( $new_file, $perms ); 1045 1065 1046 1066 // Compute the URL 1047 1067 $url = $upload['url'] . "/$filename"; 1048 1068 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 1073 function wp_check_filetype( $filename, $mimes = null ) { 1053 1074 // 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( 1055 1076 'jpg|jpeg|jpe' => 'image/jpeg', 1056 1077 'gif' => 'image/gif', … … 1096 1117 'odb' => 'application/vnd.oasis.opendocument.database', 1097 1118 'odf' => 'application/vnd.oasis.opendocument.formula', 1098 1099 ) );1119 ) 1120 ); 1100 1121 1101 1122 $type = false; 1102 1123 $ext = false; 1103 1124 1104 foreach ( $mimes as $ext_preg => $mime_match) {1125 foreach ( $mimes as $ext_preg => $mime_match ) { 1105 1126 $ext_preg = '!\.(' . $ext_preg . ')$!i'; 1106 if ( preg_match( $ext_preg, $filename, $ext_matches) ) {1127 if ( preg_match( $ext_preg, $filename, $ext_matches ) ) { 1107 1128 $type = $mime_match; 1108 1129 $ext = $ext_matches[1]; … … 1111 1132 } 1112 1133 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 1137 function wp_explain_nonce( $action ) { 1138 if ( $action !== -1 && preg_match( '/([a-z]+)-([a-z]+)(_(.+))?/', $action, $matches ) ) { 1118 1139 $verb = $matches[1]; 1119 1140 $noun = $matches[2]; 1120 1141 1121 1142 $trans = array(); 1122 $trans['update']['attachment'] = array( __('Are you sure you want to edit this attachment: "%s"?'), '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: "%s"?'), 'get_catname');1126 $trans['update']['category'] = array(__('Are you sure you want to edit this category: "%s"?'), 'get_catname');1127 1128 $trans['delete']['comment'] = array(__('Are you sure you want to delete this comment: "%s"?'), 'use_id');1129 $trans['unapprove']['comment'] = array( __('Are you sure you want to unapprove this comment: "%s"?'), 'use_id');1130 $trans['approve']['comment'] = array(__('Are you sure you want to approve this comment: "%s"?'), 'use_id');1131 $trans['update']['comment'] = array(__('Are you sure you want to edit this comment: "%s"?'), '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: "%s"?'), 'use_id');1137 $trans['update']['bookmark'] = array(__('Are you sure you want to edit this link: "%s"?'), '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: "%s"?'), 'get_the_title');1142 $trans['update']['page'] = array(__('Are you sure you want to edit this page: "%s"?'), 'get_the_title');1143 1144 $trans['edit']['plugin'] = array(__('Are you sure you want to edit this plugin file: "%s"?'), 'use_id');1145 $trans['activate']['plugin'] = array(__('Are you sure you want to activate this plugin: "%s"?'), 'use_id');1146 $trans['deactivate']['plugin'] = array( __('Are you sure you want to deactivate this plugin: "%s"?'), '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: "%s"?'), 'get_the_title');1150 $trans['update']['post'] = array(__('Are you sure you want to edit this post: "%s"?'), '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: "%s"?'), 'get_author_name');1156 $trans['update']['profile'] = array(__('Are you sure you want to modify the profile for: "%s"?'), '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: "%s"?'), 'use_id');1161 $trans['edit']['theme'] = array(__('Are you sure you want to edit this theme file: "%s"?'), 'use_id');1162 $trans['switch']['theme'] = array(__('Are you sure you want to switch to this theme: "%s"?'), '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: "%s"?' ), '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: "%s"?' ), 'get_catname' ); 1147 $trans['update']['category'] = array( __( 'Are you sure you want to edit this category: "%s"?' ), 'get_catname' ); 1148 1149 $trans['delete']['comment'] = array( __( 'Are you sure you want to delete this comment: "%s"?' ), 'use_id' ); 1150 $trans['unapprove']['comment'] = array( __( 'Are you sure you want to unapprove this comment: "%s"?' ), 'use_id' ); 1151 $trans['approve']['comment'] = array( __( 'Are you sure you want to approve this comment: "%s"?' ), 'use_id' ); 1152 $trans['update']['comment'] = array( __( 'Are you sure you want to edit this comment: "%s"?' ), '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: "%s"?' ), 'use_id' ); 1158 $trans['update']['bookmark'] = array( __( 'Are you sure you want to edit this link: "%s"?' ), '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: "%s"?' ), 'get_the_title' ); 1163 $trans['update']['page'] = array( __( 'Are you sure you want to edit this page: "%s"?' ), 'get_the_title' ); 1164 1165 $trans['edit']['plugin'] = array( __( 'Are you sure you want to edit this plugin file: "%s"?' ), 'use_id' ); 1166 $trans['activate']['plugin'] = array( __( 'Are you sure you want to activate this plugin: "%s"?' ), 'use_id' ); 1167 $trans['deactivate']['plugin'] = array( __( 'Are you sure you want to deactivate this plugin: "%s"?' ), '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: "%s"?' ), 'get_the_title' ); 1171 $trans['update']['post'] = array( __( 'Are you sure you want to edit this post: "%s"?' ), '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: "%s"?' ), 'get_author_name' ); 1177 $trans['update']['profile'] = array( __( 'Are you sure you want to modify the profile for: "%s"?' ), '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: "%s"?' ), 'use_id' ); 1182 $trans['edit']['theme'] = array( __( 'Are you sure you want to edit this theme file: "%s"?' ), 'use_id' ); 1183 $trans['switch']['theme'] = array( __( 'Are you sure you want to switch to this theme: "%s"?' ), 'use_id' ); 1184 1185 if ( isset( $trans[$verb][$noun] ) ) { 1186 if ( !empty( $trans[$verb][$noun][1] ) ) { 1166 1187 $lookup = $trans[$verb][$noun][1]; 1167 1188 $object = $matches[4]; 1168 1189 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 ); 1171 1192 } else { 1172 1193 return $trans[$verb][$noun][0]; … … 1175 1196 } 1176 1197 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 1202 function wp_nonce_ays( $action ) { 1181 1203 global $pagenow, $menu, $submenu, $parent_file, $submenu_file; 1182 1204 1183 $adminurl = get_option( 'siteurl') . '/wp-admin';1205 $adminurl = get_option( 'siteurl' ) . '/wp-admin'; 1184 1206 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' ); 1188 1210 // Remove extra layer of slashes. 1189 $_POST = stripslashes_deep( $_POST);1211 $_POST = stripslashes_deep( $_POST ); 1190 1212 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"; 1194 1216 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"; 1198 1220 } 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"; 1201 1223 } 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"; 1203 1225 } 1204 1226 $html .= "</body>\n</html>"; 1205 wp_die($html, $title); 1206 } 1227 wp_die( $html, $title ); 1228 } 1229 1207 1230 1208 1231 function wp_die( $message, $title = '' ) { … … 1210 1233 1211 1234 if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) { 1212 if ( empty( $title) ) {1235 if ( empty( $title ) ) { 1213 1236 $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'] ) ) 1215 1238 $title = $error_data['title']; 1216 1239 } 1217 1240 $errors = $message->get_error_messages(); 1218 switch ( count( $errors) ) :1241 switch ( count( $errors ) ) : 1219 1242 case 0 : 1220 1243 $message = ''; … … 1227 1250 break; 1228 1251 endswitch; 1229 } elseif ( is_string( $message) ) {1252 } elseif ( is_string( $message ) ) { 1230 1253 $message = "<p>$message</p>"; 1231 1254 } 1232 1255 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 ) 1238 1261 $admin_dir = ''; 1239 1262 else 1240 1263 $admin_dir = 'wp-admin/'; 1241 1264 1242 if ( !function_exists( 'did_action') || !did_action('admin_head') ) :1265 if ( !function_exists( 'did_action' ) || !did_action( 'admin_head' ) ) : 1243 1266 if( !headers_sent() ){ 1244 status_header( 500);1267 status_header( 500 ); 1245 1268 nocache_headers(); 1246 header( 'Content-Type: text/html; charset=utf-8');1247 } 1248 1249 if ( empty($title) ) {1250 if ( function_exists('__') )1251 $title = __( 'WordPress › Error');1269 header( 'Content-Type: text/html; charset=utf-8' ); 1270 } 1271 1272 if ( empty($title) ) { 1273 if ( function_exists( '__' ) ) 1274 $title = __( 'WordPress › Error' ); 1252 1275 else 1253 1276 $title = 'WordPress › Error'; … … 1256 1279 ?> 1257 1280 <!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(); ?>> 1259 1282 <head> 1260 1283 <title><?php echo $title ?></title> … … 1262 1285 <link rel="stylesheet" href="<?php echo $admin_dir; ?>css/install.css" type="text/css" /> 1263 1286 <?php 1264 if ( ( $wp_locale ) && ( 'rtl' == $wp_locale->text_direction) ) : ?>1287 if ( ( $wp_locale ) && ( 'rtl' == $wp_locale->text_direction ) ) : ?> 1265 1288 <link rel="stylesheet" href="<?php echo $admin_dir; ?>css/install-rtl.css" type="text/css" /> 1266 1289 <?php endif; ?> … … 1277 1300 } 1278 1301 1279 function _config_wp_home($url = '') { 1302 1303 function _config_wp_home( $url = '' ) { 1280 1304 if ( defined( 'WP_HOME' ) ) 1281 1305 return WP_HOME; 1282 else return $url; 1283 } 1284 1285 function _config_wp_siteurl($url = '') { 1306 return $url; 1307 } 1308 1309 1310 function _config_wp_siteurl( $url = '' ) { 1286 1311 if ( defined( 'WP_SITEURL' ) ) 1287 1312 return WP_SITEURL; 1288 else return $url; 1289 } 1313 return $url; 1314 } 1315 1290 1316 1291 1317 function _mce_set_direction() { 1292 1318 global $wp_locale; 1293 1319 1294 if ( 'rtl' == $wp_locale->text_direction) {1320 if ( 'rtl' == $wp_locale->text_direction ) { 1295 1321 echo 'directionality : "rtl" ,'; 1296 1322 echo 'theme_advanced_toolbar_align : "right" ,'; … … 1298 1324 } 1299 1325 1300 function _mce_load_rtl_plugin($input) { 1326 1327 function _mce_load_rtl_plugin( $input ) { 1301 1328 global $wp_locale; 1302 1329 1303 if ( 'rtl' == $wp_locale->text_direction)1330 if ( 'rtl' == $wp_locale->text_direction ) 1304 1331 $input[] = 'directionality'; 1305 1332 … … 1307 1334 } 1308 1335 1309 function _mce_add_direction_buttons($input) { 1336 1337 function _mce_add_direction_buttons( $input ) { 1310 1338 global $wp_locale; 1311 1339 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 ); 1315 1343 } 1316 1344 1317 1345 return $input; 1318 1346 } 1347 1319 1348 1320 1349 function smilies_init() { … … 1322 1351 1323 1352 // don't bother setting up smilies if they are disabled 1324 if ( !get_option( 'use_smilies') )1353 if ( !get_option( 'use_smilies' ) ) 1325 1354 return; 1326 1355 1327 if ( !isset($wpsmiliestrans)) {1356 if ( !isset( $wpsmiliestrans ) ) { 1328 1357 $wpsmiliestrans = array( 1329 1358 ':mrgreen:' => 'icon_mrgreen.gif', … … 1374 1403 } 1375 1404 1376 $siteurl = get_option( 'siteurl');1405 $siteurl = get_option( 'siteurl' ); 1377 1406 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 ) ); 1380 1409 $wp_smiliesreplace[] = " <img src='$siteurl/wp-includes/images/smilies/$img' alt='$smiley_masked' class='wp-smiley' /> "; 1381 1410 } 1382 1411 } 1383 1412 1413 1384 1414 function 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 ) ) 1388 1418 $r =& $args; 1389 1419 else … … 1392 1422 if ( is_array( $defaults ) ) 1393 1423 return array_merge( $defaults, $r ); 1394 else1395 return $r; 1396 } 1424 return $r; 1425 } 1426 1397 1427 1398 1428 function wp_maybe_load_widgets() { 1399 1429 if ( !function_exists( 'dynamic_sidebar' ) ) { 1400 require_once ABSPATH . WPINC . '/widgets.php';1430 require_once( ABSPATH . WPINC . '/widgets.php' ); 1401 1431 add_action( '_admin_menu', 'wp_widgets_add_menu' ); 1402 1432 } 1403 1433 } 1434 1404 1435 1405 1436 function wp_widgets_add_menu() { 1406 1437 global $submenu; 1407 1438 $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 1410 1442 1411 1443 // For PHP 5.2, make sure all output buffers are flushed 1412 1444 // before our singletons our destroyed. 1413 function wp_ob_end_flush_all() 1414 { 1445 function wp_ob_end_flush_all() { 1415 1446 while ( @ob_end_flush() ); 1416 1447 } 1448 1417 1449 1418 1450 /* … … 1424 1456 * @global $wpdb 1425 1457 */ 1426 function require_wp_db() 1427 { 1458 function require_wp_db() { 1428 1459 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' ); 1431 1462 else 1432 require_once (ABSPATH . WPINC . '/wp-db.php'); 1433 } 1463 require_once( ABSPATH . WPINC . '/wp-db.php' ); 1464 } 1465 1434 1466 1435 1467 /** … … 1438 1470 * @return int an absolute integer 1439 1471 */ 1440 function absint( $maybeint) {1441 return abs( intval($maybeint));1472 function absint( $maybeint ) { 1473 return abs( intval( $maybeint ) ); 1442 1474 } 1443 1475
Note: See TracChangeset
for help on using the changeset viewer.