'; echo "

WP Super Cache Manager

\n"; if( ini_get( 'safe_mode' ) ) { ?>

Warning! PHP Safe Mode Enabled!

You may experience problems running this plugin because SAFE MODE is enabled. Your server is set up to check the owner of PHP scripts before allowing them to read and write files.

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 /cache/ directory must also be changed. See the safe mode manual page for further details.

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.

Configuration file changed, some values might be wrong. Load the page again from the "Settings" menu to reset them.'; } if ( !wp_cache_check_link() || !wp_cache_verify_config_file() || !wp_cache_verify_cache_dir() ) { echo "Cannot continue... fix previous problems and retry."; 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' ) { ?>

Warning! Your hostname "" resolves to

Your server thinks your hostname resolves to . Some services such as garbage collection by this plugin, and WordPress scheduled posts may not operate correctly.

Please see entry 16 in the Troubleshooting section of the readme.txt

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

Warning! wp-cron.php not found!

Unfortunately WordPress cannot find the file wp-cron.php. This script is required for the the correct operation of garbage collection by this plugin, WordPress scheduled posts as well as other critical activities.

Please see entry 16 in the Troubleshooting section of the readme.txt

Mod rewrite may not be installed!

It appears that mod_rewrite is not installed. Sometimes this check isn't 100% reliable, especially if you are not using Apache. Please verify that the mod_rewrite module is loaded. It is required for serving Super Cache static files. You will still be able to use WP-Cache.

Read Only Mode. Configuration cannot be changed. Why

Warning! is writeable!

You should change the permissions on and make it more restrictive. Use your ftp client, or the following command to fix things:chmod 755 /

WP Super Cache Status

'; ?>


Mobile support requires extra rules in your .htaccess file, or you can set the plugin to half-on mode. Here's your options (in order of difficulty):

  1. 1. Set the plugin to half on mode and enable mobile support.
  2. 2. Delete the plugin mod_rewrite rules in .htaccess enclosed by # BEGIN WPSuperCache and # END WPSuperCache and let the plugin regenerate them by reloading this page.
  3. 3. Add the rules yourself. Edit .htaccess and find the block of code enclosed by the lines # 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)

    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).*

Note: If uninstalling this plugin, make sure the directory 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_nonce_field('wp-cache'); ?> 'Required to serve compressed supercache files properly.', 'mod_headers' => 'Required to set caching information on supercache pages. IE7 users will see old pages without this module.', 'mod_expires' => 'Set the expiry date on supercached pages. Visitors may not see new pages when they refresh or leave comments without this module.' ); 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

"; 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.

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

Make WordPress Faster

WP Super Cache really makes your blog go faster. Make it go faster* by buying me an Amazon gift card! Make it out to "donncha@ocaoimh.ie". A £10 card would be nice but it's up to you how much you think this plugin is worth to you.

If Amazon isn't your thing, there's also PayPal. Click the "Donate" button below or take a quick peek at my wishlist.

Thanks in advance!
Donncha
* Ok, it won't go any faster but you'll make this plugin author very happy!


Don't show me this again.

" method="post">

WP Super Cache is maintained and developed by Donncha O Caoimh with contributions from many others.

He blogs at Holy Shmoly, posts photos at In Photos.org and wishes he had more time to read and relax.

Please say hi to him on Twitter too!

Accepted Filenames & Rejected URIs

'; wp_cache_edit_rejected(); echo "\n"; wp_cache_edit_accepted(); echo '
'; wp_cache_edit_rejected_ua(); 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

'; echo $out; echo '
'; } echo "\n"; } function wsc_mod_rewrite() { global $super_cache_enabled, $cache_compression, $cache_compression_changed, $valid_nonce, $cache_path; if( $super_cache_enabled == false ) return; if( false == defined( 'WPSC_DISABLE_COMPRESSION' ) ) { ?>

Super Cache Compression

" method="post">

Compression is disabled by default because some hosts have problems with compressed files. Switching this on and off clears the cache.

Super Cache compression is now disabled.

Super Cache compression is now enabled.

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

Mod Rewrite Rules

\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

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.

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

Mod Rewrite rules cannot be updated!

"; echo "

You must have BEGIN and END markers in {$home_path}.htaccess for the auto update to work. They look like this and surround the main WordPress mod_rewrite rules:

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

Thank you for upgrading. 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:

RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*\$
so it looks like this:
RewriteCond %{HTTP:Cookie} !^.*wordpress.*\$
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.

"; 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.

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."; echo "To fix, you must edit your .htaccess file and add these two rules to the two groups of Super Cache rules:

"; 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.

"; $dohtaccess = false; } elseif( strpos( $scrules, 'supercache' ) || strpos( $wprules, 'supercache' ) ) { // only write the rules once $dohtaccess = false; } // cache/.htaccess rules $gziprules = "\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 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

The file {$home_path}.htaccess cannot be modified by the web server. Please correct this using the chmod command or your ftp client.

Refresh this page when the file permissions have been modified.

Alternatively, you can edit your {$home_path}.htaccess file manually and add the following code (before any WordPress rules):

"; echo "

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

"; } else { echo "

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

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

"; echo "

Rules must be added to " . WP_CONTENT_DIR . "/cache/.htaccess too:

"; 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!

"; echo "

{$home_path}.htaccess has been updated with the necessary mod_rewrite rules. Please verify they are correct. They should look like this:

\n"; } else { echo "

Mod Rewrite rules must be updated!

"; echo "

Your {$home_path}.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:

\n"; } echo "

" . wp_specialchars( $rules ) . "

\n
"; } else { ?>

WP Super Cache mod rewrite rules were detected in your .htaccess file.
Click the following link to see the lines added to that file. If you have upgraded the plugin make sure these rules match.

View Mod_Rewrite Rules

Gzip encoding rules in {$cache_path}.htaccess created."; } ?>

Fix Configuration

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

Lock Down: Disabled' : 'Enabled'; ?>

Prepare your server for an expected spike in traffic by enabling the lock down. When this is enabled, new comments on a post will not refresh the cached static files.

Developers: Make your plugin lock down compatible by checking the 'WPLOCKDOWN' constant. The following code will make sure your plugin respects the WPLOCKDOWN setting.

if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) ) {     echo "Sorry. My blog is locked down. Updates will appear shortly"; }

WordPress is locked down. Super Cache static files will not be deleted when new comments are made.

WordPress is not locked down. New comments will refresh Super Cache static files as normal.

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

Directly Cached Files

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 "$pagefile removed!"; prune_super_cache( $cache_path, true ); } } $readonly = ''; if( !is_writeable_ACLSafe( ABSPATH ) ) { $readonly = 'READONLY'; ?>

Warning! You must make writable to enable this feature. As this is a security risk please make it readonly after your page is generated.

Warning! is writable. Please make it readonly after your page is generated as this is a security risk.

'; 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: "; echo "

Directly cached files are files created directly off " . ABSPATH . " 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.

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

For example: to cache '" . trailingslashit( get_option( 'siteurl' ) ) . "about/', you would enter '" . trailingslashit( get_option( 'siteurl' ) ) . "about/' or '/about/'. The cached file will be generated the next time an anonymous user visits that page.

"; echo "

Make the textbox blank to remove it from the list of direct pages and delete the cached file.

"; } 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); } } ?>

Expiry Time & Garbage Collection

'; echo ' '; echo " seconds"; echo "

Garbage Collection

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.

"; 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.

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

Rejected User Agents

'; 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.

\n"; echo '
'; echo ' '; echo '
'; wp_nonce_field('wp-cache'); echo ''; 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 "

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.

\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 "

Add here those filenames that can be cached, even if they match one of the rejected substring specified above.

\n"; echo ' '; echo '
'; wp_nonce_field('wp-cache'); echo "\n"; } 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."; 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: GZIP compression is enabled in Wordpress, wp-cache will be bypassed until you disable gzip compression."; 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: Your cache directory ($cache_path) did not exist and couldn't be created by the web server. Check $dir permissions."; return false; } } if ( !is_writeable_ACLSafe($cache_path)) { echo "Error: Your cache directory ($cache_path) or $dir need to be writable for this plugin to work. Double-check it."; 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: Your WP-Cache config file ($wp_cache_config_file) is out of date and not writable by the Web server.Please delete it and refresh this page."; return false; } } } elseif( !is_writeable_ACLSafe($dir)) { echo "Error: Configuration file missing and " . WP_CONTENT_DIR . " directory ($dir) is not writable by the Web server.Check its permissions."; return false; } if ( !file_exists($wp_cache_config_file) ) { if ( !file_exists($wp_cache_config_file_sample) ) { echo "Error: Sample WP-Cache config file ($wp_cache_config_file_sample) does not exist.Verify you installation."; 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! " . constant( 'WP_CONTENT_DIR' ) . "/advanced-cache.php does not exist or cannot be updated.

"; echo "

"; echo "If that doesn't work, make sure the file " . constant( 'WP_CONTENT_DIR' ) . "/advanced-cache.php doesn't exist:
    "; echo "
  1. 1. Open $wp_cache_file in a text editor.
  2. 2. Change the text CACHEHOME to " . constant( 'WPCACHEHOME' ) . "
  3. 3. Save the file and copy it to $wp_cache_link and refresh this page.
  4. "; return false; } return true; } function wp_cache_check_global_config() { if( defined( 'WP_CACHE' ) ) return true; if ( file_exists( ABSPATH . 'wp-config.php') ) { $global = ABSPATH . 'wp-config.php'; } else { $global = dirname(ABSPATH) . '/wp-config.php'; } $howtoenable = "Edit $global and add the following line: define('WP_CACHE', true);Otherwise, WP-Cache will not be executed by Wordpress core. "; $lines = file($global); foreach($lines as $line) { if (preg_match('/^\s*define\s*\(\s*\'WP_CACHE\'\s*,\s*(?i:TRUE|1)\s*\)\s*;/', $line)) { echo $howtoenable; return false; } } $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."; echo $howtoenable; return false; } 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; 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_cache_file'])) { wp_cache_clean_cache($_REQUEST['wp_delete_cache_file']); } if(isset($_REQUEST['wp_delete_expired'])) { wp_cache_clean_expired($file_prefix); } } if(isset($_REQUEST['wp_list_cache'])) { $list_files = true; $list_mess = "Update list"; } else $list_mess = "List files"; echo '

    Cache Contents

    '; /* echo '
    '; echo ''; echo '
    '; echo "\n"; */ $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 "
Existing direct pageDelete cached file
"; $wp_cache_fsize = 0; while ( false !== ($file = readdir($handle))) { if ( preg_match("/^$file_prefix.*\.meta/", $file) ) { $this_expired = false; $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 $wp_cache_fsize += $fsize; $fsize = intval($fsize/1024); $age = $now - $mtime; if ( $age > $cache_max_time ) { $expired++; $this_expired = true; } $count++; /* if ($list_files) { $meta = new CacheMeta; $meta = unserialize(file_get_contents($cache_path . 'meta/' . $file)); echo $flip ? '' : ''; $flip = !$flip; echo '"; if ($this_expired) echo ""; else echo ""; echo ""; echo '\n"; } */ } } closedir($handle); if ($list_files) echo "
'; echo $meta->uri . "$age secs$age secs$fsize KB
'; echo ''; echo ''; echo '
'; wp_nonce_field('wp-cache'); 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, 'cached' => 0, '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 { if(is_file($supercachedir) && filemtime( $supercachedir ) + $cache_max_time <= $now ) $sizes[ 'expired' ] ++; } $sizes[ 'ts' ] = time(); } echo "

WP-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"; } echo "

WP-Super-Cache ({$fsize})

"; echo ""; } $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 "

Garbage Collection
Last GC was " . date( 'i:s', $next_gc_mins ) . " minutes ago
"; echo "Next GC in " . date( 'i:s', $next_gc - $next_gc_mins ) . " minutes

"; } echo "

Expired files are files older than $cache_max_time seconds. They are still used by the plugin and are deleted periodically.

"; 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 "
  • Delete Cache
  • "; } add_action( 'dashmenu', 'delete_cache_dashboard' ); function wpsc_dirsize($directory, $sizes) { global $cache_max_time; $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) ) { if( filemtime( $directory ) + $cache_max_time <= $now ) { $sizes[ 'expired' ]+=1; } else { $sizes[ 'cached' ]+=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; } return wp_cache_phase2_clean_cache($file_prefix); } $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() { ?>

    is Digg proof thanks to caching by 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' ), '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 'WP Super Cache must be configured. Go to the admin page to enable and configure the plugin.'; } 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 wpsc_author_url( $url ) { return clean_url( $url ); } add_filter( 'get_comment_author_url' , 'wpsc_author_url' ); 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.' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '

    '; } add_action( 'admin_notices', 'wp_cache_admin_notice' ); ?>