PageRenderTime 79ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/kennethreitz-archive/wordpress-skeleton
PHP | 1840 lines | 1675 code | 125 blank | 40 comment | 390 complexity | 15970bd9668db53b0707470932ca3bfd MD5 | raw file
  1. <?php
  2. /*
  3. Plugin Name: WP Super Cache
  4. Plugin URI: http://ocaoimh.ie/wp-super-cache/
  5. Description: Very fast caching plugin for WordPress.
  6. Version: 0.9.9
  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-2009 Donncha O Caoimh (http://ocaoimh.ie/)
  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' ) ) {
  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. // from legolas558 d0t users dot sf dot net at http://www.php.net/is_writable
  49. function is_writeable_ACLSafe($path) {
  50. // PHP's is_writable does not work with Win32 NTFS
  51. if ($path{strlen($path)-1}=='/') // recursively return a temporary file path
  52. return is_writeable_ACLSafe($path.uniqid(mt_rand()).'.tmp');
  53. else if (is_dir($path))
  54. return is_writeable_ACLSafe($path.'/'.uniqid(mt_rand()).'.tmp');
  55. // check tmp file for read/write capabilities
  56. $rm = file_exists($path);
  57. $f = @fopen($path, 'a');
  58. if ($f===false)
  59. return false;
  60. fclose($f);
  61. if (!$rm)
  62. unlink($path);
  63. return true;
  64. }
  65. function get_wpcachehome() {
  66. if( defined( 'WPCACHEHOME' ) == false ) {
  67. if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
  68. define( 'WPCACHEHOME', trailingslashit( dirname(__FILE__) ) );
  69. } elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
  70. define( 'WPCACHEHOME', dirname(__FILE__) . '/wp-super-cache/' );
  71. } else {
  72. die( sprintf( __( 'Please create %s /wp-cache-config.php from wp-super-cache/wp-cache-config-sample.php', 'wp-super-cache' ), WP_CONTENT_DIR ) );
  73. }
  74. }
  75. }
  76. function wpsupercache_deactivate() {
  77. global $wp_cache_config_file, $wp_cache_link, $cache_path;
  78. $files = array( $wp_cache_config_file, $wp_cache_link );
  79. foreach( $files as $file ) {
  80. if( file_exists( $file ) )
  81. unlink( $file );
  82. }
  83. if( !function_exists( 'prune_super_cache' ) )
  84. include_once( 'wp-cache-phase2.php' );
  85. prune_super_cache ($cache_path, true);
  86. @unlink( $cache_path . '.htaccess' );
  87. @unlink( $cache_path . 'meta' );
  88. @unlink( $cache_path . 'supercache' );
  89. wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
  90. }
  91. register_deactivation_hook( __FILE__, 'wpsupercache_deactivate' );
  92. function wpsupercache_activate() {
  93. }
  94. register_activation_hook( __FILE__, 'wpsupercache_activate' );
  95. function wp_cache_add_pages() {
  96. if( function_exists( 'is_site_admin' ) ) {
  97. if( is_site_admin() ) {
  98. add_submenu_page('wpmu-admin.php', 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
  99. add_options_page('WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
  100. }
  101. } else {
  102. add_options_page('WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
  103. }
  104. }
  105. add_action('admin_menu', 'wp_cache_add_pages');
  106. function wp_cache_manager() {
  107. global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled, $wp_cache_hello_world;
  108. global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers;
  109. global $wp_cache_cron_check, $wp_cache_debug, $wp_cache_hide_donation, $wp_cache_not_logged_in, $wp_supercache_cache_list;
  110. global $wp_super_cache_front_page_check, $wp_cache_object_cache, $_wp_using_ext_object_cache;
  111. if( function_exists( 'is_site_admin' ) )
  112. if( !is_site_admin() )
  113. return;
  114. $supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]);
  115. if( get_option( 'gzipcompression' ) == 1 )
  116. update_option( 'gzipcompression', 0 );
  117. if( !isset( $cache_rebuild_files ) )
  118. $cache_rebuild_files = 0;
  119. $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
  120. /* http://www.netlobo.com/div_hiding.html */
  121. ?>
  122. <script type='text/javascript'>
  123. <!--
  124. function toggleLayer( whichLayer ) {
  125. var elem, vis;
  126. if( document.getElementById ) // this is the way the standards work
  127. elem = document.getElementById( whichLayer );
  128. else if( document.all ) // this is the way old msie versions work
  129. elem = document.all[whichLayer];
  130. else if( document.layers ) // this is the way nn4 works
  131. elem = document.layers[whichLayer];
  132. vis = elem.style;
  133. // if the style.display value is blank we try to figure it out here
  134. if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
  135. vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  136. vis.display = (vis.display==''||vis.display=='block')?'none':'block';
  137. }
  138. // -->
  139. //Clicking header opens fieldset options
  140. jQuery(document).ready(function(){
  141. jQuery("fieldset h3").css("cursor","pointer").click(function(){
  142. jQuery(this).parent("fieldset").find("p,form,ul,blockquote").toggle("slow");
  143. });
  144. });
  145. </script>
  146. <?php
  147. echo '<div class="wrap">';
  148. echo "<h2><a href='?page=wpsupercache'>" . __( 'WP Super Cache Manager', 'wp-super-cache' ) . "</a></h2>\n";
  149. if ( 1 == ini_get( 'safe_mode' ) || "on" == strtolower( ini_get( 'safe_mode' ) ) ) {
  150. ?><h3><?php _e( 'Warning! PHP Safe Mode Enabled!', 'wp-super-cache' ); ?></h3>
  151. <p><?php _e( 'You may experience problems running this plugin because SAFE MODE is enabled.', 'wp-super-cache' );
  152. if( !ini_get( 'safe_mode_gid' ) ) {
  153. echo __( 'Your server is set up to check the owner of PHP scripts before allowing them to read and write files.', 'wp-super-cache' ) . "</p><p>";
  154. echo sprintf( __( 'You or an administrator may be able to make it work by changing the group owner of the plugin scripts to match that of the web server user. The group owner of the %s/cache/ directory must also be changed. See the <a href="http://php.net/features.safe-mode">safe mode manual page</a> for further details.', 'wp-super-cache' ), WP_CONTENT_DIR ) . "</p>";
  155. } else {
  156. echo __( 'You or an administrator must disable this. See the <a href="http://php.net/features.safe-mode">safe mode manual page</a> for further details. This cannot be disabled in a .htaccess file unfortunately. It must be done in the php.ini config file.', 'wp-super-cache' ) . "</p>";
  157. }
  158. }
  159. if ( '' == get_option( 'permalink_structure' ) ) {
  160. echo "<h3>" . __( 'Permlink Structure Error', 'wp-super-cache' ) . "</h3>";
  161. 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>";
  162. }
  163. if ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 1 && !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
  164. wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
  165. 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 );
  166. }
  167. if(isset($_REQUEST['wp_restore_config']) && $valid_nonce) {
  168. unlink($wp_cache_config_file);
  169. 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>';
  170. }
  171. if ( !wp_cache_check_link() ||
  172. !wp_cache_verify_config_file() ||
  173. !wp_cache_verify_cache_dir() ) {
  174. echo '<p>' . __( "Cannot continue... fix previous problems and retry.", 'wp-super-cache' ) . '</p>';
  175. echo "</div>\n";
  176. return;
  177. }
  178. if (!wp_cache_check_global_config()) {
  179. echo "</div>\n";
  180. return;
  181. }
  182. if( $wp_cache_debug || !$wp_cache_cron_check ) {
  183. if( function_exists( "wp_remote_get" ) == false ) {
  184. $hostname = str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'siteurl' ) ) );
  185. if( strpos( $hostname, '/' ) )
  186. $hostname = substr( $hostname, 0, strpos( $hostname, '/' ) );
  187. $ip = gethostbyname( $hostname );
  188. if( substr( $ip, 0, 3 ) == '127' || substr( $ip, 0, 7 ) == '192.168' ) {
  189. ?><h3><?php printf( __( 'Warning! Your hostname "%s" resolves to %s', 'wp-super-cache' ), $hostname, $ip ); ?></h3>
  190. <div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'>
  191. <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>
  192. <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>
  193. </div>
  194. <?php
  195. } else {
  196. wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
  197. }
  198. } else {
  199. $cron_url = get_option( 'siteurl' ) . '/wp-cron.php?check=' . wp_hash('187425');
  200. $cron = wp_remote_get($cron_url, array('timeout' => 0.01, 'blocking' => true));
  201. if( is_array( $cron ) ) {
  202. if( $cron[ 'response' ][ 'code' ] == '404' ) {
  203. ?><h3>Warning! wp-cron.php not found!</h3>
  204. <div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'>
  205. <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>
  206. <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>
  207. </div>
  208. <?php
  209. } else {
  210. wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
  211. }
  212. }
  213. }
  214. }
  215. if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) {
  216. ?><h4 style='color: #a00'><?php _e( 'Zlib Output Compression Enabled!', 'wp-super-cache' ); ?></h4>
  217. <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><?php
  218. }
  219. if( $cache_enabled == true && $super_cache_enabled == true && !got_mod_rewrite() ) {
  220. ?><h4 style='color: #a00'><?php _e( 'Mod rewrite may not be installed!', 'wp-super-cache' ); ?></h4>
  221. <p><?php _e( 'It appears that mod_rewrite is not installed. Sometimes this check isn&#8217;t 100% reliable, especially if you are not using Apache. Please verify that the mod_rewrite module is loaded. It is required for serving Super Cache static files. You will still be able to use half-on mode.', 'wp-super-cache' ); ?></p><?php
  222. }
  223. if( !is_writeable_ACLSafe($wp_cache_config_file) ) {
  224. define( "SUBMITDISABLED", 'disabled style="color: #aaa" ' );
  225. ?><h4 style='text-align:center; color: #a00'><?php _e( 'Read Only Mode. Configuration cannot be changed.', 'wp-super-cache' ); ?> <a href="javascript:toggleLayer('readonlywarning');" title="<?php _e( 'Why your configuration may not be changed', 'wp-super-cache' ); ?>"><?php _e( 'Why', 'wp-super-cache' ); ?></a></h4>
  226. <div id='readonlywarning' style='border: 1px solid #aaa; margin: 2px; padding: 2px; display: none;'>
  227. <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 ); ?>
  228. <?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>
  229. <?php _e( 'Writeable:', 'wp-super-cache' ); ?> <code>chmod 666 <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code>
  230. <?php _e( 'Readonly:', 'wp-super-cache' ); ?> <code>chmod 644 <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code></p>
  231. </div><?php
  232. } else {
  233. define( "SUBMITDISABLED", ' ' );
  234. }
  235. // Server could be running as the owner of the wp-content directory. Therefore, if it's
  236. // writable, issue a warning only if the permissions aren't 755.
  237. if( is_writeable_ACLSafe( WP_CONTENT_DIR . '/' ) ) {
  238. $wp_content_stat = stat(WP_CONTENT_DIR . '/');
  239. $wp_content_mode = ($wp_content_stat['mode'] & 0777);
  240. if( $wp_content_mode != 0755 ) {
  241. ?><h4 style='text-align:center; color: #a00'><?php printf( __( 'Warning! %s is writeable!', 'wp-super-cache' ), WP_CONTENT_DIR ); ?></h4>
  242. <p><?php printf( __( 'You should change the permissions on %s and make it more restrictive. Use your ftp client, or the following command to fix things:', 'wp-super-cache' ), WP_CONTENT_DIR ); ?><code>chmod 755 <?php echo WP_CONTENT_DIR; ?>/</code></p><?php
  243. }
  244. }
  245. // used by mod_rewrite rules and config file
  246. if ( function_exists( "cfmobi_default_browsers" ) ) {
  247. $mobile_browsers = cfmobi_default_browsers( "mobile" );
  248. $mobile_browsers = array_merge( $mobile_browsers, cfmobi_default_browsers( "touch" ) );
  249. } else {
  250. $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' );
  251. }
  252. if ( $valid_nonce ) {
  253. if( isset( $_POST[ 'wp_cache_status' ] ) ) {
  254. if( isset( $_POST[ 'wp_cache_mobile_enabled' ] ) ) {
  255. $wp_cache_mobile_enabled = 1;
  256. } else {
  257. $wp_cache_mobile_enabled = 0;
  258. }
  259. if( $wp_cache_mobile_enabled == 1 ) {
  260. wp_cache_replace_line('^ *\$wp_cache_mobile_browsers', "\$wp_cache_mobile_browsers = '" . implode( ', ', $mobile_browsers ) . "';", $wp_cache_config_file);
  261. }
  262. wp_cache_replace_line('^ *\$wp_cache_mobile_enabled', "\$wp_cache_mobile_enabled = " . $wp_cache_mobile_enabled . ";", $wp_cache_config_file);
  263. $wp_supercache_cache_list = $_POST[ 'wp_supercache_cache_list' ] == 1 ? 1 : 0;
  264. wp_cache_replace_line('^ *\$wp_supercache_cache_list', "\$wp_supercache_cache_list = " . $wp_supercache_cache_list . ";", $wp_cache_config_file);
  265. switch( $_POST[ 'wp_cache_status' ] ) {
  266. case 'all':
  267. wp_cache_enable();
  268. break;
  269. case 'none':
  270. wp_cache_disable();
  271. break;
  272. case 'wpcache':
  273. wp_cache_enable();
  274. wp_super_cache_disable();
  275. break;
  276. }
  277. if( isset( $_POST[ 'wp_cache_hello_world' ] ) ) {
  278. $wp_cache_hello_world = 1;
  279. } else {
  280. $wp_cache_hello_world = 0;
  281. }
  282. wp_cache_replace_line('^ *\$wp_cache_hello_world', '$wp_cache_hello_world = ' . (int)$wp_cache_hello_world . ";", $wp_cache_config_file);
  283. if( isset( $_POST[ 'wp_cache_clear_on_post_edit' ] ) ) {
  284. $wp_cache_clear_on_post_edit = 1;
  285. } else {
  286. $wp_cache_clear_on_post_edit = 0;
  287. }
  288. 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);
  289. if( isset( $_POST[ 'cache_rebuild_files' ] ) ) {
  290. $cache_rebuild_files = 1;
  291. } else {
  292. $cache_rebuild_files = 0;
  293. }
  294. wp_cache_replace_line('^ *\$cache_rebuild_files', "\$cache_rebuild_files = " . $cache_rebuild_files . ";", $wp_cache_config_file);
  295. if( isset( $_POST[ 'wp_cache_mutex_disabled' ] ) ) {
  296. $wp_cache_mutex_disabled = 0;
  297. } else {
  298. $wp_cache_mutex_disabled = 1;
  299. }
  300. if( defined( 'WPSC_DISABLE_LOCKING' ) ) {
  301. $wp_cache_mutex_disabled = 1;
  302. }
  303. wp_cache_replace_line('^ *\$wp_cache_mutex_disabled', "\$wp_cache_mutex_disabled = " . $wp_cache_mutex_disabled . ";", $wp_cache_config_file);
  304. if( isset( $_POST[ 'wp_cache_not_logged_in' ] ) ) {
  305. if( $wp_cache_not_logged_in == 0 && function_exists( 'prune_super_cache' ) )
  306. prune_super_cache ($cache_path, true);
  307. $wp_cache_not_logged_in = 1;
  308. } else {
  309. $wp_cache_not_logged_in = 0;
  310. }
  311. wp_cache_replace_line('^ *\$wp_cache_not_logged_in', "\$wp_cache_not_logged_in = " . $wp_cache_not_logged_in . ";", $wp_cache_config_file);
  312. if( $_wp_using_ext_object_cache && isset( $_POST[ 'wp_cache_object_cache' ] ) ) {
  313. if( $wp_cache_object_cache == 0 && function_exists( 'prune_super_cache' ) )
  314. prune_super_cache ($cache_path, true);
  315. $wp_cache_object_cache = 1;
  316. } else {
  317. $wp_cache_object_cache = 0;
  318. }
  319. wp_cache_replace_line('^ *\$wp_cache_object_cache', "\$wp_cache_object_cache = " . $wp_cache_object_cache . ";", $wp_cache_config_file);
  320. }
  321. if( defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
  322. $cache_compression_changed = false;
  323. $cache_compression = 0;
  324. wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
  325. } elseif( isset( $_POST[ 'cache_compression' ] ) && $_POST[ 'cache_compression' ] != $cache_compression ) {
  326. if ( $_POST[ 'cache_compression' ] && 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) {
  327. _e( "<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' );
  328. } else {
  329. $cache_compression = intval( $_POST[ 'cache_compression' ] );
  330. $cache_compression_changed = true;
  331. wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
  332. if( function_exists( 'prune_super_cache' ) )
  333. prune_super_cache ($cache_path, true);
  334. delete_option( 'super_cache_meta' );
  335. }
  336. }
  337. if( isset( $_POST[ 'wp_cache_hide_donation' ] ) && $_POST[ 'wp_cache_hide_donation' ] != $wp_cache_hide_donation ) {
  338. $wp_cache_hide_donation = intval( $_POST[ 'wp_cache_hide_donation' ] );
  339. wp_cache_replace_line('^ *\$wp_cache_hide_donation', "\$wp_cache_hide_donation = " . $wp_cache_hide_donation . ";", $wp_cache_config_file);
  340. }
  341. }
  342. echo '<a name="top"></a>';
  343. ?>
  344. <table><td><fieldset class="options" id="show-this-fieldset">
  345. <h3><?php _e( 'WP Super Cache Status', 'wp-super-cache' ); ?></h3><?php
  346. echo '<form name="wp_manager" action="#top" method="post">';
  347. ?>
  348. <label><input type='radio' name='wp_cache_status' value='all' <?php if( $cache_enabled == true && $super_cache_enabled == true ) { echo 'checked=checked'; } ?>> <strong><?php _e( 'ON', 'wp-super-cache' ); ?></strong> <span class="setting-description"><?php _e( 'WP Cache and Super Cache enabled', 'wp-super-cache' ); ?></span></label><br />
  349. <label><input type='radio' name='wp_cache_status' value='wpcache' <?php if( $cache_enabled == true && $super_cache_enabled == false ) { echo 'checked=checked'; } ?>> <strong><?php _e( 'HALF ON', 'wp-super-cache' ); ?></strong> <span class="setting-description"><?php _e( 'Super Cache Disabled, only legacy WP-Cache caching.', 'wp-super-cache' ); ?></span></label><br />
  350. <label><input type='radio' name='wp_cache_status' value='none' <?php if( $cache_enabled == false ) { echo 'checked=checked'; } ?>> <strong><?php _e( 'OFF', 'wp-super-cache' ); ?></strong> <span class="setting-description"><?php _e( 'WP Cache and Super Cache disabled', 'wp-super-cache' ); ?></span></label><br />
  351. <p><label><input type='checkbox' name='wp_cache_not_logged_in' <?php if( $wp_cache_not_logged_in ) echo "checked"; ?> value='1'> <?php _e( 'Don&#8217;t cache pages for logged in users.', 'wp-super-cache' ); ?></label></p>
  352. <p><label><input type='checkbox' name='wp_cache_hello_world' <?php if( $wp_cache_hello_world ) echo "checked"; ?> value='1'> <?php _e( 'Proudly tell the world your server is Digg proof! (places a message in your blog&#8217;s footer)', 'wp-super-cache' ); ?></label></p>
  353. <p><label><input type='checkbox' name='wp_cache_clear_on_post_edit' <?php if( $wp_cache_clear_on_post_edit ) echo "checked"; ?> value='1'> <?php _e( 'Clear all cache files when a post or page is published. (This may significantly slow down saving of posts.)', 'wp-super-cache' ); ?></label></p>
  354. <p><label><input type='checkbox' name='cache_rebuild_files' <?php if( $cache_rebuild_files ) echo "checked"; ?> value='1'> <?php _e( 'Cache rebuild. Serve a supercache file to anonymous users while a new file is being generated. Recommended for <em>very</em> busy websites with lots of comments. Makes "directly cached pages" and "Lockdown mode" obsolete.', 'wp-super-cache' ); ?></label></p>
  355. <?php if( false == defined( 'WPSC_DISABLE_LOCKING' ) ) { ?>
  356. <p><label><input type='checkbox' name='wp_cache_mutex_disabled' <?php if( !$wp_cache_mutex_disabled ) echo "checked"; ?> value='0'> <?php _e( 'Coarse file locking. You probably don&#8217;t need this but it may help if your server is underpowered. Warning! <em>May cause your server to lock up in very rare cases!</em>', 'wp-super-cache' ); ?></label></p>
  357. <?php } ?>
  358. <p><label><input type='checkbox' name='wp_supercache_cache_list' <?php if( $wp_supercache_cache_list ) echo "checked"; ?> value='1'> <?php _e( 'List the newest cached pages (may be expensive to run on busy sites, use with caution.)', 'wp-super-cache' ); ?></label>
  359. <p><label><input type='checkbox' name='wp_cache_mobile_enabled' <?php if( $wp_cache_mobile_enabled ) echo "checked"; ?> value='1'> <?php printf( __( 'Mobile device support using <a href="%s">WordPress Mobile Edition</a>.', 'wp-super-cache' ), 'http://wordpress.org/extend/plugins/wordpress-mobile-edition/' ); ?></label>
  360. <?php
  361. $home_path = trailingslashit( get_home_path() );
  362. $scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
  363. if ( !$wp_cache_mobile_enabled && strpos( $scrules, addcslashes( implode( '|', $mobile_browsers ), ' ' ) ) ) {
  364. echo "<blockquote style='background-color:#feefb3; padding: 5px; margin: 5px;'><h4>" . __( 'Mobile rewrite rules detected', 'wp-super-cache' ) . "</h4>";
  365. 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></blockquote>";
  366. } elseif ( $wp_cache_mobile_enabled && $scrules != '' && false === strpos( $scrules, addcslashes( implode( '|', $mobile_browsers ), ' ' ) ) ) {
  367. ?>
  368. <blockquote style='background-color:#fefeb3; padding: 5px; margin: 5px;'><h4><?php _e( 'Rewrite rules must be updated', 'wp-super-cache' ); ?></h4>
  369. <p><?php _e( 'The rewrite rules required by this plugin have changed or are missing. ', 'wp-super-cache' ); ?>
  370. <?php _e( 'Mobile support requires extra rules in your .htaccess file, or you can set the plugin to half-on mode. Here are your options (in order of difficulty):', 'wp-super-cache' ); ?>
  371. <ol><li> <?php _e( 'Set the plugin to half on mode and enable mobile support.', 'wp-super-cache' ); ?></li>
  372. <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>
  373. <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|wp-postpass_).*$</code> add this line: (do it twice, once for each section)', 'wp-super-cache' ), $home_path ); ?></p>
  374. <div style='padding: 2px; margin: 2px; border: 1px solid #333; width:400px; overflow: scroll'><pre>RewriteCond %{HTTP_user_agent} !^.*(<?php echo addcslashes( implode( '|', $mobile_browsers ), ' ' ); ?>).*</pre></div></li></ol></blockquote>
  375. <?php } ?>
  376. <p><strong><?php _e( 'Note:', 'wp-super-cache' ); ?></strong> <?php printf( __( 'If uninstalling this plugin, make sure the directory <em>%s</em> is writeable by the webserver so the files <em>advanced-cache.php</em> and <em>cache-config.php</em> can be deleted automatically. (Making sure those files are writeable too is probably a good idea!)', 'wp-super-cache' ), WP_CONTENT_DIR ); ?></p>
  377. <p><?php printf( __( 'Uninstall using the <a href="%1$s/wp-super-cache/uninstall.php">uninstall script</a> to remove files and directories created by the plugin. (Please see <a href="%1$s/wp-super-cache/readme.txt">readme.txt</a> for instructions on uninstalling this script.)', 'wp-super-cache' ), WP_PLUGIN_URL ); ?></p>
  378. <?php if ( $_wp_using_ext_object_cache ) {
  379. ?><p><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></p><?php
  380. }
  381. echo "<p><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></p>";
  382. echo "<div class='submit'><input type='submit' " . SUBMITDISABLED . " value='" . __( 'Update Status', 'wp-super-cache' ) . " &raquo;' /></div>";
  383. wp_nonce_field('wp-cache');
  384. ?>
  385. </form>
  386. <?php
  387. if( $super_cache_enabled && function_exists( 'apache_get_modules' ) ) {
  388. $mods = apache_get_modules();
  389. $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' ) );
  390. foreach( $required_modules as $req => $desc ) {
  391. if( !in_array( $req, $mods ) ) {
  392. $missing_mods[ $req ] = $desc;
  393. }
  394. }
  395. if( isset( $missing_mods) && is_array( $missing_mods ) ) {
  396. echo "<h3>" . __( 'Missing Apache Modules', 'wp-super-cache' ) . "</h3>";
  397. echo "<p>" . __( 'The following Apache modules are missing. The plugin will work in half-on mode without them. In full Supercache mode, your visitors may see corrupted pages or out of date content however.', 'wp-super-cache' ) . "</p>";
  398. echo "<ul>";
  399. foreach( $missing_mods as $req => $desc ) {
  400. echo "<li> $req - $desc</li>";
  401. }
  402. echo "</ul>";
  403. }
  404. }
  405. ?>
  406. </fieldset>
  407. </td><td valign='top'>
  408. <div style='background: #ffc; border: 1px solid #333; margin: 2px; padding: 5px'>
  409. <h3 align='center'><?php _e( 'Make WordPress Faster', 'wp-super-cache' ); ?></h3>
  410. <?php if( $wp_cache_hide_donation != 1 ) { ?>
  411. <p><?php printf( __( '%1$s really makes your blog go faster. Make it go faster<sup>*</sup> by buying me an <a href="%2$s">Amazon gift card</a>! Make it out to "%3$s" for whatever amount you want. Every penny helps!', 'wp-super-cache' ), '<a href="http://ocaoimh.ie/wp-super-cache/?r=wpsc">WP Super Cache</a>', 'http://ocaoimh.ie/agc', 'donncha@ocaoimh.ie' ) ?>;</p>
  412. <p><?php printf( __( 'If Amazon isn&#8217;t your thing, there&#8217;s also PayPal. Click the "Donate" button below or take a quick peek at my <a href="%s">wishlist</a>.', 'wp-super-cache' ), 'http://ocaoimh.ie/wish' ); ?></p>
  413. <p><?php _e( 'Thanks in advance!', 'wp-super-cache' ); ?><br />Donncha<br />
  414. <small>* <?php _e( 'Ok, it won&#8217;t go any faster but you&#8217;ll make this plugin author very happy!', 'wp-super-cache' ); ?></small></p>
  415. <div align='center'>
  416. <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
  417. <input type="hidden" name="cmd" value="_s-xclick"/>
  418. <input type="hidden" name="hosted_button_id" value="3244504"/>
  419. <input type="image" src="https://www.paypal.com/en_GB/i/btn/btn_donate_SM.gif" border="0" name="submit" alt=""/>
  420. <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"/><br />
  421. </form>
  422. <p><?php _e( 'Don&#8217;t show me this again.', 'wp-super-cache' ); ?> <form action="#top" method="post"><input type='hidden' name='wp_cache_hide_donation' value='1' /><input type='submit' value='<?php _e( 'Hide', 'wp-super-cache' ); ?>' /><?php wp_nonce_field('wp-cache'); ?></form></p>
  423. </div>
  424. <?php } else { ?>
  425. <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>
  426. <p><?php printf( __( 'He blogs at %1$s, posts photos at %2$s and <a href="%3$s">wishes</a> he had more time to read and relax.', 'wp-super-cache' ), '<a href="http://ocaoimh.ie/?r=supercache">Holy Shmoly</a>', '<a href="http://inphotos.org/?r=supercache">In Photos.org</a>', 'http://ocaoimh.ie/gad' ); ?></p>
  427. <p><?php printf( __( 'Please say hi to him on %s too!', 'wp-super-cache' ), '<a href="http://twitter.com/donncha/">Twitter</a>' ); ?></p>
  428. <?php
  429. }
  430. if ( isset( $wp_supercache_cache_list ) && $wp_supercache_cache_list ) {
  431. $start_date = get_option( 'wpsupercache_start' );
  432. if ( !$start_date ) {
  433. $start_date = time();
  434. }
  435. ?>
  436. <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>
  437. <p><?php _e( 'Newest Cached Pages:', 'wp-super-cache' ); ?><ol>
  438. <?php
  439. foreach( array_reverse( (array)get_option( 'supercache_last_cached' ) ) as $url ) {
  440. $since = time() - strtotime( $url[ 'date' ] );
  441. echo "<li><a title='" . sprintf( __( 'Cached %s seconds ago', 'wp-super-cache' ), $since ) . "' href='" . site_url( $url[ 'url' ] ) . "'>{$url[ 'url' ]}</a></li>\n";
  442. }
  443. ?></ol>
  444. <small><?php _e( '(may not always be accurate on busy sites)', 'wp-super-cache' ); ?></small>
  445. </p><?php
  446. } else {
  447. $start_date = get_option( 'wpsupercache_start' );
  448. if ( $start_date ) {
  449. update_option( 'wpsupercache_start', $start_date );
  450. update_option( 'wpsupercache_count', 0 );
  451. }
  452. }
  453. ?>
  454. </div>
  455. </td></table>
  456. <?php
  457. wp_cache_files();
  458. wsc_mod_rewrite( $mobile_browsers );
  459. wp_cache_edit_max_time();
  460. echo '<a name="files"></a><fieldset class="options"><h3>' . __( 'Accepted Filenames &amp; Rejected URIs', 'wp-super-cache' ) . '</h3>';
  461. wp_cache_edit_rejected_pages();
  462. echo "\n";
  463. wp_cache_edit_rejected();
  464. echo "\n";
  465. wp_cache_edit_accepted();
  466. echo '</fieldset>';
  467. wp_cache_edit_rejected_ua();
  468. wp_cache_debug_settings();
  469. wp_lock_down();
  470. wp_cache_restore();
  471. ob_start();
  472. if( defined( 'WP_CACHE' ) ) {
  473. if( function_exists( 'do_cacheaction' ) ) {
  474. do_cacheaction( 'cache_admin_page' );
  475. }
  476. }
  477. $out = ob_get_contents();
  478. ob_end_clean();
  479. if( SUBMITDISABLED == ' ' && $out != '' ) {
  480. echo '<fieldset class="options"><h3>' . __( 'Cache Plugins', 'wp-super-cache' ) . '</h3>';
  481. echo $out;
  482. echo '</fieldset>';
  483. }
  484. echo "</div>\n";
  485. }
  486. function wsc_mod_rewrite( $mobile_browsers ) {
  487. global $cache_enabled, $super_cache_enabled, $cache_compression, $cache_compression_changed, $valid_nonce, $cache_path;
  488. if( $super_cache_enabled == false && $cache_enabled == true ) {
  489. ?><h3><?php _e( 'Super Cache Compression', 'wp-super-cache' ); ?></h3>
  490. <p><?php _e( 'Compression is enabled by default when in <em>HALF ON</em> mode.', 'wp-super-cache' ); ?></p>
  491. <?php
  492. return;
  493. } elseif ( $super_cache_enabled == false ) {
  494. return;
  495. }
  496. if( false == defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
  497. ?>
  498. <a name='rewrite'></a>
  499. <fieldset class="options">
  500. <h3><?php _e( 'Super Cache Compression', 'wp-super-cache' ); ?></h3>
  501. <form name="wp_manager" action="#rewrite" method="post">
  502. <label><input type="radio" name="cache_compression" value="1" <?php if( $cache_compression ) { echo "checked=checked"; } ?>> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
  503. <label><input type="radio" name="cache_compression" value="0" <?php if( !$cache_compression ) { echo "checked=checked"; } ?>> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
  504. <p><?php _e( 'Compression is disabled by default because some hosts have problems with compressed files. Switching this on and off clears the cache.', 'wp-super-cache' ); ?></p>
  505. <?php
  506. if( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && !$cache_compression ) {
  507. ?><p><strong><?php _e( 'Super Cache compression is now disabled.', 'wp-super-cache' ); ?></strong></p> <?php
  508. } elseif( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && $cache_compression ) {
  509. ?><p><strong><?php _e( 'Super Cache compression is now enabled.', 'wps-uper-cache' ); ?></strong></p><?php
  510. }
  511. echo '<div class="submit"><input ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update Compression', 'wp-super-cache' ) . ' &raquo;" /></div>';
  512. wp_nonce_field('wp-cache');
  513. echo "</form>\n";
  514. ?></fieldset>
  515. <?php } ?>
  516. <a name="modrewrite"></a><fieldset class="options">
  517. <h3><?php _e( 'Mod Rewrite Rules', 'wp-super-cache' ); ?></h3><?php
  518. if ( isset( $_SERVER[ "PHP_DOCUMENT_ROOT" ] ) ) {
  519. $document_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
  520. $apache_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
  521. } else {
  522. $document_root = $_SERVER[ "DOCUMENT_ROOT" ];
  523. $apache_root = '%{DOCUMENT_ROOT}';
  524. }
  525. $home_path = get_home_path();
  526. $home_root = parse_url(get_bloginfo('url'));
  527. $home_root = isset( $home_root['path'] ) ? trailingslashit( $home_root['path'] ) : '/';
  528. $inst_root = str_replace( '//', '/', '/' . trailingslashit( str_replace( $document_root, '', str_replace( '\\', '/', WP_CONTENT_DIR ) ) ) );
  529. $wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) );
  530. $wprules = str_replace( "RewriteEngine On\n", '', $wprules );
  531. $wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
  532. $scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
  533. if( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
  534. $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*[^/]$";
  535. $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*//.*$";
  536. }
  537. $condition_rules[] = "RewriteCond %{REQUEST_METHOD} !POST";
  538. $condition_rules[] = "RewriteCond %{QUERY_STRING} !.*=.*";
  539. $condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$";
  540. $condition_rules[] = "RewriteCond %{HTTP_USER_AGENT} !^.*(" . addcslashes( implode( '|', $mobile_browsers ), ' ' ) . ").*";
  541. $condition_rules = apply_filters( 'supercacherewriteconditions', $condition_rules );
  542. $rules = "<IfModule mod_rewrite.c>\n";
  543. $rules .= "RewriteEngine On\n";
  544. $rules .= "RewriteBase $home_root\n"; // props Chris Messina
  545. $charset = get_option('blog_charset') == '' ? 'UTF-8' : get_option('blog_charset');
  546. $rules .= "AddDefaultCharset {$charset}\n";
  547. $rules .= "CONDITION_RULES";
  548. $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
  549. $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz -f\n";
  550. $rules .= "RewriteRule ^(.*) {$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz [L]\n\n";
  551. $rules .= "CONDITION_RULES";
  552. $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html -f\n";
  553. $rules .= "RewriteRule ^(.*) {$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html [L]\n";
  554. $rules .= "</IfModule>\n";
  555. $rules = apply_filters( 'supercacherewriterules', $rules );
  556. $rules = str_replace( "CONDITION_RULES", implode( "\n", $condition_rules ) . "\n", $rules );
  557. $dohtaccess = true;
  558. if( function_exists( 'is_site_admin' ) ) {
  559. 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>";
  560. } elseif( !$wprules || $wprules == '' ) {
  561. echo "<h4 style='color: #a00'>" . __( 'Mod Rewrite rules cannot be updated!', 'wp-super-cache' ) . "</h4>";
  562. 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 );
  563. 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>";
  564. _e( 'Refresh this page when you have updated your .htaccess file.', 'wp-super-cache' );
  565. echo "</fieldset></div>";
  566. return;
  567. } elseif( strpos( $wprules, 'wordpressuser' ) ) { // Need to clear out old mod_rewrite rules
  568. 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>";
  569. echo "</fieldset></div>";
  570. return;
  571. } elseif( $scrules != '' && strpos( $scrules, '%{REQUEST_URI} !^.*[^/]$' ) === false && substr( get_option( 'permalink_structure' ), -1 ) == '/' ) { // permalink structure has a trailing slash, need slash check in rules.
  572. 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>";
  573. echo "<blockquote><code>RewriteCond %{REQUEST_URI} !^.*[^/]$RewriteCond %{REQUEST_URI} !^.*//.*$</code></blockquote>";
  574. 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>";
  575. $dohtaccess = false;
  576. } elseif( strpos( $scrules, 'supercache' ) || strpos( $wprules, 'supercache' ) ) { // only write the rules once
  577. $dohtaccess = false;
  578. }
  579. // cache/.htaccess rules
  580. $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";
  581. $gziprules .= "<IfModule mod_deflate.c>\n SetEnvIfNoCase Request_URI \.gz$ no-gzip\n</IfModule>\n";
  582. $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";
  583. $gziprules .= "<IfModule mod_expires.c>\n ExpiresActive On\n ExpiresByType text/html A300\n</IfModule>\n";
  584. if( $dohtaccess && !$_POST[ 'updatehtaccess' ] ) {
  585. if( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) {
  586. 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>";
  587. echo "<p><pre># BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache</pre></p></div>";
  588. } else {
  589. 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 ) . " ";
  590. if( !function_exists( 'is_site_admin' ) ) {
  591. _e( "You must edit the file yourself add the following rules.", 'wp-super-cache' );
  592. } else {
  593. _e( "You can edit the file yourself add the following rules.", 'wp-super-cache' );
  594. }
  595. echo __( " Make sure they appear before any existing WordPress rules. ", 'wp-super-cache' ) . "</p>";
  596. echo "<pre># BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache</pre></p>";
  597. echo "<p>" . sprintf( __( 'Rules must be added to %s too:', 'wp-super-cache' ), WP_CONTENT_DIR . "/cache/.htaccess" ) . "</p>";
  598. echo "<pre># BEGIN supercache\n" . wp_specialchars( $gziprules ) . "# END supercache</pre></p>";
  599. if( !function_exists( 'is_site_admin' ) ) {
  600. echo '<form name="updatehtaccess" action="#modrewrite" method="post">';
  601. echo '<input type="hidden" name="updatehtaccess" value="1" />';
  602. echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'id="updatehtaccess" value="' . __( 'Update Mod_Rewrite Rules', 'wp-super-cache' ) . ' &raquo;" /></div>';
  603. wp_nonce_field('wp-cache');
  604. echo "</form></div>\n";
  605. }
  606. }
  607. } elseif( $dohtaccess && $valid_nonce && $_POST[ 'updatehtaccess' ] ) {
  608. wpsc_remove_marker( $home_path.'.htaccess', 'WordPress' ); // remove original WP rules so SuperCache rules go on top
  609. echo "<div style='padding:0 8px;color:#4f8a10;background-color:#dff2bf;border:1px solid #4f8a10;'>";
  610. if( insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', explode( "\n", $rules ) ) && insert_with_markers( $home_path.'.htaccess', 'WordPress', explode( "\n", $wprules ) ) ) {
  611. echo "<h4>" . __( 'Mod Rewrite rules updated!', 'wp-super-cache' ) . "</h4>";
  612. 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";
  613. } else {
  614. echo "<h4>" . __( 'Mod Rewrite rules must be updated!', 'wp-super-cache' ) . "</h4>";
  615. 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";
  616. }
  617. echo "<p><pre>" . wp_specialchars( $rules ) . "</pre></p>\n</div>";
  618. } else {
  619. ?>
  620. <p><?php printf( __( 'WP Super Cache mod rewrite rules were detected in your %s.htaccess file.<br /> Click the following link to see the lines added to that file. If you have upgraded the plugin make sure these rules match.', 'wp-super-cache' ), $home_path ); ?><br /><br />
  621. <a href="javascript:toggleLayer('rewriterules');" class="button"><?php _e( 'View Mod_Rewrite Rules', 'wp-super-cache' ); ?></a>
  622. <div id='rewriterules' style='display: none;'>
  623. <?php echo "<p><pre># BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache</pre></p>\n";
  624. echo "<p>" . sprintf( __( 'Rules must be added to %s too:', 'wp-super-cache' ), WP_CONTENT_DIR . "/cache/.htaccess" ) . "</p>";
  625. echo "<pre># BEGIN supercache\n" . wp_specialchars( $gziprules ) . "# END supercache</pre></p>"; ?>
  626. </div>
  627. <?php
  628. }
  629. // http://allmybrain.com/2007/11/08/making-wp-super-cache-gzip-compression-work/
  630. if( !is_file( $cache_path . '.htaccess' ) ) {
  631. $gziprules = insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $gziprules ) );
  632. echo "<h4>" . sprintf( __( 'Gzip encoding rules in %s.htaccess created.', 'wp-super-cache' ), $cache_path ) . "</h4>";
  633. }
  634. ?></fieldset><?php
  635. }
  636. function wp_cache_restore() {
  637. echo '<fieldset class="options"><h3>' . __( 'Fix Configuration', 'wp-super-cache' ) . '</h3>';
  638. echo '<form name="wp_restore" action="#top" method="post">';
  639. echo '<input type="hidden" name="wp_restore_config" />';
  640. echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'id="deletepost" value="' . __( 'Restore Default Configuration', 'wp-super-cache' ) . ' &raquo;" /></div>';
  641. wp_nonce_field('wp-cache');
  642. echo "</form>\n";
  643. echo '</fieldset>';
  644. }
  645. function comment_form_lockdown_message() {
  646. ?><p><?php _e( "Comment moderation is enabled. Your comment may take some time to appear.", 'wp-super-cache' ); ?></p><?php
  647. }
  648. if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) )
  649. add_action( 'comment_form', 'comment_form_lockdown_message' );
  650. function wp_lock_down() {
  651. global $wpdb, $cache_path, $wp_cache_config_file, $valid_nonce, $cached_direct_pages, $cache_enabled, $super_cache_enabled;
  652. if(isset($_POST['wp_lock_down']) && $valid_nonce) {
  653. $wp_lock_down = $_POST['wp_lock_down'] == '1' ? '1' : '0';
  654. wp_cache_replace_line('^.*WPLOCKDOWN', "define( 'WPLOCKDOWN', '$wp_lock_down' );", $wp_cache_config_file);
  655. if( $wp_lock_down == '0' && function_exists( 'prune_super_cache' ) )
  656. prune_super_cache( $cache_path, true ); // clear the cache after lockdown
  657. }
  658. if( !isset( $wp_lock_down ) ) {
  659. if( defined( 'WPLOCKDOWN' ) ) {
  660. $wp_lock_down = constant( 'WPLOCKDOWN' );
  661. } else {
  662. $wp_lock_down = '0';
  663. }
  664. }
  665. ?><a name='lockdown'></a>
  666. <fieldset class="options">
  667. <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>
  668. <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>
  669. <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' ); ?>
  670. <blockquote><code>if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) ) {
  671. &nbsp;&nbsp;&nbsp;&nbsp;echo "<?php _e( 'Sorry. My blog is locked down. Updates will appear shortly', 'wp-super-cache' ); ?>";
  672. }</code></blockquote>
  673. <?php
  674. if( $wp_lock_down == '1' ) {
  675. ?><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
  676. } else {
  677. ?><p><?php _e( 'WordPress is not locked down. New comments will refresh Super Cache static files as normal.', 'wp-super-cache' ); ?></p><?php
  678. }
  679. $new_lockdown = $wp_lock_down == '1' ? '0' : '1';
  680. $new_lockdown_desc = $wp_lock_down == '1' ? __( 'Disable', 'wp-super-cache' ) : __( 'Enable', 'wp-super-cache' );
  681. echo '<form name="wp_lock_down" action="#lockdown" method="post">';
  682. echo "<input type='hidden' name='wp_lock_down' value='{$new_lockdown}' />";
  683. echo "<div class='submit'><input type='submit' " . SUBMITDISABLED . " value='{$new_lockdown_desc} " . __( 'Lock Down', 'wp-super-cache' ) . " &raquo;' /></div>";
  684. wp_nonce_field('wp-cache');
  685. echo "</form>\n";
  686. ?></fieldset><?php
  687. if( $cache_enabled == true && $super_cache_enabled == true ) {
  688. ?><a name='direct'></a>
  689. <fieldset class="options">
  690. <h3><?php _e( 'Directly Cached Files', 'wp-super-cache' ); ?></h3><?php
  691. $out = '';
  692. if( $valid_nonce && is_array( $_POST[ 'direct_pages' ] ) && !empty( $_POST[ 'direct_pages' ] ) ) {
  693. $expiredfiles = array_diff( $cached_direct_pages, $_POST[ 'direct_pages' ] );
  694. unset( $cached_direct_pages );
  695. foreach( $_POST[ 'direct_pages' ] as $page ) {
  696. $page = $wpdb->escape( $page );
  697. if( $page != '' ) {
  698. $cached_direct_pages[] = $page;
  699. $out .= "'$page', ";
  700. }
  701. }
  702. if( $out == '' ) {
  703. $out = "'', ";
  704. }
  705. }
  706. if( $valid_nonce && $_POST[ 'new_direct_page' ] && '' != $_POST[ 'new_direct_page' ] ) {
  707. $page = str_replace( get_option( 'siteurl' ), '', $_POST[ 'new_direct_page' ] );
  708. if( substr( $page, 0, 1 ) != '/' )
  709. $page = '/' . $page;
  710. $page = $wpdb->escape( $page );
  711. if( in_array( $page, $cached_direct_pages ) == false ) {
  712. $cached_direct_pages[] = $page;
  713. $out .= "'$page', ";
  714. }
  715. }
  716. if( $out != '' ) {
  717. $out = substr( $out, 0, -2 );
  718. $out = '$cached_direct_pages = array( ' . $out . ' );';
  719. wp_cache_replace_line('^ *\$cached_direct_pages', "$out", $wp_cache_config_file);
  720. prune_super_cache( $cache_path, true );
  721. }
  722. if( !empty( $expiredfiles ) ) {
  723. foreach( $expiredfiles as $file ) {
  724. if( $file != '' ) {
  725. $firstfolder = explode( '/', $file );
  726. $firstfolder = ABSPATH . $firstfolder[1];
  727. $file = ABSPATH . $file;
  728. @unlink( trailingslashit( $file ) . 'index.html' );
  729. @unlink( trailingslashit( $file ) . 'index.html.gz' );
  730. RecursiveFolderDelete( trailingslashit( $firstfolder ) );
  731. }
  732. }
  733. }
  734. if( $valid_nonce && $_POST[ 'deletepage' ] ) {
  735. $page = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_POST['deletepage']) );
  736. $pagefile = ABSPATH . $page . 'index.html';
  737. $firstfolder = explode( '/', $page );
  738. $firstfolder = ABSPATH . $firstfolder[1];
  739. $page = ABSPATH . $page;
  740. if( is_file( $pagefile ) && is_writeable_ACLSafe( $pagefile ) && is_writeable_ACLSafe( $firstfolder ) ) {
  741. @unlink( $pagefile );
  742. @unlink( $pagefile . '.gz' );
  743. RecursiveFolderDelete( $firstfolder );
  744. echo "<strong>" . sprintf( __( '%s removed!', 'wp-super-cache' ), $pagefile ) . "</strong>";
  745. prune_super_cache( $cache_path, true );
  746. }
  747. }
  748. $readonly = '';
  749. if( !is_writeable_ACLSafe( ABSPATH ) ) {
  750. $readonly = 'READONLY';
  751. ?><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
  752. } else {
  753. ?><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
  754. }
  755. echo '<form name="direct_page" action="#direct" method="post">';
  756. if( is_array( $cached_direct_pages ) ) {
  757. $out = '';
  758. foreach( $cached_direct_pages as $page ) {
  759. if( $page == '' )
  760. continue;
  761. $generated = '';
  762. if( is_file( ABSPATH . $page . '/index.html' ) )
  763. $generated = '<input type="Submit" name="deletepage" value="' . $page . '">';
  764. $out .= "<tr><td><input type='text' $readonly name='direct_pages[]' size='30' value='$page' /></td><td>$generated</td></tr>";
  765. }
  766. if( $out != '' ) {
  767. ?><table><tr><th><?php _e( 'Existing direct page', 'wp-super-cache' ); ?></th><th><?php _e( 'Delete cached file', 'wp-super-cache' ); ?></th></tr><?php
  768. echo "$out</table>";
  769. }
  770. }
  771. if( $readonly != 'READONLY' )
  772. echo __( "Add direct page:", 'wp-super-cache' ) . "<input type='text' $readonly name='new_direct_page' size='30' value='' />";
  773. 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>";
  774. if( $readonly != 'READONLY' ) {
  775. 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>";
  776. echo "<p>" . __( 'Make the textbox blank to remove it from the list of direct pages and delete the cached file.', 'wp-super-cache' ) . "</p>";
  777. }
  778. wp_nonce_field('wp-cache');
  779. if( $readonly != 'READONLY' )
  780. echo "<div class='submit'><input type='submit' ' . SUBMITDISABLED . 'value='" . __( 'Update Direct Pages', 'wp-super-cache' ) . " &raquo;' /></div>";
  781. echo "</form>\n";
  782. ?></fieldset><?php
  783. } // if $super_cache_enabled
  784. }
  785. function RecursiveFolderDelete ( $folderPath ) { // from http://www.php.net/manual/en/function.rmdir.php
  786. if( trailingslashit( constant( 'ABSPATH' ) ) == trailingslashit( $folderPath ) )
  787. return false;
  788. if ( @is_dir ( $folderPath ) ) {
  789. $dh = @opendir($folderPath);
  790. while (false !== ($value = @readdir($dh))) {
  791. if ( $value != "." && $value != ".." ) {
  792. $value = $folderPath . "/" . $value;
  793. if ( @is_dir ( $value ) ) {
  794. RecursiveFolderDelete ( $value );
  795. }
  796. }
  797. }
  798. return @rmdir ( $folderPath );
  799. } else {
  800. return FALSE;
  801. }
  802. }
  803. function wp_cache_edit_max_time () {
  804. global $cache_max_time, $wp_cache_config_file, $valid_nonce, $cache_enabled, $super_cache_enabled;
  805. if( !isset( $cache_max_time ) )
  806. $cache_max_time = 3600;
  807. if(isset($_POST['wp_max_time']) && $valid_nonce) {
  808. $max_time = (int)$_POST['wp_max_time'];
  809. if ($max_time > 0) {
  810. $cache_max_time = $max_time;
  811. wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file);
  812. }
  813. }
  814. ?><fieldset class="options">
  815. <a name='expirytime'></a>
  816. <h3><?php _e( 'Expiry Time &amp; Garbage Collection', 'wp-super-cache' ); ?></h3><?php
  817. echo '<form name="wp_edit_max_time" action="#expirytime" method="post">';
  818. echo '<label for="wp_max_time">' . __( 'Expire time:', 'wp-super-cache' ) . '</label> ';
  819. echo "<input type=\"text\" size=6 name=\"wp_max_time\" value=\"$cache_max_time\" /> " . __( "seconds", 'wp-super-cache' );
  820. echo "<h4>" . __( 'Garbage Collection', 'wp-super-cache' ) . "</h4><p>" . __( 'If expiry time is more than 1800 seconds (half an hour), garbage collection will be done every 10 minutes, otherwise it will happen 10 seconds after the expiry time above.', 'wp-super-cache' ) . "</p>";
  821. echo "<p>" . __( 'Checking for and deleting expired files is expensive, but it&#8217;s expensive leaving them there too. On a very busy site you should set the expiry time to <em>300 seconds</em>. Experiment with different values and visit this page to see how many expired files remain at different times during the day. Aim to have less than 500 cached files if possible.', 'wp-super-cache' ) . "</p>";
  822. echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Change Expiration', 'wp-super-cache' ) . ' &raquo;" /></div>';
  823. wp_nonce_field('wp-cache');
  824. echo "</form>\n";
  825. ?></fieldset><?php
  826. }
  827. function wp_cache_sanitize_value($text, & $array) {
  828. $text = wp_specialchars(strip_tags($text));
  829. $array = preg_split("/[\s,]+/", chop($text));
  830. $text = var_export($array, true);
  831. $text = preg_replace('/[\s]+/', ' ', $text);
  832. return $text;
  833. }
  834. // from tehjosh at gamingg dot net http://uk2.php.net/manual/en/function.apache-request-headers.php#73964
  835. // fixed bug in second substr()
  836. if( !function_exists('apache_request_headers') ) {
  837. function apache_request_headers() {
  838. $headers = array();
  839. foreach(array_keys($_SERVER) as $skey) {
  840. if(substr($skey, 0, 5) == "HTTP_") {
  841. $headername = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($skey, 5)))));
  842. $headers[$headername] = $_SERVER[$skey];
  843. }
  844. }
  845. return $headers;
  846. }
  847. }
  848. function wp_cache_edit_rejected_ua() {
  849. global $cache_rejected_user_agent, $wp_cache_config_file, $valid_nonce;
  850. if (!function_exists('apache_request_headers')) return;
  851. if(isset($_REQUEST['wp_rejected_user_agent']) && $valid_nonce) {
  852. $text = wp_cache_sanitize_value($_REQUEST['wp_rejected_user_agent'], $cache_rejected_user_agent);
  853. wp_cache_replace_line('^ *\$cache_rejected_user_agent', "\$cache_rejected_user_agent = $text;", $wp_cache_config_file);
  854. }
  855. echo '<a name="useragents"></a><fieldset class="options"><h3>' . __( 'Rejected User Agents', 'wp-super-cache' ) . '</h3>';
  856. 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";
  857. echo '<form name="wp_edit_rejected_user_agent" action="#useragents" method="post">';
  858. echo '<textarea name="wp_rejected_user_agent" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
  859. foreach ($cache_rejected_user_agent as $ua) {
  860. echo wp_specialchars($ua) . "\n";
  861. }
  862. echo '</textarea> ';
  863. echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save UA Strings', 'wp-super-cache' ) . ' &raquo;" /></div>';
  864. wp_nonce_field('wp-cache');
  865. echo '</form>';
  866. echo "</fieldset>\n";
  867. }
  868. function wp_cache_edit_rejected_pages() {
  869. global $wp_cache_config_file, $valid_nonce, $wp_cache_pages;
  870. if ( isset( $_POST[ 'wp_edit_rejected_pages' ] ) && $valid_nonce ) {
  871. $pages = array( 'single', 'pages', 'archives', 'tag', 'frontpage', 'home', 'category', 'feed', 'search' );
  872. foreach( $pages as $page ) {
  873. if ( isset( $_POST[ 'wp_cache_pages' ][ $page ] ) ) {
  874. $value = 1;
  875. } else {
  876. $value = 0;
  877. }
  878. wp_cache_replace_line('^ *\$wp_cache_pages\[ "' . $page . '" \]', "\$wp_cache_pages[ \"{$page}\" ] = $value;", $wp_cache_config_file);
  879. $wp_cache_pages[ $page ] = $value;
  880. }
  881. }
  882. echo '<a name="rejectpages"></a>';
  883. 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>';
  884. echo '<form name="wp_edit_rejected_pages" action="#rejectpages" method="post">';
  885. echo '<input type="hidden" name="wp_edit_rejected_pages" value="1" />';
  886. 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 />';
  887. 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 />';
  888. 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 />';
  889. 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 />';
  890. 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 />';
  891. 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 />';
  892. 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 />';
  893. 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 />';
  894. 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 />';
  895. echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save' ) . ' &raquo;" /></div>';
  896. wp_nonce_field('wp-cache');
  897. echo "</form>\n";
  898. }
  899. function wp_cache_edit_rejected() {
  900. global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file, $valid_nonce;
  901. if(isset($_REQUEST['wp_rejected_uri']) && $valid_nonce) {
  902. $text = wp_cache_sanitize_value( str_replace( '\\\\', '\\', $_REQUEST['wp_rejected_uri'] ), $cache_rejected_uri );
  903. wp_cache_replace_line('^ *\$cache_rejected_uri', "\$cache_rejected_uri = $text;", $wp_cache_config_file);
  904. }
  905. echo '<a name="rejecturi"></a>';
  906. echo '<form name="wp_edit_rejected" action="#rejecturi" method="post">';
  907. 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";
  908. echo '<textarea name="wp_rejected_uri" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
  909. foreach ($cache_rejected_uri as $file) {
  910. echo wp_specialchars( $file ) . "\n";
  911. }
  912. echo '</textarea> ';
  913. echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save Strings', 'wp-super-cache' ) . ' &raquo;" /></div>';
  914. wp_nonce_field('wp-cache');
  915. echo "</form>\n";
  916. }
  917. function wp_cache_edit_accepted() {
  918. global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file, $valid_nonce;
  919. if(isset($_REQUEST['wp_accepted_files']) && $valid_nonce) {
  920. $text = wp_cache_sanitize_value($_REQUEST['wp_accepted_files'], $cache_acceptable_files);
  921. wp_cache_replace_line('^ *\$cache_acceptable_files', "\$cache_acceptable_files = $text;", $wp_cache_config_file);
  922. }
  923. echo '<a name="cancache"></a>';
  924. echo '<div style="clear:both"></div><form name="wp_edit_accepted" action="#cancache" method="post">';
  925. 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";
  926. echo '<textarea name="wp_accepted_files" cols="40" rows="8" style="width: 50%; font-size: 12px;" class="code">';
  927. foreach ($cache_acceptable_files as $file) {
  928. echo wp_specialchars($file) . "\n";
  929. }
  930. echo '</textarea> ';
  931. echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save Files', 'wp-super-cache' ) . ' &raquo;" /></div>';
  932. wp_nonce_field('wp-cache');
  933. echo "</form>\n";
  934. }
  935. function wp_cache_debug_settings() {
  936. global $wp_super_cache_debug, $wp_cache_debug_email, $wp_cache_debug_log, $wp_cache_debug_level, $wp_cache_debug_ip, $cache_path, $valid_nonce, $wp_cache_config_file, $wp_cache_debug_to_file;
  937. 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;
  938. if ( !isset( $wp_cache_debug_level ) )
  939. $wp_cache_debug_level = 1;
  940. if ( isset( $_POST[ 'wp_cache_debug' ] ) && $valid_nonce ) {
  941. $wp_super_cache_debug = intval( $_POST[ 'wp_super_cache_debug' ] );
  942. wp_cache_replace_line('^ *\$wp_super_cache_debug', "\$wp_super_cache_debug = '$wp_super_cache_debug';", $wp_cache_config_file);
  943. $wp_cache_debug_email = wp_specialchars( $_POST[ 'wp_cache_debug_email' ] );
  944. wp_cache_replace_line('^ *\$wp_cache_debug_email', "\$wp_cache_debug_email = '$wp_cache_debug_email';", $wp_cache_config_file);
  945. $wp_cache_debug_to_file = intval( $_POST[ 'wp_cache_debug_to_file' ] );
  946. if ( $wp_cache_debug_to_file && ( ( isset( $wp_cache_debug_log ) && $wp_cache_debug_log == '' ) || !isset( $wp_cache_debug_log ) ) ) {
  947. $wp_cache_debug_log = md5( time() ) . ".txt";
  948. } elseif( $wp_cache_debug_to_file == false ) {
  949. $wp_cache_debug_log = "";
  950. }
  951. wp_cache_replace_line('^ *\$wp_cache_debug_to_file', "\$wp_cache_debug_to_file = '$wp_cache_debug_to_file';", $wp_cache_config_file);
  952. wp_cache_replace_line('^ *\$wp_cache_debug_log', "\$wp_cache_debug_log = '$wp_cache_debug_log';", $wp_cache_config_file);
  953. $wp_cache_debug_ip = wp_specialchars( $_POST[ 'wp_cache_debug_ip' ] );
  954. wp_cache_replace_line('^ *\$wp_cache_debug_ip', "\$wp_cache_debug_ip = '$wp_cache_debug_ip';", $wp_cache_config_file);
  955. $wp_cache_debug_level = (int)$_POST[ 'wp_cache_debug_level' ];
  956. wp_cache_replace_line('^ *\$wp_cache_debug_level', "\$wp_cache_debug_level = '$wp_cache_debug_level';", $wp_cache_config_file);
  957. $wp_super_cache_front_page_check = (int)$_POST[ 'wp_super_cache_front_page_check' ];
  958. 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);
  959. $wp_super_cache_front_page_clear = (int)$_POST[ 'wp_super_cache_front_page_clear' ];
  960. 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);
  961. $wp_super_cache_front_page_text = wp_specialchars( $_POST[ 'wp_super_cache_front_page_text' ] );
  962. 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);
  963. $wp_super_cache_front_page_notification = (int)$_POST[ 'wp_super_cache_front_page_notification' ];
  964. 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);
  965. if ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 1 && !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
  966. wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
  967. 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 );
  968. }
  969. }
  970. echo '<a name="debug"></a>';
  971. echo '<fieldset class="options">';
  972. echo "<h3>" . __( 'Debug Settings', 'wp-super-cache' ) . "</h3>";
  973. if ( ( isset( $wp_cache_debug_log ) && $wp_cache_debug_log != '' ) || ( isset( $wp_cache_debug_email ) && $wp_cache_debug_email != '' ) ) {
  974. echo "<p>" . __( 'Currently logging to: ', 'wp-super-cache' );
  975. if ( isset( $wp_cache_debug_log ) && $wp_cache_debug_log != '' ) {
  976. $url = str_replace( ABSPATH, '', "{$cache_path}{$wp_cache_debug_log}" );
  977. echo "<a href='" . site_url( $url ) . "'>$cache_path{$wp_cache_debug_log}</a> ";
  978. }
  979. if ( isset( $wp_cache_debug_email ) )
  980. echo " $wp_cache_debug_email ";
  981. echo "</p>";
  982. }
  983. echo '<p>' . __( 'Fix problems with the plugin by debugging it here. It can send you debug emails or log them to a file in your cache directory.', 'wp-super-cache' ) . '</p>';
  984. echo '<p>' . __( 'Logging to a file is easier but faces the problem that clearing the cache will clear the log file.', 'wp-super-cache' ) . '</p>';
  985. echo '<div style="clear:both"></div><form name="wp_cache_debug" action="#debug" method="post">';
  986. echo "<input type='hidden' name='wp_cache_debug' value='1' /><br />";
  987. echo "<table class='form-table'>";
  988. 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>";
  989. echo "<tr><td valign='top' rowspan='2'>" . __( 'Logging Type', 'wp-super-cache' ) . "</td><td> " . __( 'Email', 'wp-super-cache' ) . ": <input type='text' size='30' name='wp_cache_debug_email' value='{$wp_cache_debug_email}' /></td></tr>";
  990. echo "<tr><td><input type='checkbox' name='wp_cache_debug_to_file' value='1' " . checked( 1, $wp_cache_debug_to_file, false ) . " /> " . __( 'file', 'wp-super-cache' ) . "</td></tr>";
  991. 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>";
  992. echo "<tr><td>" . __( 'Log level', 'wp-super-cache' ) . "</td><td> ";
  993. for( $t = 1; $t <= 5; $t++ ) {
  994. echo "<input type='radio' name='wp_cache_debug_level' value='$t' ";
  995. echo $wp_cache_debug_level == $t ? "checked='checked' " : '';
  996. echo "/> $t ";
  997. }
  998. echo " " . __( '(1 = less, 5 = more, may cause severe server load.)', 'wp-super-cache' ) . "</td></tr>";
  999. echo "</table>\n";
  1000. if ( isset( $wp_super_cache_advanced_debug ) ) {
  1001. 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>';
  1002. 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>";
  1003. echo "<table class='form-table'>";
  1004. 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>";
  1005. 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>";
  1006. 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>";
  1007. 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>";
  1008. echo "</table>\n";
  1009. }
  1010. echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save', 'wp-super-cache' ) . ' &raquo;" /></div>';
  1011. wp_nonce_field('wp-cache');
  1012. echo "</form>\n";
  1013. echo '</fieldset>';
  1014. }
  1015. function wp_cache_enable() {
  1016. global $wp_cache_config_file, $cache_enabled, $supercachedir;
  1017. if(get_option('gzipcompression')) {
  1018. echo "<strong>" . __( 'Error: GZIP compression is enabled, disable it if you want to enable wp-cache.', 'wp-super-cache' ) . "</strong>";
  1019. return false;
  1020. }
  1021. if( wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = true;', $wp_cache_config_file) ) {
  1022. $cache_enabled = true;
  1023. }
  1024. wp_super_cache_enable();
  1025. }
  1026. function wp_cache_disable() {
  1027. global $wp_cache_config_file, $cache_enabled;
  1028. if (wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file)) {
  1029. $cache_enabled = false;
  1030. }
  1031. wp_super_cache_disable();
  1032. }
  1033. function wp_super_cache_enable() {
  1034. global $supercachedir, $wp_cache_config_file, $super_cache_enabled;
  1035. if( is_dir( $supercachedir . ".disabled" ) )
  1036. if( is_dir( $supercachedir ) ) {
  1037. prune_super_cache( $supercachedir . ".disabled", true );
  1038. @unlink( $supercachedir . ".disabled" );
  1039. } else {
  1040. @rename( $supercachedir . ".disabled", $supercachedir );
  1041. }
  1042. wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = true;', $wp_cache_config_file);
  1043. $super_cache_enabled = true;
  1044. }
  1045. function wp_super_cache_disable() {
  1046. global $cache_path, $supercachedir, $wp_cache_config_file, $super_cache_enabled;
  1047. wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = false;', $wp_cache_config_file);
  1048. if( is_dir( $supercachedir ) )
  1049. @rename( $supercachedir, $supercachedir . ".disabled" );
  1050. $super_cache_enabled = false;
  1051. sleep( 1 ); // allow existing processes to write to the supercachedir and then delete it
  1052. if (function_exists ('prune_super_cache') && is_dir( $supercachedir ) ) {
  1053. prune_super_cache( $cache_path, true );
  1054. }
  1055. }
  1056. function wp_cache_is_enabled() {
  1057. global $wp_cache_config_file;
  1058. if(get_option('gzipcompression')) {
  1059. 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' );
  1060. return false;
  1061. }
  1062. $lines = file($wp_cache_config_file);
  1063. foreach($lines as $line) {
  1064. if (preg_match('/^ *\$cache_enabled *= *true *;/', $line))
  1065. return true;
  1066. }
  1067. return false;
  1068. }
  1069. function wp_cache_replace_line($old, $new, $my_file) {
  1070. if (!is_writeable_ACLSafe($my_file)) {
  1071. echo "Error: file $my_file is not writable.\n";
  1072. return false;
  1073. }
  1074. $found = false;
  1075. $lines = file($my_file);
  1076. foreach($lines as $line) {
  1077. if ( preg_match("/$old/", $line)) {
  1078. $found = true;
  1079. break;
  1080. }
  1081. }
  1082. if ($found) {
  1083. $fd = fopen($my_file, 'w');
  1084. foreach($lines as $line) {
  1085. if ( !preg_match("/$old/", $line))
  1086. fputs($fd, $line);
  1087. else {
  1088. fputs($fd, "$new //Added by WP-Cache Manager\n");
  1089. }
  1090. }
  1091. fclose($fd);
  1092. return true;
  1093. }
  1094. $fd = fopen($my_file, 'w');
  1095. $done = false;
  1096. foreach($lines as $line) {
  1097. if ( $done || !preg_match('/^(if\ \(\ \!\ )?define|\$|\?>/', $line) ) {
  1098. fputs($fd, $line);
  1099. } else {
  1100. fputs($fd, "$new //Added by WP-Cache Manager\n");
  1101. fputs($fd, $line);
  1102. $done = true;
  1103. }
  1104. }
  1105. fclose($fd);
  1106. return true;
  1107. }
  1108. function wp_cache_verify_cache_dir() {
  1109. global $cache_path, $blog_cache_dir, $blogcacheid;
  1110. $dir = dirname($cache_path);
  1111. if ( !file_exists($cache_path) ) {
  1112. if ( !is_writeable_ACLSafe( $dir ) || !($dir = mkdir( $cache_path ) ) ) {
  1113. 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 );
  1114. return false;
  1115. }
  1116. }
  1117. if ( !is_writeable_ACLSafe($cache_path)) {
  1118. 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 );
  1119. return false;
  1120. }
  1121. if ( '/' != substr($cache_path, -1)) {
  1122. $cache_path .= '/';
  1123. }
  1124. if( false == is_dir( $blog_cache_dir ) ) {
  1125. @mkdir( $cache_path . "blogs" );
  1126. if( $blog_cache_dir != $cache_path . "blogs/" )
  1127. @mkdir( $blog_cache_dir );
  1128. }
  1129. if( false == is_dir( $blog_cache_dir . 'meta' ) )
  1130. @mkdir( $blog_cache_dir . 'meta' );
  1131. return true;
  1132. }
  1133. function wp_cache_verify_config_file() {
  1134. global $wp_cache_config_file, $wp_cache_config_file_sample, $sem_id, $cache_path;
  1135. $new = false;
  1136. $dir = dirname($wp_cache_config_file);
  1137. if ( file_exists($wp_cache_config_file) ) {
  1138. $lines = join( ' ', file( $wp_cache_config_file ) );
  1139. if( strpos( $lines, 'WPCACHEHOME' ) === false ) {
  1140. if( is_writeable_ACLSafe( $wp_cache_config_file ) ) {
  1141. @unlink( $wp_cache_config_file );
  1142. } else {
  1143. 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 );
  1144. return false;
  1145. }
  1146. }
  1147. } elseif( !is_writeable_ACLSafe($dir)) {
  1148. 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 );
  1149. return false;
  1150. }
  1151. if ( !file_exists($wp_cache_config_file) ) {
  1152. if ( !file_exists($wp_cache_config_file_sample) ) {
  1153. 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 );
  1154. return false;
  1155. }
  1156. copy($wp_cache_config_file_sample, $wp_cache_config_file);
  1157. $dir = str_replace( str_replace( '\\', '/', WP_CONTENT_DIR ), '', str_replace( '\\', '/', dirname(__FILE__) ) );
  1158. if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
  1159. wp_cache_replace_line('define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/\" );", $wp_cache_config_file);
  1160. } elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
  1161. wp_cache_replace_line('define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/wp-super-cache/\" );", $wp_cache_config_file);
  1162. }
  1163. $new = true;
  1164. }
  1165. if( $sem_id == 5419 && $cache_path != '' ) {
  1166. $sem_id = crc32( $_SERVER[ 'HTTP_HOST' ] . $cache_path ) & 0x7fffffff;
  1167. wp_cache_replace_line('sem_id', '$sem_id = ' . $sem_id . ';', $wp_cache_config_file);
  1168. }
  1169. require($wp_cache_config_file);
  1170. return true;
  1171. }
  1172. function wp_cache_create_advanced_cache() {
  1173. global $wp_cache_link, $wp_cache_file;
  1174. $ret = true;
  1175. $file = file_get_contents( $wp_cache_file );
  1176. $file = str_replace( 'CACHEHOME', constant( 'WPCACHEHOME' ), $file );
  1177. $fp = @fopen( $wp_cache_link, 'w' );
  1178. if( $fp ) {
  1179. fputs( $fp, $file );
  1180. fclose( $fp );
  1181. } else {
  1182. $ret = false;
  1183. }
  1184. return $ret;
  1185. }
  1186. function wp_cache_check_link() {
  1187. global $wp_cache_link, $wp_cache_file;
  1188. $ret = true;
  1189. if( file_exists($wp_cache_link) ) {
  1190. $file = file_get_contents( $wp_cache_link );
  1191. if( strpos( $file, "WP SUPER CACHE 0.8.9.1" ) ) {
  1192. return true;
  1193. } else {
  1194. if( !@unlink($wp_cache_link) ) {
  1195. $ret = false;
  1196. } else {
  1197. $ret = wp_cache_create_advanced_cache();
  1198. }
  1199. }
  1200. } else {
  1201. $ret = wp_cache_create_advanced_cache();
  1202. }
  1203. if( false == $ret ) {
  1204. echo "<h3>" . __( 'Warning', 'wp-super-cache' ) . "! <em>" . sprintf( __( '%s/advanced-cache.php</em> does not exist or cannot be updated.', 'wp-super-cache' ), WP_CONTENT_DIR ) . "</h3>";
  1205. echo "<p><ul><li>" . __( '1. If it already exists please delete the file first.', 'wp-super-cache' ) . "</li>";
  1206. 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>";
  1207. echo "<li>" . sprintf( __( '3. Refresh this page to update <em>%s/advanced-cache.php</em>', 'wp-super-cache' ), WP_CONTENT_DIR ) . "</li></ul>";
  1208. 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>";
  1209. 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 );
  1210. return false;
  1211. }
  1212. return true;
  1213. }
  1214. function wp_cache_check_global_config() {
  1215. global $wp_cache_check_wp_config;
  1216. if ( !isset( $wp_cache_check_wp_config ) )
  1217. return true;
  1218. if ( file_exists( ABSPATH . 'wp-config.php') ) {
  1219. $global = ABSPATH . 'wp-config.php';
  1220. } else {
  1221. $global = dirname(ABSPATH) . '/wp-config.php';
  1222. }
  1223. $line = 'define(\'WP_CACHE\', true);';
  1224. if (!is_writeable_ACLSafe($global) || !wp_cache_replace_line('define *\( *\'WP_CACHE\'', $line, $global) ) {
  1225. 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>";;
  1226. 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>";
  1227. return false;
  1228. } else {
  1229. echo "<div style='border: 1px solid #333; background: #ffffaa; padding: 2px;'>" . __( '<h3>WP_CACHE constant added to wp-config.php</h3><p>If you continue to see this warning message please see point 5 of the <a href="http://wordpress.org/extend/plugins/wp-super-cache/faq/">FAQ</a>. The WP_CACHE line must be moved up.', 'wp-super-cache' ) . "</div>";
  1230. }
  1231. return true;
  1232. }
  1233. function wp_cache_files() {
  1234. global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled, $blog_cache_dir, $cache_compression;
  1235. global $wp_cache_object_cache;
  1236. if ( '/' != substr($cache_path, -1)) {
  1237. $cache_path .= '/';
  1238. }
  1239. if ( $valid_nonce ) {
  1240. if(isset($_REQUEST['wp_delete_cache'])) {
  1241. wp_cache_clean_cache($file_prefix);
  1242. }
  1243. if(isset($_REQUEST['wp_delete_expired'])) {
  1244. wp_cache_clean_expired($file_prefix);
  1245. }
  1246. }
  1247. echo "<a name='listfiles'></a>";
  1248. echo '<fieldset class="options" id="show-this-fieldset"><h3>' . __( 'Cache Contents', 'wp-super-cache' ) . '</h3>';
  1249. if ( $wp_cache_object_cache ) {
  1250. echo "<p>" . __( "Object cache in use. No cache listing available.", 'wp-super-cache' ) . "</p>";
  1251. wp_cache_delete_buttons();
  1252. echo "</fieldset>";
  1253. return false;
  1254. }
  1255. $list_files = false; // it doesn't list supercached files, and removing single pages is buggy
  1256. $count = 0;
  1257. $expired = 0;
  1258. $now = time();
  1259. if ( ($handle = @opendir( $blog_cache_dir . 'meta/' )) ) {
  1260. if ($list_files) echo "<table cellspacing=\"0\" cellpadding=\"5\">";
  1261. $wp_cache_fsize = 0;
  1262. if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletewpcache' ) {
  1263. $deleteuri = preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '/index.php', '/', str_replace( '..', '', preg_replace("/(\?.*)?$/", '', base64_decode( $_GET[ 'uri' ] ) ) ) ) );
  1264. $deleteuri = str_replace( '\\', '', $deleteuri );
  1265. } else {
  1266. $deleteuri = '';
  1267. }
  1268. if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletesupercache' ) {
  1269. $supercacheuri = preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '/index.php', '/', str_replace( '..', '', preg_replace("/(\?.*)?$/", '', base64_decode( $_GET[ 'uri' ] ) ) ) ) );
  1270. $supercacheuri = trailingslashit( str_replace( '\\', '', $supercacheuri ) );
  1271. printf( __( "Deleting supercache file: <strong>%s</strong><br />", 'wp-super-cache' ), $supercacheuri );
  1272. @unlink( $cache_path . 'supercache/' . $supercacheuri . 'index.html' );
  1273. @unlink( $cache_path . 'supercache/' . $supercacheuri . 'index.html.gz' );
  1274. prune_super_cache( $cache_path . 'supercache/' . $supercacheuri . 'page', true );
  1275. @rmdir( $cache_path . 'supercache/' . $supercacheuri );
  1276. }
  1277. while( false !== ($file = readdir($handle))) {
  1278. if ( preg_match("/^$file_prefix.*\.meta/", $file) ) {
  1279. $content_file = preg_replace("/meta$/", "html", $file);
  1280. $mtime = filemtime( $blog_cache_dir . 'meta/' . $file );
  1281. if ( ! ( $fsize = @filesize( $blog_cache_dir . $content_file ) ) )
  1282. continue; // .meta does not exists
  1283. $age = $now - $mtime;
  1284. if ( $valid_nonce && $_GET[ 'listfiles' ] ) {
  1285. $meta = unserialize( file_get_contents( $blog_cache_dir . 'meta/' . $file ) );
  1286. if ( $deleteuri != '' && $meta[ 'uri' ] == $deleteuri ) {
  1287. printf( __( "Deleting wp-cache file: <strong>%s</strong><br />", 'wp-super-cache' ), $deleteuri );
  1288. @unlink( $blog_cache_dir . 'meta/' . $file );
  1289. @unlink( $blog_cache_dir . $content_file );
  1290. continue;
  1291. }
  1292. $meta[ 'age' ] = $age;
  1293. if ( $age > $cache_max_time ) {
  1294. $expired_list[ $age ][] = $meta;
  1295. } else {
  1296. $cached_list[ $age ][] = $meta;
  1297. }
  1298. }
  1299. if ( $age > $cache_max_time ) {
  1300. $expired++;
  1301. } else {
  1302. $count++;
  1303. }
  1304. $wp_cache_fsize += $fsize;
  1305. $fsize = intval($fsize/1024);
  1306. }
  1307. }
  1308. closedir($handle);
  1309. if ($list_files) echo "</table>";
  1310. }
  1311. if( $wp_cache_fsize != 0 ) {
  1312. $wp_cache_fsize = $wp_cache_fsize/1024;
  1313. } else {
  1314. $wp_cache_fsize = 0;
  1315. }
  1316. if( $wp_cache_fsize > 1024 ) {
  1317. $wp_cache_fsize = number_format( $wp_cache_fsize / 1024, 2 ) . "MB";
  1318. } elseif( $wp_cache_fsize != 0 ) {
  1319. $wp_cache_fsize = number_format( $wp_cache_fsize, 2 ) . "KB";
  1320. } else {
  1321. $wp_cache_fsize = '0KB';
  1322. }
  1323. if( $cache_enabled == true && $super_cache_enabled == true ) {
  1324. $now = time();
  1325. $sizes = array( 'expired' => 0, 'expired_list' => array(), 'cached' => 0, 'cached_list' => array(), 'ts' => 0 );
  1326. if (is_dir($supercachedir)) {
  1327. if( $dh = opendir( $supercachedir ) ) {
  1328. while( ( $entry = readdir( $dh ) ) !== false ) {
  1329. if ($entry != '.' && $entry != '..') {
  1330. $sizes = wpsc_dirsize( trailingslashit( $supercachedir ) . $entry, $sizes );
  1331. }
  1332. }
  1333. closedir($dh);
  1334. }
  1335. } else {
  1336. $filem = @filemtime( $supercachedir );
  1337. if(is_file($supercachedir) && $filem + $cache_max_time <= $now ) {
  1338. $sizes[ 'expired' ] ++;
  1339. if ( $valid_nonce && $_GET[ 'listfiles' ] )
  1340. $sizes[ 'expired_list' ][ str_replace( $cache_path . 'supercache/' , '', $supercachedir ) ] = $now - $filem;
  1341. } else {
  1342. if ( $valid_nonce && $_GET[ 'listfiles' ] && $filem )
  1343. $sizes[ 'cached_list' ][ str_replace( $cache_path . 'supercache/' , '', $supercachedir ) ] = $now - $filem;
  1344. }
  1345. }
  1346. $sizes[ 'ts' ] = time();
  1347. }
  1348. echo "<p><strong>" . __( 'WP-Cache', 'wp-super-cache' ) . " ({$wp_cache_fsize})</strong></p>";
  1349. echo "<ul><li>" . sprintf( __( '%s Cached Pages', 'wp-super-cache' ), $count ) . "</li>";
  1350. echo "<li>" . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), $expired ) . "</li></ul>";
  1351. if( $cache_enabled == true && $super_cache_enabled == true ) {
  1352. $fsize = $sizes[ 'fsize' ] / 1024;
  1353. if( $fsize > 1024 ) {
  1354. $fsize = number_format( $fsize / 1024, 2 ) . "MB";
  1355. } elseif( $fsize != 0 ) {
  1356. $fsize = number_format( $fsize, 2 ) . "KB";
  1357. } else {
  1358. $fsize = "0KB";
  1359. }
  1360. $divisor = $cache_compression == 1 ? 2 : 1;
  1361. echo "<p><strong>" . __( 'WP-Super-Cache', 'wp-super-cache' ) . " ({$fsize})</strong></p>";
  1362. echo "<ul><li>" . sprintf( __( '%s Cached Pages', 'wp-super-cache' ), intval( $sizes[ 'cached' ] / $divisor ) ) . "</li>";
  1363. $age = intval(($now - $sizes['ts'])/60);
  1364. echo "<li>" . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), intval( $sizes[ 'expired' ] / $divisor ) ) . "</li></ul>";
  1365. }
  1366. if ( $valid_nonce && $_GET[ 'listfiles' ] ) {
  1367. echo "<div style='padding: 10px; border: 1px solid #333; height: 400px; width: 70%; overflow: auto'>";
  1368. if ( is_array( $cached_list ) && !empty( $cached_list ) ) {
  1369. echo "<h4>" . __( 'Fresh WP-Cached Files', 'wp-super-cache' ) . "</h4>";
  1370. 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>";
  1371. $c = 1;
  1372. $flip = 1;
  1373. ksort( $cached_list );
  1374. foreach( $cached_list as $age => $d ) {
  1375. foreach( $d as $details ) {
  1376. $bg = $flip ? 'style="background: #EAEAEA;"' : '';
  1377. 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";
  1378. $flip = !$flip;
  1379. $c++;
  1380. }
  1381. }
  1382. echo "</table>";
  1383. }
  1384. if ( is_array( $expired_list ) && !empty( $expired_list ) ) {
  1385. echo "<h4>" . __( 'Stale WP-Cached Files', 'wp-super-cache' ) . "</h4>";
  1386. 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>";
  1387. $c = 1;
  1388. $flip = 1;
  1389. ksort( $expired_list );
  1390. foreach( $expired_list as $age => $d ) {
  1391. foreach( $d as $details ) {
  1392. $bg = $flip ? 'style="background: #EAEAEA;"' : '';
  1393. 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";
  1394. $flip = !$flip;
  1395. $c++;
  1396. }
  1397. }
  1398. echo "</table>";
  1399. }
  1400. if ( is_array( $sizes[ 'cached_list' ] ) & !empty( $sizes[ 'cached_list' ] ) ) {
  1401. echo "<h4>" . __( 'Fresh Super Cached Files', 'wp-super-cache' ) . "</h4>";
  1402. 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>";
  1403. $c = 1;
  1404. $flip = 1;
  1405. ksort( $sizes[ 'cached_list' ] );
  1406. foreach( $sizes[ 'cached_list' ] as $age => $d ) {
  1407. foreach( $d as $uri => $n ) {
  1408. $bg = $flip ? 'style="background: #EAEAEA;"' : '';
  1409. 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";
  1410. $flip = !$flip;
  1411. $c++;
  1412. }
  1413. }
  1414. echo "</table>";
  1415. }
  1416. if ( is_array( $sizes[ 'expired_list' ] ) && !empty( $sizes[ 'expired_list' ] ) ) {
  1417. echo "<h4>" . __( 'Stale Super Cached Files', 'wp-super-cache' ) . "</h4>";
  1418. 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>";
  1419. $c = 1;
  1420. $flip = 1;
  1421. ksort( $sizes[ 'expired_list' ] );
  1422. foreach( $sizes[ 'expired_list' ] as $age => $d ) {
  1423. foreach( $d as $uri => $n ) {
  1424. $bg = $flip ? 'style="background: #EAEAEA;"' : '';
  1425. 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";
  1426. $flip = !$flip;
  1427. $c++;
  1428. }
  1429. }
  1430. echo "</table>";
  1431. }
  1432. echo "</div>";
  1433. echo "<p><a href='?page=wpsupercache#top'>" . __( 'Hide file list', 'wp-super-cache' ) . "</a></p>";
  1434. } else {
  1435. 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>";
  1436. }
  1437. $last_gc = get_option( "wpsupercache_gc_time" );
  1438. if( $last_gc ) {
  1439. $next_gc = $cache_max_time < 1800 ? $cache_max_time : 600;
  1440. $next_gc_mins = ( time() - $last_gc );
  1441. 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 ) );
  1442. printf( __( "Next GC in <strong>%s</strong> minutes", 'wp-super-cache' ), date( 'i:s', $next_gc - $next_gc_mins ) ) . "</p>";
  1443. }
  1444. 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>";
  1445. wp_cache_delete_buttons();
  1446. echo '</fieldset>';
  1447. }
  1448. function wp_cache_delete_buttons() {
  1449. echo '<form name="wp_cache_content_expired" action="#listfiles" method="post">';
  1450. echo '<input type="hidden" name="wp_delete_expired" />';
  1451. echo '<div class="submit" style="float:left"><input type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Expired', 'wp-super-cache' ) . ' &raquo;" /></div>';
  1452. wp_nonce_field('wp-cache');
  1453. echo "</form>\n";
  1454. echo '<form name="wp_cache_content_delete" action="#listfiles" method="post">';
  1455. echo '<input type="hidden" name="wp_delete_cache" />';
  1456. echo '<div class="submit" style="float:left;margin-left:10px"><input id="deletepost" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Cache', 'wp-super-cache' ) . ' &raquo;" /></div>';
  1457. wp_nonce_field('wp-cache');
  1458. echo "</form>\n";
  1459. }
  1460. function delete_cache_dashboard() {
  1461. if( function_exists( 'is_site_admin' ) && !is_site_admin() )
  1462. return false;
  1463. if( function_exists('current_user_can') && !current_user_can('manage_options') )
  1464. return false;
  1465. 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>";
  1466. }
  1467. add_action( 'dashmenu', 'delete_cache_dashboard' );
  1468. function wpsc_dirsize($directory, $sizes) {
  1469. global $cache_max_time, $cache_path, $valid_nonce;
  1470. $now = time();
  1471. if (is_dir($directory)) {
  1472. if( $dh = opendir( $directory ) ) {
  1473. while( ( $entry = readdir( $dh ) ) !== false ) {
  1474. if ($entry != '.' && $entry != '..') {
  1475. $sizes = wpsc_dirsize( trailingslashit( $directory ) . $entry, $sizes );
  1476. }
  1477. }
  1478. closedir($dh);
  1479. }
  1480. } else {
  1481. if(is_file($directory) ) {
  1482. $filem = filemtime( $directory );
  1483. if( $filem + $cache_max_time <= $now ) {
  1484. $sizes[ 'expired' ]+=1;
  1485. if ( $valid_nonce && $_GET[ 'listfiles' ] )
  1486. $sizes[ 'expired_list' ][ $now - $filem ][ str_replace( $cache_path . 'supercache/' , '', str_replace( 'index.html', '', str_replace( 'index.html.gz', '', $directory ) ) ) ] = 1;
  1487. } else {
  1488. $sizes[ 'cached' ]+=1;
  1489. if ( $valid_nonce && $_GET[ 'listfiles' ] )
  1490. $sizes[ 'cached_list' ][ $now - $filem ][ str_replace( $cache_path . 'supercache/' , '', str_replace( 'index.html', '', str_replace( 'index.html.gz', '', $directory ) ) ) ] = 1;
  1491. }
  1492. if ( ! isset( $sizes[ 'fsize' ] ) )
  1493. $sizes[ 'fsize' ] = @filesize( $directory );
  1494. else
  1495. $sizes[ 'fsize' ] += @filesize( $directory );
  1496. }
  1497. }
  1498. return $sizes;
  1499. }
  1500. function wp_cache_clean_cache($file_prefix) {
  1501. global $cache_path, $supercachedir, $blog_cache_dir, $wp_cache_object_cache;
  1502. if ( $wp_cache_object_cache && function_exists( "reset_oc_version" ) )
  1503. reset_oc_version();
  1504. // If phase2 was compiled, use its function to avoid race-conditions
  1505. if(function_exists('wp_cache_phase2_clean_cache')) {
  1506. if (function_exists ('prune_super_cache')) {
  1507. if( is_dir( $supercachedir ) ) {
  1508. prune_super_cache( $supercachedir, true );
  1509. } elseif( is_dir( $supercachedir . '.disabled' ) ) {
  1510. prune_super_cache( $supercachedir . '.disabled', true );
  1511. }
  1512. prune_super_cache( $cache_path, true );
  1513. $_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
  1514. } 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 );
  1515. return wp_cache_phase2_clean_cache($file_prefix);
  1516. } 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 );
  1517. $expr = "/^$file_prefix/";
  1518. if ( ($handle = @opendir( $blog_cache_dir )) ) {
  1519. while ( false !== ($file = readdir($handle))) {
  1520. if ( preg_match($expr, $file) ) {
  1521. @unlink( $blog_cache_dir . $file);
  1522. @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
  1523. }
  1524. }
  1525. closedir($handle);
  1526. }
  1527. }
  1528. function wp_cache_clean_expired($file_prefix) {
  1529. global $cache_path, $cache_max_time, $blog_cache_dir;
  1530. // If phase2 was compiled, use its function to avoid race-conditions
  1531. if(function_exists('wp_cache_phase2_clean_expired')) {
  1532. if (function_exists ('prune_super_cache')) {
  1533. $dir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]);
  1534. if( is_dir( $dir ) ) {
  1535. prune_super_cache( $dir );
  1536. } elseif( is_dir( $dir . '.disabled' ) ) {
  1537. prune_super_cache( $dir . '.disabled' );
  1538. }
  1539. $_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
  1540. }
  1541. return wp_cache_phase2_clean_expired($file_prefix);
  1542. }
  1543. $expr = "/^$file_prefix/";
  1544. $now = time();
  1545. if ( ($handle = @opendir( $blog_cache_dir )) ) {
  1546. while ( false !== ($file = readdir($handle))) {
  1547. if ( preg_match( $expr, $file ) &&
  1548. ( filemtime( $blog_cache_dir . $file ) + $cache_max_time ) <= $now ) {
  1549. @unlink( $blog_cache_dir . $file );
  1550. @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
  1551. }
  1552. }
  1553. closedir($handle);
  1554. }
  1555. }
  1556. function wpsc_remove_marker( $filename, $marker ) {
  1557. if (!file_exists( $filename ) || is_writeable_ACLSafe( $filename ) ) {
  1558. if (!file_exists( $filename ) ) {
  1559. return '';
  1560. } else {
  1561. $markerdata = explode( "\n", implode( '', file( $filename ) ) );
  1562. }
  1563. $f = fopen( $filename, 'w' );
  1564. $foundit = false;
  1565. if ( $markerdata ) {
  1566. $state = true;
  1567. foreach ( $markerdata as $n => $markerline ) {
  1568. if (strpos($markerline, '# BEGIN ' . $marker) !== false)
  1569. $state = false;
  1570. if ( $state ) {
  1571. if ( $n + 1 < count( $markerdata ) )
  1572. fwrite( $f, "{$markerline}\n" );
  1573. else
  1574. fwrite( $f, "{$markerline}" );
  1575. }
  1576. if (strpos($markerline, '# END ' . $marker) !== false) {
  1577. $state = true;
  1578. }
  1579. }
  1580. }
  1581. return true;
  1582. } else {
  1583. return false;
  1584. }
  1585. }
  1586. function wp_super_cache_footer() {
  1587. ?><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
  1588. }
  1589. if( isset( $wp_cache_hello_world ) && $wp_cache_hello_world )
  1590. add_action( 'wp_footer', 'wp_super_cache_footer' );
  1591. if( get_option( 'gzipcompression' ) )
  1592. update_option( 'gzipcompression', 0 );
  1593. // Catch 404 requests. Themes that use query_posts() destroy $wp_query->is_404
  1594. function wp_cache_catch_404() {
  1595. global $wp_cache_404;
  1596. $wp_cache_404 = false;
  1597. if( is_404() )
  1598. $wp_cache_404 = true;
  1599. }
  1600. add_action( 'template_redirect', 'wp_cache_catch_404' );
  1601. function wp_cache_favorite_action( $actions ) {
  1602. if( function_exists( 'is_site_admin' ) && !is_site_admin() )
  1603. return $actions;
  1604. if( function_exists('current_user_can') && !current_user_can('manage_options') )
  1605. return $actions;
  1606. $actions[ wp_nonce_url( 'options-general.php?page=wpsupercache&wp_delete_cache=1', 'wp-cache' ) ] = array( __( 'Delete Cache', 'wp-super-cache' ), 'manage_options' );
  1607. return $actions;
  1608. }
  1609. add_filter( 'favorite_actions', 'wp_cache_favorite_action' );
  1610. function wp_cache_plugin_notice( $plugin ) {
  1611. global $cache_enabled;
  1612. if( $plugin == 'wp-super-cache/wp-cache.php' && !$cache_enabled && function_exists( "admin_url" ) )
  1613. 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>';
  1614. }
  1615. add_action( 'after_plugin_row', 'wp_cache_plugin_notice' );
  1616. function wp_cache_plugin_actions( $links, $file ) {
  1617. if( $file == 'wp-super-cache/wp-cache.php' && function_exists( "admin_url" ) ) {
  1618. $settings_link = '<a href="' . admin_url( 'options-general.php?page=wpsupercache' ) . '">' . __('Settings') . '</a>';
  1619. array_unshift( $links, $settings_link ); // before other links
  1620. }
  1621. return $links;
  1622. }
  1623. add_filter( 'plugin_action_links', 'wp_cache_plugin_actions', 10, 2 );
  1624. function wp_cache_admin_notice() {
  1625. global $cache_enabled;
  1626. if( substr( $_SERVER["PHP_SELF"], -11 ) == 'plugins.php' && !$cache_enabled && function_exists( "admin_url" ) )
  1627. 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>';
  1628. }
  1629. add_action( 'admin_notices', 'wp_cache_admin_notice' );
  1630. function wp_cache_check_site() {
  1631. 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;
  1632. if ( !isset( $wp_super_cache_front_page_check ) || ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 0 ) ) {
  1633. return false;
  1634. }
  1635. if ( function_exists( "wp_remote_get" ) == false ) {
  1636. return false;
  1637. }
  1638. $front_page = wp_remote_get( site_url(), array('timeout' => 60, 'blocking' => true ) );
  1639. if( is_array( $front_page ) ) {
  1640. // Check for gzipped front page
  1641. if ( $front_page[ 'headers' ][ 'content-type' ] == 'application/x-gzip' ) {
  1642. if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) {
  1643. 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" ) );
  1644. } else {
  1645. wp_cache_clear_cache();
  1646. 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" ) );
  1647. }
  1648. }
  1649. // Check for broken front page
  1650. 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 ) ) {
  1651. if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) {
  1652. 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 ) );
  1653. } else {
  1654. wp_cache_clear_cache();
  1655. 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 ) );
  1656. }
  1657. }
  1658. }
  1659. if ( isset( $wp_super_cache_front_page_notification ) && $wp_super_cache_front_page_notification == 1 ) {
  1660. 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 ) );
  1661. }
  1662. if ( !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
  1663. wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
  1664. 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 );
  1665. }
  1666. }
  1667. add_action( 'wp_cache_check_site_hook', 'wp_cache_check_site' );
  1668. ?>