enable the cache. Based on WP-Cache by Ricardo Galli Granada.
Version: 0.8.1
Author: Donncha O Caoimh
Author URI: http://ocaoimh.ie/
*/
/* Copyright 2005-2006 Ricardo Galli Granada (email : gallir@uib.es)
Some code copyright 2007-2008 Donncha O Caoimh (http://ocaoimh.ie/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Pre-2.6 compatibility
if( !defined('WP_CONTENT_URL') )
define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
if( !defined('WP_CONTENT_DIR') )
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
$wp_cache_config_file = WP_CONTENT_DIR . '/wp-cache-config.php';
if( !@include($wp_cache_config_file) ) {
get_wpcachehome();
$wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
@include($wp_cache_config_file_sample);
} else {
get_wpcachehome();
}
$wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
$wp_cache_link = WP_CONTENT_DIR . '/advanced-cache.php';
$wp_cache_file = WPCACHEHOME . 'wp-cache-phase1.php';
include(WPCACHEHOME . 'wp-cache-base.php');
// from legolas558 d0t users dot sf dot net at http://www.php.net/is_writable
function is_writeable_ACLSafe($path) {
// PHP's is_writable does not work with Win32 NTFS
if ($path{strlen($path)-1}=='/') // recursively return a temporary file path
return is_writeable_ACLSafe($path.uniqid(mt_rand()).'.tmp');
else if (is_dir($path))
return is_writeable_ACLSafe($path.'/'.uniqid(mt_rand()).'.tmp');
// check tmp file for read/write capabilities
$rm = file_exists($path);
$f = @fopen($path, 'a');
if ($f===false)
return false;
fclose($f);
if (!$rm)
unlink($path);
return true;
}
function get_wpcachehome() {
if( defined( 'WPCACHEHOME' ) == false ) {
if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
define( 'WPCACHEHOME', trailingslashit( dirname(__FILE__) ) );
} elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
define( 'WPCACHEHOME', dirname(__FILE__) . '/wp-super-cache/' );
} else {
die( 'Please create ' . WP_CONTENT_DIR . '/wp-cache-config.php from wp-super-cache/wp-cache-config-sample.php' );
}
}
}
function wpsupercache_deactivate() {
global $wp_cache_config_file, $wp_cache_link, $cache_path;
$files = array( $wp_cache_config_file, $wp_cache_link );
foreach( $files as $file ) {
if( file_exists( $file ) )
unlink( $file );
}
if( !function_exists( 'prune_super_cache' ) )
include_once( 'wp-cache-phase2.php' );
prune_super_cache ($cache_path, true);
@unlink( $cache_path . '.htaccess' );
@unlink( $cache_path . 'meta' );
@unlink( $cache_path . 'supercache' );
}
register_deactivation_hook( __FILE__, 'wpsupercache_deactivate' );
function wp_cache_add_pages() {
if( function_exists( 'is_site_admin' ) ) {
if( is_site_admin() ) {
add_submenu_page('wpmu-admin.php', __('WP Super Cache'), __('WP Super Cache'), 'manage_options', 'wpsupercache', 'wp_cache_manager');
add_options_page('WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
}
} else {
add_options_page('WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
}
}
add_action('admin_menu', 'wp_cache_add_pages');
function wp_cache_manager() {
global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled, $wp_cache_hello_world, $wp_cache_clear_on_post_edit;
if( function_exists( 'is_site_admin' ) )
if( !is_site_admin() )
return;
$supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]);
if( get_option( 'gzipcompression' ) == 1 )
update_option( 'gzipcompression', 0 );
$valid_nonce = wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache');
/* http://www.netlobo.com/div_hiding.html */
?>
';
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 "Options" 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( $cache_enabled == true && $super_cache_enabled == true && !got_mod_rewrite() ) {
?>
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
The WP Super Cache configuration file is /wp-cache-config.php and cannot be modified. The file /wp-cache-config.php must be writeable by the webserver to make any changes.
A simple way of doing that is by changing the permissions temporarily using the CHMOD command or through your ftp client. Make sure it's globally writeable and it should be fine.
Writeable: chmod 666 /wp-cache-config.php
Readonly: chmod 644 /wp-cache-config.php
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 /
";
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:
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 This can be done automatically by clicking the 'Update mod_rewrite rules »' button or you can edit the file yourself and add the following rules. Make sure they appear before any existing WordPress rules.";
echo "
# BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache
";
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 "
{$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
# BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache