diff -r 53cff4b4a802 -r bde1974c263b web/wp-content/plugins/wp-super-cache/wp-cache.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/wp-content/plugins/wp-super-cache/wp-cache.php Wed Feb 03 15:37:20 2010 +0000 @@ -0,0 +1,1792 @@ + + +'; + echo "

" . __( 'WP Super Cache Manager', 'wp-super-cache' ) . "

\n"; + if( 1 == ini_get( 'safe_mode' ) || "on" == strtolower( ini_get( 'safe_mode' ) ) ) { + ?>

+

"; + echo sprintf( __( 'You or an administrator may be able to make it work by changing the group owner of the plugin scripts to match that of the web server user. The group owner of the %s/cache/ directory must also be changed. See the safe mode manual page for further details.', 'wp-super-cache' ), WP_CONTENT_DIR ) . "

"; + } else { + echo __( 'You or an administrator must disable this. See the safe mode manual page for further details. This cannot be disabled in a .htaccess file unfortunately. It must be done in the php.ini config file.', 'wp-super-cache' ) . "

"; + } + } + + if ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 1 && !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) { + wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' ); + if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'scheduled wp_cache_check_site_hook for 360 seconds time.', 2 ); + } + + if(isset($_REQUEST['wp_restore_config']) && $valid_nonce) { + unlink($wp_cache_config_file); + echo '' . __( 'Configuration file changed, some values might be wrong. Load the page again from the "Settings" menu to reset them.', 'wp-super-cache' ) . ''; + } + + if ( !wp_cache_check_link() || + !wp_cache_verify_config_file() || + !wp_cache_verify_cache_dir() ) { + echo '

' . __( "Cannot continue... fix previous problems and retry.", 'wp-super-cache' ) . '

'; + echo "\n"; + return; + } + + if (!wp_cache_check_global_config()) { + echo "\n"; + return; + } + if( $wp_cache_debug || !$wp_cache_cron_check ) { + if( function_exists( "wp_remote_get" ) == false ) { + $hostname = str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'siteurl' ) ) ); + if( strpos( $hostname, '/' ) ) + $hostname = substr( $hostname, 0, strpos( $hostname, '/' ) ); + $ip = gethostbyname( $hostname ); + if( substr( $ip, 0, 3 ) == '127' || substr( $ip, 0, 7 ) == '192.168' ) { + ?>

+
+

+

Troubleshooting section of the readme.txt', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/wp-super-cache/faq/' ); ?>

+
+ 0.01, 'blocking' => true)); + if( is_array( $cron ) ) { + if( $cron[ 'response' ][ 'code' ] == '404' ) { + ?>

Warning! wp-cron.php not found!

+
+

+

Troubleshooting section of the readme.txt', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/wp-super-cache/faq/' ); ?>

+
+

+

+

+

chmod 755 /

'; + ?> +
+

'; + ?> +
+
+
+

+

+

+

+ +

+ +

+

+

" . __( 'Mobile rewrite rules detected', 'wp-super-cache' ) . "

"; + echo "

" . __( 'For best performance you should enable "Mobile device support" or delete the mobile rewrite rules in your .htaccess. Look for the 2 lines with the text "Android|2.0\ MMP|240x320|AvantGo|BlackBerry|Blazer|Cellphone" and delete those.', 'wp-super-cache' ) . "

" . __( 'This will have no affect on ordinary users but mobile users will see uncached pages.', 'wp-super-cache' ) . "

"; + } elseif ( $wp_cache_mobile_enabled && $scrules != '' && false === strpos( $scrules, '240x320|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo' ) ) { + ?> +

+

  1. 1.
  2. +
  3. 2. # BEGIN WPSuperCache and # END WPSuperCache and let the plugin regenerate them by reloading this page.', 'wp-super-cache' ), $home_path ); ?>
  4. +
  5. 3. # BEGIN WPSuperCache and # END WPSuperCache. There are two sections that look very similar. Just below the line %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$ add this line: (do it twice, once for each section)', 'wp-super-cache' ), $home_path ); ?>

    +
    RewriteCond %{HTTP_user_agent} !^.*(Android|2.0\ MMP|240x320|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|hiptop|IEMobile|iPhone|iPod|KYOCERA/WX310K|LG/U990|MIDP-2.0|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|Playstation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|Windows\ CE|WinWAP).*
+ +

%s is writeable by the webserver so the files advanced-cache.php and cache-config.php can be deleted automatically. (Making sure those files are writeable too is probably a good idea!)', 'wp-super-cache' ), WP_CONTENT_DIR ); ?>

+

uninstall script to remove files and directories created by the plugin. (Please see readme.txt for instructions on uninstalling this script.)', 'wp-super-cache' ), WP_PLUGIN_URL ); ?>

+ "; + wp_nonce_field('wp-cache'); + ?> + + __( 'Required to serve compressed supercache files properly.', 'wp-super-cache' ), 'mod_headers' => __( 'Required to set caching information on supercache pages. IE7 users will see old pages without this module.', 'wp-super-cache' ), 'mod_expires' => __( 'Set the expiry date on supercached pages. Visitors may not see new pages when they refresh or leave comments without this module.', 'wp-super-cache' ) ); + foreach( $required_modules as $req => $desc ) { + if( !in_array( $req, $mods ) ) { + $missing_mods[ $req ] = $desc; + } + } + if( isset( $missing_mods) && is_array( $missing_mods ) ) { + echo "

" . __( 'Missing Apache Modules', 'wp-super-cache' ) . "

"; + echo "

" . __( 'The following Apache modules are missing. The plugin will work in half-on mode without them. In full Supercache mode, your visitors may see corrupted pages or out of date content however.', 'wp-super-cache' ) . "

"; + echo "
    "; + foreach( $missing_mods as $req => $desc ) { + echo "
  • $req - $desc
  • "; + } + echo "
"; + } + } + ?> +
+
+
+

+ +

* by buying me an Amazon gift card! Make it out to "%3$s" for whatever amount you want. Every penny helps!', 'wp-super-cache' ), 'WP Super Cache', 'http://ocaoimh.ie/agc', 'donncha@ocaoimh.ie' ) ?>;

+

wishlist.', 'wp-super-cache' ), 'http://ocaoimh.ie/wish' ); ?>

+


Donncha
+ *

+
+
+ + + +
+
+

' />

+
+ +

WP Super Cache', 'Donncha O Caoimh' ); ?>

+

wishes he had more time to read and relax.', 'wp-super-cache' ), 'Holy Shmoly', 'In Photos.org', 'http://ocaoimh.ie/gad' ); ?>

+

Twitter' ); ?>

+ +

%2$s', 'wp-super-cache' ), date( 'M j, Y', $start_date ), number_format( get_option( 'wpsupercache_count' ) ) ); ?>

+

    + {$url[ 'url' ]}\n"; + } + ?>
+ +

+
+ +
+

' . __( 'Accepted Filenames & Rejected URIs', 'wp-super-cache' ) . '

'; + wp_cache_edit_rejected_pages(); + echo "\n"; + wp_cache_edit_rejected(); + echo "\n"; + wp_cache_edit_accepted(); + echo '
'; + + wp_cache_edit_rejected_ua(); + + wp_cache_debug_settings(); + + wp_lock_down(); + + wp_cache_restore(); + + ob_start(); + if( defined( 'WP_CACHE' ) ) { + if( function_exists( 'do_cacheaction' ) ) { + do_cacheaction( 'cache_admin_page' ); + } + } + $out = ob_get_contents(); + ob_end_clean(); + if( SUBMITDISABLED == ' ' && $out != '' ) { + echo '

' . __( 'Cache Plugins', 'wp-super-cache' ) . '

'; + echo $out; + echo '
'; + } + + echo "\n"; +} + +function wsc_mod_rewrite() { + global $cache_enabled, $super_cache_enabled, $cache_compression, $cache_compression_changed, $valid_nonce, $cache_path; + if( $super_cache_enabled == false && $cache_enabled == true ) { + ?>

+

HALF ON mode.', 'wp-super-cache' ); ?>

+ + +
+

+
+ + +

+

'; + wp_nonce_field('wp-cache'); + echo "
\n"; + ?>
+ + +
+

\n"; + $rules .= "RewriteEngine On\n"; + $rules .= "RewriteBase $home_root\n"; // props Chris Messina + $charset = get_option('blog_charset') == '' ? 'UTF-8' : get_option('blog_charset'); + $rules .= "AddDefaultCharset {$charset}\n"; + $rules .= "CONDITION_RULES"; + $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n"; + $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz -f\n"; + $rules .= "RewriteRule ^(.*) {$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz [L]\n\n"; + + $rules .= "CONDITION_RULES"; + $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html -f\n"; + $rules .= "RewriteRule ^(.*) {$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html [L]\n"; + $rules .= "\n"; + $rules = apply_filters( 'supercacherewriterules', $rules ); + + $rules = str_replace( "CONDITION_RULES", implode( "\n", $condition_rules ) . "\n", $rules ); + + $dohtaccess = true; + if( function_exists( 'is_site_admin' ) ) { + echo "

" . __( 'WordPress MU Detected', 'wp-super-cache' ) . "

" . __( "Unfortunately the rewrite rules cannot be updated automatically when running WordPress MU. Please open your .htaccess and add the following mod_rewrite rules above any other rules in that file.", 'wp-super-cache' ) . "

"; + } elseif( !$wprules || $wprules == '' ) { + echo "

" . __( 'Mod Rewrite rules cannot be updated!', 'wp-super-cache' ) . "

"; + echo "

" . sprintf( __( "You must have BEGIN and END markers in %s.htaccess for the auto update to work. They look like this and surround the main WordPress mod_rewrite rules:", 'wp-super-cache' ), $home_path ); + echo "

# BEGIN WordPress\n RewriteCond %{REQUEST_FILENAME} !-f\n RewriteCond %{REQUEST_FILENAME} !-d\n RewriteRule . /index.php [L]\n # END WordPress
"; + _e( 'Refresh this page when you have updated your .htaccess file.', 'wp-super-cache' ); + echo "
"; + return; + } elseif( strpos( $wprules, 'wordpressuser' ) ) { // Need to clear out old mod_rewrite rules + echo "

" . __( 'Thank you for upgrading.', 'wp-super-cache' ) . " " . sprintf( __( 'The mod_rewrite rules changed since you last installed this plugin. Unfortunately you must remove the old supercache rules before the new ones are updated. Refresh this page when you have edited your .htaccess file. If you wish to manually upgrade, change the following line: %1$s so it looks like this: %2$s The only changes are "HTTP_COOKIE" becomes "HTTP:Cookie" and "wordpressuser" becomes "wordpress". This is a WordPress 2.5 change but it’s backwards compatible with older versions if you’re brave enough to use them.', 'wp-super-cache' ), '

RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
', '
RewriteCond %{HTTP:Cookie} !^.*wordpress.*$
' ) . "

"; + echo ""; + return; + } elseif( $scrules != '' && strpos( $scrules, '%{REQUEST_URI} !^.*[^/]$' ) === false && substr( get_option( 'permalink_structure' ), -1 ) == '/' ) { // permalink structure has a trailing slash, need slash check in rules. + echo "

" . __( 'Trailing slash check required.', 'wp-super-cache' ) . "

" . __( 'It looks like your blog has URLs that end with a "/". Unfortunately since you installed this plugin a duplicate content bug has been found where URLs not ending in a "/" end serve the same content as those with the "/" and do not redirect to the proper URL. To fix, you must edit your .htaccess file and add these two rules to the two groups of Super Cache rules:', 'wp-super-cache' ) . "

"; + echo "
RewriteCond %{REQUEST_URI} !^.*[^/]$RewriteCond %{REQUEST_URI} !^.*//.*$
"; + echo "

" . __( 'You can see where the rules go and examine the complete rules by clicking the "View mod_rewrite rules" link below.', 'wp-super-cache' ) . "

"; + $dohtaccess = false; + } elseif( strpos( $scrules, 'supercache' ) || strpos( $wprules, 'supercache' ) ) { // only write the rules once + $dohtaccess = false; + } + // cache/.htaccess rules + $gziprules = "\n \n ForceType text/html\n FileETag None\n \n AddEncoding gzip .gz\n AddType text/html .gz\n\n"; + $gziprules .= "\n SetEnvIfNoCase Request_URI \.gz$ no-gzip\n\n"; + $gziprules .= "\n Header set Vary \"Accept-Encoding, Cookie\"\n Header set Cache-Control 'max-age=300, must-revalidate'\n\n"; + $gziprules .= "\n ExpiresActive On\n ExpiresByType text/html A300\n\n"; + if( $dohtaccess && !$_POST[ 'updatehtaccess' ] ) { + if( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) { + echo "

" . __( 'Cannot update .htaccess', 'wp-super-cache' ) . "

" . sprintf( __( 'The file %s.htaccess cannot be modified by the web server. Please correct this using the chmod command or your ftp client.', 'wp-super-cache' ), $home_path ) . "

" . __( 'Refresh this page when the file permissions have been modified.' ) . "

" . sprintf( __( 'Alternatively, you can edit your %s.htaccess file manually and add the following code (before any WordPress rules):', 'wp-super-cache' ), $home_path ) . "

"; + echo "

# BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache

"; + } else { + echo "

" . sprintf( __( 'To serve static html files your server must have the correct mod_rewrite rules added to a file called %s.htaccess', 'wp-super-cache' ), $home_path ) . " "; + if( !function_exists( 'is_site_admin' ) ) { + _e( "You must edit the file yourself add the following rules.", 'wp-super-cache' ); + } else { + _e( "You can edit the file yourself add the following rules.", 'wp-super-cache' ); + } + echo __( " Make sure they appear before any existing WordPress rules. ", 'wp-super-cache' ) . "

"; + echo "
# BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache

"; + echo "

" . sprintf( __( 'Rules must be added to %s too:', 'wp-super-cache' ), WP_CONTENT_DIR . "/cache/.htaccess" ) . "

"; + echo "
# BEGIN supercache\n" . wp_specialchars( $gziprules ) . "# END supercache

"; + if( !function_exists( 'is_site_admin' ) ) { + echo '
'; + echo ''; + echo '
'; + wp_nonce_field('wp-cache'); + echo "
\n"; + } + } + } elseif( $dohtaccess && $valid_nonce && $_POST[ 'updatehtaccess' ] ) { + wpsc_remove_marker( $home_path.'.htaccess', 'WordPress' ); // remove original WP rules so SuperCache rules go on top + echo "
"; + if( insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', explode( "\n", $rules ) ) && insert_with_markers( $home_path.'.htaccess', 'WordPress', explode( "\n", $wprules ) ) ) { + echo "

" . __( 'Mod Rewrite rules updated!', 'wp-super-cache' ) . "

"; + echo "

" . sprintf( __( '%s.htaccess has been updated with the necessary mod_rewrite rules. Please verify they are correct. They should look like this:', 'wp-super-cache' ), $home_path ) . "

\n"; + } else { + echo "

" . __( 'Mod Rewrite rules must be updated!', 'wp-super-cache' ) . "

"; + echo "

" . sprintf( __( 'Your %s.htaccess is not writable by the webserver and must be updated with the necessary mod_rewrite rules. The new rules go above the regular WordPress rules as shown in the code below:', 'wp-super-cache' ), $home_path ) . "

\n"; + } + echo "

" . wp_specialchars( $rules ) . "

\n
"; + } else { + ?> +

Click the following link to see the lines added to that file. If you have upgraded the plugin make sure these rules match.', 'wp-super-cache' ), $home_path ); ?>

+ +

+ " . sprintf( __( 'Gzip encoding rules in %s.htaccess created.', 'wp-super-cache' ), $cache_path ) . ""; + } + + ?>

' . __( 'Fix Configuration', 'wp-super-cache' ) . '

'; + echo '
'; + echo ''; + echo '
'; + wp_nonce_field('wp-cache'); + echo "
\n"; + echo ''; + +} + +function comment_form_lockdown_message() { + ?>

+
+

' . __( 'Disabled', 'wp-super-cache' ) . '' : '' . __( 'Enabled', 'wp-super-cache' ) . ''; ?>

+

+

+

if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) ) { +     echo ""; + }
+

'; + echo ""; + echo "
"; + wp_nonce_field('wp-cache'); + echo "\n"; + + ?>
+
+

escape( $page ); + if( $page != '' ) { + $cached_direct_pages[] = $page; + $out .= "'$page', "; + } + } + if( $out == '' ) { + $out = "'', "; + } + } + if( $valid_nonce && $_POST[ 'new_direct_page' ] && '' != $_POST[ 'new_direct_page' ] ) { + $page = str_replace( get_option( 'siteurl' ), '', $_POST[ 'new_direct_page' ] ); + if( substr( $page, 0, 1 ) != '/' ) + $page = '/' . $page; + $page = $wpdb->escape( $page ); + if( in_array( $page, $cached_direct_pages ) == false ) { + $cached_direct_pages[] = $page; + $out .= "'$page', "; + } + } + + if( $out != '' ) { + $out = substr( $out, 0, -2 ); + $out = '$cached_direct_pages = array( ' . $out . ' );'; + wp_cache_replace_line('^ *\$cached_direct_pages', "$out", $wp_cache_config_file); + prune_super_cache( $cache_path, true ); + } + + if( !empty( $expiredfiles ) ) { + foreach( $expiredfiles as $file ) { + if( $file != '' ) { + $firstfolder = explode( '/', $file ); + $firstfolder = ABSPATH . $firstfolder[1]; + $file = ABSPATH . $file; + @unlink( trailingslashit( $file ) . 'index.html' ); + @unlink( trailingslashit( $file ) . 'index.html.gz' ); + RecursiveFolderDelete( trailingslashit( $firstfolder ) ); + } + } + } + + if( $valid_nonce && $_POST[ 'deletepage' ] ) { + $page = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_POST['deletepage']) ); + $pagefile = ABSPATH . $page . 'index.html'; + $firstfolder = explode( '/', $page ); + $firstfolder = ABSPATH . $firstfolder[1]; + $page = ABSPATH . $page; + if( is_file( $pagefile ) && is_writeable_ACLSafe( $pagefile ) && is_writeable_ACLSafe( $firstfolder ) ) { + @unlink( $pagefile ); + @unlink( $pagefile . '.gz' ); + RecursiveFolderDelete( $firstfolder ); + echo "" . sprintf( __( '%s removed!', 'wp-super-cache' ), $pagefile ) . ""; + prune_super_cache( $cache_path, true ); + } + } + + $readonly = ''; + if( !is_writeable_ACLSafe( ABSPATH ) ) { + $readonly = 'READONLY'; + ?>

'; + if( is_array( $cached_direct_pages ) ) { + $out = ''; + foreach( $cached_direct_pages as $page ) { + if( $page == '' ) + continue; + $generated = ''; + if( is_file( ABSPATH . $page . '/index.html' ) ) + $generated = ''; + $out .= "$generated"; + } + if( $out != '' ) { + ?>"; + } + } + if( $readonly != 'READONLY' ) + echo __( "Add direct page:", 'wp-super-cache' ) . ""; + + echo "

" . sprintf( __( "Directly cached files are files created directly off %s where your blog lives. This feature is only useful if you are expecting a major Digg or Slashdot level of traffic to one post or page.", 'wp-super-cache' ), ABSPATH ) . "

"; + if( $readonly != 'READONLY' ) { + echo "

" . sprintf( __( 'For example: to cache %1$sabout/, you would enter %1$sabout/ or /about/. The cached file will be generated the next time an anonymous user visits that page.', 'wp-super-cache' ), trailingslashit( get_option( 'siteurl' ) ) ) . "

"; + echo "

" . __( 'Make the textbox blank to remove it from the list of direct pages and delete the cached file.', 'wp-super-cache' ) . "

"; + } + + wp_nonce_field('wp-cache'); + if( $readonly != 'READONLY' ) + echo "
"; + echo "\n"; + ?> 0) { + $cache_max_time = $max_time; + wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file); + } + } + ?>
+ +

'; + echo ' '; + echo " " . __( "seconds", 'wp-super-cache' ); + echo "

" . __( 'Garbage Collection', 'wp-super-cache' ) . "

" . __( 'If expiry time is more than 1800 seconds (half an hour), garbage collection will be done every 10 minutes, otherwise it will happen 10 seconds after the expiry time above.', 'wp-super-cache' ) . "

"; + echo "

" . __( 'Checking for and deleting expired files is expensive, but it’s expensive leaving them there too. On a very busy site you should set the expiry time to 300 seconds. Experiment with different values and visit this page to see how many expired files remain at different times during the day. Aim to have less than 500 cached files if possible.', 'wp-super-cache' ) . "

"; + echo '
'; + wp_nonce_field('wp-cache'); + echo "\n"; + ?>

' . __( 'Rejected User Agents', 'wp-super-cache' ) . '

'; + 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 '
'; + echo ' '; + echo '
'; + wp_nonce_field('wp-cache'); + echo ''; + echo "
\n"; +} + +function wp_cache_edit_rejected_pages() { + global $wp_cache_config_file, $valid_nonce, $wp_cache_pages; + + if ( isset( $_POST[ 'wp_edit_rejected_pages' ] ) && $valid_nonce ) { + $pages = array( 'single', 'pages', 'archives', 'tag', 'frontpage', 'home', 'category', 'feed', 'search' ); + foreach( $pages as $page ) { + if ( isset( $_POST[ 'wp_cache_pages' ][ $page ] ) ) { + $value = 1; + } else { + $value = 0; + } + wp_cache_replace_line('^ *\$wp_cache_pages\[ "' . $page . '" \]', "\$wp_cache_pages[ \"{$page}\" ] = $value;", $wp_cache_config_file); + $wp_cache_pages[ $page ] = $value; + } + } + + echo ''; + echo '

' . __( 'Do not cache the following page types. See the Conditional Tags documentation for a complete discussion on each type.', 'wp-super-cache' ) . '

'; + echo ''; + echo ''; + echo '
'; + echo '
'; + echo '
'; + echo '  
'; + echo '
'; + echo '  
'; + echo '  
'; + echo '
'; + echo '
'; + + echo '
'; + wp_nonce_field('wp-cache'); + echo "\n"; + +} + +function wp_cache_edit_rejected() { + global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file, $valid_nonce; + + if(isset($_REQUEST['wp_rejected_uri']) && $valid_nonce) { + $text = wp_cache_sanitize_value( str_replace( '\\\\', '\\', $_REQUEST['wp_rejected_uri'] ), $cache_rejected_uri ); + wp_cache_replace_line('^ *\$cache_rejected_uri', "\$cache_rejected_uri = $text;", $wp_cache_config_file); + } + + + echo ''; + echo ''; + echo "

" . __( 'Add here strings (not a filename) that forces a page not to be cached. For example, if your URLs include year and you dont want to cache last year posts, it’s enough to specify the year, i.e. ’/2004/’. WP-Cache will search if that string is part of the URI and if so, it will not cache that page.', 'wp-super-cache' ) . "

\n"; + echo ' '; + echo '
'; + wp_nonce_field('wp-cache'); + echo "\n"; +} + +function wp_cache_edit_accepted() { + global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file, $valid_nonce; + + if(isset($_REQUEST['wp_accepted_files']) && $valid_nonce) { + $text = wp_cache_sanitize_value($_REQUEST['wp_accepted_files'], $cache_acceptable_files); + wp_cache_replace_line('^ *\$cache_acceptable_files', "\$cache_acceptable_files = $text;", $wp_cache_config_file); + } + + + echo ''; + echo '
'; + echo "

" . __( 'Add here those filenames that can be cached, even if they match one of the rejected substring specified above.', 'wp-super-cache' ) . "

\n"; + echo ' '; + echo '
'; + wp_nonce_field('wp-cache'); + echo "\n"; +} + +function wp_cache_debug_settings() { + global $wp_super_cache_debug, $wp_cache_debug_email, $wp_cache_debug_log, $wp_cache_debug_level, $wp_cache_debug_ip, $cache_path, $valid_nonce, $wp_cache_config_file, $wp_cache_debug_to_file; + global $wp_super_cache_front_page_check, $wp_super_cache_front_page_clear, $wp_super_cache_front_page_text, $wp_super_cache_front_page_notification, $wp_super_cache_advanced_debug; + + if ( !isset( $wp_cache_debug_level ) ) + $wp_cache_debug_level = 1; + if ( isset( $_POST[ 'wp_cache_debug' ] ) && $valid_nonce ) { + $wp_super_cache_debug = intval( $_POST[ 'wp_super_cache_debug' ] ); + wp_cache_replace_line('^ *\$wp_super_cache_debug', "\$wp_super_cache_debug = '$wp_super_cache_debug';", $wp_cache_config_file); + $wp_cache_debug_email = wp_specialchars( $_POST[ 'wp_cache_debug_email' ] ); + wp_cache_replace_line('^ *\$wp_cache_debug_email', "\$wp_cache_debug_email = '$wp_cache_debug_email';", $wp_cache_config_file); + $wp_cache_debug_to_file = intval( $_POST[ 'wp_cache_debug_to_file' ] ); + if ( $wp_cache_debug_to_file && ( ( isset( $wp_cache_debug_log ) && $wp_cache_debug_log == '' ) || !isset( $wp_cache_debug_log ) ) ) { + $wp_cache_debug_log = md5( time() ) . ".txt"; + } elseif( $wp_cache_debug_to_file == false ) { + $wp_cache_debug_log = ""; + } + wp_cache_replace_line('^ *\$wp_cache_debug_to_file', "\$wp_cache_debug_to_file = '$wp_cache_debug_to_file';", $wp_cache_config_file); + wp_cache_replace_line('^ *\$wp_cache_debug_log', "\$wp_cache_debug_log = '$wp_cache_debug_log';", $wp_cache_config_file); + $wp_cache_debug_ip = wp_specialchars( $_POST[ 'wp_cache_debug_ip' ] ); + wp_cache_replace_line('^ *\$wp_cache_debug_ip', "\$wp_cache_debug_ip = '$wp_cache_debug_ip';", $wp_cache_config_file); + $wp_cache_debug_level = (int)$_POST[ 'wp_cache_debug_level' ]; + wp_cache_replace_line('^ *\$wp_cache_debug_level', "\$wp_cache_debug_level = '$wp_cache_debug_level';", $wp_cache_config_file); + $wp_super_cache_front_page_check = (int)$_POST[ 'wp_super_cache_front_page_check' ]; + wp_cache_replace_line('^ *\$wp_super_cache_front_page_check', "\$wp_super_cache_front_page_check = '$wp_super_cache_front_page_check';", $wp_cache_config_file); + $wp_super_cache_front_page_clear = (int)$_POST[ 'wp_super_cache_front_page_clear' ]; + wp_cache_replace_line('^ *\$wp_super_cache_front_page_clear', "\$wp_super_cache_front_page_clear = '$wp_super_cache_front_page_clear';", $wp_cache_config_file); + $wp_super_cache_front_page_text = wp_specialchars( $_POST[ 'wp_super_cache_front_page_text' ] ); + wp_cache_replace_line('^ *\$wp_super_cache_front_page_text', "\$wp_super_cache_front_page_text = '$wp_super_cache_front_page_text';", $wp_cache_config_file); + $wp_super_cache_front_page_notification = (int)$_POST[ 'wp_super_cache_front_page_notification' ]; + wp_cache_replace_line('^ *\$wp_super_cache_front_page_notification', "\$wp_super_cache_front_page_notification = '$wp_super_cache_front_page_notification';", $wp_cache_config_file); + if ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 1 && !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) { + wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' ); + if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'scheduled wp_cache_check_site_hook for 360 seconds time.', 2 ); + } + } + + echo ''; + echo '
'; + echo "

" . __( 'Debug Settings', 'wp-super-cache' ) . "

"; + if ( ( isset( $wp_cache_debug_log ) && $wp_cache_debug_log != '' ) || ( isset( $wp_cache_debug_email ) && $wp_cache_debug_email != '' ) ) { + echo "

" . __( 'Currently logging to: ', 'wp-super-cache' ); + if ( isset( $wp_cache_debug_log ) && $wp_cache_debug_log != '' ) { + $url = str_replace( ABSPATH, '', "{$cache_path}{$wp_cache_debug_log}" ); + echo "$cache_path{$wp_cache_debug_log} "; + + } + if ( isset( $wp_cache_debug_email ) ) + echo " $wp_cache_debug_email "; + echo "

"; + } + echo '

' . __( 'Fix problems with the plugin by debugging it here. It can send you debug emails or log them to a file in your cache directory.', 'wp-super-cache' ) . '

'; + echo '

' . __( 'Logging to a file is easier but faces the problem that clearing the cache will clear the log file.', 'wp-super-cache' ) . '

'; + echo '
'; + echo "
"; + echo "
"; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo "
" . __( 'Debugging', 'wp-super-cache' ) . " " . __( 'enabled', 'wp-super-cache' ) . "
" . __( 'Logging Type', 'wp-super-cache' ) . " " . __( 'Email', 'wp-super-cache' ) . ":
" . __( 'file', 'wp-super-cache' ) . "
" . __( 'IP Address', 'wp-super-cache' ) . " " . sprintf( __( '(only log requests from this IP address. Your IP is %s)', 'wp-super-cache' ), $_SERVER[ 'REMOTE_ADDR' ] ) . "
" . __( 'Log level', 'wp-super-cache' ) . " "; + for( $t = 1; $t <= 5; $t++ ) { + echo " $t "; + } + echo " " . __( '(1 = less, 5 = more, may cause severe server load.)', 'wp-super-cache' ) . "
\n"; + if ( isset( $wp_super_cache_advanced_debug ) ) { + echo "

" . __( 'Advanced', 'wp-super-cache' ) . "

" . __( 'In very rare cases two problems may arise on some blogs:

  1. The front page may start downloading as a zip file.
  2. The wrong page is occasionally cached as the front page if your blog uses a static front page and the permalink structure is /%category%/%postname%/.
', 'wp-super-cache' ) . '

'; + echo "

" . __( 'I’m 99% certain that they aren’t bugs in WP Super Cache and they only happen in very rare cases but you can run a simple check once every 5 minutes to verify that your site is ok if you’re worried. You will be emailed if there is a problem.', 'wp-super-cache' ) . "

"; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + echo "
" . __( 'Check front page every 5 minutes.', 'wp-super-cache' ) . "
" . __( 'Front page text', 'wp-super-cache' ) . " (" . __( 'Text to search for on your front page. If this text is missing the cache will be cleared. Leave blank to disable.', 'wp-super-cache' ) . ")
" . __( 'Clear cache on error.', 'wp-super-cache' ) . "
" . __( 'Email the blog admin when checks are made. (useful for testing)', 'wp-super-cache' ) . "
\n"; + } + echo '
'; + wp_nonce_field('wp-cache'); + echo "\n"; + echo '
'; +} + +function wp_cache_enable() { + global $wp_cache_config_file, $cache_enabled, $supercachedir; + + if(get_option('gzipcompression')) { + echo "" . __( 'Error: GZIP compression is enabled, disable it if you want to enable wp-cache.', 'wp-super-cache' ) . ""; + return false; + } + if( wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = true;', $wp_cache_config_file) ) { + $cache_enabled = true; + } + wp_super_cache_enable(); +} + +function wp_cache_disable() { + global $wp_cache_config_file, $cache_enabled; + + if (wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file)) { + $cache_enabled = false; + } + wp_super_cache_disable(); +} +function wp_super_cache_enable() { + global $supercachedir, $wp_cache_config_file, $super_cache_enabled; + + if( is_dir( $supercachedir . ".disabled" ) ) + if( is_dir( $supercachedir ) ) { + prune_super_cache( $supercachedir . ".disabled", true ); + @unlink( $supercachedir . ".disabled" ); + } else { + @rename( $supercachedir . ".disabled", $supercachedir ); + } + wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = true;', $wp_cache_config_file); + $super_cache_enabled = true; +} + +function wp_super_cache_disable() { + global $cache_path, $supercachedir, $wp_cache_config_file, $super_cache_enabled; + + wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = false;', $wp_cache_config_file); + if( is_dir( $supercachedir ) ) + @rename( $supercachedir, $supercachedir . ".disabled" ); + $super_cache_enabled = false; + sleep( 1 ); // allow existing processes to write to the supercachedir and then delete it + if (function_exists ('prune_super_cache') && is_dir( $supercachedir ) ) { + prune_super_cache( $cache_path, true ); + } +} + +function wp_cache_is_enabled() { + global $wp_cache_config_file; + + if(get_option('gzipcompression')) { + echo "" . __( 'Warning', 'wp-super-cache' ) . ": " . __( "GZIP compression is enabled in Wordpress, wp-cache will be bypassed until you disable gzip compression.", 'wp-super-cache' ); + return false; + } + $lines = file($wp_cache_config_file); + foreach($lines as $line) { + if (preg_match('/^ *\$cache_enabled *= *true *;/', $line)) + return true; + } + return false; +} + + +function wp_cache_replace_line($old, $new, $my_file) { + if (!is_writeable_ACLSafe($my_file)) { + echo "Error: file $my_file is not writable.\n"; + return false; + } + $found = false; + $lines = file($my_file); + foreach($lines as $line) { + if ( preg_match("/$old/", $line)) { + $found = true; + break; + } + } + if ($found) { + $fd = fopen($my_file, 'w'); + foreach($lines as $line) { + if ( !preg_match("/$old/", $line)) + fputs($fd, $line); + else { + fputs($fd, "$new //Added by WP-Cache Manager\n"); + } + } + fclose($fd); + return true; + } + $fd = fopen($my_file, 'w'); + $done = false; + foreach($lines as $line) { + if ( $done || !preg_match('/^(if\ \(\ \!\ )?define|\$|\?>/', $line) ) { + fputs($fd, $line); + } else { + fputs($fd, "$new //Added by WP-Cache Manager\n"); + fputs($fd, $line); + $done = true; + } + } + fclose($fd); + return true; +} + +function wp_cache_verify_cache_dir() { + global $cache_path, $blog_cache_dir, $blogcacheid; + + $dir = dirname($cache_path); + if ( !file_exists($cache_path) ) { + if ( !is_writeable_ACLSafe( $dir ) || !($dir = mkdir( $cache_path ) ) ) { + echo "" . __( 'Error', 'wp-super-cache' ) . ": " . sprintf( __( 'Your cache directory ($cache_path) did not exist and couldn’t be created by the web server. Check %s permissions.', 'wp-super-cache' ), $dir ); + return false; + } + } + if ( !is_writeable_ACLSafe($cache_path)) { + echo "" . __( 'Error', 'wp-super-cache' ) . ": " . sprintf( __( 'Your cache directory (%1$s) or %2$s need to be writable for this plugin to work. Double-check it.', 'wp-super-cache' ), $cache_path, $dir ); + return false; + } + + if ( '/' != substr($cache_path, -1)) { + $cache_path .= '/'; + } + + if( false == is_dir( $blog_cache_dir ) ) { + @mkdir( $cache_path . "blogs" ); + if( $blog_cache_dir != $cache_path . "blogs/" ) + @mkdir( $blog_cache_dir ); + } + + if( false == is_dir( $blog_cache_dir . 'meta' ) ) + @mkdir( $blog_cache_dir . 'meta' ); + + return true; +} + +function wp_cache_verify_config_file() { + global $wp_cache_config_file, $wp_cache_config_file_sample, $sem_id, $cache_path; + + $new = false; + $dir = dirname($wp_cache_config_file); + + if ( file_exists($wp_cache_config_file) ) { + $lines = join( ' ', file( $wp_cache_config_file ) ); + if( strpos( $lines, 'WPCACHEHOME' ) === false ) { + if( is_writeable_ACLSafe( $wp_cache_config_file ) ) { + @unlink( $wp_cache_config_file ); + } else { + echo "" . __( 'Error', 'wp-super-cache' ) . ": " . sprintf( __( 'Your WP-Cache config file (%s) is out of date and not writable by the Web server.Please delete it and refresh this page.', 'wp-super-cache' ), $wp_cache_config_file ); + return false; + } + } + } elseif( !is_writeable_ACLSafe($dir)) { + echo "" . __( 'Error', 'wp-super-cache' ) . ": " . sprintf( __( 'Configuration file missing and %1$s directory (%2$s) is not writable by the Web server.Check its permissions.', 'wp-super-cache' ), WP_CONTENT_DIR, $dir ); + return false; + } + + if ( !file_exists($wp_cache_config_file) ) { + if ( !file_exists($wp_cache_config_file_sample) ) { + echo "" . __( 'Error', 'wp-super-cache' ) . ": " . sprintf( __( 'Sample WP-Cache config file (%s) does not exist.Verify you installation.', 'wp-super-cache' ), $wp_cache_config_file_sample ); + return false; + } + copy($wp_cache_config_file_sample, $wp_cache_config_file); + $dir = str_replace( str_replace( '\\', '/', WP_CONTENT_DIR ), '', str_replace( '\\', '/', dirname(__FILE__) ) ); + if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) { + wp_cache_replace_line('define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/\" );", $wp_cache_config_file); + } elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) { + wp_cache_replace_line('define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/wp-super-cache/\" );", $wp_cache_config_file); + } + $new = true; + } + if( $sem_id == 5419 && $cache_path != '' ) { + $sem_id = crc32( $_SERVER[ 'HTTP_HOST' ] . $cache_path ) & 0x7fffffff; + wp_cache_replace_line('sem_id', '$sem_id = ' . $sem_id . ';', $wp_cache_config_file); + } + require($wp_cache_config_file); + return true; +} + +function wp_cache_create_advanced_cache() { + global $wp_cache_link, $wp_cache_file; + $ret = true; + + $file = file_get_contents( $wp_cache_file ); + $file = str_replace( 'CACHEHOME', constant( 'WPCACHEHOME' ), $file ); + $fp = @fopen( $wp_cache_link, 'w' ); + if( $fp ) { + fputs( $fp, $file ); + fclose( $fp ); + } else { + $ret = false; + } + return $ret; +} + +function wp_cache_check_link() { + global $wp_cache_link, $wp_cache_file; + + $ret = true; + if( file_exists($wp_cache_link) ) { + $file = file_get_contents( $wp_cache_link ); + if( strpos( $file, "WP SUPER CACHE 0.8.9.1" ) ) { + return true; + } else { + if( !@unlink($wp_cache_link) ) { + $ret = false; + } else { + $ret = wp_cache_create_advanced_cache(); + } + } + } else { + $ret = wp_cache_create_advanced_cache(); + } + + if( false == $ret ) { + echo "

" . __( 'Warning', 'wp-super-cache' ) . "! " . sprintf( __( '%s/advanced-cache.php does not exist or cannot be updated.', 'wp-super-cache' ), WP_CONTENT_DIR ) . "

"; + echo "

"; + echo sprintf( __( 'If that doesn’t work, make sure the file %s/advanced-cache.php doesn’t exist:', 'wp-super-cache' ), WP_CONTENT_DIR ) . "
    "; + printf( __( '
  1. 1. Open %1$s$wp_cache_file in a text editor.
  2. 2. Change the text CACHEHOME to %2$s
  3. 3. Save the file and copy it to %3$s and refresh this page.
  4. ', 'wp-super-cache' ), $wp_cache_file, WPCACHEHOME, $wp_cache_link ); + return false; + } + return true; +} + +function wp_cache_check_global_config() { + global $wp_cache_check_wp_config; + + if ( !isset( $wp_cache_check_wp_config ) ) + return true; + + if ( file_exists( ABSPATH . 'wp-config.php') ) { + $global = ABSPATH . 'wp-config.php'; + } else { + $global = dirname(ABSPATH) . '/wp-config.php'; + } + + $line = 'define(\'WP_CACHE\', true);'; + if (!is_writeable_ACLSafe($global) || !wp_cache_replace_line('define *\( *\'WP_CACHE\'', $line, $global) ) { + echo "

    " . __( "Error: WP_CACHE is not enabled in your wp-config.php file and I couldn’t modify it.", 'wp-super-cache' ) . "

    ";; + echo "

    " . sprintf( __( "Edit %s and add the following line:
    define('WP_CACHE', true);
    Otherwise, WP-Cache will not be executed by Wordpress core. ", 'wp-super-cache' ), $global ) . "

    "; + return false; + } else { + echo "
    " . __( '

    WP_CACHE constant added to wp-config.php

    If you continue to see this warning message please see point 5 of the FAQ. The WP_CACHE line must be moved up.', 'wp-super-cache' ) . "

    "; + } + return true; +} + +function wp_cache_files() { + global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled, $blog_cache_dir, $cache_compression; + + if ( '/' != substr($cache_path, -1)) { + $cache_path .= '/'; + } + + if ( $valid_nonce ) { + if(isset($_REQUEST['wp_delete_cache'])) { + wp_cache_clean_cache($file_prefix); + } + if(isset($_REQUEST['wp_delete_expired'])) { + wp_cache_clean_expired($file_prefix); + } + } + echo ""; + echo '

    ' . __( 'Cache Contents', 'wp-super-cache' ) . '

    '; + + $list_files = false; // it doesn't list supercached files, and removing single pages is buggy + $count = 0; + $expired = 0; + $now = time(); + if ( ($handle = @opendir( $blog_cache_dir . 'meta/' )) ) { + if ($list_files) echo ""; + $wp_cache_fsize = 0; + if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletewpcache' ) { + $deleteuri = preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '/index.php', '/', str_replace( '..', '', preg_replace("/(\?.*)?$/", '', base64_decode( $_GET[ 'uri' ] ) ) ) ) ); + $deleteuri = str_replace( '\\', '', $deleteuri ); + } else { + $deleteuri = ''; + } + + if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletesupercache' ) { + $supercacheuri = preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '/index.php', '/', str_replace( '..', '', preg_replace("/(\?.*)?$/", '', base64_decode( $_GET[ 'uri' ] ) ) ) ) ); + $supercacheuri = trailingslashit( str_replace( '\\', '', $supercacheuri ) ); + printf( __( "Deleting supercache file: %s
    ", 'wp-super-cache' ), $supercacheuri ); + @unlink( $cache_path . 'supercache/' . $supercacheuri . 'index.html' ); + @unlink( $cache_path . 'supercache/' . $supercacheuri . 'index.html.gz' ); + prune_super_cache( $cache_path . 'supercache/' . $supercacheuri . 'page', true ); + @rmdir( $cache_path . 'supercache/' . $supercacheuri ); + } + while( false !== ($file = readdir($handle))) { + if ( preg_match("/^$file_prefix.*\.meta/", $file) ) { + $content_file = preg_replace("/meta$/", "html", $file); + $mtime = filemtime( $blog_cache_dir . 'meta/' . $file ); + if ( ! ( $fsize = @filesize( $blog_cache_dir . $content_file ) ) ) + continue; // .meta does not exists + + $age = $now - $mtime; + if ( $valid_nonce && $_GET[ 'listfiles' ] ) { + $meta = unserialize( file_get_contents( $blog_cache_dir . 'meta/' . $file ) ); + if ( $deleteuri != '' && $meta[ 'uri' ] == $deleteuri ) { + printf( __( "Deleting wp-cache file: %s
    ", 'wp-super-cache' ), $deleteuri ); + @unlink( $blog_cache_dir . 'meta/' . $file ); + @unlink( $blog_cache_dir . $content_file ); + continue; + } + $meta[ 'age' ] = $age; + if ( $age > $cache_max_time ) { + $expired_list[ $age ][] = $meta; + } else { + $cached_list[ $age ][] = $meta; + } + } + + if ( $age > $cache_max_time ) { + $expired++; + } else { + $count++; + } + $wp_cache_fsize += $fsize; + $fsize = intval($fsize/1024); + } + } + closedir($handle); + if ($list_files) echo "
    "; + } + if( $wp_cache_fsize != 0 ) { + $wp_cache_fsize = $wp_cache_fsize/1024; + } else { + $wp_cache_fsize = 0; + } + if( $wp_cache_fsize > 1024 ) { + $wp_cache_fsize = number_format( $wp_cache_fsize / 1024, 2 ) . "MB"; + } elseif( $wp_cache_fsize != 0 ) { + $wp_cache_fsize = number_format( $wp_cache_fsize, 2 ) . "KB"; + } else { + $wp_cache_fsize = '0KB'; + } + if( $cache_enabled == true && $super_cache_enabled == true ) { + $now = time(); + $sizes = array( 'expired' => 0, 'expired_list' => array(), 'cached' => 0, 'cached_list' => array(), 'ts' => 0 ); + + if (is_dir($supercachedir)) { + if( $dh = opendir( $supercachedir ) ) { + while( ( $entry = readdir( $dh ) ) !== false ) { + if ($entry != '.' && $entry != '..') { + $sizes = wpsc_dirsize( trailingslashit( $supercachedir ) . $entry, $sizes ); + } + } + closedir($dh); + } + } else { + $filem = @filemtime( $supercachedir ); + if(is_file($supercachedir) && $filem + $cache_max_time <= $now ) { + $sizes[ 'expired' ] ++; + if ( $valid_nonce && $_GET[ 'listfiles' ] ) + $sizes[ 'expired_list' ][ str_replace( $cache_path . 'supercache/' , '', $supercachedir ) ] = $now - $filem; + } else { + if ( $valid_nonce && $_GET[ 'listfiles' ] && $filem ) + $sizes[ 'cached_list' ][ str_replace( $cache_path . 'supercache/' , '', $supercachedir ) ] = $now - $filem; + } + } + $sizes[ 'ts' ] = time(); + } + + echo "

    " . __( 'WP-Cache', 'wp-super-cache' ) . " ({$wp_cache_fsize})

    "; + echo ""; + if( $cache_enabled == true && $super_cache_enabled == true ) { + $fsize = $sizes[ 'fsize' ] / 1024; + if( $fsize > 1024 ) { + $fsize = number_format( $fsize / 1024, 2 ) . "MB"; + } elseif( $fsize != 0 ) { + $fsize = number_format( $fsize, 2 ) . "KB"; + } else { + $fsize = "0KB"; + } + $divisor = $cache_compression == 1 ? 2 : 1; + echo "

    " . __( 'WP-Super-Cache', 'wp-super-cache' ) . " ({$fsize})

    "; + echo ""; + } + if ( $valid_nonce && $_GET[ 'listfiles' ] ) { + echo "
    "; + if ( is_array( $cached_list ) && !empty( $cached_list ) ) { + echo "

    " . __( 'Fresh WP-Cached Files', 'wp-super-cache' ) . "

    "; + echo ""; + $c = 1; + $flip = 1; + ksort( $cached_list ); + foreach( $cached_list as $age => $d ) { + foreach( $d as $details ) { + $bg = $flip ? 'style="background: #EAEAEA;"' : ''; + echo "\n"; + $flip = !$flip; + $c++; + } + } + echo "
    #" . __( 'URI', 'wp-super-cache' ) . "" . __( 'Key', 'wp-super-cache' ) . "" . __( 'Age', 'wp-super-cache' ) . "" . __( 'Delete', 'wp-super-cache' ) . "
    $c " . $details[ 'uri' ] . " " . str_replace( $details[ 'uri' ], '', $details[ 'key' ] ) . " {$age} 'wpsupercache', 'action' => 'deletewpcache', 'uri' => base64_encode( $details[ 'uri' ] ) ) ), 'wp-cache' ) . "#listfiles'>X
    "; + } + if ( is_array( $expired_list ) && !empty( $expired_list ) ) { + echo "

    " . __( 'Stale WP-Cached Files', 'wp-super-cache' ) . "

    "; + echo ""; + $c = 1; + $flip = 1; + ksort( $expired_list ); + foreach( $expired_list as $age => $d ) { + foreach( $d as $details ) { + $bg = $flip ? 'style="background: #EAEAEA;"' : ''; + echo "\n"; + $flip = !$flip; + $c++; + } + } + echo "
    #" . __( 'URI', 'wp-super-cache' ) . "" . __( 'Key', 'wp-super-cache' ) . "" . __( 'Age', 'wp-super-cache' ) . "" . __( 'Delete', 'wp-super-cache' ) . "
    $c " . $details[ 'uri' ] . " " . str_replace( $details[ 'uri' ], '', $details[ 'key' ] ) . " {$age} 'wpsupercache', 'action' => 'deletewpcache', 'uri' => base64_encode( $details[ 'uri' ] ) ) ), 'wp-cache' ) . "#listfiles'>X
    "; + } + if ( is_array( $sizes[ 'cached_list' ] ) & !empty( $sizes[ 'cached_list' ] ) ) { + echo "

    " . __( 'Fresh Super Cached Files', 'wp-super-cache' ) . "

    "; + echo ""; + $c = 1; + $flip = 1; + ksort( $sizes[ 'cached_list' ] ); + foreach( $sizes[ 'cached_list' ] as $age => $d ) { + foreach( $d as $uri => $n ) { + $bg = $flip ? 'style="background: #EAEAEA;"' : ''; + echo "\n"; + $flip = !$flip; + $c++; + } + } + echo "
    #" . __( 'URI', 'wp-super-cache' ) . "" . __( 'Age', 'wp-super-cache' ) . "" . __( 'Delete', 'wp-super-cache' ) . "
    $c " . $uri . "$age 'wpsupercache', 'action' => 'deletesupercache', 'uri' => base64_encode( $uri ) ) ), 'wp-cache' ) . "#listfiles'>X
    "; + } + if ( is_array( $sizes[ 'expired_list' ] ) && !empty( $sizes[ 'expired_list' ] ) ) { + echo "

    " . __( 'Stale Super Cached Files', 'wp-super-cache' ) . "

    "; + echo ""; + $c = 1; + $flip = 1; + ksort( $sizes[ 'expired_list' ] ); + foreach( $sizes[ 'expired_list' ] as $age => $d ) { + foreach( $d as $uri => $n ) { + $bg = $flip ? 'style="background: #EAEAEA;"' : ''; + echo "\n"; + $flip = !$flip; + $c++; + } + } + echo "
    #" . __( 'URI', 'wp-super-cache' ) . "" . __( 'Age', 'wp-super-cache' ) . "" . __( 'Delete', 'wp-super-cache' ) . "
    $c " . $uri . "$age 'wpsupercache', 'action' => 'deletesupercache', 'uri' => base64_encode( $uri ) ) ), 'wp-cache' ) . "#listfiles'>X
    "; + } + echo "
    "; + echo "

    " . __( 'Hide file list', 'wp-super-cache' ) . "

    "; + } else { + echo "

    'wpsupercache', 'listfiles' => '1' ) ), 'wp-cache' ) . "#listfiles'>" . __( 'List all cached files', 'wp-super-cache' ) . "

    "; + } + $last_gc = get_option( "wpsupercache_gc_time" ); + if( $last_gc ) { + $next_gc = $cache_max_time < 1800 ? $cache_max_time : 600; + $next_gc_mins = ( time() - $last_gc ); + echo "

    " . sprintf( __( 'Garbage Collection
    Last GC was %s minutes ago
    ', 'wp-super-cache' ), date( 'i:s', $next_gc_mins ) ); + printf( __( "Next GC in %s minutes", 'wp-super-cache' ), date( 'i:s', $next_gc - $next_gc_mins ) ) . "

    "; + } + + echo "

    " . sprintf( __( 'Expired files are files older than %s seconds. They are still used by the plugin and are deleted periodically.', 'wp-super-cache' ), $cache_max_time ) . "

    "; + echo '
    '; + echo ''; + echo '
    '; + wp_nonce_field('wp-cache'); + echo "
    \n"; + + echo '
    '; + echo ''; + echo '
    '; + wp_nonce_field('wp-cache'); + echo "
    \n"; + + echo '
    '; +} + +function delete_cache_dashboard() { + if( function_exists( 'is_site_admin' ) && !is_site_admin() ) + return false; + + if( function_exists('current_user_can') && !current_user_can('manage_options') ) + return false; + + echo "
  5. " . __( 'Delete Cache', 'wp-super-cache' ) . "
  6. "; +} +add_action( 'dashmenu', 'delete_cache_dashboard' ); + +function wpsc_dirsize($directory, $sizes) { + global $cache_max_time, $cache_path, $valid_nonce; + $now = time(); + + if (is_dir($directory)) { + if( $dh = opendir( $directory ) ) { + while( ( $entry = readdir( $dh ) ) !== false ) { + if ($entry != '.' && $entry != '..') { + $sizes = wpsc_dirsize( trailingslashit( $directory ) . $entry, $sizes ); + } + } + closedir($dh); + } + } else { + if(is_file($directory) ) { + $filem = filemtime( $directory ); + if( $filem + $cache_max_time <= $now ) { + $sizes[ 'expired' ]+=1; + if ( $valid_nonce && $_GET[ 'listfiles' ] ) + $sizes[ 'expired_list' ][ $now - $filem ][ str_replace( $cache_path . 'supercache/' , '', str_replace( 'index.html', '', str_replace( 'index.html.gz', '', $directory ) ) ) ] = 1; + } else { + $sizes[ 'cached' ]+=1; + if ( $valid_nonce && $_GET[ 'listfiles' ] ) + $sizes[ 'cached_list' ][ $now - $filem ][ str_replace( $cache_path . 'supercache/' , '', str_replace( 'index.html', '', str_replace( 'index.html.gz', '', $directory ) ) ) ] = 1; + } + if ( ! isset( $sizes[ 'fsize' ] ) ) + $sizes[ 'fsize' ] = @filesize( $directory ); + else + $sizes[ 'fsize' ] += @filesize( $directory ); + } + } + return $sizes; +} + + +function wp_cache_clean_cache($file_prefix) { + global $cache_path, $supercachedir, $blog_cache_dir; + + // If phase2 was compiled, use its function to avoid race-conditions + if(function_exists('wp_cache_phase2_clean_cache')) { + if (function_exists ('prune_super_cache')) { + if( is_dir( $supercachedir ) ) { + prune_super_cache( $supercachedir, true ); + } elseif( is_dir( $supercachedir . '.disabled' ) ) { + prune_super_cache( $supercachedir . '.disabled', true ); + } + prune_super_cache( $cache_path, true ); + $_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats; + } elseif ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Warning! prune_super_cache() not found in wp-cache.php', 1 ); + return wp_cache_phase2_clean_cache($file_prefix); + } elseif ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Warning! wp_cache_phase2_clean_cache() not found in wp-cache.php', 1 ); + + $expr = "/^$file_prefix/"; + if ( ($handle = @opendir( $blog_cache_dir )) ) { + while ( false !== ($file = readdir($handle))) { + if ( preg_match($expr, $file) ) { + @unlink( $blog_cache_dir . $file); + @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) ); + } + } + closedir($handle); + } +} + +function wp_cache_clean_expired($file_prefix) { + global $cache_path, $cache_max_time, $blog_cache_dir; + + // If phase2 was compiled, use its function to avoid race-conditions + if(function_exists('wp_cache_phase2_clean_expired')) { + if (function_exists ('prune_super_cache')) { + $dir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]); + if( is_dir( $dir ) ) { + prune_super_cache( $dir ); + } elseif( is_dir( $dir . '.disabled' ) ) { + prune_super_cache( $dir . '.disabled' ); + } + $_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats; + } + return wp_cache_phase2_clean_expired($file_prefix); + } + + $expr = "/^$file_prefix/"; + $now = time(); + if ( ($handle = @opendir( $blog_cache_dir )) ) { + while ( false !== ($file = readdir($handle))) { + if ( preg_match( $expr, $file ) && + ( filemtime( $blog_cache_dir . $file ) + $cache_max_time ) <= $now ) { + @unlink( $blog_cache_dir . $file ); + @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) ); + } + } + closedir($handle); + } +} + +function wpsc_remove_marker( $filename, $marker ) { + if (!file_exists( $filename ) || is_writeable_ACLSafe( $filename ) ) { + if (!file_exists( $filename ) ) { + return ''; + } else { + $markerdata = explode( "\n", implode( '', file( $filename ) ) ); + } + + $f = fopen( $filename, 'w' ); + $foundit = false; + if ( $markerdata ) { + $state = true; + foreach ( $markerdata as $n => $markerline ) { + if (strpos($markerline, '# BEGIN ' . $marker) !== false) + $state = false; + if ( $state ) { + if ( $n + 1 < count( $markerdata ) ) + fwrite( $f, "{$markerline}\n" ); + else + fwrite( $f, "{$markerline}" ); + } + if (strpos($markerline, '# END ' . $marker) !== false) { + $state = true; + } + } + } + return true; + } else { + return false; + } +} + +function wp_super_cache_footer() { + ?>

    WP Super Cache' ); ?>

    is_404 +function wp_cache_catch_404() { + global $wp_cache_404; + $wp_cache_404 = false; + if( is_404() ) + $wp_cache_404 = true; +} +add_action( 'template_redirect', 'wp_cache_catch_404' ); + +function wp_cache_favorite_action( $actions ) { + if( function_exists( 'is_site_admin' ) && !is_site_admin() ) + return $actions; + + if( function_exists('current_user_can') && !current_user_can('manage_options') ) + return $actions; + + $actions[ wp_nonce_url( 'options-general.php?page=wpsupercache&wp_delete_cache=1', 'wp-cache' ) ] = array( __( 'Delete Cache', 'wp-super-cache' ), 'manage_options' ); + + return $actions; +} +add_filter( 'favorite_actions', 'wp_cache_favorite_action' ); + +function wp_cache_plugin_notice( $plugin ) { + global $cache_enabled; + if( $plugin == 'wp-super-cache/wp-cache.php' && !$cache_enabled && function_exists( "admin_url" ) ) + echo '' . sprintf( __( 'WP Super Cache must be configured. Go to the admin page to enable and configure the plugin.' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . ''; +} +add_action( 'after_plugin_row', 'wp_cache_plugin_notice' ); + +function wp_cache_plugin_actions( $links, $file ) { + if( $file == 'wp-super-cache/wp-cache.php' && function_exists( "admin_url" ) ) { + $settings_link = '' . __('Settings') . ''; + array_unshift( $links, $settings_link ); // before other links + } + return $links; +} +add_filter( 'plugin_action_links', 'wp_cache_plugin_actions', 10, 2 ); + +function wp_cache_admin_notice() { + global $cache_enabled; + if( substr( $_SERVER["PHP_SELF"], -11 ) == 'plugins.php' && !$cache_enabled && function_exists( "admin_url" ) ) + echo '

    ' . sprintf( __('WP Super Cache is disabled. Please go to the plugin admin page to enable caching.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '

    '; +} +add_action( 'admin_notices', 'wp_cache_admin_notice' ); + +function wp_cache_check_site() { + global $wp_super_cache_front_page_check, $wp_super_cache_front_page_clear, $wp_super_cache_front_page_text, $wp_super_cache_front_page_notification; + + if ( !isset( $wp_super_cache_front_page_check ) || ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 0 ) ) { + return false; + } + + if ( function_exists( "wp_remote_get" ) == false ) { + return false; + } + $front_page = wp_remote_get( site_url(), array('timeout' => 60, 'blocking' => true ) ); + if( is_array( $front_page ) ) { + // Check for gzipped front page + if ( $front_page[ 'headers' ][ 'content-type' ] == 'application/x-gzip' ) { + if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) { + wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Please clear cache!', 'wp-super-cache' ), site_url() ), sprintf( __( "Please visit %s to clear the cache as the front page of your site is now downloading!", 'wp-super-cache' ), trailingslashit( site_url() ) . "wp-admin/options-general.php?page=wpsupercache" ) ); + } else { + wp_cache_clear_cache(); + wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Cache Cleared!', 'wp-super-cache' ), site_url() ), sprintf( __( "The cache on your blog has been cleared because the front page of your site is now downloading. Please visit %s to verify the cache has been cleared.", 'wp-super-cache' ), trailingslashit( site_url() ) . "wp-admin/options-general.php?page=wpsupercache" ) ); + } + } + + // Check for broken front page + if ( isset( $wp_super_cache_front_page_text ) && $wp_super_cache_front_page_text != '' && false === strpos( $front_page[ 'body' ], $wp_super_cache_front_page_text ) ) { + if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) { + wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is not correct! Please clear cache!', 'wp-super-cache' ), site_url() ), sprintf( __( 'Please visit %1$s to clear the cache as the front page of your site is not correct and missing the text, "%2$s"!', 'wp-super-cache' ), trailingslashit( site_url() ) . "wp-admin/options-general.php?page=wpsupercache", $wp_super_cache_front_page_text ) ); + } else { + wp_cache_clear_cache(); + wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is not correct! Cache Cleared!', 'wp-super-cache' ), site_url() ), sprintf( __( 'The cache on your blog has been cleared because the front page of your site is missing the text "%2$s". Please visit %1$s to verify the cache has been cleared.', 'wp-super-cache' ), trailingslashit( site_url() ) . "wp-admin/options-general.php?page=wpsupercache", $wp_super_cache_front_page_text ) ); + } + } + } + if ( isset( $wp_super_cache_front_page_notification ) && $wp_super_cache_front_page_notification == 1 ) { + wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page check!', 'wp-super-cache' ), site_url() ), sprintf( __( "WP Super Cache has checked the front page of your blog. Please visit %s if you would like to disable this.", 'wp-super-cache' ) . "\n\n", trailingslashit( site_url() ) . "wp-admin/options-general.php?page=wpsupercache#debug" ) . print_r( $front_page, 1 ) ); + } + + if ( !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) { + wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' ); + if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'scheduled wp_cache_check_site_hook for 360 seconds time.', 2 ); + } +} +add_action( 'wp_cache_check_site_hook', 'wp_cache_check_site' ); +?>