diff --git a/wp-cache-config-sample.php b/wp-cache-config-sample.php index f943169c..53862716 100644 --- a/wp-cache-config-sample.php +++ b/wp-cache-config-sample.php @@ -5,13 +5,14 @@ See wp-cache.php for author details. */ -if ( ! defined('WPCACHEHOME') ) +if ( ! defined( 'WPCACHEHOME' ) ) { define( 'WPCACHEHOME', WP_PLUGIN_DIR . '/wp-super-cache/' ); +} $cache_compression = 0; // Super cache compression $cache_enabled = false; $super_cache_enabled = true; -$cache_max_time = 3600; //in seconds +$cache_max_time = 3600; // in seconds //$use_flock = true; // Set it true or false if you know what to use $cache_path = WP_CONTENT_DIR . '/cache/'; $file_prefix = 'wp-cache-'; @@ -20,8 +21,8 @@ // Array of files that have 'wp-' but should still be cached $cache_acceptable_files = array( 'wp-comments-popup.php', 'wp-links-opml.php', 'wp-locations.php' ); -$cache_rejected_uri = array('wp-.*\\.php', 'index\\.php'); -$cache_rejected_user_agent = array ( 0 => 'bot', 1 => 'ia_archive', 2 => 'slurp', 3 => 'crawl', 4 => 'spider', 5 => 'Yandex' ); +$cache_rejected_uri = array( 'wp-.*\\.php', 'index\\.php' ); +$cache_rejected_user_agent = array( 'bot', 'ia_archive', 'slurp', 'crawl', 'spider', 'Yandex' ); $cache_rebuild_files = 1; @@ -33,7 +34,7 @@ // Just modify it if you have conflicts with semaphores $sem_id = 5419; -if ( '/' != substr($cache_path, -1)) { +if ( '/' != substr( $cache_path, -1 ) ) { $cache_path .= '/'; } @@ -63,16 +64,16 @@ $wp_cache_debug_ip = ''; $wp_cache_debug_log = ''; $wp_cache_debug_email = ''; -$wp_cache_pages[ "search" ] = 0; -$wp_cache_pages[ "feed" ] = 0; -$wp_cache_pages[ "category" ] = 0; -$wp_cache_pages[ "home" ] = 0; -$wp_cache_pages[ "frontpage" ] = 0; -$wp_cache_pages[ "tag" ] = 0; -$wp_cache_pages[ "archives" ] = 0; -$wp_cache_pages[ "pages" ] = 0; -$wp_cache_pages[ "single" ] = 0; -$wp_cache_pages[ "author" ] = 0; +$wp_cache_pages['search'] = 0; +$wp_cache_pages['feed'] = 0; +$wp_cache_pages['category'] = 0; +$wp_cache_pages['home'] = 0; +$wp_cache_pages['frontpage'] = 0; +$wp_cache_pages['tag'] = 0; +$wp_cache_pages['archives'] = 0; +$wp_cache_pages['pages'] = 0; +$wp_cache_pages['single'] = 0; +$wp_cache_pages['author'] = 0; $wp_cache_hide_donation = 0; $wp_cache_not_logged_in = 0; $wp_cache_clear_on_post_edit = 0; @@ -102,4 +103,3 @@ $wpsc_save_headers = 0; $cache_schedule_interval = 'daily'; $wp_super_cache_comments = 1; -?> diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index da6b2696..cdc1eda1 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -1019,18 +1019,28 @@ function is_writeable_ACLSafe( $path ) { return true; } +function wpsc_var_export( $var ) { + + if ( is_string( $var ) ) { + return "'" . addslashes($var) . "'"; + } + elseif ( is_numeric( $var ) ) { + return strval( $var ); + } + elseif ( is_array( $var ) ) { + $str = implode( ', ', array_map( 'wpsc_var_export', $var ) ); + return empty( $str ) ? 'array()' : 'array( ' . $str . ' )'; + } + + return str_replace( PHP_EOL, ' ', var_export( $var, true ) ); +} + function wp_cache_setting( $field, $value ) { - global $wp_cache_config_file; - - $GLOBALS[ $field ] = $value; - if ( is_numeric( $value ) ) { - wp_cache_replace_line( '^ *\$' . $field, "\$$field = $value;", $wp_cache_config_file ); - } elseif ( is_object( $value ) || is_array( $value ) ) { - $text = var_export( $value, true ); - $text = preg_replace( '/[\s]+/', ' ', $text ); - wp_cache_replace_line( '^ *\$' . $field, "\$$field = $text;", $wp_cache_config_file ); - } else { - wp_cache_replace_line( '^ *\$' . $field, "\$$field = '$value';", $wp_cache_config_file ); + + if ( $value !== $GLOBALS[ $field ] ) { + $new_value = '$' . $field . ' = ' . wpsc_var_export( $value ) . ';'; + wp_cache_replace_line( '^\s*\$' . $field . '\s*=', $new_value , $GLOBALS['wp_cache_config_file'] ); + $GLOBALS[ $field ] = $value; } } @@ -1081,15 +1091,31 @@ function wp_cache_replace_line( $old, $new, $my_file ) { } } } else { - $done = false; + $reg_exps = array( '/^\s*define\s*\(/', '/^\s*\$/' ); + foreach( $reg_exps as $reg_exp ) { + if ( preg_match( $reg_exp, $new ) ) { + break; + } + } + + $done = false; + $state = false; foreach( (array) $lines as $line ) { - if ( $done || ! preg_match( '/^(if\ \(\ \!\ )?define|\$|\?>/', $line ) ) { - fputs($fd, $line); - } else { + + if ( false !== strpos( $line, '{' ) ) { + $state = true; + } + + // Insert new line before first variable/constant. + if ( ! $done && ! $state && preg_match( $reg_exp, $line ) ) { fputs($fd, "$new\n"); - fputs($fd, $line); $done = true; } + fputs($fd, $line); + + if ( false !== strpos( $line, '}' ) ) { + $state = false; + } } } fclose( $fd ); diff --git a/wp-cache.php b/wp-cache.php index 034927a4..4f43286a 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -1443,7 +1443,7 @@ function wp_update_lock_down() { if ( isset( $_POST[ 'wp_lock_down' ] ) && $valid_nonce ) { $wp_lock_down = $_POST[ 'wp_lock_down' ] == '1' ? '1' : '0'; - wp_cache_replace_line( '^.*WPLOCKDOWN', "if ( ! defined( 'WPLOCKDOWN' ) ) define( 'WPLOCKDOWN', '$wp_lock_down' );", $wp_cache_config_file ); + wp_cache_replace_line( '^.*WPLOCKDOWN', "defined( 'WPLOCKDOWN' ) && define( 'WPLOCKDOWN', '$wp_lock_down' );", $wp_cache_config_file ); if ( false == defined( 'WPLOCKDOWN' ) ) define( 'WPLOCKDOWN', $wp_lock_down ); if ( $wp_lock_down == '0' && function_exists( 'prune_super_cache' ) ) @@ -1707,7 +1707,7 @@ function wp_cache_time_update() { } function wp_cache_edit_max_time() { - global $cache_max_time, $wp_cache_config_file, $valid_nonce, $super_cache_enabled, $cache_schedule_type, $cache_scheduled_time, $cache_schedule_interval, $cache_time_interval, $cache_gc_email_me, $wp_cache_preload_on; + global $cache_max_time, $super_cache_enabled, $cache_schedule_type, $cache_scheduled_time, $cache_schedule_interval, $cache_time_interval, $cache_gc_email_me, $wp_cache_preload_on; $timezone_format = _x('Y-m-d G:i:s', 'timezone date format'); @@ -1787,6 +1787,11 @@ function wp_cache_edit_max_time() { } function wp_cache_sanitize_value($text, & $array) { + + if ( function_exists( '_deprecated_function' ) ) { + _deprecated_function( __FUNCTION__, 'WP Super Cache 1.5.9' ); + } + $text = esc_html(strip_tags($text)); $array = preg_split("/[\s,]+/", chop($text)); $text = var_export($array, true); @@ -1810,23 +1815,19 @@ function apache_request_headers() { } function wp_cache_update_rejected_ua() { - global $cache_rejected_user_agent, $wp_cache_config_file, $valid_nonce; if ( !function_exists( 'apache_request_headers' ) ) return; - if ( isset( $_POST[ 'wp_rejected_user_agent' ] ) && $valid_nonce ) { - $_POST[ 'wp_rejected_user_agent' ] = str_replace( ' ', '___', $_POST[ 'wp_rejected_user_agent' ] ); - $text = str_replace( '___', ' ', wp_cache_sanitize_value( $_POST[ 'wp_rejected_user_agent' ], $cache_rejected_user_agent ) ); - wp_cache_replace_line( '^ *\$cache_rejected_user_agent', "\$cache_rejected_user_agent = $text;", $wp_cache_config_file ); - foreach( $cache_rejected_user_agent as $k => $ua ) { - $cache_rejected_user_agent[ $k ] = str_replace( '___', ' ', $ua ); - } - reset( $cache_rejected_user_agent ); + if ( isset( $_POST['wp_rejected_user_agent'], $_POST['_wpnonce'] ) + && wp_verify_nonce( $_POST['_wpnonce'], 'wp-cache' ) + ) { + $array = preg_split( "/[\r\n,]+/", stripslashes( $_POST['wp_rejected_user_agent'] ) ); + $array = array_map( 'trim', array_filter( $array ) ); + wp_cache_setting( 'cache_rejected_user_agent', $array ); } } function wp_cache_edit_rejected_ua() { - global $cache_rejected_user_agent, $wp_cache_config_file, $valid_nonce; if ( !function_exists( 'apache_request_headers' ) ) return; @@ -1836,8 +1837,8 @@ function wp_cache_edit_rejected_ua() { echo "
" . __( 'Strings in the HTTP ’User Agent’ header that prevent WP-Cache from caching bot, spiders, and crawlers’ requests. Note that super cached files are still sent to these agents if they already exists.', 'wp-super-cache' ) . "
\n"; echo '