PluginProbe ʕ •ᴥ•ʔ
WP Super Cache / 0.9.6.1
WP Super Cache v0.9.6.1
3.1.1 trunk 0.1 0.2 0.3 0.3.1 0.4 0.5 0.5.1 0.5.2 0.5.3 0.6.2 0.6.3 0.6.4 0.6.5 0.6.6 0.6.7 0.6.8 0.7 0.7.1 0.8 0.8.1 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.8.8 0.8.9 0.9 0.9.1 0.9.2 0.9.3 0.9.3.1 0.9.4 0.9.4.1 0.9.4.2 0.9.4.3 0.9.5 0.9.6 0.9.6.1 0.9.7 0.9.8 0.9.9 0.9.9.1 0.9.9.2 0.9.9.3 0.9.9.4 0.9.9.5 0.9.9.6 0.9.9.7 0.9.9.8 0.9.9.9 1.0 1.0.1 1.1 1.1.1 1.10.0 1.11.0 1.12.0 1.12.1 1.12.2 1.12.3 1.12.4 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.7.1 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8 1.9 1.9.1 1.9.2 1.9.3 1.9.4 2.0.0 2.0.1 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0
wp-super-cache / wp-cache.php
wp-super-cache Last commit date
plugins 17 years ago Changelog.txt 16 years ago advanced-cache.php 17 years ago readme.txt 16 years ago uninstall.php 16 years ago wp-cache-base.php 18 years ago wp-cache-config-sample.php 16 years ago wp-cache-phase1.php 16 years ago wp-cache-phase2.php 16 years ago wp-cache.php 16 years ago
wp-cache.php
1517 lines
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.6.1
7 Author: Donncha O Caoimh
8 Author URI: http://ocaoimh.ie/
9 */
10
11 /* Copyright 2005-2006 Ricardo Galli Granada (email : gallir@uib.es)
12 Some code copyright 2007-2008 Donncha O Caoimh (http://ocaoimh.ie/)
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 */
28
29 // Pre-2.6 compatibility
30 if( !defined('WP_CONTENT_URL') )
31 define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
32 if( !defined('WP_CONTENT_DIR') )
33 define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
34
35 $wp_cache_config_file = WP_CONTENT_DIR . '/wp-cache-config.php';
36
37 if( !@include($wp_cache_config_file) ) {
38 get_wpcachehome();
39 $wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
40 @include($wp_cache_config_file_sample);
41 } else {
42 get_wpcachehome();
43 }
44
45 $wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
46 $wp_cache_link = WP_CONTENT_DIR . '/advanced-cache.php';
47 $wp_cache_file = WPCACHEHOME . 'advanced-cache.php';
48
49 include(WPCACHEHOME . 'wp-cache-base.php');
50
51
52 // from legolas558 d0t users dot sf dot net at http://www.php.net/is_writable
53 function is_writeable_ACLSafe($path) {
54
55 // PHP's is_writable does not work with Win32 NTFS
56
57 if ($path{strlen($path)-1}=='/') // recursively return a temporary file path
58 return is_writeable_ACLSafe($path.uniqid(mt_rand()).'.tmp');
59 else if (is_dir($path))
60 return is_writeable_ACLSafe($path.'/'.uniqid(mt_rand()).'.tmp');
61 // check tmp file for read/write capabilities
62 $rm = file_exists($path);
63 $f = @fopen($path, 'a');
64 if ($f===false)
65 return false;
66 fclose($f);
67 if (!$rm)
68 unlink($path);
69 return true;
70 }
71
72 function get_wpcachehome() {
73 if( defined( 'WPCACHEHOME' ) == false ) {
74 if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
75 define( 'WPCACHEHOME', trailingslashit( dirname(__FILE__) ) );
76 } elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
77 define( 'WPCACHEHOME', dirname(__FILE__) . '/wp-super-cache/' );
78 } else {
79 die( 'Please create ' . WP_CONTENT_DIR . '/wp-cache-config.php from wp-super-cache/wp-cache-config-sample.php' );
80 }
81 }
82 }
83
84 function wpsupercache_deactivate() {
85 global $wp_cache_config_file, $wp_cache_link, $cache_path;
86 $files = array( $wp_cache_config_file, $wp_cache_link );
87 foreach( $files as $file ) {
88 if( file_exists( $file ) )
89 unlink( $file );
90 }
91 if( !function_exists( 'prune_super_cache' ) )
92 include_once( 'wp-cache-phase2.php' );
93 prune_super_cache ($cache_path, true);
94 @unlink( $cache_path . '.htaccess' );
95 @unlink( $cache_path . 'meta' );
96 @unlink( $cache_path . 'supercache' );
97 }
98 register_deactivation_hook( __FILE__, 'wpsupercache_deactivate' );
99
100 function wp_cache_add_pages() {
101 if( function_exists( 'is_site_admin' ) ) {
102 if( is_site_admin() ) {
103 add_submenu_page('wpmu-admin.php', __('WP Super Cache'), __('WP Super Cache'), 'manage_options', 'wpsupercache', 'wp_cache_manager');
104 add_options_page('WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
105 }
106 } else {
107 add_options_page('WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager');
108 }
109 }
110 add_action('admin_menu', 'wp_cache_add_pages');
111
112 function wp_cache_manager() {
113 global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled, $wp_cache_hello_world;
114 global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_mobile_enabled, $wp_cache_mobile_whitelist, $wp_cache_mobile_browsers;
115 global $wp_cache_cron_check, $wp_cache_debug, $wp_cache_hide_donation, $wp_cache_not_logged_in;
116
117 if( function_exists( 'is_site_admin' ) )
118 if( !is_site_admin() )
119 return;
120
121 $supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]);
122 if( get_option( 'gzipcompression' ) == 1 )
123 update_option( 'gzipcompression', 0 );
124 if( !isset( $cache_rebuild_files ) )
125 $cache_rebuild_files = 0;
126
127 $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
128 /* http://www.netlobo.com/div_hiding.html */
129 ?>
130 <script type='text/javascript'>
131 <!--
132 function toggleLayer( whichLayer ) {
133 var elem, vis;
134 if( document.getElementById ) // this is the way the standards work
135 elem = document.getElementById( whichLayer );
136 else if( document.all ) // this is the way old msie versions work
137 elem = document.all[whichLayer];
138 else if( document.layers ) // this is the way nn4 works
139 elem = document.layers[whichLayer];
140 vis = elem.style;
141 // if the style.display value is blank we try to figure it out here
142 if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
143 vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
144 vis.display = (vis.display==''||vis.display=='block')?'none':'block';
145 }
146 // -->
147 //Clicking header opens fieldset options
148 jQuery(document).ready(function(){
149 jQuery("fieldset h3").css("cursor","pointer").click(function(){
150 jQuery(this).parent("fieldset").find("p,form,ul,blockquote").toggle("slow");
151 });
152 });
153 </script>
154 <?php
155 echo '<div class="wrap">';
156 echo "<h2>WP Super Cache Manager</h2>\n";
157 if( ini_get( 'safe_mode' ) ) {
158 ?><h3>Warning! PHP Safe Mode Enabled!</h3>
159 <p>You may experience problems running this plugin because SAFE MODE is enabled. <?php
160 if( !ini_get( 'safe_mode_gid' ) ) {
161 ?>Your server is set up to check the owner of PHP scripts before allowing them to read and write files.</p><p>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 <?php echo WP_CONTENT_DIR; ?>/cache/ directory must also be changed. See the <a href='http://php.net/features.safe-mode'>safe mode manual page</a> for further details.</p><?php
162 } else {
163 ?>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.</p><?php
164 }
165 }
166 if(isset($_REQUEST['wp_restore_config']) && $valid_nonce) {
167 unlink($wp_cache_config_file);
168 echo '<strong>Configuration file changed, some values might be wrong. Load the page again from the "Settings" menu to reset them.</strong>';
169 }
170
171 if ( !wp_cache_check_link() ||
172 !wp_cache_verify_config_file() ||
173 !wp_cache_verify_cache_dir() ) {
174 echo "Cannot continue... fix previous problems and retry.";
175 echo "</div>\n";
176 return;
177 }
178
179 if (!wp_cache_check_global_config()) {
180 echo "</div>\n";
181 return;
182 }
183 if( $wp_cache_debug || !$wp_cache_cron_check ) {
184 if( function_exists( "wp_remote_get" ) == false ) {
185 $hostname = str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'siteurl' ) ) );
186 if( strpos( $hostname, '/' ) )
187 $hostname = substr( $hostname, 0, strpos( $hostname, '/' ) );
188 $ip = gethostbyname( $hostname );
189 if( substr( $ip, 0, 3 ) == '127' || substr( $ip, 0, 7 ) == '192.168' ) {
190 ?><h3>Warning! Your hostname "<?php echo $hostname; ?>" resolves to <?php echo $ip; ?></h3>
191 <div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'>
192 <p>Your server thinks your hostname resolves to <?php echo $ip; ?>. Some services such as garbage collection by this plugin, and WordPress scheduled posts may not operate correctly.</p>
193 <p>Please see entry 16 in the <a href="http://wordpress.org/extend/plugins/wp-super-cache/faq/">Troubleshooting section</a> of the readme.txt</p>
194 </div>
195 <?php
196 } else {
197 wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
198 }
199 } else {
200 $cron_url = get_option( 'siteurl' ) . '/wp-cron.php?check=' . wp_hash('187425');
201 $cron = wp_remote_get($cron_url, array('timeout' => 0.01, 'blocking' => true));
202 if( is_array( $cron ) ) {
203 if( $cron[ 'response' ][ 'code' ] == '404' ) {
204 ?><h3>Warning! wp-cron.php not found!</h3>
205 <div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'>
206 <p>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.</p>
207 <p>Please see entry 16 in the <a href="http://wordpress.org/extend/plugins/wp-super-cache/faq/">Troubleshooting section</a> of the readme.txt</p>
208 </div>
209 <?php
210 } else {
211 wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
212 }
213 }
214 }
215 }
216
217 if( $cache_enabled == true && $super_cache_enabled == true && !got_mod_rewrite() ) {
218 ?><h4 style='color: #a00'>Mod rewrite may not be installed!</h4>
219 <p>It appears that mod_rewrite is not installed. Sometimes this check isn'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 WP-Cache.</p><?php
220 }
221
222 if( !is_writeable_ACLSafe($wp_cache_config_file) ) {
223 define( "SUBMITDISABLED", 'disabled style="color: #aaa" ' );
224 ?><h4 style='text-align:center; color: #a00'>Read Only Mode. Configuration cannot be changed. <a href="javascript:toggleLayer('readonlywarning');" title="Why your configuration may not be changed">Why</a></h4>
225 <div id='readonlywarning' style='border: 1px solid #aaa; margin: 2px; padding: 2px; display: none;'>
226 <p>The WP Super Cache configuration file is <code><?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code> and cannot be modified. The file <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php must be writeable by the webserver to make any changes.
227 A simple way of doing that is by changing the permissions temporarily using the CHMOD command or through your ftp client. Make sure it's globally writeable and it should be fine.
228 Writeable: <code>chmod 666 <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code>
229 Readonly: <code>chmod 644 <?php echo WP_CONTENT_DIR; ?>/wp-cache-config.php</code></p>
230 </div><?php
231 } else {
232 define( "SUBMITDISABLED", ' ' );
233 }
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'>Warning! <?php echo WP_CONTENT_DIR; ?> is writeable!</h4>
242 <p>You should change the permissions on <?php echo WP_CONTENT_DIR; ?> and make it more restrictive. Use your ftp client, or the following command to fix things:<code>chmod 755 <?php echo WP_CONTENT_DIR; ?>/</code></p><?php
243 }
244 }
245
246 if ( $valid_nonce ) {
247 if( isset( $_POST[ 'wp_cache_status' ] ) ) {
248 if( isset( $_POST[ 'wp_cache_mobile_enabled' ] ) ) {
249 $wp_cache_mobile_enabled = 1;
250 } else {
251 $wp_cache_mobile_enabled = 0;
252 }
253 if( $wp_cache_mobile_enabled == 1 ) {
254 if( !isset( $wp_cache_mobile_whitelist ) )
255 wp_cache_replace_line('^ *\$wp_cache_mobile_whitelist', "\$wp_cache_mobile_whitelist = 'Stand Alone/QNws';", $wp_cache_config_file);
256 if( false == isset( $wp_cache_mobile_browsers ) )
257 wp_cache_replace_line('^ *\$wp_cache_mobile_browsers', "\$wp_cache_mobile_browsers = 'Android, 2.0 MMP, 240x320, AvantGo, BlackBerry, Blazer, Cellphone, Danger, DoCoMo, Elaine/3.0, EudoraWeb, hiptop, IEMobile, iPhone, iPod, KYOCERA/WX310K, LG/U990, MIDP-2.0, MMEF20, MOT-V, NetFront, Newt, Nintendo Wii, Nitro, Nokia, Opera Mini, Palm, Playstation Portable, portalmmm, Proxinet, ProxiNet, SHARP-TQ-GX10, Small, SonyEricsson, Symbian OS, SymbianOS, TS21i-10, UP.Browser, UP.Link, Windows CE, WinWAP';", $wp_cache_config_file);
258 }
259 wp_cache_replace_line('^ *\$wp_cache_mobile_enabled', "\$wp_cache_mobile_enabled = " . $wp_cache_mobile_enabled . ";", $wp_cache_config_file);
260 switch( $_POST[ 'wp_cache_status' ] ) {
261 case 'all':
262 wp_cache_enable();
263 break;
264 case 'none':
265 wp_cache_disable();
266 break;
267 case 'wpcache':
268 wp_cache_enable();
269 wp_super_cache_disable();
270 break;
271 }
272 if( isset( $_POST[ 'wp_cache_hello_world' ] ) ) {
273 $wp_cache_hello_world = 1;
274 } else {
275 $wp_cache_hello_world = 0;
276 }
277 wp_cache_replace_line('^ *\$wp_cache_hello_world', '$wp_cache_hello_world = ' . (int)$wp_cache_hello_world . ";", $wp_cache_config_file);
278 if( isset( $_POST[ 'wp_cache_clear_on_post_edit' ] ) ) {
279 $wp_cache_clear_on_post_edit = 1;
280 } else {
281 $wp_cache_clear_on_post_edit = 0;
282 }
283 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);
284 if( isset( $_POST[ 'cache_rebuild_files' ] ) ) {
285 $cache_rebuild_files = 1;
286 } else {
287 $cache_rebuild_files = 0;
288 }
289 wp_cache_replace_line('^ *\$cache_rebuild_files', "\$cache_rebuild_files = " . $cache_rebuild_files . ";", $wp_cache_config_file);
290 if( isset( $_POST[ 'wp_cache_mutex_disabled' ] ) ) {
291 $wp_cache_mutex_disabled = 0;
292 } else {
293 $wp_cache_mutex_disabled = 1;
294 }
295 if( defined( 'WPSC_DISABLE_LOCKING' ) ) {
296 $wp_cache_mutex_disabled = 1;
297 }
298 wp_cache_replace_line('^ *\$wp_cache_mutex_disabled', "\$wp_cache_mutex_disabled = " . $wp_cache_mutex_disabled . ";", $wp_cache_config_file);
299 if( isset( $_POST[ 'wp_cache_not_logged_in' ] ) ) {
300 if( $wp_cache_not_logged_in == 0 && function_exists( 'prune_super_cache' ) )
301 prune_super_cache ($cache_path, true);
302 $wp_cache_not_logged_in = 1;
303 } else {
304 $wp_cache_not_logged_in = 0;
305 }
306 wp_cache_replace_line('^ *\$wp_cache_not_logged_in', "\$wp_cache_not_logged_in = " . $wp_cache_not_logged_in . ";", $wp_cache_config_file);
307 }
308 if( defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
309 $cache_compression_changed = false;
310 $cache_compression = 0;
311 wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
312 } elseif( isset( $_POST[ 'cache_compression' ] ) && $_POST[ 'cache_compression' ] != $cache_compression ) {
313 $cache_compression_changed = true;
314 $cache_compression = intval( $_POST[ 'cache_compression' ] );
315 wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
316 if( function_exists( 'prune_super_cache' ) )
317 prune_super_cache ($cache_path, true);
318 delete_option( 'super_cache_meta' );
319 }
320 if( isset( $_POST[ 'wp_cache_hide_donation' ] ) && $_POST[ 'wp_cache_hide_donation' ] != $wp_cache_hide_donation ) {
321 $wp_cache_hide_donation = intval( $_POST[ 'wp_cache_hide_donation' ] );
322 wp_cache_replace_line('^ *\$wp_cache_hide_donation', "\$wp_cache_hide_donation = " . $wp_cache_hide_donation . ";", $wp_cache_config_file);
323 }
324 }
325
326 ?>
327 <table><td><fieldset class="options" id="show-this-fieldset">
328 <h3>WP Super Cache Status</h3><?php
329 echo '<form name="wp_manager" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
330 ?>
331 <label><input type='radio' name='wp_cache_status' value='all' <?php if( $cache_enabled == true && $super_cache_enabled == true ) { echo 'checked=checked'; } ?>> <strong>ON</strong> <span class="setting-description">WP Cache and Super Cache enabled</span></label><br />
332 <label><input type='radio' name='wp_cache_status' value='wpcache' <?php if( $cache_enabled == true && $super_cache_enabled == false ) { echo 'checked=checked'; } ?>> <strong>HALF ON</strong> <span class="setting-description">Super Cache Disabled, only legacy WP-Cache caching.</span></label><br />
333 <label><input type='radio' name='wp_cache_status' value='none' <?php if( $cache_enabled == false ) { echo 'checked=checked'; } ?>> <strong>OFF</strong> <span class="setting-description">WP Cache and Super Cache disabled</span></label><br />
334 <p><label><input type='checkbox' name='wp_cache_not_logged_in' <?php if( $wp_cache_not_logged_in ) echo "checked"; ?> value='1'> Don't cache pages for logged in users.</label></p>
335 <p><label><input type='checkbox' name='wp_cache_hello_world' <?php if( $wp_cache_hello_world ) echo "checked"; ?> value='1'> Proudly tell the world your server is Digg proof! (places a message in your blog's footer)</label></p>
336 <p><label><input type='checkbox' name='wp_cache_clear_on_post_edit' <?php if( $wp_cache_clear_on_post_edit ) echo "checked"; ?> value='1'> Clear all cache files when a post or page is published. (This may significantly slow down saving of posts.)</label></p>
337 <p><label><input type='checkbox' name='cache_rebuild_files' <?php if( $cache_rebuild_files ) echo "checked"; ?> value='1'> 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.</label></p>
338 <?php if( false == defined( 'WPSC_DISABLE_LOCKING' ) ) { ?>
339 <p><label><input type='checkbox' name='wp_cache_mutex_disabled' <?php if( !$wp_cache_mutex_disabled ) echo "checked"; ?> value='0'> Coarse file locking. You probably don'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></label></p>
340 <?php } ?>
341 <p><label><input type='checkbox' name='wp_cache_mobile_enabled' <?php if( $wp_cache_mobile_enabled ) echo "checked"; ?> value='1'> Mobile device support.</label>
342 <?php
343 $home_path = trailingslashit( get_home_path() );
344 if ( false === strpos( implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) ), 'SHARP-TQ-GX10' ) ) { // we don't have the rewrite rules
345 ?>
346 <blockquote><p>Mobile support requires extra rules in your .htaccess file, or you can set the plugin to half-on mode. Here's your options (in order of difficulty):
347 <ol><li> 1. Set the plugin to half on mode and enable mobile support.</li>
348 <li> 2. Delete the plugin mod_rewrite rules in <?php echo $home_path; ?>.htaccess enclosed by <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code> and let the plugin regenerate them by reloading this page.</li>
349 <li> 3. Add the rules yourself. Edit <?php echo $home_path; ?>.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)</p>
350 <div style='border: 1px solid #333; width:400px; overflow: scroll'><pre>RewriteCond %{HTTP_user_agent} !^.*(Android|2.0\ MMP|240x320|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|hiptop|IEMobile|iPhone|iPod|KYOCERA/WX310K|LG/U990|MIDP-2.0|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|Playstation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|Windows\ CE|WinWAP).*</pre></div></li></ol></blockquote>
351 <?php } ?>
352 <p><strong>Note:</strong> If uninstalling this plugin, make sure the directory <em><?php echo WP_CONTENT_DIR; ?></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!)</p>
353 <p>Uninstall using the <a href="<?php echo WP_PLUGIN_URL; ?>/wp-super-cache/uninstall.php">uninstall script</a> to remove files and directories created by the plugin. (Please see <a href="<?php echo WP_PLUGIN_URL; ?>/wp-super-cache/readme.txt">readme.txt</a> for instructions on uninstalling this script.)</p>
354 <?php
355 echo "<div class='submit'><input type='submit' " . SUBMITDISABLED . " value='Update Status &raquo;' /></div>";
356 wp_nonce_field('wp-cache');
357 ?>
358 </form>
359 <?php
360 if( $super_cache_enabled && function_exists( 'apache_get_modules' ) ) {
361 $mods = apache_get_modules();
362 $required_modules = array( 'mod_mime' => 'Required to serve compressed supercache files properly.', 'mod_headers' => 'Required to set caching information on supercache pages. IE7 users will see old pages without this module.', 'mod_expires' => 'Set the expiry date on supercached pages. Visitors may not see new pages when they refresh or leave comments without this module.' );
363 foreach( $required_modules as $req => $desc ) {
364 if( !in_array( $req, $mods ) ) {
365 $missing_mods[ $req ] = $desc;
366 }
367 }
368 if( isset( $missing_mods) && is_array( $missing_mods ) ) {
369 echo "<h3>Missing Apache Modules</h3>";
370 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.</p>";
371 echo "<ul>";
372 foreach( $missing_mods as $req => $desc ) {
373 echo "<li> $req - $desc</li>";
374 }
375 echo "</ul>";
376 }
377 }
378 ?>
379 </fieldset>
380 </td><td valign='top'>
381 <div style='background: #ffc; border: 1px solid #333; margin: 2px; padding: 5px'>
382 <h3 align='center'>Make WordPress Faster</h3>
383 <?php if( $wp_cache_hide_donation != 1 ) { ?>
384 <p><a href="http://ocaoimh.ie/wp-super-cache/?r=wpsc">WP Super Cache</a> really makes your blog go faster. Make it go faster<sup>*</sup> by buying me an <a href="http://ocaoimh.ie/agc">Amazon gift card</a>! Make it out to "donncha@ocaoimh.ie". A £10 card would be nice but it's up to you how much you think this plugin is worth to you.</p>
385 <p>If Amazon isn't your thing, there's also PayPal. Click the "Donate" button below or take a quick peek at my <a href="http://ocaoimh.ie/wish">wishlist</a>.</p>
386 <p>Thanks in advance!<br />Donncha<br />
387 <small>* Ok, it won't go any faster but you'll make this plugin author very happy!</small></p>
388 <div align='center'>
389 <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
390 <input type="hidden" name="cmd" value="_s-xclick"/>
391 <input type="hidden" name="hosted_button_id" value="3244504"/>
392 <input type="image" src="https://www.paypal.com/en_GB/i/btn/btn_donate_SM.gif" border="0" name="submit" alt=""/>
393 <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"/><br />
394 </form>
395 <p>Don't show me this again. <form action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post"><input type='hidden' name='wp_cache_hide_donation' value='1' /><input type='submit' value='Hide' /><?php wp_nonce_field('wp-cache'); ?></form></p>
396 </div>
397 <?php } else { ?>
398 <p><a href="http://ocaoimh.ie/wp-super-cache/?r=supercache">WP Super Cache</a> is maintained and developed by <a href="http://ocaoimh.ie/?r=supercache">Donncha O Caoimh</a> with contributions from many others.</p>
399 <p>He blogs at <a href="http://ocaoimh.ie/?r=supercache">Holy Shmoly</a>, posts photos at <a href="http://inphotos.org/?r=supercache">In Photos.org</a> and <a href="http://ocaoimh.ie/gad">wishes</a> he had more time to read and relax.</p><p>Please say hi to him on <a href="http://twitter.com/donncha/">Twitter</a> too!</p>
400 <?php } ?>
401 </div>
402
403 </td></table>
404 <?php
405
406 wp_cache_files();
407
408 wsc_mod_rewrite();
409
410 wp_cache_edit_max_time();
411
412 echo '<a name="files"></a><fieldset class="options"><h3>Accepted Filenames &amp; Rejected URIs</h3>';
413 wp_cache_edit_rejected_pages();
414 echo "\n";
415 wp_cache_edit_rejected();
416 echo "\n";
417 wp_cache_edit_accepted();
418 echo '</fieldset>';
419
420 wp_cache_edit_rejected_ua();
421
422
423 wp_lock_down();
424
425 wp_cache_restore();
426
427 ob_start();
428 if( defined( 'WP_CACHE' ) ) {
429 if( function_exists( 'do_cacheaction' ) ) {
430 do_cacheaction( 'cache_admin_page' );
431 }
432 }
433 $out = ob_get_contents();
434 ob_end_clean();
435 if( SUBMITDISABLED == ' ' && $out != '' ) {
436 echo '<fieldset class="options"><h3>Cache Plugins</h3>';
437 echo $out;
438 echo '</fieldset>';
439 }
440
441 echo "</div>\n";
442 }
443
444 function wsc_mod_rewrite() {
445 global $super_cache_enabled, $cache_compression, $cache_compression_changed, $valid_nonce, $cache_path;
446 if( $super_cache_enabled == false )
447 return;
448 if( false == defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
449 ?>
450 <fieldset class="options">
451 <h3>Super Cache Compression</h3>
452 <form name="wp_manager" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post">
453 <label><input type="radio" name="cache_compression" value="1" <?php if( $cache_compression ) { echo "checked=checked"; } ?>> Enabled</label>
454 <label><input type="radio" name="cache_compression" value="0" <?php if( !$cache_compression ) { echo "checked=checked"; } ?>> Disabled</label>
455 <p>Compression is disabled by default because some hosts have problems with compressed files. Switching this on and off clears the cache.</p>
456 <?php
457 if( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && !$cache_compression ) {
458 ?><p><strong>Super Cache compression is now disabled.</strong></p> <?php
459 } elseif( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && $cache_compression ) {
460 ?><p><strong>Super Cache compression is now enabled.</strong></p><?php
461 }
462 echo '<div class="submit"><input ' . SUBMITDISABLED . 'type="submit" value="Update Compression &raquo;" /></div>';
463 wp_nonce_field('wp-cache');
464 echo "</form>\n";
465 ?></fieldset>
466 <?php } ?>
467
468 <a name="modrewrite"></a><fieldset class="options">
469 <h3>Mod Rewrite Rules</h3><?php
470 if ( isset( $_SERVER[ "PHP_DOCUMENT_ROOT" ] ) ) {
471 $document_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
472 $apache_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
473 } else {
474 $document_root = $_SERVER[ "DOCUMENT_ROOT" ];
475 $apache_root = '%{DOCUMENT_ROOT}';
476 }
477 $home_path = get_home_path();
478 $home_root = parse_url(get_bloginfo('url'));
479 $home_root = trailingslashit($home_root['path']);
480 $home_root = isset( $home_root['path'] ) ? trailingslashit( $home_root['path'] ) : '/';
481 $inst_root = str_replace( '//', '/', '/' . trailingslashit( str_replace( $document_root, '', str_replace( '\\', '/', WP_CONTENT_DIR ) ) ) );
482 $wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) );
483 $wprules = str_replace( "RewriteEngine On\n", '', $wprules );
484 $wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
485 $scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
486
487 if( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
488 $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*[^/]$";
489 $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*//.*$";
490 }
491 $condition_rules[] = "RewriteCond %{REQUEST_METHOD} !=POST";
492 $condition_rules[] = "RewriteCond %{QUERY_STRING} !.*=.*";
493 $condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$";
494 $condition_rules[] = "RewriteCond %{HTTP_user_agent} !^.*(Android|2.0\\ MMP|240x320|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|hiptop|IEMobile|iPhone|iPod|KYOCERA/WX310K|LG/U990|MIDP-2.0|MMEF20|MOT-V|NetFront|Newt|Nintendo\\ Wii|Nitro|Nokia|Opera\\ Mini|Palm|Playstation\\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|Small|SonyEricsson|Symbian\\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|Windows\\ CE|WinWAP).*";
495 $condition_rules = apply_filters( 'supercacherewriteconditions', $condition_rules );
496
497 $rules = "<IfModule mod_rewrite.c>\n";
498 $rules .= "RewriteEngine On\n";
499 $rules .= "RewriteBase $home_root\n"; // props Chris Messina
500 $charset = get_option('blog_charset') == '' ? 'UTF-8' : get_option('blog_charset');
501 $rules .= "AddDefaultCharset {$charset}\n";
502 $rules .= "CONDITION_RULES";
503 $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
504 $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz -f\n";
505 $rules .= "RewriteRule ^(.*) {$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz [L]\n\n";
506
507 $rules .= "CONDITION_RULES";
508 $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html -f\n";
509 $rules .= "RewriteRule ^(.*) {$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html [L]\n";
510 $rules .= "</IfModule>\n";
511 $rules = apply_filters( 'supercacherewriterules', $rules );
512
513 $rules = str_replace( "CONDITION_RULES", implode( "\n", $condition_rules ) . "\n", $rules );
514
515 $dohtaccess = true;
516 if( function_exists( 'is_site_admin' ) ) {
517 echo "<h4 style='color: #a00'>WordPress MU Detected</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.</p>";
518 } elseif( !$wprules || $wprules == '' ) {
519 echo "<h4 style='color: #a00'>Mod Rewrite rules cannot be updated!</h4>";
520 echo "<p>You must have <strong>BEGIN</strong> and <strong>END</strong> markers in {$home_path}.htaccess for the auto update to work. They look like this and surround the main WordPress mod_rewrite rules:
521 <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>
522 Refresh this page when you have updated your .htaccess file.";
523 echo "</fieldset></div>";
524 return;
525 } elseif( strpos( $wprules, 'wordpressuser' ) ) { // Need to clear out old mod_rewrite rules
526 echo "<p><strong>Thank you for upgrading.</strong> 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: <blockquote><code>RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*\$</code></blockquote> so it looks like this: <blockquote><code>RewriteCond %{HTTP:Cookie} !^.*wordpress.*\$</code></blockquote> The only changes are 'HTTP_COOKIE' becomes 'HTTP:Cookie' and 'wordpressuser' becomes 'wordpress'. This is a WordPress 2.5 change but it's backwards compatible with older versions if you're brave enough to use them.</p>";
527 echo "</fieldset></div>";
528 return;
529 } elseif( $scrules != '' && strpos( $scrules, '%{REQUEST_URI} !^.*[^/]$' ) === false && substr( get_option( 'permalink_structure' ), -1 ) == '/' ) { // permalink structure has a trailing slash, need slash check in rules.
530 echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><h4>Trailing slash check required.</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.";
531 echo "To fix, you must edit your .htaccess file and add these two rules to the two groups of Super Cache rules:</p>";
532 echo "<blockquote><code>RewriteCond %{REQUEST_URI} !^.*[^/]$RewriteCond %{REQUEST_URI} !^.*//.*$</code></blockquote>";
533 echo "<p>You can see where the rules go and examine the complete rules by clicking the 'View mod_rewrite rules' link below.</p></div>";
534 $dohtaccess = false;
535 } elseif( strpos( $scrules, 'supercache' ) || strpos( $wprules, 'supercache' ) ) { // only write the rules once
536 $dohtaccess = false;
537 }
538 // cache/.htaccess rules
539 $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";
540 $gziprules .= "<IfModule mod_deflate.c>\n SetEnvIfNoCase Request_URI \.gz$ no-gzip\n</IfModule>\n";
541 $gziprules .= "<IfModule mod_headers.c>\n Header set Cache-Control 'max-age=300, must-revalidate'\n</IfModule>\n";
542 $gziprules .= "<IfModule mod_expires.c>\n ExpiresActive On\n ExpiresByType text/html A300\n</IfModule>\n";
543 if( $dohtaccess && !$_POST[ 'updatehtaccess' ] ) {
544 if( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) {
545 echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><h4>Cannot update .htaccess</h4><p>The file <code>{$home_path}.htaccess</code> cannot be modified by the web server. Please correct this using the chmod command or your ftp client.</p><p>Refresh this page when the file permissions have been modified.</p><p>Alternatively, you can edit your <code>{$home_path}.htaccess</code> file manually and add the following code (before any WordPress rules):</p>";
546 echo "<p><pre># BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache</pre></p></div>";
547 } else {
548 echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><p>To serve static html files your server must have the correct mod_rewrite rules added to a file called <code>{$home_path}.htaccess</code> ";
549 if( !function_exists( 'is_site_admin' ) ) {
550 echo "You must edit the file yourself add the following rules.";
551 } else {
552 echo "You can edit the file yourself add the following rules.";
553 }
554 echo " Make sure they appear before any existing WordPress rules.</p>";
555 echo "<pre># BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache</pre></p>";
556 echo "<p>Rules must be added to " . WP_CONTENT_DIR . "/cache/.htaccess too:</p>";
557 echo "<pre># BEGIN supercache\n" . wp_specialchars( $gziprules ) . "# END supercache</pre></p>";
558 if( !function_exists( 'is_site_admin' ) ) {
559 echo '<form name="updatehtaccess" action="'. $_SERVER["REQUEST_URI"] . '#modrewrite" method="post">';
560 echo '<input type="hidden" name="updatehtaccess" value="1" />';
561 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'id="updatehtaccess" value="Update Mod_Rewrite Rules &raquo;" /></div>';
562 wp_nonce_field('wp-cache');
563 echo "</form></div>\n";
564 }
565 }
566 } elseif( $dohtaccess && $valid_nonce && $_POST[ 'updatehtaccess' ] ) {
567 wpsc_remove_marker( $home_path.'.htaccess', 'WordPress' ); // remove original WP rules so SuperCache rules go on top
568 echo "<div style='padding:0 8px;color:#4f8a10;background-color:#dff2bf;border:1px solid #4f8a10;'>";
569 if( insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', explode( "\n", $rules ) ) && insert_with_markers( $home_path.'.htaccess', 'WordPress', explode( "\n", $wprules ) ) ) {
570 echo "<h4>Mod Rewrite rules updated!</h4>";
571 echo "<p><strong>{$home_path}.htaccess has been updated with the necessary mod_rewrite rules. Please verify they are correct. They should look like this:</strong></p>\n";
572 } else {
573 echo "<h4>Mod Rewrite rules must be updated!</h4>";
574 echo "<p><strong> Your {$home_path}.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:</strong></p>\n";
575 }
576 echo "<p><pre>" . wp_specialchars( $rules ) . "</pre></p>\n</div>";
577 } else {
578 ?>
579 <p>WP Super Cache mod rewrite rules were detected in your <?php echo $home_path ?>.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.<br /><br />
580 <a href="javascript:toggleLayer('rewriterules');" class="button">View Mod_Rewrite Rules</a>
581 <div id='rewriterules' style='display: none;'>
582 <?php echo "<p><pre># BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache</pre></p>\n";
583 echo "<p>Rules must be added to " . WP_CONTENT_DIR ."/cache/.htaccess too:</p>";
584 echo "<pre># BEGIN supercache\n" . wp_specialchars( $gziprules ) . "# END supercache</pre></p>"; ?>
585 </div>
586 <?php
587 }
588 // http://allmybrain.com/2007/11/08/making-wp-super-cache-gzip-compression-work/
589 if( !is_file( $cache_path . '.htaccess' ) ) {
590 $gziprules = insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $gziprules ) );
591 echo "<h4>Gzip encoding rules in {$cache_path}.htaccess created.</h4>";
592 }
593
594 ?></fieldset><?php
595 }
596
597 function wp_cache_restore() {
598 echo '<fieldset class="options"><h3>Fix Configuration</h3>';
599 echo '<form name="wp_restore" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
600 echo '<input type="hidden" name="wp_restore_config" />';
601 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'id="deletepost" value="Restore Default Configuration &raquo;" /></div>';
602 wp_nonce_field('wp-cache');
603 echo "</form>\n";
604 echo '</fieldset>';
605
606 }
607
608 function comment_form_lockdown_message() {
609 ?><p><?php _e( "Comment moderation is enabled. Your comment may take some time to appear." ); ?></p><?php
610 }
611 if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) )
612 add_action( 'comment_form', 'comment_form_lockdown_message' );
613
614 function wp_lock_down() {
615 global $wpdb, $cache_path, $wp_cache_config_file, $valid_nonce, $cached_direct_pages, $cache_enabled, $super_cache_enabled;
616
617 if(isset($_POST['wp_lock_down']) && $valid_nonce) {
618 $wp_lock_down = $_POST['wp_lock_down'] == '1' ? '1' : '0';
619 wp_cache_replace_line('^.*WPLOCKDOWN', "define( 'WPLOCKDOWN', '$wp_lock_down' );", $wp_cache_config_file);
620 if( $wp_lock_down == '0' && function_exists( 'prune_super_cache' ) )
621 prune_super_cache( $cache_path, true ); // clear the cache after lockdown
622
623 }
624 if( !isset( $wp_lock_down ) ) {
625 if( defined( 'WPLOCKDOWN' ) ) {
626 $wp_lock_down = constant( 'WPLOCKDOWN' );
627 } else {
628 $wp_lock_down = '0';
629 }
630 }
631 ?><fieldset class="options">
632 <h3>Lock Down: <?php echo $wp_lock_down == '0' ? '<span style="color:red">Disabled</span>' : '<span style="color:green">Enabled</span>'; ?></h3>
633 <p>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.</p>
634 <p>Developers: Make your plugin lock down compatible by checking the 'WPLOCKDOWN' constant. The following code will make sure your plugin respects the WPLOCKDOWN setting.
635 <blockquote><code>if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) ) {
636 &nbsp;&nbsp;&nbsp;&nbsp;echo "Sorry. My blog is locked down. Updates will appear shortly";
637 }</code></blockquote>
638 <?php
639 if( $wp_lock_down == '1' ) {
640 ?><p>WordPress is locked down. Super Cache static files will not be deleted when new comments are made.</p><?php
641 } else {
642 ?><p>WordPress is not locked down. New comments will refresh Super Cache static files as normal.</p><?php
643 }
644 $new_lockdown = $wp_lock_down == '1' ? '0' : '1';
645 $new_lockdown_desc = $wp_lock_down == '1' ? 'Disable' : 'Enable';
646 echo '<form name="wp_lock_down" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
647 echo "<input type='hidden' name='wp_lock_down' value='{$new_lockdown}' />";
648 echo "<div class='submit'><input type='submit' " . SUBMITDISABLED . " value='{$new_lockdown_desc} Lock Down &raquo;' /></div>";
649 wp_nonce_field('wp-cache');
650 echo "</form>\n";
651
652 ?></fieldset><?php
653 if( $cache_enabled == true && $super_cache_enabled == true ) {
654 ?><fieldset class="options">
655 <h3>Directly Cached Files</h3><?php
656
657 $out = '';
658 if( $valid_nonce && is_array( $_POST[ 'direct_pages' ] ) && !empty( $_POST[ 'direct_pages' ] ) ) {
659 $expiredfiles = array_diff( $cached_direct_pages, $_POST[ 'direct_pages' ] );
660 unset( $cached_direct_pages );
661 foreach( $_POST[ 'direct_pages' ] as $page ) {
662 $page = $wpdb->escape( $page );
663 if( $page != '' ) {
664 $cached_direct_pages[] = $page;
665 $out .= "'$page', ";
666 }
667 }
668 if( $out == '' ) {
669 $out = "'', ";
670 }
671 }
672 if( $valid_nonce && $_POST[ 'new_direct_page' ] && '' != $_POST[ 'new_direct_page' ] ) {
673 $page = str_replace( get_option( 'siteurl' ), '', $_POST[ 'new_direct_page' ] );
674 if( substr( $page, 0, 1 ) != '/' )
675 $page = '/' . $page;
676 $page = $wpdb->escape( $page );
677 if( in_array( $page, $cached_direct_pages ) == false ) {
678 $cached_direct_pages[] = $page;
679 $out .= "'$page', ";
680 }
681 }
682
683 if( $out != '' ) {
684 $out = substr( $out, 0, -2 );
685 $out = '$cached_direct_pages = array( ' . $out . ' );';
686 wp_cache_replace_line('^ *\$cached_direct_pages', "$out", $wp_cache_config_file);
687 prune_super_cache( $cache_path, true );
688 }
689
690 if( !empty( $expiredfiles ) ) {
691 foreach( $expiredfiles as $file ) {
692 if( $file != '' ) {
693 $firstfolder = explode( '/', $file );
694 $firstfolder = ABSPATH . $firstfolder[1];
695 $file = ABSPATH . $file;
696 @unlink( trailingslashit( $file ) . 'index.html' );
697 @unlink( trailingslashit( $file ) . 'index.html.gz' );
698 RecursiveFolderDelete( trailingslashit( $firstfolder ) );
699 }
700 }
701 }
702
703 if( $valid_nonce && $_POST[ 'deletepage' ] ) {
704 $page = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_POST['deletepage']) );
705 $pagefile = ABSPATH . $page . 'index.html';
706 $firstfolder = explode( '/', $page );
707 $firstfolder = ABSPATH . $firstfolder[1];
708 $page = ABSPATH . $page;
709 if( is_file( $pagefile ) && is_writeable_ACLSafe( $pagefile ) && is_writeable_ACLSafe( $firstfolder ) ) {
710 @unlink( $pagefile );
711 @unlink( $pagefile . '.gz' );
712 RecursiveFolderDelete( $firstfolder );
713 echo "<strong>$pagefile removed!</strong>";
714 prune_super_cache( $cache_path, true );
715 }
716 }
717
718 $readonly = '';
719 if( !is_writeable_ACLSafe( ABSPATH ) ) {
720 $readonly = 'READONLY';
721 ?><p style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><strong>Warning!</strong> You must make <?php echo ABSPATH ?> writable to enable this feature. As this is a security risk please make it readonly after your page is generated.</p><?php
722 } else {
723 ?><p style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><strong>Warning!</strong> <?php echo ABSPATH ?> is writable. Please make it readonly after your page is generated as this is a security risk.</p><?php
724 }
725 echo '<form name="direct_page" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
726 if( is_array( $cached_direct_pages ) ) {
727 $out = '';
728 foreach( $cached_direct_pages as $page ) {
729 if( $page == '' )
730 continue;
731 $generated = '';
732 if( is_file( ABSPATH . $page . '/index.html' ) )
733 $generated = '<input type="Submit" name="deletepage" value="' . $page . '">';
734 $out .= "<tr><td><input type='text' $readonly name='direct_pages[]' size='30' value='$page' /></td><td>$generated</td></tr>";
735 }
736 if( $out != '' ) {
737 ?><table><tr><th>Existing direct page</th><th>Delete cached file</th></tr><?php
738 echo "$out</table>";
739 }
740 }
741 if( $readonly != 'READONLY' )
742 echo "Add direct page: <input type='text' $readonly name='new_direct_page' size='30' value='' />";
743
744 echo "<p>Directly cached files are files created directly off " . ABSPATH . " 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.</p>";
745 if( $readonly != 'READONLY' ) {
746 echo "<p>For example: to cache <em>'" . trailingslashit( get_option( 'siteurl' ) ) . "about/'</em>, you would enter '" . trailingslashit( get_option( 'siteurl' ) ) . "about/' or '/about/'. The cached file will be generated the next time an anonymous user visits that page.</p>";
747 echo "<p>Make the textbox blank to remove it from the list of direct pages and delete the cached file.</p>";
748 }
749
750 wp_nonce_field('wp-cache');
751 if( $readonly != 'READONLY' )
752 echo "<div class='submit'><input type='submit' ' . SUBMITDISABLED . 'value='Update Direct Pages &raquo;' /></div>";
753 echo "</form>\n";
754 ?></fieldset><?php
755 } // if $super_cache_enabled
756 }
757
758 function RecursiveFolderDelete ( $folderPath ) { // from http://www.php.net/manual/en/function.rmdir.php
759 if( trailingslashit( constant( 'ABSPATH' ) ) == trailingslashit( $folderPath ) )
760 return false;
761 if ( @is_dir ( $folderPath ) ) {
762 $dh = @opendir($folderPath);
763 while (false !== ($value = @readdir($dh))) {
764 if ( $value != "." && $value != ".." ) {
765 $value = $folderPath . "/" . $value;
766 if ( @is_dir ( $value ) ) {
767 RecursiveFolderDelete ( $value );
768 }
769 }
770 }
771 return @rmdir ( $folderPath );
772 } else {
773 return FALSE;
774 }
775 }
776
777 function wp_cache_edit_max_time () {
778 global $cache_max_time, $wp_cache_config_file, $valid_nonce, $cache_enabled, $super_cache_enabled;
779
780 if( !isset( $cache_max_time ) )
781 $cache_max_time = 3600;
782
783 if(isset($_POST['wp_max_time']) && $valid_nonce) {
784 $max_time = (int)$_POST['wp_max_time'];
785 if ($max_time > 0) {
786 $cache_max_time = $max_time;
787 wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file);
788 }
789 }
790 ?><fieldset class="options">
791 <h3>Expiry Time &amp; Garbage Collection</h3><?php
792 echo '<form name="wp_edit_max_time" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
793 echo '<label for="wp_max_time">Expire time:</label> ';
794 echo "<input type=\"text\" size=6 name=\"wp_max_time\" value=\"$cache_max_time\" /> seconds";
795 echo "<h4>Garbage Collection</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.</p>";
796 echo "<p>Checking for and deleting expired files is expensive, but it'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.</p>";
797 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Change Expiration &raquo;" /></div>';
798 wp_nonce_field('wp-cache');
799 echo "</form>\n";
800 ?></fieldset><?php
801 }
802
803 function wp_cache_sanitize_value($text, & $array) {
804 $text = wp_specialchars(strip_tags($text));
805 $array = preg_split("/[\s,]+/", chop($text));
806 $text = var_export($array, true);
807 $text = preg_replace('/[\s]+/', ' ', $text);
808 return $text;
809 }
810
811 // from tehjosh at gamingg dot net http://uk2.php.net/manual/en/function.apache-request-headers.php#73964
812 // fixed bug in second substr()
813 if( !function_exists('apache_request_headers') ) {
814 function apache_request_headers() {
815 $headers = array();
816 foreach(array_keys($_SERVER) as $skey) {
817 if(substr($skey, 0, 5) == "HTTP_") {
818 $headername = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($skey, 5)))));
819 $headers[$headername] = $_SERVER[$skey];
820 }
821 }
822 return $headers;
823 }
824 }
825
826 function wp_cache_edit_rejected_ua() {
827 global $cache_rejected_user_agent, $wp_cache_config_file, $valid_nonce;
828
829 if (!function_exists('apache_request_headers')) return;
830
831 if(isset($_REQUEST['wp_rejected_user_agent']) && $valid_nonce) {
832 $text = wp_cache_sanitize_value($_REQUEST['wp_rejected_user_agent'], $cache_rejected_user_agent);
833 wp_cache_replace_line('^ *\$cache_rejected_user_agent', "\$cache_rejected_user_agent = $text;", $wp_cache_config_file);
834 }
835
836 echo '<a name="user-agents"></a><fieldset class="options"><h3>Rejected User Agents</h3>';
837 echo "<p>Strings in the HTTP 'User Agent' header that prevent WP-Cache from
838 caching bot, spiders, and crawlers' requests.
839 Note that super cached files are still sent to these agents if they already exists.</p>\n";
840 echo '<form name="wp_edit_rejected_user_agent" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
841 echo '<textarea name="wp_rejected_user_agent" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
842 foreach ($cache_rejected_user_agent as $ua) {
843 echo wp_specialchars($ua) . "\n";
844 }
845 echo '</textarea> ';
846 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Save UA Strings &raquo;" /></div>';
847 wp_nonce_field('wp-cache');
848 echo '</form>';
849 echo "</fieldset>\n";
850 }
851
852 function wp_cache_edit_rejected_pages() {
853 global $wp_cache_config_file, $valid_nonce, $wp_cache_pages;
854
855 if ( isset( $_POST[ 'wp_edit_rejected_pages' ] ) && $valid_nonce ) {
856 $pages = array( 'single', 'pages', 'archives', 'tag', 'frontpage', 'home', 'category' );
857 foreach( $pages as $page ) {
858 if ( isset( $_POST[ 'wp_cache_pages' ][ $page ] ) ) {
859 $value = 1;
860 } else {
861 $value = 0;
862 }
863 wp_cache_replace_line('^ *\$wp_cache_pages\[ "' . $page . '" \]', "\$wp_cache_pages[ \"{$page}\" ] = $value;", $wp_cache_config_file);
864 $wp_cache_pages[ $page ] = $value;
865 }
866 }
867
868 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.</p>';
869 echo '<form name="wp_edit_rejected_pages" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
870 echo '<input type="hidden" name="wp_edit_rejected_pages" value="1" />';
871 echo '<label><input type="checkbox" value="1" name="wp_cache_pages[single]" ' . checked( 1, $wp_cache_pages[ 'single' ], false ) . ' /> Single Posts (is_single)</label><br />';
872 echo '<label><input type="checkbox" value="1" name="wp_cache_pages[pages]" ' . checked( 1, $wp_cache_pages[ 'pages' ], false ) . ' /> Pages (is_page)</label><br />';
873 echo '<label><input type="checkbox" value="1" name="wp_cache_pages[frontpage]" ' . checked( 1, $wp_cache_pages[ 'frontpage' ], false ) . ' /> Front Page (is_front_page)</label><br />';
874 echo '&nbsp;&nbsp;<label><input type="checkbox" value="1" name="wp_cache_pages[home]" ' . checked( 1, $wp_cache_pages[ 'home' ], false ) . ' /> Home (is_home)</label><br />';
875 echo '<label><input type="checkbox" value="1" name="wp_cache_pages[archives]" ' . checked( 1, $wp_cache_pages[ 'archives' ], false ) . ' /> Archives (is_archive)</label><br />';
876 echo '&nbsp;&nbsp;<label><input type="checkbox" value="1" name="wp_cache_pages[tag]" ' . checked( 1, $wp_cache_pages[ 'tag' ], false ) . ' /> Tags (is_tag)</label><br />';
877 echo '&nbsp;&nbsp;<label><input type="checkbox" value="1" name="wp_cache_pages[category]" ' . checked( 1, $wp_cache_pages[ 'category' ], false ) . ' /> Category (is_category)</label><br />';
878
879 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Save &raquo;" /></div>';
880 wp_nonce_field('wp-cache');
881 echo "</form>\n";
882
883 }
884
885 function wp_cache_edit_rejected() {
886 global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file, $valid_nonce;
887
888 if(isset($_REQUEST['wp_rejected_uri']) && $valid_nonce) {
889 $text = wp_cache_sanitize_value( str_replace( '\\\\', '\\', $_REQUEST['wp_rejected_uri'] ), $cache_rejected_uri );
890 wp_cache_replace_line('^ *\$cache_rejected_uri', "\$cache_rejected_uri = $text;", $wp_cache_config_file);
891 }
892
893
894 echo '<form name="wp_edit_rejected" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
895 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's enough to specify the year, i.e. '/2004/'. WP-Cache will search if that string is part of the URI and if so, it will not cache that page.</p>\n";
896 echo '<textarea name="wp_rejected_uri" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
897 foreach ($cache_rejected_uri as $file) {
898 echo wp_specialchars( $file ) . "\n";
899 }
900 echo '</textarea> ';
901 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Save Strings &raquo;" /></div>';
902 wp_nonce_field('wp-cache');
903 echo "</form>\n";
904 }
905
906 function wp_cache_edit_accepted() {
907 global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file, $valid_nonce;
908
909 if(isset($_REQUEST['wp_accepted_files']) && $valid_nonce) {
910 $text = wp_cache_sanitize_value($_REQUEST['wp_accepted_files'], $cache_acceptable_files);
911 wp_cache_replace_line('^ *\$cache_acceptable_files', "\$cache_acceptable_files = $text;", $wp_cache_config_file);
912 }
913
914
915 echo '<div style="clear:both"></div><form name="wp_edit_accepted" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
916 echo "<p>Add here those filenames that can be cached, even if they match one of the rejected substring specified above.</p>\n";
917 echo '<textarea name="wp_accepted_files" cols="40" rows="8" style="width: 50%; font-size: 12px;" class="code">';
918 foreach ($cache_acceptable_files as $file) {
919 echo wp_specialchars($file) . "\n";
920 }
921 echo '</textarea> ';
922 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Save Files &raquo;" /></div>';
923 wp_nonce_field('wp-cache');
924 echo "</form>\n";
925 }
926
927 function wp_cache_enable() {
928 global $wp_cache_config_file, $cache_enabled, $supercachedir;
929
930 if(get_option('gzipcompression')) {
931 echo "<strong>Error: GZIP compression is enabled, disable it if you want to enable wp-cache.</strong>";
932 return false;
933 }
934 if( wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = true;', $wp_cache_config_file) ) {
935 $cache_enabled = true;
936 }
937 wp_super_cache_enable();
938 }
939
940 function wp_cache_disable() {
941 global $wp_cache_config_file, $cache_enabled;
942
943 if (wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file)) {
944 $cache_enabled = false;
945 }
946 wp_super_cache_disable();
947 }
948 function wp_super_cache_enable() {
949 global $supercachedir, $wp_cache_config_file, $super_cache_enabled;
950
951 if( is_dir( $supercachedir . ".disabled" ) )
952 if( is_dir( $supercachedir ) ) {
953 prune_super_cache( $supercachedir . ".disabled", true );
954 @unlink( $supercachedir . ".disabled" );
955 } else {
956 @rename( $supercachedir . ".disabled", $supercachedir );
957 }
958 wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = true;', $wp_cache_config_file);
959 $super_cache_enabled = true;
960 }
961
962 function wp_super_cache_disable() {
963 global $cache_path, $supercachedir, $wp_cache_config_file, $super_cache_enabled;
964
965 wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = false;', $wp_cache_config_file);
966 if( is_dir( $supercachedir ) )
967 @rename( $supercachedir, $supercachedir . ".disabled" );
968 $super_cache_enabled = false;
969 sleep( 1 ); // allow existing processes to write to the supercachedir and then delete it
970 if (function_exists ('prune_super_cache') && is_dir( $supercachedir ) ) {
971 prune_super_cache( $cache_path, true );
972 }
973 }
974
975 function wp_cache_is_enabled() {
976 global $wp_cache_config_file;
977
978 if(get_option('gzipcompression')) {
979 echo "<strong>Warning</strong>: GZIP compression is enabled in Wordpress, wp-cache will be bypassed until you disable gzip compression.";
980 return false;
981 }
982 $lines = file($wp_cache_config_file);
983 foreach($lines as $line) {
984 if (preg_match('/^ *\$cache_enabled *= *true *;/', $line))
985 return true;
986 }
987 return false;
988 }
989
990
991 function wp_cache_replace_line($old, $new, $my_file) {
992 if (!is_writeable_ACLSafe($my_file)) {
993 echo "Error: file $my_file is not writable.\n";
994 return false;
995 }
996 $found = false;
997 $lines = file($my_file);
998 foreach($lines as $line) {
999 if ( preg_match("/$old/", $line)) {
1000 $found = true;
1001 break;
1002 }
1003 }
1004 if ($found) {
1005 $fd = fopen($my_file, 'w');
1006 foreach($lines as $line) {
1007 if ( !preg_match("/$old/", $line))
1008 fputs($fd, $line);
1009 else {
1010 fputs($fd, "$new //Added by WP-Cache Manager\n");
1011 }
1012 }
1013 fclose($fd);
1014 return true;
1015 }
1016 $fd = fopen($my_file, 'w');
1017 $done = false;
1018 foreach($lines as $line) {
1019 if ( $done || !preg_match('/^(if\ \(\ \!\ )?define|\$|\?>/', $line) ) {
1020 fputs($fd, $line);
1021 } else {
1022 fputs($fd, "$new //Added by WP-Cache Manager\n");
1023 fputs($fd, $line);
1024 $done = true;
1025 }
1026 }
1027 fclose($fd);
1028 return true;
1029 }
1030
1031 function wp_cache_verify_cache_dir() {
1032 global $cache_path, $blog_cache_dir, $blogcacheid;
1033
1034 $dir = dirname($cache_path);
1035 if ( !file_exists($cache_path) ) {
1036 if ( !is_writeable_ACLSafe( $dir ) || !($dir = mkdir( $cache_path ) ) ) {
1037 echo "<strong>Error:</strong> Your cache directory (<strong>$cache_path</strong>) did not exist and couldn't be created by the web server. Check $dir permissions.";
1038 return false;
1039 }
1040 }
1041 if ( !is_writeable_ACLSafe($cache_path)) {
1042 echo "<strong>Error:</strong> Your cache directory (<strong>$cache_path</strong>) or <strong>$dir</strong> need to be writable for this plugin to work. Double-check it.";
1043 return false;
1044 }
1045
1046 if ( '/' != substr($cache_path, -1)) {
1047 $cache_path .= '/';
1048 }
1049
1050 if( false == is_dir( $blog_cache_dir ) ) {
1051 @mkdir( $cache_path . "blogs" );
1052 if( $blog_cache_dir != $cache_path . "blogs/" )
1053 @mkdir( $blog_cache_dir );
1054 }
1055
1056 if( false == is_dir( $blog_cache_dir . 'meta' ) )
1057 @mkdir( $blog_cache_dir . 'meta' );
1058
1059 return true;
1060 }
1061
1062 function wp_cache_verify_config_file() {
1063 global $wp_cache_config_file, $wp_cache_config_file_sample, $sem_id, $cache_path;
1064
1065 $new = false;
1066 $dir = dirname($wp_cache_config_file);
1067
1068 if ( file_exists($wp_cache_config_file) ) {
1069 $lines = join( ' ', file( $wp_cache_config_file ) );
1070 if( strpos( $lines, 'WPCACHEHOME' ) === false ) {
1071 if( is_writeable_ACLSafe( $wp_cache_config_file ) ) {
1072 @unlink( $wp_cache_config_file );
1073 } else {
1074 echo "<strong>Error:</strong> Your WP-Cache config file (<strong>$wp_cache_config_file</strong>) is out of date and not writable by the Web server.Please delete it and refresh this page.";
1075 return false;
1076 }
1077 }
1078 } elseif( !is_writeable_ACLSafe($dir)) {
1079 echo "<strong>Error:</strong> Configuration file missing and " . WP_CONTENT_DIR . " directory (<strong>$dir</strong>) is not writable by the Web server.Check its permissions.";
1080 return false;
1081 }
1082
1083 if ( !file_exists($wp_cache_config_file) ) {
1084 if ( !file_exists($wp_cache_config_file_sample) ) {
1085 echo "<strong>Error:</strong> Sample WP-Cache config file (<strong>$wp_cache_config_file_sample</strong>) does not exist.Verify you installation.";
1086 return false;
1087 }
1088 copy($wp_cache_config_file_sample, $wp_cache_config_file);
1089 $dir = str_replace( str_replace( '\\', '/', WP_CONTENT_DIR ), '', str_replace( '\\', '/', dirname(__FILE__) ) );
1090 if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
1091 wp_cache_replace_line('define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/\" );", $wp_cache_config_file);
1092 } elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
1093 wp_cache_replace_line('define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/wp-super-cache/\" );", $wp_cache_config_file);
1094 }
1095 $new = true;
1096 }
1097 if( $sem_id == 5419 && $cache_path != '' ) {
1098 $sem_id = crc32( $_SERVER[ 'HTTP_HOST' ] . $cache_path ) & 0x7fffffff;
1099 wp_cache_replace_line('sem_id', '$sem_id = ' . $sem_id . ';', $wp_cache_config_file);
1100 }
1101 require($wp_cache_config_file);
1102 return true;
1103 }
1104
1105 function wp_cache_create_advanced_cache() {
1106 global $wp_cache_link, $wp_cache_file;
1107 $ret = true;
1108
1109 $file = file_get_contents( $wp_cache_file );
1110 $file = str_replace( 'CACHEHOME', constant( 'WPCACHEHOME' ), $file );
1111 $fp = @fopen( $wp_cache_link, 'w' );
1112 if( $fp ) {
1113 fputs( $fp, $file );
1114 fclose( $fp );
1115 } else {
1116 $ret = false;
1117 }
1118 return $ret;
1119 }
1120
1121 function wp_cache_check_link() {
1122 global $wp_cache_link, $wp_cache_file;
1123
1124 $ret = true;
1125 if( file_exists($wp_cache_link) ) {
1126 $file = file_get_contents( $wp_cache_link );
1127 if( strpos( $file, "WP SUPER CACHE 0.8.9.1" ) ) {
1128 return true;
1129 } else {
1130 if( !@unlink($wp_cache_link) ) {
1131 $ret = false;
1132 } else {
1133 $ret = wp_cache_create_advanced_cache();
1134 }
1135 }
1136 } else {
1137 $ret = wp_cache_create_advanced_cache();
1138 }
1139
1140 if( false == $ret ) {
1141 echo "<h3>Warning! <em>" . constant( 'WP_CONTENT_DIR' ) . "/advanced-cache.php</em> does not exist or cannot be updated.</h3>";
1142 echo "<p><ul><li>1. If it already exists please delete the file first.</li>";
1143 echo "<li>2. Make " . constant( 'WP_CONTENT_DIR' ) . " writable using the chmod command through your ftp or server software. (<em>chmod 777 " . constant( 'WP_CONTENT_DIR' ) . "</em>) and refresh this page. This is only a temporary measure and you'll have to make it read only afterwards again. (Change 777 to 755 in the previous command)</li>";
1144 echo "<li>3. Refresh this page to update <em>" . constant( 'WP_CONTENT_DIR' ) . "/advanced-cache.php</em></li></ul>";
1145 echo "If that doesn't work, make sure the file <em>" . constant( 'WP_CONTENT_DIR' ) . "/advanced-cache.php</em> doesn't exist:<ol>";
1146 echo "<li>1. Open <em>$wp_cache_file</em> in a text editor.</li><li>2. Change the text <em>CACHEHOME</em> to <em>" . constant( 'WPCACHEHOME' ) . "</em></li><li>3. Save the file and copy it to <em>$wp_cache_link</em> and refresh this page.</li>";
1147 return false;
1148 }
1149 return true;
1150 }
1151
1152 function wp_cache_check_global_config() {
1153 if( defined( 'WP_CACHE' ) )
1154 return true;
1155
1156 if ( file_exists( ABSPATH . 'wp-config.php') ) {
1157 $global = ABSPATH . 'wp-config.php';
1158 } else {
1159 $global = dirname(ABSPATH) . '/wp-config.php';
1160 }
1161
1162 $howtoenable = "Edit <code>$global</code> and add the following line: <code>define('WP_CACHE', true);</code>Otherwise, <strong>WP-Cache will not be executed</strong> by Wordpress core. ";
1163 $lines = file($global);
1164 foreach($lines as $line) {
1165 if (preg_match('/^\s*define\s*\(\s*\'WP_CACHE\'\s*,\s*(?i:TRUE|1)\s*\)\s*;/', $line)) {
1166 echo $howtoenable;
1167 return false;
1168 }
1169 }
1170 $line = 'define(\'WP_CACHE\', true);';
1171 if (!is_writeable_ACLSafe($global) || !wp_cache_replace_line('define *\( *\'WP_CACHE\'', $line, $global) ) {
1172 echo "<strong>Error: WP_CACHE is not enabled</strong> in your <code>wp-config.php</code> file and I couldn't modify it.";
1173 echo $howtoenable;
1174 return false;
1175 }
1176 return true;
1177 }
1178
1179 function wp_cache_files() {
1180 global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled, $blog_cache_dir;
1181
1182 if ( '/' != substr($cache_path, -1)) {
1183 $cache_path .= '/';
1184 }
1185
1186 if ( $valid_nonce ) {
1187 if(isset($_REQUEST['wp_delete_cache'])) {
1188 wp_cache_clean_cache($file_prefix);
1189 }
1190 if(isset($_REQUEST['wp_delete_cache_file'])) {
1191 wp_cache_clean_cache($_REQUEST['wp_delete_cache_file']);
1192 }
1193 if(isset($_REQUEST['wp_delete_expired'])) {
1194 wp_cache_clean_expired($file_prefix);
1195 }
1196 }
1197 if(isset($_REQUEST['wp_list_cache'])) {
1198 $list_files = true;
1199 $list_mess = "Update list";
1200 } else
1201 $list_mess = "List files";
1202
1203 echo '<fieldset class="options" id="show-this-fieldset"><h3>Cache Contents</h3>';
1204 /*
1205 echo '<form name="wp_cache_content_list" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
1206 echo '<input type="hidden" name="wp_list_cache" />';
1207 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="'.$list_mess.' &raquo;" /></div>';
1208 echo "</form>\n";
1209 */
1210
1211 $list_files = false; // it doesn't list supercached files, and removing single pages is buggy
1212 $count = 0;
1213 $expired = 0;
1214 $now = time();
1215 if ( ($handle = @opendir( $blog_cache_dir . 'meta/' )) ) {
1216 if ($list_files) echo "<table cellspacing=\"0\" cellpadding=\"5\">";
1217 $wp_cache_fsize = 0;
1218 while ( false !== ($file = readdir($handle))) {
1219 if ( preg_match("/^$file_prefix.*\.meta/", $file) ) {
1220 $this_expired = false;
1221 $content_file = preg_replace("/meta$/", "html", $file);
1222 $mtime = filemtime( $blog_cache_dir . 'meta/' . $file );
1223 if ( ! ( $fsize = @filesize( $blog_cache_dir . $content_file ) ) )
1224 continue; // .meta does not exists
1225 $wp_cache_fsize += $fsize;
1226 $fsize = intval($fsize/1024);
1227 $age = $now - $mtime;
1228 if ( $age > $cache_max_time ) {
1229 $expired++;
1230 $this_expired = true;
1231 }
1232 $count++;
1233 /*
1234 if ($list_files) {
1235 $meta = new CacheMeta;
1236 $meta = unserialize(file_get_contents($cache_path . 'meta/' . $file));
1237 echo $flip ? '<tr style="background: #EAEAEA;">' : '<tr>';
1238 $flip = !$flip;
1239 echo '<td><a href="http://' . $meta->uri . '" target="_blank" >';
1240 echo $meta->uri . "</a></td>";
1241 if ($this_expired) echo "<td><span style='color:red'>$age secs</span></td>";
1242 else echo "<td>$age secs</td>";
1243 echo "<td>$fsize KB</td>";
1244 echo '<td><form name="wp_delete_cache_file" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
1245 echo '<input type="hidden" name="wp_list_cache" />';
1246 echo '<input type="hidden" name="wp_delete_cache_file" value="'.preg_replace("/^(.*)\.meta$/", "$1", $file).'" />';
1247 echo '<div class="submit"><input id="deletepost" ' . SUBMITDISABLED . 'type="submit" value="Remove" /></div>';
1248 wp_nonce_field('wp-cache');
1249 echo "</form></td></tr>\n";
1250 }
1251 */
1252 }
1253 }
1254 closedir($handle);
1255 if ($list_files) echo "</table>";
1256 }
1257 if( $wp_cache_fsize != 0 ) {
1258 $wp_cache_fsize = $wp_cache_fsize/1024;
1259 } else {
1260 $wp_cache_fsize = 0;
1261 }
1262 if( $wp_cache_fsize > 1024 ) {
1263 $wp_cache_fsize = number_format( $wp_cache_fsize / 1024, 2 ) . "MB";
1264 } elseif( $wp_cache_fsize != 0 ) {
1265 $wp_cache_fsize = number_format( $wp_cache_fsize, 2 ) . "KB";
1266 } else {
1267 $wp_cache_fsize = '0KB';
1268 }
1269 if( $cache_enabled == true && $super_cache_enabled == true ) {
1270 $now = time();
1271 $sizes = array( 'expired' => 0, 'cached' => 0, 'ts' => 0 );
1272
1273 if (is_dir($supercachedir)) {
1274 if( $dh = opendir( $supercachedir ) ) {
1275 while( ( $entry = readdir( $dh ) ) !== false ) {
1276 if ($entry != '.' && $entry != '..') {
1277 $sizes = wpsc_dirsize( trailingslashit( $supercachedir ) . $entry, $sizes );
1278 }
1279 }
1280 closedir($dh);
1281 }
1282 } else {
1283 if(is_file($supercachedir) && filemtime( $supercachedir ) + $cache_max_time <= $now )
1284 $sizes[ 'expired' ] ++;
1285 }
1286 $sizes[ 'ts' ] = time();
1287 }
1288
1289 echo "<p><strong>WP-Cache ({$wp_cache_fsize})</strong></p>";
1290 echo "<ul><li>$count Cached Pages</li>";
1291 echo "<li>$expired Expired Pages</li></ul>";
1292 if( $cache_enabled == true && $super_cache_enabled == true ) {
1293 $fsize = $sizes[ 'fsize' ] / 1024;
1294 if( $fsize > 1024 ) {
1295 $fsize = number_format( $fsize / 1024, 2 ) . "MB";
1296 } elseif( $fsize != 0 ) {
1297 $fsize = number_format( $fsize, 2 ) . "KB";
1298 } else {
1299 $fsize = "0KB";
1300 }
1301 echo "<p><strong>WP-Super-Cache ({$fsize})</strong></p>";
1302 echo "<ul><li>" . intval($sizes['cached']/2) . " Cached Pages</li>";
1303 $age = intval(($now - $sizes['ts'])/60);
1304 echo "<li>" . intval($sizes['expired']/2) . " Expired Pages</li></ul>";
1305 }
1306 $last_gc = get_option( "wpsupercache_gc_time" );
1307 if( $last_gc ) {
1308 $next_gc = $cache_max_time < 1800 ? $cache_max_time : 600;
1309 $next_gc_mins = ( time() - $last_gc );
1310 echo "<p><strong>Garbage Collection</strong><br />Last GC was <strong>" . date( 'i:s', $next_gc_mins ) . "</strong> minutes ago<br />";
1311 echo "Next GC in <strong>" . date( 'i:s', $next_gc - $next_gc_mins ) . "</strong> minutes</p>";
1312 }
1313
1314 echo "<p>Expired files are files older than $cache_max_time seconds. They are still used by the plugin and are deleted periodically.</p>";
1315 echo '<form name="wp_cache_content_expired" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
1316 echo '<input type="hidden" name="wp_delete_expired" />';
1317 echo '<div class="submit" style="float:left"><input type="submit" ' . SUBMITDISABLED . 'value="Delete Expired &raquo;" /></div>';
1318 wp_nonce_field('wp-cache');
1319 echo "</form>\n";
1320
1321 echo '<form name="wp_cache_content_delete" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
1322 echo '<input type="hidden" name="wp_delete_cache" />';
1323 echo '<div class="submit" style="float:left;margin-left:10px"><input id="deletepost" type="submit" ' . SUBMITDISABLED . 'value="Delete Cache &raquo;" /></div>';
1324 wp_nonce_field('wp-cache');
1325 echo "</form>\n";
1326
1327 echo '</fieldset>';
1328 }
1329
1330 function delete_cache_dashboard() {
1331 if( function_exists( 'is_site_admin' ) && !is_site_admin() )
1332 return false;
1333
1334 if( function_exists('current_user_can') && !current_user_can('manage_options') )
1335 return false;
1336
1337 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)'>Delete Cache</a></li>";
1338 }
1339 add_action( 'dashmenu', 'delete_cache_dashboard' );
1340
1341 function wpsc_dirsize($directory, $sizes) {
1342 global $cache_max_time;
1343 $now = time();
1344
1345 if (is_dir($directory)) {
1346 if( $dh = opendir( $directory ) ) {
1347 while( ( $entry = readdir( $dh ) ) !== false ) {
1348 if ($entry != '.' && $entry != '..') {
1349 $sizes = wpsc_dirsize( trailingslashit( $directory ) . $entry, $sizes );
1350 }
1351 }
1352 closedir($dh);
1353 }
1354 } else {
1355 if(is_file($directory) ) {
1356 if( filemtime( $directory ) + $cache_max_time <= $now ) {
1357 $sizes[ 'expired' ]+=1;
1358 } else {
1359 $sizes[ 'cached' ]+=1;
1360 }
1361 if ( ! isset( $sizes[ 'fsize' ] ) )
1362 $sizes[ 'fsize' ] = @filesize( $directory );
1363 else
1364 $sizes[ 'fsize' ] += @filesize( $directory );
1365 }
1366 }
1367 return $sizes;
1368 }
1369
1370
1371 function wp_cache_clean_cache($file_prefix) {
1372 global $cache_path, $supercachedir, $blog_cache_dir;
1373
1374 // If phase2 was compiled, use its function to avoid race-conditions
1375 if(function_exists('wp_cache_phase2_clean_cache')) {
1376 if (function_exists ('prune_super_cache')) {
1377 if( is_dir( $supercachedir ) ) {
1378 prune_super_cache( $supercachedir, true );
1379 } elseif( is_dir( $supercachedir . '.disabled' ) ) {
1380 prune_super_cache( $supercachedir . '.disabled', true );
1381 }
1382 prune_super_cache( $cache_path, true );
1383 $_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
1384 }
1385 return wp_cache_phase2_clean_cache($file_prefix);
1386 }
1387
1388 $expr = "/^$file_prefix/";
1389 if ( ($handle = @opendir( $blog_cache_dir )) ) {
1390 while ( false !== ($file = readdir($handle))) {
1391 if ( preg_match($expr, $file) ) {
1392 @unlink( $blog_cache_dir . $file);
1393 @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
1394 }
1395 }
1396 closedir($handle);
1397 }
1398 }
1399
1400 function wp_cache_clean_expired($file_prefix) {
1401 global $cache_path, $cache_max_time, $blog_cache_dir;
1402
1403 // If phase2 was compiled, use its function to avoid race-conditions
1404 if(function_exists('wp_cache_phase2_clean_expired')) {
1405 if (function_exists ('prune_super_cache')) {
1406 $dir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]);
1407 if( is_dir( $dir ) ) {
1408 prune_super_cache( $dir );
1409 } elseif( is_dir( $dir . '.disabled' ) ) {
1410 prune_super_cache( $dir . '.disabled' );
1411 }
1412 $_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
1413 }
1414 return wp_cache_phase2_clean_expired($file_prefix);
1415 }
1416
1417 $expr = "/^$file_prefix/";
1418 $now = time();
1419 if ( ($handle = @opendir( $blog_cache_dir )) ) {
1420 while ( false !== ($file = readdir($handle))) {
1421 if ( preg_match( $expr, $file ) &&
1422 ( filemtime( $blog_cache_dir . $file ) + $cache_max_time ) <= $now ) {
1423 @unlink( $blog_cache_dir . $file );
1424 @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
1425 }
1426 }
1427 closedir($handle);
1428 }
1429 }
1430
1431 function wpsc_remove_marker( $filename, $marker ) {
1432 if (!file_exists( $filename ) || is_writeable_ACLSafe( $filename ) ) {
1433 if (!file_exists( $filename ) ) {
1434 return '';
1435 } else {
1436 $markerdata = explode( "\n", implode( '', file( $filename ) ) );
1437 }
1438
1439 $f = fopen( $filename, 'w' );
1440 $foundit = false;
1441 if ( $markerdata ) {
1442 $state = true;
1443 foreach ( $markerdata as $n => $markerline ) {
1444 if (strpos($markerline, '# BEGIN ' . $marker) !== false)
1445 $state = false;
1446 if ( $state ) {
1447 if ( $n + 1 < count( $markerdata ) )
1448 fwrite( $f, "{$markerline}\n" );
1449 else
1450 fwrite( $f, "{$markerline}" );
1451 }
1452 if (strpos($markerline, '# END ' . $marker) !== false) {
1453 $state = true;
1454 }
1455 }
1456 }
1457 return true;
1458 } else {
1459 return false;
1460 }
1461 }
1462
1463 function wp_super_cache_footer() {
1464 ?><p id='supercache'><?php bloginfo('name'); ?> is Digg proof thanks to caching by <a href="http://ocaoimh.ie/wp-super-cache/">WP Super Cache</a>!</p><?php
1465 }
1466 if( isset( $wp_cache_hello_world ) && $wp_cache_hello_world )
1467 add_action( 'wp_footer', 'wp_super_cache_footer' );
1468
1469 if( get_option( 'gzipcompression' ) )
1470 update_option( 'gzipcompression', 0 );
1471
1472 // Catch 404 requests. Themes that use query_posts() destroy $wp_query->is_404
1473 function wp_cache_catch_404() {
1474 global $wp_cache_404;
1475 $wp_cache_404 = false;
1476 if( is_404() )
1477 $wp_cache_404 = true;
1478 }
1479 add_action( 'template_redirect', 'wp_cache_catch_404' );
1480
1481 function wp_cache_favorite_action( $actions ) {
1482 if( function_exists( 'is_site_admin' ) && !is_site_admin() )
1483 return $actions;
1484
1485 if( function_exists('current_user_can') && !current_user_can('manage_options') )
1486 return $actions;
1487
1488 $actions[ wp_nonce_url( 'options-general.php?page=wpsupercache&wp_delete_cache=1', 'wp-cache' ) ] = array( __( 'Delete Cache' ), 'manage_options' );
1489
1490 return $actions;
1491 }
1492 add_filter( 'favorite_actions', 'wp_cache_favorite_action' );
1493
1494 function wp_cache_plugin_notice( $plugin ) {
1495 global $cache_enabled;
1496 if( $plugin == 'wp-super-cache/wp-cache.php' && !$cache_enabled && function_exists( "admin_url" ) )
1497 echo '<td colspan="5" class="plugin-update">WP Super Cache must be configured. Go to <a href="' . admin_url( 'options-general.php?page=wpsupercache' ) . '">the admin page</a> to enable and configure the plugin.</td>';
1498 }
1499 add_action( 'after_plugin_row', 'wp_cache_plugin_notice' );
1500
1501 function wp_cache_plugin_actions( $links, $file ) {
1502 if( $file == 'wp-super-cache/wp-cache.php' && function_exists( "admin_url" ) ) {
1503 $settings_link = '<a href="' . admin_url( 'options-general.php?page=wpsupercache' ) . '">' . __('Settings') . '</a>';
1504 array_unshift( $links, $settings_link ); // before other links
1505 }
1506 return $links;
1507 }
1508 add_filter( 'plugin_action_links', 'wp_cache_plugin_actions', 10, 2 );
1509
1510 function wp_cache_admin_notice() {
1511 global $cache_enabled;
1512 if( substr( $_SERVER["PHP_SELF"], -11 ) == 'plugins.php' && !$cache_enabled && function_exists( "admin_url" ) )
1513 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.' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '</strong></p></div>';
1514 }
1515 add_action( 'admin_notices', 'wp_cache_admin_notice' );
1516 ?>
1517