PageRenderTime 65ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/p13t3rm/wpaustralia
PHP | 3163 lines | 2902 code | 209 blank | 52 comment | 706 complexity | 48be02874c1bd66a7c2a999c8e197cbb MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, AGPL-1.0, GPL-2.0, GPL-3.0

Large files files are truncated, but you can click here to view the full file

  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: 1.4
  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-2013 Donncha Ó 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 ( !defined( 'WPCACHEHOME' ) ) {
  31. define( 'WPCACHEHOME', dirname( __FILE__ ) . '/' );
  32. $wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
  33. $wp_cache_file = WPCACHEHOME . 'advanced-cache.php';
  34. } elseif ( WPCACHEHOME != dirname( __FILE__ ) . '/' ) {
  35. $wp_cache_config_file_sample = dirname( __FILE__ ) . '/wp-cache-config-sample.php';
  36. $wp_cache_file = dirname( __FILE__ ) . '/advanced-cache.php';
  37. } else {
  38. $wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
  39. $wp_cache_file = WPCACHEHOME . 'advanced-cache.php';
  40. }
  41. if( !@include($wp_cache_config_file) ) {
  42. get_wpcachehome();
  43. $wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
  44. @include($wp_cache_config_file_sample);
  45. } else {
  46. get_wpcachehome();
  47. }
  48. $wp_cache_link = WP_CONTENT_DIR . '/advanced-cache.php';
  49. if( !defined( 'WP_CACHE' ) || ( defined( 'WP_CACHE' ) && constant( 'WP_CACHE' ) == false ) ) {
  50. $wp_cache_check_wp_config = true;
  51. }
  52. include(WPCACHEHOME . 'wp-cache-base.php');
  53. function wp_super_cache_text_domain() {
  54. load_plugin_textdomain( 'wp-super-cache', WPCACHEHOME . 'languages', basename( dirname( __FILE__ ) ) . '/languages' );
  55. }
  56. add_action( 'init', 'wp_super_cache_text_domain' );
  57. function wp_cache_set_home() {
  58. global $wp_cache_is_home;
  59. $wp_cache_is_home = ( is_front_page() || is_home() );
  60. if ( $wp_cache_is_home && is_paged() )
  61. $wp_cache_is_home = false;
  62. }
  63. add_action( 'template_redirect', 'wp_cache_set_home' );
  64. // OSSDL CDN plugin (http://wordpress.org/extend/plugins/ossdl-cdn-off-linker/)
  65. include_once( WPCACHEHOME . 'ossdl-cdn.php' );
  66. // from legolas558 d0t users dot sf dot net at http://www.php.net/is_writable
  67. function is_writeable_ACLSafe($path) {
  68. // PHP's is_writable does not work with Win32 NTFS
  69. if ($path{strlen($path)-1}=='/') // recursively return a temporary file path
  70. return is_writeable_ACLSafe($path.uniqid(mt_rand()).'.tmp');
  71. else if (is_dir($path))
  72. return is_writeable_ACLSafe($path.'/'.uniqid(mt_rand()).'.tmp');
  73. // check tmp file for read/write capabilities
  74. $rm = file_exists($path);
  75. $f = @fopen($path, 'a');
  76. if ($f===false)
  77. return false;
  78. fclose($f);
  79. if (!$rm)
  80. unlink($path);
  81. return true;
  82. }
  83. function get_wpcachehome() {
  84. if( defined( 'WPCACHEHOME' ) == false ) {
  85. if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
  86. define( 'WPCACHEHOME', trailingslashit( dirname(__FILE__) ) );
  87. } elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
  88. define( 'WPCACHEHOME', dirname(__FILE__) . '/wp-super-cache/' );
  89. } else {
  90. die( sprintf( __( 'Please create %s /wp-cache-config.php from wp-super-cache/wp-cache-config-sample.php', 'wp-super-cache' ), WP_CONTENT_DIR ) );
  91. }
  92. }
  93. }
  94. function wpsupercache_deactivate() {
  95. global $wp_cache_config_file, $wp_cache_link, $cache_path;
  96. $files = array( $wp_cache_config_file, $wp_cache_link );
  97. foreach( $files as $file ) {
  98. if( file_exists( $file ) )
  99. unlink( $file );
  100. }
  101. if( !function_exists( 'prune_super_cache' ) )
  102. include_once( 'wp-cache-phase2.php' );
  103. prune_super_cache ($cache_path, true);
  104. @unlink( $cache_path . '.htaccess' );
  105. @unlink( $cache_path . 'meta' );
  106. @unlink( $cache_path . 'supercache' );
  107. wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
  108. wp_clear_scheduled_hook( 'wp_cache_gc' );
  109. wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
  110. wp_cache_disable_plugin();
  111. }
  112. register_uninstall_hook( __FILE__, 'wpsupercache_deactivate' );
  113. function wpsupercache_activate() {
  114. }
  115. register_activation_hook( __FILE__, 'wpsupercache_activate' );
  116. function wpsupercache_site_admin() {
  117. if ( function_exists( 'is_super_admin' ) ) {
  118. return is_super_admin();
  119. } elseif ( function_exists( 'is_site_admin' ) ) {
  120. return is_site_admin();
  121. } else {
  122. return true;
  123. }
  124. }
  125. function wp_cache_add_pages() {
  126. global $wpmu_version;
  127. if ( function_exists( 'is_multisite' ) && is_multisite() && wpsupercache_site_admin() ) {
  128. add_submenu_page( 'ms-admin.php', 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager' );
  129. } elseif ( isset( $wpmu_version ) && wpsupercache_site_admin() ) {
  130. add_submenu_page( 'wpmu-admin.php', 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager' );
  131. }
  132. if ( wpsupercache_site_admin() ) { // in single or MS mode add this menu item too, but only for superadmins in MS mode.
  133. add_options_page( 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
  134. }
  135. }
  136. add_action('admin_menu', 'wp_cache_add_pages');
  137. function wp_cache_network_pages() {
  138. add_submenu_page('settings.php', 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
  139. }
  140. add_action( 'network_admin_menu', 'wp_cache_network_pages' );
  141. function wp_cache_manager_error_checks() {
  142. global $wpmu_version, $wp_cache_debug, $wp_cache_cron_check, $cache_enabled, $super_cache_enabled, $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_mobile_enabled, $wp_cache_mod_rewrite, $cache_path;
  143. global $dismiss_htaccess_warning, $dismiss_readable_warning, $dismiss_gc_warning, $wp_cache_shutdown_gc;
  144. if ( !wpsupercache_site_admin() )
  145. return false;
  146. if ( version_compare( PHP_VERSION, '5.3.0', '<' ) && ( 1 == ini_get( 'safe_mode' ) || "on" == strtolower( ini_get( 'safe_mode' ) ) ) ) {
  147. echo '<div id="message" class="updated fade"><h3>' . __( 'Warning! PHP Safe Mode Enabled!', 'wp-super-cache' ) . '</h3><p>' .
  148. __( 'You may experience problems running this plugin because SAFE MODE is enabled.', 'wp-super-cache' ) . ' ';
  149. if( !ini_get( 'safe_mode_gid' ) ) {
  150. _e( 'Your server is set up to check the owner of PHP scripts before allowing them to read and write files.', 'wp-super-cache' ) . " ";
  151. 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 );
  152. } else {
  153. _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' );
  154. }
  155. echo '</p></div>';
  156. }
  157. if ( '' == get_option( 'permalink_structure' ) ) {
  158. echo '<div id="message" class="updated fade"><h3>' . __( 'Permlink Structure Error', 'wp-super-cache' ) . '</h3>';
  159. 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>";
  160. echo '</div>';
  161. return false;
  162. }
  163. if( $wp_cache_debug || !$wp_cache_cron_check ) {
  164. if( function_exists( "wp_remote_get" ) == false ) {
  165. $hostname = str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'siteurl' ) ) );
  166. if( strpos( $hostname, '/' ) )
  167. $hostname = substr( $hostname, 0, strpos( $hostname, '/' ) );
  168. $ip = gethostbyname( $hostname );
  169. if( substr( $ip, 0, 3 ) == '127' || substr( $ip, 0, 7 ) == '192.168' ) {
  170. ?><div id="message" class="updated fade"><h3><?php printf( __( 'Warning! Your hostname "%s" resolves to %s', 'wp-super-cache' ), $hostname, $ip ); ?></h3>
  171. <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>
  172. <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>
  173. </div>
  174. <?php
  175. return false;
  176. } else {
  177. wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
  178. }
  179. } else {
  180. $cron_url = get_option( 'siteurl' ) . '/wp-cron.php?check=' . wp_hash('187425');
  181. $cron = wp_remote_get($cron_url, array('timeout' => 0.01, 'blocking' => true));
  182. if( is_array( $cron ) ) {
  183. if( $cron[ 'response' ][ 'code' ] == '404' ) {
  184. ?><div id="message" class="updated fade"><h3>Warning! wp-cron.php not found!</h3>
  185. <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>
  186. <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>
  187. </div>
  188. <?php
  189. } else {
  190. wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
  191. }
  192. }
  193. }
  194. }
  195. if ( !wp_cache_check_link() ||
  196. !wp_cache_verify_config_file() ||
  197. !wp_cache_verify_cache_dir() ) {
  198. echo '<p>' . __( "Cannot continue... fix previous problems and retry.", 'wp-super-cache' ) . '</p>';
  199. return false;
  200. }
  201. if (!wp_cache_check_global_config()) {
  202. return false;
  203. }
  204. if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) {
  205. ?><div id="message" class="updated fade"><h3><?php _e( 'Zlib Output Compression Enabled!', 'wp-super-cache' ); ?></h3>
  206. <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
  207. }
  208. if( $cache_enabled == true && $super_cache_enabled == true && $wp_cache_mod_rewrite && !got_mod_rewrite() ) {
  209. ?><div id="message" class="updated fade"><h3><?php _e( 'Mod rewrite may not be installed!', 'wp-super-cache' ); ?></h3>
  210. <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
  211. }
  212. if( !is_writeable_ACLSafe( $wp_cache_config_file ) ) {
  213. if ( !defined( 'SUBMITDISABLED' ) )
  214. define( "SUBMITDISABLED", 'disabled style="color: #aaa" ' );
  215. ?><div id="message" class="updated fade"><h3><?php _e( 'Read Only Mode. Configuration cannot be changed.', 'wp-super-cache' ); ?></h3>
  216. <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 ); ?>
  217. <?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>
  218. <p><?php _e( '<a href="http://codex.wordpress.org/Changing_File_Permissions">This page</a> explains how to change file permissions.', 'wp-super-cache' ); ?></p>
  219. <?php _e( 'Writeable:', 'wp-super-cache' ); ?> <code>chmod 666 <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code>
  220. <?php _e( 'Readonly:', 'wp-super-cache' ); ?> <code>chmod 644 <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code></p>
  221. </div><?php
  222. } elseif ( !defined( 'SUBMITDISABLED' ) ) {
  223. define( "SUBMITDISABLED", ' ' );
  224. }
  225. $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
  226. // Check that garbage collection is running
  227. if ( $valid_nonce && isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'dismiss_gc_warning' ) {
  228. wp_cache_replace_line('^ *\$dismiss_gc_warning', "\$dismiss_gc_warning = 1;", $wp_cache_config_file);
  229. $dismiss_gc_warning = 1;
  230. } elseif ( !isset( $dismiss_gc_warning ) ) {
  231. $dismiss_gc_warning = 0;
  232. }
  233. if ( $cache_enabled && ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) && function_exists( 'get_gc_flag' ) ) {
  234. $gc_flag = get_gc_flag();
  235. if ( $dismiss_gc_warning == 0 ) {
  236. if ( false == maybe_stop_gc( $gc_flag ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) {
  237. ?><div id="message" class="updated fade"><h3><?php _e( 'Warning! Garbage collection is not scheduled!', 'wp-super-cache' ); ?></h3>
  238. <p><?php _e( 'Garbage collection by this plugin clears out expired and old cached pages on a regular basis. Use <a href="#expirytime">this form</a> to enable it.', 'wp-super-cache' ); ?> </p>
  239. <form action="" method="POST">
  240. <input type="hidden" name="action" value="dismiss_gc_warning" />
  241. <input type="hidden" name="page" value="wpsupercache" />
  242. <?php wp_nonce_field( 'wp-cache' ); ?>
  243. <input type='submit' value='<?php _e( 'Dismiss', 'wp-super-cache' ); ?>' />
  244. </form>
  245. <br />
  246. </div>
  247. <?php
  248. }
  249. }
  250. }
  251. // Server could be running as the owner of the wp-content directory. Therefore, if it's
  252. // writable, issue a warning only if the permissions aren't 755.
  253. if ( $valid_nonce && isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'dismiss_readable_warning' ) {
  254. wp_cache_replace_line('^ *\$dismiss_readable_warning', "\$dismiss_readable_warning = 1;", $wp_cache_config_file);
  255. $dismiss_readable_warning = 1;
  256. } elseif ( !isset( $dismiss_readable_warning ) ) {
  257. $dismiss_readable_warning = 0;
  258. }
  259. if( $dismiss_readable_warning == 0 && is_writeable_ACLSafe( WP_CONTENT_DIR . '/' ) ) {
  260. $wp_content_stat = stat(WP_CONTENT_DIR . '/');
  261. $wp_content_mode = decoct( $wp_content_stat[ 'mode' ] & 0777 );
  262. if( substr( $wp_content_mode, -2 ) == '77' ) {
  263. ?><div id="message" class="updated fade"><h3><?php printf( __( 'Warning! %s is writeable!', 'wp-super-cache' ), WP_CONTENT_DIR ); ?></h3>
  264. <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>
  265. <p><?php _e( '<a href="http://codex.wordpress.org/Changing_File_Permissions">This page</a> explains how to change file permissions.', 'wp-super-cache' ); ?></p>
  266. <form action="" method="POST">
  267. <input type="hidden" name="action" value="dismiss_readable_warning" />
  268. <input type="hidden" name="page" value="wpsupercache" />
  269. <?php wp_nonce_field( 'wp-cache' ); ?>
  270. <input type='submit' value='<?php _e( 'Dismiss', 'wp-super-cache' ); ?>' />
  271. </form>
  272. <br />
  273. </div>
  274. <?php
  275. }
  276. }
  277. if ( function_exists( "is_main_site" ) && true == is_main_site() ) {
  278. $home_path = trailingslashit( get_home_path() );
  279. $scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
  280. if ( $cache_enabled && $wp_cache_mod_rewrite && !$wp_cache_mobile_enabled && strpos( $scrules, addcslashes( implode( '|', $wp_cache_mobile_browsers ), ' ' ) ) ) {
  281. echo '<div id="message" class="updated fade"><h3>' . __( 'Mobile rewrite rules detected', 'wp-super-cache' ) . "</h3>";
  282. 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>";
  283. } elseif ( $wp_cache_mod_rewrite && $cache_enabled && $wp_cache_mobile_enabled && $scrules != '' && (
  284. ( false == empty( $wp_cache_mobile_prefixes ) && false === strpos( $scrules, addcslashes( implode( '|', $wp_cache_mobile_prefixes ), ' ' ) ) ) ||
  285. ( false == empty( $wp_cache_mobile_browsers ) && false === strpos( $scrules, addcslashes( implode( '|', $wp_cache_mobile_browsers ), ' ' ) ) ) )
  286. ) {
  287. ?>
  288. <div id="message" class="updated fade"><h3><?php _e( 'Rewrite rules must be updated', 'wp-super-cache' ); ?></h3>
  289. <p><?php _e( 'The rewrite rules required by this plugin have changed or are missing. ', 'wp-super-cache' ); ?>
  290. <?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' ); ?>
  291. <ol><li> <?php _e( 'Set the plugin to legacy mode and enable mobile support.', 'wp-super-cache' ); ?></li>
  292. <li> <?php _e( 'Scroll down the Advanced Settings page and click the <strong>Update Mod_Rewrite Rules</strong> button.', 'wp-super-cache' ); ?></li>
  293. <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>
  294. <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_|%s|wp-postpass_).*$</code> add these lines: (do it twice, once for each section)', 'wp-super-cache' ), $home_path, wpsc_get_logged_in_cookie() ); ?></p>
  295. <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
  296. }
  297. if ( $cache_enabled && $super_cache_enabled && $wp_cache_mod_rewrite && $scrules == '' ) {
  298. ?><div id="message" class="updated fade"><h3><?php _e( 'Rewrite rules must be updated', 'wp-super-cache' ); ?></h3>
  299. <p><?php _e( 'The rewrite rules required by this plugin have changed or are missing. ', 'wp-super-cache' ); ?>
  300. <?php _e( 'Scroll down the Advanced Settings page and click the <strong>Update Mod_Rewrite Rules</strong> button.', 'wp-super-cache' ); ?></p></div><?php
  301. }
  302. }
  303. if ( $wp_cache_mod_rewrite && $super_cache_enabled && function_exists( 'apache_get_modules' ) ) {
  304. $mods = apache_get_modules();
  305. $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' ) );
  306. foreach( $required_modules as $req => $desc ) {
  307. if( !in_array( $req, $mods ) ) {
  308. $missing_mods[ $req ] = $desc;
  309. }
  310. }
  311. if( isset( $missing_mods) && is_array( $missing_mods ) ) {
  312. ?><div id="message" class="updated fade"><h3><?php _e( 'Missing Apache Modules', 'wp-super-cache' ); ?></h3>
  313. <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
  314. echo "<ul>";
  315. foreach( $missing_mods as $req => $desc ) {
  316. echo "<li> $req - $desc</li>";
  317. }
  318. echo "</ul>";
  319. echo "</div>";
  320. }
  321. }
  322. if ( $valid_nonce && isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'dismiss_htaccess_warning' ) {
  323. wp_cache_replace_line('^ *\$dismiss_htaccess_warning', "\$dismiss_htaccess_warning = 1;", $wp_cache_config_file);
  324. $dismiss_htaccess_warning = 1;
  325. } elseif ( !isset( $dismiss_htaccess_warning ) ) {
  326. $dismiss_htaccess_warning = 0;
  327. }
  328. if ( $dismiss_htaccess_warning == 0 && $wp_cache_mod_rewrite && $super_cache_enabled && $disable_supercache_htaccess_warning == false && get_option( 'siteurl' ) != get_option( 'home' ) ) {
  329. $home_dir = str_replace( get_option( 'home' ), '', get_option( 'siteurl' ) );
  330. ?><div id="message" class="updated fade"><h3><?php _e( '.htaccess file may need to be moved', 'wp-super-cache' ); ?></h3>
  331. <p><?php _e( 'It appears you have WordPress installed in a sub directory as described <a href="http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory">here</a>. Unfortunately WordPress writes to the .htaccess in the install directory, not where your site is served from.<br />When you update the rewrite rules in this plugin you will have to copy the file to where your site is hosted. This will be fixed in the future.', 'wp-super-cache' ); ?></p>
  332. <form action="" method="POST">
  333. <input type="hidden" name="action" value="dismiss_htaccess_warning" />
  334. <input type="hidden" name="page" value="wpsupercache" />
  335. <?php wp_nonce_field( 'wp-cache' ); ?>
  336. <input type='submit' value='<?php _e( 'Dismiss', 'wp-super-cache' ); ?>' />
  337. </form>
  338. <br />
  339. </div><?php
  340. }
  341. return true;
  342. }
  343. add_filter( 'wp_super_cache_error_checking', 'wp_cache_manager_error_checks' );
  344. function admin_bar_delete_page() {
  345. // Delete cache for a specific page
  346. if ( function_exists('current_user_can') && false == current_user_can('delete_others_posts') )
  347. return false;
  348. if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'delcachepage' && ( isset( $_GET[ '_wpnonce' ] ) ? wp_verify_nonce( $_REQUEST[ '_wpnonce' ], 'delete-cache' ) : false ) ) {
  349. $path = get_supercache_dir() . preg_replace( '/:.*$/', '', $_GET[ 'path' ] );
  350. $files = get_all_supercache_filenames( $path );
  351. foreach( $files as $cache_file )
  352. prune_super_cache( $path . $cache_file, true );
  353. wp_redirect( preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_GET[ 'path' ] ) );
  354. die();
  355. }
  356. }
  357. if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'delcachepage' )
  358. add_action( 'admin_init', 'admin_bar_delete_page' );
  359. function wp_cache_manager_updates() {
  360. global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_hello_world, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $cache_path, $wp_cache_object_cache, $_wp_using_ext_object_cache, $wp_cache_refresh_single_only, $cache_compression, $wp_cache_mod_rewrite, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get;
  361. global $cache_schedule_type, $cache_scheduled_time, $cache_max_time, $cache_time_interval, $wp_cache_shutdown_gc;
  362. if ( !wpsupercache_site_admin() )
  363. return false;
  364. if ( false == isset( $cache_page_secret ) ) {
  365. $cache_page_secret = md5( date( 'H:i:s' ) . mt_rand() );
  366. wp_cache_replace_line('^ *\$cache_page_secret', "\$cache_page_secret = '" . $cache_page_secret . "';", $wp_cache_config_file);
  367. }
  368. $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
  369. if ( $valid_nonce == false )
  370. return false;
  371. if ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'easysetup' ) {
  372. $_POST[ 'action' ] = 'scupdates';
  373. if( isset( $_POST[ 'wp_cache_easy_on' ] ) && $_POST[ 'wp_cache_easy_on' ] == 1 ) {
  374. $_POST[ 'wp_cache_mobile_enabled' ] = 1;
  375. $_POST[ 'wp_cache_status' ] = 'all';
  376. $_POST[ 'super_cache_enabled' ] = 2; // PHP
  377. $_POST[ 'cache_rebuild_files' ] = 1;
  378. unset( $_POST[ 'cache_compression' ] );
  379. //
  380. // set up garbage collection with some default settings
  381. if ( ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) {
  382. if ( false == isset( $cache_schedule_type ) ) {
  383. $cache_schedule_type = 'interval';
  384. $cache_time_interval = 600;
  385. $cache_max_time = 1800;
  386. wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
  387. wp_cache_replace_line('^ *\$cache_time_interval', "\$cache_time_interval = '$cache_time_interval';", $wp_cache_config_file);
  388. wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = '$cache_max_time';", $wp_cache_config_file);
  389. }
  390. wp_schedule_single_event( time() + 600, 'wp_cache_gc' );
  391. }
  392. } else {
  393. unset( $_POST[ 'wp_cache_status' ] );
  394. $_POST[ 'super_cache_enabled' ] = 0;
  395. wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
  396. wp_clear_scheduled_hook( 'wp_cache_gc' );
  397. wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
  398. }
  399. }
  400. if( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'scupdates' ) {
  401. if( isset( $_POST[ 'wp_super_cache_late_init' ] ) ) {
  402. $wp_super_cache_late_init = 1;
  403. } else {
  404. $wp_super_cache_late_init = 0;
  405. }
  406. wp_cache_replace_line('^ *\$wp_super_cache_late_init', "\$wp_super_cache_late_init = " . $wp_super_cache_late_init . ";", $wp_cache_config_file);
  407. if( isset( $_POST[ 'wp_cache_disable_utf8' ] ) ) {
  408. $wp_cache_disable_utf8 = 1;
  409. } else {
  410. $wp_cache_disable_utf8 = 0;
  411. }
  412. wp_cache_replace_line('^ *\$wp_cache_disable_utf8', "\$wp_cache_disable_utf8 = " . $wp_cache_disable_utf8 . ";", $wp_cache_config_file);
  413. if( isset( $_POST[ 'wp_cache_no_cache_for_get' ] ) ) {
  414. $wp_cache_no_cache_for_get = 1;
  415. } else {
  416. $wp_cache_no_cache_for_get = 0;
  417. }
  418. wp_cache_replace_line('^ *\$wp_cache_no_cache_for_get', "\$wp_cache_no_cache_for_get = " . $wp_cache_no_cache_for_get . ";", $wp_cache_config_file);
  419. if( isset( $_POST[ 'wp_supercache_304' ] ) ) {
  420. $wp_supercache_304 = 1;
  421. } else {
  422. $wp_supercache_304 = 0;
  423. }
  424. wp_cache_replace_line('^ *\$wp_supercache_304', "\$wp_supercache_304 = " . $wp_supercache_304 . ";", $wp_cache_config_file);
  425. if( isset( $_POST[ 'wp_cache_mfunc_enabled' ] ) ) {
  426. $wp_cache_mfunc_enabled = 1;
  427. } else {
  428. $wp_cache_mfunc_enabled = 0;
  429. }
  430. wp_cache_replace_line('^ *\$wp_cache_mfunc_enabled', "\$wp_cache_mfunc_enabled = " . $wp_cache_mfunc_enabled . ";", $wp_cache_config_file);
  431. if( isset( $_POST[ 'wp_cache_mobile_enabled' ] ) ) {
  432. $wp_cache_mobile_enabled = 1;
  433. } else {
  434. $wp_cache_mobile_enabled = 0;
  435. }
  436. wp_cache_replace_line('^ *\$wp_cache_mobile_enabled', "\$wp_cache_mobile_enabled = " . $wp_cache_mobile_enabled . ";", $wp_cache_config_file);
  437. if( isset( $_POST[ 'wp_cache_front_page_checks' ] ) ) {
  438. $wp_cache_front_page_checks = 1;
  439. } else {
  440. $wp_cache_front_page_checks = 0;
  441. }
  442. wp_cache_replace_line('^ *\$wp_cache_front_page_checks', "\$wp_cache_front_page_checks = " . $wp_cache_front_page_checks . ";", $wp_cache_config_file);
  443. if( isset( $_POST[ 'wp_supercache_cache_list' ] ) ) {
  444. $wp_supercache_cache_list = 1;
  445. } else {
  446. $wp_supercache_cache_list = 0;
  447. }
  448. wp_cache_replace_line('^ *\$wp_supercache_cache_list', "\$wp_supercache_cache_list = " . $wp_supercache_cache_list . ";", $wp_cache_config_file);
  449. if ( isset( $_POST[ 'wp_cache_status' ] ) ) {
  450. if ( $_POST[ 'wp_cache_status' ] == 'all' )
  451. wp_cache_enable();
  452. if ( isset( $_POST[ 'super_cache_enabled' ] ) ) {
  453. if ( $_POST[ 'super_cache_enabled' ] == 0 ) {
  454. wp_cache_enable();
  455. wp_super_cache_disable();
  456. }
  457. if( $_POST[ 'super_cache_enabled' ] == 1 ) {
  458. $wp_cache_mod_rewrite = 1; // we need this because supercached files can be served by PHP too.
  459. } else {
  460. $wp_cache_mod_rewrite = 0;
  461. }
  462. wp_cache_replace_line('^ *\$wp_cache_mod_rewrite', '$wp_cache_mod_rewrite = ' . $wp_cache_mod_rewrite . ";", $wp_cache_config_file);
  463. }
  464. } else {
  465. wp_cache_disable();
  466. }
  467. if( isset( $_POST[ 'wp_cache_hello_world' ] ) ) {
  468. $wp_cache_hello_world = 1;
  469. } else {
  470. $wp_cache_hello_world = 0;
  471. }
  472. wp_cache_replace_line('^ *\$wp_cache_hello_world', '$wp_cache_hello_world = ' . $wp_cache_hello_world . ";", $wp_cache_config_file);
  473. if( isset( $_POST[ 'wp_cache_clear_on_post_edit' ] ) ) {
  474. $wp_cache_clear_on_post_edit = 1;
  475. } else {
  476. $wp_cache_clear_on_post_edit = 0;
  477. }
  478. 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);
  479. if( isset( $_POST[ 'cache_rebuild_files' ] ) ) {
  480. $cache_rebuild_files = 1;
  481. } else {
  482. $cache_rebuild_files = 0;
  483. }
  484. wp_cache_replace_line('^ *\$cache_rebuild_files', "\$cache_rebuild_files = " . $cache_rebuild_files . ";", $wp_cache_config_file);
  485. if( isset( $_POST[ 'wp_cache_mutex_disabled' ] ) ) {
  486. $wp_cache_mutex_disabled = 0;
  487. } else {
  488. $wp_cache_mutex_disabled = 1;
  489. }
  490. if( defined( 'WPSC_DISABLE_LOCKING' ) ) {
  491. $wp_cache_mutex_disabled = 1;
  492. }
  493. wp_cache_replace_line('^ *\$wp_cache_mutex_disabled', "\$wp_cache_mutex_disabled = " . $wp_cache_mutex_disabled . ";", $wp_cache_config_file);
  494. if( isset( $_POST[ 'wp_cache_not_logged_in' ] ) ) {
  495. if( $wp_cache_not_logged_in == 0 && function_exists( 'prune_super_cache' ) )
  496. prune_super_cache ($cache_path, true);
  497. $wp_cache_not_logged_in = 1;
  498. } else {
  499. $wp_cache_not_logged_in = 0;
  500. }
  501. wp_cache_replace_line('^ *\$wp_cache_not_logged_in', "\$wp_cache_not_logged_in = " . $wp_cache_not_logged_in . ";", $wp_cache_config_file);
  502. if( isset( $_POST[ 'wp_cache_make_known_anon' ] ) ) {
  503. if( $wp_cache_make_known_anon == 0 && function_exists( 'prune_super_cache' ) )
  504. prune_super_cache ($cache_path, true);
  505. $wp_cache_make_known_anon = 1;
  506. } else {
  507. $wp_cache_make_known_anon = 0;
  508. }
  509. wp_cache_replace_line('^ *\$wp_cache_make_known_anon', "\$wp_cache_make_known_anon = " . $wp_cache_make_known_anon . ";", $wp_cache_config_file);
  510. if( $_wp_using_ext_object_cache && isset( $_POST[ 'wp_cache_object_cache' ] ) ) {
  511. if( $wp_cache_object_cache == 0 && function_exists( 'prune_super_cache' ) )
  512. prune_super_cache( $cache_path, true );
  513. $wp_cache_object_cache = 1;
  514. } else {
  515. $wp_cache_object_cache = 0;
  516. }
  517. wp_cache_replace_line('^ *\$wp_cache_object_cache', "\$wp_cache_object_cache = " . $wp_cache_object_cache . ";", $wp_cache_config_file);
  518. if( isset( $_POST[ 'wp_cache_refresh_single_only' ] ) ) {
  519. $wp_cache_refresh_single_only = 1;
  520. } else {
  521. $wp_cache_refresh_single_only = 0;
  522. }
  523. wp_cache_replace_line('^ *\$wp_cache_refresh_single_only', "\$wp_cache_refresh_single_only = '" . $wp_cache_refresh_single_only . "';", $wp_cache_config_file);
  524. if ( defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
  525. $cache_compression = 0;
  526. wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
  527. } else {
  528. if ( isset( $_POST[ 'cache_compression' ] ) ) {
  529. $new_cache_compression = 1;
  530. } else {
  531. $new_cache_compression = 0;
  532. }
  533. if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) {
  534. 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>';
  535. } else {
  536. if ( $new_cache_compression != $cache_compression ) {
  537. $cache_compression = $new_cache_compression;
  538. wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
  539. if ( function_exists( 'prune_super_cache' ) )
  540. prune_super_cache( $cache_path, true );
  541. delete_option( 'super_cache_meta' );
  542. }
  543. }
  544. }
  545. }
  546. }
  547. if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'wpsupercache' )
  548. add_action( 'admin_init', 'wp_cache_manager_updates' );
  549. function wp_cache_manager() {
  550. global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled, $wp_cache_hello_world;
  551. global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_no_cache_for_get;
  552. global $wp_cache_cron_check, $wp_cache_debug, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_supercache_cache_list, $cache_page_secret, $cache_home_path;
  553. 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;
  554. global $wpmu_version, $cache_max_time, $wp_cache_mod_rewrite, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $wp_cache_disable_utf8, $wp_cache_mfunc_enabled;
  555. if ( !wpsupercache_site_admin() )
  556. return false;
  557. // used by mod_rewrite rules and config file
  558. if ( function_exists( "cfmobi_default_browsers" ) ) {
  559. $wp_cache_mobile_browsers = cfmobi_default_browsers( "mobile" );
  560. $wp_cache_mobile_browsers = array_merge( $wp_cache_mobile_browsers, cfmobi_default_browsers( "touch" ) );
  561. } elseif ( function_exists( 'lite_detection_ua_contains' ) ) {
  562. $wp_cache_mobile_browsers = explode( '|', lite_detection_ua_contains() );
  563. } else {
  564. $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' );
  565. }
  566. if ( function_exists( "lite_detection_ua_prefixes" ) ) {
  567. $wp_cache_mobile_prefixes = lite_detection_ua_prefixes();
  568. } else {
  569. $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
  570. }
  571. $wp_cache_mobile_browsers = apply_filters( 'cached_mobile_browsers', $wp_cache_mobile_browsers ); // Allow mobile plugins access to modify the mobile UA list
  572. $wp_cache_mobile_prefixes = apply_filters( 'cached_mobile_prefixes', $wp_cache_mobile_prefixes ); // Allow mobile plugins access to modify the mobile UA prefix list
  573. if ( function_exists( 'do_cacheaction' ) ) {
  574. $wp_cache_mobile_browsers = do_cacheaction( 'wp_super_cache_mobile_browsers', $wp_cache_mobile_browsers );
  575. $wp_cache_mobile_prefixes = do_cacheaction( 'wp_super_cache_mobile_prefixes', $wp_cache_mobile_prefixes );
  576. }
  577. $mobile_groups = apply_filters( 'cached_mobile_groups', array() ); // Group mobile user agents by capabilities. Lump them all together by default
  578. // mobile_groups = array( 'apple' => array( 'ipod', 'iphone' ), 'nokia' => array( 'nokia5800', 'symbianos' ) );
  579. if ( false == apply_filters( 'wp_super_cache_error_checking', true ) )
  580. return false;
  581. if ( function_exists( 'get_supercache_dir' ) )
  582. $supercachedir = get_supercache_dir();
  583. if( get_option( 'gzipcompression' ) == 1 )
  584. update_option( 'gzipcompression', 0 );
  585. if( !isset( $cache_rebuild_files ) )
  586. $cache_rebuild_files = 0;
  587. $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
  588. /* http://www.netlobo.com/div_hiding.html */
  589. ?>
  590. <script type='text/javascript'>
  591. <!--
  592. function toggleLayer( whichLayer ) {
  593. var elem, vis;
  594. if( document.getElementById ) // this is the way the standards work
  595. elem = document.getElementById( whichLayer );
  596. else if( document.all ) // this is the way old msie versions work
  597. elem = document.all[whichLayer];
  598. else if( document.layers ) // this is the way nn4 works
  599. elem = document.layers[whichLayer];
  600. vis = elem.style;
  601. // if the style.display value is blank we try to figure it out here
  602. if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
  603. vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  604. vis.display = (vis.display==''||vis.display=='block')?'none':'block';
  605. }
  606. // -->
  607. //Clicking header opens fieldset options
  608. jQuery(document).ready(function(){
  609. jQuery("fieldset h3").css("cursor","pointer").click(function(){
  610. jQuery(this).parent("fieldset").find("p,form,ul,blockquote").toggle("slow");
  611. });
  612. });
  613. </script>
  614. <style type='text/css'>
  615. #nav h2 {
  616. border-bottom: 1px solid #ccc;
  617. padding-bottom: 0;
  618. }
  619. </style>
  620. <?php
  621. echo '<a name="top"></a>';
  622. echo '<div class="wrap">';
  623. echo '<h2>' . __( 'WP Super Cache Settings', 'wp-super-cache' ) . '</h2>';
  624. // set a default
  625. if ( $cache_enabled == false && isset( $wp_cache_mod_rewrite ) == false ) {
  626. $wp_cache_mod_rewrite = 0;
  627. } elseif ( !isset( $wp_cache_mod_rewrite ) && $cache_enabled && $super_cache_enabled ) {
  628. $wp_cache_mod_rewrite = 1;
  629. }
  630. if ( !isset( $_GET[ 'tab' ] ) )
  631. $_GET[ 'tab' ] = '';
  632. if ( $_GET[ 'tab' ] == '' && $cache_enabled && ( $wp_cache_mod_rewrite || $super_cache_enabled == false ) ) {
  633. $_GET[ 'tab' ] = 'settings';
  634. 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>';
  635. }
  636. wpsc_admin_tabs();
  637. if ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 1 && !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
  638. wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
  639. 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 );
  640. }
  641. if(isset($_REQUEST['wp_restore_config']) && $valid_nonce) {
  642. unlink($wp_cache_config_file);
  643. 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>';
  644. }
  645. if ( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
  646. wp_cache_replace_line('^ *\$wp_cache_slash_check', "\$wp_cache_slash_check = 1;", $wp_cache_config_file);
  647. } else {
  648. wp_cache_replace_line('^ *\$wp_cache_slash_check', "\$wp_cache_slash_check = 0;", $wp_cache_config_file);
  649. }
  650. $home_path = parse_url( site_url() );
  651. $home_path = trailingslashit( array_key_exists( 'path', $home_path ) ? $home_path[ 'path' ] : '' );
  652. if (! isset( $wp_cache_home_path ) )
  653. $wp_cache_home_path = '/';
  654. if ( "$home_path" != "$wp_cache_home_path" )
  655. wp_cache_replace_line('^ *\$wp_cache_home_path', "\$wp_cache_home_path = '$home_path';", $wp_cache_config_file);
  656. if( $wp_cache_mobile_enabled == 1 ) {
  657. update_cached_mobile_ua_list( $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $mobile_groups );
  658. }
  659. ?> <table><td valign='top'><?php
  660. switch( $_GET[ 'tab' ] ) {
  661. case "cdn":
  662. scossdl_off_options();
  663. break;
  664. case "tester":
  665. case "contents":
  666. echo '<a name="test"></a>';
  667. wp_cache_files();
  668. break;
  669. case "preload":
  670. if ( !$cache_enabled )
  671. wp_die( __( 'Caching must be enabled to use this feature', 'wp-super-cache' ) );
  672. echo '<a name="preload"></a>';
  673. if ( $super_cache_enabled == true && false == defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
  674. global $wp_cache_preload_interval, $wp_cache_preload_on, $wp_cache_preload_taxonomies, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $wp_cache_preload_posts, $wpdb;
  675. $count = $wpdb->get_var( "SELECT count(*) FROM {$wpdb->posts} WHERE post_status = 'publish'" );
  676. if ( $count > 1000 ) {
  677. $min_refresh_interval = 720;
  678. } else {
  679. $min_refresh_interval = 30;
  680. }
  681. if ( array_key_exists('action', $_POST) && $_POST[ 'action' ] == 'preload' && $valid_nonce ) {
  682. if ( $_POST[ 'posts_to_cache' ] == 'all' ) {
  683. $wp_cache_preload_posts = 'all';
  684. } else {
  685. $wp_cache_preload_posts = (int)$_POST[ 'posts_to_cache' ];
  686. }
  687. wp_cache_replace_line('^ *\$wp_cache_preload_posts', "\$wp_cache_preload_posts = '$wp_cache_preload_posts';", $wp_cache_config_file);
  688. if ( isset( $_POST[ 'preload' ] ) && $_POST[ 'preload' ] == __( 'Cancel Cache Preload', 'wp-super-cache' ) ) {
  689. $next_preload = wp_next_scheduled( 'wp_cache_preload_hook' );
  690. if ( $next_preload ) {
  691. update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
  692. wp_unschedule_event( $next_preload, 'wp_cache_preload_hook' );
  693. }
  694. $fp = @fopen( $cache_path . "stop_preload.txt", 'w' );
  695. @fclose( $fp );
  696. echo "<p><strong>" . __( 'Scheduled preloading of cache almost cancelled. It may take up to a minute for it to cancel completely.', 'wp-super-cache' ) . "</strong></p>";
  697. } elseif ( isset( $_POST[ 'custom_preload_interval' ] ) && ( $_POST[ 'custom_preload_interval' ] == 0 || $_POST[ 'custom_preload_interval' ] >= $min_refresh_interval ) ) {
  698. // if preload interval changes than unschedule any preload jobs and schedule any new one.
  699. $_POST[ 'custom_preload_interval' ] = (int)$_POST[ 'custom_preload_interval' ];
  700. if ( $wp_cache_preload_interval != $_POST[ 'custom_preload_interval' ] ) {
  701. $next_preload = wp_next_scheduled( 'wp_cache_full_preload_hook' );
  702. if ( $next_preload ) {
  703. update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
  704. add_option( 'preload_cache_stop', 1 );
  705. wp_unschedule_event( $next_preload, 'wp_cache_full_preload_hook' );
  706. if ( $wp_cache_preload_interval == 0 ) {
  707. echo "<p><strong>" . __( 'Scheduled preloading of cache cancelled.', 'wp-super-cache' ) . "</strong></p>";
  708. }
  709. }
  710. if ( $_POST[ 'custom_preload_interval' ] != 0 )
  711. wp_schedule_single_event( time() + ( $_POST[ 'custom_preload_interval' ] * 60 ), 'wp_cache_full_preload_hook' );
  712. }
  713. $wp_cache_preload_interval = (int)$_POST[ 'custom_preload_interval' ];
  714. wp_cache_replace_line('^ *\$wp_cache_preload_interval', "\$wp_cache_preload_interval = $wp_cache_preload_interval;", $wp_cache_config_file);
  715. if ( isset( $_POST[ 'preload_email_me' ] ) ) {
  716. $wp_cache_preload_email_me = 1;
  717. } else {
  718. $wp_cache_preload_email_me = 0;
  719. }
  720. wp_cache_replace_line('^ *\$wp_cache_preload_email_me', "\$wp_cache_preload_email_me = $wp_cache_preload_email_me;", $wp_cache_config_file);
  721. if ( isset( $_POST[ 'wp_cache_preload_email_volume' ] ) && in_array( $_POST[ 'wp_cache_preload_email_volume' ], array( 'less', 'medium', 'many' ) ) ) {
  722. $wp_cache_preload_email_volume = $_POST[ 'wp_cache_preload_email_volume' ];
  723. } else {
  724. $wp_cache_preload_email_volume = 'medium';
  725. }
  726. wp_cache_replace_line('^ *\$wp_cache_preload_email_volume', "\$wp_cache_preload_email_volume = '$wp_cache_preload_email_volume';", $wp_cache_config_file);
  727. if ( isset( $_POST[ 'preload_taxonomies' ] ) ) {
  728. $wp_cache_preload_taxonomies = 1;
  729. } else {
  730. $wp_cache_preload_taxonomies = 0;
  731. }
  732. wp_cache_replace_line('^ *\$wp_cache_preload_taxonomies', "\$wp_cache_preload_taxonomies = $wp_cache_preload_taxonomies;", $wp_cache_config_file);
  733. if ( isset( $_POST[ 'preload_on' ] ) ) {
  734. $wp_cache_preload_on = 1;
  735. } else {
  736. $wp_cache_preload_on = 0;
  737. }
  738. wp_cache_replace_line('^ *\$wp_cache_preload_on', "\$wp_cache_preload_on = $wp_cache_preload_on;", $wp_cache_config_file);
  739. if ( isset( $_POST[ 'preload' ] ) && $_POST[ 'preload' ] == __( 'Preload Cache Now', 'wp-super-cache' ) ) {
  740. @unlink( $cache_path . "preload_mutex.tmp" );
  741. update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
  742. wp_schedule_single_event( time() + 10, 'wp_cache_preload_hook' );
  743. echo "<p><strong>" . __( 'Scheduled preloading of cache in 10 seconds.' ) . "</strong></p>";
  744. } elseif ( (int)$_POST[ 'custom_preload_interval' ] ) {
  745. @unlink( $cache_path . "preload_mutex.tmp" );
  746. update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
  747. wp_schedule_single_event( time() + ( (int)$_POST[ 'custom_preload_interval' ] * 60 ), 'wp_cache_full_preload_hook' );
  748. echo "<p><strong>" . sprintf( __( 'Scheduled preloading of cache in %d minutes', 'wp-super-cache' ), (int)$_POST[ 'custom_preload_interval' ] ) . "</strong></p>";
  749. }
  750. }
  751. }
  752. 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>';
  753. 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>';
  754. 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>';
  755. echo '<form name="cache_filler" action="" method="POST">';
  756. echo '<input type="hidden" name="action" value="preload" />';
  757. echo '<input type="hidden" name="page" value="wpsupercache" />';
  758. 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>';
  759. if ( $count > 100 ) {
  760. $step = (int)( $count / 10 );
  761. $select = "<select name='posts_to_cache' size=1>";
  762. $select .= "<option value='all' ";
  763. if ( !isset( $wp_cache_preload_posts ) || $wp_cache_preload_posts == 'all' ) {
  764. $checked = 'selectect=1 ';
  765. $best = 'all';
  766. } else {
  767. $checked = ' ';
  768. $best = $wp_cache_preload_posts;
  769. }
  770. $select .= "{$checked}>" . __( 'all', 'wp-super-cache' ) . "</option>";
  771. for( $c = $step; $c < $count; $c += $step ) {
  772. $checked = ' ';
  773. if ( $best == $c )
  774. $checked = 'selected=1 ';
  775. $select .= "<option value='$c'{$checked}>$c</option>";
  776. }
  777. $checked = ' ';
  778. if ( $best == $count )
  779. $checked = 'selected=1 ';
  780. $select .= "<option value='$count'{$checked}>$count</option>";
  781. $select .= "</select>";
  782. echo '<p>' . sprintf( __( 'Preload %s posts.', 'wp-super-cache' ), $select ) . '</p>';
  783. } else {
  784. echo '<input type="hidden" name="posts_to_cache" value="' . $count . '" />';
  785. }
  786. echo '<input type="checkbox" name="preload_on" value="1" ';
  787. echo $wp_cache_preload_on == 1 ? 'checked=1' : '';
  788. echo ' /> ' . __( 'Preload mode (garbage collection only on legacy cache files. Recommended.)', 'wp-super-cache' ) . '<br />';
  789. echo '<input type="checkbox" name="preload_taxonomies" value="1" ';
  790. echo $wp_cache_preload_taxonomies == 1 ? 'checked=1' : '';
  791. echo ' /> ' . __( 'Preload tags, categories and other taxonomies.', 'wp-super-cache' ) . '<br />';
  792. echo '<input type="checkbox" name="preload_email_me" value="1" ';
  793. echo $wp_cache_preload_email_me == 1 ? 'checked=1' : '';
  794. echo ' /> ' . __( 'Send me status emails when files are refreshed.', 'wp-super-cache' ) . '<br />';
  795. if ( !isset( $wp_cache_preload_email_volume ) )
  796. $wp_cache_preload_email_volume = 'many';
  797. echo '&nbsp;&nbsp;&nbsp;&nbsp;<input name="wp_cache_preload_email_volume" type="radio" value="many" class="tog" ';
  798. checked( 'many', $wp_cache_preload_email_volume );
  799. echo '/> ' . __( 'Many emails, 2 emails per 100 posts.', 'wp-super-cache' ) . '<br >';
  800. echo '&nbsp;&nbsp;&nbsp;&nbsp;<input name="wp_cache_preload_email_volume" type="radio" value="medium" class="tog" ';
  801. checked( 'medium', $wp_cache_preload_email_volume );
  802. echo '/> ' . __( 'Medium, 1 email per 100 posts.', 'wp-super-cache' ) . '<br >';
  803. echo '&nbsp;&nbsp;&nbsp;&nbsp;<input name="wp_cache_preload_email_volum…

Large files files are truncated, but you can click here to view the full file