raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Main WordPress API
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 */
mp-wp_genesis 7
mp-wp_genesis 8 /**
mp-wp_genesis 9 * Converts MySQL DATETIME field to user specified date format.
mp-wp_genesis 10 *
mp-wp_genesis 11 * If $dateformatstring has 'G' value, then gmmktime() function will be used to
mp-wp_genesis 12 * make the time. If $dateformatstring is set to 'U', then mktime() function
mp-wp_genesis 13 * will be used to make the time.
mp-wp_genesis 14 *
mp-wp_genesis 15 * The $translate will only be used, if it is set to true and it is by default
mp-wp_genesis 16 * and if the $wp_locale object has the month and weekday set.
mp-wp_genesis 17 *
mp-wp_genesis 18 * @since 0.71
mp-wp_genesis 19 *
mp-wp_genesis 20 * @param string $dateformatstring Either 'G', 'U', or php date format.
mp-wp_genesis 21 * @param string $mysqlstring Time from mysql DATETIME field.
mp-wp_genesis 22 * @param bool $translate Optional. Default is true. Will switch format to locale.
mp-wp_genesis 23 * @return string Date formated by $dateformatstring or locale (if available).
mp-wp_genesis 24 */
mp-wp_genesis 25 function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) {
mp-wp_genesis 26 global $wp_locale;
mp-wp_genesis 27 $m = $mysqlstring;
mp-wp_genesis 28 if ( empty( $m ) )
mp-wp_genesis 29 return false;
mp-wp_genesis 30
mp-wp_genesis 31 if( 'G' == $dateformatstring ) {
mp-wp_genesis 32 return gmmktime(
mp-wp_genesis 33 (int) substr( $m, 11, 2 ), (int) substr( $m, 14, 2 ), (int) substr( $m, 17, 2 ),
mp-wp_genesis 34 (int) substr( $m, 5, 2 ), (int) substr( $m, 8, 2 ), (int) substr( $m, 0, 4 )
mp-wp_genesis 35 );
mp-wp_genesis 36 }
mp-wp_genesis 37
mp-wp_genesis 38 $i = mktime(
mp-wp_genesis 39 (int) substr( $m, 11, 2 ), (int) substr( $m, 14, 2 ), (int) substr( $m, 17, 2 ),
mp-wp_genesis 40 (int) substr( $m, 5, 2 ), (int) substr( $m, 8, 2 ), (int) substr( $m, 0, 4 )
mp-wp_genesis 41 );
mp-wp_genesis 42
mp-wp_genesis 43 if( 'U' == $dateformatstring )
mp-wp_genesis 44 return $i;
mp-wp_genesis 45
mp-wp_genesis 46 if ( -1 == $i || false == $i )
mp-wp_genesis 47 $i = 0;
mp-wp_genesis 48
mp-wp_genesis 49 if ( !empty( $wp_locale->month ) && !empty( $wp_locale->weekday ) && $translate ) {
mp-wp_genesis 50 $datemonth = $wp_locale->get_month( date( 'm', $i ) );
mp-wp_genesis 51 $datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth );
mp-wp_genesis 52 $dateweekday = $wp_locale->get_weekday( date( 'w', $i ) );
mp-wp_genesis 53 $dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday );
mp-wp_genesis 54 $datemeridiem = $wp_locale->get_meridiem( date( 'a', $i ) );
mp-wp_genesis 55 $datemeridiem_capital = $wp_locale->get_meridiem( date( 'A', $i ) );
mp-wp_genesis 56 $dateformatstring = ' ' . $dateformatstring;
mp-wp_genesis 57 $dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring );
mp-wp_genesis 58 $dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring );
mp-wp_genesis 59 $dateformatstring = preg_replace( "/([^\\\])l/", "\\1" . backslashit( $dateweekday ), $dateformatstring );
mp-wp_genesis 60 $dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring );
mp-wp_genesis 61 $dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring );
mp-wp_genesis 62 $dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring );
mp-wp_genesis 63
mp-wp_genesis 64 $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
mp-wp_genesis 65 }
mp-wp_genesis 66 $j = @date( $dateformatstring, $i );
mp-wp_genesis 67
mp-wp_genesis 68 /*
mp-wp_genesis 69 if ( !$j ) // for debug purposes
mp-wp_genesis 70 echo $i." ".$mysqlstring;
mp-wp_genesis 71 */
mp-wp_genesis 72
mp-wp_genesis 73 return $j;
mp-wp_genesis 74 }
mp-wp_genesis 75
mp-wp_genesis 76 /**
mp-wp_genesis 77 * Retrieve the current time based on specified type.
mp-wp_genesis 78 *
mp-wp_genesis 79 * The 'mysql' type will return the time in the format for MySQL DATETIME field.
mp-wp_genesis 80 * The 'timestamp' type will return the current timestamp.
mp-wp_genesis 81 *
mp-wp_genesis 82 * If the $gmt is set to either '1' or 'true', then both types will use the
mp-wp_genesis 83 * GMT offset in the WordPress option to add the GMT offset to the time.
mp-wp_genesis 84 *
mp-wp_genesis 85 * @since 1.0.0
mp-wp_genesis 86 *
mp-wp_genesis 87 * @param string $type Either 'mysql' or 'timestamp'.
mp-wp_genesis 88 * @param int|bool $gmt Optional. Whether to use $gmt offset. Default is false.
mp-wp_genesis 89 * @return int|string String if $type is 'gmt', int if $type is 'timestamp'.
mp-wp_genesis 90 */
mp-wp_genesis 91 function current_time( $type, $gmt = 0 ) {
mp-wp_genesis 92 switch ( $type ) {
mp-wp_genesis 93 case 'mysql':
mp-wp_genesis 94 return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) );
mp-wp_genesis 95 break;
mp-wp_genesis 96 case 'timestamp':
mp-wp_genesis 97 return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * 3600 );
mp-wp_genesis 98 break;
mp-wp_genesis 99 }
mp-wp_genesis 100 }
mp-wp_genesis 101
mp-wp_genesis 102 /**
mp-wp_genesis 103 * Retrieve the date in localized format, based on timestamp.
mp-wp_genesis 104 *
mp-wp_genesis 105 * If the locale specifies the locale month and weekday, then the locale will
mp-wp_genesis 106 * take over the format for the date. If it isn't, then the date format string
mp-wp_genesis 107 * will be used instead.
mp-wp_genesis 108 *
mp-wp_genesis 109 * @since 0.71
mp-wp_genesis 110 *
mp-wp_genesis 111 * @param string $dateformatstring Format to display the date
mp-wp_genesis 112 * @param int $unixtimestamp Unix timestamp
mp-wp_genesis 113 * @return string The date, translated if locale specifies it.
mp-wp_genesis 114 */
mp-wp_genesis 115 function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) {
mp-wp_genesis 116 global $wp_locale;
mp-wp_genesis 117 $i = $unixtimestamp;
mp-wp_genesis 118 // Sanity check for PHP 5.1.0-
mp-wp_genesis 119 if ( false === $i || intval($i) < 0 ) {
mp-wp_genesis 120 if ( ! $gmt )
mp-wp_genesis 121 $i = current_time( 'timestamp' );
mp-wp_genesis 122 else
mp-wp_genesis 123 $i = time();
mp-wp_genesis 124 // we should not let date() interfere with our
mp-wp_genesis 125 // specially computed timestamp
mp-wp_genesis 126 $gmt = true;
mp-wp_genesis 127 }
mp-wp_genesis 128
mp-wp_genesis 129 $datefunc = $gmt? 'gmdate' : 'date';
mp-wp_genesis 130
mp-wp_genesis 131 if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) {
mp-wp_genesis 132 $datemonth = $wp_locale->get_month( $datefunc( 'm', $i ) );
mp-wp_genesis 133 $datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth );
mp-wp_genesis 134 $dateweekday = $wp_locale->get_weekday( $datefunc( 'w', $i ) );
mp-wp_genesis 135 $dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday );
mp-wp_genesis 136 $datemeridiem = $wp_locale->get_meridiem( $datefunc( 'a', $i ) );
mp-wp_genesis 137 $datemeridiem_capital = $wp_locale->get_meridiem( $datefunc( 'A', $i ) );
mp-wp_genesis 138 $dateformatstring = ' '.$dateformatstring;
mp-wp_genesis 139 $dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring );
mp-wp_genesis 140 $dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring );
mp-wp_genesis 141 $dateformatstring = preg_replace( "/([^\\\])l/", "\\1" . backslashit( $dateweekday ), $dateformatstring );
mp-wp_genesis 142 $dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring );
mp-wp_genesis 143 $dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring );
mp-wp_genesis 144 $dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring );
mp-wp_genesis 145
mp-wp_genesis 146 $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
mp-wp_genesis 147 }
mp-wp_genesis 148 $j = @$datefunc( $dateformatstring, $i );
mp-wp_genesis 149 return $j;
mp-wp_genesis 150 }
mp-wp_genesis 151
mp-wp_genesis 152 /**
mp-wp_genesis 153 * Convert number to format based on the locale.
mp-wp_genesis 154 *
mp-wp_genesis 155 * @since 2.3.0
mp-wp_genesis 156 *
mp-wp_genesis 157 * @param mixed $number The number to convert based on locale.
mp-wp_genesis 158 * @param int $decimals Precision of the number of decimal places.
mp-wp_genesis 159 * @return string Converted number in string format.
mp-wp_genesis 160 */
mp-wp_genesis 161 function number_format_i18n( $number, $decimals = null ) {
mp-wp_genesis 162 global $wp_locale;
mp-wp_genesis 163 // let the user override the precision only
mp-wp_genesis 164 $decimals = ( is_null( $decimals ) ) ? $wp_locale->number_format['decimals'] : intval( $decimals );
mp-wp_genesis 165
mp-wp_genesis 166 return number_format( $number, $decimals, $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] );
mp-wp_genesis 167 }
mp-wp_genesis 168
mp-wp_genesis 169 /**
mp-wp_genesis 170 * Convert number of bytes largest unit bytes will fit into.
mp-wp_genesis 171 *
mp-wp_genesis 172 * It is easier to read 1kB than 1024 bytes and 1MB than 1048576 bytes. Converts
mp-wp_genesis 173 * number of bytes to human readable number by taking the number of that unit
mp-wp_genesis 174 * that the bytes will go into it. Supports TB value.
mp-wp_genesis 175 *
mp-wp_genesis 176 * Please note that integers in PHP are limited to 32 bits, unless they are on
mp-wp_genesis 177 * 64 bit architecture, then they have 64 bit size. If you need to place the
mp-wp_genesis 178 * larger size then what PHP integer type will hold, then use a string. It will
mp-wp_genesis 179 * be converted to a double, which should always have 64 bit length.
mp-wp_genesis 180 *
mp-wp_genesis 181 * Technically the correct unit names for powers of 1024 are KiB, MiB etc.
mp-wp_genesis 182 * @link http://en.wikipedia.org/wiki/Byte
mp-wp_genesis 183 *
mp-wp_genesis 184 * @since 2.3.0
mp-wp_genesis 185 *
mp-wp_genesis 186 * @param int|string $bytes Number of bytes. Note max integer size for integers.
mp-wp_genesis 187 * @param int $decimals Precision of number of decimal places.
mp-wp_genesis 188 * @return bool|string False on failure. Number string on success.
mp-wp_genesis 189 */
mp-wp_genesis 190 function size_format( $bytes, $decimals = null ) {
mp-wp_genesis 191 $quant = array(
mp-wp_genesis 192 // ========================= Origin ====
mp-wp_genesis 193 'TB' => 1099511627776, // pow( 1024, 4)
mp-wp_genesis 194 'GB' => 1073741824, // pow( 1024, 3)
mp-wp_genesis 195 'MB' => 1048576, // pow( 1024, 2)
mp-wp_genesis 196 'kB' => 1024, // pow( 1024, 1)
mp-wp_genesis 197 'B ' => 1, // pow( 1024, 0)
mp-wp_genesis 198 );
mp-wp_genesis 199
mp-wp_genesis 200 foreach ( $quant as $unit => $mag )
mp-wp_genesis 201 if ( doubleval($bytes) >= $mag )
mp-wp_genesis 202 return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;
mp-wp_genesis 203
mp-wp_genesis 204 return false;
mp-wp_genesis 205 }
mp-wp_genesis 206
mp-wp_genesis 207 /**
mp-wp_genesis 208 * Get the week start and end from the datetime or date string from mysql.
mp-wp_genesis 209 *
mp-wp_genesis 210 * @since 0.71
mp-wp_genesis 211 *
mp-wp_genesis 212 * @param string $mysqlstring Date or datetime field type from mysql.
mp-wp_genesis 213 * @param int $start_of_week Optional. Start of the week as an integer.
mp-wp_genesis 214 * @return array Keys are 'start' and 'end'.
mp-wp_genesis 215 */
mp-wp_genesis 216 function get_weekstartend( $mysqlstring, $start_of_week = '' ) {
mp-wp_genesis 217 $my = substr( $mysqlstring, 0, 4 ); // Mysql string Year
mp-wp_genesis 218 $mm = substr( $mysqlstring, 8, 2 ); // Mysql string Month
mp-wp_genesis 219 $md = substr( $mysqlstring, 5, 2 ); // Mysql string day
mp-wp_genesis 220 $day = mktime( 0, 0, 0, $md, $mm, $my ); // The timestamp for mysqlstring day.
mp-wp_genesis 221 $weekday = date( 'w', $day ); // The day of the week from the timestamp
mp-wp_genesis 222 $i = 86400; // One day
mp-wp_genesis 223 if( !is_numeric($start_of_week) )
mp-wp_genesis 224 $start_of_week = get_option( 'start_of_week' );
mp-wp_genesis 225
mp-wp_genesis 226 if ( $weekday < $start_of_week )
mp-wp_genesis 227 $weekday = 7 - $start_of_week - $weekday;
mp-wp_genesis 228
mp-wp_genesis 229 while ( $weekday > $start_of_week ) {
mp-wp_genesis 230 $weekday = date( 'w', $day );
mp-wp_genesis 231 if ( $weekday < $start_of_week )
mp-wp_genesis 232 $weekday = 7 - $start_of_week - $weekday;
mp-wp_genesis 233
mp-wp_genesis 234 $day -= 86400;
mp-wp_genesis 235 $i = 0;
mp-wp_genesis 236 }
mp-wp_genesis 237 $week['start'] = $day + 86400 - $i;
mp-wp_genesis 238 $week['end'] = $week['start'] + 604799;
mp-wp_genesis 239 return $week;
mp-wp_genesis 240 }
mp-wp_genesis 241
mp-wp_genesis 242 /**
mp-wp_genesis 243 * Unserialize value only if it was serialized.
mp-wp_genesis 244 *
mp-wp_genesis 245 * @since 2.0.0
mp-wp_genesis 246 *
mp-wp_genesis 247 * @param string $original Maybe unserialized original, if is needed.
mp-wp_genesis 248 * @return mixed Unserialized data can be any type.
mp-wp_genesis 249 */
mp-wp_genesis 250 function maybe_unserialize( $original ) {
mp-wp_genesis 251 if ( is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in
mp-wp_genesis 252 if ( false !== $gm = @unserialize( $original ) )
mp-wp_genesis 253 return $gm;
mp-wp_genesis 254 return $original;
mp-wp_genesis 255 }
mp-wp_genesis 256
mp-wp_genesis 257 /**
mp-wp_genesis 258 * Check value to find if it was serialized.
mp-wp_genesis 259 *
mp-wp_genesis 260 * If $data is not an string, then returned value will always be false.
mp-wp_genesis 261 * Serialized data is always a string.
mp-wp_genesis 262 *
mp-wp_genesis 263 * @since 2.0.5
mp-wp_genesis 264 *
mp-wp_genesis 265 * @param mixed $data Value to check to see if was serialized.
mp-wp_genesis 266 * @return bool False if not serialized and true if it was.
mp-wp_genesis 267 */
mp-wp_genesis 268 function is_serialized( $data ) {
mp-wp_genesis 269 // if it isn't a string, it isn't serialized
mp-wp_genesis 270 if ( !is_string( $data ) )
mp-wp_genesis 271 return false;
mp-wp_genesis 272 $data = trim( $data );
mp-wp_genesis 273 if ( 'N;' == $data )
mp-wp_genesis 274 return true;
mp-wp_genesis 275 if ( !preg_match( '/^([adObis]):/', $data, $badions ) )
mp-wp_genesis 276 return false;
mp-wp_genesis 277 switch ( $badions[1] ) {
mp-wp_genesis 278 case 'a' :
mp-wp_genesis 279 case 'O' :
mp-wp_genesis 280 case 's' :
mp-wp_genesis 281 if ( preg_match( "/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data ) )
mp-wp_genesis 282 return true;
mp-wp_genesis 283 break;
mp-wp_genesis 284 case 'b' :
mp-wp_genesis 285 case 'i' :
mp-wp_genesis 286 case 'd' :
mp-wp_genesis 287 if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) )
mp-wp_genesis 288 return true;
mp-wp_genesis 289 break;
mp-wp_genesis 290 }
mp-wp_genesis 291 return false;
mp-wp_genesis 292 }
mp-wp_genesis 293
mp-wp_genesis 294 /**
mp-wp_genesis 295 * Check whether serialized data is of string type.
mp-wp_genesis 296 *
mp-wp_genesis 297 * @since 2.0.5
mp-wp_genesis 298 *
mp-wp_genesis 299 * @param mixed $data Serialized data
mp-wp_genesis 300 * @return bool False if not a serialized string, true if it is.
mp-wp_genesis 301 */
mp-wp_genesis 302 function is_serialized_string( $data ) {
mp-wp_genesis 303 // if it isn't a string, it isn't a serialized string
mp-wp_genesis 304 if ( !is_string( $data ) )
mp-wp_genesis 305 return false;
mp-wp_genesis 306 $data = trim( $data );
mp-wp_genesis 307 if ( preg_match( '/^s:[0-9]+:.*;$/s', $data ) ) // this should fetch all serialized strings
mp-wp_genesis 308 return true;
mp-wp_genesis 309 return false;
mp-wp_genesis 310 }
mp-wp_genesis 311
mp-wp_genesis 312 /**
mp-wp_genesis 313 * Retrieve option value based on setting name.
mp-wp_genesis 314 *
mp-wp_genesis 315 * If the option does not exist or does not have a value, then the return value
mp-wp_genesis 316 * will be false. This is useful to check whether you need to install an option
mp-wp_genesis 317 * and is commonly used during installation of plugin options and to test
mp-wp_genesis 318 * whether upgrading is required.
mp-wp_genesis 319 *
mp-wp_genesis 320 * You can "short-circuit" the retrieval of the option from the database for
mp-wp_genesis 321 * your plugin or core options that aren't protected. You can do so by hooking
mp-wp_genesis 322 * into the 'pre_option_$option' with the $option being replaced by the option
mp-wp_genesis 323 * name. You should not try to override special options, but you will not be
mp-wp_genesis 324 * prevented from doing so.
mp-wp_genesis 325 *
mp-wp_genesis 326 * There is a second filter called 'option_$option' with the $option being
mp-wp_genesis 327 * replaced with the option name. This gives the value as the only parameter.
mp-wp_genesis 328 *
mp-wp_genesis 329 * If the option was serialized, when the option was added and, or updated, then
mp-wp_genesis 330 * it will be unserialized, when it is returned.
mp-wp_genesis 331 *
mp-wp_genesis 332 * @since 1.5.0
mp-wp_genesis 333 * @package WordPress
mp-wp_genesis 334 * @subpackage Option
mp-wp_genesis 335 * @uses apply_filters() Calls 'pre_option_$optionname' false to allow
mp-wp_genesis 336 * overwriting the option value in a plugin.
mp-wp_genesis 337 * @uses apply_filters() Calls 'option_$optionname' with the option name value.
mp-wp_genesis 338 *
mp-wp_genesis 339 * @param string $setting Name of option to retrieve. Should already be SQL-escaped
mp-wp_genesis 340 * @return mixed Value set for the option.
mp-wp_genesis 341 */
mp-wp_genesis 342 function get_option( $setting, $default = false ) {
mp-wp_genesis 343 global $wpdb;
mp-wp_genesis 344
mp-wp_genesis 345 // Allow plugins to short-circuit options.
mp-wp_genesis 346 $pre = apply_filters( 'pre_option_' . $setting, false );
mp-wp_genesis 347 if ( false !== $pre )
mp-wp_genesis 348 return $pre;
mp-wp_genesis 349
mp-wp_genesis 350 // prevent non-existent options from triggering multiple queries
mp-wp_genesis 351 $notoptions = wp_cache_get( 'notoptions', 'options' );
mp-wp_genesis 352 if ( isset( $notoptions[$setting] ) )
mp-wp_genesis 353 return $default;
mp-wp_genesis 354
mp-wp_genesis 355 $alloptions = wp_load_alloptions();
mp-wp_genesis 356
mp-wp_genesis 357 if ( isset( $alloptions[$setting] ) ) {
mp-wp_genesis 358 $value = $alloptions[$setting];
mp-wp_genesis 359 } else {
mp-wp_genesis 360 $value = wp_cache_get( $setting, 'options' );
mp-wp_genesis 361
mp-wp_genesis 362 if ( false === $value ) {
mp-wp_genesis 363 if ( defined( 'WP_INSTALLING' ) )
mp-wp_genesis 364 $suppress = $wpdb->suppress_errors();
mp-wp_genesis 365 // expected_slashed ($setting)
mp-wp_genesis 366 $row = $wpdb->get_row( "SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1" );
mp-wp_genesis 367 if ( defined( 'WP_INSTALLING' ) )
mp-wp_genesis 368 $wpdb->suppress_errors($suppress);
mp-wp_genesis 369
mp-wp_genesis 370 if ( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
mp-wp_genesis 371 $value = $row->option_value;
mp-wp_genesis 372 wp_cache_add( $setting, $value, 'options' );
mp-wp_genesis 373 } else { // option does not exist, so we must cache its non-existence
mp-wp_genesis 374 $notoptions[$setting] = true;
mp-wp_genesis 375 wp_cache_set( 'notoptions', $notoptions, 'options' );
mp-wp_genesis 376 return $default;
mp-wp_genesis 377 }
mp-wp_genesis 378 }
mp-wp_genesis 379 }
mp-wp_genesis 380
mp-wp_genesis 381 // If home is not set use siteurl.
mp-wp_genesis 382 if ( 'home' == $setting && '' == $value )
mp-wp_genesis 383 return get_option( 'siteurl' );
mp-wp_genesis 384
mp-wp_genesis 385 if ( in_array( $setting, array('siteurl', 'home', 'category_base', 'tag_base') ) )
mp-wp_genesis 386 $value = untrailingslashit( $value );
mp-wp_genesis 387
mp-wp_genesis 388 return apply_filters( 'option_' . $setting, maybe_unserialize( $value ) );
mp-wp_genesis 389 }
mp-wp_genesis 390
mp-wp_genesis 391 /**
mp-wp_genesis 392 * Protect WordPress special option from being modified.
mp-wp_genesis 393 *
mp-wp_genesis 394 * Will die if $option is in protected list. Protected options are 'alloptions'
mp-wp_genesis 395 * and 'notoptions' options.
mp-wp_genesis 396 *
mp-wp_genesis 397 * @since 2.2.0
mp-wp_genesis 398 * @package WordPress
mp-wp_genesis 399 * @subpackage Option
mp-wp_genesis 400 *
mp-wp_genesis 401 * @param string $option Option name.
mp-wp_genesis 402 */
mp-wp_genesis 403 function wp_protect_special_option( $option ) {
mp-wp_genesis 404 $protected = array( 'alloptions', 'notoptions' );
mp-wp_genesis 405 if ( in_array( $option, $protected ) )
mp-wp_genesis 406 die( sprintf( __( '%s is a protected WP option and may not be modified' ), wp_specialchars( $option ) ) );
mp-wp_genesis 407 }
mp-wp_genesis 408
mp-wp_genesis 409 /**
mp-wp_genesis 410 * Print option value after sanitizing for forms.
mp-wp_genesis 411 *
mp-wp_genesis 412 * @uses attribute_escape Sanitizes value.
mp-wp_genesis 413 * @since 1.5.0
mp-wp_genesis 414 * @package WordPress
mp-wp_genesis 415 * @subpackage Option
mp-wp_genesis 416 *
mp-wp_genesis 417 * @param string $option Option name.
mp-wp_genesis 418 */
mp-wp_genesis 419 function form_option( $option ) {
mp-wp_genesis 420 echo attribute_escape (get_option( $option ) );
mp-wp_genesis 421 }
mp-wp_genesis 422
mp-wp_genesis 423 /**
mp-wp_genesis 424 * Retrieve all autoload options or all options, if no autoloaded ones exist.
mp-wp_genesis 425 *
mp-wp_genesis 426 * This is different from wp_load_alloptions() in that this function does not
mp-wp_genesis 427 * cache its results and will retrieve all options from the database every time
mp-wp_genesis 428 *
mp-wp_genesis 429 * it is called.
mp-wp_genesis 430 *
mp-wp_genesis 431 * @since 1.0.0
mp-wp_genesis 432 * @package WordPress
mp-wp_genesis 433 * @subpackage Option
mp-wp_genesis 434 * @uses apply_filters() Calls 'pre_option_$optionname' hook with option value as parameter.
mp-wp_genesis 435 * @uses apply_filters() Calls 'all_options' on options list.
mp-wp_genesis 436 *
mp-wp_genesis 437 * @return array List of all options.
mp-wp_genesis 438 */
mp-wp_genesis 439 function get_alloptions() {
mp-wp_genesis 440 global $wpdb;
mp-wp_genesis 441 $show = $wpdb->hide_errors();
mp-wp_genesis 442 if ( !$options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) )
mp-wp_genesis 443 $options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
mp-wp_genesis 444 $wpdb->show_errors($show);
mp-wp_genesis 445
mp-wp_genesis 446 foreach ( (array) $options as $option ) {
mp-wp_genesis 447 // "When trying to design a foolproof system,
mp-wp_genesis 448 // never underestimate the ingenuity of the fools :)" -- Dougal
mp-wp_genesis 449 if ( in_array( $option->option_name, array( 'siteurl', 'home', 'category_base', 'tag_base' ) ) )
mp-wp_genesis 450 $option->option_value = untrailingslashit( $option->option_value );
mp-wp_genesis 451 $value = maybe_unserialize( $option->option_value );
mp-wp_genesis 452 $all_options->{$option->option_name} = apply_filters( 'pre_option_' . $option->option_name, $value );
mp-wp_genesis 453 }
mp-wp_genesis 454 return apply_filters( 'all_options', $all_options );
mp-wp_genesis 455 }
mp-wp_genesis 456
mp-wp_genesis 457 /**
mp-wp_genesis 458 * Loads and caches all autoloaded options, if available or all options.
mp-wp_genesis 459 *
mp-wp_genesis 460 * This is different from get_alloptions(), in that this function will cache the
mp-wp_genesis 461 * options and will return the cached options when called again.
mp-wp_genesis 462 *
mp-wp_genesis 463 * @since 2.2.0
mp-wp_genesis 464 * @package WordPress
mp-wp_genesis 465 * @subpackage Option
mp-wp_genesis 466 *
mp-wp_genesis 467 * @return array List all options.
mp-wp_genesis 468 */
mp-wp_genesis 469 function wp_load_alloptions() {
mp-wp_genesis 470 global $wpdb;
mp-wp_genesis 471
mp-wp_genesis 472 $alloptions = wp_cache_get( 'alloptions', 'options' );
mp-wp_genesis 473
mp-wp_genesis 474 if ( !$alloptions ) {
mp-wp_genesis 475 $suppress = $wpdb->suppress_errors();
mp-wp_genesis 476 if ( !$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) )
mp-wp_genesis 477 $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
mp-wp_genesis 478 $wpdb->suppress_errors($suppress);
mp-wp_genesis 479 $alloptions = array();
mp-wp_genesis 480 foreach ( (array) $alloptions_db as $o )
mp-wp_genesis 481 $alloptions[$o->option_name] = $o->option_value;
mp-wp_genesis 482 wp_cache_add( 'alloptions', $alloptions, 'options' );
mp-wp_genesis 483 }
mp-wp_genesis 484 return $alloptions;
mp-wp_genesis 485 }
mp-wp_genesis 486
mp-wp_genesis 487 /**
mp-wp_genesis 488 * Update the value of an option that was already added.
mp-wp_genesis 489 *
mp-wp_genesis 490 * You do not need to serialize values, if the value needs to be serialize, then
mp-wp_genesis 491 * it will be serialized before it is inserted into the database. Remember,
mp-wp_genesis 492 * resources can not be serialized or added as an option.
mp-wp_genesis 493 *
mp-wp_genesis 494 * If the option does not exist, then the option will be added with the option
mp-wp_genesis 495 * value, but you will not be able to set whether it is autoloaded. If you want
mp-wp_genesis 496 * to set whether an option autoloaded, then you need to use the add_option().
mp-wp_genesis 497 *
mp-wp_genesis 498 * When the option is updated, then the filter named
mp-wp_genesis 499 * 'update_option_$option_name', with the $option_name as the $option_name
mp-wp_genesis 500 * parameter value, will be called. The hook should accept two parameters, the
mp-wp_genesis 501 * first is the old parameter and the second is the new parameter.
mp-wp_genesis 502 *
mp-wp_genesis 503 * @since 1.0.0
mp-wp_genesis 504 * @package WordPress
mp-wp_genesis 505 * @subpackage Option
mp-wp_genesis 506 *
mp-wp_genesis 507 * @param string $option_name Option name. Expected to not be SQL-escaped
mp-wp_genesis 508 * @param mixed $newvalue Option value.
mp-wp_genesis 509 * @return bool False if value was not updated and true if value was updated.
mp-wp_genesis 510 */
mp-wp_genesis 511 function update_option( $option_name, $newvalue ) {
mp-wp_genesis 512 global $wpdb;
mp-wp_genesis 513
mp-wp_genesis 514 wp_protect_special_option( $option_name );
mp-wp_genesis 515
mp-wp_genesis 516 $safe_option_name = $wpdb->escape( $option_name );
mp-wp_genesis 517 $newvalue = sanitize_option( $option_name, $newvalue );
mp-wp_genesis 518
mp-wp_genesis 519 $oldvalue = get_option( $safe_option_name );
mp-wp_genesis 520
mp-wp_genesis 521 $newvalue = apply_filters( 'pre_update_option_' . $option_name, $newvalue, $oldvalue );
mp-wp_genesis 522
mp-wp_genesis 523 // If the new and old values are the same, no need to update.
mp-wp_genesis 524 if ( $newvalue === $oldvalue )
mp-wp_genesis 525 return false;
mp-wp_genesis 526
mp-wp_genesis 527 if ( false === $oldvalue ) {
mp-wp_genesis 528 add_option( $option_name, $newvalue );
mp-wp_genesis 529 return true;
mp-wp_genesis 530 }
mp-wp_genesis 531
mp-wp_genesis 532 $notoptions = wp_cache_get( 'notoptions', 'options' );
mp-wp_genesis 533 if ( is_array( $notoptions ) && isset( $notoptions[$option_name] ) ) {
mp-wp_genesis 534 unset( $notoptions[$option_name] );
mp-wp_genesis 535 wp_cache_set( 'notoptions', $notoptions, 'options' );
mp-wp_genesis 536 }
mp-wp_genesis 537
mp-wp_genesis 538 $_newvalue = $newvalue;
mp-wp_genesis 539 $newvalue = maybe_serialize( $newvalue );
mp-wp_genesis 540
mp-wp_genesis 541 $alloptions = wp_load_alloptions();
mp-wp_genesis 542 if ( isset( $alloptions[$option_name] ) ) {
mp-wp_genesis 543 $alloptions[$option_name] = $newvalue;
mp-wp_genesis 544 wp_cache_set( 'alloptions', $alloptions, 'options' );
mp-wp_genesis 545 } else {
mp-wp_genesis 546 wp_cache_set( $option_name, $newvalue, 'options' );
mp-wp_genesis 547 }
mp-wp_genesis 548
mp-wp_genesis 549 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s", $newvalue, $option_name ) );
mp-wp_genesis 550 if ( $wpdb->rows_affected == 1 ) {
mp-wp_genesis 551 do_action( "update_option_{$option_name}", $oldvalue, $_newvalue );
mp-wp_genesis 552 return true;
mp-wp_genesis 553 }
mp-wp_genesis 554 return false;
mp-wp_genesis 555 }
mp-wp_genesis 556
mp-wp_genesis 557 /**
mp-wp_genesis 558 * Add a new option.
mp-wp_genesis 559 *
mp-wp_genesis 560 * You do not need to serialize values, if the value needs to be serialize, then
mp-wp_genesis 561 * it will be serialized before it is inserted into the database. Remember,
mp-wp_genesis 562 * resources can not be serialized or added as an option.
mp-wp_genesis 563 *
mp-wp_genesis 564 * You can create options without values and then add values later. Does not
mp-wp_genesis 565 * check whether the option has already been added, but does check that you
mp-wp_genesis 566 * aren't adding a protected WordPress option. Care should be taken to not name
mp-wp_genesis 567 * options, the same as the ones which are protected and to not add options
mp-wp_genesis 568 * that were already added.
mp-wp_genesis 569 *
mp-wp_genesis 570 * The filter named 'add_option_$optionname', with the $optionname being
mp-wp_genesis 571 * replaced with the option's name, will be called. The hook should accept two
mp-wp_genesis 572 * parameters, the first is the option name, and the second is the value.
mp-wp_genesis 573 *
mp-wp_genesis 574 * @package WordPress
mp-wp_genesis 575 * @subpackage Option
mp-wp_genesis 576 * @since 1.0.0
mp-wp_genesis 577 * @link http://alex.vort-x.net/blog/ Thanks Alex Stapleton
mp-wp_genesis 578 *
mp-wp_genesis 579 * @param string $name Option name to add. Expects to NOT be SQL escaped.
mp-wp_genesis 580 * @param mixed $value Optional. Option value, can be anything.
mp-wp_genesis 581 * @param mixed $deprecated Optional. Description. Not used anymore.
mp-wp_genesis 582 * @param bool $autoload Optional. Default is enabled. Whether to load the option when WordPress starts up.
mp-wp_genesis 583 * @return null returns when finished.
mp-wp_genesis 584 */
mp-wp_genesis 585 function add_option( $name, $value = '', $deprecated = '', $autoload = 'yes' ) {
mp-wp_genesis 586 global $wpdb;
mp-wp_genesis 587
mp-wp_genesis 588 wp_protect_special_option( $name );
mp-wp_genesis 589 $safe_name = $wpdb->escape( $name );
mp-wp_genesis 590 $value = sanitize_option( $name, $value );
mp-wp_genesis 591
mp-wp_genesis 592 // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
mp-wp_genesis 593 $notoptions = wp_cache_get( 'notoptions', 'options' );
mp-wp_genesis 594 if ( !is_array( $notoptions ) || !isset( $notoptions[$name] ) )
mp-wp_genesis 595 if ( false !== get_option( $safe_name ) )
mp-wp_genesis 596 return;
mp-wp_genesis 597
mp-wp_genesis 598 $value = maybe_serialize( $value );
mp-wp_genesis 599 $autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
mp-wp_genesis 600
mp-wp_genesis 601 if ( 'yes' == $autoload ) {
mp-wp_genesis 602 $alloptions = wp_load_alloptions();
mp-wp_genesis 603 $alloptions[$name] = $value;
mp-wp_genesis 604 wp_cache_set( 'alloptions', $alloptions, 'options' );
mp-wp_genesis 605 } else {
mp-wp_genesis 606 wp_cache_set( $name, $value, 'options' );
mp-wp_genesis 607 }
mp-wp_genesis 608
mp-wp_genesis 609 // This option exists now
mp-wp_genesis 610 $notoptions = wp_cache_get( 'notoptions', 'options' ); // yes, again... we need it to be fresh
mp-wp_genesis 611 if ( is_array( $notoptions ) && isset( $notoptions[$name] ) ) {
mp-wp_genesis 612 unset( $notoptions[$name] );
mp-wp_genesis 613 wp_cache_set( 'notoptions', $notoptions, 'options' );
mp-wp_genesis 614 }
mp-wp_genesis 615
mp-wp_genesis 616 $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES (%s, %s, %s)", $name, $value, $autoload ) );
mp-wp_genesis 617
mp-wp_genesis 618 do_action( "add_option_{$name}", $name, $value );
mp-wp_genesis 619 return;
mp-wp_genesis 620 }
mp-wp_genesis 621
mp-wp_genesis 622 /**
mp-wp_genesis 623 * Removes option by name and prevents removal of protected WordPress options.
mp-wp_genesis 624 *
mp-wp_genesis 625 * @package WordPress
mp-wp_genesis 626 * @subpackage Option
mp-wp_genesis 627 * @since 1.2.0
mp-wp_genesis 628 *
mp-wp_genesis 629 * @param string $name Option name to remove.
mp-wp_genesis 630 * @return bool True, if succeed. False, if failure.
mp-wp_genesis 631 */
mp-wp_genesis 632 function delete_option( $name ) {
mp-wp_genesis 633 global $wpdb;
mp-wp_genesis 634
mp-wp_genesis 635 wp_protect_special_option( $name );
mp-wp_genesis 636
mp-wp_genesis 637 // Get the ID, if no ID then return
mp-wp_genesis 638 // expected_slashed ($name)
mp-wp_genesis 639 $option = $wpdb->get_row( "SELECT option_id, autoload FROM $wpdb->options WHERE option_name = '$name'" );
mp-wp_genesis 640 if ( is_null($option) || !$option->option_id )
mp-wp_genesis 641 return false;
mp-wp_genesis 642 // expected_slashed ($name)
mp-wp_genesis 643 $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" );
mp-wp_genesis 644 if ( 'yes' == $option->autoload ) {
mp-wp_genesis 645 $alloptions = wp_load_alloptions();
mp-wp_genesis 646 if ( isset( $alloptions[$name] ) ) {
mp-wp_genesis 647 unset( $alloptions[$name] );
mp-wp_genesis 648 wp_cache_set( 'alloptions', $alloptions, 'options' );
mp-wp_genesis 649 }
mp-wp_genesis 650 } else {
mp-wp_genesis 651 wp_cache_delete( $name, 'options' );
mp-wp_genesis 652 }
mp-wp_genesis 653 return true;
mp-wp_genesis 654 }
mp-wp_genesis 655
mp-wp_genesis 656 /**
mp-wp_genesis 657 * Saves and restores user interface settings stored in a cookie.
mp-wp_genesis 658 *
mp-wp_genesis 659 * Checks if the current user-settings cookie is updated and stores it. When no
mp-wp_genesis 660 * cookie exists (different browser used), adds the last saved cookie restoring
mp-wp_genesis 661 * the settings.
mp-wp_genesis 662 *
mp-wp_genesis 663 * @package WordPress
mp-wp_genesis 664 * @subpackage Option
mp-wp_genesis 665 * @since 2.7.0
mp-wp_genesis 666 */
mp-wp_genesis 667 function wp_user_settings() {
mp-wp_genesis 668
mp-wp_genesis 669 if ( ! is_admin() )
mp-wp_genesis 670 return;
mp-wp_genesis 671
mp-wp_genesis 672 if ( defined('DOING_AJAX') )
mp-wp_genesis 673 return;
mp-wp_genesis 674
mp-wp_genesis 675 if ( ! $user = wp_get_current_user() )
mp-wp_genesis 676 return;
mp-wp_genesis 677
mp-wp_genesis 678 $settings = get_user_option( 'user-settings', $user->ID, false );
mp-wp_genesis 679
mp-wp_genesis 680 if ( isset( $_COOKIE['wp-settings-' . $user->ID] ) ) {
mp-wp_genesis 681 $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user->ID] );
mp-wp_genesis 682
mp-wp_genesis 683 if ( ! empty( $cookie ) && strpos( $cookie, '=' ) ) {
mp-wp_genesis 684 if ( $cookie == $settings )
mp-wp_genesis 685 return;
mp-wp_genesis 686
mp-wp_genesis 687 $last_time = (int) get_user_option( 'user-settings-time', $user->ID, false );
mp-wp_genesis 688 $saved = isset( $_COOKIE['wp-settings-time-' . $user->ID]) ? preg_replace( '/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user->ID] ) : 0;
mp-wp_genesis 689
mp-wp_genesis 690 if ( $saved > $last_time ) {
mp-wp_genesis 691 update_user_option( $user->ID, 'user-settings', $cookie, false );
mp-wp_genesis 692 update_user_option( $user->ID, 'user-settings-time', time() - 5, false );
mp-wp_genesis 693 return;
mp-wp_genesis 694 }
mp-wp_genesis 695 }
mp-wp_genesis 696 }
mp-wp_genesis 697
mp-wp_genesis 698 setcookie( 'wp-settings-' . $user->ID, $settings, time() + 31536000, SITECOOKIEPATH );
mp-wp_genesis 699 setcookie( 'wp-settings-time-' . $user->ID, time(), time() + 31536000, SITECOOKIEPATH );
mp-wp_genesis 700 }
mp-wp_genesis 701
mp-wp_genesis 702 /**
mp-wp_genesis 703 * Retrieve user interface setting value based on setting name.
mp-wp_genesis 704 *
mp-wp_genesis 705 * @package WordPress
mp-wp_genesis 706 * @subpackage Option
mp-wp_genesis 707 * @since 2.7.0
mp-wp_genesis 708 *
mp-wp_genesis 709 * @param string $name The name of the setting.
mp-wp_genesis 710 * @param string $default Optional default value to return when $name is not set.
mp-wp_genesis 711 * @return mixed the last saved user setting or the default value/false if it doesn't exist.
mp-wp_genesis 712 */
mp-wp_genesis 713 function get_user_setting( $name, $default = false ) {
mp-wp_genesis 714
mp-wp_genesis 715 $arr = get_all_user_settings();
mp-wp_genesis 716
mp-wp_genesis 717 return isset($arr[$name]) ? $arr[$name] : $default;
mp-wp_genesis 718 }
mp-wp_genesis 719
mp-wp_genesis 720 /**
mp-wp_genesis 721 * Delete user interface settings.
mp-wp_genesis 722 *
mp-wp_genesis 723 * Deleting settings would reset them to the defaults.
mp-wp_genesis 724 *
mp-wp_genesis 725 * @package WordPress
mp-wp_genesis 726 * @subpackage Option
mp-wp_genesis 727 * @since 2.7.0
mp-wp_genesis 728 *
mp-wp_genesis 729 * @param mixed $names The name or array of names of the setting to be deleted.
mp-wp_genesis 730 */
mp-wp_genesis 731 function delete_user_setting( $names ) {
mp-wp_genesis 732 global $current_user;
mp-wp_genesis 733
mp-wp_genesis 734 $arr = get_all_user_settings();
mp-wp_genesis 735 $names = (array) $names;
mp-wp_genesis 736
mp-wp_genesis 737 foreach ( $names as $name ) {
mp-wp_genesis 738 if ( isset($arr[$name]) ) {
mp-wp_genesis 739 unset($arr[$name]);
mp-wp_genesis 740 $settings = '';
mp-wp_genesis 741 }
mp-wp_genesis 742 }
mp-wp_genesis 743
mp-wp_genesis 744 if ( isset($settings) ) {
mp-wp_genesis 745 foreach ( $arr as $k => $v )
mp-wp_genesis 746 $settings .= $k . '=' . $v . '&';
mp-wp_genesis 747
mp-wp_genesis 748 $settings = rtrim($settings, '&');
mp-wp_genesis 749
mp-wp_genesis 750 update_user_option( $current_user->ID, 'user-settings', $settings );
mp-wp_genesis 751 setcookie('wp-settings-'.$current_user->ID, $settings, time() + 31536000, SITECOOKIEPATH);
mp-wp_genesis 752 }
mp-wp_genesis 753 }
mp-wp_genesis 754
mp-wp_genesis 755 /**
mp-wp_genesis 756 * Retrieve all user interface settings.
mp-wp_genesis 757 *
mp-wp_genesis 758 * @package WordPress
mp-wp_genesis 759 * @subpackage Option
mp-wp_genesis 760 * @since 2.7.0
mp-wp_genesis 761 *
mp-wp_genesis 762 * @return array the last saved user settings or empty array.
mp-wp_genesis 763 */
mp-wp_genesis 764 function get_all_user_settings() {
mp-wp_genesis 765 if ( ! $user = wp_get_current_user() )
mp-wp_genesis 766 return array();
mp-wp_genesis 767
mp-wp_genesis 768 if ( isset($_COOKIE['wp-settings-'.$user->ID]) ) {
mp-wp_genesis 769 $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-'.$user->ID] );
mp-wp_genesis 770
mp-wp_genesis 771 if ( $cookie && strpos($cookie, '=') ) { // the '=' cannot be 1st char
mp-wp_genesis 772 parse_str($cookie, $arr);
mp-wp_genesis 773 return $arr;
mp-wp_genesis 774 }
mp-wp_genesis 775 }
mp-wp_genesis 776
mp-wp_genesis 777 return array();
mp-wp_genesis 778 }
mp-wp_genesis 779
mp-wp_genesis 780 /**
mp-wp_genesis 781 * Delete the user settings of the current user.
mp-wp_genesis 782 *
mp-wp_genesis 783 * @package WordPress
mp-wp_genesis 784 * @subpackage Option
mp-wp_genesis 785 * @since 2.7.0
mp-wp_genesis 786 */
mp-wp_genesis 787 function delete_all_user_settings() {
mp-wp_genesis 788 if ( ! $user = wp_get_current_user() )
mp-wp_genesis 789 return;
mp-wp_genesis 790
mp-wp_genesis 791 delete_usermeta( $user->ID, 'user-settings' );
mp-wp_genesis 792 setcookie('wp-settings-'.$user->ID, ' ', time() - 31536000, SITECOOKIEPATH);
mp-wp_genesis 793 }
mp-wp_genesis 794
mp-wp_genesis 795 /**
mp-wp_genesis 796 * Serialize data, if needed.
mp-wp_genesis 797 *
mp-wp_genesis 798 * @since 2.0.5
mp-wp_genesis 799 *
mp-wp_genesis 800 * @param mixed $data Data that might be serialized.
mp-wp_genesis 801 * @return mixed A scalar data
mp-wp_genesis 802 */
mp-wp_genesis 803 function maybe_serialize( $data ) {
mp-wp_genesis 804 if ( is_array( $data ) || is_object( $data ) )
mp-wp_genesis 805 return serialize( $data );
mp-wp_genesis 806
mp-wp_genesis 807 if ( is_serialized( $data ) )
mp-wp_genesis 808 return serialize( $data );
mp-wp_genesis 809
mp-wp_genesis 810 return $data;
mp-wp_genesis 811 }
mp-wp_genesis 812
mp-wp_genesis 813 /**
mp-wp_genesis 814 * Strip HTML and put links at the bottom of stripped content.
mp-wp_genesis 815 *
mp-wp_genesis 816 * Searches for all of the links, strips them out of the content, and places
mp-wp_genesis 817 * them at the bottom of the content with numbers.
mp-wp_genesis 818 *
mp-wp_genesis 819 * @since 0.71
mp-wp_genesis 820 *
mp-wp_genesis 821 * @param string $content Content to get links
mp-wp_genesis 822 * @return string HTML stripped out of content with links at the bottom.
mp-wp_genesis 823 */
mp-wp_genesis 824 function make_url_footnote( $content ) {
mp-wp_genesis 825 preg_match_all( '/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches );
mp-wp_genesis 826 $links_summary = "\n";
mp-wp_genesis 827 for ( $i=0; $i<count($matches[0]); $i++ ) {
mp-wp_genesis 828 $link_match = $matches[0][$i];
mp-wp_genesis 829 $link_number = '['.($i+1).']';
mp-wp_genesis 830 $link_url = $matches[2][$i];
mp-wp_genesis 831 $link_text = $matches[4][$i];
mp-wp_genesis 832 $content = str_replace( $link_match, $link_text . ' ' . $link_number, $content );
mp-wp_genesis 833 $link_url = ( ( strtolower( substr( $link_url, 0, 7 ) ) != 'http://' ) && ( strtolower( substr( $link_url, 0, 8 ) ) != 'https://' ) ) ? get_option( 'home' ) . $link_url : $link_url;
mp-wp_genesis 834 $links_summary .= "\n" . $link_number . ' ' . $link_url;
mp-wp_genesis 835 }
mp-wp_genesis 836 $content = strip_tags( $content );
mp-wp_genesis 837 $content .= $links_summary;
mp-wp_genesis 838 return $content;
mp-wp_genesis 839 }
mp-wp_genesis 840
mp-wp_genesis 841 /**
mp-wp_genesis 842 * Retrieve post title from XMLRPC XML.
mp-wp_genesis 843 *
mp-wp_genesis 844 * If the title element is not part of the XML, then the default post title from
mp-wp_genesis 845 * the $post_default_title will be used instead.
mp-wp_genesis 846 *
mp-wp_genesis 847 * @package WordPress
mp-wp_genesis 848 * @subpackage XMLRPC
mp-wp_genesis 849 * @since 0.71
mp-wp_genesis 850 *
mp-wp_genesis 851 * @global string $post_default_title Default XMLRPC post title.
mp-wp_genesis 852 *
mp-wp_genesis 853 * @param string $content XMLRPC XML Request content
mp-wp_genesis 854 * @return string Post title
mp-wp_genesis 855 */
mp-wp_genesis 856 function xmlrpc_getposttitle( $content ) {
mp-wp_genesis 857 global $post_default_title;
mp-wp_genesis 858 if ( preg_match( '/<title>(.+?)<\/title>/is', $content, $matchtitle ) ) {
mp-wp_genesis 859 $post_title = $matchtitle[0];
mp-wp_genesis 860 $post_title = preg_replace( '/<title>/si', '', $post_title );
mp-wp_genesis 861 $post_title = preg_replace( '/<\/title>/si', '', $post_title );
mp-wp_genesis 862 } else {
mp-wp_genesis 863 $post_title = $post_default_title;
mp-wp_genesis 864 }
mp-wp_genesis 865 return $post_title;
mp-wp_genesis 866 }
mp-wp_genesis 867
mp-wp_genesis 868 /**
mp-wp_genesis 869 * Retrieve the post category or categories from XMLRPC XML.
mp-wp_genesis 870 *
mp-wp_genesis 871 * If the category element is not found, then the default post category will be
mp-wp_genesis 872 * used. The return type then would be what $post_default_category. If the
mp-wp_genesis 873 * category is found, then it will always be an array.
mp-wp_genesis 874 *
mp-wp_genesis 875 * @package WordPress
mp-wp_genesis 876 * @subpackage XMLRPC
mp-wp_genesis 877 * @since 0.71
mp-wp_genesis 878 *
mp-wp_genesis 879 * @global string $post_default_category Default XMLRPC post category.
mp-wp_genesis 880 *
mp-wp_genesis 881 * @param string $content XMLRPC XML Request content
mp-wp_genesis 882 * @return string|array List of categories or category name.
mp-wp_genesis 883 */
mp-wp_genesis 884 function xmlrpc_getpostcategory( $content ) {
mp-wp_genesis 885 global $post_default_category;
mp-wp_genesis 886 if ( preg_match( '/<category>(.+?)<\/category>/is', $content, $matchcat ) ) {
mp-wp_genesis 887 $post_category = trim( $matchcat[1], ',' );
mp-wp_genesis 888 $post_category = explode( ',', $post_category );
mp-wp_genesis 889 } else {
mp-wp_genesis 890 $post_category = $post_default_category;
mp-wp_genesis 891 }
mp-wp_genesis 892 return $post_category;
mp-wp_genesis 893 }
mp-wp_genesis 894
mp-wp_genesis 895 /**
mp-wp_genesis 896 * XMLRPC XML content without title and category elements.
mp-wp_genesis 897 *
mp-wp_genesis 898 * @package WordPress
mp-wp_genesis 899 * @subpackage XMLRPC
mp-wp_genesis 900 * @since 0.71
mp-wp_genesis 901 *
mp-wp_genesis 902 * @param string $content XMLRPC XML Request content
mp-wp_genesis 903 * @return string XMLRPC XML Request content without title and category elements.
mp-wp_genesis 904 */
mp-wp_genesis 905 function xmlrpc_removepostdata( $content ) {
mp-wp_genesis 906 $content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content );
mp-wp_genesis 907 $content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content );
mp-wp_genesis 908 $content = trim( $content );
mp-wp_genesis 909 return $content;
mp-wp_genesis 910 }
mp-wp_genesis 911
mp-wp_genesis 912 /**
mp-wp_genesis 913 * Open the file handle for debugging.
mp-wp_genesis 914 *
mp-wp_genesis 915 * This function is used for XMLRPC feature, but it is general purpose enough
mp-wp_genesis 916 * to be used in anywhere.
mp-wp_genesis 917 *
mp-wp_genesis 918 * @see fopen() for mode options.
mp-wp_genesis 919 * @package WordPress
mp-wp_genesis 920 * @subpackage Debug
mp-wp_genesis 921 * @since 0.71
mp-wp_genesis 922 * @uses $debug Used for whether debugging is enabled.
mp-wp_genesis 923 *
mp-wp_genesis 924 * @param string $filename File path to debug file.
mp-wp_genesis 925 * @param string $mode Same as fopen() mode parameter.
mp-wp_genesis 926 * @return bool|resource File handle. False on failure.
mp-wp_genesis 927 */
mp-wp_genesis 928 function debug_fopen( $filename, $mode ) {
mp-wp_genesis 929 global $debug;
mp-wp_genesis 930 if ( 1 == $debug ) {
mp-wp_genesis 931 $fp = fopen( $filename, $mode );
mp-wp_genesis 932 return $fp;
mp-wp_genesis 933 } else {
mp-wp_genesis 934 return false;
mp-wp_genesis 935 }
mp-wp_genesis 936 }
mp-wp_genesis 937
mp-wp_genesis 938 /**
mp-wp_genesis 939 * Write contents to the file used for debugging.
mp-wp_genesis 940 *
mp-wp_genesis 941 * Technically, this can be used to write to any file handle when the global
mp-wp_genesis 942 * $debug is set to 1 or true.
mp-wp_genesis 943 *
mp-wp_genesis 944 * @package WordPress
mp-wp_genesis 945 * @subpackage Debug
mp-wp_genesis 946 * @since 0.71
mp-wp_genesis 947 * @uses $debug Used for whether debugging is enabled.
mp-wp_genesis 948 *
mp-wp_genesis 949 * @param resource $fp File handle for debugging file.
mp-wp_genesis 950 * @param string $string Content to write to debug file.
mp-wp_genesis 951 */
mp-wp_genesis 952 function debug_fwrite( $fp, $string ) {
mp-wp_genesis 953 global $debug;
mp-wp_genesis 954 if ( 1 == $debug )
mp-wp_genesis 955 fwrite( $fp, $string );
mp-wp_genesis 956 }
mp-wp_genesis 957
mp-wp_genesis 958 /**
mp-wp_genesis 959 * Close the debugging file handle.
mp-wp_genesis 960 *
mp-wp_genesis 961 * Technically, this can be used to close any file handle when the global $debug
mp-wp_genesis 962 * is set to 1 or true.
mp-wp_genesis 963 *
mp-wp_genesis 964 * @package WordPress
mp-wp_genesis 965 * @subpackage Debug
mp-wp_genesis 966 * @since 0.71
mp-wp_genesis 967 * @uses $debug Used for whether debugging is enabled.
mp-wp_genesis 968 *
mp-wp_genesis 969 * @param resource $fp Debug File handle.
mp-wp_genesis 970 */
mp-wp_genesis 971 function debug_fclose( $fp ) {
mp-wp_genesis 972 global $debug;
mp-wp_genesis 973 if ( 1 == $debug )
mp-wp_genesis 974 fclose( $fp );
mp-wp_genesis 975 }
mp-wp_genesis 976
mp-wp_genesis 977 /**
mp-wp_genesis 978 * Check content for video and audio links to add as enclosures.
mp-wp_genesis 979 *
mp-wp_genesis 980 * Will not add enclosures that have already been added. This is called as
mp-wp_genesis 981 * pingbacks and trackbacks.
mp-wp_genesis 982 *
mp-wp_genesis 983 * @package WordPress
mp-wp_genesis 984 * @since 1.5.0
mp-wp_genesis 985 *
mp-wp_genesis 986 * @uses $wpdb
mp-wp_genesis 987 *
mp-wp_genesis 988 * @param string $content Post Content
mp-wp_genesis 989 * @param int $post_ID Post ID
mp-wp_genesis 990 */
mp-wp_genesis 991 function do_enclose( $content, $post_ID ) {
mp-wp_genesis 992 global $wpdb;
mp-wp_genesis 993 include_once( ABSPATH . WPINC . '/class-IXR.php' );
mp-wp_genesis 994
mp-wp_genesis 995 $log = debug_fopen( ABSPATH . 'enclosures.log', 'a' );
mp-wp_genesis 996 $post_links = array();
mp-wp_genesis 997 debug_fwrite( $log, 'BEGIN ' . date( 'YmdHis', time() ) . "\n" );
mp-wp_genesis 998
mp-wp_genesis 999 $pung = get_enclosed( $post_ID );
mp-wp_genesis 1000
mp-wp_genesis 1001 $ltrs = '\w';
mp-wp_genesis 1002 $gunk = '/#~:.?+=&%@!\-';
mp-wp_genesis 1003 $punc = '.:?\-';
mp-wp_genesis 1004 $any = $ltrs . $gunk . $punc;
mp-wp_genesis 1005
mp-wp_genesis 1006 preg_match_all( "{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp );
mp-wp_genesis 1007
mp-wp_genesis 1008 debug_fwrite( $log, 'Post contents:' );
mp-wp_genesis 1009 debug_fwrite( $log, $content . "\n" );
mp-wp_genesis 1010
mp-wp_genesis 1011 foreach ( (array) $post_links_temp[0] as $link_test ) {
mp-wp_genesis 1012 if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already
mp-wp_genesis 1013 $test = parse_url( $link_test );
mp-wp_genesis 1014 if ( isset( $test['query'] ) )
mp-wp_genesis 1015 $post_links[] = $link_test;
mp-wp_genesis 1016 elseif ( $test['path'] != '/' && $test['path'] != '' )
mp-wp_genesis 1017 $post_links[] = $link_test;
mp-wp_genesis 1018 }
mp-wp_genesis 1019 }
mp-wp_genesis 1020
mp-wp_genesis 1021 foreach ( (array) $post_links as $url ) {
mp-wp_genesis 1022 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 . '%' ) ) ) {
mp-wp_genesis 1023 if ( $headers = wp_get_http_headers( $url) ) {
mp-wp_genesis 1024 $len = (int) $headers['content-length'];
mp-wp_genesis 1025 $type = $wpdb->escape( $headers['content-type'] );
mp-wp_genesis 1026 $allowed_types = array( 'video', 'audio' );
mp-wp_genesis 1027 if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
mp-wp_genesis 1028 $meta_value = "$url\n$len\n$type\n";
mp-wp_genesis 1029 $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->postmeta` ( `post_id` , `meta_key` , `meta_value` )
mp-wp_genesis 1030 VALUES ( %d, 'enclosure' , %s)", $post_ID, $meta_value ) );
mp-wp_genesis 1031 }
mp-wp_genesis 1032 }
mp-wp_genesis 1033 }
mp-wp_genesis 1034 }
mp-wp_genesis 1035 }
mp-wp_genesis 1036
mp-wp_genesis 1037 /**
mp-wp_genesis 1038 * Perform a HTTP HEAD or GET request.
mp-wp_genesis 1039 *
mp-wp_genesis 1040 * If $file_path is a writable filename, this will do a GET request and write
mp-wp_genesis 1041 * the file to that path.
mp-wp_genesis 1042 *
mp-wp_genesis 1043 * @since 2.5.0
mp-wp_genesis 1044 *
mp-wp_genesis 1045 * @param string $url URL to fetch.
mp-wp_genesis 1046 * @param string|bool $file_path Optional. File path to write request to.
mp-wp_genesis 1047 * @param bool $deprecated Deprecated. Not used.
mp-wp_genesis 1048 * @return bool|string False on failure and string of headers if HEAD request.
mp-wp_genesis 1049 */
mp-wp_genesis 1050 function wp_get_http( $url, $file_path = false, $deprecated = false ) {
mp-wp_genesis 1051 @set_time_limit( 60 );
mp-wp_genesis 1052
mp-wp_genesis 1053 $options = array();
mp-wp_genesis 1054 $options['redirection'] = 5;
mp-wp_genesis 1055
mp-wp_genesis 1056 if ( false == $file_path )
mp-wp_genesis 1057 $options['method'] = 'HEAD';
mp-wp_genesis 1058 else
mp-wp_genesis 1059 $options['method'] = 'GET';
mp-wp_genesis 1060
mp-wp_genesis 1061 $response = wp_remote_request($url, $options);
mp-wp_genesis 1062
mp-wp_genesis 1063 if ( is_wp_error( $response ) )
mp-wp_genesis 1064 return false;
mp-wp_genesis 1065
mp-wp_genesis 1066 $headers = wp_remote_retrieve_headers( $response );
mp-wp_genesis 1067 $headers['response'] = $response['response']['code'];
mp-wp_genesis 1068
mp-wp_genesis 1069 if ( false == $file_path )
mp-wp_genesis 1070 return $headers;
mp-wp_genesis 1071
mp-wp_genesis 1072 // GET request - write it to the supplied filename
mp-wp_genesis 1073 $out_fp = fopen($file_path, 'w');
mp-wp_genesis 1074 if ( !$out_fp )
mp-wp_genesis 1075 return $headers;
mp-wp_genesis 1076
mp-wp_genesis 1077 fwrite( $out_fp, $response['body']);
mp-wp_genesis 1078 fclose($out_fp);
mp-wp_genesis 1079
mp-wp_genesis 1080 return $headers;
mp-wp_genesis 1081 }
mp-wp_genesis 1082
mp-wp_genesis 1083 /**
mp-wp_genesis 1084 * Retrieve HTTP Headers from URL.
mp-wp_genesis 1085 *
mp-wp_genesis 1086 * @since 1.5.1
mp-wp_genesis 1087 *
mp-wp_genesis 1088 * @param string $url
mp-wp_genesis 1089 * @param bool $deprecated Not Used.
mp-wp_genesis 1090 * @return bool|string False on failure, headers on success.
mp-wp_genesis 1091 */
mp-wp_genesis 1092 function wp_get_http_headers( $url, $deprecated = false ) {
mp-wp_genesis 1093 $response = wp_remote_head( $url );
mp-wp_genesis 1094
mp-wp_genesis 1095 if ( is_wp_error( $response ) )
mp-wp_genesis 1096 return false;
mp-wp_genesis 1097
mp-wp_genesis 1098 return wp_remote_retrieve_headers( $response );
mp-wp_genesis 1099 }
mp-wp_genesis 1100
mp-wp_genesis 1101 /**
mp-wp_genesis 1102 * Whether today is a new day.
mp-wp_genesis 1103 *
mp-wp_genesis 1104 * @since 0.71
mp-wp_genesis 1105 * @uses $day Today
mp-wp_genesis 1106 * @uses $previousday Previous day
mp-wp_genesis 1107 *
mp-wp_genesis 1108 * @return int 1 when new day, 0 if not a new day.
mp-wp_genesis 1109 */
mp-wp_genesis 1110 function is_new_day() {
mp-wp_genesis 1111 global $day, $previousday;
mp-wp_genesis 1112 if ( $day != $previousday )
mp-wp_genesis 1113 return 1;
mp-wp_genesis 1114 else
mp-wp_genesis 1115 return 0;
mp-wp_genesis 1116 }
mp-wp_genesis 1117
mp-wp_genesis 1118 /**
mp-wp_genesis 1119 * Build URL query based on an associative and, or indexed array.
mp-wp_genesis 1120 *
mp-wp_genesis 1121 * This is a convenient function for easily building url queries. It sets the
mp-wp_genesis 1122 * separator to '&' and uses _http_build_query() function.
mp-wp_genesis 1123 *
mp-wp_genesis 1124 * @see _http_build_query() Used to build the query
mp-wp_genesis 1125 * @link http://us2.php.net/manual/en/function.http-build-query.php more on what
mp-wp_genesis 1126 * http_build_query() does.
mp-wp_genesis 1127 *
mp-wp_genesis 1128 * @since 2.3.0
mp-wp_genesis 1129 *
mp-wp_genesis 1130 * @param array $data URL-encode key/value pairs.
mp-wp_genesis 1131 * @return string URL encoded string
mp-wp_genesis 1132 */
mp-wp_genesis 1133 function build_query( $data ) {
mp-wp_genesis 1134 return _http_build_query( $data, null, '&', '', false );
mp-wp_genesis 1135 }
mp-wp_genesis 1136
mp-wp_genesis 1137 /**
mp-wp_genesis 1138 * Retrieve a modified URL query string.
mp-wp_genesis 1139 *
mp-wp_genesis 1140 * You can rebuild the URL and append a new query variable to the URL query by
mp-wp_genesis 1141 * using this function. You can also retrieve the full URL with query data.
mp-wp_genesis 1142 *
mp-wp_genesis 1143 * Adding a single key & value or an associative array. Setting a key value to
mp-wp_genesis 1144 * emptystring removes the key. Omitting oldquery_or_uri uses the $_SERVER
mp-wp_genesis 1145 * value.
mp-wp_genesis 1146 *
mp-wp_genesis 1147 * @since 1.5.0
mp-wp_genesis 1148 *
mp-wp_genesis 1149 * @param mixed $param1 Either newkey or an associative_array
mp-wp_genesis 1150 * @param mixed $param2 Either newvalue or oldquery or uri
mp-wp_genesis 1151 * @param mixed $param3 Optional. Old query or uri
mp-wp_genesis 1152 * @return string New URL query string.
mp-wp_genesis 1153 */
mp-wp_genesis 1154 function add_query_arg() {
mp-wp_genesis 1155 $ret = '';
mp-wp_genesis 1156 if ( is_array( func_get_arg(0) ) ) {
mp-wp_genesis 1157 if ( @func_num_args() < 2 || false === @func_get_arg( 1 ) )
mp-wp_genesis 1158 $uri = $_SERVER['REQUEST_URI'];
mp-wp_genesis 1159 else
mp-wp_genesis 1160 $uri = @func_get_arg( 1 );
mp-wp_genesis 1161 } else {
mp-wp_genesis 1162 if ( @func_num_args() < 3 || false === @func_get_arg( 2 ) )
mp-wp_genesis 1163 $uri = $_SERVER['REQUEST_URI'];
mp-wp_genesis 1164 else
mp-wp_genesis 1165 $uri = @func_get_arg( 2 );
mp-wp_genesis 1166 }
mp-wp_genesis 1167
mp-wp_genesis 1168 if ( $frag = strstr( $uri, '#' ) )
mp-wp_genesis 1169 $uri = substr( $uri, 0, -strlen( $frag ) );
mp-wp_genesis 1170 else
mp-wp_genesis 1171 $frag = '';
mp-wp_genesis 1172
mp-wp_genesis 1173 if ( preg_match( '|^https?://|i', $uri, $matches ) ) {
mp-wp_genesis 1174 $protocol = $matches[0];
mp-wp_genesis 1175 $uri = substr( $uri, strlen( $protocol ) );
mp-wp_genesis 1176 } else {
mp-wp_genesis 1177 $protocol = '';
mp-wp_genesis 1178 }
mp-wp_genesis 1179
mp-wp_genesis 1180 if ( strpos( $uri, '?' ) !== false ) {
mp-wp_genesis 1181 $parts = explode( '?', $uri, 2 );
mp-wp_genesis 1182 if ( 1 == count( $parts ) ) {
mp-wp_genesis 1183 $base = '?';
mp-wp_genesis 1184 $query = $parts[0];
mp-wp_genesis 1185 } else {
mp-wp_genesis 1186 $base = $parts[0] . '?';
mp-wp_genesis 1187 $query = $parts[1];
mp-wp_genesis 1188 }
mp-wp_genesis 1189 } elseif ( !empty( $protocol ) || strpos( $uri, '=' ) === false ) {
mp-wp_genesis 1190 $base = $uri . '?';
mp-wp_genesis 1191 $query = '';
mp-wp_genesis 1192 } else {
mp-wp_genesis 1193 $base = '';
mp-wp_genesis 1194 $query = $uri;
mp-wp_genesis 1195 }
mp-wp_genesis 1196
mp-wp_genesis 1197 wp_parse_str( $query, $qs );
mp-wp_genesis 1198 $qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string
mp-wp_genesis 1199 if ( is_array( func_get_arg( 0 ) ) ) {
mp-wp_genesis 1200 $kayvees = func_get_arg( 0 );
mp-wp_genesis 1201 $qs = array_merge( $qs, $kayvees );
mp-wp_genesis 1202 } else {
mp-wp_genesis 1203 $qs[func_get_arg( 0 )] = func_get_arg( 1 );
mp-wp_genesis 1204 }
mp-wp_genesis 1205
mp-wp_genesis 1206 foreach ( (array) $qs as $k => $v ) {
mp-wp_genesis 1207 if ( $v === false )
mp-wp_genesis 1208 unset( $qs[$k] );
mp-wp_genesis 1209 }
mp-wp_genesis 1210
mp-wp_genesis 1211 $ret = build_query( $qs );
mp-wp_genesis 1212 $ret = trim( $ret, '?' );
mp-wp_genesis 1213 $ret = preg_replace( '#=(&|$)#', '$1', $ret );
mp-wp_genesis 1214 $ret = $protocol . $base . $ret . $frag;
mp-wp_genesis 1215 $ret = rtrim( $ret, '?' );
mp-wp_genesis 1216 return $ret;
mp-wp_genesis 1217 }
mp-wp_genesis 1218
mp-wp_genesis 1219 /**
mp-wp_genesis 1220 * Removes an item or list from the query string.
mp-wp_genesis 1221 *
mp-wp_genesis 1222 * @since 1.5.0
mp-wp_genesis 1223 *
mp-wp_genesis 1224 * @param string|array $key Query key or keys to remove.
mp-wp_genesis 1225 * @param bool $query When false uses the $_SERVER value.
mp-wp_genesis 1226 * @return string New URL query string.
mp-wp_genesis 1227 */
mp-wp_genesis 1228 function remove_query_arg( $key, $query=false ) {
mp-wp_genesis 1229 if ( is_array( $key ) ) { // removing multiple keys
mp-wp_genesis 1230 foreach ( $key as $k )
mp-wp_genesis 1231 $query = add_query_arg( $k, false, $query );
mp-wp_genesis 1232 return $query;
mp-wp_genesis 1233 }
mp-wp_genesis 1234 return add_query_arg( $key, false, $query );
mp-wp_genesis 1235 }
mp-wp_genesis 1236
mp-wp_genesis 1237 /**
mp-wp_genesis 1238 * Walks the array while sanitizing the contents.
mp-wp_genesis 1239 *
mp-wp_genesis 1240 * @uses $wpdb Used to sanitize values
mp-wp_genesis 1241 * @since 0.71
mp-wp_genesis 1242 *
mp-wp_genesis 1243 * @param array $array Array to used to walk while sanitizing contents.
mp-wp_genesis 1244 * @return array Sanitized $array.
mp-wp_genesis 1245 */
mp-wp_genesis 1246 function add_magic_quotes( $array ) {
mp-wp_genesis 1247 global $wpdb;
mp-wp_genesis 1248
mp-wp_genesis 1249 foreach ( (array) $array as $k => $v ) {
mp-wp_genesis 1250 if ( is_array( $v ) ) {
mp-wp_genesis 1251 $array[$k] = add_magic_quotes( $v );
mp-wp_genesis 1252 } else {
mp-wp_genesis 1253 $array[$k] = $wpdb->escape( $v );
mp-wp_genesis 1254 }
mp-wp_genesis 1255 }
mp-wp_genesis 1256 return $array;
mp-wp_genesis 1257 }
mp-wp_genesis 1258
mp-wp_genesis 1259 /**
mp-wp_genesis 1260 * HTTP request for URI to retrieve content.
mp-wp_genesis 1261 *
mp-wp_genesis 1262 * @since 1.5.1
mp-wp_genesis 1263 * @uses wp_remote_get()
mp-wp_genesis 1264 *
mp-wp_genesis 1265 * @param string $uri URI/URL of web page to retrieve.
mp-wp_genesis 1266 * @return bool|string HTTP content. False on failure.
mp-wp_genesis 1267 */
mp-wp_genesis 1268 function wp_remote_fopen( $uri ) {
mp-wp_genesis 1269 $parsed_url = @parse_url( $uri );
mp-wp_genesis 1270
mp-wp_genesis 1271 if ( !$parsed_url || !is_array( $parsed_url ) )
mp-wp_genesis 1272 return false;
mp-wp_genesis 1273
mp-wp_genesis 1274 $options = array();
mp-wp_genesis 1275 $options['timeout'] = 10;
mp-wp_genesis 1276
mp-wp_genesis 1277 $response = wp_remote_get( $uri, $options );
mp-wp_genesis 1278
mp-wp_genesis 1279 if ( is_wp_error( $response ) )
mp-wp_genesis 1280 return false;
mp-wp_genesis 1281
mp-wp_genesis 1282 return $response['body'];
mp-wp_genesis 1283 }
mp-wp_genesis 1284
mp-wp_genesis 1285 /**
mp-wp_genesis 1286 * Setup the WordPress query.
mp-wp_genesis 1287 *
mp-wp_genesis 1288 * @since 2.0.0
mp-wp_genesis 1289 *
mp-wp_genesis 1290 * @param string $query_vars Default WP_Query arguments.
mp-wp_genesis 1291 */
mp-wp_genesis 1292 function wp( $query_vars = '' ) {
mp-wp_genesis 1293 global $wp, $wp_query, $wp_the_query;
mp-wp_genesis 1294 $wp->main( $query_vars );
mp-wp_genesis 1295
mp-wp_genesis 1296 if( !isset($wp_the_query) )
mp-wp_genesis 1297 $wp_the_query = $wp_query;
mp-wp_genesis 1298 }
mp-wp_genesis 1299
mp-wp_genesis 1300 /**
mp-wp_genesis 1301 * Retrieve the description for the HTTP status.
mp-wp_genesis 1302 *
mp-wp_genesis 1303 * @since 2.3.0
mp-wp_genesis 1304 *
mp-wp_genesis 1305 * @param int $code HTTP status code.
mp-wp_genesis 1306 * @return string Empty string if not found, or description if found.
mp-wp_genesis 1307 */
mp-wp_genesis 1308 function get_status_header_desc( $code ) {
mp-wp_genesis 1309 global $wp_header_to_desc;
mp-wp_genesis 1310
mp-wp_genesis 1311 $code = absint( $code );
mp-wp_genesis 1312
mp-wp_genesis 1313 if ( !isset( $wp_header_to_desc ) ) {
mp-wp_genesis 1314 $wp_header_to_desc = array(
mp-wp_genesis 1315 100 => 'Continue',
mp-wp_genesis 1316 101 => 'Switching Protocols',
mp-wp_genesis 1317
mp-wp_genesis 1318 200 => 'OK',
mp-wp_genesis 1319 201 => 'Created',
mp-wp_genesis 1320 202 => 'Accepted',
mp-wp_genesis 1321 203 => 'Non-Authoritative Information',
mp-wp_genesis 1322 204 => 'No Content',
mp-wp_genesis 1323 205 => 'Reset Content',
mp-wp_genesis 1324 206 => 'Partial Content',
mp-wp_genesis 1325
mp-wp_genesis 1326 300 => 'Multiple Choices',
mp-wp_genesis 1327 301 => 'Moved Permanently',
mp-wp_genesis 1328 302 => 'Found',
mp-wp_genesis 1329 303 => 'See Other',
mp-wp_genesis 1330 304 => 'Not Modified',
mp-wp_genesis 1331 305 => 'Use Proxy',
mp-wp_genesis 1332 307 => 'Temporary Redirect',
mp-wp_genesis 1333
mp-wp_genesis 1334 400 => 'Bad Request',
mp-wp_genesis 1335 401 => 'Unauthorized',
mp-wp_genesis 1336 403 => 'Forbidden',
mp-wp_genesis 1337 404 => 'Not Found',
mp-wp_genesis 1338 405 => 'Method Not Allowed',
mp-wp_genesis 1339 406 => 'Not Acceptable',
mp-wp_genesis 1340 407 => 'Proxy Authentication Required',
mp-wp_genesis 1341 408 => 'Request Timeout',
mp-wp_genesis 1342 409 => 'Conflict',
mp-wp_genesis 1343 410 => 'Gone',
mp-wp_genesis 1344 411 => 'Length Required',
mp-wp_genesis 1345 412 => 'Precondition Failed',
mp-wp_genesis 1346 413 => 'Request Entity Too Large',
mp-wp_genesis 1347 414 => 'Request-URI Too Long',
mp-wp_genesis 1348 415 => 'Unsupported Media Type',
mp-wp_genesis 1349 416 => 'Requested Range Not Satisfiable',
mp-wp_genesis 1350 417 => 'Expectation Failed',
mp-wp_genesis 1351
mp-wp_genesis 1352 500 => 'Internal Server Error',
mp-wp_genesis 1353 501 => 'Not Implemented',
mp-wp_genesis 1354 502 => 'Bad Gateway',
mp-wp_genesis 1355 503 => 'Service Unavailable',
mp-wp_genesis 1356 504 => 'Gateway Timeout',
mp-wp_genesis 1357 505 => 'HTTP Version Not Supported'
mp-wp_genesis 1358 );
mp-wp_genesis 1359 }
mp-wp_genesis 1360
mp-wp_genesis 1361 if ( isset( $wp_header_to_desc[$code] ) )
mp-wp_genesis 1362 return $wp_header_to_desc[$code];
mp-wp_genesis 1363 else
mp-wp_genesis 1364 return '';
mp-wp_genesis 1365 }
mp-wp_genesis 1366
mp-wp_genesis 1367 /**
mp-wp_genesis 1368 * Set HTTP status header.
mp-wp_genesis 1369 *
mp-wp_genesis 1370 * @since 2.0.0
mp-wp_genesis 1371 * @uses apply_filters() Calls 'status_header' on status header string, HTTP
mp-wp_genesis 1372 * HTTP code, HTTP code description, and protocol string as separate
mp-wp_genesis 1373 * parameters.
mp-wp_genesis 1374 *
mp-wp_genesis 1375 * @param int $header HTTP status code
mp-wp_genesis 1376 * @return null Does not return anything.
mp-wp_genesis 1377 */
mp-wp_genesis 1378 function status_header( $header ) {
mp-wp_genesis 1379 $text = get_status_header_desc( $header );
mp-wp_genesis 1380
mp-wp_genesis 1381 if ( empty( $text ) )
mp-wp_genesis 1382 return false;
mp-wp_genesis 1383
mp-wp_genesis 1384 $protocol = $_SERVER["SERVER_PROTOCOL"];
mp-wp_genesis 1385 if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol )
mp-wp_genesis 1386 $protocol = 'HTTP/1.0';
mp-wp_genesis 1387 $status_header = "$protocol $header $text";
mp-wp_genesis 1388 if ( function_exists( 'apply_filters' ) )
mp-wp_genesis 1389 $status_header = apply_filters( 'status_header', $status_header, $header, $text, $protocol );
mp-wp_genesis 1390
mp-wp_genesis 1391 if ( version_compare( phpversion(), '4.3.0', '>=' ) )
mp-wp_genesis 1392 return @header( $status_header, true, $header );
mp-wp_genesis 1393 else
mp-wp_genesis 1394 return @header( $status_header );
mp-wp_genesis 1395 }
mp-wp_genesis 1396
mp-wp_genesis 1397 /**
mp-wp_genesis 1398 * Sets the headers to prevent caching for the different browsers.
mp-wp_genesis 1399 *
mp-wp_genesis 1400 * Different browsers support different nocache headers, so several headers must
mp-wp_genesis 1401 * be sent so that all of them get the point that no caching should occur.
mp-wp_genesis 1402 *
mp-wp_genesis 1403 * @since 2.0.0
mp-wp_genesis 1404 */
mp-wp_genesis 1405 function nocache_headers() {
mp-wp_genesis 1406 // why are these @-silenced when other header calls aren't?
mp-wp_genesis 1407 @header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
mp-wp_genesis 1408 @header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
mp-wp_genesis 1409 @header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
mp-wp_genesis 1410 @header( 'Pragma: no-cache' );
mp-wp_genesis 1411 }
mp-wp_genesis 1412
mp-wp_genesis 1413 /**
mp-wp_genesis 1414 * Set the headers for caching for 10 days with JavaScript content type.
mp-wp_genesis 1415 *
mp-wp_genesis 1416 * @since 2.1.0
mp-wp_genesis 1417 */
mp-wp_genesis 1418 function cache_javascript_headers() {
mp-wp_genesis 1419 $expiresOffset = 864000; // 10 days
mp-wp_genesis 1420 header( "Content-Type: text/javascript; charset=" . get_bloginfo( 'charset' ) );
mp-wp_genesis 1421 header( "Vary: Accept-Encoding" ); // Handle proxies
mp-wp_genesis 1422 header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . " GMT" );
mp-wp_genesis 1423 }
mp-wp_genesis 1424
mp-wp_genesis 1425 /**
mp-wp_genesis 1426 * Retrieve the number of database queries during the WordPress execution.
mp-wp_genesis 1427 *
mp-wp_genesis 1428 * @since 2.0.0
mp-wp_genesis 1429 *
mp-wp_genesis 1430 * @return int Number of database queries
mp-wp_genesis 1431 */
mp-wp_genesis 1432 function get_num_queries() {
mp-wp_genesis 1433 global $wpdb;
mp-wp_genesis 1434 return $wpdb->num_queries;
mp-wp_genesis 1435 }
mp-wp_genesis 1436
mp-wp_genesis 1437 /**
mp-wp_genesis 1438 * Whether input is yes or no. Must be 'y' to be true.
mp-wp_genesis 1439 *
mp-wp_genesis 1440 * @since 1.0.0
mp-wp_genesis 1441 *
mp-wp_genesis 1442 * @param string $yn Character string containing either 'y' or 'n'
mp-wp_genesis 1443 * @return bool True if yes, false on anything else
mp-wp_genesis 1444 */
mp-wp_genesis 1445 function bool_from_yn( $yn ) {
mp-wp_genesis 1446 return ( strtolower( $yn ) == 'y' );
mp-wp_genesis 1447 }
mp-wp_genesis 1448
mp-wp_genesis 1449 /**
mp-wp_genesis 1450 * Loads the feed template from the use of an action hook.
mp-wp_genesis 1451 *
mp-wp_genesis 1452 * If the feed action does not have a hook, then the function will die with a
mp-wp_genesis 1453 * message telling the visitor that the feed is not valid.
mp-wp_genesis 1454 *
mp-wp_genesis 1455 * It is better to only have one hook for each feed.
mp-wp_genesis 1456 *
mp-wp_genesis 1457 * @since 2.1.0
mp-wp_genesis 1458 * @uses $wp_query Used to tell if the use a comment feed.
mp-wp_genesis 1459 * @uses do_action() Calls 'do_feed_$feed' hook, if a hook exists for the feed.
mp-wp_genesis 1460 */
mp-wp_genesis 1461 function do_feed() {
mp-wp_genesis 1462 global $wp_query;
mp-wp_genesis 1463
mp-wp_genesis 1464 $feed = get_query_var( 'feed' );
mp-wp_genesis 1465
mp-wp_genesis 1466 // Remove the pad, if present.
mp-wp_genesis 1467 $feed = preg_replace( '/^_+/', '', $feed );
mp-wp_genesis 1468
mp-wp_genesis 1469 if ( $feed == '' || $feed == 'feed' )
mp-wp_genesis 1470 $feed = get_default_feed();
mp-wp_genesis 1471
mp-wp_genesis 1472 $hook = 'do_feed_' . $feed;
mp-wp_genesis 1473 if ( !has_action($hook) ) {
mp-wp_genesis 1474 $message = sprintf( __( 'ERROR: %s is not a valid feed template' ), wp_specialchars($feed));
mp-wp_genesis 1475 wp_die($message);
mp-wp_genesis 1476 }
mp-wp_genesis 1477
mp-wp_genesis 1478 do_action( $hook, $wp_query->is_comment_feed );
mp-wp_genesis 1479 }
mp-wp_genesis 1480
mp-wp_genesis 1481 /**
mp-wp_genesis 1482 * Load the RDF RSS 0.91 Feed template.
mp-wp_genesis 1483 *
mp-wp_genesis 1484 * @since 2.1.0
mp-wp_genesis 1485 */
mp-wp_genesis 1486 function do_feed_rdf() {
mp-wp_genesis 1487 load_template( ABSPATH . WPINC . '/feed-rdf.php' );
mp-wp_genesis 1488 }
mp-wp_genesis 1489
mp-wp_genesis 1490 /**
mp-wp_genesis 1491 * Load the RSS 1.0 Feed Template
mp-wp_genesis 1492 *
mp-wp_genesis 1493 * @since 2.1.0
mp-wp_genesis 1494 */
mp-wp_genesis 1495 function do_feed_rss() {
mp-wp_genesis 1496 load_template( ABSPATH . WPINC . '/feed-rss.php' );
mp-wp_genesis 1497 }
mp-wp_genesis 1498
mp-wp_genesis 1499 /**
mp-wp_genesis 1500 * Load either the RSS2 comment feed or the RSS2 posts feed.
mp-wp_genesis 1501 *
mp-wp_genesis 1502 * @since 2.1.0
mp-wp_genesis 1503 *
mp-wp_genesis 1504 * @param bool $for_comments True for the comment feed, false for normal feed.
mp-wp_genesis 1505 */
mp-wp_genesis 1506 function do_feed_rss2( $for_comments ) {
mp-wp_genesis 1507 if ( $for_comments )
mp-wp_genesis 1508 load_template( ABSPATH . WPINC . '/feed-rss2-comments.php' );
mp-wp_genesis 1509 else
mp-wp_genesis 1510 load_template( ABSPATH . WPINC . '/feed-rss2.php' );
mp-wp_genesis 1511 }
mp-wp_genesis 1512
mp-wp_genesis 1513 /**
mp-wp_genesis 1514 * Load either Atom comment feed or Atom posts feed.
mp-wp_genesis 1515 *
mp-wp_genesis 1516 * @since 2.1.0
mp-wp_genesis 1517 *
mp-wp_genesis 1518 * @param bool $for_comments True for the comment feed, false for normal feed.
mp-wp_genesis 1519 */
mp-wp_genesis 1520 function do_feed_atom( $for_comments ) {
mp-wp_genesis 1521 if ($for_comments)
mp-wp_genesis 1522 load_template( ABSPATH . WPINC . '/feed-atom-comments.php');
mp-wp_genesis 1523 else
mp-wp_genesis 1524 load_template( ABSPATH . WPINC . '/feed-atom.php' );
mp-wp_genesis 1525 }
mp-wp_genesis 1526
mp-wp_genesis 1527 /**
mp-wp_genesis 1528 * Display the robot.txt file content.
mp-wp_genesis 1529 *
mp-wp_genesis 1530 * The echo content should be with usage of the permalinks or for creating the
mp-wp_genesis 1531 * robot.txt file.
mp-wp_genesis 1532 *
mp-wp_genesis 1533 * @since 2.1.0
mp-wp_genesis 1534 * @uses do_action() Calls 'do_robotstxt' hook for displaying robot.txt rules.
mp-wp_genesis 1535 */
mp-wp_genesis 1536 function do_robots() {
mp-wp_genesis 1537 header( 'Content-Type: text/plain; charset=utf-8' );
mp-wp_genesis 1538
mp-wp_genesis 1539 do_action( 'do_robotstxt' );
mp-wp_genesis 1540
mp-wp_genesis 1541 if ( '0' == get_option( 'blog_public' ) ) {
mp-wp_genesis 1542 echo "User-agent: *\n";
mp-wp_genesis 1543 echo "Disallow: /\n";
mp-wp_genesis 1544 } else {
mp-wp_genesis 1545 echo "User-agent: *\n";
mp-wp_genesis 1546 echo "Disallow:\n";
mp-wp_genesis 1547 }
mp-wp_genesis 1548 }
mp-wp_genesis 1549
mp-wp_genesis 1550 /**
mp-wp_genesis 1551 * Test whether blog is already installed.
mp-wp_genesis 1552 *
mp-wp_genesis 1553 * The cache will be checked first. If you have a cache plugin, which saves the
mp-wp_genesis 1554 * cache values, then this will work. If you use the default WordPress cache,
mp-wp_genesis 1555 * and the database goes away, then you might have problems.
mp-wp_genesis 1556 *
mp-wp_genesis 1557 * Checks for the option siteurl for whether WordPress is installed.
mp-wp_genesis 1558 *
mp-wp_genesis 1559 * @since 2.1.0
mp-wp_genesis 1560 * @uses $wpdb
mp-wp_genesis 1561 *
mp-wp_genesis 1562 * @return bool Whether blog is already installed.
mp-wp_genesis 1563 */
mp-wp_genesis 1564 function is_blog_installed() {
mp-wp_genesis 1565 global $wpdb;
mp-wp_genesis 1566
mp-wp_genesis 1567 // Check cache first. If options table goes away and we have true cached, oh well.
mp-wp_genesis 1568 if ( wp_cache_get('is_blog_installed') )
mp-wp_genesis 1569 return true;
mp-wp_genesis 1570
mp-wp_genesis 1571 $suppress = $wpdb->suppress_errors();
mp-wp_genesis 1572 $installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" );
mp-wp_genesis 1573 $wpdb->suppress_errors($suppress);
mp-wp_genesis 1574
mp-wp_genesis 1575 $installed = !empty( $installed ) ? true : false;
mp-wp_genesis 1576 wp_cache_set('is_blog_installed', $installed);
mp-wp_genesis 1577
mp-wp_genesis 1578 return $installed;
mp-wp_genesis 1579 }
mp-wp_genesis 1580
mp-wp_genesis 1581 /**
mp-wp_genesis 1582 * Retrieve URL with nonce added to URL query.
mp-wp_genesis 1583 *
mp-wp_genesis 1584 * @package WordPress
mp-wp_genesis 1585 * @subpackage Security
mp-wp_genesis 1586 * @since 2.0.4
mp-wp_genesis 1587 *
mp-wp_genesis 1588 * @param string $actionurl URL to add nonce action
mp-wp_genesis 1589 * @param string $action Optional. Nonce action name
mp-wp_genesis 1590 * @return string URL with nonce action added.
mp-wp_genesis 1591 */
mp-wp_genesis 1592 function wp_nonce_url( $actionurl, $action = -1 ) {
mp-wp_genesis 1593 $actionurl = str_replace( '&amp;', '&', $actionurl );
mp-wp_genesis 1594 return wp_specialchars( add_query_arg( '_wpnonce', wp_create_nonce( $action ), $actionurl ) );
mp-wp_genesis 1595 }
mp-wp_genesis 1596
mp-wp_genesis 1597 /**
mp-wp_genesis 1598 * Retrieve or display nonce hidden field for forms.
mp-wp_genesis 1599 *
mp-wp_genesis 1600 * The nonce field is used to validate that the contents of the form came from
mp-wp_genesis 1601 * the location on the current site and not somewhere else. The nonce does not
mp-wp_genesis 1602 * offer absolute protection, but should protect against most cases. It is very
mp-wp_genesis 1603 * important to use nonce field in forms.
mp-wp_genesis 1604 *
mp-wp_genesis 1605 * If you set $echo to true and set $referer to true, then you will need to
mp-wp_genesis 1606 * retrieve the {@link wp_referer_field() wp referer field}. If you have the
mp-wp_genesis 1607 * $referer set to true and are echoing the nonce field, it will also echo the
mp-wp_genesis 1608 * referer field.
mp-wp_genesis 1609 *
mp-wp_genesis 1610 * The $action and $name are optional, but if you want to have better security,
mp-wp_genesis 1611 * it is strongly suggested to set those two parameters. It is easier to just
mp-wp_genesis 1612 * call the function without any parameters, because validation of the nonce
mp-wp_genesis 1613 * doesn't require any parameters, but since crackers know what the default is
mp-wp_genesis 1614 * it won't be difficult for them to find a way around your nonce and cause
mp-wp_genesis 1615 * damage.
mp-wp_genesis 1616 *
mp-wp_genesis 1617 * The input name will be whatever $name value you gave. The input value will be
mp-wp_genesis 1618 * the nonce creation value.
mp-wp_genesis 1619 *
mp-wp_genesis 1620 * @package WordPress
mp-wp_genesis 1621 * @subpackage Security
mp-wp_genesis 1622 * @since 2.0.4
mp-wp_genesis 1623 *
mp-wp_genesis 1624 * @param string $action Optional. Action name.
mp-wp_genesis 1625 * @param string $name Optional. Nonce name.
mp-wp_genesis 1626 * @param bool $referer Optional, default true. Whether to set the referer field for validation.
mp-wp_genesis 1627 * @param bool $echo Optional, default true. Whether to display or return hidden form field.
mp-wp_genesis 1628 * @return string Nonce field.
mp-wp_genesis 1629 */
mp-wp_genesis 1630 function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = true ) {
mp-wp_genesis 1631 $name = attribute_escape( $name );
mp-wp_genesis 1632 $nonce_field = '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />';
mp-wp_genesis 1633 if ( $echo )
mp-wp_genesis 1634 echo $nonce_field;
mp-wp_genesis 1635
mp-wp_genesis 1636 if ( $referer )
mp-wp_genesis 1637 wp_referer_field( $echo, 'previous' );
mp-wp_genesis 1638
mp-wp_genesis 1639 return $nonce_field;
mp-wp_genesis 1640 }
mp-wp_genesis 1641
mp-wp_genesis 1642 /**
mp-wp_genesis 1643 * Retrieve or display referer hidden field for forms.
mp-wp_genesis 1644 *
mp-wp_genesis 1645 * The referer link is the current Request URI from the server super global. The
mp-wp_genesis 1646 * input name is '_wp_http_referer', in case you wanted to check manually.
mp-wp_genesis 1647 *
mp-wp_genesis 1648 * @package WordPress
mp-wp_genesis 1649 * @subpackage Security
mp-wp_genesis 1650 * @since 2.0.4
mp-wp_genesis 1651 *
mp-wp_genesis 1652 * @param bool $echo Whether to echo or return the referer field.
mp-wp_genesis 1653 * @return string Referer field.
mp-wp_genesis 1654 */
mp-wp_genesis 1655 function wp_referer_field( $echo = true) {
mp-wp_genesis 1656 $ref = attribute_escape( $_SERVER['REQUEST_URI'] );
mp-wp_genesis 1657 $referer_field = '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />';
mp-wp_genesis 1658
mp-wp_genesis 1659 if ( $echo )
mp-wp_genesis 1660 echo $referer_field;
mp-wp_genesis 1661 return $referer_field;
mp-wp_genesis 1662 }
mp-wp_genesis 1663
mp-wp_genesis 1664 /**
mp-wp_genesis 1665 * Retrieve or display original referer hidden field for forms.
mp-wp_genesis 1666 *
mp-wp_genesis 1667 * The input name is '_wp_original_http_referer' and will be either the same
mp-wp_genesis 1668 * value of {@link wp_referer_field()}, if that was posted already or it will
mp-wp_genesis 1669 * be the current page, if it doesn't exist.
mp-wp_genesis 1670 *
mp-wp_genesis 1671 * @package WordPress
mp-wp_genesis 1672 * @subpackage Security
mp-wp_genesis 1673 * @since 2.0.4
mp-wp_genesis 1674 *
mp-wp_genesis 1675 * @param bool $echo Whether to echo the original http referer
mp-wp_genesis 1676 * @param string $jump_back_to Optional, default is 'current'. Can be 'previous' or page you want to jump back to.
mp-wp_genesis 1677 * @return string Original referer field.
mp-wp_genesis 1678 */
mp-wp_genesis 1679 function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) {
mp-wp_genesis 1680 $jump_back_to = ( 'previous' == $jump_back_to ) ? wp_get_referer() : $_SERVER['REQUEST_URI'];
mp-wp_genesis 1681 $ref = ( wp_get_original_referer() ) ? wp_get_original_referer() : $jump_back_to;
mp-wp_genesis 1682 $orig_referer_field = '<input type="hidden" name="_wp_original_http_referer" value="' . attribute_escape( stripslashes( $ref ) ) . '" />';
mp-wp_genesis 1683 if ( $echo )
mp-wp_genesis 1684 echo $orig_referer_field;
mp-wp_genesis 1685 return $orig_referer_field;
mp-wp_genesis 1686 }
mp-wp_genesis 1687
mp-wp_genesis 1688 /**
mp-wp_genesis 1689 * Retrieve referer from '_wp_http_referer', HTTP referer, or current page respectively.
mp-wp_genesis 1690 *
mp-wp_genesis 1691 * @package WordPress
mp-wp_genesis 1692 * @subpackage Security
mp-wp_genesis 1693 * @since 2.0.4
mp-wp_genesis 1694 *
mp-wp_genesis 1695 * @return string|bool False on failure. Referer URL on success.
mp-wp_genesis 1696 */
mp-wp_genesis 1697 function wp_get_referer() {
mp-wp_genesis 1698 $ref = '';
mp-wp_genesis 1699 if ( ! empty( $_REQUEST['_wp_http_referer'] ) )
mp-wp_genesis 1700 $ref = $_REQUEST['_wp_http_referer'];
mp-wp_genesis 1701 else if ( ! empty( $_SERVER['HTTP_REFERER'] ) )
mp-wp_genesis 1702 $ref = $_SERVER['HTTP_REFERER'];
mp-wp_genesis 1703
mp-wp_genesis 1704 if ( $ref !== $_SERVER['REQUEST_URI'] )
mp-wp_genesis 1705 return $ref;
mp-wp_genesis 1706 return false;
mp-wp_genesis 1707 }
mp-wp_genesis 1708
mp-wp_genesis 1709 /**
mp-wp_genesis 1710 * Retrieve original referer that was posted, if it exists.
mp-wp_genesis 1711 *
mp-wp_genesis 1712 * @package WordPress
mp-wp_genesis 1713 * @subpackage Security
mp-wp_genesis 1714 * @since 2.0.4
mp-wp_genesis 1715 *
mp-wp_genesis 1716 * @return string|bool False if no original referer or original referer if set.
mp-wp_genesis 1717 */
mp-wp_genesis 1718 function wp_get_original_referer() {
mp-wp_genesis 1719 if ( !empty( $_REQUEST['_wp_original_http_referer'] ) )
mp-wp_genesis 1720 return $_REQUEST['_wp_original_http_referer'];
mp-wp_genesis 1721 return false;
mp-wp_genesis 1722 }
mp-wp_genesis 1723
mp-wp_genesis 1724 /**
mp-wp_genesis 1725 * Recursive directory creation based on full path.
mp-wp_genesis 1726 *
mp-wp_genesis 1727 * Will attempt to set permissions on folders.
mp-wp_genesis 1728 *
mp-wp_genesis 1729 * @since 2.0.1
mp-wp_genesis 1730 *
mp-wp_genesis 1731 * @param string $target Full path to attempt to create.
mp-wp_genesis 1732 * @return bool Whether the path was created or not. True if path already exists.
mp-wp_genesis 1733 */
mp-wp_genesis 1734 function wp_mkdir_p( $target ) {
mp-wp_genesis 1735 // from php.net/mkdir user contributed notes
mp-wp_genesis 1736 $target = str_replace( '//', '/', $target );
mp-wp_genesis 1737 if ( file_exists( $target ) )
mp-wp_genesis 1738 return @is_dir( $target );
mp-wp_genesis 1739
mp-wp_genesis 1740 // Attempting to create the directory may clutter up our display.
mp-wp_genesis 1741 if ( @mkdir( $target ) ) {
mp-wp_genesis 1742 $stat = @stat( dirname( $target ) );
mp-wp_genesis 1743 $dir_perms = $stat['mode'] & 0007777; // Get the permission bits.
mp-wp_genesis 1744 @chmod( $target, $dir_perms );
mp-wp_genesis 1745 return true;
mp-wp_genesis 1746 } elseif ( is_dir( dirname( $target ) ) ) {
mp-wp_genesis 1747 return false;
mp-wp_genesis 1748 }
mp-wp_genesis 1749
mp-wp_genesis 1750 // If the above failed, attempt to create the parent node, then try again.
mp-wp_genesis 1751 if ( ( $target != '/' ) && ( wp_mkdir_p( dirname( $target ) ) ) )
mp-wp_genesis 1752 return wp_mkdir_p( $target );
mp-wp_genesis 1753
mp-wp_genesis 1754 return false;
mp-wp_genesis 1755 }
mp-wp_genesis 1756
mp-wp_genesis 1757 /**
mp-wp_genesis 1758 * Test if a give filesystem path is absolute ('/foo/bar', 'c:\windows').
mp-wp_genesis 1759 *
mp-wp_genesis 1760 * @since 2.5.0
mp-wp_genesis 1761 *
mp-wp_genesis 1762 * @param string $path File path
mp-wp_genesis 1763 * @return bool True if path is absolute, false is not absolute.
mp-wp_genesis 1764 */
mp-wp_genesis 1765 function path_is_absolute( $path ) {
mp-wp_genesis 1766 // this is definitive if true but fails if $path does not exist or contains a symbolic link
mp-wp_genesis 1767 if ( realpath($path) == $path )
mp-wp_genesis 1768 return true;
mp-wp_genesis 1769
mp-wp_genesis 1770 if ( strlen($path) == 0 || $path{0} == '.' )
mp-wp_genesis 1771 return false;
mp-wp_genesis 1772
mp-wp_genesis 1773 // windows allows absolute paths like this
mp-wp_genesis 1774 if ( preg_match('#^[a-zA-Z]:\\\\#', $path) )
mp-wp_genesis 1775 return true;
mp-wp_genesis 1776
mp-wp_genesis 1777 // a path starting with / or \ is absolute; anything else is relative
mp-wp_genesis 1778 return (bool) preg_match('#^[/\\\\]#', $path);
mp-wp_genesis 1779 }
mp-wp_genesis 1780
mp-wp_genesis 1781 /**
mp-wp_genesis 1782 * Join two filesystem paths together (e.g. 'give me $path relative to $base').
mp-wp_genesis 1783 *
mp-wp_genesis 1784 * If the $path is absolute, then it the full path is returned.
mp-wp_genesis 1785 *
mp-wp_genesis 1786 * @since 2.5.0
mp-wp_genesis 1787 *
mp-wp_genesis 1788 * @param string $base
mp-wp_genesis 1789 * @param string $path
mp-wp_genesis 1790 * @return string The path with the base or absolute path.
mp-wp_genesis 1791 */
mp-wp_genesis 1792 function path_join( $base, $path ) {
mp-wp_genesis 1793 if ( path_is_absolute($path) )
mp-wp_genesis 1794 return $path;
mp-wp_genesis 1795
mp-wp_genesis 1796 return rtrim($base, '/') . '/' . ltrim($path, '/');
mp-wp_genesis 1797 }
mp-wp_genesis 1798
mp-wp_genesis 1799 /**
mp-wp_genesis 1800 * Get an array containing the current upload directory's path and url.
mp-wp_genesis 1801 *
mp-wp_genesis 1802 * Checks the 'upload_path' option, which should be from the web root folder,
mp-wp_genesis 1803 * and if it isn't empty it will be used. If it is empty, then the path will be
mp-wp_genesis 1804 * 'WP_CONTENT_DIR/uploads'. If the 'UPLOADS' constant is defined, then it will
mp-wp_genesis 1805 * override the 'upload_path' option and 'WP_CONTENT_DIR/uploads' path.
mp-wp_genesis 1806 *
mp-wp_genesis 1807 * The upload URL path is set either by the 'upload_url_path' option or by using
mp-wp_genesis 1808 * the 'WP_CONTENT_URL' constant and appending '/uploads' to the path.
mp-wp_genesis 1809 *
mp-wp_genesis 1810 * If the 'uploads_use_yearmonth_folders' is set to true (checkbox if checked in
mp-wp_genesis 1811 * the administration settings panel), then the time will be used. The format
mp-wp_genesis 1812 * will be year first and then month.
mp-wp_genesis 1813 *
mp-wp_genesis 1814 * If the path couldn't be created, then an error will be returned with the key
mp-wp_genesis 1815 * 'error' containing the error message. The error suggests that the parent
mp-wp_genesis 1816 * directory is not writable by the server.
mp-wp_genesis 1817 *
mp-wp_genesis 1818 * On success, the returned array will have many indices:
mp-wp_genesis 1819 * 'path' - base directory and sub directory or full path to upload directory.
mp-wp_genesis 1820 * 'url' - base url and sub directory or absolute URL to upload directory.
mp-wp_genesis 1821 * 'subdir' - sub directory if uploads use year/month folders option is on.
mp-wp_genesis 1822 * 'basedir' - path without subdir.
mp-wp_genesis 1823 * 'baseurl' - URL path without subdir.
mp-wp_genesis 1824 * 'error' - set to false.
mp-wp_genesis 1825 *
mp-wp_genesis 1826 * @since 2.0.0
mp-wp_genesis 1827 * @uses apply_filters() Calls 'upload_dir' on returned array.
mp-wp_genesis 1828 *
mp-wp_genesis 1829 * @param string $time Optional. Time formatted in 'yyyy/mm'.
mp-wp_genesis 1830 * @return array See above for description.
mp-wp_genesis 1831 */
mp-wp_genesis 1832 function wp_upload_dir( $time = null ) {
mp-wp_genesis 1833 $siteurl = get_option( 'siteurl' );
mp-wp_genesis 1834 $upload_path = get_option( 'upload_path' );
mp-wp_genesis 1835 $upload_path = trim($upload_path);
mp-wp_genesis 1836 if ( empty($upload_path) )
mp-wp_genesis 1837 $dir = WP_CONTENT_DIR . '/uploads';
mp-wp_genesis 1838 else
mp-wp_genesis 1839 $dir = $upload_path;
mp-wp_genesis 1840
mp-wp_genesis 1841 // $dir is absolute, $path is (maybe) relative to ABSPATH
mp-wp_genesis 1842 $dir = path_join( ABSPATH, $dir );
mp-wp_genesis 1843
mp-wp_genesis 1844 if ( !$url = get_option( 'upload_url_path' ) ) {
mp-wp_genesis 1845 if ( empty($upload_path) or ( $upload_path == $dir ) )
mp-wp_genesis 1846 $url = WP_CONTENT_URL . '/uploads';
mp-wp_genesis 1847 else
mp-wp_genesis 1848 $url = trailingslashit( $siteurl ) . $upload_path;
mp-wp_genesis 1849 }
mp-wp_genesis 1850
mp-wp_genesis 1851 if ( defined('UPLOADS') ) {
mp-wp_genesis 1852 $dir = ABSPATH . UPLOADS;
mp-wp_genesis 1853 $url = trailingslashit( $siteurl ) . UPLOADS;
mp-wp_genesis 1854 }
mp-wp_genesis 1855
mp-wp_genesis 1856 $bdir = $dir;
mp-wp_genesis 1857 $burl = $url;
mp-wp_genesis 1858
mp-wp_genesis 1859 $subdir = '';
mp-wp_genesis 1860 if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
mp-wp_genesis 1861 // Generate the yearly and monthly dirs
mp-wp_genesis 1862 if ( !$time )
mp-wp_genesis 1863 $time = current_time( 'mysql' );
mp-wp_genesis 1864 $y = substr( $time, 0, 4 );
mp-wp_genesis 1865 $m = substr( $time, 5, 2 );
mp-wp_genesis 1866 $subdir = "/$y/$m";
mp-wp_genesis 1867 }
mp-wp_genesis 1868
mp-wp_genesis 1869 $dir .= $subdir;
mp-wp_genesis 1870 $url .= $subdir;
mp-wp_genesis 1871
mp-wp_genesis 1872 // Make sure we have an uploads dir
mp-wp_genesis 1873 if ( ! wp_mkdir_p( $dir ) ) {
mp-wp_genesis 1874 $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $dir );
mp-wp_genesis 1875 return array( 'error' => $message );
mp-wp_genesis 1876 }
mp-wp_genesis 1877
mp-wp_genesis 1878 $uploads = array( 'path' => $dir, 'url' => $url, 'subdir' => $subdir, 'basedir' => $bdir, 'baseurl' => $burl, 'error' => false );
mp-wp_genesis 1879
mp-wp_genesis 1880 return apply_filters( 'upload_dir', $uploads );
mp-wp_genesis 1881 }
mp-wp_genesis 1882
mp-wp_genesis 1883 /**
mp-wp_genesis 1884 * Get a filename that is sanitized and unique for the given directory.
mp-wp_genesis 1885 *
mp-wp_genesis 1886 * If the filename is not unique, then a number will be added to the filename
mp-wp_genesis 1887 * before the extension, and will continue adding numbers until the filename is
mp-wp_genesis 1888 * unique.
mp-wp_genesis 1889 *
mp-wp_genesis 1890 * The callback must accept two parameters, the first one is the directory and
mp-wp_genesis 1891 * the second is the filename. The callback must be a function.
mp-wp_genesis 1892 *
mp-wp_genesis 1893 * @since 2.5
mp-wp_genesis 1894 *
mp-wp_genesis 1895 * @param string $dir
mp-wp_genesis 1896 * @param string $filename
mp-wp_genesis 1897 * @param string $unique_filename_callback Function name, must be a function.
mp-wp_genesis 1898 * @return string New filename, if given wasn't unique.
mp-wp_genesis 1899 */
mp-wp_genesis 1900 function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) {
mp-wp_genesis 1901 $filename = strtolower( $filename );
mp-wp_genesis 1902 // separate the filename into a name and extension
mp-wp_genesis 1903 $info = pathinfo($filename);
mp-wp_genesis 1904 $ext = !empty($info['extension']) ? $info['extension'] : '';
mp-wp_genesis 1905 $name = basename($filename, ".{$ext}");
mp-wp_genesis 1906
mp-wp_genesis 1907 // edge case: if file is named '.ext', treat as an empty name
mp-wp_genesis 1908 if( $name === ".$ext" )
mp-wp_genesis 1909 $name = '';
mp-wp_genesis 1910
mp-wp_genesis 1911 // Increment the file number until we have a unique file to save in $dir. Use $override['unique_filename_callback'] if supplied.
mp-wp_genesis 1912 if ( $unique_filename_callback && function_exists( $unique_filename_callback ) ) {
mp-wp_genesis 1913 $filename = $unique_filename_callback( $dir, $name );
mp-wp_genesis 1914 } else {
mp-wp_genesis 1915 $number = '';
mp-wp_genesis 1916
mp-wp_genesis 1917 if ( !empty( $ext ) )
mp-wp_genesis 1918 $ext = strtolower( ".$ext" );
mp-wp_genesis 1919
mp-wp_genesis 1920 $filename = str_replace( $ext, '', $filename );
mp-wp_genesis 1921 // Strip % so the server doesn't try to decode entities.
mp-wp_genesis 1922 $filename = str_replace('%', '', sanitize_title_with_dashes( $filename ) ) . $ext;
mp-wp_genesis 1923
mp-wp_genesis 1924 while ( file_exists( $dir . "/$filename" ) ) {
mp-wp_genesis 1925 if ( '' == "$number$ext" )
mp-wp_genesis 1926 $filename = $filename . ++$number . $ext;
mp-wp_genesis 1927 else
mp-wp_genesis 1928 $filename = str_replace( "$number$ext", ++$number . $ext, $filename );
mp-wp_genesis 1929 }
mp-wp_genesis 1930 }
mp-wp_genesis 1931
mp-wp_genesis 1932 return $filename;
mp-wp_genesis 1933 }
mp-wp_genesis 1934
mp-wp_genesis 1935 /**
mp-wp_genesis 1936 * Create a file in the upload folder with given content.
mp-wp_genesis 1937 *
mp-wp_genesis 1938 * If there is an error, then the key 'error' will exist with the error message.
mp-wp_genesis 1939 * If success, then the key 'file' will have the unique file path, the 'url' key
mp-wp_genesis 1940 * will have the link to the new file. and the 'error' key will be set to false.
mp-wp_genesis 1941 *
mp-wp_genesis 1942 * This function will not move an uploaded file to the upload folder. It will
mp-wp_genesis 1943 * create a new file with the content in $bits parameter. If you move the upload
mp-wp_genesis 1944 * file, read the content of the uploaded file, and then you can give the
mp-wp_genesis 1945 * filename and content to this function, which will add it to the upload
mp-wp_genesis 1946 * folder.
mp-wp_genesis 1947 *
mp-wp_genesis 1948 * The permissions will be set on the new file automatically by this function.
mp-wp_genesis 1949 *
mp-wp_genesis 1950 * @since 2.0.0
mp-wp_genesis 1951 *
mp-wp_genesis 1952 * @param string $name
mp-wp_genesis 1953 * @param null $deprecated Not used. Set to null.
mp-wp_genesis 1954 * @param mixed $bits File content
mp-wp_genesis 1955 * @param string $time Optional. Time formatted in 'yyyy/mm'.
mp-wp_genesis 1956 * @return array
mp-wp_genesis 1957 */
mp-wp_genesis 1958 function wp_upload_bits( $name, $deprecated, $bits, $time = null ) {
mp-wp_genesis 1959 if ( empty( $name ) )
mp-wp_genesis 1960 return array( 'error' => __( 'Empty filename' ) );
mp-wp_genesis 1961
mp-wp_genesis 1962 $wp_filetype = wp_check_filetype( $name );
mp-wp_genesis 1963 if ( !$wp_filetype['ext'] )
mp-wp_genesis 1964 return array( 'error' => __( 'Invalid file type' ) );
mp-wp_genesis 1965
mp-wp_genesis 1966 $upload = wp_upload_dir( $time );
mp-wp_genesis 1967
mp-wp_genesis 1968 if ( $upload['error'] !== false )
mp-wp_genesis 1969 return $upload;
mp-wp_genesis 1970
mp-wp_genesis 1971 $filename = wp_unique_filename( $upload['path'], $name );
mp-wp_genesis 1972
mp-wp_genesis 1973 $new_file = $upload['path'] . "/$filename";
mp-wp_genesis 1974 if ( ! wp_mkdir_p( dirname( $new_file ) ) ) {
mp-wp_genesis 1975 $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), dirname( $new_file ) );
mp-wp_genesis 1976 return array( 'error' => $message );
mp-wp_genesis 1977 }
mp-wp_genesis 1978
mp-wp_genesis 1979 $ifp = @ fopen( $new_file, 'wb' );
mp-wp_genesis 1980 if ( ! $ifp )
mp-wp_genesis 1981 return array( 'error' => sprintf( __( 'Could not write file %s' ), $new_file ) );
mp-wp_genesis 1982
mp-wp_genesis 1983 @fwrite( $ifp, $bits );
mp-wp_genesis 1984 fclose( $ifp );
mp-wp_genesis 1985 // Set correct file permissions
mp-wp_genesis 1986 $stat = @ stat( dirname( $new_file ) );
mp-wp_genesis 1987 $perms = $stat['mode'] & 0007777;
mp-wp_genesis 1988 $perms = $perms & 0000666;
mp-wp_genesis 1989 @ chmod( $new_file, $perms );
mp-wp_genesis 1990
mp-wp_genesis 1991 // Compute the URL
mp-wp_genesis 1992 $url = $upload['url'] . "/$filename";
mp-wp_genesis 1993
mp-wp_genesis 1994 return array( 'file' => $new_file, 'url' => $url, 'error' => false );
mp-wp_genesis 1995 }
mp-wp_genesis 1996
mp-wp_genesis 1997 /**
mp-wp_genesis 1998 * Retrieve the file type based on the extension name.
mp-wp_genesis 1999 *
mp-wp_genesis 2000 * @package WordPress
mp-wp_genesis 2001 * @since 2.5.0
mp-wp_genesis 2002 * @uses apply_filters() Calls 'ext2type' hook on default supported types.
mp-wp_genesis 2003 *
mp-wp_genesis 2004 * @param string $ext The extension to search.
mp-wp_genesis 2005 * @return string|null The file type, example: audio, video, document, spreadsheet, etc. Null if not found.
mp-wp_genesis 2006 */
mp-wp_genesis 2007 function wp_ext2type( $ext ) {
mp-wp_genesis 2008 $ext2type = apply_filters('ext2type', array(
mp-wp_genesis 2009 'audio' => array('aac','ac3','aif','aiff','mp1','mp2','mp3','m3a','m4a','m4b','ogg','ram','wav','wma'),
mp-wp_genesis 2010 'video' => array('asf','avi','divx','dv','mov','mpg','mpeg','mp4','mpv','ogm','qt','rm','vob','wmv'),
mp-wp_genesis 2011 'document' => array('doc','docx','pages','odt','rtf','pdf'),
mp-wp_genesis 2012 'spreadsheet' => array('xls','xlsx','numbers','ods'),
mp-wp_genesis 2013 'interactive' => array('ppt','pptx','key','odp','swf'),
mp-wp_genesis 2014 'text' => array('txt'),
mp-wp_genesis 2015 'archive' => array('tar','bz2','gz','cab','dmg','rar','sea','sit','sqx','zip'),
mp-wp_genesis 2016 'code' => array('css','html','php','js'),
mp-wp_genesis 2017 ));
mp-wp_genesis 2018 foreach ( $ext2type as $type => $exts )
mp-wp_genesis 2019 if ( in_array($ext, $exts) )
mp-wp_genesis 2020 return $type;
mp-wp_genesis 2021 }
mp-wp_genesis 2022
mp-wp_genesis 2023 /**
mp-wp_genesis 2024 * Retrieve the file type from the file name.
mp-wp_genesis 2025 *
mp-wp_genesis 2026 * You can optionally define the mime array, if needed.
mp-wp_genesis 2027 *
mp-wp_genesis 2028 * @since 2.0.4
mp-wp_genesis 2029 *
mp-wp_genesis 2030 * @param string $filename File name or path.
mp-wp_genesis 2031 * @param array $mimes Optional. Key is the file extension with value as the mime type.
mp-wp_genesis 2032 * @return array Values with extension first and mime type.
mp-wp_genesis 2033 */
mp-wp_genesis 2034 function wp_check_filetype( $filename, $mimes = null ) {
mp-wp_genesis 2035 // Accepted MIME types are set here as PCRE unless provided.
mp-wp_genesis 2036 $mimes = ( is_array( $mimes ) ) ? $mimes : apply_filters( 'upload_mimes', array(
mp-wp_genesis 2037 'jpg|jpeg|jpe' => 'image/jpeg',
mp-wp_genesis 2038 'gif' => 'image/gif',
mp-wp_genesis 2039 'png' => 'image/png',
mp-wp_genesis 2040 'bmp' => 'image/bmp',
mp-wp_genesis 2041 'tif|tiff' => 'image/tiff',
mp-wp_genesis 2042 'ico' => 'image/x-icon',
mp-wp_genesis 2043 'asf|asx|wax|wmv|wmx' => 'video/asf',
mp-wp_genesis 2044 'avi' => 'video/avi',
mp-wp_genesis 2045 'divx' => 'video/divx',
mp-wp_genesis 2046 'mov|qt' => 'video/quicktime',
mp-wp_genesis 2047 'mpeg|mpg|mpe|mp4' => 'video/mpeg',
mp-wp_genesis 2048 'txt|c|cc|h' => 'text/plain',
mp-wp_genesis 2049 'rtx' => 'text/richtext',
mp-wp_genesis 2050 'css' => 'text/css',
mp-wp_genesis 2051 'htm|html' => 'text/html',
mp-wp_genesis 2052 'mp3|m4a' => 'audio/mpeg',
mp-wp_genesis 2053 'ra|ram' => 'audio/x-realaudio',
mp-wp_genesis 2054 'wav' => 'audio/wav',
mp-wp_genesis 2055 'ogg' => 'audio/ogg',
mp-wp_genesis 2056 'mid|midi' => 'audio/midi',
mp-wp_genesis 2057 'wma' => 'audio/wma',
mp-wp_genesis 2058 'rtf' => 'application/rtf',
mp-wp_genesis 2059 'js' => 'application/javascript',
mp-wp_genesis 2060 'pdf' => 'application/pdf',
mp-wp_genesis 2061 'doc|docx' => 'application/msword',
mp-wp_genesis 2062 'pot|pps|ppt|pptx' => 'application/vnd.ms-powerpoint',
mp-wp_genesis 2063 'wri' => 'application/vnd.ms-write',
mp-wp_genesis 2064 'xla|xls|xlsx|xlt|xlw' => 'application/vnd.ms-excel',
mp-wp_genesis 2065 'mdb' => 'application/vnd.ms-access',
mp-wp_genesis 2066 'mpp' => 'application/vnd.ms-project',
mp-wp_genesis 2067 'swf' => 'application/x-shockwave-flash',
mp-wp_genesis 2068 'class' => 'application/java',
mp-wp_genesis 2069 'tar' => 'application/x-tar',
mp-wp_genesis 2070 'zip' => 'application/zip',
mp-wp_genesis 2071 'gz|gzip' => 'application/x-gzip',
mp-wp_genesis 2072 'exe' => 'application/x-msdownload',
mp-wp_genesis 2073 // openoffice formats
mp-wp_genesis 2074 'odt' => 'application/vnd.oasis.opendocument.text',
mp-wp_genesis 2075 'odp' => 'application/vnd.oasis.opendocument.presentation',
mp-wp_genesis 2076 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
mp-wp_genesis 2077 'odg' => 'application/vnd.oasis.opendocument.graphics',
mp-wp_genesis 2078 'odc' => 'application/vnd.oasis.opendocument.chart',
mp-wp_genesis 2079 'odb' => 'application/vnd.oasis.opendocument.database',
mp-wp_genesis 2080 'odf' => 'application/vnd.oasis.opendocument.formula',
mp-wp_genesis 2081 )
mp-wp_genesis 2082 );
mp-wp_genesis 2083
mp-wp_genesis 2084 $type = false;
mp-wp_genesis 2085 $ext = false;
mp-wp_genesis 2086
mp-wp_genesis 2087 foreach ( $mimes as $ext_preg => $mime_match ) {
mp-wp_genesis 2088 $ext_preg = '!\.(' . $ext_preg . ')$!i';
mp-wp_genesis 2089 if ( preg_match( $ext_preg, $filename, $ext_matches ) ) {
mp-wp_genesis 2090 $type = $mime_match;
mp-wp_genesis 2091 $ext = $ext_matches[1];
mp-wp_genesis 2092 break;
mp-wp_genesis 2093 }
mp-wp_genesis 2094 }
mp-wp_genesis 2095
mp-wp_genesis 2096 return compact( 'ext', 'type' );
mp-wp_genesis 2097 }
mp-wp_genesis 2098
mp-wp_genesis 2099 /**
mp-wp_genesis 2100 * Retrieve nonce action "Are you sure" message.
mp-wp_genesis 2101 *
mp-wp_genesis 2102 * The action is split by verb and noun. The action format is as follows:
mp-wp_genesis 2103 * verb-action_extra. The verb is before the first dash and has the format of
mp-wp_genesis 2104 * letters and no spaces and numbers. The noun is after the dash and before the
mp-wp_genesis 2105 * underscore, if an underscore exists. The noun is also only letters.
mp-wp_genesis 2106 *
mp-wp_genesis 2107 * The filter will be called for any action, which is not defined by WordPress.
mp-wp_genesis 2108 * You may use the filter for your plugin to explain nonce actions to the user,
mp-wp_genesis 2109 * when they get the "Are you sure?" message. The filter is in the format of
mp-wp_genesis 2110 * 'explain_nonce_$verb-$noun' with the $verb replaced by the found verb and the
mp-wp_genesis 2111 * $noun replaced by the found noun. The two parameters that are given to the
mp-wp_genesis 2112 * hook are the localized "Are you sure you want to do this?" message with the
mp-wp_genesis 2113 * extra text (the text after the underscore).
mp-wp_genesis 2114 *
mp-wp_genesis 2115 * @package WordPress
mp-wp_genesis 2116 * @subpackage Security
mp-wp_genesis 2117 * @since 2.0.4
mp-wp_genesis 2118 *
mp-wp_genesis 2119 * @param string $action Nonce action.
mp-wp_genesis 2120 * @return string Are you sure message.
mp-wp_genesis 2121 */
mp-wp_genesis 2122 function wp_explain_nonce( $action ) {
mp-wp_genesis 2123 if ( $action !== -1 && preg_match( '/([a-z]+)-([a-z]+)(_(.+))?/', $action, $matches ) ) {
mp-wp_genesis 2124 $verb = $matches[1];
mp-wp_genesis 2125 $noun = $matches[2];
mp-wp_genesis 2126
mp-wp_genesis 2127 $trans = array();
mp-wp_genesis 2128 $trans['update']['attachment'] = array( __( 'Your attempt to edit this attachment: &quot;%s&quot; has failed.' ), 'get_the_title' );
mp-wp_genesis 2129
mp-wp_genesis 2130 $trans['add']['category'] = array( __( 'Your attempt to add this category has failed.' ), false );
mp-wp_genesis 2131 $trans['delete']['category'] = array( __( 'Your attempt to delete this category: &quot;%s&quot; has failed.' ), 'get_catname' );
mp-wp_genesis 2132 $trans['update']['category'] = array( __( 'Your attempt to edit this category: &quot;%s&quot; has failed.' ), 'get_catname' );
mp-wp_genesis 2133
mp-wp_genesis 2134 $trans['delete']['comment'] = array( __( 'Your attempt to delete this comment: &quot;%s&quot; has failed.' ), 'use_id' );
mp-wp_genesis 2135 $trans['unapprove']['comment'] = array( __( 'Your attempt to unapprove this comment: &quot;%s&quot; has failed.' ), 'use_id' );
mp-wp_genesis 2136 $trans['approve']['comment'] = array( __( 'Your attempt to approve this comment: &quot;%s&quot; has failed.' ), 'use_id' );
mp-wp_genesis 2137 $trans['update']['comment'] = array( __( 'Your attempt to edit this comment: &quot;%s&quot; has failed.' ), 'use_id' );
mp-wp_genesis 2138 $trans['bulk']['comments'] = array( __( 'Your attempt to bulk modify comments has failed.' ), false );
mp-wp_genesis 2139 $trans['moderate']['comments'] = array( __( 'Your attempt to moderate comments has failed.' ), false );
mp-wp_genesis 2140
mp-wp_genesis 2141 $trans['add']['bookmark'] = array( __( 'Your attempt to add this link has failed.' ), false );
mp-wp_genesis 2142 $trans['delete']['bookmark'] = array( __( 'Your attempt to delete this link: &quot;%s&quot; has failed.' ), 'use_id' );
mp-wp_genesis 2143 $trans['update']['bookmark'] = array( __( 'Your attempt to edit this link: &quot;%s&quot; has failed.' ), 'use_id' );
mp-wp_genesis 2144 $trans['bulk']['bookmarks'] = array( __( 'Your attempt to bulk modify links has failed.' ), false );
mp-wp_genesis 2145
mp-wp_genesis 2146 $trans['add']['page'] = array( __( 'Your attempt to add this page has failed.' ), false );
mp-wp_genesis 2147 $trans['delete']['page'] = array( __( 'Your attempt to delete this page: &quot;%s&quot; has failed.' ), 'get_the_title' );
mp-wp_genesis 2148 $trans['update']['page'] = array( __( 'Your attempt to edit this page: &quot;%s&quot; has failed.' ), 'get_the_title' );
mp-wp_genesis 2149
mp-wp_genesis 2150 $trans['edit']['plugin'] = array( __( 'Your attempt to edit this plugin file: &quot;%s&quot; has failed.' ), 'use_id' );
mp-wp_genesis 2151 $trans['activate']['plugin'] = array( __( 'Your attempt to activate this plugin: &quot;%s&quot; has failed.' ), 'use_id' );
mp-wp_genesis 2152 $trans['deactivate']['plugin'] = array( __( 'Your attempt to deactivate this plugin: &quot;%s&quot; has failed.' ), 'use_id' );
mp-wp_genesis 2153 $trans['upgrade']['plugin'] = array( __( 'Your attempt to upgrade this plugin: &quot;%s&quot; has failed.' ), 'use_id' );
mp-wp_genesis 2154
mp-wp_genesis 2155 $trans['add']['post'] = array( __( 'Your attempt to add this post has failed.' ), false );
mp-wp_genesis 2156 $trans['delete']['post'] = array( __( 'Your attempt to delete this post: &quot;%s&quot; has failed.' ), 'get_the_title' );
mp-wp_genesis 2157 $trans['update']['post'] = array( __( 'Your attempt to edit this post: &quot;%s&quot; has failed.' ), 'get_the_title' );
mp-wp_genesis 2158
mp-wp_genesis 2159 $trans['add']['user'] = array( __( 'Your attempt to add this user has failed.' ), false );
mp-wp_genesis 2160 $trans['delete']['users'] = array( __( 'Your attempt to delete users has failed.' ), false );
mp-wp_genesis 2161 $trans['bulk']['users'] = array( __( 'Your attempt to bulk modify users has failed.' ), false );
mp-wp_genesis 2162 $trans['update']['user'] = array( __( 'Your attempt to edit this user: &quot;%s&quot; has failed.' ), 'get_author_name' );
mp-wp_genesis 2163 $trans['update']['profile'] = array( __( 'Your attempt to modify the profile for: &quot;%s&quot; has failed.' ), 'get_author_name' );
mp-wp_genesis 2164
mp-wp_genesis 2165 $trans['update']['options'] = array( __( 'Your attempt to edit your settings has failed.' ), false );
mp-wp_genesis 2166 $trans['update']['permalink'] = array( __( 'Your attempt to change your permalink structure to: %s has failed.' ), 'use_id' );
mp-wp_genesis 2167 $trans['edit']['file'] = array( __( 'Your attempt to edit this file: &quot;%s&quot; has failed.' ), 'use_id' );
mp-wp_genesis 2168 $trans['edit']['theme'] = array( __( 'Your attempt to edit this theme file: &quot;%s&quot; has failed.' ), 'use_id' );
mp-wp_genesis 2169 $trans['switch']['theme'] = array( __( 'Your attempt to switch to this theme: &quot;%s&quot; has failed.' ), 'use_id' );
mp-wp_genesis 2170
mp-wp_genesis 2171 $trans['log']['out'] = array( sprintf( __( 'You are attempting to log out of %s' ), get_bloginfo( 'sitename' ) ), false );
mp-wp_genesis 2172
mp-wp_genesis 2173 if ( isset( $trans[$verb][$noun] ) ) {
mp-wp_genesis 2174 if ( !empty( $trans[$verb][$noun][1] ) ) {
mp-wp_genesis 2175 $lookup = $trans[$verb][$noun][1];
mp-wp_genesis 2176 $object = $matches[4];
mp-wp_genesis 2177 if ( 'use_id' != $lookup )
mp-wp_genesis 2178 $object = call_user_func( $lookup, $object );
mp-wp_genesis 2179 return sprintf( $trans[$verb][$noun][0], wp_specialchars($object) );
mp-wp_genesis 2180 } else {
mp-wp_genesis 2181 return $trans[$verb][$noun][0];
mp-wp_genesis 2182 }
mp-wp_genesis 2183 }
mp-wp_genesis 2184 }
mp-wp_genesis 2185
mp-wp_genesis 2186 return apply_filters( 'explain_nonce_' . $verb . '-' . $noun, __( 'Are you sure you want to do this?' ), $matches[4] );
mp-wp_genesis 2187 }
mp-wp_genesis 2188
mp-wp_genesis 2189 /**
mp-wp_genesis 2190 * Display "Are You Sure" message to confirm the action being taken.
mp-wp_genesis 2191 *
mp-wp_genesis 2192 * If the action has the nonce explain message, then it will be displayed along
mp-wp_genesis 2193 * with the "Are you sure?" message.
mp-wp_genesis 2194 *
mp-wp_genesis 2195 * @package WordPress
mp-wp_genesis 2196 * @subpackage Security
mp-wp_genesis 2197 * @since 2.0.4
mp-wp_genesis 2198 *
mp-wp_genesis 2199 * @param string $action The nonce action.
mp-wp_genesis 2200 */
mp-wp_genesis 2201 function wp_nonce_ays( $action ) {
mp-wp_genesis 2202 $title = __( 'WordPress Failure Notice' );
mp-wp_genesis 2203 $html = wp_specialchars( wp_explain_nonce( $action ) );
mp-wp_genesis 2204 if ( wp_get_referer() )
mp-wp_genesis 2205 $html .= "</p><p><a href='" . remove_query_arg( 'updated', clean_url( wp_get_referer() ) ) . "'>" . __( 'Please try again.' ) . "</a>";
mp-wp_genesis 2206 elseif ( 'log-out' == $action )
mp-wp_genesis 2207 $html .= "</p><p>" . sprintf( __( "Do you really want to <a href='%s'>log out</a>?"), wp_nonce_url( site_url('wp-login.php?action=logout', 'login'), 'log-out' ) );
mp-wp_genesis 2208
mp-wp_genesis 2209 wp_die( $html, $title);
mp-wp_genesis 2210 }
mp-wp_genesis 2211
mp-wp_genesis 2212 /**
mp-wp_genesis 2213 * Kill WordPress execution and display HTML message with error message.
mp-wp_genesis 2214 *
mp-wp_genesis 2215 * Call this function complements the die() PHP function. The difference is that
mp-wp_genesis 2216 * HTML will be displayed to the user. It is recommended to use this function
mp-wp_genesis 2217 * only, when the execution should not continue any further. It is not
mp-wp_genesis 2218 * recommended to call this function very often and try to handle as many errors
mp-wp_genesis 2219 * as possible siliently.
mp-wp_genesis 2220 *
mp-wp_genesis 2221 * @since 2.0.4
mp-wp_genesis 2222 *
mp-wp_genesis 2223 * @param string $message Error message.
mp-wp_genesis 2224 * @param string $title Error title.
mp-wp_genesis 2225 * @param string|array $args Optional arguements to control behaviour.
mp-wp_genesis 2226 */
mp-wp_genesis 2227 function wp_die( $message, $title = '', $args = array() ) {
mp-wp_genesis 2228 global $wp_locale;
mp-wp_genesis 2229
mp-wp_genesis 2230 $defaults = array( 'response' => 500 );
mp-wp_genesis 2231 $r = wp_parse_args($args, $defaults);
mp-wp_genesis 2232
mp-wp_genesis 2233 if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) {
mp-wp_genesis 2234 if ( empty( $title ) ) {
mp-wp_genesis 2235 $error_data = $message->get_error_data();
mp-wp_genesis 2236 if ( is_array( $error_data ) && isset( $error_data['title'] ) )
mp-wp_genesis 2237 $title = $error_data['title'];
mp-wp_genesis 2238 }
mp-wp_genesis 2239 $errors = $message->get_error_messages();
mp-wp_genesis 2240 switch ( count( $errors ) ) :
mp-wp_genesis 2241 case 0 :
mp-wp_genesis 2242 $message = '';
mp-wp_genesis 2243 break;
mp-wp_genesis 2244 case 1 :
mp-wp_genesis 2245 $message = "<p>{$errors[0]}</p>";
mp-wp_genesis 2246 break;
mp-wp_genesis 2247 default :
mp-wp_genesis 2248 $message = "<ul>\n\t\t<li>" . join( "</li>\n\t\t<li>", $errors ) . "</li>\n\t</ul>";
mp-wp_genesis 2249 break;
mp-wp_genesis 2250 endswitch;
mp-wp_genesis 2251 } elseif ( is_string( $message ) ) {
mp-wp_genesis 2252 $message = "<p>$message</p>";
mp-wp_genesis 2253 }
mp-wp_genesis 2254
mp-wp_genesis 2255 if ( defined( 'WP_SITEURL' ) && '' != WP_SITEURL )
mp-wp_genesis 2256 $admin_dir = WP_SITEURL . '/wp-admin/';
mp-wp_genesis 2257 elseif ( function_exists( 'get_bloginfo' ) && '' != get_bloginfo( 'wpurl' ) )
mp-wp_genesis 2258 $admin_dir = get_bloginfo( 'wpurl' ) . '/wp-admin/';
mp-wp_genesis 2259 elseif ( strpos( $_SERVER['PHP_SELF'], 'wp-admin' ) !== false )
mp-wp_genesis 2260 $admin_dir = '';
mp-wp_genesis 2261 else
mp-wp_genesis 2262 $admin_dir = 'wp-admin/';
mp-wp_genesis 2263
mp-wp_genesis 2264 if ( !function_exists( 'did_action' ) || !did_action( 'admin_head' ) ) :
mp-wp_genesis 2265 if( !headers_sent() ){
mp-wp_genesis 2266 status_header( $r['response'] );
mp-wp_genesis 2267 nocache_headers();
mp-wp_genesis 2268 header( 'Content-Type: text/html; charset=utf-8' );
mp-wp_genesis 2269 }
mp-wp_genesis 2270
mp-wp_genesis 2271 if ( empty($title) ) {
mp-wp_genesis 2272 if ( function_exists( '__' ) )
mp-wp_genesis 2273 $title = __( 'WordPress &rsaquo; Error' );
mp-wp_genesis 2274 else
mp-wp_genesis 2275 $title = 'WordPress &rsaquo; Error';
mp-wp_genesis 2276 }
mp-wp_genesis 2277
mp-wp_genesis 2278 ?>
mp-wp_genesis 2279 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
mp-wp_genesis 2280 <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) ) language_attributes(); ?>>
mp-wp_genesis 2281 <head>
mp-wp_genesis 2282 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
mp-wp_genesis 2283 <title><?php echo $title ?></title>
mp-wp_genesis 2284 <link rel="stylesheet" href="<?php echo $admin_dir; ?>css/install.css" type="text/css" />
mp-wp_genesis 2285 <?php
mp-wp_genesis 2286 if ( ( $wp_locale ) && ( 'rtl' == $wp_locale->text_direction ) ) : ?>
mp-wp_genesis 2287 <link rel="stylesheet" href="<?php echo $admin_dir; ?>css/install-rtl.css" type="text/css" />
mp-wp_genesis 2288 <?php endif; ?>
mp-wp_genesis 2289 </head>
mp-wp_genesis 2290 <body id="error-page">
mp-wp_genesis 2291 <?php endif; ?>
mp-wp_genesis 2292 <?php echo $message; ?>
mp-wp_genesis 2293 <?php if ( strlen($message) < 512) echo str_repeat(' ', 512-strlen($message)); ?>
mp-wp_genesis 2294 </body>
mp-wp_genesis 2295 </html>
mp-wp_genesis 2296 <?php
mp-wp_genesis 2297 die();
mp-wp_genesis 2298 }
mp-wp_genesis 2299
mp-wp_genesis 2300 /**
mp-wp_genesis 2301 * Retrieve the WordPress home page URL.
mp-wp_genesis 2302 *
mp-wp_genesis 2303 * If the constant named 'WP_HOME' exists, then it willl be used and returned by
mp-wp_genesis 2304 * the function. This can be used to counter the redirection on your local
mp-wp_genesis 2305 * development environment.
mp-wp_genesis 2306 *
mp-wp_genesis 2307 * @access private
mp-wp_genesis 2308 * @package WordPress
mp-wp_genesis 2309 * @since 2.2.0
mp-wp_genesis 2310 *
mp-wp_genesis 2311 * @param string $url URL for the home location
mp-wp_genesis 2312 * @return string Homepage location.
mp-wp_genesis 2313 */
mp-wp_genesis 2314 function _config_wp_home( $url = '' ) {
mp-wp_genesis 2315 if ( defined( 'WP_HOME' ) )
mp-wp_genesis 2316 return WP_HOME;
mp-wp_genesis 2317 return $url;
mp-wp_genesis 2318 }
mp-wp_genesis 2319
mp-wp_genesis 2320 /**
mp-wp_genesis 2321 * Retrieve the WordPress site URL.
mp-wp_genesis 2322 *
mp-wp_genesis 2323 * If the constant named 'WP_SITEURL' is defined, then the value in that
mp-wp_genesis 2324 * constant will always be returned. This can be used for debugging a site on
mp-wp_genesis 2325 * your localhost while not having to change the database to your URL.
mp-wp_genesis 2326 *
mp-wp_genesis 2327 * @access private
mp-wp_genesis 2328 * @package WordPress
mp-wp_genesis 2329 * @since 2.2.0
mp-wp_genesis 2330 *
mp-wp_genesis 2331 * @param string $url URL to set the WordPress site location.
mp-wp_genesis 2332 * @return string The WordPress Site URL
mp-wp_genesis 2333 */
mp-wp_genesis 2334 function _config_wp_siteurl( $url = '' ) {
mp-wp_genesis 2335 if ( defined( 'WP_SITEURL' ) )
mp-wp_genesis 2336 return WP_SITEURL;
mp-wp_genesis 2337 return $url;
mp-wp_genesis 2338 }
mp-wp_genesis 2339
mp-wp_genesis 2340 /**
mp-wp_genesis 2341 * Set the localized direction for MCE plugin.
mp-wp_genesis 2342 *
mp-wp_genesis 2343 * Will only set the direction to 'rtl', if the WordPress locale has the text
mp-wp_genesis 2344 * direction set to 'rtl'.
mp-wp_genesis 2345 *
mp-wp_genesis 2346 * Fills in the 'directionality', 'plugins', and 'theme_advanced_button1' array
mp-wp_genesis 2347 * keys. These keys are then returned in the $input array.
mp-wp_genesis 2348 *
mp-wp_genesis 2349 * @access private
mp-wp_genesis 2350 * @package WordPress
mp-wp_genesis 2351 * @subpackage MCE
mp-wp_genesis 2352 * @since 2.1.0
mp-wp_genesis 2353 *
mp-wp_genesis 2354 * @param array $input MCE plugin array.
mp-wp_genesis 2355 * @return array Direction set for 'rtl', if needed by locale.
mp-wp_genesis 2356 */
mp-wp_genesis 2357 function _mce_set_direction( $input ) {
mp-wp_genesis 2358 global $wp_locale;
mp-wp_genesis 2359
mp-wp_genesis 2360 if ( 'rtl' == $wp_locale->text_direction ) {
mp-wp_genesis 2361 $input['directionality'] = 'rtl';
mp-wp_genesis 2362 $input['plugins'] .= ',directionality';
mp-wp_genesis 2363 $input['theme_advanced_buttons1'] .= ',ltr';
mp-wp_genesis 2364 }
mp-wp_genesis 2365
mp-wp_genesis 2366 return $input;
mp-wp_genesis 2367 }
mp-wp_genesis 2368
mp-wp_genesis 2369 /**
mp-wp_genesis 2370 * Convert smiley code to the icon graphic file equivalent.
mp-wp_genesis 2371 *
mp-wp_genesis 2372 * You can turn off smilies, by going to the write setting screen and unchecking
mp-wp_genesis 2373 * the box, or by setting 'use_smilies' option to false or removing the option.
mp-wp_genesis 2374 *
mp-wp_genesis 2375 * Plugins may override the default smiley list by setting the $wpsmiliestrans
mp-wp_genesis 2376 * to an array, with the key the code the blogger types in and the value the
mp-wp_genesis 2377 * image file.
mp-wp_genesis 2378 *
mp-wp_genesis 2379 * The $wp_smiliessearch global is for the regular expression array and is
mp-wp_genesis 2380 * set each time the function is called. The $wp_smiliesreplace is the full
mp-wp_genesis 2381 * replacement. Supposely, the $wp_smiliessearch array is looped over using
mp-wp_genesis 2382 * preg_replace() or just setting the array of $wp_smiliessearch along with the
mp-wp_genesis 2383 * array of $wp_smiliesreplace in the search and replace parameters of
mp-wp_genesis 2384 * preg_replace(), which would be faster and less overhead. Either way, both are
mp-wp_genesis 2385 * used with preg_replace() and can be defined after the function is called.
mp-wp_genesis 2386 *
mp-wp_genesis 2387 * The full list of smilies can be found in the function and won't be listed in
mp-wp_genesis 2388 * the description. Probably should create a Codex page for it, so that it is
mp-wp_genesis 2389 * available.
mp-wp_genesis 2390 *
mp-wp_genesis 2391 * @global array $wpsmiliestrans
mp-wp_genesis 2392 * @global array $wp_smiliesreplace
mp-wp_genesis 2393 * @global array $wp_smiliessearch
mp-wp_genesis 2394 * @since 2.2.0
mp-wp_genesis 2395 */
mp-wp_genesis 2396 function smilies_init() {
mp-wp_genesis 2397 global $wpsmiliestrans, $wp_smiliessearch, $wp_smiliesreplace;
mp-wp_genesis 2398
mp-wp_genesis 2399 // don't bother setting up smilies if they are disabled
mp-wp_genesis 2400 if ( !get_option( 'use_smilies' ) )
mp-wp_genesis 2401 return;
mp-wp_genesis 2402
mp-wp_genesis 2403 if ( !isset( $wpsmiliestrans ) ) {
mp-wp_genesis 2404 $wpsmiliestrans = array(
mp-wp_genesis 2405 ':mrgreen:' => 'icon_mrgreen.gif',
mp-wp_genesis 2406 ':neutral:' => 'icon_neutral.gif',
mp-wp_genesis 2407 ':twisted:' => 'icon_twisted.gif',
mp-wp_genesis 2408 ':arrow:' => 'icon_arrow.gif',
mp-wp_genesis 2409 ':shock:' => 'icon_eek.gif',
mp-wp_genesis 2410 ':smile:' => 'icon_smile.gif',
mp-wp_genesis 2411 ':???:' => 'icon_confused.gif',
mp-wp_genesis 2412 ':cool:' => 'icon_cool.gif',
mp-wp_genesis 2413 ':evil:' => 'icon_evil.gif',
mp-wp_genesis 2414 ':grin:' => 'icon_biggrin.gif',
mp-wp_genesis 2415 ':idea:' => 'icon_idea.gif',
mp-wp_genesis 2416 ':oops:' => 'icon_redface.gif',
mp-wp_genesis 2417 ':razz:' => 'icon_razz.gif',
mp-wp_genesis 2418 ':roll:' => 'icon_rolleyes.gif',
mp-wp_genesis 2419 ':wink:' => 'icon_wink.gif',
mp-wp_genesis 2420 ':cry:' => 'icon_cry.gif',
mp-wp_genesis 2421 ':eek:' => 'icon_surprised.gif',
mp-wp_genesis 2422 ':lol:' => 'icon_lol.gif',
mp-wp_genesis 2423 ':mad:' => 'icon_mad.gif',
mp-wp_genesis 2424 ':sad:' => 'icon_sad.gif',
mp-wp_genesis 2425 '8-)' => 'icon_cool.gif',
mp-wp_genesis 2426 '8-O' => 'icon_eek.gif',
mp-wp_genesis 2427 ':-(' => 'icon_sad.gif',
mp-wp_genesis 2428 ':-)' => 'icon_smile.gif',
mp-wp_genesis 2429 ':-?' => 'icon_confused.gif',
mp-wp_genesis 2430 ':-D' => 'icon_biggrin.gif',
mp-wp_genesis 2431 ':-P' => 'icon_razz.gif',
mp-wp_genesis 2432 ':-o' => 'icon_surprised.gif',
mp-wp_genesis 2433 ':-x' => 'icon_mad.gif',
mp-wp_genesis 2434 ':-|' => 'icon_neutral.gif',
mp-wp_genesis 2435 ';-)' => 'icon_wink.gif',
mp-wp_genesis 2436 '8)' => 'icon_cool.gif',
mp-wp_genesis 2437 '8O' => 'icon_eek.gif',
mp-wp_genesis 2438 ':(' => 'icon_sad.gif',
mp-wp_genesis 2439 ':)' => 'icon_smile.gif',
mp-wp_genesis 2440 ':?' => 'icon_confused.gif',
mp-wp_genesis 2441 ':D' => 'icon_biggrin.gif',
mp-wp_genesis 2442 ':P' => 'icon_razz.gif',
mp-wp_genesis 2443 ':o' => 'icon_surprised.gif',
mp-wp_genesis 2444 ':x' => 'icon_mad.gif',
mp-wp_genesis 2445 ':|' => 'icon_neutral.gif',
mp-wp_genesis 2446 ';)' => 'icon_wink.gif',
mp-wp_genesis 2447 ':!:' => 'icon_exclaim.gif',
mp-wp_genesis 2448 ':?:' => 'icon_question.gif',
mp-wp_genesis 2449 );
mp-wp_genesis 2450 }
mp-wp_genesis 2451
mp-wp_genesis 2452 $siteurl = get_option( 'siteurl' );
mp-wp_genesis 2453 foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
mp-wp_genesis 2454 $wp_smiliessearch[] = '/(\s|^)' . preg_quote( $smiley, '/' ) . '(\s|$)/';
mp-wp_genesis 2455 $smiley_masked = attribute_escape( trim( $smiley ) );
mp-wp_genesis 2456 $wp_smiliesreplace[] = " <img src='$siteurl/wp-includes/images/smilies/$img' alt='$smiley_masked' class='wp-smiley' /> ";
mp-wp_genesis 2457 }
mp-wp_genesis 2458 }
mp-wp_genesis 2459
mp-wp_genesis 2460 /**
mp-wp_genesis 2461 * Merge user defined arguments into defaults array.
mp-wp_genesis 2462 *
mp-wp_genesis 2463 * This function is used throughout WordPress to allow for both string or array
mp-wp_genesis 2464 * to be merged into another array.
mp-wp_genesis 2465 *
mp-wp_genesis 2466 * @since 2.2.0
mp-wp_genesis 2467 *
mp-wp_genesis 2468 * @param string|array $args Value to merge with $defaults
mp-wp_genesis 2469 * @param array $defaults Array that serves as the defaults.
mp-wp_genesis 2470 * @return array Merged user defined values with defaults.
mp-wp_genesis 2471 */
mp-wp_genesis 2472 function wp_parse_args( $args, $defaults = '' ) {
mp-wp_genesis 2473 if ( is_object( $args ) )
mp-wp_genesis 2474 $r = get_object_vars( $args );
mp-wp_genesis 2475 elseif ( is_array( $args ) )
mp-wp_genesis 2476 $r =& $args;
mp-wp_genesis 2477 else
mp-wp_genesis 2478 wp_parse_str( $args, $r );
mp-wp_genesis 2479
mp-wp_genesis 2480 if ( is_array( $defaults ) )
mp-wp_genesis 2481 return array_merge( $defaults, $r );
mp-wp_genesis 2482 return $r;
mp-wp_genesis 2483 }
mp-wp_genesis 2484
mp-wp_genesis 2485 /**
mp-wp_genesis 2486 * Determines if Widgets library should be loaded.
mp-wp_genesis 2487 *
mp-wp_genesis 2488 * Checks to make sure that the widgets library hasn't already been loaded. If
mp-wp_genesis 2489 * it hasn't, then it will load the widgets library and run an action hook.
mp-wp_genesis 2490 *
mp-wp_genesis 2491 * @since 2.2.0
mp-wp_genesis 2492 * @uses add_action() Calls '_admin_menu' hook with 'wp_widgets_add_menu' value.
mp-wp_genesis 2493 */
mp-wp_genesis 2494 function wp_maybe_load_widgets() {
mp-wp_genesis 2495 if ( !function_exists( 'dynamic_sidebar' ) ) {
mp-wp_genesis 2496 require_once( ABSPATH . WPINC . '/widgets.php' );
mp-wp_genesis 2497 add_action( '_admin_menu', 'wp_widgets_add_menu' );
mp-wp_genesis 2498 }
mp-wp_genesis 2499 }
mp-wp_genesis 2500
mp-wp_genesis 2501 /**
mp-wp_genesis 2502 * Append the Widgets menu to the themes main menu.
mp-wp_genesis 2503 *
mp-wp_genesis 2504 * @since 2.2.0
mp-wp_genesis 2505 * @uses $submenu The administration submenu list.
mp-wp_genesis 2506 */
mp-wp_genesis 2507 function wp_widgets_add_menu() {
mp-wp_genesis 2508 global $submenu;
mp-wp_genesis 2509 $submenu['themes.php'][7] = array( __( 'Widgets' ), 'switch_themes', 'widgets.php' );
mp-wp_genesis 2510 ksort( $submenu['themes.php'], SORT_NUMERIC );
mp-wp_genesis 2511 }
mp-wp_genesis 2512
mp-wp_genesis 2513 /**
mp-wp_genesis 2514 * Flush all output buffers for PHP 5.2.
mp-wp_genesis 2515 *
mp-wp_genesis 2516 * Make sure all output buffers are flushed before our singletons our destroyed.
mp-wp_genesis 2517 *
mp-wp_genesis 2518 * @since 2.2.0
mp-wp_genesis 2519 */
mp-wp_genesis 2520 function wp_ob_end_flush_all() {
mp-wp_genesis 2521 while ( @ob_end_flush() );
mp-wp_genesis 2522 }
mp-wp_genesis 2523
mp-wp_genesis 2524 /**
mp-wp_genesis 2525 * Load the correct database class file.
mp-wp_genesis 2526 *
mp-wp_genesis 2527 * This function is used to load the database class file either at runtime or by
mp-wp_genesis 2528 * wp-admin/setup-config.php We must globalise $wpdb to ensure that it is
mp-wp_genesis 2529 * defined globally by the inline code in wp-db.php.
mp-wp_genesis 2530 *
mp-wp_genesis 2531 * @since 2.5.0
mp-wp_genesis 2532 * @global $wpdb WordPress Database Object
mp-wp_genesis 2533 */
mp-wp_genesis 2534 function require_wp_db() {
mp-wp_genesis 2535 global $wpdb;
mp-wp_genesis 2536 if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
mp-wp_genesis 2537 require_once( WP_CONTENT_DIR . '/db.php' );
mp-wp_genesis 2538 else
mp-wp_genesis 2539 require_once( ABSPATH . WPINC . '/wp-db.php' );
mp-wp_genesis 2540 }
mp-wp_genesis 2541
mp-wp_genesis 2542 /**
mp-wp_genesis 2543 * Load custom DB error or display WordPress DB error.
mp-wp_genesis 2544 *
mp-wp_genesis 2545 * If a file exists in the wp-content directory named db-error.php, then it will
mp-wp_genesis 2546 * be loaded instead of displaying the WordPress DB error. If it is not found,
mp-wp_genesis 2547 * then the WordPress DB error will be displayed instead.
mp-wp_genesis 2548 *
mp-wp_genesis 2549 * The WordPress DB error sets the HTTP status header to 500 to try to prevent
mp-wp_genesis 2550 * search engines from caching the message. Custom DB messages should do the
mp-wp_genesis 2551 * same.
mp-wp_genesis 2552 *
mp-wp_genesis 2553 * This function was backported to the the WordPress 2.3.2, but originally was
mp-wp_genesis 2554 * added in WordPress 2.5.0.
mp-wp_genesis 2555 *
mp-wp_genesis 2556 * @since 2.3.2
mp-wp_genesis 2557 * @uses $wpdb
mp-wp_genesis 2558 */
mp-wp_genesis 2559 function dead_db() {
mp-wp_genesis 2560 global $wpdb;
mp-wp_genesis 2561
mp-wp_genesis 2562 // Load custom DB error template, if present.
mp-wp_genesis 2563 if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
mp-wp_genesis 2564 require_once( WP_CONTENT_DIR . '/db-error.php' );
mp-wp_genesis 2565 die();
mp-wp_genesis 2566 }
mp-wp_genesis 2567
mp-wp_genesis 2568 // If installing or in the admin, provide the verbose message.
mp-wp_genesis 2569 if ( defined('WP_INSTALLING') || defined('WP_ADMIN') )
mp-wp_genesis 2570 wp_die($wpdb->error);
mp-wp_genesis 2571
mp-wp_genesis 2572 // Otherwise, be terse.
mp-wp_genesis 2573 status_header( 500 );
mp-wp_genesis 2574 nocache_headers();
mp-wp_genesis 2575 header( 'Content-Type: text/html; charset=utf-8' );
mp-wp_genesis 2576 ?>
mp-wp_genesis 2577 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
mp-wp_genesis 2578 <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) ) language_attributes(); ?>>
mp-wp_genesis 2579 <head>
mp-wp_genesis 2580 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
mp-wp_genesis 2581 <title>Database Error</title>
mp-wp_genesis 2582
mp-wp_genesis 2583 </head>
mp-wp_genesis 2584 <body>
mp-wp_genesis 2585 <h1>Error establishing a database connection</h1>
mp-wp_genesis 2586 </body>
mp-wp_genesis 2587 </html>
mp-wp_genesis 2588 <?php
mp-wp_genesis 2589 die();
mp-wp_genesis 2590 }
mp-wp_genesis 2591
mp-wp_genesis 2592 /**
mp-wp_genesis 2593 * Converts value to positive integer.
mp-wp_genesis 2594 *
mp-wp_genesis 2595 * @since 2.5.0
mp-wp_genesis 2596 *
mp-wp_genesis 2597 * @param mixed $maybeint Data you wish to have convered to an absolute integer
mp-wp_genesis 2598 * @return int An absolute integer
mp-wp_genesis 2599 */
mp-wp_genesis 2600 function absint( $maybeint ) {
mp-wp_genesis 2601 return abs( intval( $maybeint ) );
mp-wp_genesis 2602 }
mp-wp_genesis 2603
mp-wp_genesis 2604 /**
mp-wp_genesis 2605 * Determines if the blog can be accessed over SSL.
mp-wp_genesis 2606 *
mp-wp_genesis 2607 * Determines if blog can be accessed over SSL by using cURL to access the site
mp-wp_genesis 2608 * using the https in the siteurl. Requires cURL extension to work correctly.
mp-wp_genesis 2609 *
mp-wp_genesis 2610 * @since 2.5.0
mp-wp_genesis 2611 *
mp-wp_genesis 2612 * @return bool Whether or not SSL access is available
mp-wp_genesis 2613 */
mp-wp_genesis 2614 function url_is_accessable_via_ssl($url)
mp-wp_genesis 2615 {
mp-wp_genesis 2616 if (in_array('curl', get_loaded_extensions())) {
mp-wp_genesis 2617 $ssl = preg_replace( '/^http:\/\//', 'https://', $url );
mp-wp_genesis 2618
mp-wp_genesis 2619 $ch = curl_init();
mp-wp_genesis 2620 curl_setopt($ch, CURLOPT_URL, $ssl);
mp-wp_genesis 2621 curl_setopt($ch, CURLOPT_FAILONERROR, true);
mp-wp_genesis 2622 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
mp-wp_genesis 2623 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
mp-wp_genesis 2624
mp-wp_genesis 2625 curl_exec($ch);
mp-wp_genesis 2626
mp-wp_genesis 2627 $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
mp-wp_genesis 2628 curl_close ($ch);
mp-wp_genesis 2629
mp-wp_genesis 2630 if ($status == 200 || $status == 401) {
mp-wp_genesis 2631 return true;
mp-wp_genesis 2632 }
mp-wp_genesis 2633 }
mp-wp_genesis 2634 return false;
mp-wp_genesis 2635 }
mp-wp_genesis 2636
mp-wp_genesis 2637 /**
mp-wp_genesis 2638 * Secure URL, if available or the given URL.
mp-wp_genesis 2639 *
mp-wp_genesis 2640 * @since 2.5.0
mp-wp_genesis 2641 *
mp-wp_genesis 2642 * @param string $url Complete URL path with transport.
mp-wp_genesis 2643 * @return string Secure or regular URL path.
mp-wp_genesis 2644 */
mp-wp_genesis 2645 function atom_service_url_filter($url)
mp-wp_genesis 2646 {
mp-wp_genesis 2647 if ( url_is_accessable_via_ssl($url) )
mp-wp_genesis 2648 return preg_replace( '/^http:\/\//', 'https://', $url );
mp-wp_genesis 2649 else
mp-wp_genesis 2650 return $url;
mp-wp_genesis 2651 }
mp-wp_genesis 2652
mp-wp_genesis 2653 /**
mp-wp_genesis 2654 * Marks a function as deprecated and informs when it has been used.
mp-wp_genesis 2655 *
mp-wp_genesis 2656 * There is a hook deprecated_function_run that will be called that can be used
mp-wp_genesis 2657 * to get the backtrace up to what file and function called the deprecated
mp-wp_genesis 2658 * function.
mp-wp_genesis 2659 *
mp-wp_genesis 2660 * The current behavior is to trigger an user error if WP_DEBUG is defined and
mp-wp_genesis 2661 * is true.
mp-wp_genesis 2662 *
mp-wp_genesis 2663 * This function is to be used in every function in depreceated.php
mp-wp_genesis 2664 *
mp-wp_genesis 2665 * @package WordPress
mp-wp_genesis 2666 * @package Debug
mp-wp_genesis 2667 * @since 2.5.0
mp-wp_genesis 2668 * @access private
mp-wp_genesis 2669 *
mp-wp_genesis 2670 * @uses do_action() Calls 'deprecated_function_run' and passes the function name and what to use instead.
mp-wp_genesis 2671 * @uses apply_filters() Calls 'deprecated_function_trigger_error' and expects boolean value of true to do trigger or false to not trigger error.
mp-wp_genesis 2672 *
mp-wp_genesis 2673 * @param string $function The function that was called
mp-wp_genesis 2674 * @param string $version The version of WordPress that deprecated the function
mp-wp_genesis 2675 * @param string $replacement Optional. The function that should have been called
mp-wp_genesis 2676 */
mp-wp_genesis 2677 function _deprecated_function($function, $version, $replacement=null) {
mp-wp_genesis 2678
mp-wp_genesis 2679 do_action('deprecated_function_run', $function, $replacement);
mp-wp_genesis 2680
mp-wp_genesis 2681 // Allow plugin to filter the output error trigger
mp-wp_genesis 2682 if( defined('WP_DEBUG') && ( true === WP_DEBUG ) && apply_filters( 'deprecated_function_trigger_error', true )) {
mp-wp_genesis 2683 if( !is_null($replacement) )
mp-wp_genesis 2684 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) );
mp-wp_genesis 2685 else
mp-wp_genesis 2686 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) );
mp-wp_genesis 2687 }
mp-wp_genesis 2688 }
mp-wp_genesis 2689
mp-wp_genesis 2690 /**
mp-wp_genesis 2691 * Marks a file as deprecated and informs when it has been used.
mp-wp_genesis 2692 *
mp-wp_genesis 2693 * There is a hook deprecated_file_included that will be called that can be used
mp-wp_genesis 2694 * to get the backtrace up to what file and function included the deprecated
mp-wp_genesis 2695 * file.
mp-wp_genesis 2696 *
mp-wp_genesis 2697 * The current behavior is to trigger an user error if WP_DEBUG is defined and
mp-wp_genesis 2698 * is true.
mp-wp_genesis 2699 *
mp-wp_genesis 2700 * This function is to be used in every file that is depreceated
mp-wp_genesis 2701 *
mp-wp_genesis 2702 * @package WordPress
mp-wp_genesis 2703 * @package Debug
mp-wp_genesis 2704 * @since 2.5.0
mp-wp_genesis 2705 * @access private
mp-wp_genesis 2706 *
mp-wp_genesis 2707 * @uses do_action() Calls 'deprecated_file_included' and passes the file name and what to use instead.
mp-wp_genesis 2708 * @uses apply_filters() Calls 'deprecated_file_trigger_error' and expects boolean value of true to do trigger or false to not trigger error.
mp-wp_genesis 2709 *
mp-wp_genesis 2710 * @param string $file The file that was included
mp-wp_genesis 2711 * @param string $version The version of WordPress that deprecated the function
mp-wp_genesis 2712 * @param string $replacement Optional. The function that should have been called
mp-wp_genesis 2713 */
mp-wp_genesis 2714 function _deprecated_file($file, $version, $replacement=null) {
mp-wp_genesis 2715
mp-wp_genesis 2716 do_action('deprecated_file_included', $file, $replacement);
mp-wp_genesis 2717
mp-wp_genesis 2718 // Allow plugin to filter the output error trigger
mp-wp_genesis 2719 if( defined('WP_DEBUG') && ( true === WP_DEBUG ) && apply_filters( 'deprecated_file_trigger_error', true )) {
mp-wp_genesis 2720 if( !is_null($replacement) )
mp-wp_genesis 2721 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $file, $version, $replacement ) );
mp-wp_genesis 2722 else
mp-wp_genesis 2723 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $file, $version ) );
mp-wp_genesis 2724 }
mp-wp_genesis 2725 }
mp-wp_genesis 2726
mp-wp_genesis 2727 /**
mp-wp_genesis 2728 * Is the server running earlier than 1.5.0 version of lighttpd
mp-wp_genesis 2729 *
mp-wp_genesis 2730 * @since 2.5.0
mp-wp_genesis 2731 *
mp-wp_genesis 2732 * @return bool Whether the server is running lighttpd < 1.5.0
mp-wp_genesis 2733 */
mp-wp_genesis 2734 function is_lighttpd_before_150() {
mp-wp_genesis 2735 $server_parts = explode( '/', isset( $_SERVER['SERVER_SOFTWARE'] )? $_SERVER['SERVER_SOFTWARE'] : '' );
mp-wp_genesis 2736 $server_parts[1] = isset( $server_parts[1] )? $server_parts[1] : '';
mp-wp_genesis 2737 return 'lighttpd' == $server_parts[0] && -1 == version_compare( $server_parts[1], '1.5.0' );
mp-wp_genesis 2738 }
mp-wp_genesis 2739
mp-wp_genesis 2740 /**
mp-wp_genesis 2741 * Does the specified module exist in the apache config?
mp-wp_genesis 2742 *
mp-wp_genesis 2743 * @since 2.5.0
mp-wp_genesis 2744 *
mp-wp_genesis 2745 * @param string $mod e.g. mod_rewrite
mp-wp_genesis 2746 * @param bool $default The default return value if the module is not found
mp-wp_genesis 2747 * @return bool
mp-wp_genesis 2748 */
mp-wp_genesis 2749 function apache_mod_loaded($mod, $default = false) {
mp-wp_genesis 2750 global $is_apache;
mp-wp_genesis 2751
mp-wp_genesis 2752 if ( !$is_apache )
mp-wp_genesis 2753 return false;
mp-wp_genesis 2754
mp-wp_genesis 2755 if ( function_exists('apache_get_modules') ) {
mp-wp_genesis 2756 $mods = apache_get_modules();
mp-wp_genesis 2757 if ( in_array($mod, $mods) )
mp-wp_genesis 2758 return true;
mp-wp_genesis 2759 } elseif ( function_exists('phpinfo') ) {
mp-wp_genesis 2760 ob_start();
mp-wp_genesis 2761 phpinfo(8);
mp-wp_genesis 2762 $phpinfo = ob_get_clean();
mp-wp_genesis 2763 if ( false !== strpos($phpinfo, $mod) )
mp-wp_genesis 2764 return true;
mp-wp_genesis 2765 }
mp-wp_genesis 2766 return $default;
mp-wp_genesis 2767 }
mp-wp_genesis 2768
mp-wp_genesis 2769 /**
mp-wp_genesis 2770 * File validates against allowed set of defined rules.
mp-wp_genesis 2771 *
mp-wp_genesis 2772 * A return value of '1' means that the $file contains either '..' or './'. A
mp-wp_genesis 2773 * return value of '2' means that the $file contains ':' after the first
mp-wp_genesis 2774 * character. A return value of '3' means that the file is not in the allowed
mp-wp_genesis 2775 * files list.
mp-wp_genesis 2776 *
mp-wp_genesis 2777 * @since 1.2.0
mp-wp_genesis 2778 *
mp-wp_genesis 2779 * @param string $file File path.
mp-wp_genesis 2780 * @param array $allowed_files List of allowed files.
mp-wp_genesis 2781 * @return int 0 means nothing is wrong, greater than 0 means something was wrong.
mp-wp_genesis 2782 */
mp-wp_genesis 2783 function validate_file( $file, $allowed_files = '' ) {
mp-wp_genesis 2784 if ( false !== strpos( $file, '..' ))
mp-wp_genesis 2785 return 1;
mp-wp_genesis 2786
mp-wp_genesis 2787 if ( false !== strpos( $file, './' ))
mp-wp_genesis 2788 return 1;
mp-wp_genesis 2789
mp-wp_genesis 2790 if (':' == substr( $file, 1, 1 ))
mp-wp_genesis 2791 return 2;
mp-wp_genesis 2792
mp-wp_genesis 2793 if (!empty ( $allowed_files ) && (!in_array( $file, $allowed_files ) ) )
mp-wp_genesis 2794 return 3;
mp-wp_genesis 2795
mp-wp_genesis 2796 return 0;
mp-wp_genesis 2797 }
mp-wp_genesis 2798
mp-wp_genesis 2799 /**
mp-wp_genesis 2800 * Determine if SSL is used.
mp-wp_genesis 2801 *
mp-wp_genesis 2802 * @since 2.6.0
mp-wp_genesis 2803 *
mp-wp_genesis 2804 * @return bool True if SSL, false if not used.
mp-wp_genesis 2805 */
mp-wp_genesis 2806 function is_ssl() {
mp-wp_genesis 2807 return ( isset($_SERVER['HTTPS']) && 'on' == strtolower($_SERVER['HTTPS']) ) ? true : false;
mp-wp_genesis 2808 }
mp-wp_genesis 2809
mp-wp_genesis 2810 /**
mp-wp_genesis 2811 * Whether SSL login should be forced.
mp-wp_genesis 2812 *
mp-wp_genesis 2813 * @since 2.6.0
mp-wp_genesis 2814 *
mp-wp_genesis 2815 * @param string|bool $force Optional.
mp-wp_genesis 2816 * @return bool True if forced, false if not forced.
mp-wp_genesis 2817 */
mp-wp_genesis 2818 function force_ssl_login($force = '') {
mp-wp_genesis 2819 static $forced;
mp-wp_genesis 2820
mp-wp_genesis 2821 if ( '' != $force ) {
mp-wp_genesis 2822 $old_forced = $forced;
mp-wp_genesis 2823 $forced = $force;
mp-wp_genesis 2824 return $old_forced;
mp-wp_genesis 2825 }
mp-wp_genesis 2826
mp-wp_genesis 2827 return $forced;
mp-wp_genesis 2828 }
mp-wp_genesis 2829
mp-wp_genesis 2830 /**
mp-wp_genesis 2831 * Whether to force SSL used for the Administration Panels.
mp-wp_genesis 2832 *
mp-wp_genesis 2833 * @since 2.6.0
mp-wp_genesis 2834 *
mp-wp_genesis 2835 * @param string|bool $force
mp-wp_genesis 2836 * @return bool True if forced, false if not forced.
mp-wp_genesis 2837 */
mp-wp_genesis 2838 function force_ssl_admin($force = '') {
mp-wp_genesis 2839 static $forced;
mp-wp_genesis 2840
mp-wp_genesis 2841 if ( '' != $force ) {
mp-wp_genesis 2842 $old_forced = $forced;
mp-wp_genesis 2843 $forced = $force;
mp-wp_genesis 2844 return $old_forced;
mp-wp_genesis 2845 }
mp-wp_genesis 2846
mp-wp_genesis 2847 return $forced;
mp-wp_genesis 2848 }
mp-wp_genesis 2849
mp-wp_genesis 2850 /**
mp-wp_genesis 2851 * Guess the URL for the site.
mp-wp_genesis 2852 *
mp-wp_genesis 2853 * Will remove wp-admin links to retrieve only return URLs not in the wp-admin
mp-wp_genesis 2854 * directory.
mp-wp_genesis 2855 *
mp-wp_genesis 2856 * @since 2.6.0
mp-wp_genesis 2857 *
mp-wp_genesis 2858 * @return string
mp-wp_genesis 2859 */
mp-wp_genesis 2860 function wp_guess_url() {
mp-wp_genesis 2861 if ( defined('WP_SITEURL') && '' != WP_SITEURL ) {
mp-wp_genesis 2862 $url = WP_SITEURL;
mp-wp_genesis 2863 } else {
mp-wp_genesis 2864 $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
mp-wp_genesis 2865 $url = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
mp-wp_genesis 2866 }
mp-wp_genesis 2867 return $url;
mp-wp_genesis 2868 }
mp-wp_genesis 2869
mp-wp_genesis 2870 /**
mp-wp_genesis 2871 * Suspend cache invalidation.
mp-wp_genesis 2872 *
mp-wp_genesis 2873 * Turns cache invalidation on and off. Useful during imports where you don't wont to do invalidations
mp-wp_genesis 2874 * every time a post is inserted. Callers must be sure that what they are doing won't lead to an inconsistent
mp-wp_genesis 2875 * cache when invalidation is suspended.
mp-wp_genesis 2876 *
mp-wp_genesis 2877 * @since 2.7.0
mp-wp_genesis 2878 *
mp-wp_genesis 2879 * @param bool $suspend Whether to suspend or enable cache invalidation
mp-wp_genesis 2880 * @return bool The current suspend setting
mp-wp_genesis 2881 */
mp-wp_genesis 2882 function wp_suspend_cache_invalidation($suspend = true) {
mp-wp_genesis 2883 global $_wp_suspend_cache_invalidation;
mp-wp_genesis 2884
mp-wp_genesis 2885 $current_suspend = $_wp_suspend_cache_invalidation;
mp-wp_genesis 2886 $_wp_suspend_cache_invalidation = $suspend;
mp-wp_genesis 2887 return $current_suspend;
mp-wp_genesis 2888 }
mp-wp_genesis 2889
mp-wp_genesis 2890 /**
mp-wp_genesis 2891 * Copy an object.
mp-wp_genesis 2892 *
mp-wp_genesis 2893 * Returns a cloned copy of an object.
mp-wp_genesis 2894 *
mp-wp_genesis 2895 * @since 2.7.0
mp-wp_genesis 2896 *
mp-wp_genesis 2897 * @param object $object The object to clone
mp-wp_genesis 2898 * @return object The cloned object
mp-wp_genesis 2899 */
mp-wp_genesis 2900 function wp_clone($object) {
mp-wp_genesis 2901 return version_compare(phpversion(), '5.0') < 0 ? $object : clone($object);
mp-wp_genesis 2902 }
mp-wp_genesis 2903
mp-wp_genesis 2904
mp-wp_genesis 2905 ?>