PageRenderTime 41ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

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

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