PageRenderTime 53ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/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

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

  1. <?php
  2. /*
  3. Plugin Name: WP Super Cache
  4. Plugin URI: http://ocaoimh.ie/wp-super-cache/
  5. Description: Very fast caching plugin for WordPress.
  6. Version: 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><?p

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