web/wp-content/plugins/wp-super-cache/wp-cache.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     1 <?php
     1 <?php
     2 /*
     2 /*
     3 Plugin Name: WP Super Cache
     3 Plugin Name: WP Super Cache
     4 Plugin URI: http://ocaoimh.ie/wp-super-cache/
     4 Plugin URI: http://ocaoimh.ie/wp-super-cache/
     5 Description: Very fast caching plugin for WordPress.
     5 Description: Very fast caching plugin for WordPress.
     6 Version: 0.9.8
     6 Version: 1.2
     7 Author: Donncha O Caoimh
     7 Author: Donncha O Caoimh
     8 Author URI: http://ocaoimh.ie/
     8 Author URI: http://ocaoimh.ie/
     9 */
     9 */
    10 
    10 
    11 /*  Copyright 2005-2006  Ricardo Galli Granada  (email : gallir@uib.es)
    11 /*  Copyright 2005-2006  Ricardo Galli Granada  (email : gallir@uib.es)
    12     Copyright 2007-2009 Donncha O Caoimh (http://ocaoimh.ie/)
    12     Copyright 2007-2012 Donncha O Caoimh (http://ocaoimh.ie/) and many others.
    13 
    13 
    14     This program is free software; you can redistribute it and/or modify
    14     This program is free software; you can redistribute it and/or modify
    15     it under the terms of the GNU General Public License as published by
    15     it under the terms of the GNU General Public License as published by
    16     the Free Software Foundation; either version 2 of the License, or
    16     the Free Software Foundation; either version 2 of the License, or
    17     (at your option) any later version.
    17     (at your option) any later version.
    44 
    44 
    45 $wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
    45 $wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
    46 $wp_cache_link = WP_CONTENT_DIR . '/advanced-cache.php';
    46 $wp_cache_link = WP_CONTENT_DIR . '/advanced-cache.php';
    47 $wp_cache_file = WPCACHEHOME . 'advanced-cache.php';
    47 $wp_cache_file = WPCACHEHOME . 'advanced-cache.php';
    48 
    48 
    49 if( !defined( 'WP_CACHE' ) ) {
    49 if( !defined( 'WP_CACHE' ) || ( defined( 'WP_CACHE' ) && constant( 'WP_CACHE' ) == false ) ) {
    50 	$wp_cache_check_wp_config = true;
    50 	$wp_cache_check_wp_config = true;
    51 }
    51 }
    52 
    52 
    53 include(WPCACHEHOME . 'wp-cache-base.php');
    53 include(WPCACHEHOME . 'wp-cache-base.php');
    54 
    54 
    55 function wp_super_cache_text_domain() {
    55 function wp_super_cache_text_domain() {
    56 	load_plugin_textdomain( 'wp-super-cache', WPCACHEHOME . 'languages', basename( dirname( __FILE__ ) ) . '/languages' );
    56 	load_plugin_textdomain( 'wp-super-cache', WPCACHEHOME . 'languages', basename( dirname( __FILE__ ) ) . '/languages' );
    57 }
    57 }
    58 add_action( 'init', 'wp_super_cache_text_domain' );
    58 add_action( 'init', 'wp_super_cache_text_domain' );
       
    59 
       
    60 function wp_cache_set_home() {
       
    61 	global $wp_cache_is_home;
       
    62 	$wp_cache_is_home = ( is_front_page() || is_home() );
       
    63 	if ( $wp_cache_is_home && is_paged() )
       
    64 		$wp_cache_is_home = false;
       
    65 }
       
    66 add_action( 'template_redirect', 'wp_cache_set_home' );
       
    67 
       
    68 
       
    69 // OSSDL CDN plugin (http://wordpress.org/extend/plugins/ossdl-cdn-off-linker/)
       
    70 include_once( WPCACHEHOME . 'ossdl-cdn.php' );
    59 
    71 
    60 // from legolas558 d0t users dot sf dot net at http://www.php.net/is_writable
    72 // from legolas558 d0t users dot sf dot net at http://www.php.net/is_writable
    61 function is_writeable_ACLSafe($path) {
    73 function is_writeable_ACLSafe($path) {
    62 
    74 
    63 	// PHP's is_writable does not work with Win32 NTFS
    75 	// PHP's is_writable does not work with Win32 NTFS
   101 	prune_super_cache ($cache_path, true);
   113 	prune_super_cache ($cache_path, true);
   102 	@unlink( $cache_path . '.htaccess' );
   114 	@unlink( $cache_path . '.htaccess' );
   103 	@unlink( $cache_path . 'meta' );
   115 	@unlink( $cache_path . 'meta' );
   104 	@unlink( $cache_path . 'supercache' );
   116 	@unlink( $cache_path . 'supercache' );
   105 	wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
   117 	wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
   106 }
   118 	wp_clear_scheduled_hook( 'wp_cache_gc' );
   107 register_deactivation_hook( __FILE__, 'wpsupercache_deactivate' );
   119 	wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
       
   120 	wp_cache_disable_plugin();
       
   121 }
       
   122 register_uninstall_hook( __FILE__, 'wpsupercache_deactivate' );
   108 
   123 
   109 function wpsupercache_activate() {
   124 function wpsupercache_activate() {
   110 }
   125 }
   111 register_activation_hook( __FILE__, 'wpsupercache_activate' );
   126 register_activation_hook( __FILE__, 'wpsupercache_activate' );
   112 
   127 
       
   128 function wpsupercache_site_admin() {
       
   129 	if ( function_exists( 'is_super_admin' ) ) {
       
   130 		return is_super_admin();
       
   131 	} elseif ( function_exists( 'is_site_admin' ) ) {
       
   132 		return is_site_admin();
       
   133 	} else {
       
   134 		return true;
       
   135 	}
       
   136 }
       
   137 
   113 function wp_cache_add_pages() {
   138 function wp_cache_add_pages() {
   114 	if( function_exists( 'is_site_admin' ) ) {
   139 	global $wpmu_version;
   115 		if( is_site_admin() ) {
   140 	if ( function_exists( 'is_multisite' ) && is_multisite() && wpsupercache_site_admin() ) {
   116 			add_submenu_page('wpmu-admin.php', 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
   141 		add_submenu_page( 'ms-admin.php', 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager' );
   117 			add_options_page('WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
   142 	} elseif ( isset( $wpmu_version ) && wpsupercache_site_admin() ) {
   118 		}
   143 		add_submenu_page( 'wpmu-admin.php', 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager' );
   119 	} else {
   144 	}
   120 		add_options_page('WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
   145 
       
   146 	if ( wpsupercache_site_admin() ) { // in single or MS mode add this menu item too, but only for superadmins in MS mode.
       
   147 		add_options_page( 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
   121 	}
   148 	}
   122 }
   149 }
   123 add_action('admin_menu', 'wp_cache_add_pages');
   150 add_action('admin_menu', 'wp_cache_add_pages');
       
   151 
       
   152 function wp_cache_network_pages() {
       
   153 	add_submenu_page('settings.php', 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
       
   154 }
       
   155 add_action( 'network_admin_menu', 'wp_cache_network_pages' );
       
   156 
       
   157 function wp_cache_manager_error_checks() {
       
   158 	global $wpmu_version, $wp_cache_debug, $wp_cache_cron_check, $cache_enabled, $super_cache_enabled, $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_mobile_enabled, $wp_cache_mod_rewrite, $cache_path;
       
   159 	global $dismiss_htaccess_warning, $dismiss_readable_warning, $dismiss_gc_warning, $wp_cache_shutdown_gc;
       
   160 
       
   161 	if ( !wpsupercache_site_admin() )
       
   162 		return false;
       
   163 	
       
   164 	if ( version_compare( PHP_VERSION, '5.3.0', '<' ) && ( 1 == ini_get( 'safe_mode' ) || "on" == strtolower( ini_get( 'safe_mode' ) ) ) ) {
       
   165 		echo '<div id="message" class="updated fade"><h3>' . __( 'Warning! PHP Safe Mode Enabled!', 'wp-super-cache' ) . '</h3><p>' .
       
   166 			__( 'You may experience problems running this plugin because SAFE MODE is enabled.', 'wp-super-cache' ) . ' ';
       
   167 		
       
   168 		
       
   169 		if( !ini_get( 'safe_mode_gid' ) ) {
       
   170 			_e( 'Your server is set up to check the owner of PHP scripts before allowing them to read and write files.', 'wp-super-cache' ) . " ";
       
   171 			printf( __( 'You or an administrator may be able to make it work by changing the group owner of the plugin scripts to match that of the web server user. The group owner of the %s/cache/ directory must also be changed. See the <a href="http://php.net/features.safe-mode">safe mode manual page</a> for further details.', 'wp-super-cache' ), WP_CONTENT_DIR );
       
   172 		} else {
       
   173 			_e( 'You or an administrator must disable this. See the <a href="http://php.net/features.safe-mode">safe mode manual page</a> for further details. This cannot be disabled in a .htaccess file unfortunately. It must be done in the php.ini config file.', 'wp-super-cache' );
       
   174 		}
       
   175 		echo '</p></div>';
       
   176 	}
       
   177 
       
   178 	if ( '' == get_option( 'permalink_structure' ) ) {
       
   179 		echo '<div id="message" class="updated fade"><h3>' . __( 'Permlink Structure Error', 'wp-super-cache' ) . '</h3>';
       
   180 		echo "<p>" . __( 'A custom url or permalink structure is required for this plugin to work correctly. Please go to the <a href="options-permalink.php">Permalinks Options Page</a> to configure your permalinks.' ) . "</p>";
       
   181 		echo '</div>';
       
   182 		return false;
       
   183 	}
       
   184 
       
   185 	if( $wp_cache_debug || !$wp_cache_cron_check ) {
       
   186 		if( function_exists( "wp_remote_get" ) == false ) {
       
   187 			$hostname = str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'siteurl' ) ) );
       
   188 			if( strpos( $hostname, '/' ) )
       
   189 				$hostname = substr( $hostname, 0, strpos( $hostname, '/' ) );
       
   190 			$ip = gethostbyname( $hostname );
       
   191 			if( substr( $ip, 0, 3 ) == '127' || substr( $ip, 0, 7 ) == '192.168' ) {
       
   192 				?><div id="message" class="updated fade"><h3><?php printf( __( 'Warning! Your hostname "%s" resolves to %s', 'wp-super-cache' ), $hostname, $ip ); ?></h3>
       
   193 					<p><?php printf( __( 'Your server thinks your hostname resolves to %s. Some services such as garbage collection by this plugin, and WordPress scheduled posts may not operate correctly.', 'wp-super-cache' ), $ip ); ?></p>
       
   194 					<p><?php printf( __( 'Please see entry 16 in the <a href="%s">Troubleshooting section</a> of the readme.txt', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/wp-super-cache/faq/' ); ?></p>
       
   195 					</div>
       
   196 					<?php
       
   197 					return false;
       
   198 			} else {
       
   199 				wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
       
   200 			}
       
   201 		} else {
       
   202 			$cron_url = get_option( 'siteurl' ) . '/wp-cron.php?check=' . wp_hash('187425');
       
   203 			$cron = wp_remote_get($cron_url, array('timeout' => 0.01, 'blocking' => true));
       
   204 			if( is_array( $cron ) ) {
       
   205 				if( $cron[ 'response' ][ 'code' ] == '404' ) {
       
   206 					?><div id="message" class="updated fade"><h3>Warning! wp-cron.php not found!</h3>
       
   207 					<p><?php _e( '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.', 'wp-super-cache' ); ?></p>
       
   208 					<p><?php printf( __( 'Please see entry 16 in the <a href="%s">Troubleshooting section</a> of the readme.txt', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/wp-super-cache/faq/' ); ?></p>
       
   209 					</div>
       
   210 					<?php
       
   211 				} else {
       
   212 					wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
       
   213 				}
       
   214 			}
       
   215 		}
       
   216 	}
       
   217 
       
   218 	if ( !wp_cache_check_link() ||
       
   219 		!wp_cache_verify_config_file() ||
       
   220 		!wp_cache_verify_cache_dir() ) {
       
   221 		echo '<p>' . __( "Cannot continue... fix previous problems and retry.", 'wp-super-cache' ) . '</p>';
       
   222 		return false;
       
   223 	}
       
   224 
       
   225 	if (!wp_cache_check_global_config()) {
       
   226 		return false;
       
   227 	}
       
   228 
       
   229 	if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) { 
       
   230 		?><div id="message" class="updated fade"><h3><?php _e( 'Zlib Output Compression Enabled!', 'wp-super-cache' ); ?></h3>
       
   231 		<p><?php _e( 'PHP is compressing the data sent to the visitors of your site. Disabling this is recommended as the plugin caches the compressed output once instead of compressing the same page over and over again. Also see #21 in the Troubleshooting section. See <a href="http://php.net/manual/en/zlib.configuration.php">this page</a> for instructions on modifying your php.ini.', 'wp-super-cache' ); ?></p></div><?php
       
   232 	}
       
   233 
       
   234 	if( $cache_enabled == true && $super_cache_enabled == true && $wp_cache_mod_rewrite && !got_mod_rewrite() ) {
       
   235 		?><div id="message" class="updated fade"><h3><?php _e( 'Mod rewrite may not be installed!', 'wp-super-cache' ); ?></h3>
       
   236 		<p><?php _e( 'It appears that mod_rewrite is not installed. Sometimes this check isn&#8217;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 legacy or PHP modes.', 'wp-super-cache' ); ?></p></div><?php
       
   237 	}
       
   238 
       
   239 	if( !is_writeable_ACLSafe( $wp_cache_config_file ) ) {
       
   240 		if ( !defined( 'SUBMITDISABLED' ) )
       
   241 			define( "SUBMITDISABLED", 'disabled style="color: #aaa" ' );
       
   242 		?><div id="message" class="updated fade"><h3><?php _e( 'Read Only Mode. Configuration cannot be changed.', 'wp-super-cache' ); ?></h3>
       
   243 		<p><?php printf( __( 'The WP Super Cache configuration file is <code>%s/wp-cache-config.php</code> and cannot be modified. That file must be writeable by the webserver to make any changes.', 'wp-super-cache' ), WP_CONTENT_DIR ); ?>
       
   244 		<?php _e( 'A simple way of doing that is by changing the permissions temporarily using the CHMOD command or through your ftp client. Make sure it&#8217;s globally writeable and it should be fine.', 'wp-super-cache' ); ?></p>
       
   245 		<p><?php _e( '<a href="http://codex.wordpress.org/Changing_File_Permissions">This page</a> explains how to change file permissions.', 'wp-super-cache' ); ?></p>
       
   246 		<?php _e( 'Writeable:', 'wp-super-cache' ); ?> <code>chmod 666 <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code>
       
   247 		<?php _e( 'Readonly:', 'wp-super-cache' ); ?> <code>chmod 644 <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code></p>
       
   248 		</div><?php
       
   249 	} elseif ( !defined( 'SUBMITDISABLED' ) ) {
       
   250 		define( "SUBMITDISABLED", ' ' );
       
   251 	}
       
   252 
       
   253 	$valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
       
   254 	// Check that garbage collection is running
       
   255 	if ( $valid_nonce && $_POST[ 'action' ] == 'dismiss_gc_warning' ) {
       
   256 		wp_cache_replace_line('^ *\$dismiss_gc_warning', "\$dismiss_gc_warning = 1;", $wp_cache_config_file);
       
   257 		$dismiss_gc_warning = 1;
       
   258 	} elseif ( !isset( $dismiss_gc_warning ) ) {
       
   259 		$dismiss_gc_warning = 0;
       
   260 	}
       
   261 	if ( $cache_enabled && ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) && function_exists( 'get_gc_flag' ) ) {
       
   262 		$gc_flag = get_gc_flag();
       
   263 		if ( $dismiss_gc_warning == 0 ) {
       
   264 			if ( false == maybe_stop_gc( $gc_flag ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) {
       
   265 				?><div id="message" class="updated fade"><h3><?php _e( 'Warning! Garbage collection is not scheduled!', 'wp-super-cache' ); ?></h3>
       
   266 				<p><?php _e( 'Garbage collection by this plugin clears out expired and old cached pages on a regular basis. Use <a href="#expirytime">this form</a> to enable it.', 'wp-super-cache' ); ?> </p>
       
   267 				<form action="" method="POST">
       
   268 				<input type="hidden" name="action" value="dismiss_gc_warning" />
       
   269 				<input type="hidden" name="page" value="wpsupercache" />
       
   270 				<?php wp_nonce_field( 'wp-cache' ); ?>
       
   271 				<input type='submit' value='<?php _e( 'Dismiss', 'wp-super-cache' ); ?>' />
       
   272 				</form>
       
   273 				<br />
       
   274 				</div>
       
   275 				<?php
       
   276 			}
       
   277 		}
       
   278 	}
       
   279 
       
   280 	// Server could be running as the owner of the wp-content directory.  Therefore, if it's
       
   281 	// writable, issue a warning only if the permissions aren't 755.
       
   282 	if ( $valid_nonce && $_POST[ 'action' ] == 'dismiss_readable_warning' ) {
       
   283 		wp_cache_replace_line('^ *\$dismiss_readable_warning', "\$dismiss_readable_warning = 1;", $wp_cache_config_file);
       
   284 		$dismiss_readable_warning = 1;
       
   285 	} elseif ( !isset( $dismiss_readable_warning ) ) {
       
   286 		$dismiss_readable_warning = 0;
       
   287 	}
       
   288 	if( $dismiss_readable_warning == 0 && is_writeable_ACLSafe( WP_CONTENT_DIR . '/' ) ) {
       
   289 		$wp_content_stat = stat(WP_CONTENT_DIR . '/');
       
   290 		$wp_content_mode = decoct( $wp_content_stat[ 'mode' ] & 0777 );
       
   291 		if( substr( $wp_content_mode, -2 ) == '77' ) {
       
   292 			?><div id="message" class="updated fade"><h3><?php printf( __( 'Warning! %s is writeable!', 'wp-super-cache' ), WP_CONTENT_DIR ); ?></h3>
       
   293 			<p><?php printf( __( 'You should change the permissions on %s and make it more restrictive. Use your ftp client, or the following command to fix things:', 'wp-super-cache' ), WP_CONTENT_DIR ); ?> <code>chmod 755 <?php echo WP_CONTENT_DIR; ?>/</code></p>
       
   294 			<p><?php _e( '<a href="http://codex.wordpress.org/Changing_File_Permissions">This page</a> explains how to change file permissions.', 'wp-super-cache' ); ?></p>
       
   295 			<form action="" method="POST">
       
   296 			<input type="hidden" name="action" value="dismiss_readable_warning" />
       
   297 			<input type="hidden" name="page" value="wpsupercache" />
       
   298 			<?php wp_nonce_field( 'wp-cache' ); ?>
       
   299 			<input type='submit' value='<?php _e( 'Dismiss', 'wp-super-cache' ); ?>' />
       
   300 			</form>
       
   301 			<br />
       
   302 			</div>
       
   303 			<?php
       
   304 		}
       
   305 	}
       
   306 
       
   307 	if ( function_exists( "is_main_site" ) && true == is_main_site() ) {
       
   308 	$home_path = trailingslashit( get_home_path() );
       
   309 	$scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
       
   310 	if ( $cache_enabled && $wp_cache_mod_rewrite && !$wp_cache_mobile_enabled && strpos( $scrules, addcslashes( implode( '|', $wp_cache_mobile_browsers ), ' ' ) ) ) {
       
   311 		echo '<div id="message" class="updated fade"><h3>' . __( 'Mobile rewrite rules detected', 'wp-super-cache' ) . "</h3>";
       
   312 		echo "<p>" . __( 'For best performance you should enable "Mobile device support" or delete the mobile rewrite rules in your .htaccess. Look for the 2 lines with the text "2.0\ MMP|240x320" and delete those.', 'wp-super-cache' ) . "</p><p>" . __( 'This will have no affect on ordinary users but mobile users will see uncached pages.', 'wp-super-cache' ) . "</p></div>";
       
   313 	} elseif ( $wp_cache_mod_rewrite && $cache_enabled && $wp_cache_mobile_enabled && $scrules != '' && ( 
       
   314 		( false == empty( $wp_cache_mobile_prefixes ) && false === strpos( $scrules, addcslashes( implode( '|', $wp_cache_mobile_prefixes ), ' ' ) ) ) ||
       
   315 		( false == empty( $wp_cache_mobile_browsers ) && false === strpos( $scrules, addcslashes( implode( '|', $wp_cache_mobile_browsers ), ' ' ) ) ) )
       
   316 		) {
       
   317 		?>
       
   318 			<div id="message" class="updated fade"><h3><?php _e( 'Rewrite rules must be updated', 'wp-super-cache' ); ?></h3>
       
   319 			<p><?php _e( 'The rewrite rules required by this plugin have changed or are missing. ', 'wp-super-cache' ); ?>
       
   320 			<?php _e( 'Mobile support requires extra rules in your .htaccess file, or you can set the plugin to legacy mode. Here are your options (in order of difficulty):', 'wp-super-cache' ); ?>
       
   321 			<ol><li> <?php _e( 'Set the plugin to legacy mode and enable mobile support.', 'wp-super-cache' ); ?></li>
       
   322 			<li> <?php _e( 'Scroll down the Advanced Settings page and click the <strong>Update Mod_Rewrite Rules</strong> button.', 'wp-super-cache' ); ?></li>
       
   323 			<li> <?php printf( __( 'Delete the plugin mod_rewrite rules in %s.htaccess enclosed by <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code> and let the plugin regenerate them by reloading this page.', 'wp-super-cache' ), $home_path ); ?></li>
       
   324 			<li> <?php printf( __( 'Add the rules yourself. Edit %s.htaccess and find the block of code enclosed by the lines <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code>. There are two sections that look very similar. Just below the line <code>%%{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$</code> add these lines: (do it twice, once for each section)', 'wp-super-cache' ), $home_path ); ?></p>
       
   325 			<div style='padding: 2px; margin: 2px; border: 1px solid #333; width:400px; overflow: scroll'><pre><?php echo "RewriteCond %{HTTP_user_agent} !^.*(" . addcslashes( implode( '|', $wp_cache_mobile_browsers ), ' ' ) . ").*\nRewriteCond %{HTTP_user_agent} !^(" . addcslashes( implode( '|', $wp_cache_mobile_prefixes ), ' ' ) . ").*"; ?></pre></div></li></ol></div><?php 
       
   326 	}
       
   327 
       
   328 	if ( $cache_enabled && $super_cache_enabled && $wp_cache_mod_rewrite && $scrules == '' ) {
       
   329 		?><div id="message" class="updated fade"><h3><?php _e( 'Rewrite rules must be updated', 'wp-super-cache' ); ?></h3>
       
   330 		<p><?php _e( 'The rewrite rules required by this plugin have changed or are missing. ', 'wp-super-cache' ); ?>
       
   331 		<?php _e( 'Scroll down the Advanced Settings page and click the <strong>Update Mod_Rewrite Rules</strong> button.', 'wp-super-cache' ); ?></p></div><?php
       
   332 	}
       
   333 	}
       
   334 
       
   335 	if ( $wp_cache_mod_rewrite && $super_cache_enabled && function_exists( 'apache_get_modules' ) ) {
       
   336 		$mods = apache_get_modules();
       
   337 		$required_modules = array( 'mod_mime' => __( 'Required to serve compressed supercache files properly.', 'wp-super-cache' ), 'mod_headers' => __( 'Required to set caching information on supercache pages. IE7 users will see old pages without this module.', 'wp-super-cache' ), 'mod_expires' => __( 'Set the expiry date on supercached pages. Visitors may not see new pages when they refresh or leave comments without this module.', 'wp-super-cache' ) );
       
   338 		foreach( $required_modules as $req => $desc ) {
       
   339 			if( !in_array( $req, $mods ) ) {
       
   340 				$missing_mods[ $req ] = $desc;
       
   341 			}
       
   342 		}
       
   343 		if( isset( $missing_mods) && is_array( $missing_mods ) ) {
       
   344 			?><div id="message" class="updated fade"><h3><?php _e( 'Missing Apache Modules', 'wp-super-cache' ); ?></h3>
       
   345 			<p><?php __( 'The following Apache modules are missing. The plugin will work in legacy mode without them. In full Supercache mode, your visitors may see corrupted pages or out of date content however.', 'wp-super-cache' ); ?></p><?php
       
   346 			echo "<ul>";
       
   347 			foreach( $missing_mods as $req => $desc ) {
       
   348 				echo "<li> $req - $desc</li>";
       
   349 			}
       
   350 			echo "</ul>";
       
   351 			echo "</div>";
       
   352 		}
       
   353 	}
       
   354 
       
   355 	if ( $valid_nonce && $_POST[ 'action' ] == 'dismiss_htaccess_warning' ) {
       
   356 		wp_cache_replace_line('^ *\$dismiss_htaccess_warning', "\$dismiss_htaccess_warning = 1;", $wp_cache_config_file);
       
   357 		$dismiss_htaccess_warning = 1;
       
   358 	} elseif ( !isset( $dismiss_htaccess_warning ) ) {
       
   359 		$dismiss_htaccess_warning = 0;
       
   360 	}
       
   361 	if ( $dismiss_htaccess_warning == 0 && $wp_cache_mod_rewrite && $super_cache_enabled && $disable_supercache_htaccess_warning == false && get_option( 'siteurl' ) != get_option( 'home' ) ) {
       
   362 		$home_dir = str_replace( get_option( 'home' ), '', get_option( 'siteurl' ) );
       
   363 		?><div id="message" class="updated fade"><h3><?php _e( '.htaccess file may need to be moved', 'wp-super-cache' ); ?></h3>
       
   364 		<p><?php _e( 'It appears you have WordPress installed in a sub directory as described <a href="http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory">here</a>. Unfortunately WordPress writes to the .htaccess in the install directory, not where your site is served from.<br />When you update the rewrite rules in this plugin you will have to copy the file to where your site is hosted. This will be fixed in the future.', 'wp-super-cache' ); ?></p>
       
   365 		<form action="" method="POST">
       
   366 		<input type="hidden" name="action" value="dismiss_htaccess_warning" />
       
   367 		<input type="hidden" name="page" value="wpsupercache" />
       
   368 		<?php wp_nonce_field( 'wp-cache' ); ?>
       
   369 		<input type='submit' value='<?php _e( 'Dismiss', 'wp-super-cache' ); ?>' />
       
   370 		</form>
       
   371 		<br />	
       
   372 		</div><?php
       
   373 	}
       
   374 
       
   375 	return true;
       
   376 
       
   377 }
       
   378 add_filter( 'wp_super_cache_error_checking', 'wp_cache_manager_error_checks' );
       
   379 
       
   380 function admin_bar_delete_page() {
       
   381 	// Delete cache for a specific page
       
   382 	if ( function_exists('current_user_can') && false == current_user_can('delete_others_posts') )
       
   383 		return false;
       
   384 	if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'delcachepage' && ( isset( $_GET[ '_wpnonce' ] ) ? wp_verify_nonce( $_REQUEST[ '_wpnonce' ], 'delete-cache' ) : false ) ) {
       
   385 		$path = get_supercache_dir() . preg_replace( '/:.*$/', '', $_GET[ 'path' ] );
       
   386 		$files = get_all_supercache_filenames( $path );
       
   387 		foreach( $files as $cache_file )
       
   388 			prune_super_cache( $path . $cache_file, true ); 
       
   389 
       
   390 		wp_redirect( preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_GET[ 'path' ] ) );
       
   391 		die();
       
   392 	}
       
   393 }
       
   394 if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'delcachepage' )
       
   395    add_action( 'admin_init', 'admin_bar_delete_page' );
       
   396 
       
   397 function wp_cache_manager_updates() {
       
   398 	global $wp_cache_mobile_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_hello_world, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $cache_path, $wp_cache_object_cache, $_wp_using_ext_object_cache, $wp_cache_refresh_single_only, $cache_compression, $wp_cache_mod_rewrite, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get;
       
   399 	global $cache_schedule_type, $cache_scheduled_time, $cache_max_time, $cache_time_interval, $wp_cache_shutdown_gc;
       
   400 
       
   401 	if ( !wpsupercache_site_admin() )
       
   402 		return false;
       
   403 
       
   404 	if ( false == isset( $cache_page_secret ) ) {
       
   405 		$cache_page_secret = md5( date( 'H:i:s' ) . mt_rand() );
       
   406 		wp_cache_replace_line('^ *\$cache_page_secret', "\$cache_page_secret = '" . $cache_page_secret . "';", $wp_cache_config_file);
       
   407 	}
       
   408 
       
   409 	$valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
       
   410 	if ( $valid_nonce == false )
       
   411 		return false;
       
   412 
       
   413 	if ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'easysetup' ) {
       
   414 		$_POST[ 'action' ] = 'scupdates';
       
   415 		if( isset( $_POST[ 'wp_cache_easy_on' ] ) && $_POST[ 'wp_cache_easy_on' ] == 1 ) {
       
   416 			$_POST[ 'wp_cache_mobile_enabled' ] = 1;
       
   417 			$_POST[ 'wp_cache_status' ] = 'all';
       
   418 			$_POST[ 'super_cache_enabled' ] = 2; // PHP
       
   419 			$_POST[ 'cache_rebuild_files' ] = 1;
       
   420 			unset( $_POST[ 'cache_compression' ] );
       
   421 			//
       
   422 			// set up garbage collection with some default settings
       
   423 			if ( ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) {
       
   424 				if ( false == isset( $cache_schedule_type ) ) {
       
   425 					$cache_schedule_type = 'interval';
       
   426 					$cache_time_interval = 600;
       
   427 					$cache_max_time = 1800;
       
   428 					wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
       
   429 					wp_cache_replace_line('^ *\$cache_time_interval', "\$cache_time_interval = '$cache_time_interval';", $wp_cache_config_file);
       
   430 					wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = '$cache_max_time';", $wp_cache_config_file);
       
   431 				}
       
   432 				wp_schedule_single_event( time() + 600, 'wp_cache_gc' );
       
   433 			}
       
   434 
       
   435 		} else {
       
   436 			unset( $_POST[ 'wp_cache_status' ] );
       
   437 			$_POST[ 'super_cache_enabled' ] = 0;
       
   438 			wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
       
   439 			wp_clear_scheduled_hook( 'wp_cache_gc' );
       
   440 			wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
       
   441 		}
       
   442 	}
       
   443 
       
   444 	if( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'scupdates' ) {
       
   445 
       
   446 		if( isset( $_POST[ 'wp_super_cache_late_init' ] ) ) {
       
   447 			$wp_super_cache_late_init = 1;
       
   448 		} else {
       
   449 			$wp_super_cache_late_init = 0;
       
   450 		}
       
   451 		wp_cache_replace_line('^ *\$wp_super_cache_late_init', "\$wp_super_cache_late_init = " . $wp_super_cache_late_init . ";", $wp_cache_config_file);
       
   452 
       
   453 		if( isset( $_POST[ 'wp_cache_disable_utf8' ] ) ) {
       
   454 			$wp_cache_disable_utf8 = 1;
       
   455 		} else {
       
   456 			$wp_cache_disable_utf8 = 0;
       
   457 		}
       
   458 		wp_cache_replace_line('^ *\$wp_cache_disable_utf8', "\$wp_cache_disable_utf8 = " . $wp_cache_disable_utf8 . ";", $wp_cache_config_file);
       
   459 
       
   460 		if( isset( $_POST[ 'wp_cache_no_cache_for_get' ] ) ) {
       
   461 			$wp_cache_no_cache_for_get = 1;
       
   462 		} else {
       
   463 			$wp_cache_no_cache_for_get = 0;
       
   464 		}
       
   465 		wp_cache_replace_line('^ *\$wp_cache_no_cache_for_get', "\$wp_cache_no_cache_for_get = " . $wp_cache_no_cache_for_get . ";", $wp_cache_config_file);
       
   466 
       
   467 		if( isset( $_POST[ 'wp_supercache_304' ] ) ) {
       
   468 			$wp_supercache_304 = 1;
       
   469 		} else {
       
   470 			$wp_supercache_304 = 0;
       
   471 		}
       
   472 		wp_cache_replace_line('^ *\$wp_supercache_304', "\$wp_supercache_304 = " . $wp_supercache_304 . ";", $wp_cache_config_file);
       
   473 
       
   474 		if( isset( $_POST[ 'wp_cache_mobile_enabled' ] ) ) {
       
   475 			$wp_cache_mobile_enabled = 1;
       
   476 		} else {
       
   477 			$wp_cache_mobile_enabled = 0;
       
   478 		}
       
   479 		wp_cache_replace_line('^ *\$wp_cache_mobile_enabled', "\$wp_cache_mobile_enabled = " . $wp_cache_mobile_enabled . ";", $wp_cache_config_file);
       
   480 
       
   481 		if( isset( $_POST[ 'wp_cache_front_page_checks' ] ) ) {
       
   482 			$wp_cache_front_page_checks = 1;
       
   483 		} else {
       
   484 			$wp_cache_front_page_checks = 0;
       
   485 		}
       
   486 		wp_cache_replace_line('^ *\$wp_cache_front_page_checks', "\$wp_cache_front_page_checks = " . $wp_cache_front_page_checks . ";", $wp_cache_config_file);
       
   487 
       
   488 		if( isset( $_POST[ 'wp_supercache_cache_list' ] ) ) {
       
   489 			$wp_supercache_cache_list = 1;
       
   490 		} else {
       
   491 			$wp_supercache_cache_list = 0;
       
   492 		}
       
   493 		wp_cache_replace_line('^ *\$wp_supercache_cache_list', "\$wp_supercache_cache_list = " . $wp_supercache_cache_list . ";", $wp_cache_config_file);
       
   494 
       
   495 		if ( isset( $_POST[ 'wp_cache_status' ] ) ) {
       
   496 			if ( $_POST[ 'wp_cache_status' ] == 'all' )
       
   497 					wp_cache_enable();
       
   498 
       
   499 			if ( isset( $_POST[ 'super_cache_enabled' ] ) ) {
       
   500 				if ( $_POST[ 'super_cache_enabled' ] == 0 ) {
       
   501 					wp_cache_enable();
       
   502 					wp_super_cache_disable();
       
   503 				}
       
   504 				if( $_POST[ 'super_cache_enabled' ] == 1 ) {
       
   505 					$wp_cache_mod_rewrite = 1; // we need this because supercached files can be served by PHP too.
       
   506 				} else {
       
   507 					$wp_cache_mod_rewrite = 0;
       
   508 				}
       
   509 				wp_cache_replace_line('^ *\$wp_cache_mod_rewrite', '$wp_cache_mod_rewrite = ' . $wp_cache_mod_rewrite . ";", $wp_cache_config_file);
       
   510 			}
       
   511 		} else {
       
   512 			wp_cache_disable();
       
   513 		}
       
   514 
       
   515 		if( isset( $_POST[ 'wp_cache_hello_world' ] ) ) {
       
   516 			$wp_cache_hello_world = 1;
       
   517 		} else {
       
   518 			$wp_cache_hello_world = 0;
       
   519 		}
       
   520 		wp_cache_replace_line('^ *\$wp_cache_hello_world', '$wp_cache_hello_world = ' . $wp_cache_hello_world . ";", $wp_cache_config_file);
       
   521 
       
   522 		if( isset( $_POST[ 'wp_cache_clear_on_post_edit' ] ) ) {
       
   523 			$wp_cache_clear_on_post_edit = 1;
       
   524 		} else {
       
   525 			$wp_cache_clear_on_post_edit = 0;
       
   526 		}
       
   527 		wp_cache_replace_line('^ *\$wp_cache_clear_on_post_edit', "\$wp_cache_clear_on_post_edit = " . $wp_cache_clear_on_post_edit . ";", $wp_cache_config_file);
       
   528 
       
   529 		if( isset( $_POST[ 'cache_rebuild_files' ] ) ) {
       
   530 			$cache_rebuild_files = 1;
       
   531 		} else {
       
   532 			$cache_rebuild_files = 0;
       
   533 		}
       
   534 		wp_cache_replace_line('^ *\$cache_rebuild_files', "\$cache_rebuild_files = " . $cache_rebuild_files . ";", $wp_cache_config_file);
       
   535 
       
   536 		if( isset( $_POST[ 'wp_cache_mutex_disabled' ] ) ) {
       
   537 			$wp_cache_mutex_disabled = 0;
       
   538 		} else {
       
   539 			$wp_cache_mutex_disabled = 1;
       
   540 		}
       
   541 		if( defined( 'WPSC_DISABLE_LOCKING' ) ) {
       
   542 			$wp_cache_mutex_disabled = 1;
       
   543 		}
       
   544 		wp_cache_replace_line('^ *\$wp_cache_mutex_disabled', "\$wp_cache_mutex_disabled = " . $wp_cache_mutex_disabled . ";", $wp_cache_config_file);
       
   545 
       
   546 		if( isset( $_POST[ 'wp_cache_not_logged_in' ] ) ) {
       
   547 			if( $wp_cache_not_logged_in == 0 && function_exists( 'prune_super_cache' ) )
       
   548 				prune_super_cache ($cache_path, true);
       
   549 			$wp_cache_not_logged_in = 1;
       
   550 		} else {
       
   551 			$wp_cache_not_logged_in = 0;
       
   552 		}
       
   553 		wp_cache_replace_line('^ *\$wp_cache_not_logged_in', "\$wp_cache_not_logged_in = " . $wp_cache_not_logged_in . ";", $wp_cache_config_file);
       
   554 
       
   555 		if( isset( $_POST[ 'wp_cache_make_known_anon' ] ) ) {
       
   556 			if( $wp_cache_make_known_anon == 0 && function_exists( 'prune_super_cache' ) )
       
   557 				prune_super_cache ($cache_path, true);
       
   558 			$wp_cache_make_known_anon = 1;
       
   559 		} else {
       
   560 			$wp_cache_make_known_anon = 0;
       
   561 		}
       
   562 		wp_cache_replace_line('^ *\$wp_cache_make_known_anon', "\$wp_cache_make_known_anon = " . $wp_cache_make_known_anon . ";", $wp_cache_config_file);
       
   563 
       
   564 		if( $_wp_using_ext_object_cache && isset( $_POST[ 'wp_cache_object_cache' ] ) ) {
       
   565 			if( $wp_cache_object_cache == 0 && function_exists( 'prune_super_cache' ) )
       
   566 				prune_super_cache( $cache_path, true );
       
   567 			$wp_cache_object_cache = 1;
       
   568 		} else {
       
   569 			$wp_cache_object_cache = 0;
       
   570 		}
       
   571 		wp_cache_replace_line('^ *\$wp_cache_object_cache', "\$wp_cache_object_cache = " . $wp_cache_object_cache . ";", $wp_cache_config_file);
       
   572 
       
   573 		if( isset( $_POST[ 'wp_cache_refresh_single_only' ] ) ) {
       
   574 			$wp_cache_refresh_single_only = 1;
       
   575 		} else {
       
   576 			$wp_cache_refresh_single_only = 0;
       
   577 		}
       
   578 		wp_cache_replace_line('^ *\$wp_cache_refresh_single_only', "\$wp_cache_refresh_single_only = '" . $wp_cache_refresh_single_only . "';", $wp_cache_config_file);
       
   579 	
       
   580 		if ( defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
       
   581 			$cache_compression = 0;
       
   582 			wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
       
   583 		} else {
       
   584 			if ( isset( $_POST[ 'cache_compression' ] ) ) {
       
   585 				$new_cache_compression = 1;
       
   586 			} else {
       
   587 				$new_cache_compression = 0;
       
   588 			}
       
   589 			if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) { 
       
   590 				echo '<div id="message" class="updated fade">' . __( "<strong>Warning!</strong> You attempted to enable compression but <code>zlib.output_compression</code> is enabled. See #21 in the Troubleshooting section of the readme file.", 'wp-super-cache' ) . '</div>';
       
   591 			} else {
       
   592 				if ( $new_cache_compression != $cache_compression ) {
       
   593 					$cache_compression = $new_cache_compression;
       
   594 					wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
       
   595 					if ( function_exists( 'prune_super_cache' ) )
       
   596 						prune_super_cache( $cache_path, true );
       
   597 					delete_option( 'super_cache_meta' );
       
   598 				}
       
   599 			}
       
   600 		}
       
   601 	}
       
   602 }
       
   603 if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'wpsupercache' )
       
   604 	add_action( 'admin_init', 'wp_cache_manager_updates' );
   124 
   605 
   125 function wp_cache_manager() {
   606 function wp_cache_manager() {
   126 	global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled, $wp_cache_hello_world;
   607 	global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled, $wp_cache_hello_world;
   127 	global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_mobile_enabled, $wp_cache_mobile_whitelist, $wp_cache_mobile_browsers;
   608 	global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_no_cache_for_get;
   128 	global $wp_cache_cron_check, $wp_cache_debug, $wp_cache_hide_donation, $wp_cache_not_logged_in, $wp_supercache_cache_list;
   609 	global $wp_cache_cron_check, $wp_cache_debug, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_supercache_cache_list, $cache_page_secret, $cache_home_path;
   129 	global $wp_super_cache_front_page_check;
   610 	global $wp_super_cache_front_page_check, $wp_cache_object_cache, $_wp_using_ext_object_cache, $wp_cache_refresh_single_only, $wp_cache_mobile_prefixes;
   130 
   611 	global $wpmu_version, $cache_max_time, $wp_cache_mod_rewrite, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $wp_cache_disable_utf8;
   131 	if( function_exists( 'is_site_admin' ) )
   612 
   132 		if( !is_site_admin() )
   613 	if ( !wpsupercache_site_admin() )
   133 			return;
   614 		return false;
   134 
   615 
   135 	$supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '',  $_SERVER["HTTP_HOST"]);
   616 	// used by mod_rewrite rules and config file
       
   617 	if ( function_exists( "cfmobi_default_browsers" ) ) {
       
   618 		$wp_cache_mobile_browsers = cfmobi_default_browsers( "mobile" );
       
   619 		$wp_cache_mobile_browsers = array_merge( $wp_cache_mobile_browsers, cfmobi_default_browsers( "touch" ) );
       
   620 	} elseif ( function_exists( 'lite_detection_ua_contains' ) ) {
       
   621 		$wp_cache_mobile_browsers = explode( '|', lite_detection_ua_contains() );
       
   622 	} else {
       
   623 		$wp_cache_mobile_browsers = array( '2.0 MMP', '240x320', '400X240', 'AvantGo', 'BlackBerry', 'Blazer', 'Cellphone', 'Danger', 'DoCoMo', 'Elaine/3.0', 'EudoraWeb', 'Googlebot-Mobile', 'hiptop', 'IEMobile', 'KYOCERA/WX310K', 'LG/U990', 'MIDP-2.', 'MMEF20', 'MOT-V', 'NetFront', 'Newt', 'Nintendo Wii', 'Nitro', 'Nokia', 'Opera Mini', 'Palm', 'PlayStation Portable', 'portalmmm', 'Proxinet', 'ProxiNet', 'SHARP-TQ-GX10', 'SHG-i900', 'Small', 'SonyEricsson', 'Symbian OS', 'SymbianOS', 'TS21i-10', 'UP.Browser', 'UP.Link', 'webOS', 'Windows CE', 'WinWAP', 'YahooSeeker/M1A1-R2D2', 'iPhone', 'iPod', 'Android', 'BlackBerry9530', 'LG-TU915 Obigo', 'LGE VX', 'webOS', 'Nokia5800' );
       
   624 	}
       
   625 	if ( function_exists( "lite_detection_ua_prefixes" ) ) {
       
   626 		$wp_cache_mobile_prefixes = lite_detection_ua_prefixes();
       
   627 	} else {
       
   628 		$wp_cache_mobile_prefixes = array( 'w3c ', 'w3c-', 'acs-', 'alav', 'alca', 'amoi', 'audi', 'avan', 'benq', 'bird', 'blac', 'blaz', 'brew', 'cell', 'cldc', 'cmd-', 'dang', 'doco', 'eric', 'hipt', 'htc_', 'inno', 'ipaq', 'ipod', 'jigs', 'kddi', 'keji', 'leno', 'lg-c', 'lg-d', 'lg-g', 'lge-', 'lg/u', 'maui', 'maxo', 'midp', 'mits', 'mmef', 'mobi', 'mot-', 'moto', 'mwbp', 'nec-', 'newt', 'noki', 'palm', 'pana', 'pant', 'phil', 'play', 'port', 'prox', 'qwap', 'sage', 'sams', 'sany', 'sch-', 'sec-', 'send', 'seri', 'sgh-', 'shar', 'sie-', 'siem', 'smal', 'smar', 'sony', 'sph-', 'symb', 't-mo', 'teli', 'tim-', 'tosh', 'tsm-', 'upg1', 'upsi', 'vk-v', 'voda', 'wap-', 'wapa', 'wapi', 'wapp', 'wapr', 'webc', 'winw', 'winw', 'xda ', 'xda-' ); // from http://svn.wp-plugins.org/wordpress-mobile-pack/trunk/plugins/wpmp_switcher/lite_detection.php
       
   629 	}
       
   630 	$wp_cache_mobile_browsers = apply_filters( 'cached_mobile_browsers', $wp_cache_mobile_browsers ); // Allow mobile plugins access to modify the mobile UA list
       
   631 	$wp_cache_mobile_prefixes = apply_filters( 'cached_mobile_prefixes', $wp_cache_mobile_prefixes ); // Allow mobile plugins access to modify the mobile UA prefix list
       
   632 	if ( function_exists( 'do_cacheaction' ) ) {
       
   633 		$wp_cache_mobile_browsers = do_cacheaction( 'wp_super_cache_mobile_browsers', $wp_cache_mobile_browsers );
       
   634 		$wp_cache_mobile_prefixes = do_cacheaction( 'wp_super_cache_mobile_prefixes', $wp_cache_mobile_prefixes ); 
       
   635 	}
       
   636 	$mobile_groups = apply_filters( 'cached_mobile_groups', array() ); // Group mobile user agents by capabilities. Lump them all together by default
       
   637 	// mobile_groups = array( 'apple' => array( 'ipod', 'iphone' ), 'nokia' => array( 'nokia5800', 'symbianos' ) );
       
   638 
       
   639 	if ( false == apply_filters( 'wp_super_cache_error_checking', true ) )
       
   640 		return false;
       
   641 
       
   642 	if ( function_exists( 'get_supercache_dir' ) )
       
   643 		$supercachedir = get_supercache_dir();
   136 	if( get_option( 'gzipcompression' ) == 1 )
   644 	if( get_option( 'gzipcompression' ) == 1 )
   137 		update_option( 'gzipcompression', 0 );
   645 		update_option( 'gzipcompression', 0 );
   138 	if( !isset( $cache_rebuild_files ) )
   646 	if( !isset( $cache_rebuild_files ) )
   139 		$cache_rebuild_files = 0;
   647 		$cache_rebuild_files = 0;
   140 
   648 
   163 	jQuery("fieldset h3").css("cursor","pointer").click(function(){
   671 	jQuery("fieldset h3").css("cursor","pointer").click(function(){
   164 		jQuery(this).parent("fieldset").find("p,form,ul,blockquote").toggle("slow");
   672 		jQuery(this).parent("fieldset").find("p,form,ul,blockquote").toggle("slow");
   165 	});
   673 	});
   166 });
   674 });
   167 </script>
   675 </script>
       
   676 
       
   677 <style type='text/css'>
       
   678 #nav h2 {
       
   679 	border-bottom: 1px solid #ccc;
       
   680 	padding-bottom: 0;
       
   681 }
       
   682 </style>
   168 <?php
   683 <?php
       
   684 	echo '<a name="top"></a>';
   169 	echo '<div class="wrap">';
   685 	echo '<div class="wrap">';
   170 	echo "<h2><a href='?page=wpsupercache'>" . __( 'WP Super Cache Manager', 'wp-super-cache' ) . "</a></h2>\n";
   686 	echo '<h2>' . __( 'WP Super Cache Settings', 'wp-super-cache' ) . '</h2>';
   171 	if( 1 == ini_get( 'safe_mode' ) || "on" == strtolower( ini_get( 'safe_mode' ) ) ) {
   687 
   172 		?><h3><?php _e( 'Warning! PHP Safe Mode Enabled!', 'wp-super-cache' ); ?></h3>
   688 	// set a default
   173 		<p><?php _e( 'You may experience problems running this plugin because SAFE MODE is enabled.', 'wp-super-cache' );
   689 	if ( $cache_enabled == false && isset( $wp_cache_mod_rewrite ) == false ) {
   174 		if( !ini_get( 'safe_mode_gid' ) ) {
   690 		$wp_cache_mod_rewrite = 0;
   175 			echo __( 'Your server is set up to check the owner of PHP scripts before allowing them to read and write files.', 'wp-super-cache' ) . "</p><p>";
   691 	} elseif ( !isset( $wp_cache_mod_rewrite ) && $cache_enabled && $super_cache_enabled ) {
   176 			echo sprintf( __( 'You or an administrator may be able to make it work by changing the group owner of the plugin scripts to match that of the web server user. The group owner of the %s/cache/ directory must also be changed. See the <a href="http://php.net/features.safe-mode">safe mode manual page</a> for further details.', 'wp-super-cache' ), WP_CONTENT_DIR ) . "</p>";
   692 		$wp_cache_mod_rewrite = 1;
   177 		} else {
   693 	}
   178 			echo __( 'You or an administrator must disable this. See the <a href="http://php.net/features.safe-mode">safe mode manual page</a> for further details. This cannot be disabled in a .htaccess file unfortunately. It must be done in the php.ini config file.', 'wp-super-cache' ) . "</p>";
   694 
   179 		}
   695 	if ( !isset( $_GET[ 'tab' ] ) )
   180 	}
   696 		$_GET[ 'tab' ] = '';
       
   697 
       
   698 	if ( $_GET[ 'tab' ] == '' && $cache_enabled && ( $wp_cache_mod_rewrite || $super_cache_enabled == false ) ) {
       
   699 		$_GET[ 'tab' ] = 'settings';
       
   700 		echo '<div id="message" class="updated fade"><p>' .  __( 'Notice: <em>Mod_rewrite or Legacy caching enabled</em>. Showing Advanced Settings Page by default.', 'wp-super-cache' ) . '</p></div>';
       
   701 	}
       
   702 	wpsc_admin_tabs();
   181 
   703 
   182 	if ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 1 && !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
   704 	if ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 1 && !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
   183 		wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
   705 		wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
   184 		if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'scheduled wp_cache_check_site_hook for 360 seconds time.', 2 );
   706 		if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'scheduled wp_cache_check_site_hook for 360 seconds time.', 2 );
   185 	}
   707 	}
   187 	if(isset($_REQUEST['wp_restore_config']) && $valid_nonce) {
   709 	if(isset($_REQUEST['wp_restore_config']) && $valid_nonce) {
   188 		unlink($wp_cache_config_file);
   710 		unlink($wp_cache_config_file);
   189 		echo '<strong>' . __( 'Configuration file changed, some values might be wrong. Load the page again from the "Settings" menu to reset them.', 'wp-super-cache' ) . '</strong>';
   711 		echo '<strong>' . __( 'Configuration file changed, some values might be wrong. Load the page again from the "Settings" menu to reset them.', 'wp-super-cache' ) . '</strong>';
   190 	}
   712 	}
   191 
   713 
   192 	if ( !wp_cache_check_link() ||
   714 	if ( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
   193 		!wp_cache_verify_config_file() ||
   715 		wp_cache_replace_line('^ *\$wp_cache_slash_check', "\$wp_cache_slash_check = 1;", $wp_cache_config_file);
   194 		!wp_cache_verify_cache_dir() ) {
   716 	} else {
   195 		echo '<p>' . __( "Cannot continue... fix previous problems and retry.", 'wp-super-cache' ) . '</p>';
   717 		wp_cache_replace_line('^ *\$wp_cache_slash_check', "\$wp_cache_slash_check = 0;", $wp_cache_config_file);
   196 		echo "</div>\n";
   718 	}
   197 		return;
   719 	$home_path = parse_url( site_url() );
   198 	}
   720 	$home_path = trailingslashit( array_key_exists( 'path', $home_path ) ? $home_path[ 'path' ] : '' );
   199 
   721 	if (! isset( $wp_cache_home_path ) )
   200 	if (!wp_cache_check_global_config()) {
   722 		$wp_cache_home_path = '/'; 
   201 		echo "</div>\n";
   723 	if ( "$home_path" != "$wp_cache_home_path" )
   202 		return;
   724 		wp_cache_replace_line('^ *\$wp_cache_home_path', "\$wp_cache_home_path = '$home_path';", $wp_cache_config_file);
   203 	}
   725 	
   204 	if( $wp_cache_debug || !$wp_cache_cron_check ) {
   726 
   205 	if( function_exists( "wp_remote_get" ) == false ) {
   727 	if( $wp_cache_mobile_enabled == 1 ) {
   206 		$hostname = str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'siteurl' ) ) );
   728 		update_cached_mobile_ua_list( $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $mobile_groups );
   207 		if( strpos( $hostname, '/' ) )
   729 	}
   208 			$hostname = substr( $hostname, 0, strpos( $hostname, '/' ) );
   730 
   209 		$ip = gethostbyname( $hostname );
   731 	?> <table><td valign='top'><?php
   210 		if( substr( $ip, 0, 3 ) == '127' || substr( $ip, 0, 7 ) == '192.168' ) {
   732 	switch( $_GET[ 'tab' ] ) {
   211 			?><h3><?php printf( __( 'Warning! Your hostname "%s" resolves to %s', 'wp-super-cache' ), $hostname, $ip ); ?></h3>
   733 		case "cdn":
   212 			<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'>
   734 		scossdl_off_options();
   213 			<p><?php printf( __( 'Your server thinks your hostname resolves to %s. Some services such as garbage collection by this plugin, and WordPress scheduled posts may not operate correctly.', 'wp-super-cache' ), $ip ); ?></p>
   735 		break;
   214 			<p><?php printf( __( 'Please see entry 16 in the <a href="%s">Troubleshooting section</a> of the readme.txt', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/wp-super-cache/faq/' ); ?></p>
   736 		case "tester":
   215 			</div>
   737 		case "contents":
       
   738 		echo '<a name="test"></a>';
       
   739 		wp_cache_files();
       
   740 		break;
       
   741 		case "preload":
       
   742 		if ( !$cache_enabled )
       
   743 			wp_die( __( 'Caching must be enabled to use this feature', 'wp-super-cache' ) );
       
   744 		echo '<a name="preload"></a>';
       
   745 		if ( $super_cache_enabled == true && false == defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
       
   746 			global $wp_cache_preload_interval, $wp_cache_preload_on, $wp_cache_preload_taxonomies, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $wp_cache_preload_posts, $wpdb;
       
   747 			$count = $wpdb->get_var( "SELECT count(*) FROM {$wpdb->posts} WHERE post_status = 'publish'" );
       
   748 			if ( $count > 1000 ) {
       
   749 				$min_refresh_interval = 720;
       
   750 			} else {
       
   751 				$min_refresh_interval = 30;
       
   752 			}
       
   753 			if ( array_key_exists('action', $_POST) && $_POST[ 'action' ] == 'preload' && $valid_nonce ) {
       
   754 				if ( $_POST[ 'posts_to_cache' ] == 'all' ) {
       
   755 					$wp_cache_preload_posts = 'all';
       
   756 				} else {
       
   757 					$wp_cache_preload_posts = (int)$_POST[ 'posts_to_cache' ];
       
   758 				}
       
   759 				wp_cache_replace_line('^ *\$wp_cache_preload_posts', "\$wp_cache_preload_posts = '$wp_cache_preload_posts';", $wp_cache_config_file);
       
   760 
       
   761 				if ( isset( $_POST[ 'preload' ] ) && $_POST[ 'preload' ] == __( 'Cancel Cache Preload', 'wp-super-cache' ) ) {
       
   762 					$next_preload = wp_next_scheduled( 'wp_cache_preload_hook' );
       
   763 					if ( $next_preload ) {
       
   764 						update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
       
   765 						wp_unschedule_event( $next_preload, 'wp_cache_preload_hook' );
       
   766 					}
       
   767 					$fp = @fopen( $cache_path . "stop_preload.txt", 'w' );
       
   768 					@fclose( $fp );
       
   769 					echo "<p><strong>" . __( 'Scheduled preloading of cache almost cancelled. It may take up to a minute for it to cancel completely.', 'wp-super-cache' ) . "</strong></p>";
       
   770 				} elseif ( isset( $_POST[ 'custom_preload_interval' ] ) && ( $_POST[ 'custom_preload_interval' ] == 0 || $_POST[ 'custom_preload_interval' ] >= $min_refresh_interval ) ) {
       
   771 					// if preload interval changes than unschedule any preload jobs and schedule any new one.
       
   772 					$_POST[ 'custom_preload_interval' ] = (int)$_POST[ 'custom_preload_interval' ];
       
   773 					if ( $wp_cache_preload_interval != $_POST[ 'custom_preload_interval' ] ) {
       
   774 						$next_preload = wp_next_scheduled( 'wp_cache_full_preload_hook' );
       
   775 						if ( $next_preload ) {
       
   776 							update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
       
   777 							add_option( 'preload_cache_stop', 1 );
       
   778 							wp_unschedule_event( $next_preload, 'wp_cache_full_preload_hook' );
       
   779 							if ( $wp_cache_preload_interval == 0 ) {
       
   780 								echo "<p><strong>" . __( 'Scheduled preloading of cache cancelled.', 'wp-super-cache' ) . "</strong></p>";
       
   781 							} 
       
   782 						}
       
   783 						if ( $_POST[ 'custom_preload_interval' ] != 0 )
       
   784 							wp_schedule_single_event( time() + ( $_POST[ 'custom_preload_interval' ] * 60 ), 'wp_cache_full_preload_hook' );
       
   785 					}
       
   786 					$wp_cache_preload_interval = (int)$_POST[ 'custom_preload_interval' ];
       
   787 					wp_cache_replace_line('^ *\$wp_cache_preload_interval', "\$wp_cache_preload_interval = $wp_cache_preload_interval;", $wp_cache_config_file);
       
   788 					if ( isset( $_POST[ 'preload_email_me' ] ) ) {
       
   789 						$wp_cache_preload_email_me = 1;
       
   790 					} else {
       
   791 						$wp_cache_preload_email_me = 0;
       
   792 					}
       
   793 					wp_cache_replace_line('^ *\$wp_cache_preload_email_me', "\$wp_cache_preload_email_me = $wp_cache_preload_email_me;", $wp_cache_config_file);
       
   794 					if ( isset( $_POST[ 'wp_cache_preload_email_volume' ] ) && in_array( $_POST[ 'wp_cache_preload_email_volume' ], array( 'less', 'medium', 'many' ) ) ) {
       
   795 						$wp_cache_preload_email_volume = $_POST[ 'wp_cache_preload_email_volume' ];
       
   796 					} else {
       
   797 						$wp_cache_preload_email_volume = 'medium';
       
   798 					}
       
   799 					wp_cache_replace_line('^ *\$wp_cache_preload_email_volume', "\$wp_cache_preload_email_volume = '$wp_cache_preload_email_volume';", $wp_cache_config_file);
       
   800 					if ( isset( $_POST[ 'preload_taxonomies' ] ) ) {
       
   801 						$wp_cache_preload_taxonomies = 1;
       
   802 					} else {
       
   803 						$wp_cache_preload_taxonomies = 0;
       
   804 					}
       
   805 					wp_cache_replace_line('^ *\$wp_cache_preload_taxonomies', "\$wp_cache_preload_taxonomies = $wp_cache_preload_taxonomies;", $wp_cache_config_file);
       
   806 					if ( isset( $_POST[ 'preload_on' ] ) ) {
       
   807 						$wp_cache_preload_on = 1;
       
   808 					} else {
       
   809 						$wp_cache_preload_on = 0;
       
   810 					}
       
   811 					wp_cache_replace_line('^ *\$wp_cache_preload_on', "\$wp_cache_preload_on = $wp_cache_preload_on;", $wp_cache_config_file);
       
   812 					if ( isset( $_POST[ 'preload' ] ) && $_POST[ 'preload' ] == __( 'Preload Cache Now', 'wp-super-cache' ) ) {
       
   813 						@unlink( $cache_path . "preload_mutex.tmp" );
       
   814 						update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
       
   815 						wp_schedule_single_event( time() + 10, 'wp_cache_preload_hook' );
       
   816 						echo "<p><strong>" . __( 'Scheduled preloading of cache in 10 seconds.' ) . "</strong></p>";
       
   817 					} elseif ( (int)$_POST[ 'custom_preload_interval' ] ) {
       
   818 						@unlink( $cache_path . "preload_mutex.tmp" );
       
   819 						update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
       
   820 						wp_schedule_single_event( time() + ( (int)$_POST[ 'custom_preload_interval' ] * 60 ), 'wp_cache_full_preload_hook' );
       
   821 						echo "<p><strong>" . sprintf( __( 'Scheduled preloading of cache in %d minutes', 'wp-super-cache' ), (int)$_POST[ 'custom_preload_interval' ] ) . "</strong></p>";
       
   822 					}
       
   823 				}
       
   824 			}
       
   825 			echo '<p>' . __( 'This will cache every published post and page on your site. It will create supercache static files so unknown visitors (including bots) will hit a cached page. This will probably help your Google ranking as they are using speed as a metric when judging websites now.', 'wp-super-cache' ) . '</p>';
       
   826 			echo '<p>' . __( 'Preloading creates lots of files however. Caching is done from the newest post to the oldest so please consider only caching the newest if you have lots (10,000+) of posts. This is especially important on shared hosting.', 'wp-super-cache' ) . '</p>';
       
   827 			echo '<p>' . __( 'In &#8217;Preload Mode&#8217; regular garbage collection will only clean out old legacy files for known users, not the preloaded supercache files. This is a recommended setting when the cache is preloaded.', 'wp-super-cache' ) . '</p>';
       
   828 			echo '<form name="cache_filler" action="" method="POST">';
       
   829 			echo '<input type="hidden" name="action" value="preload" />';
       
   830 			echo '<input type="hidden" name="page" value="wpsupercache" />';
       
   831 			echo '<p>' . sprintf( __( 'Refresh preloaded cache files every %s minutes. (0 to disable, minimum %d minutes.)', 'wp-super-cache' ), "<input type='text' size=4 name='custom_preload_interval' value='" . (int)$wp_cache_preload_interval . "' />", $min_refresh_interval ) . '</p>';
       
   832 			if ( $count > 100 ) {
       
   833 				$step = (int)( $count / 10 );
       
   834 
       
   835 				$select = "<select name='posts_to_cache' size=1>";
       
   836 				$select .= "<option value='all' ";
       
   837 				if ( !isset( $wp_cache_preload_posts ) || $wp_cache_preload_posts == 'all' ) {
       
   838 					$checked = 'selectect=1 ';
       
   839 					$best = 'all';
       
   840 				} else {
       
   841 					$checked = ' ';
       
   842 					$best = $wp_cache_preload_posts;
       
   843 				}
       
   844 				$select .= "{$checked}>" . __( 'all', 'wp-super-cache' ) . "</option>";
       
   845 
       
   846 				for( $c = $step; $c < $count; $c += $step ) {
       
   847 					$checked = ' ';
       
   848 					if ( $best == $c )
       
   849 						$checked = 'selected=1 ';
       
   850 					$select .= "<option value='$c'{$checked}>$c</option>";
       
   851 				}
       
   852 				$checked = ' ';
       
   853 				if ( $best == $count )
       
   854 					$checked = 'selected=1 ';
       
   855 				$select .= "<option value='$count'{$checked}>$count</option>";
       
   856 				$select .= "</select>";
       
   857 				echo '<p>' . sprintf( __( 'Preload %s posts.', 'wp-super-cache' ), $select ) . '</p>';
       
   858 			} else {
       
   859 				echo '<input type="hidden" name="posts_to_cache" value="' . $count . '" />';
       
   860 			}
       
   861 
       
   862 			echo '<input type="checkbox" name="preload_on" value="1" ';
       
   863 			echo $wp_cache_preload_on == 1 ? 'checked=1' : '';
       
   864 			echo ' /> ' . __( 'Preload mode (garbage collection only on legacy cache files. Recommended.)', 'wp-super-cache' ) . '<br />';
       
   865 			echo '<input type="checkbox" name="preload_taxonomies" value="1" ';
       
   866 			echo $wp_cache_preload_taxonomies == 1 ? 'checked=1' : '';
       
   867 			echo ' /> ' . __( 'Preload tags, categories and other taxonomies.', 'wp-super-cache' ) . '<br />';
       
   868 			echo '<input type="checkbox" name="preload_email_me" value="1" ';
       
   869 			echo $wp_cache_preload_email_me == 1 ? 'checked=1' : '';
       
   870 			echo ' /> ' . __( 'Send me status emails when files are refreshed.', 'wp-super-cache' ) . '<br />';
       
   871 			if ( !isset( $wp_cache_preload_email_volume ) )
       
   872 				$wp_cache_preload_email_volume = 'many';
       
   873 			echo '&nbsp;&nbsp;&nbsp;&nbsp;<input name="wp_cache_preload_email_volume" type="radio" value="many" class="tog" ';
       
   874 			checked( 'many', $wp_cache_preload_email_volume );
       
   875 			echo '/> ' . __( 'Many emails, 2 emails per 100 posts.', 'wp-super-cache' ) . '<br >';
       
   876 			echo '&nbsp;&nbsp;&nbsp;&nbsp;<input name="wp_cache_preload_email_volume" type="radio" value="medium" class="tog" ';
       
   877 			checked( 'medium', $wp_cache_preload_email_volume );
       
   878 			echo '/> ' . __( 'Medium, 1 email per 100 posts.', 'wp-super-cache' ) . '<br >';
       
   879 			echo '&nbsp;&nbsp;&nbsp;&nbsp;<input name="wp_cache_preload_email_volume" type="radio" value="less" class="tog" ';
       
   880 			checked( 'less', $wp_cache_preload_email_volume );
       
   881 			echo '/> ' . __( 'Less emails, 1 at the start and 1 at the end of preloading all posts.', 'wp-super-cache' ) . '<br >';
       
   882 
       
   883 			$currently_preloading = false;
       
   884 
       
   885 			next_preload_message( 'wp_cache_preload_hook', __( 'Refresh of cache in %d hours %d minutes and %d seconds.', 'wp-super-cache' ), 60 );
       
   886 			next_preload_message( 'wp_cache_full_preload_hook', __( 'Full refresh of cache in %d hours %d minutes and %d seconds.', 'wp-super-cache' ) );
       
   887 
       
   888 			$preload_counter = get_option( 'preload_cache_counter' );
       
   889 			if ( isset( $preload_counter[ 'first' ] ) ) // converted from int to array
       
   890 				update_option( 'preload_cache_counter', array( 'c' => $preload_counter[ 'c' ], 't' => time() ) );
       
   891 			if ( is_array( $preload_counter ) && $preload_counter[ 'c' ] > 0 ) {
       
   892 				echo '<p><strong>' . sprintf( __( 'Currently caching from post %d to %d.', 'wp-super-cache' ), ( $preload_counter[ 'c' ] - 100 ), $preload_counter[ 'c' ] ) . '</strong></p>';
       
   893 				$currently_preloading = true;
       
   894 				if ( @file_exists( $cache_path . "preload_permalink.txt" ) ) {
       
   895 					$url = file_get_contents( $cache_path . "preload_permalink.txt" );
       
   896 					echo "<p>" . sprintf( __( "<strong>Page last cached:</strong> %s", 'wp-super-cache' ), $url ) . "</p>";
       
   897 				}
       
   898 			}
       
   899 			echo '<div class="submit"><input type="submit" name="preload" value="' . __( 'Update Settings', 'wp-super-cache' ) . '" />&nbsp;<input type="submit" name="preload" value="' . __( 'Preload Cache Now', 'wp-super-cache' ) . '" />';
       
   900 			if ( $currently_preloading ) {
       
   901 				echo '&nbsp;<input type="submit" name="preload" value="' . __( 'Cancel Cache Preload', 'wp-super-cache' ) . '" />';
       
   902 			}
       
   903 			echo '</div>';
       
   904 			wp_nonce_field('wp-cache');
       
   905 			echo '</form>';
       
   906 		} else {
       
   907 			echo '<p>' . __( 'Preloading of cache disabled. Please disable legacy page caching or talk to your host administrator.', 'wp-super-cache' ) . '</p>';
       
   908 		}
       
   909 		break;
       
   910 		case 'plugins':
       
   911 		wpsc_plugins_tab();
       
   912 		break;
       
   913 		case 'debug':
       
   914 		wp_cache_debug_settings();
       
   915 		break;
       
   916 		case 'settings':
       
   917 		if ( isset( $wp_cache_front_page_checks ) == false )
       
   918 			$wp_cache_front_page_checks = true;
       
   919 		echo '<form name="wp_manager" action="' . add_query_arg( array( 'page' => 'wpsupercache', 'tab' => 'settings' ) ) . '" method="post">';
       
   920 		wp_nonce_field('wp-cache');
       
   921 		echo '<input type="hidden" name="action" value="scupdates" />';
       
   922 		?><table class="form-table">
       
   923 		<tr valign="top">
       
   924 			<th scope="row"><label for="wp_cache_status"><?php _e( 'Caching', 'wp-super-cache' ); ?></label></th>
       
   925 			<td>
       
   926 				<fieldset>
       
   927 				<legend class="hidden">Caching</legend>
       
   928 				<label><input type='checkbox' name='wp_cache_status' value='all' <?php if ( $cache_enabled == true ) { echo 'checked=checked'; } ?>> <?php _e( 'Cache hits to this website for quick access.', 'wp-super-cache' ); echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?></label><br /><br />
       
   929 				<label><input type='radio' name='super_cache_enabled' <?php if( $super_cache_enabled ) echo "checked"; ?> value='1'> <?php printf( __( 'Use mod_rewrite to serve cache files.', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/wordpress-mobile-edition/' ); echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?></label><br />
       
   930 				<label><input type='radio' name='super_cache_enabled' <?php if( $wp_cache_mod_rewrite == 0 ) echo "checked"; ?> value='2'> <?php printf( __( 'Use PHP to serve cache files.', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/wordpress-mobile-edition/' ); ?></label><br />
       
   931 				<label><input type='radio' name='super_cache_enabled' <?php if( $super_cache_enabled == false ) echo "checked"; ?> value='0'> <?php _e( 'Legacy page caching.', 'wp-super-cache' ); ?></label><br />
       
   932 				<em><?php _e( 'Mod_rewrite is fastest, PHP is almost as fast and easier to get working, while legacy caching is slower again, but more flexible and also easy to get working. New users should use PHP caching.', 'wp-super-cache' ); ?></em><br />
       
   933 				</legend>
       
   934 				</fieldset>
       
   935 			</td>
       
   936 		</tr>
       
   937 		<tr valign="top">
       
   938 			<th scope="row"><label for="wp_cache_status"><?php _e( 'Miscellaneous', 'wp-super-cache' ); ?></label></th>
       
   939 			<td>
       
   940 				<fieldset>
       
   941 				<legend class="hidden">Miscellaneous</legend>
       
   942 				<?php if ( false == defined( 'WPSC_DISABLE_COMPRESSION' ) ) { ?>
       
   943 					<?php if ( false == function_exists( 'gzencode' ) ) { ?>
       
   944 						<em><?php _e( 'Warning! Compression is disabled as gzencode() function not found.', 'wp-super-cache' ); ?></em><br />
       
   945 					<?php } else { ?>
       
   946 						<label><input type='checkbox' name='cache_compression' <?php if( $cache_compression ) echo "checked"; ?> value='1'> <?php _e( 'Compress pages so they&#8217;re served more quickly to visitors.', 'wp-super-cache' ); echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?></label><br />
       
   947 						<em><?php _e( 'Compression is disabled by default because some hosts have problems with compressed files. Switching it on and off clears the cache.', 'wp-super-cache' ); ?></em><br />
       
   948 					<?php }
       
   949 				}
       
   950 				$disable_304 = true;
       
   951 				if ( 0 == $wp_cache_mod_rewrite )
       
   952 					$disable_304 = false;
       
   953 				if ( $disable_304 )
       
   954 					echo "<strike>";
       
   955 				?><label><input <?php if ( $disable_304 ) { echo "disabled"; } ?> type='checkbox' name='wp_supercache_304' <?php if( $wp_supercache_304 ) echo "checked"; ?> value='1'> <?php _e( '304 Not Modified browser caching. Indicate when a page has not been modified since last requested.', 'wp-super-cache' ); echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?></label><br /><?php
       
   956 				if ( $disable_304 ) {
       
   957 					echo "</strike>";
       
   958 					echo "<p><strong>" . __( 'Warning! 304 browser caching is only supported when not using mod_rewrite caching.', 'wp-super-cache' ) . "</strong></p>";
       
   959 				} else {
       
   960 					?><em><?php _e( '304 support is disabled by default because in the past GoDaddy had problems with some of the headers used.', 'wp-super-cache' ); ?></em><br /><?php
       
   961 				}
       
   962 				?><label><input type='checkbox' name='wp_cache_not_logged_in' <?php if( $wp_cache_not_logged_in ) echo "checked"; ?> value='1'> <?php _e( 'Don&#8217;t cache pages for <acronym title="Logged in users and those that comment">known users</acronym>.', 'wp-super-cache' ); echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?></label><br />
       
   963 				<label><input type='checkbox' name='wp_cache_no_cache_for_get' <?php if( $wp_cache_no_cache_for_get ) echo "checked"; ?> value='1'> <?php _e( 'Don&#8217;t cache pages with GET parameters. (?x=y at the end of a url)', 'wp-super-cache' ); ?></label><br />
       
   964 				<label><input type='checkbox' name='wp_cache_make_known_anon' <?php if( $wp_cache_make_known_anon ) echo "checked"; ?> value='1'> <?php _e( 'Make known users anonymous so they&#8217;re served supercached static files.', 'wp-super-cache' ); ?></label><br />
       
   965 				<label><input type='checkbox' name='cache_rebuild_files' <?php if( $cache_rebuild_files ) echo "checked"; ?> value='1'> <?php _e( 'Cache rebuild. Serve a supercache file to anonymous users while a new file is being generated.', 'wp-super-cache' ); echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?></label><br />
       
   966 				<label><input type='checkbox' name='wp_cache_hello_world' <?php if( $wp_cache_hello_world ) echo "checked"; ?> value='1'> <?php printf( __( 'Proudly tell the world your server is <a href="%s">Stephen Fry proof</a>! (places a message in your blog&#8217;s footer)', 'wp-super-cache' ), 'https://twitter.com/#!/HibbsLupusTrust/statuses/136429993059291136' ); ?></label><br />
       
   967 				</legend>
       
   968 				</fieldset>
       
   969 			</td>
       
   970 		</tr>
       
   971 		<tr valign="top">
       
   972 			<th scope="row"><label for="wp_cache_status"><?php _e( 'Advanced', 'wp-super-cache' ); ?></label></th>
       
   973 			<td>
       
   974 				<fieldset>
       
   975 				<legend class="hidden">Advanced</legend>
       
   976 				<label><input type='checkbox' name='wp_cache_mobile_enabled' <?php if( $wp_cache_mobile_enabled ) echo "checked"; ?> value='1'> <?php _e( 'Mobile device support. (External plugin or theme required. See the <a href="http://wordpress.org/extend/plugins/wp-super-cache/faq/">FAQ</a> for further details.)', 'wp-super-cache' ); ?></label><br />
       
   977 				<?php if ( $wp_cache_mobile_enabled ) {
       
   978 					echo '<blockquote><h4>' . __( 'Mobile Browsers', 'wp-super-cache' ) . '</h4>' . implode( ', ', $wp_cache_mobile_browsers ) . "<br /><h4>" . __( 'Mobile Prefixes', 'wp-super-cache' ) . "</h4>" . implode( ', ', $wp_cache_mobile_prefixes ) . "<br /></blockquote>";
       
   979 				} ?>
       
   980 				<label><input type='checkbox' name='wp_cache_disable_utf8' <?php if( $wp_cache_disable_utf8 ) echo "checked"; ?> value='1'> <?php _e( 'Remove UTF8/blog charset support from .htaccess file. Only necessary if you see odd characters or punctuation looks incorrect. Requires rewrite rules update.', 'wp-super-cache' ); ?></label><br />
       
   981 				<label><input type='checkbox' name='wp_cache_clear_on_post_edit' <?php if( $wp_cache_clear_on_post_edit ) echo "checked"; ?> value='1'> <?php _e( 'Clear all cache files when a post or page is published or updated.', 'wp-super-cache' ); ?></label><br />
       
   982 				<label><input type='checkbox' name='wp_cache_front_page_checks' <?php if( $wp_cache_front_page_checks ) echo "checked"; ?> value='1'> <?php _e( 'Extra homepage checks. (Very occasionally stops homepage caching)', 'wp-super-cache' ); ?></label><?php echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?><br />
       
   983 				<label><input type='checkbox' name='wp_cache_refresh_single_only' <?php if( $wp_cache_refresh_single_only ) echo "checked"; ?> value='1'> <?php _e( 'Only refresh current page when comments made.', 'wp-super-cache' ); ?></label><br />
       
   984 				<label><input type='checkbox' name='wp_supercache_cache_list' <?php if( $wp_supercache_cache_list ) echo "checked"; ?> value='1'> <?php _e( 'List the newest cached pages on this page.', 'wp-super-cache' ); ?></label><br />
       
   985 			<?php if( false == defined( 'WPSC_DISABLE_LOCKING' ) ) { ?>
       
   986 				<label><input type='checkbox' name='wp_cache_mutex_disabled' <?php if( !$wp_cache_mutex_disabled ) echo "checked"; ?> value='0'> <?php _e( 'Coarse file locking. You probably don&#8217;t need this but it may help if your server is underpowered. Warning! <em>May cause your server to lock up in very rare cases!</em>', 'wp-super-cache' ); ?></label><br />
       
   987 			<?php } ?>
       
   988 				<label><input type='checkbox' name='wp_super_cache_late_init' <?php if( $wp_super_cache_late_init ) echo "checked"; ?> value='1'> <?php _e( 'Late init. Display cached files after WordPress has loaded. Most useful in legacy mode.', 'wp-super-cache' ); ?></label><br />
       
   989 			<?php if ( $_wp_using_ext_object_cache ) { 
       
   990 				?><label><input type='checkbox' name='wp_cache_object_cache' <?php if( $wp_cache_object_cache ) echo "checked"; ?> value='1'> <?php echo __( 'Use object cache to store cached files.', 'wp-super-cache' ) . ' ' . __( '(Experimental)', 'wp-super-cache' ); ?></label><?php 
       
   991 			}?>
       
   992 			<?php printf( __( '<strong>DO NOT CACHE PAGE</strong> secret key: <a href="%s">%s</a>', 'wp-super-cache' ), trailingslashit( get_bloginfo( 'url' ) ) . "?donotcachepage={$cache_page_secret}", $cache_page_secret ); ?>
       
   993 				</legend>
       
   994 				</fieldset>
       
   995 			</td>
       
   996 		</tr>
       
   997 		</table>
       
   998 		<h3><?php _e( 'Note:', 'wp-super-cache' ); ?></h3>
       
   999 		<ol>
       
  1000 		<li><?php _e( 'Uninstall this plugin on the plugins page. It will automatically clean up after itself. If manual intervention is required then simple instructions are provided.', 'wp-super-cache' ); ?></li>
       
  1001 		<li><?php printf( __( 'If uninstalling this plugin, make sure the directory <em>%s</em> is writeable by the webserver so the files <em>advanced-cache.php</em> and <em>cache-config.php</em> can be deleted automatically. (Making sure those files are writeable too is probably a good idea!)', 'wp-super-cache' ), WP_CONTENT_DIR ); ?></li>
       
  1002 		<li><?php printf( __( 'Please see the <a href="%1$s/wp-super-cache/readme.txt">readme.txt</a> for instructions on uninstalling this script. Look for the heading, "How to uninstall WP Super Cache".', 'wp-super-cache' ), WP_PLUGIN_URL ); ?></li><?php
       
  1003 		echo "<li><em>" . sprintf( __( 'Need help? Check the <a href="%1$s">Super Cache readme file</a>. It includes installation documentation, a FAQ and Troubleshooting tips. The <a href="%2$s">support forum</a> is also available. Your question may already have been answered.', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/wp-super-cache/', 'http://wordpress.org/tags/wp-super-cache?forum_id=10' ) . "</em></li>";
       
  1004 		echo "</ol>";
       
  1005 	
       
  1006 		echo "<div class='submit'><input class='button-primary' type='submit' " . SUBMITDISABLED . " value='" . __( 'Update Status', 'wp-super-cache' ) . " &raquo;' /></div>";
       
  1007 		wp_nonce_field('wp-cache');
       
  1008 		?> </form> <?php
       
  1009 		wsc_mod_rewrite();
       
  1010 
       
  1011 		wp_cache_edit_max_time();
       
  1012 
       
  1013 		echo '<a name="files"></a><fieldset class="options"><h3>' . __( 'Accepted Filenames &amp; Rejected URIs', 'wp-super-cache' ) . '</h3>';
       
  1014 		wp_cache_edit_rejected_pages();
       
  1015 		echo "\n";
       
  1016 		wp_cache_edit_rejected();
       
  1017 		echo "\n";
       
  1018 		wp_cache_edit_accepted();
       
  1019 		echo '</fieldset>';
       
  1020 
       
  1021 		wp_cache_edit_rejected_ua();
       
  1022 
       
  1023 		wp_lock_down();
       
  1024 
       
  1025 		wp_cache_restore();
       
  1026 
       
  1027 		break;
       
  1028 		case "easy":
       
  1029 		default:
       
  1030 			echo '<form name="wp_manager" action="" method="post">';
       
  1031 			echo '<input type="hidden" name="action" value="easysetup" />';
       
  1032 			wp_nonce_field('wp-cache');
       
  1033 			?><table class="form-table">
       
  1034 				<tr valign="top">
       
  1035 				<th scope="row"><label for="wp_cache_status"><?php _e( 'Caching', 'wp-super-cache' ); ?></label></th>
       
  1036 				<td>
       
  1037 				<fieldset>
       
  1038 				<label><input type='radio' name='wp_cache_easy_on' value='1' <?php if ( $cache_enabled == true ) { echo 'checked=checked'; } ?>> <?php _e( 'Caching On', 'wp-super-cache' ); echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?></label><br />
       
  1039 				<label><input type='radio' name='wp_cache_easy_on' value='0' <?php if ( $cache_enabled == false ) { echo 'checked=checked'; } ?>> <?php _e( 'Caching Off', 'wp-super-cache' ); ?></label><br />
       
  1040 				<em><?php _e( 'Note: enables PHP caching, cache rebuild, and mobile support', 'wp-super-cache' ); ?></em><br />
       
  1041 				</legend>
       
  1042 				</fieldset>
       
  1043 				</td>
       
  1044 				</tr>
       
  1045 				</table>
   216 			<?php
  1046 			<?php
   217 		} else {
  1047 			if ( $cache_enabled && !$wp_cache_mod_rewrite ) {
   218 			wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
  1048 				$scrules = trim( implode( "\n", extract_from_markers( trailingslashit( get_home_path() ) . '.htaccess', 'WPSuperCache' ) ) );
   219 		}
  1049 				if ( $scrules != '' ) {
   220 	} else {
  1050 					echo "<p><strong>" . __( 'Notice: PHP caching enabled but Supercache mod_rewrite rules detected. Cached files will be served using those rules. If your site is working ok please ignore this message or you can edit the .htaccess file in the root of your install and remove the SuperCache rules.', 'wp-super-cache' ) . '</strong></p>';
   221 		$cron_url = get_option( 'siteurl' ) . '/wp-cron.php?check=' . wp_hash('187425');
  1051 				}
   222 		$cron = wp_remote_get($cron_url, array('timeout' => 0.01, 'blocking' => true));
  1052 			}
   223 		if( is_array( $cron ) ) {
  1053 			echo "<div class='submit'><input class='button-primary' type='submit' " . SUBMITDISABLED . " value='" . __( 'Update Status', 'wp-super-cache' ) . " &raquo;' /></div></form>";
   224 			if( $cron[ 'response' ][ 'code' ] == '404' ) {
  1054 			if ( $cache_enabled ) {
   225 				?><h3>Warning! wp-cron.php not found!</h3>
  1055 				echo "<h3>" . __( 'Cache Tester', 'wp-super-cache' ) . "</h3>";
   226 				<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'>
  1056 				echo '<p>' . __( 'Test your cached website by clicking the test button below.', 'wp-super-cache' ) . '</p>';
   227 				<p><?php _e( '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.', 'wp-super-cache' ); ?></p>
  1057 				if ( array_key_exists('action', $_POST) && $_POST[ 'action' ] == 'test' && $valid_nonce ) {
   228 				<p><?php printf( __( 'Please see entry 16 in the <a href="%s">Troubleshooting section</a> of the readme.txt', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/wp-super-cache/faq/' ); ?></p>
  1058 					$url = trailingslashit( get_bloginfo( 'url' ) );
   229 				</div>
  1059 					if ( isset( $_POST[ 'httponly' ] ) )
   230 				<?php
  1060 						$url = str_replace( 'https://', 'http://', $url );
   231 			} else {
  1061 					// Prime the cache
   232 				wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
  1062 					echo "<p>" . sprintf(  __( 'Fetching %s to prime cache: ', 'wp-super-cache' ), $url );
   233 			}
  1063 					$page = wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
   234 		}
  1064 					echo '<span style="color: #0a0; font-weight: bold;">' . __( 'OK', 'wp-super-cache' ) . '</strong></p>';
   235 	}
  1065 					sleep( 1 );
   236 	}
  1066 					// Get the first copy
   237 
  1067 					echo "<p>" . sprintf(  __( 'Fetching first copy of %s: ', 'wp-super-cache' ), $url );
   238 	if( $cache_enabled == true && $super_cache_enabled == true && !got_mod_rewrite() ) {
  1068 					$page = wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
   239 		?><h4 style='color: #a00'><?php _e( 'Mod rewrite may not be installed!', 'wp-super-cache' ); ?></h4>
  1069 					if ( !is_wp_error( $page ) ) {
   240 		<p><?php _e( 'It appears that mod_rewrite is not installed. Sometimes this check isn&#8217;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 half-on mode.', 'wp-super-cache' ); ?></p><?php
  1070 						$fp = fopen( $cache_path . "1.html", "w" );
   241 	}
  1071 						fwrite( $fp, $page[ 'body' ] );
   242 
  1072 						fclose( $fp );
   243 	if( !is_writeable_ACLSafe($wp_cache_config_file) ) {
  1073 						echo '<span style="color: #0a0; font-weight: bold;">' . __( 'OK', 'wp-super-cache' ) . "</span> (<a href='" . WP_CONTENT_URL . "/cache/1.html'>1.html</a>)</p>";
   244 		define( "SUBMITDISABLED", 'disabled style="color: #aaa" ' );
  1074 						sleep( 1 );
   245 		?><h4 style='text-align:center; color: #a00'><?php _e( 'Read Only Mode. Configuration cannot be changed.', 'wp-super-cache' ); ?> <a href="javascript:toggleLayer('readonlywarning');" title="<?php _e( 'Why your configuration may not be changed', 'wp-super-cache' ); ?>"><?php _e( 'Why', 'wp-super-cache' ); ?></a></h4>
  1075 					} else {
   246 		<div id='readonlywarning' style='border: 1px solid #aaa; margin: 2px; padding: 2px; display: none;'>
  1076 						echo '<span style="color: #a00; font-weight: bold;">' . __( 'FAILED', 'wp-super-cache' ) . "</span></p>";
   247 		<p><?php printf( __( 'The WP Super Cache configuration file is <code>%s/wp-cache-config.php</code> and cannot be modified. That file must be writeable by the webserver to make any changes.', 'wp-super-cache' ), WP_CONTENT_DIR ); ?>
  1077 					}
   248 		<?php _e( 'A simple way of doing that is by changing the permissions temporarily using the CHMOD command or through your ftp client. Make sure it&#8217;s globally writeable and it should be fine.', 'wp-super-cache' ); ?></p>
  1078 					// Get the second copy
   249 		<?php _e( 'Writeable:', 'wp-super-cache' ); ?> <code>chmod 666 <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code>
  1079 					echo "<p>" . sprintf(  __( 'Fetching second copy of %s: ', 'wp-super-cache' ), $url );
   250 		<?php _e( 'Readonly:', 'wp-super-cache' ); ?> <code>chmod 644 <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code></p>
  1080 					$page2 = wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
   251 		</div><?php
  1081 					if ( !is_wp_error( $page2 ) ) {
   252 	} else {
  1082 						$fp = fopen( $cache_path . "2.html", "w" );
   253 		define( "SUBMITDISABLED", ' ' );
  1083 						fwrite( $fp, $page2[ 'body' ] );
   254 	}
  1084 						fclose( $fp );
   255 
  1085 						echo '<span style="color: #0a0; font-weight: bold;">' . __( 'OK', 'wp-super-cache' ) . "</span> (<a href='" . WP_CONTENT_URL . "/cache/2.html'>2.html</a>)</p>";
   256 	// Server could be running as the owner of the wp-content directory.  Therefore, if it's
  1086 					} else {
   257 	// writable, issue a warning only if the permissions aren't 755.
  1087 						echo '<span style="color: #a00; font-weight: bold;">' . __( 'FAILED', 'wp-super-cache' ) . "</span></p>";
   258 	if( is_writeable_ACLSafe( WP_CONTENT_DIR . '/' ) ) {
  1088 					}
   259 		$wp_content_stat = stat(WP_CONTENT_DIR . '/');
  1089 
   260 		$wp_content_mode = ($wp_content_stat['mode'] & 0777);
  1090 					if ( is_wp_error( $page ) || is_wp_error( $page2 ) || $page[ 'response' ][ 'code' ] != 200 || $page2[ 'response' ][ 'code' ] != 200 ) {
   261 		if( $wp_content_mode != 0755 ) {
  1091 						echo '<p><span style="color: #a00; font-weight: bold;">' . __( 'One or more page requests failed:', 'wp-super-cache' ) . '</span></p>';
   262 			?><h4 style='text-align:center; color: #a00'><?php printf( __( 'Warning! %s is writeable!', 'wp-super-cache' ), WP_CONTENT_DIR ); ?></h4>
  1092 						$error = false;
   263 			<p><?php printf( __( 'You should change the permissions on %s and make it more restrictive. Use your ftp client, or the following command to fix things:', 'wp-super-cache' ), WP_CONTENT_DIR ); ?><code>chmod 755 <?php echo WP_CONTENT_DIR; ?>/</code></p><?php
  1093 						if ( is_wp_error( $page ) ) {
   264 		}
  1094 							$error = $page;
   265 	}
  1095 						} elseif ( is_wp_error( $page2 ) ) {
   266 
  1096 							$error = $page2;
   267 	if ( $valid_nonce ) {
  1097 						}
   268 		if( isset( $_POST[ 'wp_cache_status' ] ) ) {
  1098 						if ( $error ) {
   269 			if( isset( $_POST[ 'wp_cache_mobile_enabled' ] ) ) {
  1099 							$errors = '';
   270 				$wp_cache_mobile_enabled = 1;
  1100 							$messages = '';
   271 			} else {
  1101 							foreach ( $error->get_error_codes() as $code ) {
   272 				$wp_cache_mobile_enabled = 0;
  1102 								$severity = $error->get_error_data($code);
   273 			}
  1103 								foreach ( $error->get_error_messages( $code ) as $err ) {
   274 			if( $wp_cache_mobile_enabled == 1 ) {
  1104 									$errors .= '	' . $err . "<br />\n";
   275 				if( !isset( $wp_cache_mobile_whitelist ) )
  1105 								}
   276 					wp_cache_replace_line('^ *\$wp_cache_mobile_whitelist', "\$wp_cache_mobile_whitelist = 'Stand Alone/QNws';", $wp_cache_config_file);
  1106 							}
   277 				if( false == isset( $wp_cache_mobile_browsers ) )
  1107 							if ( !empty($err) )
   278 					wp_cache_replace_line('^ *\$wp_cache_mobile_browsers', "\$wp_cache_mobile_browsers = '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';", $wp_cache_config_file);
  1108 								echo '<div class="updated fade">' . $errors . "</div>\n";
   279 			}
  1109 						} else {
   280 			wp_cache_replace_line('^ *\$wp_cache_mobile_enabled', "\$wp_cache_mobile_enabled = " . $wp_cache_mobile_enabled . ";", $wp_cache_config_file);
  1110 							echo '<ul><li>' . sprintf( __( 'Page %d: %d (%s)', 'wp-super-cache' ), 1, $page[ 'response' ][ 'code' ], $page[ 'response' ][ 'message' ] ) . '</li>';
   281 
  1111 							echo '<li>' . sprintf( __( 'Page %d: %d (%s)', 'wp-super-cache' ), 2, $page2[ 'response' ][ 'code' ], $page2[ 'response' ][ 'message' ] ) . '</li></ul>';
   282 			$wp_supercache_cache_list = $_POST[ 'wp_supercache_cache_list' ] == 1 ? 1 : 0;
  1112 						}
   283 			wp_cache_replace_line('^ *\$wp_supercache_cache_list', "\$wp_supercache_cache_list = " . $wp_supercache_cache_list . ";", $wp_cache_config_file);
  1113 					}
   284 
  1114 
   285 			switch( $_POST[ 'wp_cache_status' ] ) {
  1115 					if ( ( !is_wp_error( $page ) && !is_wp_error( $page2 ) ) && preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[ 'body' ], $matches1 ) &&
   286 				case 'all':
  1116 							preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page2[ 'body' ], $matches2 ) && $matches1[2] == $matches2[2] ) {
   287 					wp_cache_enable();
  1117 						echo '<p>' . sprintf( __( 'Page 1: %s', 'wp-super-cache' ), $matches1[ 2 ] ) . '</p>';
   288 					break;
  1118 						echo '<p>' . sprintf( __( 'Page 2: %s', 'wp-super-cache' ), $matches2[ 2 ] ) . '</p>';
   289 				case 'none':
  1119 						echo '<p><span style="color: #0a0; font-weight: bold;">' . __( 'The timestamps on both pages match!', 'wp-super-cache' ) . '</span></p>';
   290 					wp_cache_disable();
  1120 					} else {
   291 					break;
  1121 						echo '<p><strong>' . __( 'The pages do not match! Timestamps differ or were not found!', 'wp-super-cache' ) . '</strong></p>';
   292 				case 'wpcache':
  1122 						echo '<p>' . __( 'Things you can do:', 'wp-super-cache' ) . '</p>';
   293 					wp_cache_enable();
  1123 						echo '<ol><li>' . __( 'Load your homepage in a logged out browser, check the timestamp at the end of the html source. Load the page again and compare the timestamp. Caching is working if the timestamps match.', 'wp-super-cache' ) . '</li>';
   294 					wp_super_cache_disable();
  1124 						echo '<li>' . __( 'Enable logging on the Debug page here. That should help you track down the problem.', 'wp-super-cache' ) . '</li>';
   295 					break;
  1125 						echo '<li>' . __( 'You should check Page 1 and Page 2 above for errors. Your local server configuration may not allow your website to access itself.', 'wp-super-cache' ) . '</li>';
   296 			}
  1126 						echo "</ol>";
   297 			if( isset( $_POST[ 'wp_cache_hello_world' ] ) ) {
  1127 
   298 				$wp_cache_hello_world = 1;
  1128 					}
   299 			} else {
  1129 				}
   300 				$wp_cache_hello_world = 0;
  1130 				echo '<form name="cache_tester" action="" method="post">';
   301 			}
  1131 				echo '<input type="hidden" name="action" value="test" />';
   302 			wp_cache_replace_line('^ *\$wp_cache_hello_world', '$wp_cache_hello_world = ' . (int)$wp_cache_hello_world . ";", $wp_cache_config_file);
  1132 				if ( isset( $_SERVER['HTTPS' ] ) && 'on' == strtolower( $_SERVER['HTTPS' ] ) )
   303 			if( isset( $_POST[ 'wp_cache_clear_on_post_edit' ] ) ) {
  1133 					echo "<input type='checkbox' name='httponly' checked='checked' value='1' /> " . __( 'Send non-secure (non https) request for homepage', 'wp-super-cache' );
   304 				$wp_cache_clear_on_post_edit = 1;
  1134 				echo '<div class="submit"><input type="submit" name="test" value="' . __( 'Test Cache', 'wp-super-cache' ) . '" /></div>';
   305 			} else {
  1135 				wp_nonce_field('wp-cache');
   306 				$wp_cache_clear_on_post_edit = 0;
  1136 				echo '</form>';
   307 			}
  1137 			}
   308 			wp_cache_replace_line('^ *\$wp_cache_clear_on_post_edit', "\$wp_cache_clear_on_post_edit = " . $wp_cache_clear_on_post_edit . ";", $wp_cache_config_file);
  1138 			echo "<h3>" . __( "Delete Cached Pages", 'wp-super-cache' ) . "</h3>";
   309 			if( isset( $_POST[ 'cache_rebuild_files' ] ) ) {
  1139 			echo "<p>" . __( "Cached pages are stored on your server as html and PHP files. If you need to delete them use the button below.", 'wp-super-cache' ) . "</p>";
   310 				$cache_rebuild_files = 1;
  1140 			echo '<form name="wp_cache_content_delete" action="?page=wpsupercache&tab=contents" method="post">';
   311 			} else {
  1141 			echo '<input type="hidden" name="wp_delete_cache" />';
   312 				$cache_rebuild_files = 0;
  1142 			echo '<div class="submit" style="float:left;margin-left:10px"><input id="deletepost" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Cache', 'wp-super-cache' ) . ' &raquo;" /></div>';
   313 			}
  1143 			wp_nonce_field('wp-cache');
   314 			wp_cache_replace_line('^ *\$cache_rebuild_files', "\$cache_rebuild_files = " . $cache_rebuild_files . ";", $wp_cache_config_file);
  1144 			echo "</form>\n";
   315 			if( isset( $_POST[ 'wp_cache_mutex_disabled' ] ) ) {
  1145 
   316 				$wp_cache_mutex_disabled = 0;
  1146 			if ( ( defined( 'VHOST' ) || ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) ) && wpsupercache_site_admin() ) {
   317 			} else {
  1147 				echo '<form name="wp_cache_content_delete" action="#listfiles" method="post">';
   318 				$wp_cache_mutex_disabled = 1;
  1148 				echo '<input type="hidden" name="wp_delete_all_cache" />';
   319 			}
  1149 				echo '<div class="submit" style="float:left;margin-left:10px"><input id="deleteallpost" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Cache On All Blogs', 'wp-super-cache' ) . ' &raquo;" />';
   320 			if( defined( 'WPSC_DISABLE_LOCKING' ) ) {
  1150 				wp_nonce_field('wp-cache');
   321 				$wp_cache_mutex_disabled = 1;
  1151 				echo "</form><br />\n";
   322 			}
  1152 			}
   323 			wp_cache_replace_line('^ *\$wp_cache_mutex_disabled', "\$wp_cache_mutex_disabled = " . $wp_cache_mutex_disabled . ";", $wp_cache_config_file);
  1153 			?>
   324 			if( isset( $_POST[ 'wp_cache_not_logged_in' ] ) ) {
  1154 			<h3><?php _e( 'Recommended Links and Plugins', 'wp-super-cache' ); ?></h3>
   325 				if( $wp_cache_not_logged_in == 0 && function_exists( 'prune_super_cache' ) )
  1155 			<p><?php _e( 'Caching is only one part of making a website faster. Here are some other plugins that will help:', 'wp-super-cache' ); ?></p>
   326 					prune_super_cache ($cache_path, true);
  1156 			<ol><li><?php printf( __( '<a href="%s">WPSCMin</a>, a Supercache plugin that minifies cached pages by removing whitespaces and extra characters ', 'wp-super-cache' ), 'http://lyncd.com/wpscmin/' ); ?></li>
   327 				$wp_cache_not_logged_in = 1;
  1157 			<li><?php printf( __( '<a href="%s">Yahoo! Yslow</a> is an extension for the Firefox add-on Firebug. It analyzes web pages and suggests ways to improve their performance based on a set of rules for high performance web pages. Also try the performance tools online at <a href="%s">GTMetrix</a>.', 'wp-super-cache' ), 'http://developer.yahoo.com/yslow/', 'http://gtmetrix.com/' ); ?></li>
   328 			} else {
  1158 			<li><?php printf( __( '<a href="%s">Use Google Libraries</a> allows you to load some commonly used Javascript libraries from Google webservers. Ironically it may reduce your Yslow score.', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/use-google-libraries/' ); ?></li>
   329 				$wp_cache_not_logged_in = 0;
  1159 			<li><?php printf( __( 'The <a href="%1$s">CDN Sync Tool</a> plugin will help upload files to Amazon S3/Cloudfront if you would rather not depend on origin pull. See the <a href="%2$s">plugin support forum</a> if you have any queries about this plugin.', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/cdn-sync-tool/', 'http://wordpress.org/tags/cdn-sync-tool?forum_id=10' ); ?></li>
   330 			}
  1160 			<li><?php printf( __( '<strong>Advanced users only:</strong> <a href="%s">Speed up your site with Caching and cache-control</a> explains how to make your site more cacheable with .htaccess rules.', 'wp-super-cache' ), 'http://www.askapache.com/htaccess/speed-up-your-site-with-caching-and-cache-control.html' ); ?></li>
   331 			wp_cache_replace_line('^ *\$wp_cache_not_logged_in', "\$wp_cache_not_logged_in = " . $wp_cache_not_logged_in . ";", $wp_cache_config_file);
  1161 			<li><?php printf( __( '<strong>Advanced users only:</strong> Install an object cache. Choose from <a href="%s">Memcached</a>, <a href="%s">XCache</a>, <a href="%s">eAcccelerator</a> and others.', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/memcached/', 'http://neosmart.net/dl.php?id=12', 'http://neosmart.net/dl.php?id=13' ); ?></li>
   332 		}
  1162 			<li><?php printf( __( '<a href="%s">Cron View</a> is a useful plugin to use when trying to debug garbage collection and preload problems.', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/cron-view/' ); ?></li>
   333 		if( defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
  1163 			</ol>
   334 			$cache_compression_changed = false;
  1164 			
   335 			$cache_compression = 0;
  1165 			<?php
   336 			wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
  1166 		break;
   337 		} elseif( isset( $_POST[ 'cache_compression' ] ) && $_POST[ 'cache_compression' ] != $cache_compression ) {
  1167 	}
   338 			$cache_compression_changed = true;
  1168 
   339 			$cache_compression = intval( $_POST[ 'cache_compression' ] );
       
   340 			wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
       
   341 			if( function_exists( 'prune_super_cache' ) )
       
   342 				prune_super_cache ($cache_path, true);
       
   343 			delete_option( 'super_cache_meta' );
       
   344 		}
       
   345 		if( isset( $_POST[ 'wp_cache_hide_donation' ] ) && $_POST[ 'wp_cache_hide_donation' ] != $wp_cache_hide_donation ) {
       
   346 			$wp_cache_hide_donation = intval( $_POST[ 'wp_cache_hide_donation' ] );
       
   347 			wp_cache_replace_line('^ *\$wp_cache_hide_donation', "\$wp_cache_hide_donation = " . $wp_cache_hide_donation . ";", $wp_cache_config_file);
       
   348 		}
       
   349 	}
       
   350 
       
   351 	echo '<a name="top"></a>';
       
   352 	?>
       
   353 	<table><td><fieldset class="options" id="show-this-fieldset"> 
       
   354 	<h3><?php _e( 'WP Super Cache Status', 'wp-super-cache' ); ?></h3><?php
       
   355 	echo '<form name="wp_manager" action="#top" method="post">';
       
   356 	?>
       
   357 	<label><input type='radio' name='wp_cache_status' value='all' <?php if( $cache_enabled == true && $super_cache_enabled == true ) { echo 'checked=checked'; } ?>> <strong><?php _e( 'ON', 'wp-super-cache' ); ?></strong> <span class="setting-description"><?php _e( 'WP Cache and Super Cache enabled', 'wp-super-cache' ); ?></span></label><br />
       
   358 	<label><input type='radio' name='wp_cache_status' value='wpcache' <?php if( $cache_enabled == true && $super_cache_enabled == false ) { echo 'checked=checked'; } ?>> <strong><?php _e( 'HALF ON', 'wp-super-cache' ); ?></strong> <span class="setting-description"><?php _e( 'Super Cache Disabled, only legacy WP-Cache caching.', 'wp-super-cache' ); ?></span></label><br />
       
   359 	<label><input type='radio' name='wp_cache_status' value='none' <?php if( $cache_enabled == false ) { echo 'checked=checked'; } ?>> <strong><?php _e( 'OFF', 'wp-super-cache' ); ?></strong> <span class="setting-description"><?php _e( 'WP Cache and Super Cache disabled', 'wp-super-cache' ); ?></span></label><br />
       
   360 	<p><label><input type='checkbox' name='wp_cache_not_logged_in' <?php if( $wp_cache_not_logged_in ) echo "checked"; ?> value='1'> <?php _e( 'Don&#8217;t cache pages for logged in users.', 'wp-super-cache' ); ?></label></p>
       
   361 	<p><label><input type='checkbox' name='wp_cache_hello_world' <?php if( $wp_cache_hello_world ) echo "checked"; ?> value='1'> <?php _e( 'Proudly tell the world your server is Digg proof! (places a message in your blog&#8217;s footer)', 'wp-super-cache' ); ?></label></p>
       
   362 	<p><label><input type='checkbox' name='wp_cache_clear_on_post_edit' <?php if( $wp_cache_clear_on_post_edit ) echo "checked"; ?> value='1'> <?php _e( 'Clear all cache files when a post or page is published. (This may significantly slow down saving of posts.)', 'wp-super-cache' ); ?></label></p>
       
   363 	<p><label><input type='checkbox' name='cache_rebuild_files' <?php if( $cache_rebuild_files ) echo "checked"; ?> value='1'> <?php _e( 'Cache rebuild. Serve a supercache file to anonymous users while a new file is being generated. Recommended for <em>very</em> busy websites with lots of comments. Makes "directly cached pages" and "Lockdown mode" obsolete.', 'wp-super-cache' ); ?></label></p>
       
   364 	<?php if( false == defined( 'WPSC_DISABLE_LOCKING' ) ) { ?>
       
   365 		<p><label><input type='checkbox' name='wp_cache_mutex_disabled' <?php if( !$wp_cache_mutex_disabled ) echo "checked"; ?> value='0'> <?php _e( 'Coarse file locking. You probably don&#8217;t need this but it may help if your server is underpowered. Warning! <em>May cause your server to lock up in very rare cases!</em>', 'wp-super-cache' ); ?></label></p>
       
   366 	<?php } ?>
       
   367 	<p><label><input type='checkbox' name='wp_supercache_cache_list' <?php if( $wp_supercache_cache_list ) echo "checked"; ?> value='1'> <?php _e( 'List the newest cached pages (may be expensive to run on busy sites, use with caution.)', 'wp-super-cache' ); ?></label>
       
   368 	<p><label><input type='checkbox' name='wp_cache_mobile_enabled' <?php if( $wp_cache_mobile_enabled ) echo "checked"; ?> value='1'> <?php _e( 'Mobile device support.', 'wp-super-cache' ); ?></label>
       
   369 	<?php
       
   370 	$home_path = trailingslashit( get_home_path() );
       
   371 	$scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
       
   372 	if ( !$wp_cache_mobile_enabled && strpos( $scrules, '240x320|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo' ) ) {
       
   373 		echo "<blockquote style='background-color:#feefb3; padding: 5px; margin: 5px;'><h4>" . __( 'Mobile rewrite rules detected', 'wp-super-cache' ) . "</h4>";
       
   374 		echo "<p>" . __( 'For best performance you should enable "Mobile device support" or delete the mobile rewrite rules in your .htaccess. Look for the 2 lines with the text "Android|2.0\ MMP|240x320|AvantGo|BlackBerry|Blazer|Cellphone" and delete those.', 'wp-super-cache' ) . "</p><p>" . __( 'This will have no affect on ordinary users but mobile users will see uncached pages.', 'wp-super-cache' ) . "</p></blockquote>";
       
   375 	} elseif ( $wp_cache_mobile_enabled && $scrules != '' && false === strpos( $scrules, '240x320|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo' ) ) {
       
   376 	?>
       
   377 	<blockquote style='background-color:#fefeb3; padding: 5px; margin: 5px;'><p><?php _e( 'Mobile support requires extra rules in your .htaccess file, or you can set the plugin to half-on mode. Here are your options (in order of difficulty):', 'wp-super-cache' ); ?>
       
   378 	<ol><li> 1. <?php _e( 'Set the plugin to half on mode and enable mobile support.', 'wp-super-cache' ); ?></li>
       
   379 	<li> 2. <?php printf( __( 'Delete the plugin mod_rewrite rules in %s.htaccess enclosed by <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code> and let the plugin regenerate them by reloading this page.', 'wp-super-cache' ), $home_path ); ?></li>
       
   380 	<li> 3. <?php printf( __( 'Add the rules yourself. Edit %s.htaccess and find the block of code enclosed by the lines <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code>. There are two sections that look very similar. Just below the line <code>%{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$</code> add this line: (do it twice, once for each section)', 'wp-super-cache' ), $home_path ); ?></p>
       
   381 	<div style='padding: 2px; margin: 2px; border: 1px solid #333; width:400px; overflow: scroll'><pre>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).*</pre></div></li></ol></blockquote>
       
   382 	<?php } ?>
       
   383 	<p><strong><?php _e( 'Note:', 'wp-super-cache' ); ?></strong> <?php printf( __( 'If uninstalling this plugin, make sure the directory <em>%s</em> is writeable by the webserver so the files <em>advanced-cache.php</em> and <em>cache-config.php</em> can be deleted automatically. (Making sure those files are writeable too is probably a good idea!)', 'wp-super-cache' ), WP_CONTENT_DIR ); ?></p>
       
   384 	<p><?php printf( __( 'Uninstall using the <a href="%1$s/wp-super-cache/uninstall.php">uninstall script</a> to remove files and directories created by the plugin. (Please see <a href="%1$s/wp-super-cache/readme.txt">readme.txt</a> for instructions on uninstalling this script.)', 'wp-super-cache' ), WP_PLUGIN_URL ); ?></p>
       
   385 	<?php
       
   386 	echo "<div class='submit'><input type='submit' " . SUBMITDISABLED . " value='" . __( 'Update Status', 'wp-super-cache' ) . " &raquo;' /></div>";
       
   387 	wp_nonce_field('wp-cache');
       
   388 	?>
       
   389 	</form>
       
   390 	<?php
       
   391 	if( $super_cache_enabled && function_exists( 'apache_get_modules' ) ) {
       
   392 		$mods = apache_get_modules();
       
   393 		$required_modules = array( 'mod_mime' => __( 'Required to serve compressed supercache files properly.', 'wp-super-cache' ), 'mod_headers' => __( 'Required to set caching information on supercache pages. IE7 users will see old pages without this module.', 'wp-super-cache' ), 'mod_expires' => __( 'Set the expiry date on supercached pages. Visitors may not see new pages when they refresh or leave comments without this module.', 'wp-super-cache' ) );
       
   394 		foreach( $required_modules as $req => $desc ) {
       
   395 			if( !in_array( $req, $mods ) ) {
       
   396 				$missing_mods[ $req ] = $desc;
       
   397 			}
       
   398 		}
       
   399 		if( isset( $missing_mods) && is_array( $missing_mods ) ) {
       
   400 			echo "<h3>" . __( 'Missing Apache Modules', 'wp-super-cache' ) . "</h3>";
       
   401 			echo "<p>" . __( 'The following Apache modules are missing. The plugin will work in half-on mode without them. In full Supercache mode, your visitors may see corrupted pages or out of date content however.', 'wp-super-cache' ) . "</p>";
       
   402 			echo "<ul>";
       
   403 			foreach( $missing_mods as $req => $desc ) {
       
   404 				echo "<li> $req - $desc</li>";
       
   405 			}
       
   406 			echo "</ul>";
       
   407 		}
       
   408 	}
       
   409 	?>
  1169 	?>
   410 	</fieldset>
  1170 	</fieldset>
   411 	</td><td valign='top'>
  1171 	</td><td valign='top' style='width: 300px'>
   412 	<div style='background: #ffc; border: 1px solid #333; margin: 2px; padding: 5px'>
  1172 	<div style='background: #ffc; border: 1px solid #333; margin: 2px; padding: 5px'>
   413 	<h3 align='center'><?php _e( 'Make WordPress Faster', 'wp-super-cache' ); ?></h3>
  1173 	<h3 align='center'><?php _e( 'Make WordPress Faster', 'wp-super-cache' ); ?></h3>
   414 	<?php if( $wp_cache_hide_donation != 1 ) { ?>
  1174 	<p><?php printf( __( '%1$s is maintained and developed by %2$s with contributions from many others.', 'wp-super-cache' ), '<a href="http://ocaoimh.ie/y/34">WP Super Cache</a>', '<a href="http://ocaoimh.ie/y/35">Donncha O Caoimh</a>' ); ?></p>
   415 	<p><?php printf( __( '%1$s really makes your blog go faster. Make it go faster<sup>*</sup> by buying me an <a href="%2$s">Amazon gift card</a>! Make it out to "%3$s" for whatever amount you want. Every penny helps!', 'wp-super-cache' ), '<a href="http://ocaoimh.ie/wp-super-cache/?r=wpsc">WP Super Cache</a>', 'http://ocaoimh.ie/agc', 'donncha@ocaoimh.ie' ) ?>;</p>
  1175 	<p><?php printf( __( 'He blogs at %1$s and posts photos at %2$s.', 'wp-super-cache' ), '<a href="http://ocaoimh.ie/y/35">Holy Shmoly</a>', '<a href="http://ocaoimh.ie/y/2m">In Photos.org</a>' ); ?></p>
   416 	<p><?php printf( __( 'If Amazon isn&#8217;t your thing, there&#8217;s also PayPal. Click the "Donate" button below or take a quick peek at my <a href="%s">wishlist</a>.', 'wp-super-cache' ), 'http://ocaoimh.ie/wish' ); ?></p>
       
   417 	<p><?php _e( 'Thanks in advance!', 'wp-super-cache' ); ?><br />Donncha<br />
       
   418 	<small>* <?php _e( 'Ok, it won&#8217;t go any faster but you&#8217;ll make this plugin author very happy!', 'wp-super-cache' ); ?></small></p>
       
   419 	<div align='center'>
       
   420 	<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
       
   421 	<input type="hidden" name="cmd" value="_s-xclick"/>
       
   422 	<input type="hidden" name="hosted_button_id" value="3244504"/>
       
   423 	<input type="image" src="https://www.paypal.com/en_GB/i/btn/btn_donate_SM.gif" border="0" name="submit" alt=""/>
       
   424 	<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"/><br />
       
   425 	</form>
       
   426 	<p><?php _e( 'Don&#8217;t show me this again.', 'wp-super-cache' ); ?> <form action="#top" method="post"><input type='hidden' name='wp_cache_hide_donation' value='1' /><input type='submit' value='<?php _e( 'Hide', 'wp-super-cache' ); ?>' /><?php wp_nonce_field('wp-cache'); ?></form></p>
       
   427 	</div>
       
   428 	<?php } else { ?>
       
   429 	<p><?php printf( __( '%1$s is maintained and developed by %2$s with contributions from many others.', 'wp-super-cache' ), '<a href="http://ocaoimh.ie/wp-super-cache/?r=supercache">WP Super Cache</a>', '<a href="http://ocaoimh.ie/?r=supercache">Donncha O Caoimh</a>' ); ?></p>
       
   430 	<p><?php printf( __( 'He blogs at %1$s, posts photos at %2$s and <a href="%3$s">wishes</a> he had more time to read and relax.', 'wp-super-cache' ), '<a href="http://ocaoimh.ie/?r=supercache">Holy Shmoly</a>', '<a href="http://inphotos.org/?r=supercache">In Photos.org</a>', 'http://ocaoimh.ie/gad' ); ?></p>
       
   431 	<p><?php printf( __( 'Please say hi to him on %s too!', 'wp-super-cache' ), '<a href="http://twitter.com/donncha/">Twitter</a>' ); ?></p>
  1176 	<p><?php printf( __( 'Please say hi to him on %s too!', 'wp-super-cache' ), '<a href="http://twitter.com/donncha/">Twitter</a>' ); ?></p>
       
  1177 	<h3 align='center'><?php _e( 'Need Help?', 'wp-super-cache' ); ?></h3>
       
  1178 	<ol>
       
  1179 	<li><?php _e( 'Use the debug system in the Debug tab above. It will tell you what the plugin is doing.', 'wp-super-cache' ); ?></li>
       
  1180 	<li><?php printf( __( '<a href="%1$s">Installation Help</a>', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/wp-super-cache/installation/' ); ?></li>
       
  1181 	<li><?php printf( __( '<a href="%1$s">Frequently Asked Questions</a>', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/wp-super-cache/faq/' ); ?></li>
       
  1182 	<li><?php printf( __( '<a href="%1$s">Support Forum</a>', 'wp-super-cache' ), 'http://wordpress.org/tags/wp-super-cache' ); ?></li>
       
  1183 	<li><?php printf( __( '<a href="%1$s">Development Version</a>', 'wp-super-cache' ), 'http://ocaoimh.ie/y/2o' ); ?></li>
       
  1184 	</ol>
       
  1185 	<h3 align='center'><?php _e( 'Rate This Plugin!', 'wp-super-cache' ); ?></h3>
       
  1186 	<p><?php printf( __( 'Please <a href="%s">rate</a> this plugin and tell me if it works for you or not. It really helps development.', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/wp-super-cache/' ); ?></p>
       
  1187 
   432 	<?php 
  1188 	<?php 
   433 	}
       
   434 	if ( isset( $wp_supercache_cache_list ) && $wp_supercache_cache_list ) { 
  1189 	if ( isset( $wp_supercache_cache_list ) && $wp_supercache_cache_list ) { 
   435 		$start_date = get_option( 'wpsupercache_start' );
  1190 		$start_date = get_option( 'wpsupercache_start' );
   436 		if ( !$start_date ) {
  1191 		if ( !$start_date ) {
   437 			$start_date = time();
  1192 			$start_date = time();
   438 		}
  1193 		}
   440 		<p><?php printf( __( 'Cached pages since %1$s : <strong>%2$s</strong>', 'wp-super-cache' ), date( 'M j, Y', $start_date ), number_format( get_option( 'wpsupercache_count' ) ) ); ?></p>
  1195 		<p><?php printf( __( 'Cached pages since %1$s : <strong>%2$s</strong>', 'wp-super-cache' ), date( 'M j, Y', $start_date ), number_format( get_option( 'wpsupercache_count' ) ) ); ?></p>
   441 		<p><?php _e( 'Newest Cached Pages:', 'wp-super-cache' ); ?><ol>
  1196 		<p><?php _e( 'Newest Cached Pages:', 'wp-super-cache' ); ?><ol>
   442 		<?php
  1197 		<?php
   443 		foreach( array_reverse( (array)get_option( 'supercache_last_cached' ) ) as $url ) {
  1198 		foreach( array_reverse( (array)get_option( 'supercache_last_cached' ) ) as $url ) {
   444 			$since = time() - strtotime( $url[ 'date' ] );
  1199 			$since = time() - strtotime( $url[ 'date' ] );
   445 			echo "<li><a title='" . sprintf( __( 'Cached %s seconds ago', 'wp-super-cache' ), $since ) . "' href='" . site_url( $url[ 'url' ] ) . "'>{$url[ 'url' ]}</a></li>\n";
  1200 			echo "<li><a title='" . sprintf( __( 'Cached %s seconds ago', 'wp-super-cache' ), $since ) . "' href='" . site_url( $url[ 'url' ] ) . "'>" . substr( $url[ 'url' ], 0, 20 ) . "</a></li>\n";
   446 		}
  1201 		}
   447 		?></ol>
  1202 		?></ol>
   448 		<small><?php _e( '(may not always be accurate on busy sites)', 'wp-super-cache' ); ?></small>
  1203 		<small><?php _e( '(may not always be accurate on busy sites)', 'wp-super-cache' ); ?></small>
   449 		</p><?php 
  1204 		</p><?php 
   450 	} else {
  1205 	} elseif ( false == get_option( 'wpsupercache_start' ) ) {
   451 		$start_date = get_option( 'wpsupercache_start' );
  1206 			update_option( 'wpsupercache_start', time() );
   452 		if ( $start_date ) {
       
   453 			update_option( 'wpsupercache_start', $start_date );
       
   454 			update_option( 'wpsupercache_count', 0 );
  1207 			update_option( 'wpsupercache_count', 0 );
   455 		}
       
   456 	}
  1208 	}
   457 	?>
  1209 	?>
   458 	</div>
  1210 	</div>
   459 
       
   460 	</td></table>
  1211 	</td></table>
       
  1212 
   461 	<?php
  1213 	<?php
   462 
  1214 
   463 	wp_cache_files();
  1215 	echo "</div>\n";
   464 
  1216 }
   465 	wsc_mod_rewrite();
  1217 
   466 
  1218 function wpsc_plugins_tab() {
   467 	wp_cache_edit_max_time();
  1219 	echo '<p>' . __( 'Cache plugins are PHP scripts that live in a plugins folder inside the wp-super-cache folder. They are loaded when Supercache loads, much sooner than regular WordPress plugins.', 'wp-super-cache' ) . '</p>';
   468 
  1220 	echo '<p>' . __( 'This is strictly an advanced feature only and knowledge of both PHP and WordPress actions is required to create them.', 'wp-super-cache' ) . '</p>';
   469 	echo '<a name="files"></a><fieldset class="options"><h3>' . __( 'Accepted Filenames &amp; Rejected URIs', 'wp-super-cache' ) . '</h3>';
  1221 	echo '<p>' . __( '<strong>Warning</strong>! Due to the way WordPress upgrades plugins the plugins you upload to wp-super-cache/plugins/ will be deleted when you upgrade WP Super Cache. You can avoid this by loading the plugins from elsewhere. Set <strong>$wp_cache_plugins_dir</strong> to the new location in wp-config.php and WP Super Cache will look there instead.<br />More info available in the <a href="http://ocaoimh.ie/wp-super-cache-developers/">developer documentation</a>.', 'wp-super-cache' ) . '</p>';
   470 	wp_cache_edit_rejected_pages();
       
   471 	echo "\n";
       
   472 	wp_cache_edit_rejected();
       
   473 	echo "\n";
       
   474 	wp_cache_edit_accepted();
       
   475 	echo '</fieldset>';
       
   476 
       
   477 	wp_cache_edit_rejected_ua();
       
   478 
       
   479 	wp_cache_debug_settings();
       
   480 
       
   481 	wp_lock_down();
       
   482 
       
   483 	wp_cache_restore();
       
   484 
       
   485 	ob_start();
  1222 	ob_start();
   486 	if( defined( 'WP_CACHE' ) ) {
  1223 	if( defined( 'WP_CACHE' ) ) {
   487 		if( function_exists( 'do_cacheaction' ) ) {
  1224 		if( function_exists( 'do_cacheaction' ) ) {
   488 			do_cacheaction( 'cache_admin_page' );
  1225 			do_cacheaction( 'cache_admin_page' );
   489 		}
  1226 		}
   490 	}
  1227 	}
   491 	$out = ob_get_contents();
  1228 	$out = ob_get_contents();
   492 	ob_end_clean();
  1229 	ob_end_clean();
   493 	if( SUBMITDISABLED == ' ' && $out != '' ) {
  1230 	if( SUBMITDISABLED == ' ' && $out != '' ) {
   494 		echo '<fieldset class="options"><h3>' . __( 'Cache Plugins', 'wp-super-cache' ) . '</h3>';
  1231 		echo '<h3>' . __( 'Available Plugins', 'wp-super-cache' ) . '</h3>';
       
  1232 		echo "<ol>";
   495 		echo $out;
  1233 		echo $out;
   496 		echo '</fieldset>';
  1234 		echo "</ol>";
   497 	}
  1235 	}
   498 
  1236 
   499 	echo "</div>\n";
  1237 }
       
  1238 
       
  1239 function wpsc_admin_tabs( $current = 0 ) {
       
  1240 	global $wp_db_version;
       
  1241 	if ( $current == 0 ) {
       
  1242 		if ( isset( $_GET[ 'tab' ] ) ) {
       
  1243 			$current = $_GET[ 'tab' ];
       
  1244 		} else {
       
  1245 			$current = 'easy';
       
  1246 		}
       
  1247 	}
       
  1248 	$tabs = array( 'easy' => __( 'Easy', 'wp-super-cache' ), 'settings' => __( 'Advanced', 'wp-super-cache' ), 'cdn' => __( 'CDN', 'wp-super-cache' ), 'contents' => __( 'Contents', 'wp-super-cache' ), 'preload' => __( 'Preload', 'wp-super-cache' ), 'plugins' => __( 'Plugins', 'wp-super-cache' ), 'debug' => __( 'Debug', 'wp-super-cache' ) );
       
  1249 	$links = array();
       
  1250 	foreach( $tabs as $tab => $name ) {
       
  1251 		if ( $current == $tab ) {
       
  1252 			$links[] = "<a class='nav-tab nav-tab-active' href='?page=wpsupercache&tab=$tab'>$name</a>";
       
  1253 		} else {
       
  1254 			$links[] = "<a class='nav-tab' href='?page=wpsupercache&tab=$tab'>$name</a>";
       
  1255 		}
       
  1256 	}
       
  1257 	if ( $wp_db_version >= 15477 ) {
       
  1258 		echo '<div id="nav"><h2 class="themes-php">';
       
  1259 		echo implode( "", $links );
       
  1260 		echo '</h2></div>';
       
  1261 	} else {
       
  1262 		echo implode( " | ", $links );
       
  1263 	}
   500 }
  1264 }
   501 
  1265 
   502 function wsc_mod_rewrite() {
  1266 function wsc_mod_rewrite() {
   503 	global $cache_enabled, $super_cache_enabled, $cache_compression, $cache_compression_changed, $valid_nonce, $cache_path;
  1267 	global $cache_enabled, $super_cache_enabled, $valid_nonce, $cache_path, $wp_cache_mod_rewrite, $wpmu_version;
   504 	if( $super_cache_enabled == false && $cache_enabled == true ) {
  1268 
   505 		?><h3><?php _e( 'Super Cache Compression', 'wp-super-cache' ); ?></h3>
  1269 	if ( !$wp_cache_mod_rewrite )
   506 		<p><?php _e( 'Compression is enabled by default when in <em>HALF ON</em> mode.', 'wp-super-cache' ); ?></p>
  1270 		return false;
   507 		<?php
  1271 
   508 		return;
  1272 	if ( isset( $wpmu_version ) || function_exists( 'is_multisite' ) && is_multisite() ) {
   509 	} elseif ( $super_cache_enabled == false ) {
  1273 		if ( false == wpsupercache_site_admin() )
   510 		return;
  1274 			return false;
   511 	}
  1275 		if ( function_exists( "is_main_site" ) && false == is_main_site() ) {
   512 	if( false == defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
  1276 			global $current_site;
       
  1277 			$protocol = ( 'on' == strtolower( $_SERVER['HTTPS' ] ) ) ? 'https://' : 'http://';
       
  1278 			if ( isset( $wpmu_version ) ) {
       
  1279 				$link_to_admin = admin_url( "wpmu-admin.php?page=wpsupercache" );
       
  1280 			} else {
       
  1281 				$link_to_admin = admin_url( "ms-admin.php?page=wpsupercache" );
       
  1282 			}
       
  1283 			echo '<div id="message" class="updated fade"><p>' .  sprintf( __( 'Notice: WP Super Cache mod_rewrite rule checks disabled unless running on <a href="%s">the main site</a> of this network.', 'wp-super-cache' ), $link_to_admin ) . '</p></div>';
       
  1284 			return false;
       
  1285 		}
       
  1286 	}
       
  1287 
       
  1288 	if ( function_exists( "is_main_site" ) && false == is_main_site() )
       
  1289 		return true;
   513 	?>
  1290 	?>
   514 	<a name='rewrite'></a>
       
   515 	<fieldset class="options"> 
       
   516 	<h3><?php _e( 'Super Cache Compression', 'wp-super-cache' ); ?></h3>
       
   517 	<form name="wp_manager" action="#rewrite" method="post">
       
   518 	<label><input type="radio" name="cache_compression" value="1" <?php if( $cache_compression ) { echo "checked=checked"; } ?>> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
       
   519 	<label><input type="radio" name="cache_compression" value="0" <?php if( !$cache_compression ) { echo "checked=checked"; } ?>> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
       
   520 	<p><?php _e( 'Compression is disabled by default because some hosts have problems with compressed files. Switching this on and off clears the cache.', 'wp-super-cache' ); ?></p>
       
   521 	<?php
       
   522 	if( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && !$cache_compression ) {
       
   523 		?><p><strong><?php _e( 'Super Cache compression is now disabled.', 'wp-super-cache' ); ?></strong></p> <?php
       
   524 	} elseif( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && $cache_compression ) {
       
   525 		?><p><strong><?php _e( 'Super Cache compression is now enabled.', 'wps-uper-cache' ); ?></strong></p><?php
       
   526 	}
       
   527 	echo '<div class="submit"><input ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update Compression', 'wp-super-cache' ) . ' &raquo;" /></div>';
       
   528 	wp_nonce_field('wp-cache');
       
   529 	echo "</form>\n";
       
   530 	?></fieldset>
       
   531 	<?php } ?>
       
   532 
       
   533 	<a name="modrewrite"></a><fieldset class="options"> 
  1291 	<a name="modrewrite"></a><fieldset class="options"> 
   534 	<h3><?php _e( 'Mod Rewrite Rules', 'wp-super-cache' ); ?></h3><?php
  1292 	<h3><?php _e( 'Mod Rewrite Rules', 'wp-super-cache' ); ?></h3><?php
   535 	if ( isset( $_SERVER[ "PHP_DOCUMENT_ROOT" ] ) ) {
  1293 
   536 		$document_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
  1294 	extract( wpsc_get_htaccess_info() );
   537 		$apache_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
       
   538 	} else {
       
   539 		$document_root = $_SERVER[ "DOCUMENT_ROOT" ];
       
   540 		$apache_root = '%{DOCUMENT_ROOT}';
       
   541 	}
       
   542 	$home_path = get_home_path();
       
   543 	$home_root = parse_url(get_bloginfo('url'));
       
   544 	$home_root = isset( $home_root['path'] ) ? trailingslashit( $home_root['path'] ) : '/';
       
   545 	$inst_root = str_replace( '//', '/', '/' . trailingslashit( str_replace( $document_root, '', str_replace( '\\', '/', WP_CONTENT_DIR ) ) ) );
       
   546 	$wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) );
       
   547 	$wprules = str_replace( "RewriteEngine On\n", '', $wprules );
       
   548 	$wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
       
   549 	$scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
       
   550 
       
   551 	if( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
       
   552 		$condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*[^/]$";
       
   553 		$condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*//.*$";
       
   554 	}
       
   555 	$condition_rules[] = "RewriteCond %{REQUEST_METHOD} !POST";
       
   556 	$condition_rules[] = "RewriteCond %{QUERY_STRING} !.*=.*";
       
   557 	$condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$";
       
   558 	$condition_rules[] = "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).*";
       
   559 	$condition_rules = apply_filters( 'supercacherewriteconditions', $condition_rules );
       
   560 
       
   561 	$rules = "<IfModule mod_rewrite.c>\n";
       
   562 	$rules .= "RewriteEngine On\n";
       
   563 	$rules .= "RewriteBase $home_root\n"; // props Chris Messina
       
   564 	$charset = get_option('blog_charset') == '' ? 'UTF-8' : get_option('blog_charset');
       
   565 	$rules .= "AddDefaultCharset {$charset}\n";
       
   566 	$rules .= "CONDITION_RULES";
       
   567 	$rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
       
   568 	$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz -f\n";
       
   569 	$rules .= "RewriteRule ^(.*) {$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz [L]\n\n";
       
   570 
       
   571 	$rules .= "CONDITION_RULES";
       
   572 	$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html -f\n";
       
   573 	$rules .= "RewriteRule ^(.*) {$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html [L]\n";
       
   574 	$rules .= "</IfModule>\n";
       
   575 	$rules = apply_filters( 'supercacherewriterules', $rules );
       
   576 
       
   577 	$rules = str_replace( "CONDITION_RULES", implode( "\n", $condition_rules ) . "\n", $rules );
       
   578 
       
   579 	$dohtaccess = true;
  1295 	$dohtaccess = true;
   580 	if( function_exists( 'is_site_admin' ) ) {
  1296 	global $wpmu_version;
       
  1297 	if( isset( $wpmu_version ) ) {
   581 		echo "<h4 style='color: #a00'>" . __( 'WordPress MU Detected', 'wp-super-cache' ) . "</h4><p>" . __( "Unfortunately the rewrite rules cannot be updated automatically when running WordPress MU. Please open your .htaccess and add the following mod_rewrite rules above any other rules in that file.", 'wp-super-cache' ) . "</p>";
  1298 		echo "<h4 style='color: #a00'>" . __( 'WordPress MU Detected', 'wp-super-cache' ) . "</h4><p>" . __( "Unfortunately the rewrite rules cannot be updated automatically when running WordPress MU. Please open your .htaccess and add the following mod_rewrite rules above any other rules in that file.", 'wp-super-cache' ) . "</p>";
   582 	} elseif( !$wprules || $wprules == '' ) {
  1299 	} elseif( !$wprules || $wprules == '' ) {
   583 		echo "<h4 style='color: #a00'>" . __( 'Mod Rewrite rules cannot be updated!', 'wp-super-cache' ) . "</h4>";
  1300 		echo "<h4 style='color: #a00'>" . __( 'Mod Rewrite rules cannot be updated!', 'wp-super-cache' ) . "</h4>";
   584 		echo "<p>" . sprintf( __( "You must have <strong>BEGIN</strong> and <strong>END</strong> markers in %s.htaccess for the auto update to work. They look like this and surround the main WordPress mod_rewrite rules:", 'wp-super-cache' ), $home_path );
  1301 		echo "<p>" . sprintf( __( "You must have <strong>BEGIN</strong> and <strong>END</strong> markers in %s.htaccess for the auto update to work. They look like this and surround the main WordPress mod_rewrite rules:", 'wp-super-cache' ), $home_path );
   585 		echo "<blockquote><pre><em># BEGIN WordPress</em>\n RewriteCond %{REQUEST_FILENAME} !-f\n RewriteCond %{REQUEST_FILENAME} !-d\n RewriteRule . /index.php [L]\n <em># END WordPress</em></pre></blockquote>";
  1302 		echo "<blockquote><pre><em># BEGIN WordPress</em>\n RewriteCond %{REQUEST_FILENAME} !-f\n RewriteCond %{REQUEST_FILENAME} !-d\n RewriteRule . /index.php [L]\n <em># END WordPress</em></pre></blockquote>";
   586 		_e( 'Refresh this page when you have updated your .htaccess file.', 'wp-super-cache' );
  1303 		_e( 'Refresh this page when you have updated your .htaccess file.', 'wp-super-cache' );
   587 		echo "</fieldset></div>";
  1304 		echo "</fieldset>";
   588 		return;
  1305 		$dohtaccess = false;
   589 	} elseif( strpos( $wprules, 'wordpressuser' ) ) { // Need to clear out old mod_rewrite rules
  1306 	} elseif( strpos( $wprules, 'wordpressuser' ) ) { // Need to clear out old mod_rewrite rules
   590 		echo "<p><strong>" . __( 'Thank you for upgrading.', 'wp-super-cache' ) . "</strong> " . sprintf( __( 'The mod_rewrite rules changed since you last installed this plugin. Unfortunately you must remove the old supercache rules before the new ones are updated. Refresh this page when you have edited your .htaccess file. If you wish to manually upgrade, change the following line: %1$s so it looks like this: %2$s The only changes are "HTTP_COOKIE" becomes "HTTP:Cookie" and "wordpressuser" becomes "wordpress". This is a WordPress 2.5 change but it&#8217;s backwards compatible with older versions if you&#8217;re brave enough to use them.', 'wp-super-cache' ), '<blockquote><code>RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$</code></blockquote>', '<blockquote><code>RewriteCond %{HTTP:Cookie} !^.*wordpress.*$</code></blockquote>' ) . "</p>";
  1307 		echo "<p><strong>" . __( 'Thank you for upgrading.', 'wp-super-cache' ) . "</strong> " . sprintf( __( 'The mod_rewrite rules changed since you last installed this plugin. Unfortunately you must remove the old supercache rules before the new ones are updated. Refresh this page when you have edited your .htaccess file. If you wish to manually upgrade, change the following line: %1$s so it looks like this: %2$s The only changes are "HTTP_COOKIE" becomes "HTTP:Cookie" and "wordpressuser" becomes "wordpress". This is a WordPress 2.5 change but it&#8217;s backwards compatible with older versions if you&#8217;re brave enough to use them.', 'wp-super-cache' ), '<blockquote><code>RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$</code></blockquote>', '<blockquote><code>RewriteCond %{HTTP:Cookie} !^.*wordpress.*$</code></blockquote>' ) . "</p>";
   591 		echo "</fieldset></div>";
  1308 		echo "</fieldset></div>";
   592 		return;
  1309 		return;
   593 	} elseif( $scrules != '' && strpos( $scrules, '%{REQUEST_URI} !^.*[^/]$' ) === false && substr( get_option( 'permalink_structure' ), -1 ) == '/' ) { // permalink structure has a trailing slash, need slash check in rules.
  1310 	} elseif( $scrules != '' && strpos( $scrules, '%{REQUEST_URI} !^.*[^/]$' ) === false && substr( get_option( 'permalink_structure' ), -1 ) == '/' ) { // permalink structure has a trailing slash, need slash check in rules.
   596 		echo "<p>" . __( 'You can see where the rules go and examine the complete rules by clicking the "View mod_rewrite rules" link below.', 'wp-super-cache' ) . "</p></div>";
  1313 		echo "<p>" . __( 'You can see where the rules go and examine the complete rules by clicking the "View mod_rewrite rules" link below.', 'wp-super-cache' ) . "</p></div>";
   597 		$dohtaccess = false;
  1314 		$dohtaccess = false;
   598 	} elseif( strpos( $scrules, 'supercache' ) || strpos( $wprules, 'supercache' ) ) { // only write the rules once
  1315 	} elseif( strpos( $scrules, 'supercache' ) || strpos( $wprules, 'supercache' ) ) { // only write the rules once
   599 		$dohtaccess = false;
  1316 		$dohtaccess = false;
   600 	}
  1317 	}
   601 	// cache/.htaccess rules
       
   602 	$gziprules =  "<IfModule mod_mime.c>\n  <FilesMatch \"\\.html\\.gz\$\">\n    ForceType text/html\n    FileETag None\n  </FilesMatch>\n  AddEncoding gzip .gz\n  AddType text/html .gz\n</IfModule>\n";
       
   603 	$gziprules .= "<IfModule mod_deflate.c>\n  SetEnvIfNoCase Request_URI \.gz$ no-gzip\n</IfModule>\n";
       
   604 	$gziprules .= "<IfModule mod_headers.c>\n  Header set Vary \"Accept-Encoding, Cookie\"\n  Header set Cache-Control 'max-age=300, must-revalidate'\n</IfModule>\n";
       
   605 	$gziprules .= "<IfModule mod_expires.c>\n  ExpiresActive On\n  ExpiresByType text/html A300\n</IfModule>\n";
       
   606 	if( $dohtaccess && !$_POST[ 'updatehtaccess' ] ) {
  1318 	if( $dohtaccess && !$_POST[ 'updatehtaccess' ] ) {
   607 		if( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) {
  1319 		if ( $scrules == '' ) {
   608 			echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><h4>" . __( 'Cannot update .htaccess', 'wp-super-cache' ) . "</h4><p>" . sprintf( __( 'The file <code>%s.htaccess</code> cannot be modified by the web server. Please correct this using the chmod command or your ftp client.', 'wp-super-cache' ), $home_path ) . "</p><p>" . __( 'Refresh this page when the file permissions have been modified.' ) . "</p><p>" . sprintf( __( 'Alternatively, you can edit your <code>%s.htaccess</code> file manually and add the following code (before any WordPress rules):', 'wp-super-cache' ), $home_path ) . "</p>";
  1320 			wpsc_update_htaccess_form( 0 ); // don't hide the update htaccess form
   609 			echo "<p><pre># BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache</pre></p></div>";
  1321 		} else {
   610 		} else {
  1322 			wpsc_update_htaccess_form();
   611 			echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><p>" . sprintf( __( 'To serve static html files your server must have the correct mod_rewrite rules added to a file called <code>%s.htaccess</code>', 'wp-super-cache' ), $home_path ) . " ";
  1323 		}
   612 			if( !function_exists( 'is_site_admin' ) ) {
  1324 	} elseif( $valid_nonce && $_POST[ 'updatehtaccess' ] ) {
   613 				_e( "You must edit the file yourself add the following rules.", 'wp-super-cache' );
       
   614 			} else {
       
   615 				_e( "You can edit the file yourself add the following rules.", 'wp-super-cache' );
       
   616 			}
       
   617 			echo __( " Make sure they appear before any existing WordPress rules. ", 'wp-super-cache' ) . "</p>";
       
   618 			echo "<pre># BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache</pre></p>";
       
   619 			echo "<p>" . sprintf( __( 'Rules must be added to %s too:', 'wp-super-cache' ), WP_CONTENT_DIR . "/cache/.htaccess" ) . "</p>";
       
   620 			echo "<pre># BEGIN supercache\n" . wp_specialchars( $gziprules ) . "# END supercache</pre></p>";
       
   621 			if( !function_exists( 'is_site_admin' ) ) {
       
   622 				echo '<form name="updatehtaccess" action="#modrewrite" method="post">';
       
   623 				echo '<input type="hidden" name="updatehtaccess" value="1" />';
       
   624 				echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'id="updatehtaccess" value="' . __( 'Update Mod_Rewrite Rules', 'wp-super-cache' ) . ' &raquo;" /></div>';
       
   625 				wp_nonce_field('wp-cache');
       
   626 				echo "</form></div>\n";
       
   627 			}
       
   628 		}
       
   629 	} elseif( $dohtaccess && $valid_nonce && $_POST[ 'updatehtaccess' ] ) {
       
   630 		wpsc_remove_marker( $home_path.'.htaccess', 'WordPress' ); // remove original WP rules so SuperCache rules go on top
       
   631 		echo "<div style='padding:0 8px;color:#4f8a10;background-color:#dff2bf;border:1px solid #4f8a10;'>";
  1325 		echo "<div style='padding:0 8px;color:#4f8a10;background-color:#dff2bf;border:1px solid #4f8a10;'>";
   632 		if( insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', explode( "\n", $rules ) ) && insert_with_markers( $home_path.'.htaccess', 'WordPress', explode( "\n", $wprules ) ) ) {
  1326 		if( wpsc_update_htaccess() ) {
   633 			echo "<h4>" . __( 'Mod Rewrite rules updated!', 'wp-super-cache' ) . "</h4>";
  1327 			echo "<h4>" . __( 'Mod Rewrite rules updated!', 'wp-super-cache' ) . "</h4>";
   634 			echo "<p><strong>" . sprintf( __( '%s.htaccess has been updated with the necessary mod_rewrite rules. Please verify they are correct. They should look like this:', 'wp-super-cache' ), $home_path ) . "</strong></p>\n";
  1328 			echo "<p><strong>" . sprintf( __( '%s.htaccess has been updated with the necessary mod_rewrite rules. Please verify they are correct. They should look like this:', 'wp-super-cache' ), $home_path ) . "</strong></p>\n";
   635 		} else {
  1329 		} else {
   636 			echo "<h4>" . __( 'Mod Rewrite rules must be updated!', 'wp-super-cache' ) . "</h4>";
  1330 			echo "<h4>" . __( 'Mod Rewrite rules must be updated!', 'wp-super-cache' ) . "</h4>";
   637 			echo "<p><strong>" . sprintf( __( 'Your %s.htaccess is not writable by the webserver and must be updated with the necessary mod_rewrite rules. The new rules go above the regular WordPress rules as shown in the code below:', 'wp-super-cache' ), $home_path ) . "</strong></p>\n";
  1331 			echo "<p><strong>" . sprintf( __( 'Your %s.htaccess is not writable by the webserver and must be updated with the necessary mod_rewrite rules. The new rules go above the regular WordPress rules as shown in the code below:', 'wp-super-cache' ), $home_path ) . "</strong></p>\n";
   638 		}
  1332 		}
   639 		echo "<p><pre>" . wp_specialchars( $rules ) . "</pre></p>\n</div>";
  1333 		echo "<p><pre>" . esc_html( $rules ) . "</pre></p>\n</div>";
   640 	} else {
  1334 	} else {
   641 		?>
  1335 		?>
   642 		<p><?php printf( __( 'WP Super Cache mod rewrite rules were detected in your %s.htaccess file.<br /> Click the following link to see the lines added to that file. If you have upgraded the plugin make sure these rules match.', 'wp-super-cache' ), $home_path ); ?><br /><br />
  1336 		<p><?php printf( __( 'WP Super Cache mod rewrite rules were detected in your %s.htaccess file.<br /> Click the following link to see the lines added to that file. If you have upgraded the plugin make sure these rules match.', 'wp-super-cache' ), $home_path ); ?></p>
   643 		<a href="javascript:toggleLayer('rewriterules');" class="button"><?php _e( 'View Mod_Rewrite Rules', 'wp-super-cache' ); ?></a>
  1337 		<?php
   644 		<div id='rewriterules' style='display: none;'>
  1338 		if ( $rules != $scrules ) {
   645 		<?php echo "<p><pre># BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache</pre></p>\n"; 
  1339 			?><p style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><?php _e( 'A difference between the rules in your .htaccess file and the plugin rewrite rules has been found. This could be simple whitespace differences but you should compare the rules in the file with those below as soon as possible. Click the &#8217;Update Mod_Rewrite Rules&#8217; button to update the rules.', 'wp-super-cache' ); ?></p><?php
       
  1340 		}
       
  1341 		?><a href="javascript:toggleLayer('rewriterules');" class="button"><?php _e( 'View Mod_Rewrite Rules', 'wp-super-cache' ); ?></a><?php
       
  1342 		wpsc_update_htaccess_form();
       
  1343 		echo "<div id='rewriterules' style='display: none;'>";
       
  1344 		if ( $rules != $scrules )
       
  1345 			echo '<div style="background: #fff; border: 1px solid #333; margin: 2px;">' . wp_text_diff( $scrules, $rules, array( 'title' => 'Rewrite Rules', 'title_left' => 'Current Rules', 'title_right' => 'New Rules' ) ) . "</div>";
       
  1346 		echo "<p><pre># BEGIN WPSuperCache\n" . esc_html( $rules ) . "# END WPSuperCache</pre></p>\n"; 
   646 		echo "<p>" . sprintf( __( 'Rules must be added to %s too:', 'wp-super-cache' ), WP_CONTENT_DIR . "/cache/.htaccess" ) . "</p>";
  1347 		echo "<p>" . sprintf( __( 'Rules must be added to %s too:', 'wp-super-cache' ), WP_CONTENT_DIR . "/cache/.htaccess" ) . "</p>";
   647 		echo "<pre># BEGIN supercache\n" . wp_specialchars( $gziprules ) . "# END supercache</pre></p>"; ?>
  1348 		echo "<pre># BEGIN supercache\n" . esc_html( $gziprules ) . "# END supercache</pre></p>";
   648 		</div>
  1349 		echo '</div>';
   649 		<?php
       
   650 	}
  1350 	}
   651 	// http://allmybrain.com/2007/11/08/making-wp-super-cache-gzip-compression-work/
  1351 	// http://allmybrain.com/2007/11/08/making-wp-super-cache-gzip-compression-work/
   652 	if( !is_file( $cache_path . '.htaccess' ) ) {
  1352 	if( !is_file( $cache_path . '.htaccess' ) ) {
   653 		$gziprules = insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $gziprules ) );
  1353 		$gziprules = insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $gziprules ) );
   654 		echo "<h4>" . sprintf( __( 'Gzip encoding rules in %s.htaccess created.', 'wp-super-cache' ), $cache_path ) . "</h4>";
  1354 		echo "<h4>" . sprintf( __( 'Gzip encoding rules in %s.htaccess created.', 'wp-super-cache' ), $cache_path ) . "</h4>";
   674 if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) )
  1374 if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) )
   675 	add_action( 'comment_form', 'comment_form_lockdown_message' );
  1375 	add_action( 'comment_form', 'comment_form_lockdown_message' );
   676 
  1376 
   677 function wp_lock_down() {
  1377 function wp_lock_down() {
   678 	global $wpdb, $cache_path, $wp_cache_config_file, $valid_nonce, $cached_direct_pages, $cache_enabled, $super_cache_enabled;
  1378 	global $wpdb, $cache_path, $wp_cache_config_file, $valid_nonce, $cached_direct_pages, $cache_enabled, $super_cache_enabled;
       
  1379 	global $wp_super_cache_lock_down;
   679 
  1380 
   680 	if(isset($_POST['wp_lock_down']) && $valid_nonce) {
  1381 	if(isset($_POST['wp_lock_down']) && $valid_nonce) {
   681 		$wp_lock_down = $_POST['wp_lock_down'] == '1' ? '1' : '0';
  1382 		$wp_lock_down = $_POST['wp_lock_down'] == '1' ? '1' : '0';
   682 		wp_cache_replace_line('^.*WPLOCKDOWN', "define( 'WPLOCKDOWN', '$wp_lock_down' );", $wp_cache_config_file);
  1383 		wp_cache_replace_line('^.*WPLOCKDOWN', "define( 'WPLOCKDOWN', '$wp_lock_down' );", $wp_cache_config_file);
   683 		if( $wp_lock_down == '0' && function_exists( 'prune_super_cache' ) )
  1384 		if( $wp_lock_down == '0' && function_exists( 'prune_super_cache' ) )
   718 		?><a name='direct'></a>
  1419 		?><a name='direct'></a>
   719 	<fieldset class="options"> 
  1420 	<fieldset class="options"> 
   720 	<h3><?php _e( 'Directly Cached Files', 'wp-super-cache' ); ?></h3><?php
  1421 	<h3><?php _e( 'Directly Cached Files', 'wp-super-cache' ); ?></h3><?php
   721 
  1422 
   722 	$out = '';
  1423 	$out = '';
   723 	if( $valid_nonce && is_array( $_POST[ 'direct_pages' ] ) && !empty( $_POST[ 'direct_pages' ] ) ) {
  1424 	if( $valid_nonce && array_key_exists('direct_pages', $_POST) && is_array( $_POST[ 'direct_pages' ] ) && !empty( $_POST[ 'direct_pages' ] ) ) {
   724 		$expiredfiles = array_diff( $cached_direct_pages, $_POST[ 'direct_pages' ] );
  1425 		$expiredfiles = array_diff( $cached_direct_pages, $_POST[ 'direct_pages' ] );
   725 		unset( $cached_direct_pages );
  1426 		unset( $cached_direct_pages );
   726 		foreach( $_POST[ 'direct_pages' ] as $page ) {
  1427 		foreach( $_POST[ 'direct_pages' ] as $page ) {
   727 			$page = $wpdb->escape( $page );
  1428 			$page = $wpdb->escape( $page );
   728 			if( $page != '' ) {
  1429 			if( $page != '' ) {
   732 		}
  1433 		}
   733 		if( $out == '' ) {
  1434 		if( $out == '' ) {
   734 			$out = "'', ";
  1435 			$out = "'', ";
   735 		}
  1436 		}
   736 	}
  1437 	}
   737 	if( $valid_nonce && $_POST[ 'new_direct_page' ] && '' != $_POST[ 'new_direct_page' ] ) {
  1438 	if( $valid_nonce && array_key_exists('new_direct_page', $_POST) && $_POST[ 'new_direct_page' ] && '' != $_POST[ 'new_direct_page' ] ) {
   738 		$page = str_replace( get_option( 'siteurl' ), '', $_POST[ 'new_direct_page' ] );
  1439 		$page = str_replace( get_option( 'siteurl' ), '', $_POST[ 'new_direct_page' ] );
   739 		if( substr( $page, 0, 1 ) != '/' )
  1440 		if( substr( $page, 0, 1 ) != '/' )
   740 			$page = '/' . $page;
  1441 			$page = '/' . $page;
   741 		$page = $wpdb->escape( $page );
  1442 		$page = $wpdb->escape( $page );
   742 		if( in_array( $page, $cached_direct_pages ) == false ) {
  1443 		if( in_array( $page, $cached_direct_pages ) == false ) {
   763 				RecursiveFolderDelete( trailingslashit( $firstfolder ) );
  1464 				RecursiveFolderDelete( trailingslashit( $firstfolder ) );
   764 			}
  1465 			}
   765 		}
  1466 		}
   766 	}
  1467 	}
   767 
  1468 
   768 	if( $valid_nonce && $_POST[ 'deletepage' ] ) {
  1469 	if( $valid_nonce && array_key_exists('deletepage', $_POST) && $_POST[ 'deletepage' ] ) {
   769 		$page = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_POST['deletepage']) );
  1470 		$page = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_POST['deletepage']) );
   770 		$pagefile = ABSPATH . $page . 'index.html';
  1471 		$pagefile = ABSPATH . $page . 'index.html';
   771 		$firstfolder = explode( '/', $page );
  1472 		$firstfolder = explode( '/', $page );
   772 		$firstfolder = ABSPATH . $firstfolder[1];
  1473 		$firstfolder = ABSPATH . $firstfolder[1];
   773 		$page = ABSPATH . $page;
  1474 		$page = ABSPATH . $page;
   783 	$readonly = '';
  1484 	$readonly = '';
   784 	if( !is_writeable_ACLSafe( ABSPATH ) ) {
  1485 	if( !is_writeable_ACLSafe( ABSPATH ) ) {
   785 		$readonly = 'READONLY';
  1486 		$readonly = 'READONLY';
   786 		?><p style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><strong><?php _e( 'Warning!', 'wp-super-cache' ); ?></strong> <?php printf( __( 'You must make %s writable to enable this feature. As this is a security risk please make it readonly after your page is generated.', 'wp-super-cache' ), ABSPATH ); ?></p><?php
  1487 		?><p style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><strong><?php _e( 'Warning!', 'wp-super-cache' ); ?></strong> <?php printf( __( 'You must make %s writable to enable this feature. As this is a security risk please make it readonly after your page is generated.', 'wp-super-cache' ), ABSPATH ); ?></p><?php
   787 	} else {
  1488 	} else {
   788 		?><p style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><strong><?php _e( 'Warning!', 'wp-super-cache' ); ?></strong> <?php printf( __( '%s is writable. Please make it readonly after your page is generated as this is a security risk.', 'wp-super-cache' ), ABSPATH ); ?></p><?php
  1489 		$abspath_stat = stat(ABSPATH . '/');
       
  1490 		$abspath_mode = decoct( $abspath_stat[ 'mode' ] & 0777 );
       
  1491 		if ( substr( $abspath_mode, -2 ) == '77' ) {
       
  1492 			?><p style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><strong><?php _e( 'Warning!', 'wp-super-cache' ); ?></strong> <?php printf( __( '%s is writable. Please make it readonly after your page is generated as this is a security risk.', 'wp-super-cache' ), ABSPATH ); ?></p><?php
       
  1493 		}
   789 	}
  1494 	}
   790 	echo '<form name="direct_page" action="#direct" method="post">';
  1495 	echo '<form name="direct_page" action="#direct" method="post">';
   791 	if( is_array( $cached_direct_pages ) ) {
  1496 	if( is_array( $cached_direct_pages ) ) {
   792 		$out = '';
  1497 		$out = '';
   793 		foreach( $cached_direct_pages as $page ) {
  1498 		foreach( $cached_direct_pages as $page ) {
   838 		return FALSE;
  1543 		return FALSE;
   839 	}
  1544 	}
   840 }
  1545 }
   841 
  1546 
   842 function wp_cache_edit_max_time () {
  1547 function wp_cache_edit_max_time () {
   843 	global $cache_max_time, $wp_cache_config_file, $valid_nonce, $cache_enabled, $super_cache_enabled;
  1548 	global $cache_max_time, $wp_cache_config_file, $valid_nonce, $cache_enabled, $super_cache_enabled, $cache_schedule_type, $cache_scheduled_time, $cache_schedule_interval, $cache_time_interval, $cache_gc_email_me, $wp_cache_preload_on;
   844 
  1549 
   845 	if( !isset( $cache_max_time ) )
  1550 	$timezone_format = _x('Y-m-d G:i:s', 'timezone date format');
       
  1551 
       
  1552 	if( !isset( $cache_schedule_type ) ) {
       
  1553 		$cache_schedule_type = 'interval';
       
  1554 		wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
       
  1555 	}
       
  1556 
       
  1557 	if( !isset( $cache_scheduled_time ) ) {
       
  1558 		$cache_scheduled_time = '00:00';
       
  1559 		wp_cache_replace_line('^ *\$cache_scheduled_time', "\$cache_scheduled_time = '$cache_scheduled_time';", $wp_cache_config_file);
       
  1560 	}
       
  1561 
       
  1562 	if( !isset( $cache_max_time ) ) {
   846 		$cache_max_time = 3600;
  1563 		$cache_max_time = 3600;
   847 
  1564 		wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file);
   848 	if(isset($_POST['wp_max_time']) && $valid_nonce) {
  1565 	}
   849 		$max_time = (int)$_POST['wp_max_time'];
  1566 
   850 		if ($max_time > 0) {
  1567 	if ( !isset( $cache_time_interval ) ) {
   851 			$cache_max_time = $max_time;
  1568 		$cache_time_interval = $cache_max_time;
   852 			wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file);
  1569 		wp_cache_replace_line('^ *\$cache_time_interval', "\$cache_time_interval = '$cache_time_interval';", $wp_cache_config_file);
   853 		}
  1570 	}
       
  1571 
       
  1572 	if ( isset( $_POST['wp_max_time'] ) && $valid_nonce ) {
       
  1573 		$cache_max_time = (int)$_POST['wp_max_time'];
       
  1574 		wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file);
       
  1575 		// schedule gc watcher
       
  1576 		if ( false == wp_next_scheduled( 'wp_cache_gc_watcher' ) )
       
  1577 			wp_schedule_event( time()+600, 'hourly', 'wp_cache_gc_watcher' );
       
  1578 	}
       
  1579 
       
  1580 	if ( isset( $_POST[ 'cache_gc_email_me' ] ) && $valid_nonce ) {
       
  1581 		$cache_gc_email_me = 1;
       
  1582 		wp_cache_replace_line('^ *\$cache_gc_email_me', "\$cache_gc_email_me = $cache_gc_email_me;", $wp_cache_config_file); 
       
  1583 	} elseif ( $valid_nonce ) {
       
  1584 		$cache_gc_email_me = 0;
       
  1585 		wp_cache_replace_line('^ *\$cache_gc_email_me', "\$cache_gc_email_me = $cache_gc_email_me;", $wp_cache_config_file); 
       
  1586 	}
       
  1587 	if ( isset( $_POST[ 'cache_schedule_type' ] ) && $_POST[ 'cache_schedule_type' ] == 'interval' && isset( $_POST['cache_time_interval'] ) && $valid_nonce ) {
       
  1588 		wp_clear_scheduled_hook( 'wp_cache_gc' );
       
  1589 		$cache_schedule_type = 'interval';
       
  1590 		if ( (int)$_POST[ 'cache_time_interval' ] == 0 )
       
  1591 			$_POST[ 'cache_time_interval' ] = 600;
       
  1592 		$cache_time_interval = (int)$_POST[ 'cache_time_interval' ];
       
  1593 		wp_schedule_single_event( time() + $cache_time_interval, 'wp_cache_gc' );
       
  1594 		wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
       
  1595 		wp_cache_replace_line('^ *\$cache_time_interval', "\$cache_time_interval = '$cache_time_interval';", $wp_cache_config_file);
       
  1596 	} elseif ( $valid_nonce ) { // clock
       
  1597 		wp_clear_scheduled_hook( 'wp_cache_gc' );
       
  1598 		$cache_schedule_type = 'time';
       
  1599 		if ( $_POST[ 'cache_scheduled_time' ] == '' )
       
  1600 			$_POST[ 'cache_scheduled_time' ] = '00:00';
       
  1601 		$cache_scheduled_time = $_POST[ 'cache_scheduled_time' ];
       
  1602 		$schedules = wp_get_schedules();
       
  1603 		if ( isset( $schedules[ $_POST[ 'cache_schedule_interval' ] ] ) )
       
  1604 			$cache_schedule_interval = $_POST[ 'cache_schedule_interval' ];
       
  1605 		wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
       
  1606 		wp_cache_replace_line('^ *\$cache_schedule_interval', "\$cache_schedule_interval = '{$cache_schedule_interval}';", $wp_cache_config_file);
       
  1607 		wp_cache_replace_line('^ *\$cache_scheduled_time', "\$cache_scheduled_time = '$cache_scheduled_time';", $wp_cache_config_file);
       
  1608 		wp_schedule_event( strtotime( $cache_scheduled_time ), $cache_schedule_interval, 'wp_cache_gc' );
   854 	}
  1609 	}
   855 	?><fieldset class="options"> 
  1610 	?><fieldset class="options"> 
   856 	<a name='expirytime'></a>
  1611 	<a name='expirytime'></a>
   857 	<h3><?php _e( 'Expiry Time &amp; Garbage Collection', 'wp-super-cache' ); ?></h3><?php
  1612 	<h3><?php _e( 'Expiry Time &amp; Garbage Collection', 'wp-super-cache' ); ?></h3><?php
       
  1613 
       
  1614 	?><span id="utc-time"><?php printf(__('<abbr title="Coordinated Universal Time">UTC</abbr> time is <code>%s</code>'), date_i18n($timezone_format, false, 'gmt')); ?></span><?php
       
  1615 	$current_offset = get_option('gmt_offset');
       
  1616 	if ( get_option('timezone_string') || !empty($current_offset) ) {
       
  1617 		?><span id="local-time"><?php printf(__('Local time is <code>%1$s</code>'), date_i18n($timezone_format)); ?></span><?php
       
  1618 	}
       
  1619 	$next_gc = wp_next_scheduled( 'wp_cache_gc' );
       
  1620 	if ( $next_gc )
       
  1621 		echo "<p>" . sprintf( __( 'Next scheduled garbage collection will be at <strong>%s UTC</strong>', 'wp-super-cache' ), date_i18n( $timezone_format, $next_gc, 'gmt' ) ) . "</p>";
       
  1622 
       
  1623 
       
  1624 	if ( $wp_cache_preload_on )
       
  1625 		echo "<p>" . __( 'Warning! <strong>PRELOAD MODE</strong> activated. Supercache files will not be deleted regardless of age.' ) . "</p>";
       
  1626 
       
  1627 	echo "<script type='text/javascript'>";
       
  1628 	echo "jQuery(function () {
       
  1629 		jQuery('#cache_interval_time').click(function () {
       
  1630 			jQuery('#schedule_interval').attr('checked', true);
       
  1631 		});
       
  1632 		jQuery('#cache_scheduled_time').click(function () {
       
  1633 			jQuery('#schedule_time').attr('checked', true);
       
  1634 		});
       
  1635 		jQuery('#cache_scheduled_select').click(function () {
       
  1636 			jQuery('#schedule_time').attr('checked', true);
       
  1637 		});
       
  1638 		});";
       
  1639 	echo "</script>";
   858 	echo '<form name="wp_edit_max_time" action="#expirytime" method="post">';
  1640 	echo '<form name="wp_edit_max_time" action="#expirytime" method="post">';
   859 	echo '<label for="wp_max_time">' . __( 'Expire time:', 'wp-super-cache' ) . '</label> ';
  1641 	echo '<table class="form-table">';
   860 	echo "<input type=\"text\" size=6 name=\"wp_max_time\" value=\"$cache_max_time\" /> " . __( "seconds", 'wp-super-cache' );
  1642 	echo '<tr><td><label for="wp_max_time"><strong>' . __( 'Cache Timeout', 'wp-super-cache' ) . '</strong></label></td>';
   861 	echo "<h4>" . __( 'Garbage Collection', 'wp-super-cache' ) . "</h4><p>" . __( 'If expiry time is more than 1800 seconds (half an hour), garbage collection will be done every 10 minutes, otherwise it will happen 10 seconds after the expiry time above.', 'wp-super-cache' ) . "</p>";
  1643 	echo "<td><input type='text' id='wp_max_time' size=6 name='wp_max_time' value='$cache_max_time' /> " . __( "seconds", 'wp-super-cache' ) . "</td></tr>\n";
   862 	echo "<p>" . __( 'Checking for and deleting expired files is expensive, but it&#8217;s expensive leaving them there too. On a very busy site you should set the expiry time to <em>300 seconds</em>. Experiment with different values and visit this page to see how many expired files remain at different times during the day. Aim to have less than 500 cached files if possible.', 'wp-super-cache' ) . "</p>";
  1644 	echo "<tr><td></td><td>" . __( 'How long should cached pages remain fresh? Set to 0 to disable garbage collection. A good starting point is 3600 seconds.', 'wp-super-cache' ) . "</td></tr>\n";
       
  1645 	echo '<tr><td valign="top"><strong>' . __( 'Scheduler', 'wp-super-cache' ) . '</strong></td><td><table cellpadding=0 cellspacing=0><tr><td valign="top"><input type="radio" id="schedule_interval" name="cache_schedule_type" value="interval" ' . checked( 'interval', $cache_schedule_type, false ) . ' /></td><td valign="top"><label for="cache_interval_time">' . __( 'Timer:', 'wp-super-cache' ) . '</label></td>';
       
  1646 	echo "<td><input type='text' id='cache_interval_time' size=6 name='cache_time_interval' value='$cache_time_interval' /> " . __( "seconds", 'wp-super-cache' ) . '<br />' . __( 'Check for stale cached files every <em>interval</em> seconds.', 'wp-super-cache' ) . "</td></tr>";
       
  1647 	echo '<tr><td valign="top"><input type="radio" id="schedule_time" name="cache_schedule_type" value="time" ' . checked( 'time', $cache_schedule_type, false ) . ' /></td><td valign="top"><label for="schedule_time">' . __( 'Clock:', 'wp-super-cache' ) . '</label></td>';
       
  1648 	echo "<td><input type=\"text\" size=5 id='cache_scheduled_time' name='cache_scheduled_time' value=\"$cache_scheduled_time\" /> " . __( "HH:MM", 'wp-super-cache' ) . "<br />" . __( 'Check for stale cached files at this time <strong>(UTC)</strong> or starting at this time every <em>interval</em> below.', 'wp-super-cache' ) . "</td></tr>";
       
  1649 	$schedules = wp_get_schedules();
       
  1650 	echo "<tr><td><br /></td><td><label for='cache_scheduled_select'>" . __( 'Interval:', 'wp-super-cache' ) . "</label></td><td><select id='cache_scheduled_select' name='cache_schedule_interval' size=1>";
       
  1651 	foreach( $schedules as $desc => $details ) {
       
  1652 		echo "<option value='$desc' " . selected( $desc, $cache_schedule_interval, false ) . " /> {$details[ 'display' ]}</option>";
       
  1653 	}
       
  1654 	echo "</select></td></tr>";
       
  1655 	echo '</table></td></tr>';
       
  1656 	echo '<tr><td><label for="cache_gc_email_me"><strong>' . __( 'Notification Emails', 'wp-super-cache' ) . '</strong></label></td>';
       
  1657 	echo "<td><input type='checkbox' id='cache_gc_email_me' name='cache_gc_email_me' " . checked( $cache_gc_email_me, 1, false ) . " /> " . __( 'Email me when the garbage collection runs.', 'wp-super-cache' ) . "</td></tr>\n";
       
  1658 	echo "</table>\n";
       
  1659 	echo "<h4>" . __( 'Garbage Collection', 'wp-super-cache' ) . "</h4>";
       
  1660 	echo "<ol><li>" . __( '<em>Garbage collection</em> is the simple act of throwing out your garbage. For this plugin that would be old or <em>stale</em> cached files that may be out of date. New cached files are described as <em>fresh</em>.', 'wp-super-cache' ) . "</li>\n";
       
  1661 	echo "<li>" . __( 'Cached files are fresh for a limited length of time. You can set that time in the <em>Cache Timeout</em> text box on this page.', 'wp-super-cache' ) . "</li>\n";
       
  1662 	echo "<li>" . __( 'Stale cached files are not removed as soon as they become stale. They have to be removed by the garbage collecter. That is why you have to tell the plugin when the garbage collector should run.', 'wp-super-cache' ) . "</li>\n";
       
  1663 	echo "<li>" . __( 'Use the <em>Timer</em> or <em>Clock</em> schedulers to define when the garbage collector should run.', 'wp-super-cache' ) . "</li>\n";
       
  1664 	echo "<li>" . __( 'The <em>Timer</em> scheduler tells the plugin to run the garbage collector at regular intervals. When one garbage collection is done, the next run is scheduled.', 'wp-super-cache' ) . "</li>\n";
       
  1665 	echo "<li>" . __( 'Or, the <em>Clock</em> scheduler allows the garbage collection to run at specific times. If set to run hourly or twicedaily the garbage collector will be first scheduled for the time you enter here. It will then run again at the indicated interval. If set to run daily it will run once a day at the time specified.', 'wp-super-cache' ) . "</li>\n";
       
  1666 	echo "</ol>";
       
  1667 	echo "<p>" . __( 'There are no best garbage collection settings but here are a few scenarios. Garbage collection is separate to other actions that clear our cached files like leaving a comment or publishing a post.', 'wp-super-cache' ) . "</p>\n";
       
  1668 	echo "<ol>";
       
  1669 	echo "<li>" . __( 'Sites that want to serve lots of newly generated data should set the <em>Cache Timeout</em> to 60 and use the <em>Timer</em> scheduler set to 90 seconds.', 'wp-super-cache' ) . "</li>\n";
       
  1670 	echo "<li>" . __( 'Sites with widgets and rss feeds in their sidebar should probably use a timeout of 3600 seconds and set the timer to 600 seconds. Stale files will be caught within 10 minutes of going stale.', 'wp-super-cache' ) . "</li>\n";
       
  1671 	echo "<li>" . __( 'Sites with lots of static content, no widgets or rss feeds in their sidebar can use a timeout of 86400 seconds or even more and set the timer to something equally long.', 'wp-super-cache' ) . "</li>\n";
       
  1672 	echo "<li>" . __( 'Sites where an external data source updates at a particular time every day should set the timeout to 86400 seconds and use the Clock scheduler set appropriately.', 'wp-super-cache' ) . "</li>\n";
       
  1673 	echo "</ol>";
       
  1674 	echo "<p>" . __( 'Checking for and deleting expired files is expensive, but it&#8217;s expensive leaving them there too. On a very busy site you should set the expiry time to <em>600 seconds</em>. Experiment with different values and visit this page to see how many expired files remain at different times during the day. If you are using legacy caching aim to have less than 500 cached files if possible. You can have many times more cached files when using mod_rewrite or PHP caching.', 'wp-super-cache' ) . "</p>";
       
  1675 	echo "<p>" . __( 'Set the expiry time to 0 seconds to disable garbage collection.', 'wp-super-cache' ) . "</p>";
   863 	echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Change Expiration', 'wp-super-cache' ) . ' &raquo;" /></div>';
  1676 	echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Change Expiration', 'wp-super-cache' ) . ' &raquo;" /></div>';
   864 	wp_nonce_field('wp-cache');
  1677 	wp_nonce_field('wp-cache');
   865 	echo "</form>\n";
  1678 	echo "</form>\n";
   866 	?></fieldset><?php
  1679 	?></fieldset><?php
   867 }
  1680 }
   868 
  1681 
   869 function wp_cache_sanitize_value($text, & $array) {
  1682 function wp_cache_sanitize_value($text, & $array) {
   870 	$text = wp_specialchars(strip_tags($text));
  1683 	$text = esc_html(strip_tags($text));
   871 	$array = preg_split("/[\s,]+/", chop($text));
  1684 	$array = preg_split("/[\s,]+/", chop($text));
   872 	$text = var_export($array, true);
  1685 	$text = var_export($array, true);
   873 	$text = preg_replace('/[\s]+/', ' ', $text);
  1686 	$text = preg_replace('/[\s]+/', ' ', $text);
   874 	return $text;
  1687 	return $text;
   875 }
  1688 }
   890 }
  1703 }
   891 
  1704 
   892 function wp_cache_edit_rejected_ua() {
  1705 function wp_cache_edit_rejected_ua() {
   893 	global $cache_rejected_user_agent, $wp_cache_config_file, $valid_nonce;
  1706 	global $cache_rejected_user_agent, $wp_cache_config_file, $valid_nonce;
   894 
  1707 
   895 	if (!function_exists('apache_request_headers')) return;
  1708 	if ( !function_exists( 'apache_request_headers' ) ) return;
   896 
  1709 
   897 	if(isset($_REQUEST['wp_rejected_user_agent']) && $valid_nonce) {
  1710 	if ( isset( $_POST[ 'wp_rejected_user_agent' ] ) && $valid_nonce ) {
   898 		$text = wp_cache_sanitize_value($_REQUEST['wp_rejected_user_agent'], $cache_rejected_user_agent);
  1711 		$_POST[ 'wp_rejected_user_agent' ] = str_replace( ' ', '___', $_POST[ 'wp_rejected_user_agent' ] );
   899 		wp_cache_replace_line('^ *\$cache_rejected_user_agent', "\$cache_rejected_user_agent = $text;", $wp_cache_config_file);
  1712 		$text = str_replace( '___', ' ', wp_cache_sanitize_value( $_POST[ 'wp_rejected_user_agent' ], $cache_rejected_user_agent ) );
       
  1713 		wp_cache_replace_line( '^ *\$cache_rejected_user_agent', "\$cache_rejected_user_agent = $text;", $wp_cache_config_file );
       
  1714 		foreach( $cache_rejected_user_agent as $k => $ua ) {
       
  1715 			$cache_rejected_user_agent[ $k ] = str_replace( '___', ' ', $ua );
       
  1716 		}
       
  1717 		reset( $cache_rejected_user_agent );
   900 	}
  1718 	}
   901 
  1719 
   902 	echo '<a name="useragents"></a><fieldset class="options"><h3>' . __( 'Rejected User Agents', 'wp-super-cache' ) . '</h3>';
  1720 	echo '<a name="useragents"></a><fieldset class="options"><h3>' . __( 'Rejected User Agents', 'wp-super-cache' ) . '</h3>';
   903 	echo "<p>" . __( 'Strings in the HTTP &#8217;User Agent&#8217; header that prevent WP-Cache from caching bot, spiders, and crawlers&#8217; requests. Note that super cached files are still sent to these agents if they already exists.', 'wp-super-cache' ) . "</p>\n";
  1721 	echo "<p>" . __( 'Strings in the HTTP &#8217;User Agent&#8217; header that prevent WP-Cache from caching bot, spiders, and crawlers&#8217; requests. Note that super cached files are still sent to these agents if they already exists.', 'wp-super-cache' ) . "</p>\n";
   904 	echo '<form name="wp_edit_rejected_user_agent" action="#useragents" method="post">';
  1722 	echo '<form name="wp_edit_rejected_user_agent" action="#useragents" method="post">';
   905 	echo '<textarea name="wp_rejected_user_agent" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
  1723 	echo '<textarea name="wp_rejected_user_agent" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
   906 	foreach ($cache_rejected_user_agent as $ua) {
  1724 	foreach( $cache_rejected_user_agent as $ua ) {
   907 		echo wp_specialchars($ua) . "\n";
  1725 		echo esc_html( $ua ) . "\n";
   908 	}
  1726 	}
   909 	echo '</textarea> ';
  1727 	echo '</textarea> ';
   910 	echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save UA Strings', 'wp-super-cache' ) . ' &raquo;" /></div>';
  1728 	echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save UA Strings', 'wp-super-cache' ) . ' &raquo;" /></div>';
   911 	wp_nonce_field('wp-cache');
  1729 	wp_nonce_field('wp-cache');
   912 	echo '</form>';
  1730 	echo '</form>';
   915 
  1733 
   916 function wp_cache_edit_rejected_pages() {
  1734 function wp_cache_edit_rejected_pages() {
   917 	global $wp_cache_config_file, $valid_nonce, $wp_cache_pages;
  1735 	global $wp_cache_config_file, $valid_nonce, $wp_cache_pages;
   918 
  1736 
   919 	if ( isset( $_POST[ 'wp_edit_rejected_pages' ] ) && $valid_nonce ) {
  1737 	if ( isset( $_POST[ 'wp_edit_rejected_pages' ] ) && $valid_nonce ) {
   920 		$pages = array( 'single', 'pages', 'archives', 'tag', 'frontpage', 'home', 'category', 'feed', 'search' );
  1738 		$pages = array( 'single', 'pages', 'archives', 'tag', 'frontpage', 'home', 'category', 'feed', 'author', 'search' );
   921 		foreach( $pages as $page ) {
  1739 		foreach( $pages as $page ) {
   922 			if ( isset( $_POST[ 'wp_cache_pages' ][ $page ] ) ) {
  1740 			if ( isset( $_POST[ 'wp_cache_pages' ][ $page ] ) ) {
   923 				$value = 1;
  1741 				$value = 1;
   924 			} else {
  1742 			} else {
   925 				$value = 0;
  1743 				$value = 0;
   940 	echo '<label><input type="checkbox" value="1" name="wp_cache_pages[archives]" ' . checked( 1, $wp_cache_pages[ 'archives' ], false ) . ' /> ' . __( 'Archives', 'wp-super-cache' ) . ' (is_archive)</label><br />';
  1758 	echo '<label><input type="checkbox" value="1" name="wp_cache_pages[archives]" ' . checked( 1, $wp_cache_pages[ 'archives' ], false ) . ' /> ' . __( 'Archives', 'wp-super-cache' ) . ' (is_archive)</label><br />';
   941 	echo '&nbsp;&nbsp;<label><input type="checkbox" value="1" name="wp_cache_pages[tag]" ' . checked( 1, $wp_cache_pages[ 'tag' ], false ) . ' /> ' . __( 'Tags', 'wp-super-cache' ) . ' (is_tag)</label><br />';
  1759 	echo '&nbsp;&nbsp;<label><input type="checkbox" value="1" name="wp_cache_pages[tag]" ' . checked( 1, $wp_cache_pages[ 'tag' ], false ) . ' /> ' . __( 'Tags', 'wp-super-cache' ) . ' (is_tag)</label><br />';
   942 	echo '&nbsp;&nbsp;<label><input type="checkbox" value="1" name="wp_cache_pages[category]" ' . checked( 1, $wp_cache_pages[ 'category' ], false ) . ' /> ' . __( 'Category', 'wp-super-cache' ) . ' (is_category)</label><br />';
  1760 	echo '&nbsp;&nbsp;<label><input type="checkbox" value="1" name="wp_cache_pages[category]" ' . checked( 1, $wp_cache_pages[ 'category' ], false ) . ' /> ' . __( 'Category', 'wp-super-cache' ) . ' (is_category)</label><br />';
   943 	echo '<label><input type="checkbox" value="1" name="wp_cache_pages[feed]" ' . checked( 1, $wp_cache_pages[ 'feed' ], false ) . ' /> ' . __( 'Feeds', 'wp-super-cache' ) . ' (is_feed)</label><br />';
  1761 	echo '<label><input type="checkbox" value="1" name="wp_cache_pages[feed]" ' . checked( 1, $wp_cache_pages[ 'feed' ], false ) . ' /> ' . __( 'Feeds', 'wp-super-cache' ) . ' (is_feed)</label><br />';
   944 	echo '<label><input type="checkbox" value="1" name="wp_cache_pages[search]" ' . checked( 1, $wp_cache_pages[ 'search' ], false ) . ' /> ' . __( 'Search Pages', 'wp-super-cache' ) . ' (is_search)</label><br />';
  1762 	echo '<label><input type="checkbox" value="1" name="wp_cache_pages[search]" ' . checked( 1, $wp_cache_pages[ 'search' ], false ) . ' /> ' . __( 'Search Pages', 'wp-super-cache' ) . ' (is_search)</label><br />';
       
  1763 	echo '<label><input type="checkbox" value="1" name="wp_cache_pages[author]" ' . checked( 1, $wp_cache_pages[ 'author' ], false ) . ' /> ' . __( 'Author Pages', 'wp-super-cache' ) . ' (is_author)</label><br />';
   945 
  1764 
   946 	echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save' ) . ' &raquo;" /></div>';
  1765 	echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save' ) . ' &raquo;" /></div>';
   947 	wp_nonce_field('wp-cache');
  1766 	wp_nonce_field('wp-cache');
   948 	echo "</form>\n";
  1767 	echo "</form>\n";
   949 
  1768 
   961 	echo '<a name="rejecturi"></a>';
  1780 	echo '<a name="rejecturi"></a>';
   962 	echo '<form name="wp_edit_rejected" action="#rejecturi" method="post">';
  1781 	echo '<form name="wp_edit_rejected" action="#rejecturi" method="post">';
   963 	echo "<p>" . __( '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&#8217;s enough to specify the year, i.e. &#8217;/2004/&#8217;. WP-Cache will search if that string is part of the URI and if so, it will not cache that page.', 'wp-super-cache' ) . "</p>\n";
  1782 	echo "<p>" . __( '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&#8217;s enough to specify the year, i.e. &#8217;/2004/&#8217;. WP-Cache will search if that string is part of the URI and if so, it will not cache that page.', 'wp-super-cache' ) . "</p>\n";
   964 	echo '<textarea name="wp_rejected_uri" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
  1783 	echo '<textarea name="wp_rejected_uri" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
   965 	foreach ($cache_rejected_uri as $file) {
  1784 	foreach ($cache_rejected_uri as $file) {
   966 		echo wp_specialchars( $file ) . "\n";
  1785 		echo esc_html( $file ) . "\n";
   967 	}
  1786 	}
   968 	echo '</textarea> ';
  1787 	echo '</textarea> ';
   969 	echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save Strings', 'wp-super-cache' ) . ' &raquo;" /></div>';
  1788 	echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save Strings', 'wp-super-cache' ) . ' &raquo;" /></div>';
   970 	wp_nonce_field('wp-cache');
  1789 	wp_nonce_field('wp-cache');
   971 	echo "</form>\n";
  1790 	echo "</form>\n";
   983 	echo '<a name="cancache"></a>';
  1802 	echo '<a name="cancache"></a>';
   984 	echo '<div style="clear:both"></div><form name="wp_edit_accepted" action="#cancache" method="post">';
  1803 	echo '<div style="clear:both"></div><form name="wp_edit_accepted" action="#cancache" method="post">';
   985 	echo "<p>" . __( 'Add here those filenames that can be cached, even if they match one of the rejected substring specified above.', 'wp-super-cache' ) . "</p>\n";
  1804 	echo "<p>" . __( 'Add here those filenames that can be cached, even if they match one of the rejected substring specified above.', 'wp-super-cache' ) . "</p>\n";
   986 	echo '<textarea name="wp_accepted_files" cols="40" rows="8" style="width: 50%; font-size: 12px;" class="code">';
  1805 	echo '<textarea name="wp_accepted_files" cols="40" rows="8" style="width: 50%; font-size: 12px;" class="code">';
   987 	foreach ($cache_acceptable_files as $file) {
  1806 	foreach ($cache_acceptable_files as $file) {
   988 		echo wp_specialchars($file) . "\n";
  1807 		echo esc_html($file) . "\n";
   989 	}
  1808 	}
   990 	echo '</textarea> ';
  1809 	echo '</textarea> ';
   991 	echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save Files', 'wp-super-cache' ) . ' &raquo;" /></div>';
  1810 	echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save Files', 'wp-super-cache' ) . ' &raquo;" /></div>';
   992 	wp_nonce_field('wp-cache');
  1811 	wp_nonce_field('wp-cache');
   993 	echo "</form>\n";
  1812 	echo "</form>\n";
   994 }
  1813 }
   995 
  1814 
   996 function wp_cache_debug_settings() {
  1815 function wp_cache_debug_settings() {
   997 	global $wp_super_cache_debug, $wp_cache_debug_email, $wp_cache_debug_log, $wp_cache_debug_level, $wp_cache_debug_ip, $cache_path, $valid_nonce, $wp_cache_config_file, $wp_cache_debug_to_file;
  1816 	global $wp_super_cache_debug, $wp_cache_debug_log, $wp_cache_debug_ip, $cache_path, $valid_nonce, $wp_cache_config_file, $wp_super_cache_comments;
   998 	global $wp_super_cache_front_page_check, $wp_super_cache_front_page_clear, $wp_super_cache_front_page_text, $wp_super_cache_front_page_notification, $wp_super_cache_advanced_debug;
  1817 	global $wp_super_cache_front_page_check, $wp_super_cache_front_page_clear, $wp_super_cache_front_page_text, $wp_super_cache_front_page_notification, $wp_super_cache_advanced_debug;
   999 
  1818 
  1000 	if ( !isset( $wp_cache_debug_level ) )
  1819 	if ( false == isset( $wp_super_cache_comments ) )
  1001 		$wp_cache_debug_level = 1;
  1820 		$wp_super_cache_comments = 1;
  1002 	if ( isset( $_POST[ 'wp_cache_debug' ] ) && $valid_nonce ) {
  1821 	if ( isset( $_POST[ 'wp_cache_debug' ] ) && $valid_nonce ) {
  1003 		$wp_super_cache_debug = intval( $_POST[ 'wp_super_cache_debug' ] );
  1822 		$wp_super_cache_debug = intval( $_POST[ 'wp_super_cache_debug' ] );
  1004 		wp_cache_replace_line('^ *\$wp_super_cache_debug', "\$wp_super_cache_debug = '$wp_super_cache_debug';", $wp_cache_config_file);
  1823 		wp_cache_replace_line('^ *\$wp_super_cache_debug', "\$wp_super_cache_debug = '$wp_super_cache_debug';", $wp_cache_config_file);
  1005 		$wp_cache_debug_email = wp_specialchars( $_POST[ 'wp_cache_debug_email' ] );
  1824 		if ( $wp_super_cache_debug && ( ( isset( $wp_cache_debug_log ) && $wp_cache_debug_log == '' ) || !isset( $wp_cache_debug_log ) ) ) {
  1006 		wp_cache_replace_line('^ *\$wp_cache_debug_email', "\$wp_cache_debug_email = '$wp_cache_debug_email';", $wp_cache_config_file);
       
  1007 		$wp_cache_debug_to_file = intval( $_POST[ 'wp_cache_debug_to_file' ] );
       
  1008 		if ( $wp_cache_debug_to_file && ( ( isset( $wp_cache_debug_log ) && $wp_cache_debug_log == '' ) || !isset( $wp_cache_debug_log ) ) ) {
       
  1009 			$wp_cache_debug_log = md5( time() ) . ".txt";
  1825 			$wp_cache_debug_log = md5( time() ) . ".txt";
  1010 		} elseif( $wp_cache_debug_to_file == false ) {
  1826 		} else {
  1011 			$wp_cache_debug_log = "";
  1827 			$wp_cache_debug_log = "";
  1012 		}
  1828 		}
  1013 		wp_cache_replace_line('^ *\$wp_cache_debug_to_file', "\$wp_cache_debug_to_file = '$wp_cache_debug_to_file';", $wp_cache_config_file);
       
  1014 		wp_cache_replace_line('^ *\$wp_cache_debug_log', "\$wp_cache_debug_log = '$wp_cache_debug_log';", $wp_cache_config_file);
  1829 		wp_cache_replace_line('^ *\$wp_cache_debug_log', "\$wp_cache_debug_log = '$wp_cache_debug_log';", $wp_cache_config_file);
  1015 		$wp_cache_debug_ip = wp_specialchars( $_POST[ 'wp_cache_debug_ip' ] );
  1830 		$wp_super_cache_comments = (int)$_POST[ 'wp_super_cache_comments' ];
       
  1831 		wp_cache_replace_line('^ *\$wp_super_cache_comments', "\$wp_super_cache_comments = '$wp_super_cache_comments';", $wp_cache_config_file);
       
  1832 		$wp_cache_debug_ip = esc_html( $_POST[ 'wp_cache_debug_ip' ] );
  1016 		wp_cache_replace_line('^ *\$wp_cache_debug_ip', "\$wp_cache_debug_ip = '$wp_cache_debug_ip';", $wp_cache_config_file);
  1833 		wp_cache_replace_line('^ *\$wp_cache_debug_ip', "\$wp_cache_debug_ip = '$wp_cache_debug_ip';", $wp_cache_config_file);
  1017 		$wp_cache_debug_level = (int)$_POST[ 'wp_cache_debug_level' ];
       
  1018 		wp_cache_replace_line('^ *\$wp_cache_debug_level', "\$wp_cache_debug_level = '$wp_cache_debug_level';", $wp_cache_config_file);
       
  1019 		$wp_super_cache_front_page_check = (int)$_POST[ 'wp_super_cache_front_page_check' ];
  1834 		$wp_super_cache_front_page_check = (int)$_POST[ 'wp_super_cache_front_page_check' ];
  1020 		wp_cache_replace_line('^ *\$wp_super_cache_front_page_check', "\$wp_super_cache_front_page_check = '$wp_super_cache_front_page_check';", $wp_cache_config_file);
  1835 		wp_cache_replace_line('^ *\$wp_super_cache_front_page_check', "\$wp_super_cache_front_page_check = '$wp_super_cache_front_page_check';", $wp_cache_config_file);
  1021 		$wp_super_cache_front_page_clear = (int)$_POST[ 'wp_super_cache_front_page_clear' ];
  1836 		$wp_super_cache_front_page_clear = (int)$_POST[ 'wp_super_cache_front_page_clear' ];
  1022 		wp_cache_replace_line('^ *\$wp_super_cache_front_page_clear', "\$wp_super_cache_front_page_clear = '$wp_super_cache_front_page_clear';", $wp_cache_config_file);
  1837 		wp_cache_replace_line('^ *\$wp_super_cache_front_page_clear', "\$wp_super_cache_front_page_clear = '$wp_super_cache_front_page_clear';", $wp_cache_config_file);
  1023 		$wp_super_cache_front_page_text = wp_specialchars( $_POST[ 'wp_super_cache_front_page_text' ] );
  1838 		$wp_super_cache_front_page_text = esc_html( $_POST[ 'wp_super_cache_front_page_text' ] );
  1024 		wp_cache_replace_line('^ *\$wp_super_cache_front_page_text', "\$wp_super_cache_front_page_text = '$wp_super_cache_front_page_text';", $wp_cache_config_file);
  1839 		wp_cache_replace_line('^ *\$wp_super_cache_front_page_text', "\$wp_super_cache_front_page_text = '$wp_super_cache_front_page_text';", $wp_cache_config_file);
  1025 		$wp_super_cache_front_page_notification = (int)$_POST[ 'wp_super_cache_front_page_notification' ];
  1840 		$wp_super_cache_front_page_notification = (int)$_POST[ 'wp_super_cache_front_page_notification' ];
  1026 		wp_cache_replace_line('^ *\$wp_super_cache_front_page_notification', "\$wp_super_cache_front_page_notification = '$wp_super_cache_front_page_notification';", $wp_cache_config_file);
  1841 		wp_cache_replace_line('^ *\$wp_super_cache_front_page_notification', "\$wp_super_cache_front_page_notification = '$wp_super_cache_front_page_notification';", $wp_cache_config_file);
  1027 		if ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 1 && !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
  1842 		if ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 1 && !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
  1028 			wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
  1843 			wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
  1030 		}
  1845 		}
  1031 	}
  1846 	}
  1032 
  1847 
  1033 	echo '<a name="debug"></a>';
  1848 	echo '<a name="debug"></a>';
  1034 	echo '<fieldset class="options">';
  1849 	echo '<fieldset class="options">';
  1035 	echo "<h3>" . __( 'Debug Settings', 'wp-super-cache' ) . "</h3>";
  1850 	if ( isset( $wp_cache_debug_log ) && $wp_cache_debug_log != '' )
  1036 	if ( ( isset( $wp_cache_debug_log ) && $wp_cache_debug_log != '' ) || ( isset( $wp_cache_debug_email ) && $wp_cache_debug_email != '' ) ) {
  1851 		echo "<p>" . sprintf( __( 'Currently logging to: %s', 'wp-super-cache' ), "<a href='" . site_url( str_replace( ABSPATH, '', "{$cache_path}{$wp_cache_debug_log}" ) ) . "'>$cache_path{$wp_cache_debug_log}</a>" ) . "</p>";
  1037 		echo "<p>" . __( 'Currently logging to: ', 'wp-super-cache' );
  1852 
  1038 		if ( isset( $wp_cache_debug_log ) && $wp_cache_debug_log != '' ) {
  1853 
  1039 			$url = str_replace( ABSPATH, '', "{$cache_path}{$wp_cache_debug_log}" );
  1854 	echo '<p>' . __( 'Fix problems with the plugin by debugging it here. It can log them to a file in your cache directory.', 'wp-super-cache' ) . '</p>';
  1040 			echo "<a href='" . site_url( $url ) . "'>$cache_path{$wp_cache_debug_log}</a> ";
  1855 	echo '<div style="clear:both"></div><form name="wp_cache_debug" action="" method="post">';
  1041 
       
  1042 		}
       
  1043 		if ( isset( $wp_cache_debug_email ) )
       
  1044 			echo " $wp_cache_debug_email ";
       
  1045 		echo "</p>";
       
  1046 	}
       
  1047 	echo '<p>' . __( 'Fix problems with the plugin by debugging it here. It can send you debug emails or log them to a file in your cache directory.', 'wp-super-cache' ) . '</p>';
       
  1048 	echo '<p>' . __( 'Logging to a file is easier but faces the problem that clearing the cache will clear the log file.', 'wp-super-cache' ) . '</p>';
       
  1049 	echo '<div style="clear:both"></div><form name="wp_cache_debug" action="#debug" method="post">';
       
  1050 	echo "<input type='hidden' name='wp_cache_debug' value='1' /><br />";
  1856 	echo "<input type='hidden' name='wp_cache_debug' value='1' /><br />";
  1051 	echo "<table class='form-table'>";
  1857 	echo "<table class='form-table'>";
  1052 	echo "<tr><td>" . __( 'Debugging', 'wp-super-cache' ) . "</td><td><input type='checkbox' name='wp_super_cache_debug' value='1' " . checked( 1, $wp_super_cache_debug, false ) . " /> " . __( 'enabled', 'wp-super-cache' ) . "</td></tr>";
  1858 	echo "<tr><td>" . __( 'Debugging', 'wp-super-cache' ) . "</td><td><input type='checkbox' name='wp_super_cache_debug' value='1' " . checked( 1, $wp_super_cache_debug, false ) . " /> " . __( 'enabled', 'wp-super-cache' ) . "</td></tr>";
  1053 	echo "<tr><td valign='top' rowspan='2'>" . __( 'Logging Type', 'wp-super-cache' ) . "</td><td> " . __( 'Email', 'wp-super-cache' ) . ": <input type='text' size='30' name='wp_cache_debug_email' value='{$wp_cache_debug_email}' /></td></tr>";
       
  1054 	echo "<tr><td><input type='checkbox' name='wp_cache_debug_to_file' value='1' " . checked( 1, $wp_cache_debug_to_file, false ) . " /> " . __( 'file', 'wp-super-cache' ) . "</td></tr>";
       
  1055 	echo "<tr><td>" . __( 'IP Address', 'wp-super-cache' ) . "</td><td> <input type='text' size='20' name='wp_cache_debug_ip' value='{$wp_cache_debug_ip}' /> " . sprintf( __( '(only log requests from this IP address. Your IP is %s)', 'wp-super-cache' ), $_SERVER[ 'REMOTE_ADDR' ] ) . "</td></tr>";
  1859 	echo "<tr><td>" . __( 'IP Address', 'wp-super-cache' ) . "</td><td> <input type='text' size='20' name='wp_cache_debug_ip' value='{$wp_cache_debug_ip}' /> " . sprintf( __( '(only log requests from this IP address. Your IP is %s)', 'wp-super-cache' ), $_SERVER[ 'REMOTE_ADDR' ] ) . "</td></tr>";
  1056 	echo "<tr><td>" . __( 'Log level', 'wp-super-cache' ) . "</td><td> ";
  1860 	echo "<tr><td valign='top'>" . __( 'Cache Status Messages', 'wp-super-cache' ) . "</td><td><input type='checkbox' name='wp_super_cache_comments' value='1' " . checked( 1, $wp_super_cache_comments, false ) . " /> " . __( 'enabled', 'wp-super-cache' ) . "<br />";
  1057 	for( $t = 1; $t <= 5; $t++ ) {
  1861 	echo  __( 'Display comments at the end of every page like this:', 'wp-super-cache' ) . "<br />";
  1058 		echo "<input type='radio' name='wp_cache_debug_level' value='$t' ";
  1862 	echo "<pre>&lt;!-- Dynamic page generated in 0.450 seconds. -->
  1059 		echo $wp_cache_debug_level == $t ? "checked='checked' " : '';
  1863 &lt;!-- Cached page generated by WP-Super-Cache on " . date( "Y-m-d H:i:s", time() ) . " -->
  1060 		echo "/> $t ";
  1864 &lt;!-- super cache --></pre></td></tr>";
  1061 	}
       
  1062 	echo " " . __( '(1 = less, 5 = more, may cause severe server load.)', 'wp-super-cache' ) . "</td></tr>";
       
  1063 	echo "</table>\n";
  1865 	echo "</table>\n";
  1064 	if ( isset( $wp_super_cache_advanced_debug ) ) {
  1866 	if ( isset( $wp_super_cache_advanced_debug ) ) {
  1065 	echo "<h4>" . __( 'Advanced', 'wp-super-cache' ) . "</h4><p>" . __( 'In very rare cases two problems may arise on some blogs:<ol><li> The front page may start downloading as a zip file.</li><li> The wrong page is occasionally cached as the front page if your blog uses a static front page and the permalink structure is <em>/%category%/%postname%/</em>.</li></ol>', 'wp-super-cache' ) . '</p>';
  1867 	echo "<h4>" . __( 'Advanced', 'wp-super-cache' ) . "</h4><p>" . __( 'In very rare cases two problems may arise on some blogs:<ol><li> The front page may start downloading as a zip file.</li><li> The wrong page is occasionally cached as the front page if your blog uses a static front page and the permalink structure is <em>/%category%/%postname%/</em>.</li></ol>', 'wp-super-cache' ) . '</p>';
  1066 	echo "<p>" . __( 'I&#8217;m 99% certain that they aren&#8217;t bugs in WP Super Cache and they only happen in very rare cases but you can run a simple check once every 5 minutes to verify that your site is ok if you&#8217;re worried. You will be emailed if there is a problem.', 'wp-super-cache' ) . "</p>";
  1868 	echo "<p>" . __( 'I&#8217;m 99% certain that they aren&#8217;t bugs in WP Super Cache and they only happen in very rare cases but you can run a simple check once every 5 minutes to verify that your site is ok if you&#8217;re worried. You will be emailed if there is a problem.', 'wp-super-cache' ) . "</p>";
  1067 	echo "<table class='form-table'>";
  1869 	echo "<table class='form-table'>";
  1092 }
  1894 }
  1093 
  1895 
  1094 function wp_cache_disable() {
  1896 function wp_cache_disable() {
  1095 	global $wp_cache_config_file, $cache_enabled;
  1897 	global $wp_cache_config_file, $cache_enabled;
  1096 
  1898 
       
  1899 	wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
       
  1900 	wp_clear_scheduled_hook( 'wp_cache_gc' );
       
  1901 	wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
  1097 	if (wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file)) {
  1902 	if (wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file)) {
  1098 		$cache_enabled = false;
  1903 		$cache_enabled = false;
  1099 	}
  1904 	}
  1100 	wp_super_cache_disable();
       
  1101 }
  1905 }
  1102 function wp_super_cache_enable() {
  1906 function wp_super_cache_enable() {
  1103 	global $supercachedir, $wp_cache_config_file, $super_cache_enabled;
  1907 	global $supercachedir, $wp_cache_config_file, $super_cache_enabled;
  1104 
  1908 
  1105 	if( is_dir( $supercachedir . ".disabled" ) )
  1909 	if( is_dir( $supercachedir . ".disabled" ) )
  1128 
  1932 
  1129 function wp_cache_is_enabled() {
  1933 function wp_cache_is_enabled() {
  1130 	global $wp_cache_config_file;
  1934 	global $wp_cache_config_file;
  1131 
  1935 
  1132 	if(get_option('gzipcompression')) {
  1936 	if(get_option('gzipcompression')) {
  1133 		echo "<strong>" . __( 'Warning', 'wp-super-cache' ) . "</strong>: " . __( "GZIP compression is enabled in Wordpress, wp-cache will be bypassed until you disable gzip compression.", 'wp-super-cache' );
  1937 		echo "<strong>" . __( 'Warning', 'wp-super-cache' ) . "</strong>: " . __( "GZIP compression is enabled in WordPress, wp-cache will be bypassed until you disable gzip compression.", 'wp-super-cache' );
  1134 		return false;
  1938 		return false;
  1135 	}
  1939 	}
  1136 	$lines = file($wp_cache_config_file);
  1940 	$lines = file($wp_cache_config_file);
  1137 	foreach($lines as $line) {
  1941 	foreach($lines as $line) {
  1138 	 	if (preg_match('/^ *\$cache_enabled *= *true *;/', $line))
  1942 	 	if (preg_match('/^ *\$cache_enabled *= *true *;/', $line))
  1141 	return false;
  1945 	return false;
  1142 }
  1946 }
  1143 
  1947 
  1144 
  1948 
  1145 function wp_cache_replace_line($old, $new, $my_file) {
  1949 function wp_cache_replace_line($old, $new, $my_file) {
       
  1950 	if ( @is_file( $my_file ) == false ) {
       
  1951 		return false;
       
  1952 	}
  1146 	if (!is_writeable_ACLSafe($my_file)) {
  1953 	if (!is_writeable_ACLSafe($my_file)) {
  1147 		echo "Error: file $my_file is not writable.\n";
  1954 		echo "Error: file $my_file is not writable.\n";
  1148 		return false;
  1955 		return false;
  1149 	}
  1956 	}
       
  1957 
  1150 	$found = false;
  1958 	$found = false;
  1151 	$lines = file($my_file);
  1959 	$lines = file($my_file);
  1152 	foreach($lines as $line) {
  1960 	foreach( (array)$lines as $line ) {
  1153 	 	if ( preg_match("/$old/", $line)) {
  1961 	 	if ( preg_match("/$old/", $line)) {
  1154 			$found = true;
  1962 			$found = true;
  1155 			break;
  1963 			break;
  1156 		}
  1964 		}
  1157 	}
  1965 	}
  1158 	if ($found) {
  1966 	if ($found) {
  1159 		$fd = fopen($my_file, 'w');
  1967 		$fd = fopen($my_file, 'w');
  1160 		foreach($lines as $line) {
  1968 		foreach( (array)$lines as $line ) {
  1161 			if ( !preg_match("/$old/", $line))
  1969 			if ( !preg_match("/$old/", $line))
  1162 				fputs($fd, $line);
  1970 				fputs($fd, $line);
  1163 			else {
  1971 			else {
  1164 				fputs($fd, "$new //Added by WP-Cache Manager\n");
  1972 				fputs($fd, "$new //Added by WP-Cache Manager\n");
  1165 			}
  1973 			}
  1167 		fclose($fd);
  1975 		fclose($fd);
  1168 		return true;
  1976 		return true;
  1169 	}
  1977 	}
  1170 	$fd = fopen($my_file, 'w');
  1978 	$fd = fopen($my_file, 'w');
  1171 	$done = false;
  1979 	$done = false;
  1172 	foreach($lines as $line) {
  1980 	foreach( (array)$lines as $line ) {
  1173 		if ( $done || !preg_match('/^(if\ \(\ \!\ )?define|\$|\?>/', $line) ) {
  1981 		if ( $done || !preg_match('/^(if\ \(\ \!\ )?define|\$|\?>/', $line) ) {
  1174 			fputs($fd, $line);
  1982 			fputs($fd, $line);
  1175 		} else {
  1983 		} else {
  1176 			fputs($fd, "$new //Added by WP-Cache Manager\n");
  1984 			fputs($fd, "$new //Added by WP-Cache Manager\n");
  1177 			fputs($fd, $line);
  1985 			fputs($fd, $line);
  1186 	global $cache_path, $blog_cache_dir, $blogcacheid;
  1994 	global $cache_path, $blog_cache_dir, $blogcacheid;
  1187 
  1995 
  1188 	$dir = dirname($cache_path);
  1996 	$dir = dirname($cache_path);
  1189 	if ( !file_exists($cache_path) ) {
  1997 	if ( !file_exists($cache_path) ) {
  1190 		if ( !is_writeable_ACLSafe( $dir ) || !($dir = mkdir( $cache_path ) ) ) {
  1998 		if ( !is_writeable_ACLSafe( $dir ) || !($dir = mkdir( $cache_path ) ) ) {
  1191 				echo "<strong>" . __( 'Error', 'wp-super-cache' ) . ":</strong> " . sprintf( __( 'Your cache directory (<strong>$cache_path</strong>) did not exist and couldn&#8217;t be created by the web server. Check %s permissions.', 'wp-super-cache' ), $dir );
  1999 				echo "<strong>" . __( 'Error', 'wp-super-cache' ) . ":</strong> " . sprintf( __( 'Your cache directory (<strong>%1$s</strong>) did not exist and couldn&#8217;t be created by the web server. Check %1$s permissions.', 'wp-super-cache' ), $dir );
  1192 				return false;
  2000 				return false;
  1193 		}
  2001 		}
  1194 	}
  2002 	}
  1195 	if ( !is_writeable_ACLSafe($cache_path)) {
  2003 	if ( !is_writeable_ACLSafe($cache_path)) {
  1196 		echo "<strong>" . __( 'Error', 'wp-super-cache' ) . ":</strong> " . sprintf( __( 'Your cache directory (<strong>%1$s</strong>) or <strong>%2$s</strong> need to be writable for this plugin to work. Double-check it.', 'wp-super-cache' ), $cache_path, $dir );
  2004 		echo "<strong>" . __( 'Error', 'wp-super-cache' ) . ":</strong> " . sprintf( __( 'Your cache directory (<strong>%1$s</strong>) or <strong>%2$s</strong> need to be writable for this plugin to work. Double-check it.', 'wp-super-cache' ), $cache_path, $dir );
  1213 	return true;
  2021 	return true;
  1214 }
  2022 }
  1215 
  2023 
  1216 function wp_cache_verify_config_file() {
  2024 function wp_cache_verify_config_file() {
  1217 	global $wp_cache_config_file, $wp_cache_config_file_sample, $sem_id, $cache_path;
  2025 	global $wp_cache_config_file, $wp_cache_config_file_sample, $sem_id, $cache_path;
       
  2026 	global $WPSC_HTTP_HOST;
  1218 
  2027 
  1219 	$new = false;
  2028 	$new = false;
  1220 	$dir = dirname($wp_cache_config_file);
  2029 	$dir = dirname($wp_cache_config_file);
  1221 
  2030 
  1222 	if ( file_exists($wp_cache_config_file) ) {
  2031 	if ( file_exists($wp_cache_config_file) ) {
  1247 			wp_cache_replace_line('define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/wp-super-cache/\" );", $wp_cache_config_file);
  2056 			wp_cache_replace_line('define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/wp-super-cache/\" );", $wp_cache_config_file);
  1248 		}
  2057 		}
  1249 		$new = true;
  2058 		$new = true;
  1250 	}
  2059 	}
  1251 	if( $sem_id == 5419 && $cache_path != '' ) {
  2060 	if( $sem_id == 5419 && $cache_path != '' ) {
  1252 		$sem_id = crc32( $_SERVER[ 'HTTP_HOST' ] . $cache_path ) & 0x7fffffff;
  2061 		$sem_id = crc32( $WPSC_HTTP_HOST . $cache_path ) & 0x7fffffff;
  1253 		wp_cache_replace_line('sem_id', '$sem_id = ' . $sem_id . ';', $wp_cache_config_file);
  2062 		wp_cache_replace_line('sem_id', '$sem_id = ' . $sem_id . ';', $wp_cache_config_file);
  1254 	}
  2063 	}
  1255 	require($wp_cache_config_file);
  2064 	require($wp_cache_config_file);
  1256 	return true;
  2065 	return true;
  1257 }
  2066 }
  1258 
  2067 
  1259 function wp_cache_create_advanced_cache() {
  2068 function wp_cache_create_advanced_cache() {
  1260 	global $wp_cache_link, $wp_cache_file;
  2069 	global $wp_cache_link, $wp_cache_file;
       
  2070 	if ( file_exists( ABSPATH . 'wp-config.php') ) {
       
  2071 		$global_config_file = ABSPATH . 'wp-config.php';
       
  2072 	} else {
       
  2073 		$global_config_file = dirname(ABSPATH) . '/wp-config.php';
       
  2074 	}
       
  2075 
       
  2076 	$line = 'define( \'WPCACHEHOME\', \'' . constant( 'WPCACHEHOME' ) . '\' );';
       
  2077 	if ( !is_writeable_ACLSafe($global_config_file) || !wp_cache_replace_line('define *\( *\'WPCACHEHOME\'', $line, $global_config_file ) ) {
       
  2078 			echo '<div id="message" class="updated fade"><h3>' . __( 'Warning', 'wp-super-cache' ) . "! <em>" . sprintf( __( 'Could not update %s!</em> WPCACHEHOME must be set in config file.', 'wp-super-cache' ), $global_config_file ) . "</h3>";
       
  2079 			return false;
       
  2080 	}
  1261 	$ret = true;
  2081 	$ret = true;
  1262 
  2082 
  1263 	$file = file_get_contents( $wp_cache_file );
  2083 	$file = file_get_contents( $wp_cache_file );
  1264 	$file = str_replace( 'CACHEHOME', constant( 'WPCACHEHOME' ), $file );
       
  1265 	$fp = @fopen( $wp_cache_link, 'w' );
  2084 	$fp = @fopen( $wp_cache_link, 'w' );
  1266 	if( $fp ) {
  2085 	if( $fp ) {
  1267 		fputs( $fp, $file );
  2086 		fputs( $fp, $file );
  1268 		fclose( $fp );
  2087 		fclose( $fp );
  1269 	} else {
  2088 	} else {
  1276 	global $wp_cache_link, $wp_cache_file;
  2095 	global $wp_cache_link, $wp_cache_file;
  1277  
  2096  
  1278  	$ret = true;
  2097  	$ret = true;
  1279 	if( file_exists($wp_cache_link) ) {
  2098 	if( file_exists($wp_cache_link) ) {
  1280 		$file = file_get_contents( $wp_cache_link );
  2099 		$file = file_get_contents( $wp_cache_link );
  1281 		if( strpos( $file, "WP SUPER CACHE 0.8.9.1" ) ) {
  2100 		if( strpos( $file, "WP SUPER CACHE 0.8.9.1" ) || strpos( $file, "WP SUPER CACHE 1.2" ) ) {
  1282 			return true;
  2101 			return true;
  1283 		} else {
  2102 		} else {
  1284 			if( !@unlink($wp_cache_link) ) {
  2103 			if( !@unlink($wp_cache_link) ) {
  1285 				$ret = false;
  2104 				$ret = false;
  1286 			} else {
  2105 			} else {
  1290 	} else {
  2109 	} else {
  1291 		$ret = wp_cache_create_advanced_cache();
  2110 		$ret = wp_cache_create_advanced_cache();
  1292 	}
  2111 	}
  1293 
  2112 
  1294 	if( false == $ret ) {
  2113 	if( false == $ret ) {
  1295 		echo "<h3>" . __( 'Warning', 'wp-super-cache' ) . "! <em>" . sprintf( __( '%s/advanced-cache.php</em> does not exist or cannot be updated.', 'wp-super-cache' ), WP_CONTENT_DIR ) . "</h3>";
  2114 		echo '<div id="message" class="updated fade"><h3>' . __( 'Warning', 'wp-super-cache' ) . "! <em>" . sprintf( __( '%s/advanced-cache.php</em> does not exist or cannot be updated.', 'wp-super-cache' ), WP_CONTENT_DIR ) . "</h3>";
  1296 		echo "<p><ul><li>" . __( '1. If it already exists please delete the file first.', 'wp-super-cache' ) . "</li>";
  2115 		echo "<p><ul><li>" . __( '1. If it already exists please delete the file first.', 'wp-super-cache' ) . "</li>";
  1297 		echo "<li>" . sprintf( __( '2. Make %1$s writable using the chmod command through your ftp or server software. (<em>chmod 777 %1$s</em>) and refresh this page. This is only a temporary measure and you&#8217;ll have to make it read only afterwards again. (Change 777 to 755 in the previous command)', 'wp-super-cache' ), WP_CONTENT_DIR ) . "</li>";
  2116 		echo "<li>" . sprintf( __( '2. Make %1$s writable using the chmod command through your ftp or server software. (<em>chmod 777 %1$s</em>) and refresh this page. This is only a temporary measure and you&#8217;ll have to make it read only afterwards again. (Change 777 to 755 in the previous command)', 'wp-super-cache' ), WP_CONTENT_DIR ) . "</li>";
  1298 		echo "<li>" . sprintf( __( '3. Refresh this page to update <em>%s/advanced-cache.php</em>', 'wp-super-cache' ), WP_CONTENT_DIR ) . "</li></ul>";
  2117 		echo "<li>" . sprintf( __( '3. Refresh this page to update <em>%s/advanced-cache.php</em>', 'wp-super-cache' ), WP_CONTENT_DIR ) . "</li></ul>";
  1299 		echo sprintf( __( 'If that doesn&#8217;t work, make sure the file <em>%s/advanced-cache.php</em> doesn&#8217;t exist:', 'wp-super-cache' ), WP_CONTENT_DIR ) . "<ol>";
  2118 		echo sprintf( __( 'If that doesn&#8217;t work, make sure the file <em>%s/advanced-cache.php</em> doesn&#8217;t exist:', 'wp-super-cache' ), WP_CONTENT_DIR ) . "<ol>";
  1300 		printf( __( '<li>1. Open <em>%1$s$wp_cache_file</em> in a text editor.</li><li>2. Change the text <em>CACHEHOME</em> to <em>%2$s</em></li><li>3. Save the file and copy it to <em>%3$s</em> and refresh this page.</li>', 'wp-super-cache' ), $wp_cache_file, WPCACHEHOME, $wp_cache_link );
  2119 		printf( __( '<li>1. Open <em>%1$s$wp_cache_file</em> in a text editor.</li><li>2. Change the text <em>CACHEHOME</em> to <em>%2$s</em></li><li>3. Save the file and copy it to <em>%3$s</em> and refresh this page.</li>', 'wp-super-cache' ), $wp_cache_file, WPCACHEHOME, $wp_cache_link );
       
  2120 		echo "</div>";
  1301 		return false;
  2121 		return false;
  1302 	}
  2122 	}
  1303 	return true;
  2123 	return true;
  1304 }
  2124 }
  1305 
  2125 
  1306 function wp_cache_check_global_config() {
  2126 function wp_cache_check_global_config() {
  1307 	global $wp_cache_check_wp_config;
  2127 	global $wp_cache_check_wp_config;
  1308 
  2128 
  1309 	if ( !isset( $wp_cache_check_wp_config ) )
  2129 	if ( !isset( $wp_cache_check_wp_config ) )
  1310 		return true;
  2130 		return true;
       
  2131 
  1311 
  2132 
  1312 	if ( file_exists( ABSPATH . 'wp-config.php') ) {
  2133 	if ( file_exists( ABSPATH . 'wp-config.php') ) {
  1313 		$global = ABSPATH . 'wp-config.php';
  2134 		$global = ABSPATH . 'wp-config.php';
  1314 	} else {
  2135 	} else {
  1315 		$global = dirname(ABSPATH) . '/wp-config.php';
  2136 		$global = dirname(ABSPATH) . '/wp-config.php';
  1316 	}
  2137 	}
  1317 
  2138 
  1318 	$line = 'define(\'WP_CACHE\', true);';
  2139 	$line = 'define(\'WP_CACHE\', true);';
  1319 	if (!is_writeable_ACLSafe($global) || !wp_cache_replace_line('define *\( *\'WP_CACHE\'', $line, $global) ) {
  2140 	if (!is_writeable_ACLSafe($global) || !wp_cache_replace_line('define *\( *\'WP_CACHE\'', $line, $global) ) {
  1320 		echo "<p>" . __( "<strong>Error: WP_CACHE is not enabled</strong> in your <code>wp-config.php</code> file and I couldn&#8217;t modify it.", 'wp-super-cache' ) . "</p>";;
  2141 		if ( defined( 'WP_CACHE' ) && constant( 'WP_CACHE' ) == false ) {
  1321 		echo "<p>" . sprintf( __( "Edit <code>%s</code> and add the following line:<br /> <code>define('WP_CACHE', true);</code><br />Otherwise, <strong>WP-Cache will not be executed</strong> by Wordpress core. ", 'wp-super-cache' ), $global ) . "</p>";
  2142 			echo '<div id="message" class="updated fade">' . __( "<h3>WP_CACHE constant set to false</h3><p>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:<br /><br /><code>define('WP_CACHE', true);</code></p>", 'wp-super-cache' ) . "</div>";
       
  2143 		} else {
       
  2144 			echo "<p>" . __( "<strong>Error: WP_CACHE is not enabled</strong> in your <code>wp-config.php</code> file and I couldn&#8217;t modify it.", 'wp-super-cache' ) . "</p>";;
       
  2145 			echo "<p>" . sprintf( __( "Edit <code>%s</code> and add the following line:<br /> <code>define('WP_CACHE', true);</code><br />Otherwise, <strong>WP-Cache will not be executed</strong> by WordPress core. ", 'wp-super-cache' ), $global ) . "</p>";
       
  2146 		}
  1322 		return false;
  2147 		return false;
  1323 	}  else {
  2148 	}  else {
  1324 		echo "<div style='border: 1px solid #333; background: #ffffaa; padding: 2px;'>" . __( '<h3>WP_CACHE constant added to wp-config.php</h3><p>If you continue to see this warning message please see point 5 of the <a href="http://wordpress.org/extend/plugins/wp-super-cache/faq/">FAQ</a>. The WP_CACHE line must be moved up.', 'wp-super-cache' ) . "</div>";
  2149 		echo "<div style='border: 1px solid #333; background: #ffffaa; padding: 2px;'>" . __( '<h3>WP_CACHE constant added to wp-config.php</h3><p>If you continue to see this warning message please see point 5 of the <a href="http://wordpress.org/extend/plugins/wp-super-cache/faq/">Troubleshooting Guide</a>. The WP_CACHE line must be moved up.', 'wp-super-cache' ) . "</p></div>";
  1325 	}
  2150 	}
  1326 	return true;
  2151 	return true;
  1327 }
  2152 }
  1328 
  2153 
  1329 function wp_cache_files() {
  2154 function wp_cache_files() {
  1330 	global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled, $blog_cache_dir, $cache_compression;
  2155 	global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled, $blog_cache_dir, $cache_compression;
       
  2156 	global $wp_cache_object_cache, $wp_cache_preload_on;
  1331 
  2157 
  1332 	if ( '/' != substr($cache_path, -1)) {
  2158 	if ( '/' != substr($cache_path, -1)) {
  1333 		$cache_path .= '/';
  2159 		$cache_path .= '/';
  1334 	}
  2160 	}
  1335 
  2161 
  1336 	if ( $valid_nonce ) {
  2162 	if ( $valid_nonce ) {
  1337 		if(isset($_REQUEST['wp_delete_cache'])) {
  2163 		if(isset($_REQUEST['wp_delete_cache'])) {
  1338 			wp_cache_clean_cache($file_prefix);
  2164 			wp_cache_clean_cache($file_prefix);
       
  2165 			$_GET[ 'action' ] = 'regenerate_cache_stats';
       
  2166 		}
       
  2167 		if ( isset( $_REQUEST[ 'wp_delete_all_cache' ] ) ) {
       
  2168 			wp_cache_clean_cache( $file_prefix, true );
       
  2169 			$_GET[ 'action' ] = 'regenerate_cache_stats';
  1339 		}
  2170 		}
  1340 		if(isset($_REQUEST['wp_delete_expired'])) {
  2171 		if(isset($_REQUEST['wp_delete_expired'])) {
  1341 			wp_cache_clean_expired($file_prefix);
  2172 			wp_cache_clean_expired($file_prefix);
       
  2173 			$_GET[ 'action' ] = 'regenerate_cache_stats';
  1342 		}
  2174 		}
  1343 	}
  2175 	}
  1344 	echo "<a name='listfiles'></a>";
  2176 	echo "<a name='listfiles'></a>";
  1345 	echo '<fieldset class="options" id="show-this-fieldset"><h3>' . __( 'Cache Contents', 'wp-super-cache' ) . '</h3>';
  2177 	echo '<fieldset class="options" id="show-this-fieldset"><h3>' . __( 'Cache Contents', 'wp-super-cache' ) . '</h3>';
  1346 
  2178 
       
  2179 	if ( $wp_cache_object_cache ) {
       
  2180 		echo "<p>" . __( "Object cache in use. No cache listing available.", 'wp-super-cache' ) . "</p>";
       
  2181 		wp_cache_delete_buttons();
       
  2182 		echo "</fieldset>";
       
  2183 		return false;
       
  2184 	}
       
  2185 
       
  2186 	$cache_stats = get_option( 'supercache_stats' );
       
  2187 	if ( !is_array( $cache_stats ) || ( isset( $_GET[ 'listfiles' ] ) ) || ( $valid_nonce && array_key_exists('action', $_GET) && $_GET[ 'action' ] == 'regenerate_cache_stats' ) ) {
  1347 	$list_files = false; // it doesn't list supercached files, and removing single pages is buggy
  2188 	$list_files = false; // it doesn't list supercached files, and removing single pages is buggy
  1348 	$count = 0;
  2189 	$count = 0;
  1349 	$expired = 0;
  2190 	$expired = 0;
  1350 	$now = time();
  2191 	$now = time();
  1351 	if ( ($handle = @opendir( $blog_cache_dir . 'meta/' )) ) { 
  2192 	if ( ($handle = @opendir( $blog_cache_dir . 'meta/' )) ) { 
  1352 		if ($list_files) echo "<table cellspacing=\"0\" cellpadding=\"5\">";
       
  1353 		$wp_cache_fsize = 0;
  2193 		$wp_cache_fsize = 0;
  1354 		if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletewpcache' ) {
  2194 		if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletewpcache' ) {
  1355 			$deleteuri = preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '/index.php', '/', str_replace( '..', '', preg_replace("/(\?.*)?$/", '', base64_decode( $_GET[ 'uri' ] ) ) ) ) );
  2195 			$deleteuri = preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '/index.php', '/', str_replace( '..', '', preg_replace("/(\?.*)?$/", '', base64_decode( $_GET[ 'uri' ] ) ) ) ) );
  1356 			$deleteuri = str_replace( '\\', '', $deleteuri );
  2196 			$deleteuri = str_replace( '\\', '', $deleteuri );
  1357 		} else {
  2197 		} else {
  1382 						@unlink( $blog_cache_dir . 'meta/' . $file );
  2222 						@unlink( $blog_cache_dir . 'meta/' . $file );
  1383 						@unlink( $blog_cache_dir . $content_file );
  2223 						@unlink( $blog_cache_dir . $content_file );
  1384 						continue;
  2224 						continue;
  1385 					}
  2225 					}
  1386 					$meta[ 'age' ] = $age;
  2226 					$meta[ 'age' ] = $age;
  1387 					if ( $age > $cache_max_time ) {
  2227 					if ( $cache_max_time > 0 && $age > $cache_max_time ) {
  1388 						$expired_list[ $age ][] = $meta;
  2228 						$expired_list[ $age ][] = $meta;
  1389 					} else {
  2229 					} else {
  1390 						$cached_list[ $age ][] = $meta;
  2230 						$cached_list[ $age ][] = $meta;
  1391 					}
  2231 					}
  1392 				}
  2232 				}
  1393 
  2233 
  1394 				if ( $age > $cache_max_time ) {
  2234 				if ( $cache_max_time > 0 && $age > $cache_max_time ) {
  1395 					$expired++;
  2235 					$expired++;
  1396 				} else {
  2236 				} else {
  1397 					$count++;
  2237 					$count++;
  1398 				}
  2238 				}
  1399 				$wp_cache_fsize += $fsize;
  2239 				$wp_cache_fsize += $fsize;
  1400 				$fsize = intval($fsize/1024);
  2240 				$fsize = intval($fsize/1024);
  1401 			}
  2241 			}
  1402 		}
  2242 		}
  1403 		closedir($handle);
  2243 		closedir($handle);
  1404 		if ($list_files) echo "</table>";
       
  1405 	}
  2244 	}
  1406 	if( $wp_cache_fsize != 0 ) {
  2245 	if( $wp_cache_fsize != 0 ) {
  1407 		$wp_cache_fsize = $wp_cache_fsize/1024;
  2246 		$wp_cache_fsize = $wp_cache_fsize/1024;
  1408 	} else {
  2247 	} else {
  1409 		$wp_cache_fsize = 0;
  2248 		$wp_cache_fsize = 0;
  1413 	} elseif( $wp_cache_fsize != 0 ) {
  2252 	} elseif( $wp_cache_fsize != 0 ) {
  1414 		$wp_cache_fsize = number_format( $wp_cache_fsize, 2 ) . "KB";
  2253 		$wp_cache_fsize = number_format( $wp_cache_fsize, 2 ) . "KB";
  1415 	} else {
  2254 	} else {
  1416 		$wp_cache_fsize = '0KB';
  2255 		$wp_cache_fsize = '0KB';
  1417 	}
  2256 	}
  1418 	if( $cache_enabled == true && $super_cache_enabled == true ) {
  2257 
  1419 		$now = time();
  2258 	// Supercache files
  1420 		$sizes = array( 'expired' => 0, 'expired_list' => array(), 'cached' => 0, 'cached_list' => array(), 'ts' => 0 );
  2259 	$now = time();
  1421 
  2260 	$sizes = array( 'expired' => 0, 'expired_list' => array(), 'cached' => 0, 'cached_list' => array(), 'ts' => 0 );
  1422 		if (is_dir($supercachedir)) {
  2261 
  1423 			if( $dh = opendir( $supercachedir ) ) {
  2262 	if (is_dir($supercachedir)) {
  1424 				while( ( $entry = readdir( $dh ) ) !== false ) {
  2263 		if( $dh = opendir( $supercachedir ) ) {
  1425 					if ($entry != '.' && $entry != '..') {
  2264 			while( ( $entry = readdir( $dh ) ) !== false ) {
  1426 						$sizes = wpsc_dirsize( trailingslashit( $supercachedir ) . $entry, $sizes );
  2265 				if ($entry != '.' && $entry != '..') {
  1427 					}
  2266 					$sizes = wpsc_dirsize( trailingslashit( $supercachedir ) . $entry, $sizes );
  1428 				}
  2267 				}
  1429 				closedir($dh);
  2268 			}
  1430 			}
  2269 			closedir($dh);
  1431 		} else {
  2270 		}
  1432 			$filem = @filemtime( $supercachedir );
  2271 	} else {
  1433 			if(is_file($supercachedir) && $filem + $cache_max_time <= $now ) {
  2272 		$filem = @filemtime( $supercachedir );
  1434 				$sizes[ 'expired' ] ++;
  2273 		if ( false == $wp_cache_preload_on && is_file( $supercachedir ) && $cache_max_time > 0 && $filem + $cache_max_time <= $now ) {
  1435 				if ( $valid_nonce && $_GET[ 'listfiles' ] )
  2274 			$sizes[ 'expired' ] ++;
  1436 					$sizes[ 'expired_list' ][ str_replace( $cache_path . 'supercache/' , '', $supercachedir ) ] = $now - $filem;
  2275 			if ( $valid_nonce && $_GET[ 'listfiles' ] )
  1437 			} else {
  2276 				$sizes[ 'expired_list' ][ str_replace( $cache_path . 'supercache/' , '', $supercachedir ) ] = $now - $filem;
  1438 				if ( $valid_nonce && $_GET[ 'listfiles' ] && $filem )
  2277 		} else {
  1439 					$sizes[ 'cached_list' ][ str_replace( $cache_path . 'supercache/' , '', $supercachedir ) ] = $now - $filem;
  2278 			if ( $valid_nonce && $_GET[ 'listfiles' ] && $filem )
  1440 			}
  2279 				$sizes[ 'cached_list' ][ str_replace( $cache_path . 'supercache/' , '', $supercachedir ) ] = $now - $filem;
  1441 		} 
  2280 		}
  1442 		$sizes[ 'ts' ] = time();
  2281 	} 
  1443 	}
  2282 	$sizes[ 'ts' ] = time();
  1444 
  2283 	$cache_stats = array( 'generated' => time(), 'supercache' => $sizes, 'wpcache' => array( 'cached' => $count, 'expired' => $expired, 'fsize' => $wp_cache_fsize ) );
  1445 	echo "<p><strong>" . __( 'WP-Cache', 'wp-super-cache' ) . " ({$wp_cache_fsize})</strong></p>";
  2284 	update_option( 'supercache_stats', $cache_stats );
  1446 	echo "<ul><li>" . sprintf( __( '%s Cached Pages', 'wp-super-cache' ), $count ) . "</li>";
  2285 	} else {
  1447 	echo "<li>" . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), $expired ) . "</li></ul>";
  2286 		echo "<p>" . __( 'Cache stats are not automatically generated. You must click the link below to regenerate the stats on this page.', 'wp-super-cache' ) . "</p>";
  1448 	if( $cache_enabled == true && $super_cache_enabled == true ) {
  2287 		echo "<a href='" . wp_nonce_url( add_query_arg( array( 'page' => 'wpsupercache', 'tab' => 'contents', 'action' => 'regenerate_cache_stats' ) ), 'wp-cache' ) . "'>" . __( 'Regenerate cache stats', 'wp-super-cache' ) . "</a>";
  1449 		$fsize = $sizes[ 'fsize' ] / 1024;
  2288 		if ( is_array( $cache_stats ) ) {
       
  2289 			echo "<p>" . sprintf( __( 'Cache stats last generated: %s minutes ago.', 'wp-super-cache' ), number_format( ( time() - $cache_stats[ 'generated' ] ) / 60 ) ) . "</p>";
       
  2290 		}
       
  2291 		$cache_stats = get_option( 'supercache_stats' );
       
  2292 	}// regerate stats cache
       
  2293 
       
  2294 	if ( is_array( $cache_stats ) ) {
       
  2295 		echo "<p><strong>" . __( 'WP-Cache', 'wp-super-cache' ) . " ({$cache_stats[ 'wpcache' ][ 'fsize' ]})</strong></p>";
       
  2296 		echo "<ul><li>" . sprintf( __( '%s Cached Pages', 'wp-super-cache' ), $cache_stats[ 'wpcache' ][ 'cached' ] ) . "</li>";
       
  2297 		echo "<li>" . sprintf( __( '%s Expired Pages', 'wp-super-cache' ),    $cache_stats[ 'wpcache' ][ 'expired' ] ) . "</li></ul>";
       
  2298 		$divisor = $cache_compression == 1 ? 2 : 1;
       
  2299 		if ( array_key_exists('fsize', (array)$cache_stats[ 'supercache' ]) )
       
  2300 			$fsize = $cache_stats[ 'supercache' ][ 'fsize' ] / 1024;
       
  2301 		else
       
  2302 			$fsize = 0;
  1450 		if( $fsize > 1024 ) {
  2303 		if( $fsize > 1024 ) {
  1451 			$fsize = number_format( $fsize / 1024, 2 ) . "MB";
  2304 			$fsize = number_format( $fsize / 1024, 2 ) . "MB";
  1452 		} elseif( $fsize != 0 ) {
  2305 		} elseif( $fsize != 0 ) {
  1453 			$fsize = number_format( $fsize, 2 ) . "KB";
  2306 			$fsize = number_format( $fsize, 2 ) . "KB";
  1454 		} else {
  2307 		} else {
  1455 			$fsize = "0KB";
  2308 			$fsize = "0KB";
  1456 		}
  2309 		}
  1457 		$divisor = $cache_compression == 1 ? 2 : 1;
       
  1458 		echo "<p><strong>" . __( 'WP-Super-Cache', 'wp-super-cache' ) . " ({$fsize})</strong></p>";
  2310 		echo "<p><strong>" . __( 'WP-Super-Cache', 'wp-super-cache' ) . " ({$fsize})</strong></p>";
  1459 		echo "<ul><li>" . sprintf( __( '%s Cached Pages', 'wp-super-cache' ), intval( $sizes[ 'cached' ] / $divisor ) ) . "</li>";
  2311 		echo "<ul><li>" . sprintf( __( '%s Cached Pages', 'wp-super-cache' ), intval( $cache_stats[ 'supercache' ][ 'cached' ] / $divisor ) ) . "</li>";
  1460 		$age = intval(($now - $sizes['ts'])/60);
  2312 		if (isset($now) && isset($sizes))
  1461 		echo "<li>" . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), intval( $sizes[ 'expired' ] / $divisor ) ) . "</li></ul>";
  2313 			$age = intval(($now - $sizes['ts'])/60);
  1462 	}
  2314 		else
  1463 	if ( $valid_nonce && $_GET[ 'listfiles' ] ) {
  2315 			$age = 0;
  1464 		echo "<div style='padding: 10px; border: 1px solid #333; height: 400px; width: 70%; overflow: auto'>";
  2316 		echo "<li>" . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), intval( $cache_stats[ 'supercache' ][ 'expired' ] / $divisor ) ) . "</li></ul>";
  1465 		if ( is_array( $cached_list ) && !empty( $cached_list ) ) {
  2317 		if ( $valid_nonce && array_key_exists('listfiles', $_GET) && $_GET[ 'listfiles' ] ) {
  1466 			echo "<h4>" . __( 'Fresh WP-Cached Files', 'wp-super-cache' ) . "</h4>";
  2318 			echo "<div style='padding: 10px; border: 1px solid #333; height: 400px; width: 90%; overflow: auto'>";
  1467 			echo "<table class='widefat'><tr><th>#</th><th>" . __( 'URI', 'wp-super-cache' ) . "</th><th>" . __( 'Key', 'wp-super-cache' ) . "</th><th>" . __( 'Age', 'wp-super-cache' ) . "</th><th>" . __( 'Delete', 'wp-super-cache' ) . "</th></tr>";
  2319 			if ( is_array( $cached_list ) && !empty( $cached_list ) ) {
  1468 			$c = 1;
  2320 				echo "<h4>" . __( 'Fresh WP-Cached Files', 'wp-super-cache' ) . "</h4>";
  1469 			$flip = 1;
  2321 				echo "<table class='widefat'><tr><th>#</th><th>" . __( 'URI', 'wp-super-cache' ) . "</th><th>" . __( 'Key', 'wp-super-cache' ) . "</th><th>" . __( 'Age', 'wp-super-cache' ) . "</th><th>" . __( 'Delete', 'wp-super-cache' ) . "</th></tr>";
  1470 			ksort( $cached_list );
  2322 				$c = 1;
  1471 			foreach( $cached_list as $age => $d ) {
  2323 				$flip = 1;
  1472 				foreach( $d as $details ) {
  2324 				ksort( $cached_list );
  1473 				$bg = $flip ? 'style="background: #EAEAEA;"' : '';
  2325 				foreach( $cached_list as $age => $d ) {
  1474 				echo "<tr $bg><td>$c</td><td> <a href='http://{$details[ 'uri' ]}'>" . $details[ 'uri' ] . "</a></td><td> " . str_replace( $details[ 'uri' ], '', $details[ 'key' ] ) . "</td><td> {$age}</td><td><a href='" . wp_nonce_url( add_query_arg( array( 'page' => 'wpsupercache', 'action' => 'deletewpcache', 'uri' => base64_encode( $details[ 'uri' ] ) ) ), 'wp-cache' ) . "#listfiles'>X</a></td></tr>\n";
  2326 					foreach( $d as $details ) {
  1475 				$flip = !$flip;
  2327 						$bg = $flip ? 'style="background: #EAEAEA;"' : '';
  1476 				$c++;
  2328 						echo "<tr $bg><td>$c</td><td> <a href='http://{$details[ 'uri' ]}'>" . $details[ 'uri' ] . "</a></td><td> " . str_replace( $details[ 'uri' ], '', $details[ 'key' ] ) . "</td><td> {$age}</td><td><a href='" . wp_nonce_url( add_query_arg( array( 'page' => 'wpsupercache', 'action' => 'deletewpcache', 'uri' => base64_encode( $details[ 'uri' ] ) ) ), 'wp-cache' ) . "#listfiles'>X</a></td></tr>\n";
       
  2329 						$flip = !$flip;
       
  2330 						$c++;
       
  2331 					}
  1477 				}
  2332 				}
  1478 			}
  2333 				echo "</table>";
  1479 			echo "</table>";
  2334 			}
  1480 		}
  2335 			if ( is_array( $expired_list ) && !empty( $expired_list ) ) {
  1481 		if ( is_array( $expired_list ) && !empty( $expired_list ) ) {
  2336 				echo "<h4>" . __( 'Stale WP-Cached Files', 'wp-super-cache' ) . "</h4>";
  1482 			echo "<h4>" . __( 'Stale WP-Cached Files', 'wp-super-cache' ) . "</h4>";
  2337 				echo "<table class='widefat'><tr><th>#</th><th>" . __( 'URI', 'wp-super-cache' ) . "</th><th>" . __( 'Key', 'wp-super-cache' ) . "</th><th>" . __( 'Age', 'wp-super-cache' ) . "</th><th>" . __( 'Delete', 'wp-super-cache' ) . "</th></tr>";
  1483 			echo "<table class='widefat'><tr><th>#</th><th>" . __( 'URI', 'wp-super-cache' ) . "</th><th>" . __( 'Key', 'wp-super-cache' ) . "</th><th>" . __( 'Age', 'wp-super-cache' ) . "</th><th>" . __( 'Delete', 'wp-super-cache' ) . "</th></tr>";
  2338 				$c = 1;
  1484 			$c = 1;
  2339 				$flip = 1;
  1485 			$flip = 1;
  2340 				ksort( $expired_list );
  1486 			ksort( $expired_list );
  2341 				foreach( $expired_list as $age => $d ) {
  1487 			foreach( $expired_list as $age => $d ) {
  2342 					foreach( $d as $details ) {
  1488 				foreach( $d as $details ) {
  2343 						$bg = $flip ? 'style="background: #EAEAEA;"' : '';
  1489 				$bg = $flip ? 'style="background: #EAEAEA;"' : '';
  2344 						echo "<tr $bg><td>$c</td><td> <a href='http://{$details[ 'uri' ]}'>" . $details[ 'uri' ] . "</a></td><td> " . str_replace( $details[ 'uri' ], '', $details[ 'key' ] ) . "</td><td> {$age}</td><td><a href='" . wp_nonce_url( add_query_arg( array( 'page' => 'wpsupercache', 'action' => 'deletewpcache', 'uri' => base64_encode( $details[ 'uri' ] ) ) ), 'wp-cache' ) . "#listfiles'>X</a></td></tr>\n";
  1490 				echo "<tr $bg><td>$c</td><td> <a href='http://{$details[ 'uri' ]}'>" . $details[ 'uri' ] . "</a></td><td> " . str_replace( $details[ 'uri' ], '', $details[ 'key' ] ) . "</td><td> {$age}</td><td><a href='" . wp_nonce_url( add_query_arg( array( 'page' => 'wpsupercache', 'action' => 'deletewpcache', 'uri' => base64_encode( $details[ 'uri' ] ) ) ), 'wp-cache' ) . "#listfiles'>X</a></td></tr>\n";
  2345 						$flip = !$flip;
  1491 				$flip = !$flip;
  2346 						$c++;
  1492 				$c++;
  2347 					}
  1493 				}
  2348 				}
  1494 			}
  2349 				echo "</table>";
  1495 			echo "</table>";
  2350 			}
  1496 		}
  2351 			if ( is_array( $sizes[ 'cached_list' ] ) & !empty( $sizes[ 'cached_list' ] ) ) {
  1497 		if ( is_array( $sizes[ 'cached_list' ] ) & !empty( $sizes[ 'cached_list' ] ) ) {
  2352 				echo "<h4>" . __( 'Fresh Super Cached Files', 'wp-super-cache' ) . "</h4>";
  1498 			echo "<h4>" . __( 'Fresh Super Cached Files', 'wp-super-cache' ) . "</h4>";
  2353 				echo "<table class='widefat'><tr><th>#</th><th>" . __( 'URI', 'wp-super-cache' ) . "</th><th>" . __( 'Age', 'wp-super-cache' ) . "</th><th>" . __( 'Delete', 'wp-super-cache' ) . "</th></tr>";
  1499 			echo "<table class='widefat'><tr><th>#</th><th>" . __( 'URI', 'wp-super-cache' ) . "</th><th>" . __( 'Age', 'wp-super-cache' ) . "</th><th>" . __( 'Delete', 'wp-super-cache' ) . "</th></tr>";
  2354 				$c = 1;
  1500 			$c = 1;
  2355 				$flip = 1;
  1501 			$flip = 1;
  2356 				ksort( $sizes[ 'cached_list' ] );
  1502 			ksort( $sizes[ 'cached_list' ] );
  2357 				foreach( $sizes[ 'cached_list' ] as $age => $d ) {
  1503 			foreach( $sizes[ 'cached_list' ] as $age => $d ) {
  2358 					foreach( $d as $uri => $n ) {
  1504 				foreach( $d as $uri => $n ) {
  2359 						$bg = $flip ? 'style="background: #EAEAEA;"' : '';
  1505 				$bg = $flip ? 'style="background: #EAEAEA;"' : '';
  2360 						echo "<tr $bg><td>$c</td><td> <a href='http://{$uri}'>" . $uri . "</a></td><td>$age</td><td><a href='" . wp_nonce_url( add_query_arg( array( 'page' => 'wpsupercache', 'action' => 'deletesupercache', 'uri' => base64_encode( $uri ) ) ), 'wp-cache' ) . "#listfiles'>X</a></td></tr>\n";
  1506 				echo "<tr $bg><td>$c</td><td> <a href='http://{$uri}'>" . $uri . "</a></td><td>$age</td><td><a href='" . wp_nonce_url( add_query_arg( array( 'page' => 'wpsupercache', 'action' => 'deletesupercache', 'uri' => base64_encode( $uri ) ) ), 'wp-cache' ) . "#listfiles'>X</a></td></tr>\n";
  2361 						$flip = !$flip;
  1507 				$flip = !$flip;
  2362 						$c++;
  1508 				$c++;
  2363 					}
  1509 				}
  2364 				}
  1510 			}
  2365 				echo "</table>";
  1511 			echo "</table>";
  2366 			}
  1512 		}
  2367 			if ( is_array( $sizes[ 'expired_list' ] ) && !empty( $sizes[ 'expired_list' ] ) ) {
  1513 		if ( is_array( $sizes[ 'expired_list' ] ) && !empty( $sizes[ 'expired_list' ] ) ) {
  2368 				echo "<h4>" . __( 'Stale Super Cached Files', 'wp-super-cache' ) . "</h4>";
  1514 			echo "<h4>" . __( 'Stale Super Cached Files', 'wp-super-cache' ) . "</h4>";
  2369 				echo "<table class='widefat'><tr><th>#</th><th>" . __( 'URI', 'wp-super-cache' ) . "</th><th>" . __( 'Age', 'wp-super-cache' ) . "</th><th>" . __( 'Delete', 'wp-super-cache' ) . "</th></tr>";
  1515 			echo "<table class='widefat'><tr><th>#</th><th>" . __( 'URI', 'wp-super-cache' ) . "</th><th>" . __( 'Age', 'wp-super-cache' ) . "</th><th>" . __( 'Delete', 'wp-super-cache' ) . "</th></tr>";
  2370 				$c = 1;
  1516 			$c = 1;
  2371 				$flip = 1;
  1517 			$flip = 1;
  2372 				ksort( $sizes[ 'expired_list' ] );
  1518 			ksort( $sizes[ 'expired_list' ] );
  2373 				foreach( $sizes[ 'expired_list' ] as $age => $d ) {
  1519 			foreach( $sizes[ 'expired_list' ] as $age => $d ) {
  2374 					foreach( $d as $uri => $n ) {
  1520 				foreach( $d as $uri => $n ) {
  2375 						$bg = $flip ? 'style="background: #EAEAEA;"' : '';
  1521 				$bg = $flip ? 'style="background: #EAEAEA;"' : '';
  2376 						echo "<tr $bg><td>$c</td><td> <a href='http://{$uri}'>" . $uri . "</a></td><td>$age</td><td><a href='" . wp_nonce_url( add_query_arg( array( 'page' => 'wpsupercache', 'action' => 'deletesupercache', 'uri' => base64_encode( $uri ) ) ), 'wp-cache' ) . "#listfiles'>X</a></td></tr>\n";
  1522 				echo "<tr $bg><td>$c</td><td> <a href='http://{$uri}'>" . $uri . "</a></td><td>$age</td><td><a href='" . wp_nonce_url( add_query_arg( array( 'page' => 'wpsupercache', 'action' => 'deletesupercache', 'uri' => base64_encode( $uri ) ) ), 'wp-cache' ) . "#listfiles'>X</a></td></tr>\n";
  2377 						$flip = !$flip;
  1523 				$flip = !$flip;
  2378 						$c++;
  1524 				$c++;
  2379 					}
  1525 				}
  2380 				}
  1526 			}
  2381 				echo "</table>";
  1527 			echo "</table>";
  2382 			}
  1528 		}
  2383 			echo "</div>";
  1529 		echo "</div>";
  2384 			echo "<p><a href='?page=wpsupercache&tab=contents#top'>" . __( 'Hide file list', 'wp-super-cache' ) . "</a></p>";
  1530 		echo "<p><a href='?page=wpsupercache#top'>" . __( 'Hide file list', 'wp-super-cache' ) . "</a></p>";
  2385 		} elseif ( $cache_stats[ 'supercache' ][ 'cached' ] > 500 || $cache_stats[ 'supercache' ][ 'expired' ] > 500 || ( $cache_stats[ 'wpcache' ][ 'cached' ] / $divisor ) > 500 || ( $cache_stats[ 'wpcache' ][ 'expired' ] / $divisor) > 500 ) {
  1531 	} else {
  2386 			echo "<p><em>" . __( 'Too many cached files, no listing possible.', 'wp-super-cache' ) . "</em></p>";
  1532 		echo "<p><a href='" . wp_nonce_url( add_query_arg( array( 'page' => 'wpsupercache', 'listfiles' => '1' ) ), 'wp-cache' ) . "#listfiles'>" . __( 'List all cached files', 'wp-super-cache' ) . "</a></p>";
  2387 		} else {
  1533 	}
  2388 			echo "<p><a href='" . wp_nonce_url( add_query_arg( array( 'page' => 'wpsupercache', 'listfiles' => '1' ) ), 'wp-cache' ) . "#listfiles'>" . __( 'List all cached files', 'wp-super-cache' ) . "</a></p>";
  1534 	$last_gc = get_option( "wpsupercache_gc_time" );
  2389 		}
  1535 	if( $last_gc ) {
  2390 		if ( $cache_max_time > 0 )
  1536 		$next_gc = $cache_max_time < 1800 ? $cache_max_time : 600;
  2391 			echo "<p>" . 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 ) . "</p>";
  1537 		$next_gc_mins = ( time() - $last_gc );
  2392 	} // cache_stats
  1538 		echo "<p>" . sprintf( __( '<strong>Garbage Collection</strong><br />Last GC was <strong>%s</strong> minutes ago<br />', 'wp-super-cache' ), date( 'i:s', $next_gc_mins ) );
  2393 	wp_cache_delete_buttons();
  1539 		printf( __( "Next GC in <strong>%s</strong> minutes", 'wp-super-cache' ), date( 'i:s', $next_gc - $next_gc_mins ) ) . "</p>";
  2394 
  1540 	}
  2395 	echo '</fieldset>';
  1541 
  2396 }
  1542 	echo "<p>" . 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 ) . "</p>";
  2397 
       
  2398 function wp_cache_delete_buttons() {
       
  2399 
  1543 	echo '<form name="wp_cache_content_expired" action="#listfiles" method="post">';
  2400 	echo '<form name="wp_cache_content_expired" action="#listfiles" method="post">';
  1544 	echo '<input type="hidden" name="wp_delete_expired" />';
  2401 	echo '<input type="hidden" name="wp_delete_expired" />';
  1545 	echo '<div class="submit" style="float:left"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Expired', 'wp-super-cache' ) . ' &raquo;" /></div>';
  2402 	echo '<div class="submit" style="float:left"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Expired', 'wp-super-cache' ) . ' &raquo;" /></div>';
  1546 	wp_nonce_field('wp-cache');
  2403 	wp_nonce_field('wp-cache');
  1547 	echo "</form>\n";
  2404 	echo "</form>\n";
  1549 	echo '<form name="wp_cache_content_delete" action="#listfiles" method="post">';
  2406 	echo '<form name="wp_cache_content_delete" action="#listfiles" method="post">';
  1550 	echo '<input type="hidden" name="wp_delete_cache" />';
  2407 	echo '<input type="hidden" name="wp_delete_cache" />';
  1551 	echo '<div class="submit" style="float:left;margin-left:10px"><input id="deletepost" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Cache', 'wp-super-cache' ) . ' &raquo;" /></div>';
  2408 	echo '<div class="submit" style="float:left;margin-left:10px"><input id="deletepost" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Cache', 'wp-super-cache' ) . ' &raquo;" /></div>';
  1552 	wp_nonce_field('wp-cache');
  2409 	wp_nonce_field('wp-cache');
  1553 	echo "</form>\n";
  2410 	echo "</form>\n";
  1554 
  2411 	if ( ( defined( 'VHOST' ) || ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) ) && wpsupercache_site_admin() ) {
  1555 	echo '</fieldset>';
  2412 		echo '<form name="wp_cache_content_delete" action="#listfiles" method="post">';
       
  2413 		echo '<input type="hidden" name="wp_delete_all_cache" />';
       
  2414 		echo '<div class="submit" style="float:left;margin-left:10px"><input id="deleteallpost" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Cache On All Blogs', 'wp-super-cache' ) . ' &raquo;" />';
       
  2415 		wp_nonce_field('wp-cache');
       
  2416 		echo "</form>\n";
       
  2417 	}
  1556 }
  2418 }
  1557 
  2419 
  1558 function delete_cache_dashboard() {
  2420 function delete_cache_dashboard() {
  1559 	if( function_exists( 'is_site_admin' ) && !is_site_admin() )
  2421 	if ( false == wpsupercache_site_admin() )
  1560 		return false;
  2422 		return false;
  1561 
  2423 
  1562 	if( function_exists('current_user_can') && !current_user_can('manage_options') )
  2424 	if ( function_exists('current_user_can') && !current_user_can('manage_options') )
  1563 		return false;
  2425 		return false;
  1564 
  2426 
  1565 	echo "<li><a href='" . wp_nonce_url( 'options-general.php?page=wpsupercache&wp_delete_cache=1', 'wp-cache' ) . "' target='_blank' title='" . __( 'Delete Super Cache cached files (opens in new window)', 'wp-super-cache' ) . "'>" . __( 'Delete Cache', 'wp-super-cache' ) . "</a></li>";
  2427 	echo "<li><a href='" . wp_nonce_url( 'options-general.php?page=wpsupercache&wp_delete_cache=1', 'wp-cache' ) . "' target='_blank' title='" . __( 'Delete Super Cache cached files (opens in new window)', 'wp-super-cache' ) . "'>" . __( 'Delete Cache', 'wp-super-cache' ) . "</a></li>";
  1566 }
  2428 }
  1567 add_action( 'dashmenu', 'delete_cache_dashboard' );
  2429 add_action( 'dashmenu', 'delete_cache_dashboard' );
  1568 
  2430 
  1569 function wpsc_dirsize($directory, $sizes) {
  2431 function wpsc_dirsize($directory, $sizes) {
  1570 	global $cache_max_time, $cache_path, $valid_nonce;
  2432 	global $cache_max_time, $cache_path, $valid_nonce, $wp_cache_preload_on;
  1571 	$now = time();
  2433 	$now = time();
  1572 
  2434 
  1573 	if (is_dir($directory)) {
  2435 	if (is_dir($directory)) {
  1574 		if( $dh = opendir( $directory ) ) {
  2436 		if( $dh = opendir( $directory ) ) {
  1575 			while( ( $entry = readdir( $dh ) ) !== false ) {
  2437 			while( ( $entry = readdir( $dh ) ) !== false ) {
  1580 			closedir($dh);
  2442 			closedir($dh);
  1581 		}
  2443 		}
  1582 	} else {
  2444 	} else {
  1583 		if(is_file($directory) ) {
  2445 		if(is_file($directory) ) {
  1584 			$filem = filemtime( $directory );
  2446 			$filem = filemtime( $directory );
  1585 			if( $filem + $cache_max_time <= $now ) {
  2447 			if ( $wp_cache_preload_on == false && $cache_max_time > 0 && $filem + $cache_max_time <= $now ) {
  1586 				$sizes[ 'expired' ]+=1;
  2448 				$sizes[ 'expired' ]+=1;
  1587 				if ( $valid_nonce && $_GET[ 'listfiles' ] )
  2449 				if ( $valid_nonce && $_GET[ 'listfiles' ] )
  1588 					$sizes[ 'expired_list' ][ $now - $filem ][ str_replace( $cache_path . 'supercache/' , '', str_replace( 'index.html', '', str_replace( 'index.html.gz', '', $directory ) ) ) ] = 1;
  2450 					$sizes[ 'expired_list' ][ $now - $filem ][ str_replace( $cache_path . 'supercache/' , '', str_replace( 'index.html', '', str_replace( 'index.html.gz', '', $directory ) ) ) ] = 1;
  1589 			} else {
  2451 			} else {
  1590 				$sizes[ 'cached' ]+=1;
  2452 				$sizes[ 'cached' ]+=1;
  1591 				if ( $valid_nonce && $_GET[ 'listfiles' ] )
  2453 				if ( $valid_nonce && array_key_exists('listfiles', $_GET) && $_GET[ 'listfiles' ] )
  1592 					$sizes[ 'cached_list' ][ $now - $filem ][ str_replace( $cache_path . 'supercache/' , '', str_replace( 'index.html', '', str_replace( 'index.html.gz', '', $directory ) ) ) ] = 1;
  2454 					$sizes[ 'cached_list' ][ $now - $filem ][ str_replace( $cache_path . 'supercache/' , '', str_replace( 'index.html', '', str_replace( 'index.html.gz', '', $directory ) ) ) ] = 1;
  1593 			}
  2455 			}
  1594 			if ( ! isset( $sizes[ 'fsize' ] ) )
  2456 			if ( ! isset( $sizes[ 'fsize' ] ) )
  1595 				$sizes[ 'fsize' ] = @filesize( $directory );
  2457 				$sizes[ 'fsize' ] = @filesize( $directory );
  1596 			else
  2458 			else
  1598 		}
  2460 		}
  1599 	}
  2461 	}
  1600 	return $sizes;
  2462 	return $sizes;
  1601 }
  2463 }
  1602 
  2464 
  1603 
  2465 function wp_cache_clean_cache( $file_prefix, $all = false ) {
  1604 function wp_cache_clean_cache($file_prefix) {
  2466 	global $wpdb, $cache_path, $supercachedir, $blog_cache_dir, $wp_cache_object_cache;
  1605 	global $cache_path, $supercachedir, $blog_cache_dir;
  2467 
  1606 
  2468 	if ( $wp_cache_object_cache && function_exists( "reset_oc_version" ) )
  1607 	// If phase2 was compiled, use its function to avoid race-conditions
  2469 		reset_oc_version();
  1608 	if(function_exists('wp_cache_phase2_clean_cache')) {
  2470 
  1609 		if (function_exists ('prune_super_cache')) {
  2471 	if ( $all == true && wpsupercache_site_admin() && function_exists( 'prune_super_cache' ) ) {
  1610 			if( is_dir( $supercachedir ) ) {
  2472 		prune_super_cache( $cache_path, true );
  1611 				prune_super_cache( $supercachedir, true );
  2473 		return true;
  1612 			} elseif( is_dir( $supercachedir . '.disabled' ) ) {
  2474 	}
  1613 				prune_super_cache( $supercachedir . '.disabled', true );
  2475 
  1614 			}
  2476 	if (function_exists ('prune_super_cache')) {
  1615 			prune_super_cache( $cache_path, true );
  2477 		if( is_dir( $supercachedir ) ) {
  1616 			$_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
  2478 			prune_super_cache( $supercachedir, true );
  1617 		} elseif ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Warning! prune_super_cache() not found in wp-cache.php', 1 );
  2479 		} elseif( is_dir( $supercachedir . '.disabled' ) ) {
  1618 		return wp_cache_phase2_clean_cache($file_prefix);
  2480 			prune_super_cache( $supercachedir . '.disabled', true );
  1619 	} elseif ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Warning! wp_cache_phase2_clean_cache() not found in wp-cache.php', 1 );
  2481 		}
  1620 
  2482 		$_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
  1621 	$expr = "/^$file_prefix/";
  2483 	} elseif ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'Warning! prune_super_cache() not found in wp-cache.php', 1 );
  1622 	if ( ($handle = @opendir( $blog_cache_dir )) ) { 
  2484 
       
  2485 	wp_cache_clean_legacy_files( $blog_cache_dir, $file_prefix );
       
  2486 	wp_cache_clean_legacy_files( $cache_path, $file_prefix );
       
  2487 
       
  2488 }
       
  2489 
       
  2490 function wp_cache_clean_legacy_files( $dir, $file_prefix ) {
       
  2491 	global $wpdb;
       
  2492 	if ( $handle = @opendir( $dir . 'meta/' ) ) { 
  1623 		while ( false !== ($file = readdir($handle))) {
  2493 		while ( false !== ($file = readdir($handle))) {
  1624 			if ( preg_match($expr, $file) ) {
  2494 			if ( preg_match( "/^$file_prefix/", $file ) ) {
  1625 				@unlink( $blog_cache_dir . $file);
  2495 				$meta = unserialize( file_get_contents( $dir . 'meta/' . $file ) );
  1626 				@unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
  2496 				if ( ( defined( 'VHOST' ) || ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) ) && $meta[ 'blog_id' ] != $wpdb->blogid )
       
  2497 					continue;
       
  2498 				@unlink( $dir . 'meta/' . $file);
       
  2499 				@unlink( $dir .  str_replace( '.meta', '.html', $file ) );
  1627 			}
  2500 			}
  1628 		}
  2501 		}
  1629 		closedir($handle);
  2502 		closedir($handle);
  1630 	}
  2503 	}
  1631 }
  2504 }
  1632 
  2505 
  1633 function wp_cache_clean_expired($file_prefix) {
  2506 function wp_cache_clean_expired($file_prefix) {
  1634 	global $cache_path, $cache_max_time, $blog_cache_dir;
  2507 	global $cache_path, $cache_max_time, $blog_cache_dir, $wp_cache_preload_on;
       
  2508 
       
  2509 	if ( $cache_max_time == 0 ) {
       
  2510 		return false;
       
  2511 	}
  1635 
  2512 
  1636 	// If phase2 was compiled, use its function to avoid race-conditions
  2513 	// If phase2 was compiled, use its function to avoid race-conditions
  1637 	if(function_exists('wp_cache_phase2_clean_expired')) {
  2514 	if(function_exists('wp_cache_phase2_clean_expired')) {
  1638 		if (function_exists ('prune_super_cache')) {
  2515 		if ( $wp_cache_preload_on != 1 && function_exists ('prune_super_cache')) {
  1639 			$dir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '',  $_SERVER["HTTP_HOST"]);
  2516 			$dir = get_supercache_dir();
  1640 			if( is_dir( $dir ) ) {
  2517 			if( is_dir( $dir ) ) {
  1641 				prune_super_cache( $dir );
  2518 				prune_super_cache( $dir );
  1642 			} elseif( is_dir( $dir . '.disabled' ) ) {
  2519 			} elseif( is_dir( $dir . '.disabled' ) ) {
  1643 				prune_super_cache( $dir . '.disabled' );
  2520 				prune_super_cache( $dir . '.disabled' );
  1644 			}
  2521 			}
  1692 		return false;
  2569 		return false;
  1693 	}
  2570 	}
  1694 }
  2571 }
  1695 
  2572 
  1696 function wp_super_cache_footer() {
  2573 function wp_super_cache_footer() {
  1697 	?><p id='supercache'><?php printf( __( '%1$s is Digg proof thanks to caching by %2$s', 'wp-super-cache' ), bloginfo( 'name' ), '<a href="http://ocaoimh.ie/wp-super-cache/">WP Super Cache</a>' ); ?></p><?php
  2574 	?><p id='supercache'><?php printf( __( '%1$s is Stephen Fry proof thanks to caching by %2$s', 'wp-super-cache' ), bloginfo( 'name' ), '<a href="http://ocaoimh.ie/wp-super-cache/">WP Super Cache</a>' ); ?></p><?php
  1698 }
  2575 }
  1699 if( isset( $wp_cache_hello_world ) && $wp_cache_hello_world )
  2576 if( isset( $wp_cache_hello_world ) && $wp_cache_hello_world )
  1700 	add_action( 'wp_footer', 'wp_super_cache_footer' );
  2577 	add_action( 'wp_footer', 'wp_super_cache_footer' );
  1701 
  2578 
  1702 if( get_option( 'gzipcompression' ) )
  2579 if( get_option( 'gzipcompression' ) )
  1710 		$wp_cache_404 = true;
  2587 		$wp_cache_404 = true;
  1711 }
  2588 }
  1712 add_action( 'template_redirect', 'wp_cache_catch_404' );
  2589 add_action( 'template_redirect', 'wp_cache_catch_404' );
  1713 
  2590 
  1714 function wp_cache_favorite_action( $actions ) {
  2591 function wp_cache_favorite_action( $actions ) {
  1715 	if( function_exists( 'is_site_admin' ) && !is_site_admin() )
  2592 	if ( false == wpsupercache_site_admin() )
  1716 		return $actions;
  2593 		return $actions;
  1717 
  2594 
  1718 	if( function_exists('current_user_can') && !current_user_can('manage_options') )
  2595 	if ( function_exists('current_user_can') && !current_user_can('manage_options') )
  1719 		return $actions;
  2596 		return $actions;
  1720 
  2597 
  1721 	$actions[ wp_nonce_url( 'options-general.php?page=wpsupercache&wp_delete_cache=1', 'wp-cache' ) ] = array( __( 'Delete Cache', 'wp-super-cache' ), 'manage_options' );
  2598 	$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' );
  1722 
  2599 
  1723 	return $actions;
  2600 	return $actions;
  1724 }
  2601 }
  1725 add_filter( 'favorite_actions', 'wp_cache_favorite_action' );
  2602 add_filter( 'favorite_actions', 'wp_cache_favorite_action' );
  1726 
  2603 
  1742 
  2619 
  1743 function wp_cache_admin_notice() {
  2620 function wp_cache_admin_notice() {
  1744 	global $cache_enabled;
  2621 	global $cache_enabled;
  1745 	if( substr( $_SERVER["PHP_SELF"], -11 ) == 'plugins.php' && !$cache_enabled && function_exists( "admin_url" ) )
  2622 	if( substr( $_SERVER["PHP_SELF"], -11 ) == 'plugins.php' && !$cache_enabled && function_exists( "admin_url" ) )
  1746 		echo '<div class="error"><p><strong>' . sprintf( __('WP Super Cache is disabled. Please go to the <a href="%s">plugin admin page</a> to enable caching.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '</strong></p></div>';
  2623 		echo '<div class="error"><p><strong>' . sprintf( __('WP Super Cache is disabled. Please go to the <a href="%s">plugin admin page</a> to enable caching.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '</strong></p></div>';
       
  2624 
       
  2625 	if ( defined( 'ADVANCEDCACHEPROBLEM' ) )
       
  2626 		echo '<div class="error"><p><strong>' . sprintf( __( 'Warning! WP Super Cache caching broken! The script advanced-cache.php could not load wp-cache-phase1.php.<br /><br />Please edit %1$s/advanced-cache.php and make sure the path to %2$swp-cache-phase1.php is correct.', 'wp-super-cache' ), WP_CONTENT_DIR, WPCACHEHOME ) . '</strong></p></div>';
  1747 }
  2627 }
  1748 add_action( 'admin_notices', 'wp_cache_admin_notice' );
  2628 add_action( 'admin_notices', 'wp_cache_admin_notice' );
  1749 
  2629 
  1750 function wp_cache_check_site() {
  2630 function wp_cache_check_site() {
  1751 	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;
  2631 	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;
  1787 		wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
  2667 		wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
  1788 		if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'scheduled wp_cache_check_site_hook for 360 seconds time.', 2 );
  2668 		if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( 'scheduled wp_cache_check_site_hook for 360 seconds time.', 2 );
  1789 	}
  2669 	}
  1790 }
  2670 }
  1791 add_action( 'wp_cache_check_site_hook', 'wp_cache_check_site' );
  2671 add_action( 'wp_cache_check_site_hook', 'wp_cache_check_site' );
       
  2672 
       
  2673 function update_cached_mobile_ua_list( $mobile_browsers, $mobile_prefixes = 0, $mobile_groups = 0 ) {
       
  2674 	global $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_groups;
       
  2675 	if ( is_array( $mobile_browsers ) ) {
       
  2676 		$wp_cache_mobile_browsers = $mobile_browsers;
       
  2677 		wp_cache_replace_line('^ *\$wp_cache_mobile_browsers', "\$wp_cache_mobile_browsers = '" . implode( ', ', $mobile_browsers ) . "';", $wp_cache_config_file);
       
  2678 	}
       
  2679 	if ( is_array( $mobile_prefixes ) ) {
       
  2680 		$wp_cache_mobile_prefixes = $mobile_prefixes;
       
  2681 		wp_cache_replace_line('^ *\$wp_cache_mobile_prefixes', "\$wp_cache_mobile_prefixes = '" . implode( ', ', $mobile_prefixes ) . "';", $wp_cache_config_file);
       
  2682 	}
       
  2683 	if ( is_array( $mobile_groups ) ) {
       
  2684 		$wp_cache_mobile_groups = $mobile_groups;
       
  2685 		wp_cache_replace_line('^ *\$wp_cache_mobile_groups', "\$wp_cache_mobile_groups = '" . implode( ', ', $mobile_groups ) . "';", $wp_cache_config_file);
       
  2686 	}
       
  2687 	
       
  2688 	return true;
       
  2689 }
       
  2690 
       
  2691 function wpsc_update_htaccess() {
       
  2692 	extract( wpsc_get_htaccess_info() );
       
  2693 	wpsc_remove_marker( $home_path.'.htaccess', 'WordPress' ); // remove original WP rules so SuperCache rules go on top
       
  2694 	if( insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', explode( "\n", $rules ) ) && insert_with_markers( $home_path.'.htaccess', 'WordPress', explode( "\n", $wprules ) ) ) {
       
  2695 		return true;
       
  2696 	} else {
       
  2697 		return false;
       
  2698 	}
       
  2699 }
       
  2700 
       
  2701 function wpsc_update_htaccess_form( $short_form = true ) {
       
  2702 	global $wpmu_version;
       
  2703 
       
  2704 	extract( wpsc_get_htaccess_info() );
       
  2705 	if( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) {
       
  2706 		echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><h4>" . __( 'Cannot update .htaccess', 'wp-super-cache' ) . "</h4><p>" . sprintf( __( 'The file <code>%s.htaccess</code> cannot be modified by the web server. Please correct this using the chmod command or your ftp client.', 'wp-super-cache' ), $home_path ) . "</p><p>" . __( 'Refresh this page when the file permissions have been modified.' ) . "</p><p>" . sprintf( __( 'Alternatively, you can edit your <code>%s.htaccess</code> file manually and add the following code (before any WordPress rules):', 'wp-super-cache' ), $home_path ) . "</p>";
       
  2707 		echo "<p><pre># BEGIN WPSuperCache\n" . esc_html( $rules ) . "# END WPSuperCache</pre></p></div>";
       
  2708 	} else {
       
  2709 		if ( $short_form == false ) {
       
  2710 			echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><p>" . sprintf( __( 'To serve static html files your server must have the correct mod_rewrite rules added to a file called <code>%s.htaccess</code>', 'wp-super-cache' ), $home_path ) . " ";
       
  2711 			_e( "You can edit the file yourself add the following rules.", 'wp-super-cache' );
       
  2712 			echo __( " Make sure they appear before any existing WordPress rules. ", 'wp-super-cache' ) . "</p>";
       
  2713 			echo "<pre># BEGIN WPSuperCache\n" . esc_html( $rules ) . "# END WPSuperCache</pre></p>";
       
  2714 			echo "<p>" . sprintf( __( 'Rules must be added to %s too:', 'wp-super-cache' ), WP_CONTENT_DIR . "/cache/.htaccess" ) . "</p>";
       
  2715 			echo "<pre># BEGIN supercache\n" . esc_html( $gziprules ) . "# END supercache</pre></p>";
       
  2716 		}
       
  2717 		if ( !isset( $wpmu_version ) || $wpmu_version == '' ) {
       
  2718 			echo '<form name="updatehtaccess" action="#modrewrite" method="post">';
       
  2719 			echo '<input type="hidden" name="updatehtaccess" value="1" />';
       
  2720 			echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'id="updatehtaccess" value="' . __( 'Update Mod_Rewrite Rules', 'wp-super-cache' ) . ' &raquo;" /></div>';
       
  2721 			wp_nonce_field('wp-cache');
       
  2722 			echo "</form></div>\n";
       
  2723 		}
       
  2724 	}
       
  2725 }
       
  2726 
       
  2727 function wpsc_get_htaccess_info() {
       
  2728 	global $wp_cache_mobile_enabled, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_disable_utf8;
       
  2729 	if ( isset( $_SERVER[ "PHP_DOCUMENT_ROOT" ] ) ) {
       
  2730 		$document_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
       
  2731 		$apache_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
       
  2732 	} else {
       
  2733 		$document_root = $_SERVER[ "DOCUMENT_ROOT" ];
       
  2734 		$apache_root = '%{DOCUMENT_ROOT}';
       
  2735 	}
       
  2736 	$content_dir_root = $document_root;
       
  2737 	if ( strpos( $document_root, '/kunden/' ) === 0 ) {
       
  2738 		// http://wordpress.org/support/topic/plugin-wp-super-cache-how-to-get-mod_rewrite-working-on-1and1-shared-hosting?replies=1
       
  2739 		// On 1and1, PHP's directory structure starts with '/homepages'. The
       
  2740 		// Apache directory structure has an extra '/kunden' before it.
       
  2741 		// Also 1and1 does not support the %{DOCUMENT_ROOT} variable in
       
  2742 		// .htaccess files.
       
  2743 		// This prevents the $inst_root from being calculated correctly and
       
  2744 		// means that the $apache_root is wrong.
       
  2745 		//
       
  2746 		// e.g. This is an example of how Apache and PHP see the directory
       
  2747 		// structure on	1and1:
       
  2748 		// Apache: /kunden/homepages/xx/dxxxxxxxx/htdocs/site1/index.html
       
  2749 		// PHP:           /homepages/xx/dxxxxxxxx/htdocs/site1/index.html
       
  2750 		// Here we fix up the paths to make mode_rewrite work on 1and1 shared hosting.
       
  2751 		$content_dir_root = substr( $content_dir_root, 7 );
       
  2752 		$apache_root = $document_root;
       
  2753 	}
       
  2754 	$home_path = get_home_path();
       
  2755 	$home_root = parse_url(get_bloginfo('url'));
       
  2756 	$home_root = isset( $home_root['path'] ) ? trailingslashit( $home_root['path'] ) : '/';
       
  2757 	$home_root_lc = str_replace( '//', '/', strtolower( $home_root ) );
       
  2758 	$inst_root = str_replace( '//', '/', '/' . trailingslashit( str_replace( $content_dir_root, '', str_replace( '\\', '/', WP_CONTENT_DIR ) ) ) );
       
  2759 	$wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) );
       
  2760 	$wprules = str_replace( "RewriteEngine On\n", '', $wprules );
       
  2761 	$wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
       
  2762 	$scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
       
  2763 
       
  2764 	if( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
       
  2765 		$condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*[^/]$";
       
  2766 		$condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*//.*$";
       
  2767 	}
       
  2768 	$condition_rules[] = "RewriteCond %{REQUEST_METHOD} !POST";
       
  2769 	$condition_rules[] = "RewriteCond %{QUERY_STRING} !.*=.*";
       
  2770 	$condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$";
       
  2771 	$condition_rules[] = "RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\\\"]+ [NC]";
       
  2772 	$condition_rules[] = "RewriteCond %{HTTP:Profile} !^[a-z0-9\\\"]+ [NC]";
       
  2773 	if ( $wp_cache_mobile_enabled ) {
       
  2774 		if ( false == empty( $wp_cache_mobile_browsers ) ) 
       
  2775 			$condition_rules[] = "RewriteCond %{HTTP_USER_AGENT} !^.*(" . addcslashes( implode( '|', $wp_cache_mobile_browsers ), ' ' ) . ").* [NC]";
       
  2776 		if ( false == empty( $wp_cache_mobile_prefixes ) ) 
       
  2777 			$condition_rules[] = "RewriteCond %{HTTP_user_agent} !^(" . addcslashes( implode( '|', $wp_cache_mobile_prefixes ), ' ' ) . ").* [NC]";
       
  2778 	}
       
  2779 	$condition_rules = apply_filters( 'supercacherewriteconditions', $condition_rules );
       
  2780 
       
  2781 	$rules = "<IfModule mod_rewrite.c>\n";
       
  2782 	$rules .= "RewriteEngine On\n";
       
  2783 	$rules .= "RewriteBase $home_root\n"; // props Chris Messina
       
  2784 	$rules .= "#If you serve pages from behind a proxy you may want to change 'RewriteCond %{HTTPS} on' to something more sensible\n";
       
  2785 	if ( isset( $wp_cache_disable_utf8 ) == false || $wp_cache_disable_utf8 == 0 ) {
       
  2786 		$charset = get_option('blog_charset') == '' ? 'UTF-8' : get_option('blog_charset');
       
  2787 		$rules .= "AddDefaultCharset {$charset}\n";
       
  2788 	}
       
  2789 
       
  2790 	$rules .= "CONDITION_RULES";
       
  2791 	$rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
       
  2792 	$rules .= "RewriteCond %{HTTPS} on\n";
       
  2793 	$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html.gz -f\n";
       
  2794 	$rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html.gz\" [L]\n\n";
       
  2795 
       
  2796 	$rules .= "CONDITION_RULES";
       
  2797 	$rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
       
  2798 	$rules .= "RewriteCond %{HTTPS} !on\n";
       
  2799 	$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html.gz -f\n";
       
  2800 	$rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html.gz\" [L]\n\n";
       
  2801 
       
  2802 	$rules .= "CONDITION_RULES";
       
  2803 	$rules .= "RewriteCond %{HTTPS} on\n";
       
  2804 	$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html -f\n";
       
  2805 	$rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html\" [L]\n\n";
       
  2806 
       
  2807 	$rules .= "CONDITION_RULES";
       
  2808 	$rules .= "RewriteCond %{HTTPS} !on\n";
       
  2809 	$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html -f\n";
       
  2810 	$rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html\" [L]\n";
       
  2811 	$rules .= "</IfModule>\n";
       
  2812 	$rules = apply_filters( 'supercacherewriterules', $rules );
       
  2813 
       
  2814 	$rules = str_replace( "CONDITION_RULES", implode( "\n", $condition_rules ) . "\n", $rules );
       
  2815 
       
  2816 	$gziprules =  "<IfModule mod_mime.c>\n  <FilesMatch \"\\.html\\.gz\$\">\n    ForceType text/html\n    FileETag None\n  </FilesMatch>\n  AddEncoding gzip .gz\n  AddType text/html .gz\n</IfModule>\n";
       
  2817 	$gziprules .= "<IfModule mod_deflate.c>\n  SetEnvIfNoCase Request_URI \.gz$ no-gzip\n</IfModule>\n";
       
  2818 	$gziprules .= "<IfModule mod_headers.c>\n  Header set Vary \"Accept-Encoding, Cookie\"\n  Header set Cache-Control 'max-age=3, must-revalidate'\n</IfModule>\n";
       
  2819 	$gziprules .= "<IfModule mod_expires.c>\n  ExpiresActive On\n  ExpiresByType text/html A3\n</IfModule>\n";
       
  2820 	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 );
       
  2821 }
       
  2822 
       
  2823 function clear_post_supercache( $post_id ) {
       
  2824 	$dir = get_current_url_supercache_dir( $post_id );
       
  2825 	if ( false == @is_dir( $dir ) )
       
  2826 		return false;
       
  2827 
       
  2828 	if ( !function_exists( 'prune_super_cache' ) )
       
  2829 		include_once( 'wp-cache-phase2.php' );
       
  2830 
       
  2831 	if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "clear_post_supercache: deleting $dir/index*.html files", 2 );
       
  2832 	$files_to_check = get_all_supercache_filenames( $dir );
       
  2833 	foreach( $files_to_check as $cache_file ) {
       
  2834 		prune_super_cache( $dir . $cache_file, true ); 
       
  2835 	}
       
  2836 }
       
  2837 
       
  2838 function wp_cron_preload_cache() {
       
  2839 	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;
       
  2840 	global $WPSC_HTTP_HOST;
       
  2841 
       
  2842 	if ( get_option( 'preload_cache_stop' ) ) {
       
  2843 		delete_option( 'preload_cache_stop' );
       
  2844 		if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cron_preload_cache: preload cancelled", 1 );
       
  2845 		return true;
       
  2846 	}
       
  2847 	$mutex = $cache_path . "preload_mutex.tmp";
       
  2848 	sleep( 3 + mt_rand( 1, 5 ) );
       
  2849 	if ( @file_exists( $mutex ) ) {
       
  2850 		if ( @filemtime( $mutex ) > ( time() - 600 ) ) {
       
  2851 			if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cron_preload_cache: preload mutex found and less than 600 seconds old. Aborting preload.", 1 );
       
  2852 			return true;
       
  2853 		} else {
       
  2854 			if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cron_preload_cache: old preload mutex found and deleted. Preload continues.", 1 );
       
  2855 			@unlink( $mutex );
       
  2856 		}
       
  2857 	}
       
  2858 	$fp = @fopen( $mutex, 'w' );
       
  2859 	@fclose( $fp );
       
  2860 
       
  2861 	$counter = get_option( 'preload_cache_counter' );
       
  2862 	if ( is_array( $counter ) == false ) {
       
  2863 		if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cron_preload_cache: setting up preload for the first time!", 5 );
       
  2864 		$counter = array( 'c' => 0, 't' => time() );
       
  2865 		update_option( 'preload_cache_counter', $counter );
       
  2866 	}
       
  2867 	$c = $counter[ 'c' ];
       
  2868 
       
  2869 	update_option( 'preload_cache_counter', array( 'c' => ( $c + 100 ), 't' => time() ) );
       
  2870 
       
  2871 	if ( $wp_cache_preload_email_me && $c == 0 )
       
  2872 		wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Started', 'wp-super-cache' ), site_url(), '' ), ' ' );
       
  2873 
       
  2874 	if ( $wp_cache_preload_posts == 'all' || $c < $wp_cache_preload_posts ) {
       
  2875 		if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cron_preload_cache: doing taxonomy preload.", 5 );
       
  2876 		$permalink_counter_msg = $cache_path . "preload_permalink.txt";
       
  2877 		if ( isset( $wp_cache_preload_taxonomies ) && $wp_cache_preload_taxonomies ) {
       
  2878 			$taxonomies = apply_filters( 'wp_cache_preload_taxonomies', array( 'post_tag' => 'tag', 'category' => 'category' ) );
       
  2879 			foreach( $taxonomies as $taxonomy => $path ) {
       
  2880 				$taxonomy_filename = $cache_path . "taxonomy_" . $taxonomy . ".txt";
       
  2881 				if ( $c == 0 )
       
  2882 					@unlink( $taxonomy_filename );
       
  2883 
       
  2884 				if ( false == @file_exists( $taxonomy_filename ) ) {
       
  2885 					$out = '';
       
  2886 					$records = get_terms( $taxonomy );
       
  2887 					foreach( $records as $term ) {
       
  2888 						$out .= get_term_link( $term ). "\n";
       
  2889 					}
       
  2890 					$fp = fopen( $taxonomy_filename, 'w' );
       
  2891 					if ( $fp ) {
       
  2892 						fwrite( $fp, $out );
       
  2893 						fclose( $fp );
       
  2894 					}
       
  2895 					$details = explode( "\n", $out );
       
  2896 				} else {
       
  2897 					$details = explode( "\n", file_get_contents( $taxonomy_filename ) );
       
  2898 				}
       
  2899 				if ( count( $details ) != 1 && $details[ 0 ] != '' ) {
       
  2900 					$rows = array_splice( $details, 0, 50 );
       
  2901 					if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume == 'many' )
       
  2902 						wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Refreshing %2$s taxonomy from %3$d to %4$d', 'wp-super-cache' ), site_url(), $taxonomy, $c, ($c+100) ), 'Refreshing: ' . print_r( $rows, 1 ) );
       
  2903 					foreach( (array)$rows as $url ) {
       
  2904 						set_time_limit( 60 );
       
  2905 						if ( $url == '' )
       
  2906 							continue;
       
  2907 						$url_info = parse_url( $url );
       
  2908 						$dir = get_supercache_dir() . $url_info[ 'path' ];
       
  2909 						if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cron_preload_cache: delete $dir", 5 );
       
  2910 						prune_super_cache( $dir );
       
  2911 						$fp = @fopen( $permalink_counter_msg, 'w' );
       
  2912 						if ( $fp ) {
       
  2913 							@fwrite( $fp, "$taxonomy: $url" );
       
  2914 							@fclose( $fp );
       
  2915 						}
       
  2916 						wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
       
  2917 						if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cron_preload_cache: fetched $url", 5 );
       
  2918 						sleep( 1 );
       
  2919 					}
       
  2920 					$fp = fopen( $taxonomy_filename, 'w' );
       
  2921 					if ( $fp ) {
       
  2922 						fwrite( $fp, implode( "\n", $details ) );
       
  2923 						fclose( $fp );
       
  2924 					}
       
  2925 				}
       
  2926 			}
       
  2927 		}
       
  2928 	}
       
  2929 
       
  2930 	if ( $wp_cache_preload_posts == 'all' || $c < $wp_cache_preload_posts ) {
       
  2931 		$posts = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE ( post_type != 'revision' AND post_type != 'nav_menu_item' ) AND post_status = 'publish' ORDER BY ID ASC LIMIT $c, 100" );
       
  2932 		if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cron_preload_cache: got 100 posts from position $c.", 5 );
       
  2933 	} else {
       
  2934 		if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cron_preload_cache: no more posts to get. Limit ($wp_cache_preload_posts) reached.", 5 );
       
  2935 		$posts = false;
       
  2936 	}
       
  2937 	if ( !isset( $wp_cache_preload_email_volume ) )
       
  2938 		$wp_cache_preload_email_volume = 'medium';
       
  2939 
       
  2940 	if ( $posts ) {
       
  2941 		if ( get_option( 'show_on_front' ) == 'page' ) {
       
  2942 			$page_on_front = get_option( 'page_on_front' );
       
  2943 			$page_for_posts = get_option( 'page_for_posts' );
       
  2944 		} else {
       
  2945 			$page_on_front = $page_for_posts = 0;
       
  2946 		}
       
  2947 		if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume == 'many' )
       
  2948 			wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Refreshing posts from %2$d to %3$d', 'wp-super-cache' ), site_url(), $c, ($c+100) ), ' ' );
       
  2949 		$msg = '';
       
  2950 		$count = $c + 1;
       
  2951 		$permalink_counter_msg = $cache_path . "preload_permalink.txt";
       
  2952 		foreach( $posts as $post_id ) {
       
  2953 			set_time_limit( 60 );
       
  2954 			if ( $page_on_front != 0 && ( $post_id == $page_on_front || $post_id == $page_for_posts ) )
       
  2955 				continue;
       
  2956 			clear_post_supercache( $post_id );
       
  2957 			$url = get_permalink( $post_id );
       
  2958 			$fp = @fopen( $permalink_counter_msg, 'w' );
       
  2959 			if ( $fp ) {
       
  2960 				@fwrite( $fp, $count . " " . $url );
       
  2961 				@fclose( $fp );
       
  2962 			}
       
  2963 			if ( @file_exists( $cache_path . "stop_preload.txt" ) ) {
       
  2964 				if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cron_preload_cache: cancelling preload. stop_preload.txt found.", 5 );
       
  2965 				@unlink( $mutex );
       
  2966 				@unlink( $cache_path . "stop_preload.txt" );
       
  2967 				update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
       
  2968 				if ( $wp_cache_preload_email_me )
       
  2969 					wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Stopped', 'wp-super-cache' ), site_url(), '' ), ' ' );
       
  2970 				return true;
       
  2971 			}
       
  2972 			$msg .= "$url\n";
       
  2973 			wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
       
  2974 			if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cron_preload_cache: fetched $url", 5 );
       
  2975 			sleep( 1 );
       
  2976 			$count++;
       
  2977 		}
       
  2978 		if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume != 'less' )
       
  2979 			wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] %2$d posts refreshed', 'wp-super-cache' ), $WPSC_HTTP_HOST, ($c+100) ), __( "Refreshed the following posts:", 'wp-super-cache' ) . "\n$msg" );
       
  2980 		if ( defined( 'DOING_CRON' ) ) {
       
  2981 			if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cron_preload_cache: scheduling the next preload in 30 seconds.", 5 );
       
  2982 			wp_schedule_single_event( time() + 30, 'wp_cache_preload_hook' );
       
  2983 		}
       
  2984 	} else {
       
  2985 		$msg = '';
       
  2986 		update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
       
  2987 		if ( (int)$wp_cache_preload_interval && defined( 'DOING_CRON' ) ) {
       
  2988 			if ( $wp_cache_preload_email_me )
       
  2989 				$msg = sprintf( __( 'Scheduling next preload refresh in %d minutes.', 'wp-super-cache' ), (int)$wp_cache_preload_interval );
       
  2990 			if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cron_preload_cache: no more posts. scheduling next preload in $wp_cache_preload_interval minutes.", 5 );
       
  2991 			wp_schedule_single_event( time() + ( (int)$wp_cache_preload_interval * 60 ), 'wp_cache_full_preload_hook' );
       
  2992 		}
       
  2993 		global $file_prefix, $cache_max_time;
       
  2994 		if ( $wp_cache_preload_interval > 0 ) {
       
  2995 			$cache_max_time = (int)$wp_cache_preload_interval * 60; // fool the GC into expiring really old files
       
  2996 		} else {
       
  2997 			$cache_max_time = 86400; // fool the GC into expiring really old files
       
  2998 		}
       
  2999 		if ( $wp_cache_preload_email_me )
       
  3000 			wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Cache Preload Completed', 'wp-super-cache' ), site_url() ), __( "Cleaning up old supercache files.", 'wp-super-cache' ) . "\n" . $msg );
       
  3001 		if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cron_preload_cache: clean expired cache files older than $cache_max_time seconds.", 5 );
       
  3002 		wp_cache_phase2_clean_expired( $file_prefix, true ); // force cleanup of old files.
       
  3003 	}
       
  3004 	@unlink( $mutex );
       
  3005 }
       
  3006 add_action( 'wp_cache_preload_hook', 'wp_cron_preload_cache' );
       
  3007 add_action( 'wp_cache_full_preload_hook', 'wp_cron_preload_cache' );
       
  3008 
       
  3009 function next_preload_message( $hook, $text, $limit = 0 ) {
       
  3010 	global $currently_preloading, $wp_cache_preload_interval;
       
  3011 	if ( $next_preload = wp_next_scheduled( $hook ) ) {
       
  3012 		$next_time = $next_preload - time();
       
  3013 		if ( $limit != 0 && $next_time > $limit )
       
  3014 			return false;
       
  3015 		$h = $m = $s = 0;
       
  3016 		if ( $next_time > 0 ) {
       
  3017 			// http://bytes.com/topic/php/answers/3917-seconds-converted-hh-mm-ss
       
  3018 			$m = (int)($next_time / 60);
       
  3019 			$s = $next_time % 60;
       
  3020 			$h = (int)($m / 60); $m = $m % 60;
       
  3021 		}
       
  3022 		if ( $next_time > 0 && $next_time < ( 60 * $wp_cache_preload_interval ) )
       
  3023 			echo '<p><strong>' . sprintf( $text, $h, $m, $s ) . '</strong></p>';
       
  3024 		if ( ( $next_preload - time() ) <= 60 )
       
  3025 			$currently_preloading = true;
       
  3026 	}
       
  3027 }
       
  3028 
       
  3029 function option_preload_cache_counter( $value ) {
       
  3030 	if ( false == is_array( $value ) ) {
       
  3031 		$ret = array( 'c' => $value, 't' => time(), 'first' => 1 );
       
  3032 		return $ret;
       
  3033 	}
       
  3034 
       
  3035 	return $value;
       
  3036 }
       
  3037 add_filter( 'option_preload_cache_counter', 'option_preload_cache_counter' );
       
  3038 
       
  3039 function check_up_on_preloading() {
       
  3040 	$value = get_option( 'preload_cache_counter' );
       
  3041 	if ( $value[ 'c' ] > 0 && ( time() - $value[ 't' ] ) > 3600 && false == wp_next_scheduled( 'wp_cache_preload_hook' ) ) {
       
  3042 		if ( is_admin() )
       
  3043 			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" ) ) );
       
  3044 		wp_schedule_single_event( time() + 30, 'wp_cache_preload_hook' );
       
  3045 	}
       
  3046 }
       
  3047 add_action( 'init', 'check_up_on_preloading' ); // sometimes preloading stops working. Kickstart it.
       
  3048 
       
  3049 function wp_cache_disable_plugin() {
       
  3050 	global $wp_cache_config_file, $wp_rewrite;
       
  3051 	if ( file_exists( ABSPATH . 'wp-config.php') ) {
       
  3052 		$global_config_file = ABSPATH . 'wp-config.php';
       
  3053 	} else {
       
  3054 		$global_config_file = dirname(ABSPATH) . '/wp-config.php';
       
  3055 	}
       
  3056 	$line = 'define(\'WP_CACHE\', true);';
       
  3057 	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 ) ) )
       
  3058 		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." );
       
  3059 
       
  3060 	uninstall_supercache( WP_CONTENT_DIR . '/cache' );
       
  3061 	$file_not_deleted = false;
       
  3062 	if ( @file_exists( WP_CONTENT_DIR . "/advanced-cache.php" ) ) {
       
  3063 		if ( false == @unlink( WP_CONTENT_DIR . "/advanced-cache.php" ) )
       
  3064 			$file_not_deleted[] = 'advanced-cache.php';
       
  3065 	}
       
  3066 	if ( @file_exists( WP_CONTENT_DIR . "/wp-cache-config.php" ) ) {
       
  3067 		if ( false == unlink( WP_CONTENT_DIR . "/wp-cache-config.php" ) )
       
  3068 			$file_not_deleted[] = 'wp-cache-config.php';
       
  3069 	}
       
  3070 	if ( $file_not_deleted ) {
       
  3071 		$msg = "<p>One or more files could not be deleted. These files and directories must be made writeable:</p>\n <ol><li>" . WP_CONTENT_DIR . "</li>\n";
       
  3072 		$code = "<ul>\n";
       
  3073 		foreach( (array)$file_not_deleted as $filename ) {
       
  3074 			$msg .= "<li>" . WP_CONTENT_DIR . "/{$filename}</li>";
       
  3075 			$code .= "<li><code>chmod 666 " . WP_CONTENT_DIR . "/{$filename}</code></li>\n";
       
  3076 		}
       
  3077 		$code .= "</ul>\n";
       
  3078 		
       
  3079 		$msg .= "</ol>\n<p>First try fixing the directory permissions with this command and refresh this page:<br /><br /><code>chmod 777 " . WP_CONTENT_DIR . "</code><br /><br />If you still see this error, you have to fix the permissions on the files themselves and refresh this page again:</p> {$code}\n<p>Don't forgot to fix things later:<br /><code>chmod 755 " . WP_CONTENT_DIR . "</code></p><p>If you don't know what <strong>chmod</strong> is use <a href='http://www.google.ie/search?hl=en&q=ftp+chmod+777'>this Google search</a> to find out all about it.</p><p>Please refresh this page when the permissions have been modified.</p>";
       
  3080 		wp_die( $msg );
       
  3081 	}
       
  3082 	extract( wpsc_get_htaccess_info() );
       
  3083 	if ( $scrules != '' && insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', array() ) ) {
       
  3084 		$wp_rewrite->flush_rules();
       
  3085 	} elseif( $scrules != '' ) {
       
  3086 		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/extend/plugins/wp-super-cache/", 'wp-super-cache' ), ABSPATH . '/.htaccess' ) );
       
  3087 	}
       
  3088 }
       
  3089 
       
  3090 function uninstall_supercache( $folderPath ) { // from http://www.php.net/manual/en/function.rmdir.php
       
  3091 	if ( trailingslashit( constant( 'ABSPATH' ) ) == trailingslashit( $folderPath ) )
       
  3092 		return false;
       
  3093 	if ( @is_dir ( $folderPath ) ) {
       
  3094 		$dh  = @opendir($folderPath);
       
  3095 		while( false !== ( $value = @readdir( $dh ) ) ) {
       
  3096 			if ( $value != "." && $value != ".." ) {
       
  3097 				$value = $folderPath . "/" . $value; 
       
  3098 				if ( @is_dir ( $value ) ) {
       
  3099 					uninstall_supercache( $value );
       
  3100 				} else {
       
  3101 					@unlink( $value );
       
  3102 				}
       
  3103 			}
       
  3104 		}
       
  3105 		return @rmdir( $folderPath );
       
  3106 	} else {
       
  3107 		return false;
       
  3108 	}
       
  3109 }
       
  3110 
       
  3111 function supercache_admin_bar_render() {
       
  3112 	global $wp_admin_bar, $wp_cache_not_logged_in;
       
  3113 	if ( !is_user_logged_in() || !$wp_cache_not_logged_in ) 
       
  3114 		return false;
       
  3115 
       
  3116 	if ( function_exists('current_user_can') && false == current_user_can('delete_others_posts') )
       
  3117 		return false;
       
  3118 
       
  3119 	$wp_admin_bar->add_menu( array(
       
  3120 				'parent' => '',
       
  3121 				'id' => 'delete-cache',
       
  3122 				'title' => __( 'Delete Cache', 'wp-super-cache' ),
       
  3123 				'meta' => array( 'title' => __( 'Delete cache of the current page', 'wp-super-cache' ) ),
       
  3124 				'href' => wp_nonce_url( admin_url( 'index.php?action=delcachepage&path=' . urlencode( $_SERVER[ 'REQUEST_URI' ] ) ), 'delete-cache' )
       
  3125 				) );
       
  3126 }
       
  3127 add_action( 'wp_before_admin_bar_render', 'supercache_admin_bar_render' );
       
  3128 
  1792 ?>
  3129 ?>