PageRenderTime 44ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/wp-super-cache/wp-cache.php

https://github.com/JeffLuckett/quickref
PHP | 2558 lines | 2334 code | 177 blank | 47 comment | 577 complexity | ef7d803ef21b67d81854aebd16500614 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0
  1. <?php
  2. /*
  3. Plugin Name: WP Super Cache
  4. Plugin URI: http://ocaoimh.ie/wp-super-cache/
  5. Description: Very fast caching plugin for WordPress.
  6. Version: 0.9.9.7
  7. Author: Donncha O Caoimh
  8. Author URI: http://ocaoimh.ie/
  9. */
  10. /* Copyright 2005-2006 Ricardo Galli Granada (email : gallir@uib.es)
  11. Copyright 2007-2010 Donncha O Caoimh (http://ocaoimh.ie/) and many others.
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. // Pre-2.6 compatibility
  25. if( !defined('WP_CONTENT_URL') )
  26. define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
  27. if( !defined('WP_CONTENT_DIR') )
  28. define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
  29. $wp_cache_config_file = WP_CONTENT_DIR . '/wp-cache-config.php';
  30. if( !@include($wp_cache_config_file) ) {
  31. get_wpcachehome();
  32. $wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
  33. @include($wp_cache_config_file_sample);
  34. } else {
  35. get_wpcachehome();
  36. }
  37. $wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
  38. $wp_cache_link = WP_CONTENT_DIR . '/advanced-cache.php';
  39. $wp_cache_file = WPCACHEHOME . 'advanced-cache.php';
  40. if( !defined( 'WP_CACHE' ) || ( defined( 'WP_CACHE' ) && constant( 'WP_CACHE' ) == false ) ) {
  41. $wp_cache_check_wp_config = true;
  42. }
  43. include(WPCACHEHOME . 'wp-cache-base.php');
  44. function wp_super_cache_text_domain() {
  45. load_plugin_textdomain( 'wp-super-cache', WPCACHEHOME . 'languages', basename( dirname( __FILE__ ) ) . '/languages' );
  46. }
  47. add_action( 'init', 'wp_super_cache_text_domain' );
  48. // OSSDL CDN plugin (http://wordpress.org/extend/plugins/ossdl-cdn-off-linker/)
  49. include_once( WPCACHEHOME . 'ossdl-cdn.php' );
  50. // from legolas558 d0t users dot sf dot net at http://www.php.net/is_writable
  51. function is_writeable_ACLSafe($path) {
  52. // PHP's is_writable does not work with Win32 NTFS
  53. if ($path{strlen($path)-1}=='/') // recursively return a temporary file path
  54. return is_writeable_ACLSafe($path.uniqid(mt_rand()).'.tmp');
  55. else if (is_dir($path))
  56. return is_writeable_ACLSafe($path.'/'.uniqid(mt_rand()).'.tmp');
  57. // check tmp file for read/write capabilities
  58. $rm = file_exists($path);
  59. $f = @fopen($path, 'a');
  60. if ($f===false)
  61. return false;
  62. fclose($f);
  63. if (!$rm)
  64. unlink($path);
  65. return true;
  66. }
  67. function get_wpcachehome() {
  68. if( defined( 'WPCACHEHOME' ) == false ) {
  69. if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
  70. define( 'WPCACHEHOME', trailingslashit( dirname(__FILE__) ) );
  71. } elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
  72. define( 'WPCACHEHOME', dirname(__FILE__) . '/wp-super-cache/' );
  73. } else {
  74. die( sprintf( __( 'Please create %s /wp-cache-config.php from wp-super-cache/wp-cache-config-sample.php', 'wp-super-cache' ), WP_CONTENT_DIR ) );
  75. }
  76. }
  77. }
  78. function wpsupercache_deactivate() {
  79. global $wp_cache_config_file, $wp_cache_link, $cache_path;
  80. $files = array( $wp_cache_config_file, $wp_cache_link );
  81. foreach( $files as $file ) {
  82. if( file_exists( $file ) )
  83. unlink( $file );
  84. }
  85. if( !function_exists( 'prune_super_cache' ) )
  86. include_once( 'wp-cache-phase2.php' );
  87. prune_super_cache ($cache_path, true);
  88. @unlink( $cache_path . '.htaccess' );
  89. @unlink( $cache_path . 'meta' );
  90. @unlink( $cache_path . 'supercache' );
  91. wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
  92. }
  93. register_deactivation_hook( __FILE__, 'wpsupercache_deactivate' );
  94. function wpsupercache_activate() {
  95. }
  96. register_activation_hook( __FILE__, 'wpsupercache_activate' );
  97. function wpsupercache_site_admin() {
  98. if ( function_exists( 'is_super_admin' ) ) {
  99. return is_super_admin();
  100. } elseif ( function_exists( 'is_site_admin' ) ) {
  101. return is_site_admin();
  102. } else {
  103. return true;
  104. }
  105. }
  106. function wp_cache_add_pages() {
  107. global $wpmu_version;
  108. if ( function_exists( 'is_multisite' ) && is_multisite() && wpsupercache_site_admin() ) {
  109. add_submenu_page( 'ms-admin.php', 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager' );
  110. } elseif ( isset( $wpmu_version ) && wpsupercache_site_admin() ) {
  111. add_submenu_page( 'wpmu-admin.php', 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager' );
  112. } else {
  113. add_options_page( 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
  114. }
  115. }
  116. add_action('admin_menu', 'wp_cache_add_pages');
  117. function wp_cache_manager_error_checks() {
  118. 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;
  119. if ( !wpsupercache_site_admin() )
  120. return false;
  121. if ( 1 == ini_get( 'safe_mode' ) || "on" == strtolower( ini_get( 'safe_mode' ) ) ) {
  122. echo '<div id="message" class="updated fade"><h3>' . __( 'Warning! PHP Safe Mode Enabled!', 'wp-super-cache' ) . '</h3><p>' .
  123. __( 'You may experience problems running this plugin because SAFE MODE is enabled.', 'wp-super-cache' ) . ' ';
  124. if( !ini_get( 'safe_mode_gid' ) ) {
  125. _e( 'Your server is set up to check the owner of PHP scripts before allowing them to read and write files.', 'wp-super-cache' ) . " ";
  126. 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 );
  127. } else {
  128. _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' );
  129. }
  130. echo '</p></div>';
  131. }
  132. if ( '' == get_option( 'permalink_structure' ) ) {
  133. echo '<div id="message" class="updated fade"><h3>' . __( 'Permlink Structure Error', 'wp-super-cache' ) . '</h3>';
  134. 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>";
  135. echo '</div>';
  136. return false;
  137. }
  138. if( $wp_cache_debug || !$wp_cache_cron_check ) {
  139. if( function_exists( "wp_remote_get" ) == false ) {
  140. $hostname = str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'siteurl' ) ) );
  141. if( strpos( $hostname, '/' ) )
  142. $hostname = substr( $hostname, 0, strpos( $hostname, '/' ) );
  143. $ip = gethostbyname( $hostname );
  144. if( substr( $ip, 0, 3 ) == '127' || substr( $ip, 0, 7 ) == '192.168' ) {
  145. ?><div id="message" class="updated fade"><h3><?php printf( __( 'Warning! Your hostname "%s" resolves to %s', 'wp-super-cache' ), $hostname, $ip ); ?></h3>
  146. <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>
  147. <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>
  148. </div>
  149. <?php
  150. return false;
  151. } else {
  152. wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
  153. }
  154. } else {
  155. $cron_url = get_option( 'siteurl' ) . '/wp-cron.php?check=' . wp_hash('187425');
  156. $cron = wp_remote_get($cron_url, array('timeout' => 0.01, 'blocking' => true));
  157. if( is_array( $cron ) ) {
  158. if( $cron[ 'response' ][ 'code' ] == '404' ) {
  159. ?><div id="message" class="updated fade"><h3>Warning! wp-cron.php not found!</h3>
  160. <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>
  161. <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>
  162. </div>
  163. <?php
  164. return false;
  165. } else {
  166. wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
  167. }
  168. }
  169. }
  170. }
  171. if ( !wp_cache_check_link() ||
  172. !wp_cache_verify_config_file() ||
  173. !wp_cache_verify_cache_dir() ) {
  174. echo '<p>' . __( "Cannot continue... fix previous problems and retry.", 'wp-super-cache' ) . '</p>';
  175. return false;
  176. }
  177. if (!wp_cache_check_global_config()) {
  178. return false;
  179. }
  180. if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) {
  181. ?><div id="message" class="updated fade"><h3><?php _e( 'Zlib Output Compression Enabled!', 'wp-super-cache' ); ?></h3>
  182. <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
  183. }
  184. if( $cache_enabled == true && $super_cache_enabled == true && $wp_cache_mod_rewrite && !got_mod_rewrite() ) {
  185. ?><div id="message" class="updated fade"><h3><?php _e( 'Mod rewrite may not be installed!', 'wp-super-cache' ); ?></h3>
  186. <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
  187. }
  188. if( !is_writeable_ACLSafe( $wp_cache_config_file ) ) {
  189. define( "SUBMITDISABLED", 'disabled style="color: #aaa" ' );
  190. ?><div id="message" class="updated fade"><h3><?php _e( 'Read Only Mode. Configuration cannot be changed.', 'wp-super-cache' ); ?></h3>
  191. <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 ); ?>
  192. <?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>
  193. <?php _e( 'Writeable:', 'wp-super-cache' ); ?> <code>chmod 666 <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code>
  194. <?php _e( 'Readonly:', 'wp-super-cache' ); ?> <code>chmod 644 <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code></p>
  195. </div><?php
  196. } else {
  197. define( "SUBMITDISABLED", ' ' );
  198. }
  199. // Server could be running as the owner of the wp-content directory. Therefore, if it's
  200. // writable, issue a warning only if the permissions aren't 755.
  201. if( is_writeable_ACLSafe( WP_CONTENT_DIR . '/' ) ) {
  202. $wp_content_stat = stat(WP_CONTENT_DIR . '/');
  203. $wp_content_mode = ( $wp_content_stat[ 'mode' ] & 0777 );
  204. if( $wp_content_mode != 0755 ) {
  205. ?><div id="message" class="updated fade"><h3><?php printf( __( 'Warning! %s is writeable!', 'wp-super-cache' ), WP_CONTENT_DIR ); ?></h3>
  206. <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></div><?php
  207. }
  208. }
  209. if ( function_exists( "is_main_site" ) && true == is_main_site() || function_exists( 'is_main_blog' ) && true == is_main_blog() ) {
  210. $home_path = trailingslashit( get_home_path() );
  211. $scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
  212. if ( $cache_enabled && $wp_cache_mod_rewrite && !$wp_cache_mobile_enabled && strpos( $scrules, addcslashes( implode( '|', $wp_cache_mobile_browsers ), ' ' ) ) ) {
  213. echo '<div id="message" class="updated fade"><h3>' . __( 'Mobile rewrite rules detected', 'wp-super-cache' ) . "</h3>";
  214. 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>";
  215. } elseif ( $wp_cache_mod_rewrite && $cache_enabled && $wp_cache_mobile_enabled && $scrules != '' && (
  216. false === strpos( $scrules, addcslashes( implode( '|', $wp_cache_mobile_prefixes ), ' ' ) ) ||
  217. false === strpos( $scrules, addcslashes( implode( '|', $wp_cache_mobile_browsers ), ' ' ) ) )
  218. ) {
  219. ?>
  220. <div id="message" class="updated fade"><h3><?php _e( 'Rewrite rules must be updated', 'wp-super-cache' ); ?></h3>
  221. <p><?php _e( 'The rewrite rules required by this plugin have changed or are missing. ', 'wp-super-cache' ); ?>
  222. <?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' ); ?>
  223. <ol><li> <?php _e( 'Set the plugin to legacy mode and enable mobile support.', 'wp-super-cache' ); ?></li>
  224. <li> <?php _e( 'Scroll down the Advanced Settings page and click the <strong>Update Mod_Rewrite Rules</strong> button.', 'wp-super-cache' ); ?></li>
  225. <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>
  226. <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>
  227. <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
  228. }
  229. if ( $cache_enabled && $super_cache_enabled && $wp_cache_mod_rewrite && $scrules == '' ) {
  230. ?><div id="message" class="updated fade"><h3><?php _e( 'Rewrite rules must be updated', 'wp-super-cache' ); ?></h3>
  231. <p><?php _e( 'The rewrite rules required by this plugin have changed or are missing. ', 'wp-super-cache' ); ?>
  232. <?php _e( 'Scroll down the Advanced Settings page and click the <strong>Update Mod_Rewrite Rules</strong> button.', 'wp-super-cache' ); ?></p></div><?php
  233. }
  234. }
  235. if ( $wp_cache_mod_rewrite && $super_cache_enabled && function_exists( 'apache_get_modules' ) ) {
  236. $mods = apache_get_modules();
  237. $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' ) );
  238. foreach( $required_modules as $req => $desc ) {
  239. if( !in_array( $req, $mods ) ) {
  240. $missing_mods[ $req ] = $desc;
  241. }
  242. }
  243. if( isset( $missing_mods) && is_array( $missing_mods ) ) {
  244. ?><div id="message" class="updated fade"><h3><?php _e( 'Missing Apache Modules', 'wp-super-cache' ); ?></h3>
  245. <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
  246. echo "<ul>";
  247. foreach( $missing_mods as $req => $desc ) {
  248. echo "<li> $req - $desc</li>";
  249. }
  250. echo "</ul>";
  251. echo "</div>";
  252. }
  253. }
  254. return true;
  255. }
  256. add_filter( 'wp_super_cache_error_checking', 'wp_cache_manager_error_checks' );
  257. function wp_cache_manager_updates() {
  258. 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, $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;
  259. if ( !wpsupercache_site_admin() )
  260. return false;
  261. $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
  262. if ( $valid_nonce == false )
  263. return false;
  264. if( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'easysetup' ) {
  265. $_POST[ 'action' ] = 'scupdates';
  266. if( isset( $_POST[ 'wp_cache_easy_on' ] ) && $_POST[ 'wp_cache_easy_on' ] == 1 ) {
  267. $_POST[ 'wp_cache_mobile_enabled' ] = 1;
  268. $_POST[ 'wp_cache_status' ] = 'all';
  269. $_POST[ 'super_cache_enabled' ] = 2; // PHP
  270. $_POST[ 'cache_rebuild_files' ] = 1;
  271. unset( $_POST[ 'cache_compression' ] );
  272. } else {
  273. unset( $_POST[ 'wp_cache_status' ] );
  274. $_POST[ 'super_cache_enabled' ] = 0;
  275. }
  276. }
  277. if( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'scupdates' ) {
  278. if( isset( $_POST[ 'wp_super_cache_late_init' ] ) ) {
  279. $wp_super_cache_late_init = 1;
  280. } else {
  281. $wp_super_cache_late_init = 0;
  282. }
  283. wp_cache_replace_line('^ *\$wp_super_cache_late_init', "\$wp_super_cache_late_init = " . $wp_super_cache_late_init . ";", $wp_cache_config_file);
  284. if( isset( $_POST[ 'wp_supercache_304' ] ) ) {
  285. $wp_supercache_304 = 1;
  286. } else {
  287. $wp_supercache_304 = 0;
  288. }
  289. wp_cache_replace_line('^ *\$wp_supercache_304', "\$wp_supercache_304 = " . $wp_supercache_304 . ";", $wp_cache_config_file);
  290. if( isset( $_POST[ 'wp_cache_mobile_enabled' ] ) ) {
  291. $wp_cache_mobile_enabled = 1;
  292. } else {
  293. $wp_cache_mobile_enabled = 0;
  294. }
  295. wp_cache_replace_line('^ *\$wp_cache_mobile_enabled', "\$wp_cache_mobile_enabled = " . $wp_cache_mobile_enabled . ";", $wp_cache_config_file);
  296. $wp_supercache_cache_list = $_POST[ 'wp_supercache_cache_list' ] == 1 ? 1 : 0;
  297. wp_cache_replace_line('^ *\$wp_supercache_cache_list', "\$wp_supercache_cache_list = " . $wp_supercache_cache_list . ";", $wp_cache_config_file);
  298. if ( isset( $_POST[ 'wp_cache_status' ] ) ) {
  299. if ( $_POST[ 'wp_cache_status' ] == 'all' )
  300. wp_cache_enable();
  301. if ( isset( $_POST[ 'super_cache_enabled' ] ) ) {
  302. if ( $_POST[ 'super_cache_enabled' ] == 0 ) {
  303. wp_cache_enable();
  304. wp_super_cache_disable();
  305. }
  306. if( $_POST[ 'super_cache_enabled' ] == 1 ) {
  307. $wp_cache_mod_rewrite = 1; // we need this because supercached files can be served by PHP too.
  308. } else {
  309. $wp_cache_mod_rewrite = 0;
  310. }
  311. wp_cache_replace_line('^ *\$wp_cache_mod_rewrite', '$wp_cache_mod_rewrite = ' . $wp_cache_mod_rewrite . ";", $wp_cache_config_file);
  312. }
  313. } else {
  314. wp_cache_disable();
  315. }
  316. if( isset( $_POST[ 'wp_cache_hello_world' ] ) ) {
  317. $wp_cache_hello_world = 1;
  318. } else {
  319. $wp_cache_hello_world = 0;
  320. }
  321. wp_cache_replace_line('^ *\$wp_cache_hello_world', '$wp_cache_hello_world = ' . $wp_cache_hello_world . ";", $wp_cache_config_file);
  322. if( isset( $_POST[ 'wp_cache_clear_on_post_edit' ] ) ) {
  323. $wp_cache_clear_on_post_edit = 1;
  324. } else {
  325. $wp_cache_clear_on_post_edit = 0;
  326. }
  327. 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);
  328. if( isset( $_POST[ 'cache_rebuild_files' ] ) ) {
  329. $cache_rebuild_files = 1;
  330. } else {
  331. $cache_rebuild_files = 0;
  332. }
  333. wp_cache_replace_line('^ *\$cache_rebuild_files', "\$cache_rebuild_files = " . $cache_rebuild_files . ";", $wp_cache_config_file);
  334. if( isset( $_POST[ 'wp_cache_mutex_disabled' ] ) ) {
  335. $wp_cache_mutex_disabled = 0;
  336. } else {
  337. $wp_cache_mutex_disabled = 1;
  338. }
  339. if( defined( 'WPSC_DISABLE_LOCKING' ) ) {
  340. $wp_cache_mutex_disabled = 1;
  341. }
  342. wp_cache_replace_line('^ *\$wp_cache_mutex_disabled', "\$wp_cache_mutex_disabled = " . $wp_cache_mutex_disabled . ";", $wp_cache_config_file);
  343. if( isset( $_POST[ 'wp_cache_not_logged_in' ] ) ) {
  344. if( $wp_cache_not_logged_in == 0 && function_exists( 'prune_super_cache' ) )
  345. prune_super_cache ($cache_path, true);
  346. $wp_cache_not_logged_in = 1;
  347. } else {
  348. $wp_cache_not_logged_in = 0;
  349. }
  350. wp_cache_replace_line('^ *\$wp_cache_not_logged_in', "\$wp_cache_not_logged_in = " . $wp_cache_not_logged_in . ";", $wp_cache_config_file);
  351. if( $_wp_using_ext_object_cache && isset( $_POST[ 'wp_cache_object_cache' ] ) ) {
  352. if( $wp_cache_object_cache == 0 && function_exists( 'prune_super_cache' ) )
  353. prune_super_cache( $cache_path, true );
  354. $wp_cache_object_cache = 1;
  355. } else {
  356. $wp_cache_object_cache = 0;
  357. }
  358. wp_cache_replace_line('^ *\$wp_cache_object_cache', "\$wp_cache_object_cache = " . $wp_cache_object_cache . ";", $wp_cache_config_file);
  359. if( isset( $_POST[ 'wp_cache_refresh_single_only' ] ) ) {
  360. $wp_cache_refresh_single_only = 1;
  361. } else {
  362. $wp_cache_refresh_single_only = 0;
  363. }
  364. wp_cache_replace_line('^ *\$wp_cache_refresh_single_only', "\$wp_cache_refresh_single_only = '" . $wp_cache_refresh_single_only . "';", $wp_cache_config_file);
  365. if ( defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
  366. $cache_compression = 0;
  367. wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
  368. } else {
  369. if ( isset( $_POST[ 'cache_compression' ] ) ) {
  370. $new_cache_compression = 1;
  371. } else {
  372. $new_cache_compression = 0;
  373. }
  374. if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) {
  375. 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>';
  376. } else {
  377. if ( $new_cache_compression != $cache_compression ) {
  378. $cache_compression = $new_cache_compression;
  379. wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
  380. if ( function_exists( 'prune_super_cache' ) )
  381. prune_super_cache( $cache_path, true );
  382. delete_option( 'super_cache_meta' );
  383. }
  384. }
  385. }
  386. }
  387. }
  388. if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'wpsupercache' )
  389. add_action( 'admin_init', 'wp_cache_manager_updates' );
  390. function wp_cache_manager() {
  391. global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled, $wp_cache_hello_world;
  392. global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers;
  393. global $wp_cache_cron_check, $wp_cache_debug, $wp_cache_not_logged_in, $wp_supercache_cache_list;
  394. 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;
  395. global $wpmu_version, $cache_max_time, $wp_cache_mod_rewrite, $wp_supercache_304, $wp_super_cache_late_init;
  396. if ( !wpsupercache_site_admin() )
  397. return false;
  398. // used by mod_rewrite rules and config file
  399. if ( function_exists( "cfmobi_default_browsers" ) ) {
  400. $wp_cache_mobile_browsers = cfmobi_default_browsers( "mobile" );
  401. $wp_cache_mobile_browsers = array_merge( $wp_cache_mobile_browsers, cfmobi_default_browsers( "touch" ) );
  402. } elseif ( function_exists( 'lite_detection_ua_contains' ) ) {
  403. $wp_cache_mobile_browsers = explode( '|', lite_detection_ua_contains() );
  404. } else {
  405. $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' );
  406. }
  407. if ( function_exists( "lite_detection_ua_prefixes" ) ) {
  408. $wp_cache_mobile_prefixes = lite_detection_ua_prefixes();
  409. } else {
  410. $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
  411. }
  412. $wp_cache_mobile_browsers = apply_filters( 'cached_mobile_browsers', $wp_cache_mobile_browsers ); // Allow mobile plugins access to modify the mobile UA list
  413. $wp_cache_mobile_prefixes = apply_filters( 'cached_mobile_prefixes', $wp_cache_mobile_prefixes ); // Allow mobile plugins access to modify the mobile UA prefix list
  414. $mobile_groups = apply_filters( 'cached_mobile_groups', array() ); // Group mobile user agents by capabilities. Lump them all together by default
  415. // mobile_groups = array( 'apple' => array( 'ipod', 'iphone' ), 'nokia' => array( 'nokia5800', 'symbianos' ) );
  416. if ( false == apply_filters( 'wp_super_cache_error_checking', true ) )
  417. return false;
  418. $supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]);
  419. if( get_option( 'gzipcompression' ) == 1 )
  420. update_option( 'gzipcompression', 0 );
  421. if( !isset( $cache_rebuild_files ) )
  422. $cache_rebuild_files = 0;
  423. $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
  424. /* http://www.netlobo.com/div_hiding.html */
  425. ?>
  426. <script type='text/javascript'>
  427. <!--
  428. function toggleLayer( whichLayer ) {
  429. var elem, vis;
  430. if( document.getElementById ) // this is the way the standards work
  431. elem = document.getElementById( whichLayer );
  432. else if( document.all ) // this is the way old msie versions work
  433. elem = document.all[whichLayer];
  434. else if( document.layers ) // this is the way nn4 works
  435. elem = document.layers[whichLayer];
  436. vis = elem.style;
  437. // if the style.display value is blank we try to figure it out here
  438. if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
  439. vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  440. vis.display = (vis.display==''||vis.display=='block')?'none':'block';
  441. }
  442. // -->
  443. //Clicking header opens fieldset options
  444. jQuery(document).ready(function(){
  445. jQuery("fieldset h3").css("cursor","pointer").click(function(){
  446. jQuery(this).parent("fieldset").find("p,form,ul,blockquote").toggle("slow");
  447. });
  448. });
  449. </script>
  450. <style type='text/css'>
  451. #nav h2 {
  452. border-bottom: 1px solid #ccc;
  453. padding-bottom: 0;
  454. }
  455. </style>
  456. <?php
  457. echo '<a name="top"></a>';
  458. echo '<div class="wrap">';
  459. echo '<h2>' . __( 'WP Super Cache Settings', 'wp-super-cache' ) . '</h2>';
  460. // set a default
  461. if ( $cache_enabled == false && isset( $wp_cache_mod_rewrite ) == false ) {
  462. $wp_cache_mod_rewrite = 0;
  463. } elseif ( !isset( $wp_cache_mod_rewrite ) && $cache_enabled && $super_cache_enabled ) {
  464. $wp_cache_mod_rewrite = 1;
  465. }
  466. if ( !isset( $_GET[ 'tab' ] ) && $cache_enabled && ( $wp_cache_mod_rewrite || $super_cache_enabled == false ) ) {
  467. $_GET[ 'tab' ] = 'settings';
  468. 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>';
  469. }
  470. wpsc_admin_tabs();
  471. if ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 1 && !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
  472. wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
  473. 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 );
  474. }
  475. if(isset($_REQUEST['wp_restore_config']) && $valid_nonce) {
  476. unlink($wp_cache_config_file);
  477. 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>';
  478. }
  479. if ( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
  480. wp_cache_replace_line('^ *\$wp_cache_slash_check', "\$wp_cache_slash_check = 1;", $wp_cache_config_file);
  481. } else {
  482. wp_cache_replace_line('^ *\$wp_cache_slash_check', "\$wp_cache_slash_check = 0;", $wp_cache_config_file);
  483. }
  484. if( $wp_cache_mobile_enabled == 1 ) {
  485. update_cached_mobile_ua_list( $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $mobile_groups );
  486. }
  487. ?> <table><td valign='top'><?php
  488. switch( $_GET[ 'tab' ] ) {
  489. case "cdn":
  490. scossdl_off_options();
  491. break;
  492. case "tester":
  493. if ( !$cache_enabled )
  494. wp_die( __( 'Caching must be enabled to use this feature', 'wp-super-cache' ) );
  495. echo '<a name="test"></a>';
  496. echo "<h3>" . __( 'Cache Tester', 'wp-super-cache' ) . "</h3>";
  497. echo '<p>' . __( 'Test your cached website by clicking the test button below.', 'wp-super-cache' ) . '</p>';
  498. if ( array_key_exists('action', $_POST) && $_POST[ 'action' ] == 'test' && $valid_nonce ) {
  499. $url = trailingslashit( get_bloginfo( 'url' ) );
  500. if ( isset( $_POST[ 'httponly' ] ) )
  501. $url = str_replace( 'https://', 'http://', $url );
  502. // Prime the cache
  503. echo "<p>";
  504. printf( __( 'Fetching %s to prime cache: ', 'wp-super-cache' ), $url );
  505. $page = wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
  506. echo '<strong>' . __( 'OK', 'wp-super-cache' ) . '</strong>';
  507. echo "</p>";
  508. sleep( 1 );
  509. // Get the first copy
  510. echo "<p>";
  511. printf( __( 'Fetching first copy of %s: ', 'wp-super-cache' ), $url );
  512. $page = wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
  513. echo '<strong>' . __( 'OK', 'wp-super-cache' ) . '</strong>';
  514. echo "</p>";
  515. sleep( 1 );
  516. // Get the second copy
  517. echo "<p>";
  518. printf( __( 'Fetching second copy of %s: ', 'wp-super-cache' ), $url );
  519. $page2 = wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
  520. echo '<strong>' . __( 'OK', 'wp-super-cache' ) . '</strong>';
  521. echo "</p>";
  522. if ( is_wp_error( $page ) || is_wp_error( $page2 ) || $page[ 'response' ][ 'code' ] != 200 || $page2[ 'response' ][ 'code' ] != 200 ) {
  523. echo '<p><strong>' . __( 'One or more page requests failed:', 'wp-super-cache' ) . '</strong></p>';
  524. $error = false;
  525. if ( is_wp_error( $page ) ) {
  526. $error = $page;
  527. } elseif ( is_wp_error( $page2 ) ) {
  528. $error = $page2;
  529. }
  530. if ( $error ) {
  531. $errors = '';
  532. $messages = '';
  533. foreach ( $error->get_error_codes() as $code ) {
  534. $severity = $error->get_error_data($code);
  535. foreach ( $error->get_error_messages( $code ) as $err ) {
  536. $errors .= ' ' . $err . "<br />\n";
  537. }
  538. }
  539. if ( !empty($err) )
  540. echo '<div class="updated fade">' . $errors . "</div>\n";
  541. } else {
  542. echo '<ul><li>' . sprintf( __( 'Page %d: %d (%s)', 'wp-super-cache' ), 1, $page[ 'response' ][ 'code' ], $page[ 'response' ][ 'message' ] ) . '</li>';
  543. echo '<li>' . sprintf( __( 'Page %d: %d (%s)', 'wp-super-cache' ), 2, $page2[ 'response' ][ 'code' ], $page2[ 'response' ][ 'message' ] ) . '</li></ul>';
  544. }
  545. }
  546. if ( 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 ) &&
  547. 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] ) {
  548. echo '<p>' . sprintf( __( 'Page 1: %s', 'wp-super-cache' ), $matches1[ 2 ] ) . '</p>';
  549. echo '<p>' . sprintf( __( 'Page 2: %s', 'wp-super-cache' ), $matches2[ 2 ] ) . '</p>';
  550. echo '<p><strong>' . __( 'The timestamps on both pages match!', 'wp-super-cache' ) . '</strong></p>';
  551. } else {
  552. echo '<p><strong>' . __( 'The pages do not match! Timestamps differ or were not found!', 'wp-super-cache' ) . '</strong></p>';
  553. }
  554. }
  555. echo '<form name="cache_tester" action="" method="post">';
  556. echo '<input type="hidden" name="action" value="test" />';
  557. if ( 'on' == strtolower( $_SERVER['HTTPS' ] ) )
  558. echo "<input type='checkbox' name='httponly' checked='checked' value='1' /> " . __( 'Send non-secure (non https) request for homepage', 'wp-super-cache' );
  559. echo '<div class="submit"><input type="submit" name="test" value="' . __( 'Test Cache', 'wp-super-cache' ) . '" /></div>';
  560. wp_nonce_field('wp-cache');
  561. echo '</form>';
  562. wp_cache_files();
  563. break;
  564. case "preload":
  565. if ( !$cache_enabled )
  566. wp_die( __( 'Caching must be enabled to use this feature', 'wp-super-cache' ) );
  567. echo '<a name="preload"></a>';
  568. if ( $super_cache_enabled == true && false == defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
  569. global $wp_cache_preload_interval, $wp_cache_preload_on, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $wp_cache_preload_posts, $wpdb;
  570. $count = $wpdb->get_var( "SELECT count(*) FROM {$wpdb->posts} WHERE post_status = 'publish'" );
  571. if ( $count > 1000 ) {
  572. $min_refresh_interval = 720;
  573. } else {
  574. $min_refresh_interval = 30;
  575. }
  576. if ( array_key_exists('action', $_POST) && $_POST[ 'action' ] == 'preload' && $valid_nonce ) {
  577. if ( $_POST[ 'posts_to_cache' ] == 'all' ) {
  578. $wp_cache_preload_posts = 'all';
  579. } else {
  580. $wp_cache_preload_posts = (int)$_POST[ 'posts_to_cache' ];
  581. }
  582. wp_cache_replace_line('^ *\$wp_cache_preload_posts', "\$wp_cache_preload_posts = '$wp_cache_preload_posts';", $wp_cache_config_file);
  583. if ( isset( $_POST[ 'preload' ] ) && $_POST[ 'preload' ] == __( 'Cancel Cache Preload', 'wp-super-cache' ) ) {
  584. $next_preload = wp_next_scheduled( 'wp_cache_preload_hook' );
  585. if ( $next_preload ) {
  586. update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
  587. wp_unschedule_event( $next_preload, 'wp_cache_preload_hook' );
  588. }
  589. $fp = @fopen( $cache_path . "stop_preload.txt", 'w' );
  590. @fclose( $fp );
  591. echo "<p><strong>" . __( 'Scheduled preloading of cache cancelled.', 'wp-super-cache' ) . "</strong></p>";
  592. } elseif ( isset( $_POST[ 'custom_preload_interval' ] ) && ( $_POST[ 'custom_preload_interval' ] == 0 || $_POST[ 'custom_preload_interval' ] >= $min_refresh_interval ) ) {
  593. // if preload interval changes than unschedule any preload jobs and schedule any new one.
  594. $_POST[ 'custom_preload_interval' ] = (int)$_POST[ 'custom_preload_interval' ];
  595. if ( $wp_cache_preload_interval != $_POST[ 'custom_preload_interval' ] ) {
  596. $next_preload = wp_next_scheduled( 'wp_cache_full_preload_hook' );
  597. if ( $next_preload ) {
  598. update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
  599. add_option( 'preload_cache_stop', 1 );
  600. wp_unschedule_event( $next_preload, 'wp_cache_full_preload_hook' );
  601. if ( $wp_cache_preload_interval == 0 ) {
  602. echo "<p><strong>" . __( 'Scheduled preloading of cache cancelled.', 'wp-super-cache' ) . "</strong></p>";
  603. }
  604. }
  605. if ( $_POST[ 'custom_preload_interval' ] != 0 )
  606. wp_schedule_single_event( time() + ( $_POST[ 'custom_preload_interval' ] * 60 ), 'wp_cache_full_preload_hook' );
  607. }
  608. $wp_cache_preload_interval = (int)$_POST[ 'custom_preload_interval' ];
  609. wp_cache_replace_line('^ *\$wp_cache_preload_interval', "\$wp_cache_preload_interval = $wp_cache_preload_interval;", $wp_cache_config_file);
  610. if ( isset( $_POST[ 'preload_email_me' ] ) ) {
  611. $wp_cache_preload_email_me = 1;
  612. } else {
  613. $wp_cache_preload_email_me = 0;
  614. }
  615. wp_cache_replace_line('^ *\$wp_cache_preload_email_me', "\$wp_cache_preload_email_me = $wp_cache_preload_email_me;", $wp_cache_config_file);
  616. if ( isset( $_POST[ 'wp_cache_preload_email_volume' ] ) && in_array( $_POST[ 'wp_cache_preload_email_volume' ], array( 'less', 'medium', 'many' ) ) ) {
  617. $wp_cache_preload_email_volume = $_POST[ 'wp_cache_preload_email_volume' ];
  618. } else {
  619. $wp_cache_preload_email_volume = 'medium';
  620. }
  621. wp_cache_replace_line('^ *\$wp_cache_preload_email_volume', "\$wp_cache_preload_email_volume = '$wp_cache_preload_email_volume';", $wp_cache_config_file);
  622. if ( isset( $_POST[ 'preload_on' ] ) ) {
  623. $wp_cache_preload_on = 1;
  624. } else {
  625. $wp_cache_preload_on = 0;
  626. }
  627. wp_cache_replace_line('^ *\$wp_cache_preload_on', "\$wp_cache_preload_on = $wp_cache_preload_on;", $wp_cache_config_file);
  628. if ( isset( $_POST[ 'preload' ] ) && $_POST[ 'preload' ] == __( 'Preload Cache Now', 'wp-super-cache' ) ) {
  629. @unlink( $cache_path . "preload_mutex.tmp" );
  630. update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
  631. wp_schedule_single_event( time() + 10, 'wp_cache_preload_hook' );
  632. echo "<p><strong>" . __( 'Scheduled preloading of cache in 10 seconds.' ) . "</strong></p>";
  633. } elseif ( (int)$_POST[ 'custom_preload_interval' ] ) {
  634. @unlink( $cache_path . "preload_mutex.tmp" );
  635. update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
  636. wp_schedule_single_event( time() + ( (int)$_POST[ 'custom_preload_interval' ] * 60 ), 'wp_cache_full_preload_hook' );
  637. echo "<p><strong>" . sprintf( __( 'Scheduled preloading of cache in %d minutes', 'wp-super-cache' ), (int)$_POST[ 'custom_preload_interval' ] ) . "</strong></p>";
  638. }
  639. }
  640. }
  641. 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>';
  642. 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>';
  643. 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>';
  644. echo '<form name="cache_filler" action="" method="POST">';
  645. echo '<input type="hidden" name="action" value="preload" />';
  646. echo '<input type="hidden" name="page" value="wpsupercache" />';
  647. 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>';
  648. if ( $count > 100 ) {
  649. $step = (int)( $count / 10 );
  650. $select = "<select name='posts_to_cache' size=1>";
  651. $select .= "<option value='all' ";
  652. if ( !isset( $wp_cache_preload_posts ) || $wp_cache_preload_posts == 'all' ) {
  653. $checked = 'selectect=1 ';
  654. $best = 'all';
  655. } else {
  656. $checked = ' ';
  657. $best = $wp_cache_preload_posts;
  658. }
  659. $select .= "{$checked}>" . __( 'all', 'wp-super-cache' ) . "</option>";
  660. for( $c = $step; $c < $count; $c += $step ) {
  661. $checked = ' ';
  662. if ( $best == $c )
  663. $checked = 'selected=1 ';
  664. $select .= "<option value='$c'{$checked}>$c</option>";
  665. }
  666. $checked = ' ';
  667. if ( $best == $count )
  668. $checked = 'selected=1 ';
  669. $select .= "<option value='$count'{$checked}>$count</option>";
  670. $select .= "</select>";
  671. echo '<p>' . sprintf( __( 'Preload %s posts.', 'wp-super-cache' ), $select ) . '</p>';
  672. } else {
  673. echo '<input type="hidden" name="posts_to_cache" value="' . $count . '" />';
  674. }
  675. echo '<input type="checkbox" name="preload_on" value="1" ';
  676. echo $wp_cache_preload_on == 1 ? 'checked=1' : '';
  677. echo ' /> ' . __( 'Preload mode (garbage collection only on legacy cache files. Recommended.)', 'wp-super-cache' ) . '<br />';
  678. echo '<input type="checkbox" name="preload_email_me" value="1" ';
  679. echo $wp_cache_preload_email_me == 1 ? 'checked=1' : '';
  680. echo ' /> ' . __( 'Send me status emails when files are refreshed.', 'wp-super-cache' ) . '<br />';
  681. if ( !isset( $wp_cache_preload_email_volume ) )
  682. $wp_cache_preload_email_volume = 'many';
  683. echo '&nbsp;&nbsp;&nbsp;&nbsp;<input name="wp_cache_preload_email_volume" type="radio" value="many" class="tog" ';
  684. checked( 'many', $wp_cache_preload_email_volume );
  685. echo '/> ' . __( 'Many emails, 2 emails per 100 posts.', 'wp-super-cache' ) . '<br >';
  686. echo '&nbsp;&nbsp;&nbsp;&nbsp;<input name="wp_cache_preload_email_volume" type="radio" value="medium" class="tog" ';
  687. checked( 'medium', $wp_cache_preload_email_volume );
  688. echo '/> ' . __( 'Medium, 1 email per 100 posts.', 'wp-super-cache' ) . '<br >';
  689. echo '&nbsp;&nbsp;&nbsp;&nbsp;<input name="wp_cache_preload_email_volume" type="radio" value="less" class="tog" ';
  690. checked( 'less', $wp_cache_preload_email_volume );
  691. echo '/> ' . __( 'Less emails, 1 at the start and 1 at the end of preloading all posts.', 'wp-super-cache' ) . '<br >';
  692. $currently_preloading = false;
  693. next_preload_message( 'wp_cache_preload_hook', __( 'Refresh of cache in %d hours %d minutes and %d seconds.', 'wp-super-cache' ), 60 );
  694. next_preload_message( 'wp_cache_full_preload_hook', __( 'Full refresh of cache in %d hours %d minutes and %d seconds.', 'wp-super-cache' ) );
  695. $preload_counter = get_option( 'preload_cache_counter' );
  696. if ( isset( $preload_counter[ 'first' ] ) ) // converted from int to array
  697. update_option( 'preload_cache_counter', array( 'c' => $preload_counter[ 'c' ], 't' => time() ) );
  698. if ( is_array( $preload_counter ) && $preload_counter[ 'c' ] > 0 ) {
  699. echo '<p><strong>' . sprintf( __( 'Currently caching from post %d to %d.', 'wp-super-cache' ), ( $preload_counter[ 'c' ] - 100 ), $preload_counter[ 'c' ] ) . '</strong></p>';
  700. $currently_preloading = true;
  701. if ( @file_exists( $cache_path . "preload_permalink.txt" ) ) {
  702. $url = file_get_contents( $cache_path . "preload_permalink.txt" );
  703. echo "<p>" . sprintf( __( "<strong>Page last cached:</strong> %s", 'wp-super-cache' ), $url ) . "</p>";
  704. }
  705. }
  706. 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' ) . '" />';
  707. if ( $currently_preloading ) {
  708. echo '&nbsp;<input type="submit" name="preload" value="' . __( 'Cancel Cache Preload', 'wp-super-cache' ) . '" />';
  709. }
  710. echo '</div>';
  711. wp_nonce_field('wp-cache');
  712. echo '</form>';
  713. } else {
  714. echo '<p>' . __( 'Preloading of cache disabled. Please disable legacy page caching or talk to your host administrator.', 'wp-super-cache' ) . '</p>';
  715. }
  716. break;
  717. case 'plugins':
  718. wpsc_plugins_tab();
  719. break;
  720. case 'debug':
  721. wp_cache_debug_settings();
  722. break;
  723. case 'settings':
  724. echo '<form name="wp_manager" action="' . add_query_arg( array( 'page' => 'wpsupercache', 'tab' => 'settings' ) ) . '" method="post">';
  725. wp_nonce_field('wp-cache');
  726. echo '<input type="hidden" name="action" value="scupdates" />';
  727. ?><table class="form-table">
  728. <tr valign="top">
  729. <th scope="row"><label for="wp_cache_status"><?php _e( 'Caching', 'wp-super-cache' ); ?></label></th>
  730. <td>
  731. <fieldset>
  732. <legend class="hidden">Caching</legend>
  733. <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 />
  734. <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 />
  735. <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 />
  736. <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 />
  737. <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 />
  738. </legend>
  739. </fieldset>
  740. </td>
  741. </tr>
  742. <tr valign="top">
  743. <th scope="row"><label for="wp_cache_status"><?php _e( 'Miscellaneous', 'wp-super-cache' ); ?></label></th>
  744. <td>
  745. <fieldset>
  746. <legend class="hidden">Miscellaneous</legend>
  747. <?php if ( false == defined( 'WPSC_DISABLE_COMPRESSION' ) ) { ?>
  748. <?php if ( false == function_exists( 'gzencode' ) ) { ?>
  749. <em><?php _e( 'Warning! Compression is disabled as gzencode() function not found.', 'wp-super-cache' ); ?></em><br />
  750. <?php } else { ?>
  751. <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 />
  752. <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 />
  753. <?php } ?>
  754. <?php } ?>
  755. <?php if ( 0 == $wp_cache_mod_rewrite ) { ?>
  756. <label><input 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 />
  757. <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 />
  758. <?php } ?>
  759. <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 />
  760. <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 />
  761. <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><br />
  762. </legend>
  763. </fieldset>
  764. </td>
  765. </tr>
  766. <tr valign="top">
  767. <th scope="row"><label for="wp_cache_status"><?php _e( 'Advanced', 'wp-super-cache' ); ?></label></th>
  768. <td>
  769. <fieldset>
  770. <legend class="hidden">Advanced</legend>
  771. <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><br />
  772. <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.', 'wp-super-cache' ); ?></label><br />
  773. <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 />
  774. <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 />
  775. <?php if( false == defined( 'WPSC_DISABLE_LOCKING' ) ) { ?>
  776. <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 />
  777. <?php } ?>
  778. <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 />
  779. <?php if ( $_wp_using_ext_object_cache ) {
  780. ?><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
  781. }?>
  782. </legend>
  783. </fieldset>
  784. </td>
  785. </tr>
  786. </table>
  787. <h3><?php _e( 'Note:', 'wp-super-cache' ); ?></h3>
  788. <ol>
  789. <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>
  790. <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
  791. 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>";
  792. echo "</ol>";
  793. echo "<div class='submit'><input class='button-primary' type='submit' " . SUBMITDISABLED . " value='" . __( 'Update Status', 'wp-super-cache' ) . " &raquo;' /></div>";
  794. wp_nonce_field('wp-cache');
  795. ?> </form> <?php
  796. wsc_mod_rewrite();
  797. wp_cache_edit_max_time();
  798. echo '<a name="files"></a><fieldset class="options"><h3>' . __( 'Accepted Filenames &amp; Rejected URIs', 'wp-super-cache' ) . '</h3>';
  799. wp_cache_edit_rejected_pages();
  800. echo "\n";
  801. wp_cache_edit_rejected();
  802. echo "\n";
  803. wp_cache_edit_accepted();
  804. echo '</fieldset>';
  805. wp_cache_edit_rejected_ua();
  806. wp_lock_down();
  807. wp_cache_restore();
  808. break;
  809. case "easy":
  810. default:
  811. echo '<form name="wp_manager" action="" method="post">';
  812. echo '<input type="hidden" name="action" value="easysetup" />';
  813. wp_nonce_field('wp-cache');
  814. ?><table class="form-table">
  815. <tr valign="top">
  816. <th scope="row"><label for="wp_cache_status"><?php _e( 'Caching', 'wp-super-cache' ); ?></label></th>
  817. <td>
  818. <fieldset>
  819. <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 />
  820. <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 />
  821. <em><?php _e( 'Note: enables PHP caching, cache rebuild, and mobile support', 'wp-super-cache' ); ?></em><br />
  822. </legend>
  823. </fieldset>
  824. </td>
  825. </tr>
  826. </table>
  827. <?php
  828. if( $cache_enabled && !$wp_cache_mod_rewrite ) {
  829. $scrules = trim( implode( "\n", extract_from_markers( trailingslashit( get_home_path() ) . '.htaccess', 'WPSuperCache' ) ) );
  830. if ( $scrules != '' ) {
  831. 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>';
  832. }
  833. }
  834. echo "<div class='submit'><input class='button-primary' type='submit' " . SUBMITDISABLED . " value='" . __( 'Update Status', 'wp-super-cache' ) . " &raquo;' /></div>";?>
  835. </form>
  836. <h3><?php _e( 'Recommended Links and Plugins', 'wp-super-cache' ); ?></h3>
  837. <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>
  838. <ol><li><?php printf( __( '<a href="%s">WP Minify</a> reduces the number of files served by your web server by joining Javascript and CSS files together. Alternatively you can use <a href="%s">WPSCMin</a>, a Supercache plugin that minifies cached pages. It does not however join JS/CSS files together.', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/wp-minify/', 'http://lyncd.com/wpscmin/' ); ?></li>
  839. <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>
  840. <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>
  841. <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>
  842. <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>
  843. </ol>
  844. <?php
  845. break;
  846. }
  847. ?>
  848. </fieldset>
  849. </td><td valign='top' style='width: 300px'>
  850. <div style='background: #ffc; border: 1px solid #333; margin: 2px; padding: 5px'>
  851. <h3 align='center'><?php _e( 'Make WordPress Faster', 'wp-super-cache' ); ?></h3>
  852. <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>
  853. <p><?php printf( __( 'He blogs at %1$s and posts photos at %2$s.', 'wp-super-cache' ), '<a href="http://ocaoimh.ie/?r=supercache">Holy Shmoly</a>', '<a href="http://inphotos.org/?r=supercache">In Photos.org</a>' ); ?></p>
  854. <p><?php printf( __( 'Please say hi to him on %s too!', 'wp-super-cache' ), '<a href="http://twitter.com/donncha/">Twitter</a>' ); ?></p>
  855. <h3 align='center'><?php _e( 'Need Help?', 'wp-super-cache' ); ?></h3>
  856. <ol>
  857. <li><?php printf( __( '<a href="%1$s">Installation Help</a>', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/wp-super-cache/installation/' ); ?></li>
  858. <li><?php printf( __( '<a href="%1$s">Frequently Asked Questions</a>', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/wp-super-cache/faq/' ); ?></li>
  859. <li><?php printf( __( '<a href="%1$s">Support Forum</a>', 'wp-super-cache' ), 'http://wordpress.org/tags/wp-super-cache' ); ?></li>
  860. </ol>
  861. <h3 align='center'><?php _e( 'Rate This Plugin!', 'wp-super-cache' ); ?></h3>
  862. <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>
  863. <?php
  864. if ( isset( $wp_supercache_cache_list ) && $wp_supercache_cache_list ) {
  865. $start_date = get_option( 'wpsupercache_start' );
  866. if ( !$start_date ) {
  867. $start_date = time();
  868. }
  869. ?>
  870. <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>
  871. <p><?php _e( 'Newest Cached Pages:', 'wp-super-cache' ); ?><ol>
  872. <?php
  873. foreach( array_reverse( (array)get_option( 'supercache_last_cached' ) ) as $url ) {
  874. $since = time() - strtotime( $url[ 'date' ] );
  875. 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";
  876. }
  877. ?></ol>
  878. <small><?php _e( '(may not always be accurate on busy sites)', 'wp-super-cache' ); ?></small>
  879. </p><?php
  880. } else {
  881. $start_date = get_option( 'wpsupercache_start' );
  882. if ( $start_date ) {
  883. update_option( 'wpsupercache_start', $start_date );
  884. update_option( 'wpsupercache_count', 0 );
  885. }
  886. }
  887. ?>
  888. </div>
  889. </td></table>
  890. <?php
  891. echo "</div>\n";
  892. }
  893. function wpsc_plugins_tab() {
  894. 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>';
  895. 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>';
  896. ob_start();
  897. if( defined( 'WP_CACHE' ) ) {
  898. if( function_exists( 'do_cacheaction' ) ) {
  899. do_cacheaction( 'cache_admin_page' );
  900. }
  901. }
  902. $out = ob_get_contents();
  903. ob_end_clean();
  904. if( SUBMITDISABLED == ' ' && $out != '' ) {
  905. echo '<h3>' . __( 'Available Plugins', 'wp-super-cache' ) . '</h3>';
  906. echo "<ol>";
  907. echo $out;
  908. echo "</ol>";
  909. }
  910. }
  911. function wpsc_admin_tabs( $current = 0 ) {
  912. global $wp_db_version;
  913. if ( $current == 0 ) {
  914. if ( isset( $_GET[ 'tab' ] ) ) {
  915. $current = $_GET[ 'tab' ];
  916. } else {
  917. $current = 'easy';
  918. }
  919. }
  920. $tabs = array( 'easy' => __( 'Easy', 'wp-super-cache' ), 'settings' => __( 'Advanced', 'wp-super-cache' ), 'cdn' => __( 'CDN', 'wp-super-cache' ), 'tester' => __( 'Tester & Contents', 'wp-super-cache' ), 'preload' => __( 'Preload', 'wp-super-cache' ), 'plugins' => __( 'Plugins', 'wp-super-cache' ), 'debug' => __( 'Debug', 'wp-super-cache' ) );
  921. $links = array();
  922. foreach( $tabs as $tab => $name ) {
  923. if ( $current == $tab ) {
  924. $links[] = "<a class='nav-tab nav-tab-active' href='?page=wpsupercache&tab=$tab'>$name</a>";
  925. } else {
  926. $links[] = "<a class='nav-tab' href='?page=wpsupercache&tab=$tab'>$name</a>";
  927. }
  928. }
  929. if ( $wp_db_version >= 15477 ) {
  930. echo '<div id="nav"><h2 class="themes-php">';
  931. echo implode( "", $links );
  932. echo '</h2></div>';
  933. } else {
  934. echo implode( " | ", $links );
  935. }
  936. }
  937. function wsc_mod_rewrite() {
  938. global $cache_enabled, $super_cache_enabled, $valid_nonce, $cache_path, $wp_cache_mod_rewrite, $wpmu_version;
  939. if ( !$wp_cache_mod_rewrite )
  940. return false;
  941. if ( isset( $wpmu_version ) || function_exists( 'is_multisite' ) && is_multisite() ) {
  942. if ( false == wpsupercache_site_admin() )
  943. return false;
  944. if ( function_exists( "is_main_site" ) && false == is_main_site() || function_exists( 'is_main_blog' ) && false == is_main_blog() ) {
  945. global $current_site;
  946. $protocol = ( 'on' == strtolower( $_SERVER['HTTPS' ] ) ) ? 'https://' : 'http://';
  947. if ( isset( $wpmu_version ) ) {
  948. 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' ), admin_url( "ms-admin.php?page=wpsupercache" ) ) . '</p></div>';
  949. } else {
  950. echo '<div id="message" class="updated fade"><p>' . sprintf( __( 'Notice: WP Super Cache mod_rewrite rule checks disabled unless running on <a href="%s">on the main site</a> of this network.', 'wp-super-cache' ), admin_url( "wpmu-admin.php?page=wpsupercache" ) ) . '</p></div>';
  951. }
  952. return false;
  953. }
  954. }
  955. if ( function_exists( "is_main_site" ) && false == is_main_site() || function_exists( 'is_main_blog' ) && false == is_main_blog() )
  956. return true;
  957. ?>
  958. <a name="modrewrite"></a><fieldset class="options">
  959. <h3><?php _e( 'Mod Rewrite Rules', 'wp-super-cache' ); ?></h3><?php
  960. extract( wpsc_get_htaccess_info() );
  961. $dohtaccess = true;
  962. global $wpmu_version;
  963. if( isset( $wpmu_version ) ) {
  964. 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>";
  965. } elseif( !$wprules || $wprules == '' ) {
  966. echo "<h4 style='color: #a00'>" . __( 'Mod Rewrite rules cannot be updated!', 'wp-super-cache' ) . "</h4>";
  967. 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 );
  968. 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>";
  969. _e( 'Refresh this page when you have updated your .htaccess file.', 'wp-super-cache' );
  970. echo "</fieldset></div>";
  971. return;
  972. } elseif( strpos( $wprules, 'wordpressuser' ) ) { // Need to clear out old mod_rewrite rules
  973. 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>";
  974. echo "</fieldset></div>";
  975. return;
  976. } elseif( $scrules != '' && strpos( $scrules, '%{REQUEST_URI} !^.*[^/]$' ) === false && substr( get_option( 'permalink_structure' ), -1 ) == '/' ) { // permalink structure has a trailing slash, need slash check in rules.
  977. echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><h4>" . __( 'Trailing slash check required.', 'wp-super-cache' ) . "</h4><p>" . __( 'It looks like your blog has URLs that end with a "/". Unfortunately since you installed this plugin a duplicate content bug has been found where URLs not ending in a "/" end serve the same content as those with the "/" and do not redirect to the proper URL. To fix, you must edit your .htaccess file and add these two rules to the two groups of Super Cache rules:', 'wp-super-cache' ) . "</p>";
  978. echo "<blockquote><code>RewriteCond %{REQUEST_URI} !^.*[^/]$RewriteCond %{REQUEST_URI} !^.*//.*$</code></blockquote>";
  979. 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>";
  980. $dohtaccess = false;
  981. } elseif( strpos( $scrules, 'supercache' ) || strpos( $wprules, 'supercache' ) ) { // only write the rules once
  982. $dohtaccess = false;
  983. }
  984. if( $dohtaccess && !$_POST[ 'updatehtaccess' ] ) {
  985. if ( $scrules == '' ) {
  986. wpsc_update_htaccess_form( 0 ); // don't hide the update htaccess form
  987. } else {
  988. wpsc_update_htaccess_form();
  989. }
  990. } elseif( $valid_nonce && $_POST[ 'updatehtaccess' ] ) {
  991. echo "<div style='padding:0 8px;color:#4f8a10;background-color:#dff2bf;border:1px solid #4f8a10;'>";
  992. if( wpsc_update_htaccess() ) {
  993. echo "<h4>" . __( 'Mod Rewrite rules updated!', 'wp-super-cache' ) . "</h4>";
  994. 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";
  995. } else {
  996. echo "<h4>" . __( 'Mod Rewrite rules must be updated!', 'wp-super-cache' ) . "</h4>";
  997. 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";
  998. }
  999. echo "<p><pre>" . esc_html( $rules ) . "</pre></p>\n</div>";
  1000. } else {
  1001. ?>
  1002. <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>
  1003. <?php
  1004. if ( $rules != $scrules ) {
  1005. ?><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
  1006. }
  1007. ?>
  1008. <a href="javascript:toggleLayer('rewriterules');" class="button"><?php _e( 'View Mod_Rewrite Rules', 'wp-super-cache' ); ?></a>
  1009. <?php wpsc_update_htaccess_form(); ?>
  1010. <div id='rewriterules' style='display: none;'>
  1011. <?php echo "<p><pre># BEGIN WPSuperCache\n" . esc_html( $rules ) . "# END WPSuperCache</pre></p>\n";
  1012. echo "<p>" . sprintf( __( 'Rules must be added to %s too:', 'wp-super-cache' ), WP_CONTENT_DIR . "/cache/.htaccess" ) . "</p>";
  1013. echo "<pre># BEGIN supercache\n" . esc_html( $gziprules ) . "# END supercache</pre></p>"; ?>
  1014. </div>
  1015. <?php
  1016. }
  1017. // http://allmybrain.com/2007/11/08/making-wp-super-cache-gzip-compression-work/
  1018. if( !is_file( $cache_path . '.htaccess' ) ) {
  1019. $gziprules = insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $gziprules ) );
  1020. echo "<h4>" . sprintf( __( 'Gzip encoding rules in %s.htaccess created.', 'wp-super-cache' ), $cache_path ) . "</h4>";
  1021. }
  1022. ?></fieldset><?php
  1023. }
  1024. function wp_cache_restore() {
  1025. echo '<fieldset class="options"><h3>' . __( 'Fix Configuration', 'wp-super-cache' ) . '</h3>';
  1026. echo '<form name="wp_restore" action="#top" method="post">';
  1027. echo '<input type="hidden" name="wp_restore_config" />';
  1028. echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'id="deletepost" value="' . __( 'Restore Default Configuration', 'wp-super-cache' ) . ' &raquo;" /></div>';
  1029. wp_nonce_field('wp-cache');
  1030. echo "</form>\n";
  1031. echo '</fieldset>';
  1032. }
  1033. function comment_form_lockdown_message() {
  1034. ?><p><?php _e( "Comment moderation is enabled. Your comment may take some time to appear.", 'wp-super-cache' ); ?></p><?php
  1035. }
  1036. if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) )
  1037. add_action( 'comment_form', 'comment_form_lockdown_message' );
  1038. function wp_lock_down() {
  1039. global $wpdb, $cache_path, $wp_cache_config_file, $valid_nonce, $cached_direct_pages, $cache_enabled, $super_cache_enabled;
  1040. global $wp_super_cache_lock_down;
  1041. if(isset($_POST['wp_lock_down']) && $valid_nonce) {
  1042. $wp_lock_down = $_POST['wp_lock_down'] == '1' ? '1' : '0';
  1043. wp_cache_replace_line('^.*WPLOCKDOWN', "define( 'WPLOCKDOWN', '$wp_lock_down' );", $wp_cache_config_file);
  1044. if( $wp_lock_down == '0' && function_exists( 'prune_super_cache' ) )
  1045. prune_super_cache( $cache_path, true ); // clear the cache after lockdown
  1046. }
  1047. if( !isset( $wp_lock_down ) ) {
  1048. if( defined( 'WPLOCKDOWN' ) ) {
  1049. $wp_lock_down = constant( 'WPLOCKDOWN' );
  1050. } else {
  1051. $wp_lock_down = '0';
  1052. }
  1053. }
  1054. ?><a name='lockdown'></a>
  1055. <fieldset class="options">
  1056. <h3><?php _e( 'Lock Down:', 'wp-super-cache' ); ?> <?php echo $wp_lock_down == '0' ? '<span style="color:red">' . __( 'Disabled', 'wp-super-cache' ) . '</span>' : '<span style="color:green">' . __( 'Enabled', 'wp-super-cache' ) . '</span>'; ?></h3>
  1057. <p><?php _e( 'Prepare your server for an expected spike in traffic by enabling the lock down. When this is enabled, new comments on a post will not refresh the cached static files.', 'wp-super-cache' ); ?></p>
  1058. <p><?php _e( 'Developers: Make your plugin lock down compatible by checking the "WPLOCKDOWN" constant. The following code will make sure your plugin respects the WPLOCKDOWN setting.', 'wp-super-cache' ); ?>
  1059. <blockquote><code>if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) ) {
  1060. &nbsp;&nbsp;&nbsp;&nbsp;echo "<?php _e( 'Sorry. My blog is locked down. Updates will appear shortly', 'wp-super-cache' ); ?>";
  1061. }</code></blockquote>
  1062. <?php
  1063. if( $wp_lock_down == '1' ) {
  1064. ?><p><?php _e( 'WordPress is locked down. Super Cache static files will not be deleted when new comments are made.', 'wp-super-cache' ); ?></p><?php
  1065. } else {
  1066. ?><p><?php _e( 'WordPress is not locked down. New comments will refresh Super Cache static files as normal.', 'wp-super-cache' ); ?></p><?php
  1067. }
  1068. $new_lockdown = $wp_lock_down == '1' ? '0' : '1';
  1069. $new_lockdown_desc = $wp_lock_down == '1' ? __( 'Disable', 'wp-super-cache' ) : __( 'Enable', 'wp-super-cache' );
  1070. echo '<form name="wp_lock_down" action="#lockdown" method="post">';
  1071. echo "<input type='hidden' name='wp_lock_down' value='{$new_lockdown}' />";
  1072. echo "<div class='submit'><input type='submit' " . SUBMITDISABLED . " value='{$new_lockdown_desc} " . __( 'Lock Down', 'wp-super-cache' ) . " &raquo;' /></div>";
  1073. wp_nonce_field('wp-cache');
  1074. echo "</form>\n";
  1075. ?></fieldset><?php
  1076. if( $cache_enabled == true && $super_cache_enabled == true ) {
  1077. ?><a name='direct'></a>
  1078. <fieldset class="options">
  1079. <h3><?php _e( 'Directly Cached Files', 'wp-super-cache' ); ?></h3><?php
  1080. $out = '';
  1081. if( $valid_nonce && array_key_exists('direct_pages', $_POST) && is_array( $_POST[ 'direct_pages' ] ) && !empty( $_POST[ 'direct_pages' ] ) ) {
  1082. $expiredfiles = array_diff( $cached_direct_pages, $_POST[ 'direct_pages' ] );
  1083. unset( $cached_direct_pages );
  1084. foreach( $_POST[ 'direct_pages' ] as $page ) {
  1085. $page = $wpdb->escape( $page );
  1086. if( $page != '' ) {
  1087. $cached_direct_pages[] = $page;
  1088. $out .= "'$page', ";
  1089. }
  1090. }
  1091. if( $out == '' ) {
  1092. $out = "'', ";
  1093. }
  1094. }
  1095. if( $valid_nonce && array_key_exists('new_direct_page', $_POST) && $_POST[ 'new_direct_page' ] && '' != $_POST[ 'new_direct_page' ] ) {
  1096. $page = str_replace( get_option( 'siteurl' ), '', $_POST[ 'new_direct_page' ] );
  1097. if( substr( $page, 0, 1 ) != '/' )
  1098. $page = '/' . $page;
  1099. $page = $wpdb->escape( $page );
  1100. if( in_array( $page, $cached_direct_pages ) == false ) {
  1101. $cached_direct_pages[] = $page;
  1102. $out .= "'$page', ";
  1103. }
  1104. }
  1105. if( $out != '' ) {
  1106. $out = substr( $out, 0, -2 );
  1107. $out = '$cached_direct_pages = array( ' . $out . ' );';
  1108. wp_cache_replace_line('^ *\$cached_direct_pages', "$out", $wp_cache_config_file);
  1109. prune_super_cache( $cache_path, true );
  1110. }
  1111. if( !empty( $expiredfiles ) ) {
  1112. foreach( $expiredfiles as $file ) {
  1113. if( $file != '' ) {
  1114. $firstfolder = explode( '/', $file );
  1115. $firstfolder = ABSPATH . $firstfolder[1];
  1116. $file = ABSPATH . $file;
  1117. @unlink( trailingslashit( $file ) . 'index.html' );
  1118. @unlink( trailingslashit( $file ) . 'index.html.gz' );
  1119. RecursiveFolderDelete( trailingslashit( $firstfolder ) );
  1120. }
  1121. }
  1122. }
  1123. if( $valid_nonce && array_key_exists('deletepage', $_POST) && $_POST[ 'deletepage' ] ) {
  1124. $page = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_POST['deletepage']) );
  1125. $pagefile = ABSPATH . $page . 'index.html';
  1126. $firstfolder = explode( '/', $page );
  1127. $firstfolder = ABSPATH . $firstfolder[1];
  1128. $page = ABSPATH . $page;
  1129. if( is_file( $pagefile ) && is_writeable_ACLSafe( $pagefile ) && is_writeable_ACLSafe( $firstfolder ) ) {
  1130. @unlink( $pagefile );
  1131. @unlink( $pagefile . '.gz' );
  1132. RecursiveFolderDelete( $firstfolder );
  1133. echo "<strong>" . sprintf( __( '%s removed!', 'wp-super-cache' ), $pagefile ) . "</strong>";
  1134. prune_super_cache( $cache_path, true );
  1135. }
  1136. }
  1137. $readonly = '';
  1138. if( !is_writeable_ACLSafe( ABSPATH ) ) {
  1139. $readonly = 'READONLY';
  1140. ?><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
  1141. } else {
  1142. ?><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
  1143. }
  1144. echo '<form name="direct_page" action="#direct" method="post">';
  1145. if( is_array( $cached_direct_pages ) ) {
  1146. $out = '';
  1147. foreach( $cached_direct_pages as $page ) {
  1148. if( $page == '' )
  1149. continue;
  1150. $generated = '';
  1151. if( is_file( ABSPATH . $page . '/index.html' ) )
  1152. $generated = '<input type="Submit" name="deletepage" value="' . $page . '">';
  1153. $out .= "<tr><td><input type='text' $readonly name='direct_pages[]' size='30' value='$page' /></td><td>$generated</td></tr>";
  1154. }
  1155. if( $out != '' ) {
  1156. ?><table><tr><th><?php _e( 'Existing direct page', 'wp-super-cache' ); ?></th><th><?php _e( 'Delete cached file', 'wp-super-cache' ); ?></th></tr><?php
  1157. echo "$out</table>";
  1158. }
  1159. }
  1160. if( $readonly != 'READONLY' )
  1161. echo __( "Add direct page:", 'wp-super-cache' ) . "<input type='text' $readonly name='new_direct_page' size='30' value='' />";
  1162. echo "<p>" . sprintf( __( "Directly cached files are files created directly off %s where your blog lives. This feature is only useful if you are expecting a major Digg or Slashdot level of traffic to one post or page.", 'wp-super-cache' ), ABSPATH ) . "</p>";
  1163. if( $readonly != 'READONLY' ) {
  1164. echo "<p>" . sprintf( __( 'For example: to cache <em>%1$sabout/</em>, you would enter %1$sabout/ or /about/. The cached file will be generated the next time an anonymous user visits that page.', 'wp-super-cache' ), trailingslashit( get_option( 'siteurl' ) ) ) . "</p>";
  1165. echo "<p>" . __( 'Make the textbox blank to remove it from the list of direct pages and delete the cached file.', 'wp-super-cache' ) . "</p>";
  1166. }
  1167. wp_nonce_field('wp-cache');
  1168. if( $readonly != 'READONLY' )
  1169. echo "<div class='submit'><input type='submit' ' . SUBMITDISABLED . 'value='" . __( 'Update Direct Pages', 'wp-super-cache' ) . " &raquo;' /></div>";
  1170. echo "</form>\n";
  1171. ?></fieldset><?php
  1172. } // if $super_cache_enabled
  1173. }
  1174. function RecursiveFolderDelete ( $folderPath ) { // from http://www.php.net/manual/en/function.rmdir.php
  1175. if( trailingslashit( constant( 'ABSPATH' ) ) == trailingslashit( $folderPath ) )
  1176. return false;
  1177. if ( @is_dir ( $folderPath ) ) {
  1178. $dh = @opendir($folderPath);
  1179. while (false !== ($value = @readdir($dh))) {
  1180. if ( $value != "." && $value != ".." ) {
  1181. $value = $folderPath . "/" . $value;
  1182. if ( @is_dir ( $value ) ) {
  1183. RecursiveFolderDelete ( $value );
  1184. }
  1185. }
  1186. }
  1187. return @rmdir ( $folderPath );
  1188. } else {
  1189. return FALSE;
  1190. }
  1191. }
  1192. function wp_cache_edit_max_time () {
  1193. global $cache_max_time, $wp_cache_config_file, $valid_nonce, $cache_enabled, $super_cache_enabled;
  1194. if( !isset( $cache_max_time ) )
  1195. $cache_max_time = 3600;
  1196. if(isset($_POST['wp_max_time']) && $valid_nonce) {
  1197. $max_time = (int)$_POST['wp_max_time'];
  1198. $cache_max_time = $max_time;
  1199. wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file);
  1200. }
  1201. ?><fieldset class="options">
  1202. <a name='expirytime'></a>
  1203. <h3><?php _e( 'Expiry Time &amp; Garbage Collection', 'wp-super-cache' ); ?></h3><?php
  1204. echo '<form name="wp_edit_max_time" action="#expirytime" method="post">';
  1205. echo '<label for="wp_max_time">' . __( 'Expire time:', 'wp-super-cache' ) . '</label> ';
  1206. echo "<input type=\"text\" size=6 name=\"wp_max_time\" value=\"$cache_max_time\" /> " . __( "seconds", 'wp-super-cache' );
  1207. echo "<h4>" . __( 'Garbage Collection', 'wp-super-cache' ) . "</h4><p>" . __( 'If the 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>";
  1208. 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. 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>";
  1209. echo "<p>" . __( 'Set the expiry time to 0 seconds to disable garbage collection.', 'wp-super-cache' ) . "</p>";
  1210. echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Change Expiration', 'wp-super-cache' ) . ' &raquo;" /></div>';
  1211. wp_nonce_field('wp-cache');
  1212. echo "</form>\n";
  1213. ?></fieldset><?php
  1214. }
  1215. function wp_cache_sanitize_value($text, & $array) {
  1216. $text = esc_html(strip_tags($text));
  1217. $array = preg_split("/[\s,]+/", chop($text));
  1218. $text = var_export($array, true);
  1219. $text = preg_replace('/[\s]+/', ' ', $text);
  1220. return $text;
  1221. }
  1222. // from tehjosh at gamingg dot net http://uk2.php.net/manual/en/function.apache-request-headers.php#73964
  1223. // fixed bug in second substr()
  1224. if( !function_exists('apache_request_headers') ) {
  1225. function apache_request_headers() {
  1226. $headers = array();
  1227. foreach(array_keys($_SERVER) as $skey) {
  1228. if(substr($skey, 0, 5) == "HTTP_") {
  1229. $headername = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($skey, 5)))));
  1230. $headers[$headername] = $_SERVER[$skey];
  1231. }
  1232. }
  1233. return $headers;
  1234. }
  1235. }
  1236. function wp_cache_edit_rejected_ua() {
  1237. global $cache_rejected_user_agent, $wp_cache_config_file, $valid_nonce;
  1238. if ( !function_exists( 'apache_request_headers' ) ) return;
  1239. if ( isset( $_POST[ 'wp_rejected_user_agent' ] ) && $valid_nonce ) {
  1240. $_POST[ 'wp_rejected_user_agent' ] = str_replace( ' ', '___', $_POST[ 'wp_rejected_user_agent' ] );
  1241. $text = str_replace( '___', ' ', wp_cache_sanitize_value( $_POST[ 'wp_rejected_user_agent' ], $cache_rejected_user_agent ) );
  1242. wp_cache_replace_line( '^ *\$cache_rejected_user_agent', "\$cache_rejected_user_agent = $text;", $wp_cache_config_file );
  1243. foreach( $cache_rejected_user_agent as $k => $ua ) {
  1244. $cache_rejected_user_agent[ $k ] = str_replace( '___', ' ', $ua );
  1245. }
  1246. reset( $cache_rejected_user_agent );
  1247. }
  1248. echo '<a name="useragents"></a><fieldset class="options"><h3>' . __( 'Rejected User Agents', 'wp-super-cache' ) . '</h3>';
  1249. 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";
  1250. echo '<form name="wp_edit_rejected_user_agent" action="#useragents" method="post">';
  1251. echo '<textarea name="wp_rejected_user_agent" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
  1252. foreach( $cache_rejected_user_agent as $ua ) {
  1253. echo esc_html( $ua ) . "\n";
  1254. }
  1255. echo '</textarea> ';
  1256. echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save UA Strings', 'wp-super-cache' ) . ' &raquo;" /></div>';
  1257. wp_nonce_field('wp-cache');
  1258. echo '</form>';
  1259. echo "</fieldset>\n";
  1260. }
  1261. function wp_cache_edit_rejected_pages() {
  1262. global $wp_cache_config_file, $valid_nonce, $wp_cache_pages;
  1263. if ( isset( $_POST[ 'wp_edit_rejected_pages' ] ) && $valid_nonce ) {
  1264. $pages = array( 'single', 'pages', 'archives', 'tag', 'frontpage', 'home', 'category', 'feed', 'search' );
  1265. foreach( $pages as $page ) {
  1266. if ( isset( $_POST[ 'wp_cache_pages' ][ $page ] ) ) {
  1267. $value = 1;
  1268. } else {
  1269. $value = 0;
  1270. }
  1271. wp_cache_replace_line('^ *\$wp_cache_pages\[ "' . $page . '" \]', "\$wp_cache_pages[ \"{$page}\" ] = $value;", $wp_cache_config_file);
  1272. $wp_cache_pages[ $page ] = $value;
  1273. }
  1274. }
  1275. echo '<a name="rejectpages"></a>';
  1276. echo '<p>' . __( 'Do not cache the following page types. See the <a href="http://codex.wordpress.org/Conditional_Tags">Conditional Tags</a> documentation for a complete discussion on each type.', 'wp-super-cache' ) . '</p>';
  1277. echo '<form name="wp_edit_rejected_pages" action="#rejectpages" method="post">';
  1278. echo '<input type="hidden" name="wp_edit_rejected_pages" value="1" />';
  1279. echo '<label><input type="checkbox" value="1" name="wp_cache_pages[single]" ' . checked( 1, $wp_cache_pages[ 'single' ], false ) . ' /> ' . __( 'Single Posts', 'wp-super-cache' ) . ' (is_single)</label><br />';
  1280. echo '<label><input type="checkbox" value="1" name="wp_cache_pages[pages]" ' . checked( 1, $wp_cache_pages[ 'pages' ], false ) . ' /> ' . __( 'Pages', 'wp-super-cache' ) . ' (is_page)</label><br />';
  1281. echo '<label><input type="checkbox" value="1" name="wp_cache_pages[frontpage]" ' . checked( 1, $wp_cache_pages[ 'frontpage' ], false ) . ' /> ' . __( 'Front Page', 'wp-super-cache' ) . ' (is_front_page)</label><br />';
  1282. echo '&nbsp;&nbsp;<label><input type="checkbox" value="1" name="wp_cache_pages[home]" ' . checked( 1, $wp_cache_pages[ 'home' ], false ) . ' /> ' . __( 'Home', 'wp-super-cache' ) . ' (is_home)</label><br />';
  1283. 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 />';
  1284. 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 />';
  1285. 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 />';
  1286. 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 />';
  1287. 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 />';
  1288. echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save' ) . ' &raquo;" /></div>';
  1289. wp_nonce_field('wp-cache');
  1290. echo "</form>\n";
  1291. }
  1292. function wp_cache_edit_rejected() {
  1293. global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file, $valid_nonce;
  1294. if(isset($_REQUEST['wp_rejected_uri']) && $valid_nonce) {
  1295. $text = wp_cache_sanitize_value( str_replace( '\\\\', '\\', $_REQUEST['wp_rejected_uri'] ), $cache_rejected_uri );
  1296. wp_cache_replace_line('^ *\$cache_rejected_uri', "\$cache_rejected_uri = $text;", $wp_cache_config_file);
  1297. }
  1298. echo '<a name="rejecturi"></a>';
  1299. echo '<form name="wp_edit_rejected" action="#rejecturi" method="post">';
  1300. 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";
  1301. echo '<textarea name="wp_rejected_uri" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
  1302. foreach ($cache_rejected_uri as $file) {
  1303. echo esc_html( $file ) . "\n";
  1304. }
  1305. echo '</textarea> ';
  1306. echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save Strings', 'wp-super-cache' ) . ' &raquo;" /></div>';
  1307. wp_nonce_field('wp-cache');
  1308. echo "</form>\n";
  1309. }
  1310. function wp_cache_edit_accepted() {
  1311. global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file, $valid_nonce;
  1312. if(isset($_REQUEST['wp_accepted_files']) && $valid_nonce) {
  1313. $text = wp_cache_sanitize_value($_REQUEST['wp_accepted_files'], $cache_acceptable_files);
  1314. wp_cache_replace_line('^ *\$cache_acceptable_files', "\$cache_acceptable_files = $text;", $wp_cache_config_file);
  1315. }
  1316. echo '<a name="cancache"></a>';
  1317. echo '<div style="clear:both"></div><form name="wp_edit_accepted" action="#cancache" method="post">';
  1318. 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";
  1319. echo '<textarea name="wp_accepted_files" cols="40" rows="8" style="width: 50%; font-size: 12px;" class="code">';
  1320. foreach ($cache_acceptable_files as $file) {
  1321. echo esc_html($file) . "\n";
  1322. }
  1323. echo '</textarea> ';
  1324. echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save Files', 'wp-super-cache' ) . ' &raquo;" /></div>';
  1325. wp_nonce_field('wp-cache');
  1326. echo "</form>\n";
  1327. }
  1328. function wp_cache_debug_settings() {
  1329. 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;
  1330. 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;
  1331. if ( !isset( $wp_cache_debug_level ) )
  1332. $wp_cache_debug_level = 1;
  1333. if ( isset( $_POST[ 'wp_cache_debug' ] ) && $valid_nonce ) {
  1334. $wp_super_cache_debug = intval( $_POST[ 'wp_super_cache_debug' ] );
  1335. wp_cache_replace_line('^ *\$wp_super_cache_debug', "\$wp_super_cache_debug = '$wp_super_cache_debug';", $wp_cache_config_file);
  1336. $wp_cache_debug_email = esc_html( $_POST[ 'wp_cache_debug_email' ] );
  1337. wp_cache_replace_line('^ *\$wp_cache_debug_email', "\$wp_cache_debug_email = '$wp_cache_debug_email';", $wp_cache_config_file);
  1338. $wp_cache_debug_to_file = intval( $_POST[ 'wp_cache_debug_to_file' ] );
  1339. if ( $wp_cache_debug_to_file && ( ( isset( $wp_cache_debug_log ) && $wp_cache_debug_log == '' ) || !isset( $wp_cache_debug_log ) ) ) {
  1340. $wp_cache_debug_log = md5( time() ) . ".txt";
  1341. } elseif( $wp_cache_debug_to_file == false ) {
  1342. $wp_cache_debug_log = "";
  1343. }
  1344. wp_cache_replace_line('^ *\$wp_cache_debug_to_file', "\$wp_cache_debug_to_file = '$wp_cache_debug_to_file';", $wp_cache_config_file);
  1345. wp_cache_replace_line('^ *\$wp_cache_debug_log', "\$wp_cache_debug_log = '$wp_cache_debug_log';", $wp_cache_config_file);
  1346. $wp_cache_debug_ip = esc_html( $_POST[ 'wp_cache_debug_ip' ] );
  1347. wp_cache_replace_line('^ *\$wp_cache_debug_ip', "\$wp_cache_debug_ip = '$wp_cache_debug_ip';", $wp_cache_config_file);
  1348. $wp_cache_debug_level = (int)$_POST[ 'wp_cache_debug_level' ];
  1349. wp_cache_replace_line('^ *\$wp_cache_debug_level', "\$wp_cache_debug_level = '$wp_cache_debug_level';", $wp_cache_config_file);
  1350. $wp_super_cache_front_page_check = (int)$_POST[ 'wp_super_cache_front_page_check' ];
  1351. 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);
  1352. $wp_super_cache_front_page_clear = (int)$_POST[ 'wp_super_cache_front_page_clear' ];
  1353. 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);
  1354. $wp_super_cache_front_page_text = esc_html( $_POST[ 'wp_super_cache_front_page_text' ] );
  1355. 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);
  1356. $wp_super_cache_front_page_notification = (int)$_POST[ 'wp_super_cache_front_page_notification' ];
  1357. 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);
  1358. if ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 1 && !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
  1359. wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
  1360. 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 );
  1361. }
  1362. }
  1363. echo '<a name="debug"></a>';
  1364. echo '<fieldset class="options">';
  1365. if ( ( isset( $wp_cache_debug_log ) && $wp_cache_debug_log != '' ) || ( isset( $wp_cache_debug_email ) && $wp_cache_debug_email != '' ) ) {
  1366. echo "<p>" . __( 'Currently logging to: ', 'wp-super-cache' );
  1367. if ( isset( $wp_cache_debug_log ) && $wp_cache_debug_log != '' ) {
  1368. $url = str_replace( ABSPATH, '', "{$cache_path}{$wp_cache_debug_log}" );
  1369. echo "<a href='" . site_url( $url ) . "'>$cache_path{$wp_cache_debug_log}</a> ";
  1370. }
  1371. if ( isset( $wp_cache_debug_email ) )
  1372. echo " $wp_cache_debug_email ";
  1373. echo "</p>";
  1374. }
  1375. 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>';
  1376. 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>';
  1377. echo '<div style="clear:both"></div><form name="wp_cache_debug" action="" method="post">';
  1378. echo "<input type='hidden' name='wp_cache_debug' value='1' /><br />";
  1379. echo "<table class='form-table'>";
  1380. 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>";
  1381. 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>";
  1382. 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>";
  1383. 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>";
  1384. echo "<tr><td>" . __( 'Log level', 'wp-super-cache' ) . "</td><td> ";
  1385. for( $t = 1; $t <= 5; $t++ ) {
  1386. echo "<input type='radio' name='wp_cache_debug_level' value='$t' ";
  1387. echo $wp_cache_debug_level == $t ? "checked='checked' " : '';
  1388. echo "/> $t ";
  1389. }
  1390. echo " " . __( '(1 = less, 5 = more, may cause severe server load.)', 'wp-super-cache' ) . "</td></tr>";
  1391. echo "</table>\n";
  1392. if ( isset( $wp_super_cache_advanced_debug ) ) {
  1393. 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>';
  1394. 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>";
  1395. echo "<table class='form-table'>";
  1396. echo "<tr><td valign='top' colspan='2'><input type='checkbox' name='wp_super_cache_front_page_check' value='1' " . checked( 1, $wp_super_cache_front_page_check, false ) . " /> " . __( 'Check front page every 5 minutes.', 'wp-super-cache' ) . "</td></tr>";
  1397. echo "<tr><td valign='top'>" . __( 'Front page text', 'wp-super-cache' ) . "</td><td> <input type='text' size='30' name='wp_super_cache_front_page_text' value='{$wp_super_cache_front_page_text}' /> (" . __( 'Text to search for on your front page. If this text is missing the cache will be cleared. Leave blank to disable.', 'wp-super-cache' ) . ")</td></tr>";
  1398. echo "<tr><td valign='top' colspan='2'><input type='checkbox' name='wp_super_cache_front_page_clear' value='1' " . checked( 1, $wp_super_cache_front_page_clear, false ) . " /> " . __( 'Clear cache on error.', 'wp-super-cache' ) . "</td></tr>";
  1399. echo "<tr><td valign='top' colspan='2'><input type='checkbox' name='wp_super_cache_front_page_notification' value='1' " . checked( 1, $wp_super_cache_front_page_notification, false ) . " /> " . __( 'Email the blog admin when checks are made. (useful for testing)', 'wp-super-cache' ) . "</td></tr>";
  1400. echo "</table>\n";
  1401. }
  1402. echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save', 'wp-super-cache' ) . ' &raquo;" /></div>';
  1403. wp_nonce_field('wp-cache');
  1404. echo "</form>\n";
  1405. echo '</fieldset>';
  1406. }
  1407. function wp_cache_enable() {
  1408. global $wp_cache_config_file, $cache_enabled, $supercachedir;
  1409. if(get_option('gzipcompression')) {
  1410. echo "<strong>" . __( 'Error: GZIP compression is enabled, disable it if you want to enable wp-cache.', 'wp-super-cache' ) . "</strong>";
  1411. return false;
  1412. }
  1413. if( wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = true;', $wp_cache_config_file) ) {
  1414. $cache_enabled = true;
  1415. }
  1416. wp_super_cache_enable();
  1417. }
  1418. function wp_cache_disable() {
  1419. global $wp_cache_config_file, $cache_enabled;
  1420. if (wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file)) {
  1421. $cache_enabled = false;
  1422. }
  1423. }
  1424. function wp_super_cache_enable() {
  1425. global $supercachedir, $wp_cache_config_file, $super_cache_enabled;
  1426. if( is_dir( $supercachedir . ".disabled" ) )
  1427. if( is_dir( $supercachedir ) ) {
  1428. prune_super_cache( $supercachedir . ".disabled", true );
  1429. @unlink( $supercachedir . ".disabled" );
  1430. } else {
  1431. @rename( $supercachedir . ".disabled", $supercachedir );
  1432. }
  1433. wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = true;', $wp_cache_config_file);
  1434. $super_cache_enabled = true;
  1435. }
  1436. function wp_super_cache_disable() {
  1437. global $cache_path, $supercachedir, $wp_cache_config_file, $super_cache_enabled;
  1438. wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = false;', $wp_cache_config_file);
  1439. if( is_dir( $supercachedir ) )
  1440. @rename( $supercachedir, $supercachedir . ".disabled" );
  1441. $super_cache_enabled = false;
  1442. sleep( 1 ); // allow existing processes to write to the supercachedir and then delete it
  1443. if (function_exists ('prune_super_cache') && is_dir( $supercachedir ) ) {
  1444. prune_super_cache( $cache_path, true );
  1445. }
  1446. }
  1447. function wp_cache_is_enabled() {
  1448. global $wp_cache_config_file;
  1449. if(get_option('gzipcompression')) {
  1450. 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' );
  1451. return false;
  1452. }
  1453. $lines = file($wp_cache_config_file);
  1454. foreach($lines as $line) {
  1455. if (preg_match('/^ *\$cache_enabled *= *true *;/', $line))
  1456. return true;
  1457. }
  1458. return false;
  1459. }
  1460. function wp_cache_replace_line($old, $new, $my_file) {
  1461. if (!is_writeable_ACLSafe($my_file)) {
  1462. echo "Error: file $my_file is not writable.\n";
  1463. return false;
  1464. }
  1465. $found = false;
  1466. $lines = file($my_file);
  1467. foreach($lines as $line) {
  1468. if ( preg_match("/$old/", $line)) {
  1469. $found = true;
  1470. break;
  1471. }
  1472. }
  1473. if ($found) {
  1474. $fd = fopen($my_file, 'w');
  1475. foreach($lines as $line) {
  1476. if ( !preg_match("/$old/", $line))
  1477. fputs($fd, $line);
  1478. else {
  1479. fputs($fd, "$new //Added by WP-Cache Manager\n");
  1480. }
  1481. }
  1482. fclose($fd);
  1483. return true;
  1484. }
  1485. $fd = fopen($my_file, 'w');
  1486. $done = false;
  1487. foreach($lines as $line) {
  1488. if ( $done || !preg_match('/^(if\ \(\ \!\ )?define|\$|\?>/', $line) ) {
  1489. fputs($fd, $line);
  1490. } else {
  1491. fputs($fd, "$new //Added by WP-Cache Manager\n");
  1492. fputs($fd, $line);
  1493. $done = true;
  1494. }
  1495. }
  1496. fclose($fd);
  1497. return true;
  1498. }
  1499. function wp_cache_verify_cache_dir() {
  1500. global $cache_path, $blog_cache_dir, $blogcacheid;
  1501. $dir = dirname($cache_path);
  1502. if ( !file_exists($cache_path) ) {
  1503. if ( !is_writeable_ACLSafe( $dir ) || !($dir = mkdir( $cache_path ) ) ) {
  1504. 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 );
  1505. return false;
  1506. }
  1507. }
  1508. if ( !is_writeable_ACLSafe($cache_path)) {
  1509. 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 );
  1510. return false;
  1511. }
  1512. if ( '/' != substr($cache_path, -1)) {
  1513. $cache_path .= '/';
  1514. }
  1515. if( false == is_dir( $blog_cache_dir ) ) {
  1516. @mkdir( $cache_path . "blogs" );
  1517. if( $blog_cache_dir != $cache_path . "blogs/" )
  1518. @mkdir( $blog_cache_dir );
  1519. }
  1520. if( false == is_dir( $blog_cache_dir . 'meta' ) )
  1521. @mkdir( $blog_cache_dir . 'meta' );
  1522. return true;
  1523. }
  1524. function wp_cache_verify_config_file() {
  1525. global $wp_cache_config_file, $wp_cache_config_file_sample, $sem_id, $cache_path;
  1526. $new = false;
  1527. $dir = dirname($wp_cache_config_file);
  1528. if ( file_exists($wp_cache_config_file) ) {
  1529. $lines = join( ' ', file( $wp_cache_config_file ) );
  1530. if( strpos( $lines, 'WPCACHEHOME' ) === false ) {
  1531. if( is_writeable_ACLSafe( $wp_cache_config_file ) ) {
  1532. @unlink( $wp_cache_config_file );
  1533. } else {
  1534. echo "<strong>" . __( 'Error', 'wp-super-cache' ) . ":</strong> " . sprintf( __( 'Your WP-Cache config file (<strong>%s</strong>) is out of date and not writable by the Web server.Please delete it and refresh this page.', 'wp-super-cache' ), $wp_cache_config_file );
  1535. return false;
  1536. }
  1537. }
  1538. } elseif( !is_writeable_ACLSafe($dir)) {
  1539. echo "<strong>" . __( 'Error', 'wp-super-cache' ) . ":</strong> " . sprintf( __( 'Configuration file missing and %1$s directory (<strong>%2$s</strong>) is not writable by the Web server.Check its permissions.', 'wp-super-cache' ), WP_CONTENT_DIR, $dir );
  1540. return false;
  1541. }
  1542. if ( !file_exists($wp_cache_config_file) ) {
  1543. if ( !file_exists($wp_cache_config_file_sample) ) {
  1544. echo "<strong>" . __( 'Error', 'wp-super-cache' ) . ":</strong> " . sprintf( __( 'Sample WP-Cache config file (<strong>%s</strong>) does not exist.Verify you installation.', 'wp-super-cache' ), $wp_cache_config_file_sample );
  1545. return false;
  1546. }
  1547. copy($wp_cache_config_file_sample, $wp_cache_config_file);
  1548. $dir = str_replace( str_replace( '\\', '/', WP_CONTENT_DIR ), '', str_replace( '\\', '/', dirname(__FILE__) ) );
  1549. if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
  1550. wp_cache_replace_line('define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/\" );", $wp_cache_config_file);
  1551. } elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
  1552. wp_cache_replace_line('define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/wp-super-cache/\" );", $wp_cache_config_file);
  1553. }
  1554. $new = true;
  1555. }
  1556. if( $sem_id == 5419 && $cache_path != '' ) {
  1557. $sem_id = crc32( $_SERVER[ 'HTTP_HOST' ] . $cache_path ) & 0x7fffffff;
  1558. wp_cache_replace_line('sem_id', '$sem_id = ' . $sem_id . ';', $wp_cache_config_file);
  1559. }
  1560. require($wp_cache_config_file);
  1561. return true;
  1562. }
  1563. function wp_cache_create_advanced_cache() {
  1564. global $wp_cache_link, $wp_cache_file;
  1565. $ret = true;
  1566. $file = file_get_contents( $wp_cache_file );
  1567. $file = str_replace( 'CACHEHOME', constant( 'WPCACHEHOME' ), $file );
  1568. $fp = @fopen( $wp_cache_link, 'w' );
  1569. if( $fp ) {
  1570. fputs( $fp, $file );
  1571. fclose( $fp );
  1572. } else {
  1573. $ret = false;
  1574. }
  1575. return $ret;
  1576. }
  1577. function wp_cache_check_link() {
  1578. global $wp_cache_link, $wp_cache_file;
  1579. $ret = true;
  1580. if( file_exists($wp_cache_link) ) {
  1581. $file = file_get_contents( $wp_cache_link );
  1582. if( strpos( $file, "WP SUPER CACHE 0.8.9.1" ) ) {
  1583. return true;
  1584. } else {
  1585. if( !@unlink($wp_cache_link) ) {
  1586. $ret = false;
  1587. } else {
  1588. $ret = wp_cache_create_advanced_cache();
  1589. }
  1590. }
  1591. } else {
  1592. $ret = wp_cache_create_advanced_cache();
  1593. }
  1594. if( false == $ret ) {
  1595. 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>";
  1596. echo "<p><ul><li>" . __( '1. If it already exists please delete the file first.', 'wp-super-cache' ) . "</li>";
  1597. 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>";
  1598. echo "<li>" . sprintf( __( '3. Refresh this page to update <em>%s/advanced-cache.php</em>', 'wp-super-cache' ), WP_CONTENT_DIR ) . "</li></ul>";
  1599. 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>";
  1600. 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 );
  1601. echo "</div>";
  1602. return false;
  1603. }
  1604. return true;
  1605. }
  1606. function wp_cache_check_global_config() {
  1607. global $wp_cache_check_wp_config;
  1608. if ( !isset( $wp_cache_check_wp_config ) )
  1609. return true;
  1610. if ( file_exists( ABSPATH . 'wp-config.php') ) {
  1611. $global = ABSPATH . 'wp-config.php';
  1612. } else {
  1613. $global = dirname(ABSPATH) . '/wp-config.php';
  1614. }
  1615. $line = 'define(\'WP_CACHE\', true);';
  1616. if (!is_writeable_ACLSafe($global) || !wp_cache_replace_line('define *\( *\'WP_CACHE\'', $line, $global) ) {
  1617. if ( defined( 'WP_CACHE' ) && constant( 'WP_CACHE' ) == false ) {
  1618. 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>";
  1619. } else {
  1620. 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>";;
  1621. 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>";
  1622. }
  1623. return false;
  1624. } else {
  1625. 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' ) . "</p></div>";
  1626. }
  1627. return true;
  1628. }
  1629. function wp_cache_files() {
  1630. global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled, $blog_cache_dir, $cache_compression;
  1631. global $wp_cache_object_cache, $wp_cache_preload_on;
  1632. if ( '/' != substr($cache_path, -1)) {
  1633. $cache_path .= '/';
  1634. }
  1635. if ( $valid_nonce ) {
  1636. if(isset($_REQUEST['wp_delete_cache'])) {
  1637. wp_cache_clean_cache($file_prefix);
  1638. }
  1639. if(isset($_REQUEST['wp_delete_expired'])) {
  1640. wp_cache_clean_expired($file_prefix);
  1641. }
  1642. }
  1643. echo "<a name='listfiles'></a>";
  1644. echo '<fieldset class="options" id="show-this-fieldset"><h3>' . __( 'Cache Contents', 'wp-super-cache' ) . '</h3>';
  1645. if ( $wp_cache_object_cache ) {
  1646. echo "<p>" . __( "Object cache in use. No cache listing available.", 'wp-super-cache' ) . "</p>";
  1647. wp_cache_delete_buttons();
  1648. echo "</fieldset>";
  1649. return false;
  1650. }
  1651. $cache_stats = get_option( 'supercache_stats' );
  1652. if ( !is_array( $cache_stats ) || ( $valid_nonce && array_key_exists('action', $_GET) && $_GET[ 'action' ] == 'regenerate_cache_stats' ) ) {
  1653. $list_files = false; // it doesn't list supercached files, and removing single pages is buggy
  1654. $count = 0;
  1655. $expired = 0;
  1656. $now = time();
  1657. if ( ($handle = @opendir( $blog_cache_dir . 'meta/' )) ) {
  1658. $wp_cache_fsize = 0;
  1659. if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletewpcache' ) {
  1660. $deleteuri = preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '/index.php', '/', str_replace( '..', '', preg_replace("/(\?.*)?$/", '', base64_decode( $_GET[ 'uri' ] ) ) ) ) );
  1661. $deleteuri = str_replace( '\\', '', $deleteuri );
  1662. } else {
  1663. $deleteuri = '';
  1664. }
  1665. if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletesupercache' ) {
  1666. $supercacheuri = preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '/index.php', '/', str_replace( '..', '', preg_replace("/(\?.*)?$/", '', base64_decode( $_GET[ 'uri' ] ) ) ) ) );
  1667. $supercacheuri = trailingslashit( str_replace( '\\', '', $supercacheuri ) );
  1668. printf( __( "Deleting supercache file: <strong>%s</strong><br />", 'wp-super-cache' ), $supercacheuri );
  1669. @unlink( $cache_path . 'supercache/' . $supercacheuri . 'index.html' );
  1670. @unlink( $cache_path . 'supercache/' . $supercacheuri . 'index.html.gz' );
  1671. prune_super_cache( $cache_path . 'supercache/' . $supercacheuri . 'page', true );
  1672. @rmdir( $cache_path . 'supercache/' . $supercacheuri );
  1673. }
  1674. while( false !== ($file = readdir($handle))) {
  1675. if ( preg_match("/^$file_prefix.*\.meta/", $file) ) {
  1676. $content_file = preg_replace("/meta$/", "html", $file);
  1677. $mtime = filemtime( $blog_cache_dir . 'meta/' . $file );
  1678. if ( ! ( $fsize = @filesize( $blog_cache_dir . $content_file ) ) )
  1679. continue; // .meta does not exists
  1680. $age = $now - $mtime;
  1681. if ( $valid_nonce && $_GET[ 'listfiles' ] ) {
  1682. $meta = unserialize( file_get_contents( $blog_cache_dir . 'meta/' . $file ) );
  1683. if ( $deleteuri != '' && $meta[ 'uri' ] == $deleteuri ) {
  1684. printf( __( "Deleting wp-cache file: <strong>%s</strong><br />", 'wp-super-cache' ), $deleteuri );
  1685. @unlink( $blog_cache_dir . 'meta/' . $file );
  1686. @unlink( $blog_cache_dir . $content_file );
  1687. continue;
  1688. }
  1689. $meta[ 'age' ] = $age;
  1690. if ( $cache_max_time > 0 && $age > $cache_max_time ) {
  1691. $expired_list[ $age ][] = $meta;
  1692. } else {
  1693. $cached_list[ $age ][] = $meta;
  1694. }
  1695. }
  1696. if ( $cache_max_time > 0 && $age > $cache_max_time ) {
  1697. $expired++;
  1698. } else {
  1699. $count++;
  1700. }
  1701. $wp_cache_fsize += $fsize;
  1702. $fsize = intval($fsize/1024);
  1703. }
  1704. }
  1705. closedir($handle);
  1706. }
  1707. if( $wp_cache_fsize != 0 ) {
  1708. $wp_cache_fsize = $wp_cache_fsize/1024;
  1709. } else {
  1710. $wp_cache_fsize = 0;
  1711. }
  1712. if( $wp_cache_fsize > 1024 ) {
  1713. $wp_cache_fsize = number_format( $wp_cache_fsize / 1024, 2 ) . "MB";
  1714. } elseif( $wp_cache_fsize != 0 ) {
  1715. $wp_cache_fsize = number_format( $wp_cache_fsize, 2 ) . "KB";
  1716. } else {
  1717. $wp_cache_fsize = '0KB';
  1718. }
  1719. if( $cache_enabled == true && $super_cache_enabled == true ) {
  1720. $now = time();
  1721. $sizes = array( 'expired' => 0, 'expired_list' => array(), 'cached' => 0, 'cached_list' => array(), 'ts' => 0 );
  1722. if (is_dir($supercachedir)) {
  1723. if( $dh = opendir( $supercachedir ) ) {
  1724. while( ( $entry = readdir( $dh ) ) !== false ) {
  1725. if ($entry != '.' && $entry != '..') {
  1726. $sizes = wpsc_dirsize( trailingslashit( $supercachedir ) . $entry, $sizes );
  1727. }
  1728. }
  1729. closedir($dh);
  1730. }
  1731. } else {
  1732. $filem = @filemtime( $supercachedir );
  1733. if ( false == $wp_cache_preload_on && is_file( $supercachedir ) && $cache_max_time > 0 && $filem + $cache_max_time <= $now ) {
  1734. $sizes[ 'expired' ] ++;
  1735. if ( $valid_nonce && $_GET[ 'listfiles' ] )
  1736. $sizes[ 'expired_list' ][ str_replace( $cache_path . 'supercache/' , '', $supercachedir ) ] = $now - $filem;
  1737. } else {
  1738. if ( $valid_nonce && $_GET[ 'listfiles' ] && $filem )
  1739. $sizes[ 'cached_list' ][ str_replace( $cache_path . 'supercache/' , '', $supercachedir ) ] = $now - $filem;
  1740. }
  1741. }
  1742. $sizes[ 'ts' ] = time();
  1743. }
  1744. $cache_stats = array( 'generated' => time(), 'supercache' => $sizes, 'wpcache' => array( 'cached' => $count, 'expired' => $expired, 'fsize' => $wp_cache_fsize ) );
  1745. update_option( 'supercache_stats', $cache_stats );
  1746. } else {
  1747. 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>";
  1748. echo "<a href='" . wp_nonce_url( add_query_arg( array( 'page' => 'wpsupercache', 'tab' => 'tester', 'action' => 'regenerate_cache_stats' ) ), 'wp-cache' ) . "'>" . __( 'Regenerate cache stats' ) . "</a>";
  1749. if ( is_array( $cache_stats ) ) {
  1750. echo "<p>" . sprintf( __( 'Cache stats last generated: %s minutes ago.', 'wp-super-cache' ), number_format( ( time() - $cache_stats[ 'generated' ] ) / 60 ) ) . "</p>";
  1751. }
  1752. $cache_stats = get_option( 'supercache_stats' );
  1753. }// regerate stats cache
  1754. if ( is_array( $cache_stats ) ) {
  1755. echo "<p><strong>" . __( 'WP-Cache', 'wp-super-cache' ) . " ({$cache_stats[ 'wpcache' ][ 'fsize' ]})</strong></p>";
  1756. echo "<ul><li>" . sprintf( __( '%s Cached Pages', 'wp-super-cache' ), $cache_stats[ 'wpcache' ][ 'cached' ] ) . "</li>";
  1757. echo "<li>" . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), $cache_stats[ 'wpcache' ][ 'expired' ] ) . "</li></ul>";
  1758. $divisor = $cache_compression == 1 ? 2 : 1;
  1759. if( $cache_enabled == true && $super_cache_enabled == true ) {
  1760. if ( array_key_exists('fsize', (array)$cache_stats[ 'supercache' ]) )
  1761. $fsize = $cache_stats[ 'supercache' ][ 'fsize' ] / 1024;
  1762. else
  1763. $fsize = 0;
  1764. if( $fsize > 1024 ) {
  1765. $fsize = number_format( $fsize / 1024, 2 ) . "MB";
  1766. } elseif( $fsize != 0 ) {
  1767. $fsize = number_format( $fsize, 2 ) . "KB";
  1768. } else {
  1769. $fsize = "0KB";
  1770. }
  1771. echo "<p><strong>" . __( 'WP-Super-Cache', 'wp-super-cache' ) . " ({$fsize})</strong></p>";
  1772. echo "<ul><li>" . sprintf( __( '%s Cached Pages', 'wp-super-cache' ), intval( $cache_stats[ 'supercache' ][ 'cached' ] / $divisor ) ) . "</li>";
  1773. if (isset($now) && isset($sizes))
  1774. $age = intval(($now - $sizes['ts'])/60);
  1775. else
  1776. $age = 0;
  1777. echo "<li>" . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), intval( $cache_stats[ 'supercache' ][ 'expired' ] / $divisor ) ) . "</li></ul>";
  1778. }
  1779. if ( $valid_nonce && array_key_exists('listfiles', $_GET) && $_GET[ 'listfiles' ] ) {
  1780. echo "<div style='padding: 10px; border: 1px solid #333; height: 400px; width: 70%; overflow: auto'>";
  1781. if ( is_array( $cached_list ) && !empty( $cached_list ) ) {
  1782. echo "<h4>" . __( 'Fresh WP-Cached Files', 'wp-super-cache' ) . "</h4>";
  1783. 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>";
  1784. $c = 1;
  1785. $flip = 1;
  1786. ksort( $cached_list );
  1787. foreach( $cached_list as $age => $d ) {
  1788. foreach( $d as $details ) {
  1789. $bg = $flip ? 'style="background: #EAEAEA;"' : '';
  1790. 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";
  1791. $flip = !$flip;
  1792. $c++;
  1793. }
  1794. }
  1795. echo "</table>";
  1796. }
  1797. if ( is_array( $expired_list ) && !empty( $expired_list ) ) {
  1798. echo "<h4>" . __( 'Stale WP-Cached Files', 'wp-super-cache' ) . "</h4>";
  1799. 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>";
  1800. $c = 1;
  1801. $flip = 1;
  1802. ksort( $expired_list );
  1803. foreach( $expired_list as $age => $d ) {
  1804. foreach( $d as $details ) {
  1805. $bg = $flip ? 'style="background: #EAEAEA;"' : '';
  1806. 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";
  1807. $flip = !$flip;
  1808. $c++;
  1809. }
  1810. }
  1811. echo "</table>";
  1812. }
  1813. if ( is_array( $sizes[ 'cached_list' ] ) & !empty( $sizes[ 'cached_list' ] ) ) {
  1814. echo "<h4>" . __( 'Fresh Super Cached Files', 'wp-super-cache' ) . "</h4>";
  1815. 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>";
  1816. $c = 1;
  1817. $flip = 1;
  1818. ksort( $sizes[ 'cached_list' ] );
  1819. foreach( $sizes[ 'cached_list' ] as $age => $d ) {
  1820. foreach( $d as $uri => $n ) {
  1821. $bg = $flip ? 'style="background: #EAEAEA;"' : '';
  1822. 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";
  1823. $flip = !$flip;
  1824. $c++;
  1825. }
  1826. }
  1827. echo "</table>";
  1828. }
  1829. if ( is_array( $sizes[ 'expired_list' ] ) && !empty( $sizes[ 'expired_list' ] ) ) {
  1830. echo "<h4>" . __( 'Stale Super Cached Files', 'wp-super-cache' ) . "</h4>";
  1831. 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>";
  1832. $c = 1;
  1833. $flip = 1;
  1834. ksort( $sizes[ 'expired_list' ] );
  1835. foreach( $sizes[ 'expired_list' ] as $age => $d ) {
  1836. foreach( $d as $uri => $n ) {
  1837. $bg = $flip ? 'style="background: #EAEAEA;"' : '';
  1838. 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";
  1839. $flip = !$flip;
  1840. $c++;
  1841. }
  1842. }
  1843. echo "</table>";
  1844. }
  1845. echo "</div>";
  1846. echo "<p><a href='?page=wpsupercache#top'>" . __( 'Hide file list', 'wp-super-cache' ) . "</a></p>";
  1847. } elseif ( $cache_stats[ 'supercache' ][ 'cached' ] > 300 || $cache_stats[ 'supercache' ][ 'expired' ] > 300 || ( $cache_stats[ 'wpcache' ][ 'cached' ] / $divisor ) > 300 || ( $cache_stats[ 'wpcache' ][ 'expired' ] / $divisor) > 300 ) {
  1848. echo "<p><em>" . __( 'Too many cached files, no listing possible.', 'wp-super-cache' ) . "</em></p>";
  1849. } else {
  1850. 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>";
  1851. }
  1852. $last_gc = get_option( "wpsupercache_gc_time" );
  1853. if ( $cache_max_time > 0 && $last_gc ) {
  1854. $next_gc = $cache_max_time < 1800 ? $cache_max_time : 600;
  1855. $next_gc_mins = ( time() - $last_gc );
  1856. 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 ) );
  1857. printf( __( "Next GC in <strong>%s</strong> minutes", 'wp-super-cache' ), date( 'i:s', $next_gc - $next_gc_mins ) ) . "</p>";
  1858. }
  1859. if ( $cache_max_time > 0 )
  1860. 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>";
  1861. } // cache_stats
  1862. wp_cache_delete_buttons();
  1863. echo '</fieldset>';
  1864. }
  1865. function wp_cache_delete_buttons() {
  1866. echo '<form name="wp_cache_content_expired" action="#listfiles" method="post">';
  1867. echo '<input type="hidden" name="wp_delete_expired" />';
  1868. echo '<div class="submit" style="float:left"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Expired', 'wp-super-cache' ) . ' &raquo;" /></div>';
  1869. wp_nonce_field('wp-cache');
  1870. echo "</form>\n";
  1871. echo '<form name="wp_cache_content_delete" action="#listfiles" method="post">';
  1872. echo '<input type="hidden" name="wp_delete_cache" />';
  1873. echo '<div class="submit" style="float:left;margin-left:10px"><input id="deletepost" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Cache', 'wp-super-cache' ) . ' &raquo;" /></div>';
  1874. wp_nonce_field('wp-cache');
  1875. echo "</form>\n";
  1876. }
  1877. function delete_cache_dashboard() {
  1878. if ( false == wpsupercache_site_admin() )
  1879. return false;
  1880. if ( function_exists('current_user_can') && !current_user_can('manage_options') )
  1881. return false;
  1882. 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>";
  1883. }
  1884. add_action( 'dashmenu', 'delete_cache_dashboard' );
  1885. function wpsc_dirsize($directory, $sizes) {
  1886. global $cache_max_time, $cache_path, $valid_nonce, $wp_cache_preload_on;
  1887. $now = time();
  1888. if (is_dir($directory)) {
  1889. if( $dh = opendir( $directory ) ) {
  1890. while( ( $entry = readdir( $dh ) ) !== false ) {
  1891. if ($entry != '.' && $entry != '..') {
  1892. $sizes = wpsc_dirsize( trailingslashit( $directory ) . $entry, $sizes );
  1893. }
  1894. }
  1895. closedir($dh);
  1896. }
  1897. } else {
  1898. if(is_file($directory) ) {
  1899. $filem = filemtime( $directory );
  1900. if ( $wp_cache_preload_on == false && $cache_max_time > 0 && $filem + $cache_max_time <= $now ) {
  1901. $sizes[ 'expired' ]+=1;
  1902. if ( $valid_nonce && $_GET[ 'listfiles' ] )
  1903. $sizes[ 'expired_list' ][ $now - $filem ][ str_replace( $cache_path . 'supercache/' , '', str_replace( 'index.html', '', str_replace( 'index.html.gz', '', $directory ) ) ) ] = 1;
  1904. } else {
  1905. $sizes[ 'cached' ]+=1;
  1906. if ( $valid_nonce && array_key_exists('listfiles', $_GET) && $_GET[ 'listfiles' ] )
  1907. $sizes[ 'cached_list' ][ $now - $filem ][ str_replace( $cache_path . 'supercache/' , '', str_replace( 'index.html', '', str_replace( 'index.html.gz', '', $directory ) ) ) ] = 1;
  1908. }
  1909. if ( ! isset( $sizes[ 'fsize' ] ) )
  1910. $sizes[ 'fsize' ] = @filesize( $directory );
  1911. else
  1912. $sizes[ 'fsize' ] += @filesize( $directory );
  1913. }
  1914. }
  1915. return $sizes;
  1916. }
  1917. function wp_cache_clean_cache($file_prefix) {
  1918. global $cache_path, $supercachedir, $blog_cache_dir, $wp_cache_object_cache;
  1919. if ( $wp_cache_object_cache && function_exists( "reset_oc_version" ) )
  1920. reset_oc_version();
  1921. // If phase2 was compiled, use its function to avoid race-conditions
  1922. if(function_exists('wp_cache_phase2_clean_cache')) {
  1923. if (function_exists ('prune_super_cache')) {
  1924. if( is_dir( $supercachedir ) ) {
  1925. prune_super_cache( $supercachedir, true );
  1926. } elseif( is_dir( $supercachedir . '.disabled' ) ) {
  1927. prune_super_cache( $supercachedir . '.disabled', true );
  1928. }
  1929. prune_super_cache( $cache_path, true );
  1930. $_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
  1931. } 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 );
  1932. return wp_cache_phase2_clean_cache($file_prefix);
  1933. } 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 );
  1934. $expr = "/^$file_prefix/";
  1935. if ( ($handle = @opendir( $blog_cache_dir )) ) {
  1936. while ( false !== ($file = readdir($handle))) {
  1937. if ( preg_match($expr, $file) ) {
  1938. @unlink( $blog_cache_dir . $file);
  1939. @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
  1940. }
  1941. }
  1942. closedir($handle);
  1943. }
  1944. }
  1945. function wp_cache_clean_expired($file_prefix) {
  1946. global $cache_path, $cache_max_time, $blog_cache_dir, $wp_cache_preload_on;
  1947. if ( $cache_max_time == 0 ) {
  1948. return false;
  1949. }
  1950. // If phase2 was compiled, use its function to avoid race-conditions
  1951. if(function_exists('wp_cache_phase2_clean_expired')) {
  1952. if ( $wp_cache_preload_on != 1 && function_exists ('prune_super_cache')) {
  1953. $dir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]);
  1954. if( is_dir( $dir ) ) {
  1955. prune_super_cache( $dir );
  1956. } elseif( is_dir( $dir . '.disabled' ) ) {
  1957. prune_super_cache( $dir . '.disabled' );
  1958. }
  1959. $_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
  1960. }
  1961. return wp_cache_phase2_clean_expired($file_prefix);
  1962. }
  1963. $expr = "/^$file_prefix/";
  1964. $now = time();
  1965. if ( ($handle = @opendir( $blog_cache_dir )) ) {
  1966. while ( false !== ($file = readdir($handle))) {
  1967. if ( preg_match( $expr, $file ) &&
  1968. ( filemtime( $blog_cache_dir . $file ) + $cache_max_time ) <= $now ) {
  1969. @unlink( $blog_cache_dir . $file );
  1970. @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
  1971. }
  1972. }
  1973. closedir($handle);
  1974. }
  1975. }
  1976. function wpsc_remove_marker( $filename, $marker ) {
  1977. if (!file_exists( $filename ) || is_writeable_ACLSafe( $filename ) ) {
  1978. if (!file_exists( $filename ) ) {
  1979. return '';
  1980. } else {
  1981. $markerdata = explode( "\n", implode( '', file( $filename ) ) );
  1982. }
  1983. $f = fopen( $filename, 'w' );
  1984. $foundit = false;
  1985. if ( $markerdata ) {
  1986. $state = true;
  1987. foreach ( $markerdata as $n => $markerline ) {
  1988. if (strpos($markerline, '# BEGIN ' . $marker) !== false)
  1989. $state = false;
  1990. if ( $state ) {
  1991. if ( $n + 1 < count( $markerdata ) )
  1992. fwrite( $f, "{$markerline}\n" );
  1993. else
  1994. fwrite( $f, "{$markerline}" );
  1995. }
  1996. if (strpos($markerline, '# END ' . $marker) !== false) {
  1997. $state = true;
  1998. }
  1999. }
  2000. }
  2001. return true;
  2002. } else {
  2003. return false;
  2004. }
  2005. }
  2006. function wp_super_cache_footer() {
  2007. ?><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
  2008. }
  2009. if( isset( $wp_cache_hello_world ) && $wp_cache_hello_world )
  2010. add_action( 'wp_footer', 'wp_super_cache_footer' );
  2011. if( get_option( 'gzipcompression' ) )
  2012. update_option( 'gzipcompression', 0 );
  2013. // Catch 404 requests. Themes that use query_posts() destroy $wp_query->is_404
  2014. function wp_cache_catch_404() {
  2015. global $wp_cache_404;
  2016. $wp_cache_404 = false;
  2017. if( is_404() )
  2018. $wp_cache_404 = true;
  2019. }
  2020. add_action( 'template_redirect', 'wp_cache_catch_404' );
  2021. function wp_cache_favorite_action( $actions ) {
  2022. if ( false == wpsupercache_site_admin() )
  2023. return $actions;
  2024. if ( function_exists('current_user_can') && !current_user_can('manage_options') )
  2025. return $actions;
  2026. $actions[ wp_nonce_url( 'options-general.php?page=wpsupercache&wp_delete_cache=1&tab=tester', 'wp-cache' ) ] = array( __( 'Delete Cache', 'wp-super-cache' ), 'manage_options' );
  2027. return $actions;
  2028. }
  2029. add_filter( 'favorite_actions', 'wp_cache_favorite_action' );
  2030. function wp_cache_plugin_notice( $plugin ) {
  2031. global $cache_enabled;
  2032. if( $plugin == 'wp-super-cache/wp-cache.php' && !$cache_enabled && function_exists( "admin_url" ) )
  2033. echo '<td colspan="5" class="plugin-update">' . sprintf( __( 'WP Super Cache must be configured. Go to <a href="%s">the admin page</a> to enable and configure the plugin.' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '</td>';
  2034. }
  2035. add_action( 'after_plugin_row', 'wp_cache_plugin_notice' );
  2036. function wp_cache_plugin_actions( $links, $file ) {
  2037. if( $file == 'wp-super-cache/wp-cache.php' && function_exists( "admin_url" ) ) {
  2038. $settings_link = '<a href="' . admin_url( 'options-general.php?page=wpsupercache' ) . '">' . __('Settings') . '</a>';
  2039. array_unshift( $links, $settings_link ); // before other links
  2040. }
  2041. return $links;
  2042. }
  2043. add_filter( 'plugin_action_links', 'wp_cache_plugin_actions', 10, 2 );
  2044. function wp_cache_admin_notice() {
  2045. global $cache_enabled;
  2046. if( substr( $_SERVER["PHP_SELF"], -11 ) == 'plugins.php' && !$cache_enabled && function_exists( "admin_url" ) )
  2047. 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>';
  2048. }
  2049. add_action( 'admin_notices', 'wp_cache_admin_notice' );
  2050. function wp_cache_check_site() {
  2051. 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;
  2052. if ( !isset( $wp_super_cache_front_page_check ) || ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 0 ) ) {
  2053. return false;
  2054. }
  2055. if ( function_exists( "wp_remote_get" ) == false ) {
  2056. return false;
  2057. }
  2058. $front_page = wp_remote_get( site_url(), array('timeout' => 60, 'blocking' => true ) );
  2059. if( is_array( $front_page ) ) {
  2060. // Check for gzipped front page
  2061. if ( $front_page[ 'headers' ][ 'content-type' ] == 'application/x-gzip' ) {
  2062. if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) {
  2063. wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Please clear cache!', 'wp-super-cache' ), site_url() ), sprintf( __( "Please visit %s to clear the cache as the front page of your site is now downloading!", 'wp-super-cache' ), trailingslashit( site_url() ) . "wp-admin/options-general.php?page=wpsupercache" ) );
  2064. } else {
  2065. wp_cache_clear_cache();
  2066. wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Cache Cleared!', 'wp-super-cache' ), site_url() ), sprintf( __( "The cache on your blog has been cleared because the front page of your site is now downloading. Please visit %s to verify the cache has been cleared.", 'wp-super-cache' ), trailingslashit( site_url() ) . "wp-admin/options-general.php?page=wpsupercache" ) );
  2067. }
  2068. }
  2069. // Check for broken front page
  2070. if ( isset( $wp_super_cache_front_page_text ) && $wp_super_cache_front_page_text != '' && false === strpos( $front_page[ 'body' ], $wp_super_cache_front_page_text ) ) {
  2071. if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) {
  2072. wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is not correct! Please clear cache!', 'wp-super-cache' ), site_url() ), sprintf( __( 'Please visit %1$s to clear the cache as the front page of your site is not correct and missing the text, "%2$s"!', 'wp-super-cache' ), trailingslashit( site_url() ) . "wp-admin/options-general.php?page=wpsupercache", $wp_super_cache_front_page_text ) );
  2073. } else {
  2074. wp_cache_clear_cache();
  2075. wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is not correct! Cache Cleared!', 'wp-super-cache' ), site_url() ), sprintf( __( 'The cache on your blog has been cleared because the front page of your site is missing the text "%2$s". Please visit %1$s to verify the cache has been cleared.', 'wp-super-cache' ), trailingslashit( site_url() ) . "wp-admin/options-general.php?page=wpsupercache", $wp_super_cache_front_page_text ) );
  2076. }
  2077. }
  2078. }
  2079. if ( isset( $wp_super_cache_front_page_notification ) && $wp_super_cache_front_page_notification == 1 ) {
  2080. wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page check!', 'wp-super-cache' ), site_url() ), sprintf( __( "WP Super Cache has checked the front page of your blog. Please visit %s if you would like to disable this.", 'wp-super-cache' ) . "\n\n", trailingslashit( site_url() ) . "wp-admin/options-general.php?page=wpsupercache#debug" ) . print_r( $front_page, 1 ) );
  2081. }
  2082. if ( !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
  2083. wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
  2084. 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 );
  2085. }
  2086. }
  2087. add_action( 'wp_cache_check_site_hook', 'wp_cache_check_site' );
  2088. function update_cached_mobile_ua_list( $mobile_browsers, $mobile_prefixes = 0, $mobile_groups = 0 ) {
  2089. global $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_groups;
  2090. if ( is_array( $mobile_browsers ) ) {
  2091. $wp_cache_mobile_browsers = $mobile_browsers;
  2092. wp_cache_replace_line('^ *\$wp_cache_mobile_browsers', "\$wp_cache_mobile_browsers = '" . implode( ', ', $mobile_browsers ) . "';", $wp_cache_config_file);
  2093. }
  2094. if ( is_array( $mobile_prefixes ) ) {
  2095. $wp_cache_mobile_prefixes = $mobile_prefixes;
  2096. wp_cache_replace_line('^ *\$wp_cache_mobile_prefixes', "\$wp_cache_mobile_prefixes = '" . implode( ', ', $mobile_prefixes ) . "';", $wp_cache_config_file);
  2097. }
  2098. if ( is_array( $mobile_groups ) ) {
  2099. $wp_cache_mobile_groups = $mobile_groups;
  2100. wp_cache_replace_line('^ *\$wp_cache_mobile_groups', "\$wp_cache_mobile_groups = '" . implode( ', ', $mobile_groups ) . "';", $wp_cache_config_file);
  2101. }
  2102. return true;
  2103. }
  2104. function wpsc_update_htaccess() {
  2105. extract( wpsc_get_htaccess_info() );
  2106. wpsc_remove_marker( $home_path.'.htaccess', 'WordPress' ); // remove original WP rules so SuperCache rules go on top
  2107. if( insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', explode( "\n", $rules ) ) && insert_with_markers( $home_path.'.htaccess', 'WordPress', explode( "\n", $wprules ) ) ) {
  2108. return true;
  2109. } else {
  2110. return false;
  2111. }
  2112. }
  2113. function wpsc_update_htaccess_form( $short_form = true ) {
  2114. global $wpmu_version;
  2115. extract( wpsc_get_htaccess_info() );
  2116. if( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) {
  2117. 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>";
  2118. echo "<p><pre># BEGIN WPSuperCache\n" . esc_html( $rules ) . "# END WPSuperCache</pre></p></div>";
  2119. } else {
  2120. if ( $short_form == false ) {
  2121. 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 ) . " ";
  2122. _e( "You can edit the file yourself add the following rules.", 'wp-super-cache' );
  2123. echo __( " Make sure they appear before any existing WordPress rules. ", 'wp-super-cache' ) . "</p>";
  2124. echo "<pre># BEGIN WPSuperCache\n" . esc_html( $rules ) . "# END WPSuperCache</pre></p>";
  2125. echo "<p>" . sprintf( __( 'Rules must be added to %s too:', 'wp-super-cache' ), WP_CONTENT_DIR . "/cache/.htaccess" ) . "</p>";
  2126. echo "<pre># BEGIN supercache\n" . esc_html( $gziprules ) . "# END supercache</pre></p>";
  2127. }
  2128. if ( !isset( $wpmu_version ) || $wpmu_version == '' ) {
  2129. echo '<form name="updatehtaccess" action="#modrewrite" method="post">';
  2130. echo '<input type="hidden" name="updatehtaccess" value="1" />';
  2131. echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'id="updatehtaccess" value="' . __( 'Update Mod_Rewrite Rules', 'wp-super-cache' ) . ' &raquo;" /></div>';
  2132. wp_nonce_field('wp-cache');
  2133. echo "</form></div>\n";
  2134. }
  2135. }
  2136. }
  2137. function wpsc_get_htaccess_info() {
  2138. global $wp_cache_mobile_enabled, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers;
  2139. if ( isset( $_SERVER[ "PHP_DOCUMENT_ROOT" ] ) ) {
  2140. $document_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
  2141. $apache_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
  2142. } else {
  2143. $document_root = $_SERVER[ "DOCUMENT_ROOT" ];
  2144. $apache_root = '%{DOCUMENT_ROOT}';
  2145. }
  2146. $home_path = get_home_path();
  2147. $home_root = parse_url(get_bloginfo('url'));
  2148. $home_root = isset( $home_root['path'] ) ? trailingslashit( $home_root['path'] ) : '/';
  2149. $inst_root = str_replace( '//', '/', '/' . trailingslashit( str_replace( $document_root, '', str_replace( '\\', '/', WP_CONTENT_DIR ) ) ) );
  2150. $wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) );
  2151. $wprules = str_replace( "RewriteEngine On\n", '', $wprules );
  2152. $wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
  2153. $scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
  2154. if( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
  2155. $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*[^/]$";
  2156. $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*//.*$";
  2157. }
  2158. $condition_rules[] = "RewriteCond %{REQUEST_METHOD} !POST";
  2159. $condition_rules[] = "RewriteCond %{QUERY_STRING} !.*=.*";
  2160. $condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$";
  2161. $condition_rules[] = "RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\\\"]+ [NC]";
  2162. $condition_rules[] = "RewriteCond %{HTTP:Profile} !^[a-z0-9\\\"]+ [NC]";
  2163. if ( $wp_cache_mobile_enabled ) {
  2164. $condition_rules[] = "RewriteCond %{HTTP_USER_AGENT} !^.*(" . addcslashes( implode( '|', $wp_cache_mobile_browsers ), ' ' ) . ").* [NC]";
  2165. $condition_rules[] = "RewriteCond %{HTTP_user_agent} !^(" . addcslashes( implode( '|', $wp_cache_mobile_prefixes ), ' ' ) . ").* [NC]";
  2166. }
  2167. $condition_rules = apply_filters( 'supercacherewriteconditions', $condition_rules );
  2168. $rules = "<IfModule mod_rewrite.c>\n";
  2169. $rules .= "RewriteEngine On\n";
  2170. $rules .= "RewriteBase $home_root\n"; // props Chris Messina
  2171. $charset = get_option('blog_charset') == '' ? 'UTF-8' : get_option('blog_charset');
  2172. $rules .= "AddDefaultCharset {$charset}\n";
  2173. $rules .= "CONDITION_RULES";
  2174. $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
  2175. $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz -f\n";
  2176. $rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz\" [L]\n\n";
  2177. $rules .= "CONDITION_RULES";
  2178. $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html -f\n";
  2179. $rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html\" [L]\n";
  2180. $rules .= "</IfModule>\n";
  2181. $rules = apply_filters( 'supercacherewriterules', $rules );
  2182. $rules = str_replace( "CONDITION_RULES", implode( "\n", $condition_rules ) . "\n", $rules );
  2183. $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";
  2184. $gziprules .= "<IfModule mod_deflate.c>\n SetEnvIfNoCase Request_URI \.gz$ no-gzip\n</IfModule>\n";
  2185. $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";
  2186. $gziprules .= "<IfModule mod_expires.c>\n ExpiresActive On\n ExpiresByType text/html A300\n</IfModule>\n";
  2187. return array( "document_root" => $document_root, "apache_root" => $apache_root, "home_path" => $home_path, "home_root" => $home_root, "inst_root" => $inst_root, "wprules" => $wprules, "scrules" => $scrules, "condition_rules" => $condition_rules, "rules" => $rules, "gziprules" => $gziprules );
  2188. }
  2189. function clear_post_supercache( $post_id ) {
  2190. $dir = get_current_url_supercache_dir( $post_id );
  2191. if ( file_exists( $dir . 'index.html' ) ) {
  2192. @unlink( $dir . 'index.html' );
  2193. }
  2194. if ( file_exists( $dir . 'index.html.gz' ) ) {
  2195. @unlink( $dir . 'index.html.gz' );
  2196. }
  2197. }
  2198. function wp_cron_preload_cache() {
  2199. global $wpdb, $wp_cache_preload_interval, $wp_cache_preload_posts, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $cache_path;
  2200. if ( get_option( 'preload_cache_stop' ) ) {
  2201. delete_option( 'preload_cache_stop' );
  2202. return true;
  2203. }
  2204. $mutex = $cache_path . "preload_mutex.tmp";
  2205. sleep( 3 + mt_rand( 1, 5 ) );
  2206. if ( @file_exists( $mutex ) ) {
  2207. if ( @filemtime( $mutex ) > ( time() - 600 ) ) {
  2208. return true;
  2209. } else {
  2210. @unlink( $mutex );
  2211. }
  2212. }
  2213. $fp = @fopen( $mutex, 'w' );
  2214. @fclose( $fp );
  2215. $counter = get_option( 'preload_cache_counter' );
  2216. $c = $counter[ 'c' ];
  2217. if ( $wp_cache_preload_posts == 'all' || $c <= $wp_cache_preload_posts ) {
  2218. $posts = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE (post_type = 'post' OR post_type='page') AND post_status = 'publish' ORDER BY post_date DESC LIMIT $c, 100" );
  2219. } else {
  2220. $posts = false;
  2221. }
  2222. if ( !isset( $wp_cache_preload_email_volume ) )
  2223. $wp_cache_preload_email_volume = 'medium';
  2224. update_option( 'preload_cache_counter', array( 'c' => ( $c + 100 ), 't' => time() ) );
  2225. if ( $posts ) {
  2226. if ( $wp_cache_preload_email_me && $c == 0 )
  2227. wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Started', 'wp-super-cache' ), site_url(), '' ), '' );
  2228. if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume == 'many' )
  2229. 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) ), '' );
  2230. $msg = '';
  2231. $count = $c + 1;
  2232. $permalink_counter_msg = $cache_path . "preload_permalink.txt";
  2233. foreach( $posts as $post_id ) {
  2234. set_time_limit( 60 );
  2235. clear_post_supercache( $post_id );
  2236. $url = get_permalink( $post_id );
  2237. $fp = @fopen( $permalink_counter_msg, 'w' );
  2238. if ( $fp ) {
  2239. @fwrite( $fp, $count . " " . $url );
  2240. @fclose( $fp );
  2241. }
  2242. if ( @file_exists( $cache_path . "stop_preload.txt" ) ) {
  2243. @unlink( $mutex );
  2244. @unlink( $cache_path . "stop_preload.txt" );
  2245. update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
  2246. if ( $wp_cache_preload_email_me )
  2247. wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Stopped', 'wp-super-cache' ), site_url(), '' ), '' );
  2248. return true;
  2249. }
  2250. $msg .= "$url\n";
  2251. wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
  2252. sleep( 1 );
  2253. $count++;
  2254. }
  2255. if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume != 'less' )
  2256. wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] %2$d posts refreshed', 'wp-super-cache' ), $_SERVER[ 'HTTP_HOST' ], ($c+100) ), __( "Refreshed the following posts:", 'wp-super-cache' ) . "\n$msg" );
  2257. if ( defined( 'DOING_CRON' ) ) {
  2258. wp_schedule_single_event( time() + 30, 'wp_cache_preload_hook' );
  2259. }
  2260. } else {
  2261. $msg = '';
  2262. update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
  2263. if ( (int)$wp_cache_preload_interval && defined( 'DOING_CRON' ) ) {
  2264. if ( $wp_cache_preload_email_me )
  2265. $msg = sprintf( __( 'Scheduling next preload refresh in %d minutes.', 'wp-super-cache' ), (int)$wp_cache_preload_interval );
  2266. wp_schedule_single_event( time() + ( (int)$wp_cache_preload_interval * 60 ), 'wp_cache_full_preload_hook' );
  2267. }
  2268. global $file_prefix, $cache_max_time;
  2269. if ( $wp_cache_preload_interval > 0 ) {
  2270. $cache_max_time = (int)$wp_cache_preload_interval * 60; // fool the GC into expiring really old files
  2271. } else {
  2272. $cache_max_time = 86400; // fool the GC into expiring really old files
  2273. }
  2274. if ( $wp_cache_preload_email_me )
  2275. 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 );
  2276. wp_cache_phase2_clean_expired( $file_prefix, true ); // force cleanup of old files.
  2277. }
  2278. @unlink( $mutex );
  2279. }
  2280. add_action( 'wp_cache_preload_hook', 'wp_cron_preload_cache' );
  2281. add_action( 'wp_cache_full_preload_hook', 'wp_cron_preload_cache' );
  2282. function next_preload_message( $hook, $text, $limit = 0 ) {
  2283. global $currently_preloading, $wp_cache_preload_interval;
  2284. if ( $next_preload = wp_next_scheduled( $hook ) ) {
  2285. $next_time = $next_preload - time();
  2286. if ( $limit != 0 && $next_time > $limit )
  2287. return false;
  2288. $h = $m = $s = 0;
  2289. if ( $next_time > 0 ) {
  2290. // http://bytes.com/topic/php/answers/3917-seconds-converted-hh-mm-ss
  2291. $m = (int)($next_time / 60);
  2292. $s = $next_time % 60;
  2293. $h = (int)($m / 60); $m = $m % 60;
  2294. }
  2295. if ( $next_time > 0 && $next_time < ( 60 * $wp_cache_preload_interval ) )
  2296. echo '<p><strong>' . sprintf( $text, $h, $m, $s ) . '</strong></p>';
  2297. if ( ( $next_preload - time() ) <= 60 )
  2298. $currently_preloading = true;
  2299. }
  2300. }
  2301. function option_preload_cache_counter( $value ) {
  2302. if ( false == is_array( $value ) ) {
  2303. $ret = array( 'c' => $value, 't' => time(), 'first' => 1 );
  2304. return $ret;
  2305. }
  2306. return $value;
  2307. }
  2308. add_filter( 'option_preload_cache_counter', 'option_preload_cache_counter' );
  2309. function check_up_on_preloading() {
  2310. $value = get_option( 'preload_cache_counter' );
  2311. if ( $value[ 'c' ] > 0 && ( time() - $value[ 't' ] ) > 3600 && false == wp_next_scheduled( 'wp_cache_preload_hook' ) ) {
  2312. if ( is_admin() )
  2313. 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" ) ) );
  2314. wp_schedule_single_event( time() + 30, 'wp_cache_preload_hook' );
  2315. }
  2316. }
  2317. add_action( 'init', 'check_up_on_preloading' ); // sometimes preloading stops working. Kickstart it.
  2318. ?>