" . 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 "' . __( 'Warning', 'wp-super-cache' ) . "! " . sprintf( __( 'Could not update %s! WPCACHEHOME must be set in config file.', 'wp-super-cache' ), $global_config_file ) . " ";
return false;
}
$ret = true;
$file = file_get_contents( $wp_cache_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" ) || strpos( $file, "WP SUPER CACHE 1.2" ) ) {
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 "
" . __( '1. If it already exists, please delete the file first.', 'wp-super-cache' ) . " ";
echo "" . sprintf( __( '2. Make %1$s writable using the chmod command through your ftp or server software. (chmod 777 %1$s ) and refresh this page. This is only a temporary measure and you’ll have to make it read only afterwards again. (Change 777 to 755 in the previous command)', 'wp-super-cache' ), WP_CONTENT_DIR ) . " ";
echo "" . sprintf( __( '3. Refresh this page to update %s/advanced-cache.php ', 'wp-super-cache' ), WP_CONTENT_DIR ) . " ";
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. Open %1$s$wp_cache_file in a text editor. 2. Change the text CACHEHOME to %2$s 3. Save the file and copy it to %3$s and refresh this page. ', 'wp-super-cache' ), $wp_cache_file, WPCACHEHOME, $wp_cache_link );
echo " ";
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) ) {
if ( defined( 'WP_CACHE' ) && constant( 'WP_CACHE' ) == false ) {
echo '
' . __( "
WP_CACHE constant set to false The WP_CACHE constant is used by WordPress to load the code that serves cached pages. Unfortunately, it is set to false. Please edit your wp-config.php and add or edit the following line above the final require_once command:define('WP_CACHE', true);
", 'wp-super-cache' ) . "
";
} else {
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 Troubleshooting Guide . 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;
global $wp_cache_object_cache, $wp_cache_preload_on;
if ( '/' != substr($cache_path, -1)) {
$cache_path .= '/';
}
if ( $valid_nonce ) {
if(isset($_REQUEST['wp_delete_cache'])) {
wp_cache_clean_cache($file_prefix);
$_GET[ 'action' ] = 'regenerate_cache_stats';
}
if ( isset( $_REQUEST[ 'wp_delete_all_cache' ] ) ) {
wp_cache_clean_cache( $file_prefix, true );
$_GET[ 'action' ] = 'regenerate_cache_stats';
}
if(isset($_REQUEST['wp_delete_expired'])) {
wp_cache_clean_expired($file_prefix);
$_GET[ 'action' ] = 'regenerate_cache_stats';
}
}
echo "
";
echo '
' . __( 'Cache Contents', 'wp-super-cache' ) . ' ';
if ( $wp_cache_object_cache ) {
echo "" . __( "Object cache in use. No cache listing available.", 'wp-super-cache' ) . "
";
wp_cache_delete_buttons();
echo "";
return false;
}
$cache_stats = get_option( 'supercache_stats' );
if ( !is_array( $cache_stats ) || ( isset( $_GET[ 'listfiles' ] ) ) || ( $valid_nonce && array_key_exists('action', $_GET) && $_GET[ 'action' ] == 'regenerate_cache_stats' ) ) {
$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 ) ) ) {
$wp_cache_fsize = 0;
if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletewpcache' ) {
$deleteuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', base64_decode( $_GET[ 'uri' ] ) ) );
} else {
$deleteuri = '';
}
if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletesupercache' ) {
$supercacheuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace("/(\?.*)?$/", '', base64_decode( $_GET[ 'uri' ] ) ) ) );
$supercacheuri = trailingslashit( realpath( $cache_path . 'supercache/' . $supercacheuri ) );
if ( wp_cache_confirm_delete( $supercacheuri ) ) {
printf( __( "Deleting supercache file:
%s ", 'wp-super-cache' ), $supercacheuri );
@unlink( $supercacheuri . 'index.html' );
@unlink( $supercacheuri . 'index.html.gz' );
prune_super_cache( $supercacheuri . 'page', true );
@rmdir( $supercacheuri );
}
}
while( false !== ( $file = readdir( $handle ) ) ) {
if ( strpos( $file, $file_prefix ) !== false && substr( $file, -4 ) == '.php' ) {
if ( false == file_exists( $blog_cache_dir . 'meta/' . $file ) ) {
@unlink( $blog_cache_dir . $file );
continue; // meta does not exist
}
$mtime = filemtime( $blog_cache_dir . 'meta/' . $file );
$fsize = @filesize( $blog_cache_dir . $file );
if ( $fsize > 0 )
$fsize = $fsize - 15; // die() command takes 15 bytes at the start of the file
$age = $now - $mtime;
if ( $valid_nonce && isset( $_GET[ 'listfiles' ] ) ) {
$meta = json_decode( wp_cache_get_legacy_cache( $blog_cache_dir . 'meta/' . $file ), true );
if ( $deleteuri != '' && $meta[ 'uri' ] == $deleteuri ) {
printf( __( "Deleting wp-cache file:
%s ", 'wp-super-cache' ), esc_html( $deleteuri ) );
@unlink( $blog_cache_dir . 'meta/' . $file );
@unlink( $blog_cache_dir . $file );
continue;
}
$meta[ 'age' ] = $age;
foreach( $meta as $key => $val )
$meta[ $key ] = esc_html( $val );
if ( $cache_max_time > 0 && $age > $cache_max_time ) {
$expired_list[ $age ][] = $meta;
} else {
$cached_list[ $age ][] = $meta;
}
}
if ( $cache_max_time > 0 && $age > $cache_max_time ) {
$expired++;
} else {
$count++;
}
$wp_cache_fsize += $fsize;
$fsize = intval($fsize/1024);
}
}
closedir($handle);
}
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';
}
// Supercache files
$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 ( false == $wp_cache_preload_on && is_file( $supercachedir ) && $cache_max_time > 0 && $filem + $cache_max_time <= $now ) {
$sizes[ 'expired' ] ++;
if ( $valid_nonce && isset( $_GET[ 'listfiles' ] ) )
$sizes[ 'expired_list' ][ str_replace( $cache_path . 'supercache/' , '', $supercachedir ) ] = $now - $filem;
} else {
if ( $valid_nonce && isset( $_GET[ 'listfiles' ] ) && $filem )
$sizes[ 'cached_list' ][ str_replace( $cache_path . 'supercache/' , '', $supercachedir ) ] = $now - $filem;
}
}
$sizes[ 'ts' ] = time();
$cache_stats = array( 'generated' => time(), 'supercache' => $sizes, 'wpcache' => array( 'cached' => $count, 'expired' => $expired, 'fsize' => $wp_cache_fsize ) );
update_option( 'supercache_stats', $cache_stats );
} else {
echo "
" . __( 'Cache stats are not automatically generated. You must click the link below to regenerate the stats on this page.', 'wp-super-cache' ) . "
";
echo "
'wpsupercache', 'tab' => 'contents', 'action' => 'regenerate_cache_stats' ) ), 'wp-cache' ) . "'>" . __( 'Regenerate cache stats', 'wp-super-cache' ) . " ";
if ( is_array( $cache_stats ) ) {
echo "
" . sprintf( __( 'Cache stats last generated: %s minutes ago.', 'wp-super-cache' ), number_format( ( time() - $cache_stats[ 'generated' ] ) / 60 ) ) . "
";
}
$cache_stats = get_option( 'supercache_stats' );
}// regerate stats cache
if ( is_array( $cache_stats ) ) {
echo "
" . __( 'WP-Cache', 'wp-super-cache' ) . " ({$cache_stats[ 'wpcache' ][ 'fsize' ]})
";
echo "
" . sprintf( __( '%s Cached Pages', 'wp-super-cache' ), $cache_stats[ 'wpcache' ][ 'cached' ] ) . " ";
echo "" . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), $cache_stats[ 'wpcache' ][ 'expired' ] ) . " ";
$divisor = $cache_compression == 1 ? 2 : 1;
if ( array_key_exists('fsize', (array)$cache_stats[ 'supercache' ]) )
$fsize = $cache_stats[ 'supercache' ][ 'fsize' ] / 1024;
else
$fsize = 0;
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', 'wp-super-cache' ) . " ({$fsize})
";
echo "
" . sprintf( __( '%s Cached Pages', 'wp-super-cache' ), intval( $cache_stats[ 'supercache' ][ 'cached' ] / $divisor ) ) . " ";
if (isset($now) && isset($sizes))
$age = intval(($now - $sizes['ts'])/60);
else
$age = 0;
echo "" . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), intval( $cache_stats[ 'supercache' ][ 'expired' ] / $divisor ) ) . " ";
if ( $valid_nonce && array_key_exists('listfiles', $_GET) && $_GET[ 'listfiles' ] ) {
echo "
";
if ( isset( $cached_list ) && is_array( $cached_list ) && !empty( $cached_list ) ) {
echo "
" . __( 'Fresh WP-Cached Files', 'wp-super-cache' ) . " ";
echo "
";
}
if ( isset( $expired_list ) && is_array( $expired_list ) && !empty( $expired_list ) ) {
echo "
" . __( 'Stale WP-Cached Files', 'wp-super-cache' ) . " ";
echo "
";
}
if ( is_array( $sizes[ 'cached_list' ] ) & !empty( $sizes[ 'cached_list' ] ) ) {
echo "
" . __( 'Fresh Super Cached Files', 'wp-super-cache' ) . " ";
echo "
";
}
if ( is_array( $sizes[ 'expired_list' ] ) && !empty( $sizes[ 'expired_list' ] ) ) {
echo "
" . __( 'Stale Super Cached Files', 'wp-super-cache' ) . " ";
echo "
";
}
echo "
";
echo "
" . __( 'Hide file list', 'wp-super-cache' ) . "
";
} elseif ( $cache_stats[ 'supercache' ][ 'cached' ] > 500 || $cache_stats[ 'supercache' ][ 'expired' ] > 500 || ( $cache_stats[ 'wpcache' ][ 'cached' ] / $divisor ) > 500 || ( $cache_stats[ 'wpcache' ][ 'expired' ] / $divisor) > 500 ) {
echo "
" . __( 'Too many cached files, no listing possible.', 'wp-super-cache' ) . "
";
} else {
echo "
'wpsupercache', 'listfiles' => '1' ) ), 'wp-cache' ) . "#listfiles'>" . __( 'List all cached files', 'wp-super-cache' ) . "
";
}
if ( $cache_max_time > 0 )
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 ) . "
";
} // cache_stats
wp_cache_delete_buttons();
echo '';
}
function wp_cache_delete_buttons() {
echo '
\n";
echo '
\n";
if ( ( defined( 'VHOST' ) || defined( 'SUBDOMAIN_INSTALL' ) || defined( 'SUNRISE' ) || ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) ) && wpsupercache_site_admin() ) {
echo '
\n";
}
}
function delete_cache_dashboard() {
if ( false == wpsupercache_site_admin() )
return false;
if ( function_exists('current_user_can') && !current_user_can('manage_options') )
return false;
echo "
" . __( 'Delete Cache', 'wp-super-cache' ) . " ";
}
add_action( 'dashmenu', 'delete_cache_dashboard' );
function wpsc_dirsize($directory, $sizes) {
global $cache_max_time, $cache_path, $valid_nonce, $wp_cache_preload_on;
$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 ( $wp_cache_preload_on == false && $cache_max_time > 0 && $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 && array_key_exists('listfiles', $_GET) && $_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, $all = false ) {
global $wpdb, $cache_path, $supercachedir, $blog_cache_dir, $wp_cache_object_cache;
if ( $wp_cache_object_cache && function_exists( "reset_oc_version" ) )
reset_oc_version();
if ( $all == true && wpsupercache_site_admin() && function_exists( 'prune_super_cache' ) ) {
prune_super_cache( $cache_path, true );
return true;
}
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 );
}
$_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
} else {
wp_cache_debug( 'Warning! prune_super_cache() not found in wp-cache.php', 1 );
}
wp_cache_clean_legacy_files( $blog_cache_dir, $file_prefix );
wp_cache_clean_legacy_files( $cache_path, $file_prefix );
}
function wp_cache_clean_legacy_files( $dir, $file_prefix ) {
global $wpdb;
$dir = trailingslashit( $dir );
if ( @is_dir( $dir . 'meta' ) == false )
return false;
if ( $handle = @opendir( $dir ) ) {
while ( false !== ( $file = readdir( $handle ) ) ) {
if ( is_file( $dir . $file ) == false || $file == 'index.html' ) {
continue;
}
if ( strpos( $file, $file_prefix ) !== false ) {
if ( strpos( $file, '.html' ) ) {
// delete old legacy files immediately
@unlink( $dir . $file);
@unlink( $dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
} else {
$meta = json_decode( wp_cache_get_legacy_cache( $dir . 'meta/' . $file ), true );
if ( ( defined( 'VHOST' ) || defined( 'SUBDOMAIN_INSTALL' ) || defined( 'SUNRISE' ) || ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) ) && $meta[ 'blog_id' ] != $wpdb->blogid )
continue;
@unlink( $dir . $file);
@unlink( $dir . 'meta/' . $file);
}
}
}
closedir($handle);
}
}
function wp_cache_clean_expired($file_prefix) {
global $cache_path, $cache_max_time, $blog_cache_dir, $wp_cache_preload_on;
if ( $cache_max_time == 0 ) {
return false;
}
// If phase2 was compiled, use its function to avoid race-conditions
if(function_exists('wp_cache_phase2_clean_expired')) {
if ( $wp_cache_preload_on != 1 && function_exists ('prune_super_cache')) {
$dir = get_supercache_dir();
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);
}
$now = time();
if ( $handle = @opendir( $blog_cache_dir ) ) {
while ( false !== ( $file = readdir( $handle ) ) ) {
if ( strpos( $file, $file_prefix ) !== false ) {
if ( strpos( $file, '.html' ) ) {
@unlink( $blog_cache_dir . $file);
@unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
} elseif ( ( filemtime( $blog_cache_dir . $file ) + $cache_max_time ) <= $now ) {
@unlink( $blog_cache_dir . $file );
@unlink( $blog_cache_dir . '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 ( false == wpsupercache_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&tab=contents', '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, $wp_cache_phase1_loaded;
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' ) ) . '
';
if ( defined( 'WP_CACHE' ) && WP_CACHE == true && ( defined( 'ADVANCEDCACHEPROBLEM' ) || ( $cache_enabled && false == isset( $wp_cache_phase1_loaded ) ) ) ) {
echo '
' . sprintf( __( 'Warning! WP Super Cache caching was broken but has been fixed ! The script advanced-cache.php could not load wp-cache-phase1.php. The file %1$s/advanced-cache.php has been recreated and WPCACHEHOME fixed in your wp-config.php. Reload to hide this message.', 'wp-super-cache' ), WP_CONTENT_DIR ) . '
';
wp_cache_create_advanced_cache();
}
}
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, $wpdb;
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' ), home_url() ), sprintf( __( "Please visit %s to clear the cache as the front page of your site is now downloading!", 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) );
} else {
wp_cache_clear_cache( $wpdb->blogid );
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Cache Cleared!', 'wp-super-cache' ), home_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' ), admin_url( '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' ), home_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' ), admin_url( 'options-general.php?page=wpsupercache' ), $wp_super_cache_front_page_text ) );
} else {
wp_cache_clear_cache( $wpdb->blogid );
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is not correct! Cache Cleared!', 'wp-super-cache' ), home_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' ), admin_url( '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' ), home_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", admin_url( 'options-general.php?page=wpsupercache' ) ) );
}
if ( !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
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' );
function update_cached_mobile_ua_list( $mobile_browsers, $mobile_prefixes = 0, $mobile_groups = 0 ) {
global $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_groups;
if ( is_array( $mobile_browsers ) ) {
$wp_cache_mobile_browsers = $mobile_browsers;
wp_cache_replace_line('^ *\$wp_cache_mobile_browsers', "\$wp_cache_mobile_browsers = '" . implode( ', ', $mobile_browsers ) . "';", $wp_cache_config_file);
}
if ( is_array( $mobile_prefixes ) ) {
$wp_cache_mobile_prefixes = $mobile_prefixes;
wp_cache_replace_line('^ *\$wp_cache_mobile_prefixes', "\$wp_cache_mobile_prefixes = '" . implode( ', ', $mobile_prefixes ) . "';", $wp_cache_config_file);
}
if ( is_array( $mobile_groups ) ) {
$wp_cache_mobile_groups = $mobile_groups;
wp_cache_replace_line('^ *\$wp_cache_mobile_groups', "\$wp_cache_mobile_groups = '" . implode( ', ', $mobile_groups ) . "';", $wp_cache_config_file);
}
return true;
}
function wpsc_update_htaccess() {
extract( wpsc_get_htaccess_info() );
wpsc_remove_marker( $home_path.'.htaccess', 'WordPress' ); // remove original WP rules so SuperCache rules go on top
if( insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', explode( "\n", $rules ) ) && insert_with_markers( $home_path.'.htaccess', 'WordPress', explode( "\n", $wprules ) ) ) {
return true;
} else {
return false;
}
}
function wpsc_update_htaccess_form( $short_form = true ) {
global $wpmu_version;
extract( wpsc_get_htaccess_info() );
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" . esc_html( $rules ) . "# END WPSuperCache ";
} else {
if ( $short_form == false ) {
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 ) . " ";
_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" . esc_html( $rules ) . "# END WPSuperCache ";
echo "
" . sprintf( __( 'Rules must be added to %s too:', 'wp-super-cache' ), WP_CONTENT_DIR . "/cache/.htaccess" ) . "
";
echo "
# BEGIN supercache\n" . esc_html( $gziprules ) . "# END supercache ";
}
if ( !isset( $wpmu_version ) || $wpmu_version == '' ) {
echo '
\n";
}
}
}
/*
* Return LOGGED_IN_COOKIE if it doesn't begin with wordpress_logged_in
* to avoid having people update their .htaccess file
*/
function wpsc_get_logged_in_cookie() {
$logged_in_cookie = 'wordpress_logged_in';
if ( defined( 'LOGGED_IN_COOKIE' ) && substr( constant( 'LOGGED_IN_COOKIE' ), 0, 19 ) != 'wordpress_logged_in' )
$logged_in_cookie = constant( 'LOGGED_IN_COOKIE' );
return $logged_in_cookie;
}
function wpsc_get_htaccess_info() {
global $wp_cache_mobile_enabled, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_disable_utf8;
if ( isset( $_SERVER[ "PHP_DOCUMENT_ROOT" ] ) ) {
$document_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
$apache_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
} else {
$document_root = $_SERVER[ "DOCUMENT_ROOT" ];
$apache_root = '%{DOCUMENT_ROOT}';
}
$content_dir_root = $document_root;
if ( strpos( $document_root, '/kunden/homepages/' ) === 0 ) {
// http://wordpress.org/support/topic/plugin-wp-super-cache-how-to-get-mod_rewrite-working-on-1and1-shared-hosting?replies=1
// On 1and1, PHP's directory structure starts with '/homepages'. The
// Apache directory structure has an extra '/kunden' before it.
// Also 1and1 does not support the %{DOCUMENT_ROOT} variable in
// .htaccess files.
// This prevents the $inst_root from being calculated correctly and
// means that the $apache_root is wrong.
//
// e.g. This is an example of how Apache and PHP see the directory
// structure on 1and1:
// Apache: /kunden/homepages/xx/dxxxxxxxx/htdocs/site1/index.html
// PHP: /homepages/xx/dxxxxxxxx/htdocs/site1/index.html
// Here we fix up the paths to make mode_rewrite work on 1and1 shared hosting.
$content_dir_root = substr( $content_dir_root, 7 );
$apache_root = $document_root;
}
$home_path = get_home_path();
$home_root = parse_url(get_bloginfo('url'));
$home_root = isset( $home_root['path'] ) ? trailingslashit( $home_root['path'] ) : '/';
$home_root_lc = str_replace( '//', '/', strtolower( $home_root ) );
$inst_root = str_replace( '//', '/', '/' . trailingslashit( str_replace( $content_dir_root, '', str_replace( '\\', '/', WP_CONTENT_DIR ) ) ) );
$wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) );
$wprules = str_replace( "RewriteEngine On\n", '', $wprules );
$wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
$scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
if( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
$condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*[^/]$";
$condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*//.*$";
}
$condition_rules[] = "RewriteCond %{REQUEST_METHOD} !POST";
$condition_rules[] = "RewriteCond %{QUERY_STRING} !.*=.*";
$condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|" . wpsc_get_logged_in_cookie() . "|wp-postpass_).*$";
$condition_rules[] = "RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\\\"]+ [NC]";
$condition_rules[] = "RewriteCond %{HTTP:Profile} !^[a-z0-9\\\"]+ [NC]";
if ( $wp_cache_mobile_enabled ) {
if ( false == empty( $wp_cache_mobile_browsers ) )
$condition_rules[] = "RewriteCond %{HTTP_USER_AGENT} !^.*(" . addcslashes( implode( '|', $wp_cache_mobile_browsers ), ' ' ) . ").* [NC]";
if ( false == empty( $wp_cache_mobile_prefixes ) )
$condition_rules[] = "RewriteCond %{HTTP_user_agent} !^(" . addcslashes( implode( '|', $wp_cache_mobile_prefixes ), ' ' ) . ").* [NC]";
}
$condition_rules = apply_filters( 'supercacherewriteconditions', $condition_rules );
$rules = "
\n";
$rules .= "RewriteEngine On\n";
$rules .= "RewriteBase $home_root\n"; // props Chris Messina
$rules .= "#If you serve pages from behind a proxy you may want to change 'RewriteCond %{HTTPS} on' to something more sensible\n";
if ( isset( $wp_cache_disable_utf8 ) == false || $wp_cache_disable_utf8 == 0 ) {
$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 %{HTTPS} on\n";
$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html.gz -f\n";
$rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html.gz\" [L]\n\n";
$rules .= "CONDITION_RULES";
$rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
$rules .= "RewriteCond %{HTTPS} !on\n";
$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html.gz -f\n";
$rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html.gz\" [L]\n\n";
$rules .= "CONDITION_RULES";
$rules .= "RewriteCond %{HTTPS} on\n";
$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html -f\n";
$rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html\" [L]\n\n";
$rules .= "CONDITION_RULES";
$rules .= "RewriteCond %{HTTPS} !on\n";
$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html -f\n";
$rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html\" [L]\n";
$rules .= " \n";
$rules = apply_filters( 'supercacherewriterules', $rules );
$rules = str_replace( "CONDITION_RULES", implode( "\n", $condition_rules ) . "\n", $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=3, must-revalidate'\n \n";
$gziprules .= "
\n ExpiresActive On\n ExpiresByType text/html A3\n \n";
$gziprules .= "Options -Indexes\n";
return array( "document_root" => $document_root, "apache_root" => $apache_root, "home_path" => $home_path, "home_root" => $home_root, "home_root_lc" => $home_root_lc, "inst_root" => $inst_root, "wprules" => $wprules, "scrules" => $scrules, "condition_rules" => $condition_rules, "rules" => $rules, "gziprules" => $gziprules );
}
function clear_post_supercache( $post_id ) {
$dir = get_current_url_supercache_dir( $post_id );
if ( false == @is_dir( $dir ) )
return false;
if ( !function_exists( 'prune_super_cache' ) )
include_once( 'wp-cache-phase2.php' );
wp_cache_debug( "clear_post_supercache: deleting $dir/index*.html files", 2 );
$files_to_check = get_all_supercache_filenames( $dir );
foreach( $files_to_check as $cache_file ) {
prune_super_cache( $dir . $cache_file, true );
}
}
function wp_cron_preload_cache() {
global $wpdb, $wp_cache_preload_interval, $wp_cache_preload_posts, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $cache_path, $wp_cache_preload_taxonomies;
if ( get_option( 'preload_cache_stop' ) ) {
delete_option( 'preload_cache_stop' );
wp_cache_debug( "wp_cron_preload_cache: preload cancelled", 1 );
return true;
}
$mutex = $cache_path . "preload_mutex.tmp";
sleep( 3 + mt_rand( 1, 5 ) );
if ( @file_exists( $mutex ) ) {
if ( @filemtime( $mutex ) > ( time() - 600 ) ) {
wp_cache_debug( "wp_cron_preload_cache: preload mutex found and less than 600 seconds old. Aborting preload.", 1 );
return true;
} else {
wp_cache_debug( "wp_cron_preload_cache: old preload mutex found and deleted. Preload continues.", 1 );
@unlink( $mutex );
}
}
$fp = @fopen( $mutex, 'w' );
@fclose( $fp );
$counter = get_option( 'preload_cache_counter' );
if ( is_array( $counter ) == false ) {
wp_cache_debug( "wp_cron_preload_cache: setting up preload for the first time!", 5 );
$counter = array( 'c' => 0, 't' => time() );
update_option( 'preload_cache_counter', $counter );
}
$c = $counter[ 'c' ];
update_option( 'preload_cache_counter', array( 'c' => ( $c + 100 ), 't' => time() ) );
if ( $wp_cache_preload_email_me && $c == 0 )
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Started', 'wp-super-cache' ), home_url(), '' ), ' ' );
if ( $wp_cache_preload_posts == 'all' || $c < $wp_cache_preload_posts ) {
wp_cache_debug( "wp_cron_preload_cache: doing taxonomy preload.", 5 );
$permalink_counter_msg = $cache_path . "preload_permalink.txt";
if ( isset( $wp_cache_preload_taxonomies ) && $wp_cache_preload_taxonomies ) {
$taxonomies = apply_filters( 'wp_cache_preload_taxonomies', array( 'post_tag' => 'tag', 'category' => 'category' ) );
foreach( $taxonomies as $taxonomy => $path ) {
$taxonomy_filename = $cache_path . "taxonomy_" . $taxonomy . ".txt";
if ( $c == 0 )
@unlink( $taxonomy_filename );
if ( false == @file_exists( $taxonomy_filename ) ) {
$out = '';
$records = get_terms( $taxonomy );
foreach( $records as $term ) {
$out .= get_term_link( $term ). "\n";
}
$fp = fopen( $taxonomy_filename, 'w' );
if ( $fp ) {
fwrite( $fp, $out );
fclose( $fp );
}
$details = explode( "\n", $out );
} else {
$details = explode( "\n", file_get_contents( $taxonomy_filename ) );
}
if ( count( $details ) != 1 && $details[ 0 ] != '' ) {
$rows = array_splice( $details, 0, 50 );
if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume == 'many' )
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Refreshing %2$s taxonomy from %3$d to %4$d', 'wp-super-cache' ), home_url(), $taxonomy, $c, ($c+100) ), 'Refreshing: ' . print_r( $rows, 1 ) );
foreach( (array)$rows as $url ) {
set_time_limit( 60 );
if ( $url == '' )
continue;
$url_info = parse_url( $url );
$dir = get_supercache_dir() . $url_info[ 'path' ];
wp_cache_debug( "wp_cron_preload_cache: delete $dir", 5 );
prune_super_cache( $dir );
$fp = @fopen( $permalink_counter_msg, 'w' );
if ( $fp ) {
@fwrite( $fp, "$taxonomy: $url" );
@fclose( $fp );
}
wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
wp_cache_debug( "wp_cron_preload_cache: fetched $url", 5 );
sleep( 1 );
}
$fp = fopen( $taxonomy_filename, 'w' );
if ( $fp ) {
fwrite( $fp, implode( "\n", $details ) );
fclose( $fp );
}
}
}
}
}
if ( $wp_cache_preload_posts == 'all' || $c < $wp_cache_preload_posts ) {
$types = get_post_types( array( 'public' => true, 'publicly_queryable' => true ), 'names', 'or' );
$types = array_map( 'esc_sql', $types );
$types = "'" . implode( "','", $types ) . "'";
$posts = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE ( post_type IN ( $types ) ) AND post_status = 'publish' ORDER BY ID ASC LIMIT $c, 100" );
wp_cache_debug( "wp_cron_preload_cache: got 100 posts from position $c.", 5 );
} else {
wp_cache_debug( "wp_cron_preload_cache: no more posts to get. Limit ($wp_cache_preload_posts) reached.", 5 );
$posts = false;
}
if ( !isset( $wp_cache_preload_email_volume ) )
$wp_cache_preload_email_volume = 'medium';
if ( $posts ) {
if ( get_option( 'show_on_front' ) == 'page' ) {
$page_on_front = get_option( 'page_on_front' );
$page_for_posts = get_option( 'page_for_posts' );
} else {
$page_on_front = $page_for_posts = 0;
}
if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume == 'many' )
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Refreshing posts from %2$d to %3$d', 'wp-super-cache' ), home_url(), $c, ($c+100) ), ' ' );
$msg = '';
$count = $c + 1;
$permalink_counter_msg = $cache_path . "preload_permalink.txt";
foreach( $posts as $post_id ) {
set_time_limit( 60 );
if ( $page_on_front != 0 && ( $post_id == $page_on_front || $post_id == $page_for_posts ) )
continue;
clear_post_supercache( $post_id );
$url = get_permalink( $post_id );
$fp = @fopen( $permalink_counter_msg, 'w' );
if ( $fp ) {
@fwrite( $fp, $count . " " . $url );
@fclose( $fp );
}
if ( @file_exists( $cache_path . "stop_preload.txt" ) ) {
wp_cache_debug( "wp_cron_preload_cache: cancelling preload. stop_preload.txt found.", 5 );
@unlink( $mutex );
@unlink( $cache_path . "stop_preload.txt" );
update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
if ( $wp_cache_preload_email_me )
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Stopped', 'wp-super-cache' ), home_url(), '' ), ' ' );
return true;
}
$msg .= "$url\n";
wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
wp_cache_debug( "wp_cron_preload_cache: fetched $url", 5 );
sleep( 1 );
$count++;
}
if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume != 'less' )
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] %2$d posts refreshed', 'wp-super-cache' ), home_url(), ($c+100) ), __( "Refreshed the following posts:", 'wp-super-cache' ) . "\n$msg" );
if ( defined( 'DOING_CRON' ) ) {
wp_cache_debug( "wp_cron_preload_cache: scheduling the next preload in 30 seconds.", 5 );
wp_schedule_single_event( time() + 30, 'wp_cache_preload_hook' );
}
} else {
$msg = '';
update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
if ( (int)$wp_cache_preload_interval && defined( 'DOING_CRON' ) ) {
if ( $wp_cache_preload_email_me )
$msg = sprintf( __( 'Scheduling next preload refresh in %d minutes.', 'wp-super-cache' ), (int)$wp_cache_preload_interval );
wp_cache_debug( "wp_cron_preload_cache: no more posts. scheduling next preload in $wp_cache_preload_interval minutes.", 5 );
wp_schedule_single_event( time() + ( (int)$wp_cache_preload_interval * 60 ), 'wp_cache_full_preload_hook' );
}
global $file_prefix, $cache_max_time;
if ( $wp_cache_preload_interval > 0 ) {
$cache_max_time = (int)$wp_cache_preload_interval * 60; // fool the GC into expiring really old files
} else {
$cache_max_time = 86400; // fool the GC into expiring really old files
}
if ( $wp_cache_preload_email_me )
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Cache Preload Completed', 'wp-super-cache' ), home_url() ), __( "Cleaning up old supercache files.", 'wp-super-cache' ) . "\n" . $msg );
wp_cache_debug( "wp_cron_preload_cache: clean expired cache files older than $cache_max_time seconds.", 5 );
wp_cache_phase2_clean_expired( $file_prefix, true ); // force cleanup of old files.
}
@unlink( $mutex );
}
add_action( 'wp_cache_preload_hook', 'wp_cron_preload_cache' );
add_action( 'wp_cache_full_preload_hook', 'wp_cron_preload_cache' );
function next_preload_message( $hook, $text, $limit = 0 ) {
global $currently_preloading, $wp_cache_preload_interval;
if ( $next_preload = wp_next_scheduled( $hook ) ) {
$next_time = $next_preload - time();
if ( $limit != 0 && $next_time > $limit )
return false;
$h = $m = $s = 0;
if ( $next_time > 0 ) {
$m = (int)($next_time / 60);
$s = $next_time % 60;
$h = (int)($m / 60); $m = $m % 60;
}
if ( $next_time > 0 && $next_time < ( 60 * $wp_cache_preload_interval ) )
echo '
' . sprintf( $text, $h, $m, $s ) . '
';
if ( ( $next_preload - time() ) <= 60 )
$currently_preloading = true;
}
}
function option_preload_cache_counter( $value ) {
if ( false == is_array( $value ) ) {
$ret = array( 'c' => $value, 't' => time(), 'first' => 1 );
return $ret;
}
return $value;
}
add_filter( 'option_preload_cache_counter', 'option_preload_cache_counter' );
function check_up_on_preloading() {
$value = get_option( 'preload_cache_counter' );
if ( $value[ 'c' ] > 0 && ( time() - $value[ 't' ] ) > 3600 && false == wp_next_scheduled( 'wp_cache_preload_hook' ) ) {
if ( is_admin() )
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Preload may have stalled.', 'wp-super-cache' ), get_bloginfo( 'url' ) ), sprintf( __( "Preload has been restarted.\n%s", 'wp-super-cache' ), admin_url( "options-general.php?page=wpsupercache" ) ) );
wp_schedule_single_event( time() + 30, 'wp_cache_preload_hook' );
}
}
add_action( 'init', 'check_up_on_preloading' ); // sometimes preloading stops working. Kickstart it.
function wp_cache_disable_plugin( $delete_config_file = true ) {
global $wp_cache_config_file, $wp_rewrite;
if ( file_exists( ABSPATH . 'wp-config.php') ) {
$global_config_file = ABSPATH . 'wp-config.php';
} else {
$global_config_file = dirname(ABSPATH) . '/wp-config.php';
}
$line = 'define(\'WP_CACHE\', true);';
if ( strpos( file_get_contents( $global_config_file ), $line ) && ( !is_writeable_ACLSafe( $global_config_file ) || !wp_cache_replace_line( 'define *\( *\'WP_CACHE\'', '//' . $line, $global_config_file ) ) )
wp_die( "Could not remove WP_CACHE define from $global_config_file. Please edit that file and remove the line containing the text 'WP_CACHE'. Then refresh this page." );
uninstall_supercache( WP_CONTENT_DIR . '/cache' );
$file_not_deleted = false;
if ( @file_exists( WP_CONTENT_DIR . "/advanced-cache.php" ) ) {
if ( false == @unlink( WP_CONTENT_DIR . "/advanced-cache.php" ) )
$file_not_deleted[] = 'advanced-cache.php';
}
if ( $delete_config_file && @file_exists( WP_CONTENT_DIR . "/wp-cache-config.php" ) ) {
if ( false == unlink( WP_CONTENT_DIR . "/wp-cache-config.php" ) )
$file_not_deleted[] = 'wp-cache-config.php';
}
if ( $file_not_deleted ) {
$msg = "
One or more files could not be deleted. These files and directories must be made writeable:
\n
" . WP_CONTENT_DIR . " \n";
$code = "\n";
foreach( (array)$file_not_deleted as $filename ) {
$msg .= "" . WP_CONTENT_DIR . "/{$filename} ";
$code .= "chmod 666 " . WP_CONTENT_DIR . "/{$filename} \n";
}
$code .= " \n";
$msg .= "\n
First try fixing the directory permissions with this command and refresh this page:chmod 777 " . WP_CONTENT_DIR . " If you still see this error, you have to fix the permissions on the files themselves and refresh this page again:
{$code}\n
Don't forgot to fix things later:chmod 755 " . WP_CONTENT_DIR . "
If you don't know what chmod is use this Google search to find out all about it.
Please refresh this page when the permissions have been modified.
";
wp_die( $msg );
}
extract( wpsc_get_htaccess_info() );
if ( $scrules != '' && insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', array() ) ) {
$wp_rewrite->flush_rules();
} elseif( $scrules != '' ) {
wp_mail( get_option( 'admin_email' ), __( 'Supercache Uninstall Problems', 'wp-super-cache' ), sprintf( __( "Dear User,\n\nWP Super Cache was removed from your blog but the mod_rewrite rules\nin your .htaccess were not.\n\nPlease edit the following file and remove the code\nbetween 'BEGIN WPSuperCache' and 'END WPSuperCache'. Please backup the file first!\n\n%s\n\nRegards,\nWP Super Cache Plugin\nhttp://wordpress.org/plugins/wp-super-cache/", 'wp-super-cache' ), ABSPATH . '/.htaccess' ) );
}
}
function uninstall_supercache( $folderPath ) { // from http://www.php.net/manual/en/function.rmdir.php
if ( trailingslashit( constant( 'ABSPATH' ) ) == trailingslashit( $folderPath ) )
return false;
if ( @is_dir ( $folderPath ) ) {
$dh = @opendir($folderPath);
while( false !== ( $value = @readdir( $dh ) ) ) {
if ( $value != "." && $value != ".." ) {
$value = $folderPath . "/" . $value;
if ( @is_dir ( $value ) ) {
uninstall_supercache( $value );
} else {
@unlink( $value );
}
}
}
return @rmdir( $folderPath );
} else {
return false;
}
}
function supercache_admin_bar_render() {
global $wp_admin_bar, $wp_cache_not_logged_in;
if ( !is_user_logged_in() || !$wp_cache_not_logged_in )
return false;
if ( function_exists('current_user_can') && false == current_user_can('delete_others_posts') )
return false;
$wp_admin_bar->add_menu( array(
'parent' => '',
'id' => 'delete-cache',
'title' => __( 'Delete Cache', 'wp-super-cache' ),
'meta' => array( 'title' => __( 'Delete cache of the current page', 'wp-super-cache' ) ),
'href' => wp_nonce_url( admin_url( 'index.php?action=delcachepage&path=' . urlencode( preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER[ 'REQUEST_URI' ] ) ) ), 'delete-cache' )
) );
}
add_action( 'wp_before_admin_bar_render', 'supercache_admin_bar_render' );
?>