PluginProbe ʕ •ᴥ•ʔ
WP Super Cache / 0.6.2
WP Super Cache v0.6.2
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 18 years ago Changelog.txt 18 years ago readme.txt 18 years ago wp-cache-base.php 18 years ago wp-cache-config-sample.php 18 years ago wp-cache-phase1.php 18 years ago wp-cache-phase2.php 18 years ago wp-cache.php 18 years ago
wp-cache.php
1080 lines
1 <?php
2 /*
3 Plugin Name: WP Super Cache
4 Plugin URI: http://ocaoimh.ie/wp-super-cache/
5 Description: Very fast caching module for WordPress. Once enabled, you must <a href="options-general.php?page=wp-super-cache/wp-cache.php">enable the cache</a>. Based on WP-Cache by <a href="http://mnm.uib.es/gallir/">Ricardo Galli Granada</a>.
6 Version: 0.6.2
7 Author: Donncha O Caoimh
8 Author URI: http://ocaoimh.ie/
9 */
10 /* Copyright 2005-2006 Ricardo Galli Granada (email : gallir@uib.es)
11 Some code copyright 2007-2008 Donncha O Caoimh (http://ocaoimh.ie/)
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 */
27
28 $wp_cache_config_file = ABSPATH . 'wp-content/wp-cache-config.php';
29
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
38 $wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
39 $wp_cache_link = ABSPATH . 'wp-content/advanced-cache.php';
40 $wp_cache_file = WPCACHEHOME . 'wp-cache-phase1.php';
41
42 include(WPCACHEHOME . 'wp-cache-base.php');
43
44 function get_wpcachehome() {
45 if( defined( 'WPCACHEHOME' ) == false ) {
46 if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
47 define( 'WPCACHEHOME', trailingslashit( dirname(__FILE__) ) );
48 } elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
49 define( 'WPCACHEHOME', dirname(__FILE__) . '/wp-super-cache/' );
50 } else {
51 die( 'Please create wp-content/wp-cache-config.php from wp-super-cache/wp-cache-config-sample.php' );
52 }
53 }
54 }
55
56 function wp_cache_add_pages() {
57 if( function_exists( 'is_site_admin' ) ) {
58 if( is_site_admin() ) {
59 add_submenu_page('wpmu-admin.php', __('WP Super Cache'), __('WP Super Cache'), 'manage_options', __FILE__, 'wp_cache_manager');
60 add_options_page('WP Super Cache', 'WP Super Cache', 'manage_options', __FILE__, 'wp_cache_manager');
61 }
62 } else {
63 add_options_page('WP Super Cache', 'WP Super Cache', 'manage_options', __FILE__, 'wp_cache_manager');
64 }
65 }
66
67 function wp_cache_manager() {
68 global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled, $wp_cache_hello_world;
69
70 if( function_exists( 'is_site_admin' ) )
71 if( !is_site_admin() )
72 return;
73
74 $supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]);
75 if( get_option( 'gzipcompression' ) == 1 )
76 update_option( 'gzipcompression', 0 );
77 $valid_nonce = wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache');
78 /* http://www.netlobo.com/div_hiding.html */
79 ?>
80 <script type='text/javascript'>
81 <!--
82 function toggleLayer( whichLayer ) {
83 var elem, vis;
84 if( document.getElementById ) // this is the way the standards work
85 elem = document.getElementById( whichLayer );
86 else if( document.all ) // this is the way old msie versions work
87 elem = document.all[whichLayer];
88 else if( document.layers ) // this is the way nn4 works
89 elem = document.layers[whichLayer];
90 vis = elem.style;
91 // if the style.display value is blank we try to figure it out here
92 if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
93 vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
94 vis.display = (vis.display==''||vis.display=='block')?'none':'block';
95 }
96 // -->
97 </script>
98 <?php
99 echo '<div class="wrap">';
100 echo "<h2>WP Super Cache Manager</h2>\n";
101 if( ini_get( 'safe_mode' ) ) {
102 ?><h3>Warning! PHP safe mode enabled!</h3>
103 <p>You may experience problems running this plugin because SAFE MODE is enabled. <?php
104 if( !ini_get( 'safe_mode_gid' ) ) {
105 ?>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 wp-content/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
106 } else {
107 ?>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
108 }
109 }
110 if(isset($_REQUEST['wp_restore_config']) && $valid_nonce) {
111 unlink($wp_cache_config_file);
112 echo '<strong>Configuration file changed, some values might be wrong. Load the page again from the "Options" menu to reset them.</strong>';
113 }
114
115 if ( !wp_cache_check_link() ||
116 !wp_cache_verify_config_file() ||
117 !wp_cache_verify_cache_dir() ) {
118 echo "<br>Cannot continue... fix previous problems and retry.<br />";
119 echo "</div>\n";
120 return;
121 }
122
123 if (!wp_cache_check_global_config()) {
124 echo "</div>\n";
125 return;
126 }
127
128 if( $cache_enabled == true && $super_cache_enabled == true && !got_mod_rewrite() ) {
129 ?><h4 style='color: #a00'>Mod rewrite may not be installed!</h4>
130 <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
131 }
132
133 if( !is_writeable( ABSPATH . 'wp-content/' ) || !is_writable($wp_cache_config_file) ) {
134 define( "SUBMITDISABLED", 'disabled style="color: #aaa" ' );
135 ?><h4 style='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>
136 <div id='readonlywarning' style='border: 1px solid #aaa; margin: 2px; padding: 2px; display: none;'>
137 <p>The WP Super Cache configuration file is <code><?php echo ABSPATH ?>wp-content/wp-cache-config.php</code> and cannot be modified. The wp-content directory and wp-cache-config.php file must be writeable by the webserver to make any changes.<br />
138 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.<br />
139 Writeable: <code>chmod 777 wp-content; chmod 666 wp-content/wp-cache-config.php</code><br />
140 Readonly: <code>chmod 755 wp-content; chmod 644 wp-content/wp-cache-config.php</code></p>
141 </div><?php
142 } else {
143 define( "SUBMITDISABLED", ' ' );
144 }
145
146 if ( $valid_nonce ) {
147 if( isset( $_POST[ 'wp_cache_status' ] ) ) {
148 switch( $_POST[ 'wp_cache_status' ] ) {
149 case 'all':
150 wp_cache_enable();
151 break;
152 case 'none':
153 wp_cache_disable();
154 break;
155 case 'wpcache':
156 wp_cache_enable();
157 wp_super_cache_disable();
158 break;
159 }
160 if( isset( $_POST[ 'wp_cache_hello_world' ] ) ) {
161 $wp_cache_hello_world = (int)$_POST[ 'wp_cache_hello_world' ];
162 } else {
163 $wp_cache_hello_world = 0;
164 }
165 wp_cache_replace_line('^ *\$wp_cache_hello_world', '$wp_cache_hello_world = ' . (int)$wp_cache_hello_world . ";", $wp_cache_config_file);
166 }
167 if( isset( $_POST[ 'cache_compression' ] ) && $_POST[ 'cache_compression' ] != $cache_compression ) {
168 $cache_compression_changed = true;
169 $cache_compression = intval( $_POST[ 'cache_compression' ] );
170 wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
171 if( function_exists( 'prune_super_cache' ) )
172 prune_super_cache ($cache_path, true);
173 delete_option( 'super_cache_meta' );
174 }
175 }
176
177 ?><fieldset style='border: 1px solid #aaa' class="options">
178 <legend>WP Super Cache Status</legend><?php
179 echo '<form name="wp_manager" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
180 ?>
181 <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> (WP Cache and Super Cache enabled)</label><br />
182 <label><input type='radio' name='wp_cache_status' value='none' <?php if( $cache_enabled == false ) { echo 'checked=checked'; } ?>> <strong>OFF</strong> (WP Cache and Super Cache disabled)</label><br />
183 <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> (Super Cache Disabled)</label><br />
184 <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>
185 <?php
186 echo "<div class='submit'><input " . SUBMITDISABLED . "type='submit' value='Update Status &raquo;' /></div>";
187 wp_nonce_field('wp-cache');
188 ?>
189 </form>
190 </fieldset>
191
192 <?php if( $cache_enabled == true && $super_cache_enabled == true ) { ?>
193 <br /><fieldset style='border: 1px solid #aaa' class="options">
194 <legend>Super Cache Compression</legend>
195 <form name="wp_manager" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post">
196 <label><input type="radio" name="cache_compression" value="1" <?php if( $cache_compression ) { echo "checked=checked"; } ?>> Enabled</label>
197 <label><input type="radio" name="cache_compression" value="0" <?php if( !$cache_compression ) { echo "checked=checked"; } ?>> Disabled</label>
198 <p>Compression is disabled by default because some hosts have problems with compressed files. Switching this on and off clears the cache.</p>
199 <?php
200 if( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && !$cache_compression ) {
201 ?><p><strong>Super Cache compression is now disabled.</strong></p> <?php
202 } elseif( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && $cache_compression ) {
203 ?><p><strong>Super Cache compression is now enabled.</strong></p><?php
204 }
205 echo '<div class="submit"><input ' . SUBMITDISABLED . 'type="submit" value="Update Compression &raquo;" /></div>';
206 wp_nonce_field('wp-cache');
207 echo "</form>\n";
208 ?></fieldset><br />
209
210 <fieldset style='border: 1px solid #aaa' class="options">
211 <legend>Mod Rewrite Rules</legend><?php
212 $home_path = get_home_path();
213 $home_root = parse_url(get_option('home'));
214 $home_root = trailingslashit($home_root['path']);
215 $wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) );
216 $wprules = str_replace( "RewriteEngine On\n", '', $wprules );
217 $wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
218 $scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
219
220 $dohtaccess = true;
221 if( !$wprules || $wprules == '' ) {
222 echo "<h4 style='color: #a00'>Mod Rewrite rules cannot be updated!</h4>";
223 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:
224 <blockquote><code><em># BEGIN WordPress</em><br /> RewriteCond %{REQUEST_FILENAME} !-f<br /> RewriteCond %{REQUEST_FILENAME} !-d<br /> RewriteRule . /index.php [L]<br /> <em># END WordPress</em></code></blockquote>
225 Refresh this page when you have updated your .htaccess file.";
226 } elseif( strpos( $wprules, 'wordpressuser' ) ) { // Need to clear out old mod_rewrite rules
227 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 change is '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>";
228 echo "</fieldset>";
229 echo "</div>\n";
230 return;
231 } elseif( strpos( $scrules, 'supercache' ) || strpos( $wprules, 'supercache' ) ) { // only write the rules once
232 $dohtaccess = false;
233 }
234 $rules = "<IfModule mod_rewrite.c>\n";
235 $rules .= "RewriteEngine On\n";
236 $rules .= "RewriteBase $home_root\n"; // props Chris Messina
237 $rules .= "RewriteCond %{QUERY_STRING} !.*s=.*\n";
238 $rules .= "RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$\n";
239 $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
240 $rules .= "RewriteCond %{DOCUMENT_ROOT}{$home_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz -f\n";
241 $rules .= "RewriteRule ^(.*) {$home_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz [L]\n\n";
242
243 $rules .= "RewriteCond %{QUERY_STRING} !.*s=.*\n";
244 $rules .= "RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$\n";
245 $rules .= "RewriteCond %{DOCUMENT_ROOT}{$home_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html -f\n";
246 $rules .= "RewriteRule ^(.*) {$home_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html [L]\n";
247 $rules .= "</IfModule>\n";
248 if( $dohtaccess && !$_POST[ 'updatehtaccess' ] ) {
249 echo "<p>In order to serve static html files your server must have the correct mod_rewrite rules added to a file called <code>" . ABSPATH . ".htaccess</code><br /> This can be done automatically by clicking the <em>'Update mod_rewrite rules &raquo;'</em> button or you can edit the file yourself and add the following rules. Make sure they appear before any existing WordPress rules.";
250 echo "<pre>" . wp_specialchars( $rules ) . "</pre></p>";
251 echo '<form name="updatehtaccess" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
252 echo '<input type="hidden" name="updatehtaccess" value="1" />';
253 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'id="updatehtaccess" value="Update mod_rewrite rules &raquo;" /></div>';
254 wp_nonce_field('wp-cache');
255 echo "</form>\n";
256 } elseif( $dohtaccess && $valid_nonce && $_POST[ 'updatehtaccess' ] ) {
257 wpsc_remove_marker( $home_path.'.htaccess', 'WordPress' ); // remove original WP rules so SuperCache rules go on top
258 if( insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', explode( "\n", $rules ) ) && insert_with_markers( $home_path.'.htaccess', 'WordPress', explode( "\n", $wprules ) ) ) {
259 echo "<h4>Mod Rewrite rules updated!</h4>";
260 echo "<p><strong>" . ABSPATH . ".htaccess has been updated with the necessary mod_rewrite rules. Please verify they are correct. They should look like this:</strong></p>\n";
261 } else {
262 echo "<h4>Mod Rewrite rules must be updated!</h4>";
263 echo "<p><strong> Your " . ABSPATH . ".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";
264 }
265 echo "<p><pre>" . wp_specialchars( $rules ) . "</pre></p>\n";
266 } else {
267 ?>
268 <p>WP Super Cache has modified your <?php echo ABSPATH ?>.htaccess file. Click the following link to see the lines added. If you have upgraded the plugin make sure these rules match. <a href="javascript:toggleLayer('rewriterules');" title="See your mod_rewrite rules">View mod_rewrite rules</a>
269 <div id='rewriterules' style='display: none;'>
270 <?php echo "<p><pre>" . wp_specialchars( $rules ) . "</pre></p>\n"; ?>
271 </div>
272 <?php
273 }
274 // http://allmybrain.com/2007/11/08/making-wp-super-cache-gzip-compression-work/
275 if( !is_file( $cache_path . '.htaccess' ) ) {
276 $gziprules = "AddEncoding x-gzip .gz\n";
277 $gziprules .= "AddType text/html .gz";
278 $gziprules = insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $gziprules ) );
279 echo "<h4>Gzip encoding rules in {$cache_path}.htaccess created.</h4>";
280 }
281
282 ?></fieldset><?php
283
284 } // if $super_cache_enabled
285
286 wp_cache_edit_max_time();
287
288 echo '<br /><a name="files"></a><fieldset style="border: 1px solid #aaa" class="options"><legend>Accepted filenames, rejected URIs</legend>';
289 wp_cache_edit_rejected();
290 echo "<br />\n";
291 wp_cache_edit_accepted();
292 echo '</fieldset>';
293
294 wp_cache_edit_rejected_ua();
295
296
297 wp_cache_files();
298
299 wp_lock_down();
300
301 wp_cache_restore();
302
303 ob_start();
304 if( defined( 'WP_CACHE' ) ) {
305 if( function_exists( 'do_cacheaction' ) ) {
306 do_cacheaction( 'cache_admin_page' );
307 }
308 }
309 $out = ob_get_contents();
310 ob_end_clean();
311 if( SUBMITDISABLED == ' ' && $out != '' ) {
312 echo '<fieldset class="options"><legend>Cache Plugins</legend>';
313 echo $out;
314 echo '</fieldset>';
315 }
316
317 echo "</div>\n";
318
319 }
320
321 function wp_cache_restore() {
322 echo '<br /><fieldset style="border: 1px solid #aaa" class="options"><legend>Configuration messed up?</legend>';
323 echo '<form name="wp_restore" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
324 echo '<input type="hidden" name="wp_restore_config" />';
325 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'id="deletepost" value="Restore default configuration &raquo;" /></div>';
326 wp_nonce_field('wp-cache');
327 echo "</form>\n";
328 echo '</fieldset>';
329
330 }
331
332 function comment_form_lockdown_message() {
333 ?><p><?php _e( "Comment moderation is enabled. Your comment may take some time to appear." ); ?></p><?php
334 }
335 if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) )
336 add_action( 'comment_form', 'comment_form_lockdown_message' );
337
338 function wp_lock_down() {
339 global $wpdb, $cache_path, $wp_cache_config_file, $valid_nonce, $cached_direct_pages, $cache_enabled, $super_cache_enabled;
340
341 if(isset($_POST['wp_lock_down']) && $valid_nonce) {
342 $wp_lock_down = $_POST['wp_lock_down'] == '1' ? '1' : '0';
343 wp_cache_replace_line('^.*WPLOCKDOWN', "define( 'WPLOCKDOWN', '$wp_lock_down' );", $wp_cache_config_file);
344 if( $wp_lock_down == '0' && function_exists( 'prune_super_cache' ) )
345 prune_super_cache( $cache_path, true ); // clear the cache after lockdown
346
347 }
348 if( !isset( $wp_lock_down ) ) {
349 if( defined( 'WPLOCKDOWN' ) ) {
350 $wp_lock_down = constant( 'WPLOCKDOWN' );
351 } else {
352 $wp_lock_down = '0';
353 }
354 }
355 ?><br /><br /><fieldset style='border: 1px solid #aaa' class="options">
356 <legend>Lock Down: <span style='color: #f00'><?php echo $wp_lock_down == '0' ? 'disabled' : 'enabled'; ?></span> (advanced use only)</legend>
357 <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>
358 <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.
359 <blockquote><code>if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) ) { <br />
360 &nbsp;&nbsp;&nbsp;&nbsp;echo "Sorry. My blog is locked down. Updates will appear shortly";<br />
361 }</code></blockquote>
362 <?php
363 if( $wp_lock_down == '1' ) {
364 ?><strong>WordPress is locked down. Super Cache static files will not be deleted when new comments are made.</strong><?php
365 } else {
366 ?><strong>WordPress is not locked down. New comments will refresh Super Cache static files as normal.</strong><?php
367 }
368 $new_lockdown = $wp_lock_down == '1' ? '0' : '1';
369 $new_lockdown_desc = $wp_lock_down == '1' ? 'Disable' : 'Enable';
370 echo '<form name="wp_lock_down" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
371 echo "<input type='hidden' name='wp_lock_down' value='{$new_lockdown}' />";
372 echo "<div class='submit'><input type='submit' " . SUBMITDISABLED . "value='{$new_lockdown_desc} Lock Down &raquo;' /></div>";
373 wp_nonce_field('wp-cache');
374 echo "</form>\n";
375
376 ?></fieldset><br /><?php
377 if( $cache_enabled == true && $super_cache_enabled == true ) {
378 ?><fieldset style='border: 1px solid #aaa' class="options">
379 <legend>Directly Cached Files (advanced use only)</legend><?php
380
381 $out = '';
382 if( $valid_nonce && is_array( $_POST[ 'direct_pages' ] ) && !empty( $_POST[ 'direct_pages' ] ) ) {
383 $expiredfiles = array_diff( $cached_direct_pages, $_POST[ 'direct_pages' ] );
384 unset( $cached_direct_pages );
385 foreach( $_POST[ 'direct_pages' ] as $page ) {
386 $page = $wpdb->escape( $page );
387 if( $page != '' ) {
388 $cached_direct_pages[] = $page;
389 $out .= "'$page', ";
390 }
391 }
392 if( $out == '' ) {
393 $out = "'', ";
394 }
395 }
396 if( $valid_nonce && $_POST[ 'new_direct_page' ] && '' != $_POST[ 'new_direct_page' ] ) {
397 $page = str_replace( get_option( 'siteurl' ), '', $_POST[ 'new_direct_page' ] );
398 if( substr( $page, 0, 1 ) != '/' )
399 $page = '/' . $page;
400 $page = $wpdb->escape( $page );
401 if( in_array( $page, $cached_direct_pages ) == false ) {
402 $cached_direct_pages[] = $page;
403 $out .= "'$page', ";
404 }
405 }
406
407 if( $out != '' ) {
408 $out = substr( $out, 0, -2 );
409 $out = '$cached_direct_pages = array( ' . $out . ' );';
410 wp_cache_replace_line('^ *\$cached_direct_pages', "$out", $wp_cache_config_file);
411 prune_super_cache( $cache_path, true );
412 }
413
414 if( !empty( $expiredfiles ) ) {
415 foreach( $expiredfiles as $file ) {
416 if( $file != '' ) {
417 $firstfolder = explode( '/', $file );
418 $firstfolder = ABSPATH . $firstfolder[1];
419 $file = ABSPATH . $file;
420 @unlink( trailingslashit( $file ) . 'index.html' );
421 @unlink( trailingslashit( $file ) . 'index.html.gz' );
422 RecursiveFolderDelete( trailingslashit( $firstfolder ) );
423 }
424 }
425 }
426
427 if( $valid_nonce && $_POST[ 'deletepage' ] ) {
428 $page = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_POST['deletepage']) );
429 $pagefile = ABSPATH . $page . 'index.html';
430 $firstfolder = explode( '/', $page );
431 $firstfolder = ABSPATH . $firstfolder[1];
432 $page = ABSPATH . $page;
433 if( is_file( $pagefile ) && is_writable( $pagefile ) && is_writable( $firstfolder ) ) {
434 @unlink( $pagefile );
435 @unlink( $pagefile . '.gz' );
436 RecursiveFolderDelete( $firstfolder );
437 echo "<strong>$pagefile removed!</strong><br />";
438 prune_super_cache( $cache_path, true );
439 }
440 }
441
442 $readonly = '';
443 if( !is_writeable( ABSPATH ) ) {
444 $readonly = 'READONLY';
445 ?><p><strong style='color: #a00'>WARNING! 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.</strong></p><?php
446 } else {
447 ?><p><strong style='color: #a00'>WARNING! <?php echo ABSPATH ?> is writable. Please make it readonly after your page is generated as this is a security risk.</strong></p><?php
448 }
449 echo '<form name="direct_page" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
450 if( is_array( $cached_direct_pages ) ) {
451 $out = '';
452 foreach( $cached_direct_pages as $page ) {
453 if( $page == '' )
454 continue;
455 $generated = '';
456 if( is_file( ABSPATH . $page . '/index.html' ) )
457 $generated = '<input type="Submit" name="deletepage" value="' . $page . '">';
458 $out .= "<tr><td><input type='text' $readonly name='direct_pages[]' size='30' value='$page' /></td><td>$generated</td></tr>";
459 }
460 if( $out != '' ) {
461 ?><table><tr><th>Existing direct page</th><th>Delete cached file</th></tr><?php
462 echo "$out</table>";
463 }
464 }
465 if( $readonly != 'READONLY' )
466 echo "Add direct page: <input type='text' $readonly name='new_direct_page' size='30' value='' /><br />";
467
468 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>";
469 if( $readonly != 'READONLY' ) {
470 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>";
471 echo "<p>Make the textbox blank to remove it from the list of direct pages and delete the cached file.</p>";
472 }
473
474 wp_nonce_field('wp-cache');
475 if( $readonly != 'READONLY' )
476 echo "<div class='submit'><input type='submit' ' . SUBMITDISABLED . 'value='Update direct pages &raquo;' /></div>";
477 echo "</form>\n";
478 ?></fieldset><?php
479 } // if $super_cache_enabled
480 }
481
482 function RecursiveFolderDelete ( $folderPath ) { // from http://www.php.net/manual/en/function.rmdir.php
483 if( trailingslashit( constant( 'ABSPATH' ) ) == trailingslashit( $folderPath ) )
484 return false;
485 if ( @is_dir ( $folderPath ) ) {
486 $dh = @opendir($folderPath);
487 while (false !== ($value = @readdir($dh))) {
488 if ( $value != "." && $value != ".." ) {
489 $value = $folderPath . "/" . $value;
490 if ( @is_dir ( $value ) ) {
491 RecursiveFolderDelete ( $value );
492 }
493 }
494 }
495 return @rmdir ( $folderPath );
496 } else {
497 return FALSE;
498 }
499 }
500
501 function wp_cache_edit_max_time () {
502 global $super_cache_max_time, $cache_max_time, $wp_cache_config_file, $valid_nonce, $cache_enabled, $super_cache_enabled;
503
504 if( !isset( $super_cache_max_time ) )
505 $super_cache_max_time = 21600;
506
507 if(isset($_POST['wp_max_time']) && $valid_nonce) {
508 $max_time = (int)$_POST['wp_max_time'];
509 if ($max_time > 0) {
510 $cache_max_time = $max_time;
511 wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file);
512 }
513 }
514 if(isset($_POST['super_cache_max_time']) && $valid_nonce) {
515 $max_time = (int)$_POST['super_cache_max_time'];
516 if ($max_time > 0) {
517 $super_cache_max_time = $max_time;
518 wp_cache_replace_line('^ *\$super_cache_max_time', "\$super_cache_max_time = $super_cache_max_time;", $wp_cache_config_file);
519 }
520 }
521 ?><br /><fieldset style='border: 1px solid #aaa' class="options">
522 <legend>Expiry Time</legend><?php
523 echo '<form name="wp_edit_max_time" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
524 echo '<label for="wp_max_time">Expire time:</label> ';
525 echo "<input type=\"text\" size=6 name=\"wp_max_time\" value=\"$cache_max_time\" /> seconds<br />";
526 if( $cache_enabled == true && $super_cache_enabled == true ) {
527 echo '<label for="super_cache_max_time">Super Cache Expire time:</label> ';
528 echo "<input type=\"text\" size=6 name=\"super_cache_max_time\" value=\"$super_cache_max_time\" /> seconds";
529 }
530 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Change expiration &raquo;" /></div>';
531 wp_nonce_field('wp-cache');
532 echo "</form>\n";
533 ?></fieldset><?php
534 }
535
536 function wp_cache_sanitize_value($text, & $array) {
537 $text = wp_specialchars(strip_tags($text));
538 $array = preg_split("/[\s,]+/", chop($text));
539 $text = var_export($array, true);
540 $text = preg_replace('/[\s]+/', ' ', $text);
541 return $text;
542 }
543
544 function wp_cache_edit_rejected_ua() {
545 global $cache_rejected_user_agent, $wp_cache_config_file, $valid_nonce;
546
547 if (!function_exists('apache_request_headers')) return;
548
549 if(isset($_REQUEST['wp_rejected_user_agent']) && $valid_nonce) {
550 $text = wp_cache_sanitize_value($_REQUEST['wp_rejected_user_agent'], $cache_rejected_user_agent);
551 wp_cache_replace_line('^ *\$cache_rejected_user_agent', "\$cache_rejected_user_agent = $text;", $wp_cache_config_file);
552 }
553
554
555 echo '<br /><a name="user-agents"></a><fieldset style="border: 1px solid #aaa" class="options"><legend>Rejected User Agents</legend>';
556 echo "<p>Strings in the HTTP 'User Agent' header that prevent WP-Cache from
557 caching bot, spiders, and crawlers' requests.
558 Note that cached files are still sent to these request if they already exists.</p>\n";
559 echo '<form name="wp_edit_rejected_user_agent" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
560 echo '<label for="wp_rejected_user_agent">Rejected UA strings</label>';
561 echo '<textarea name="wp_rejected_user_agent" cols="40" rows="4" style="width: 70%; font-size: 12px;" class="code">';
562 foreach ($cache_rejected_user_agent as $ua) {
563 echo wp_specialchars($ua) . "\n";
564 }
565 echo '</textarea> ';
566 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Save UA strings &raquo;" /></div>';
567 wp_nonce_field('wp-cache');
568 echo '</form>';
569 echo "</fieldset>\n";
570 }
571
572
573 function wp_cache_edit_rejected() {
574 global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file, $valid_nonce;
575
576 if(isset($_REQUEST['wp_rejected_uri']) && $valid_nonce) {
577 $text = wp_cache_sanitize_value($_REQUEST['wp_rejected_uri'], $cache_rejected_uri);
578 wp_cache_replace_line('^ *\$cache_rejected_uri', "\$cache_rejected_uri = $text;", $wp_cache_config_file);
579 }
580
581
582 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";
583 echo '<form name="wp_edit_rejected" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
584 echo '<label for="wp_rejected_uri">Rejected URIs</label>';
585 echo '<textarea name="wp_rejected_uri" cols="40" rows="4" style="width: 70%; font-size: 12px;" class="code">';
586 foreach ($cache_rejected_uri as $file) {
587 echo wp_specialchars($file) . "\n";
588 }
589 echo '</textarea> ';
590 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Save strings &raquo;" /></div>';
591 wp_nonce_field('wp-cache');
592 echo "</form>\n";
593 }
594
595 function wp_cache_edit_accepted() {
596 global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file, $valid_nonce;
597
598 if(isset($_REQUEST['wp_accepted_files']) && $valid_nonce) {
599 $text = wp_cache_sanitize_value($_REQUEST['wp_accepted_files'], $cache_acceptable_files);
600 wp_cache_replace_line('^ *\$cache_acceptable_files', "\$cache_acceptable_files = $text;", $wp_cache_config_file);
601 }
602
603
604 echo "<p>Add here those filenames that can be cached, even if they match one of the rejected substring specified above.</p>\n";
605 echo '<form name="wp_edit_accepted" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
606 echo '<label for="wp_accepted_files">Accepted files</label>';
607 echo '<textarea name="wp_accepted_files" cols="40" rows="8" style="width: 70%; font-size: 12px;" class="code">';
608 foreach ($cache_acceptable_files as $file) {
609 echo wp_specialchars($file) . "\n";
610 }
611 echo '</textarea> ';
612 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Save files &raquo;" /></div>';
613 wp_nonce_field('wp-cache');
614 echo "</form>\n";
615 }
616
617 function wp_cache_enable() {
618 global $wp_cache_config_file, $cache_enabled, $supercachedir;
619
620 if(get_option('gzipcompression')) {
621 echo "<b>Error: GZIP compression is enabled, disable it if you want to enable wp-cache.</b><br /><br />";
622 return false;
623 }
624 if( wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = true;', $wp_cache_config_file) ) {
625 $cache_enabled = true;
626 }
627 wp_super_cache_enable();
628 }
629
630 function wp_cache_disable() {
631 global $cache_path, $wp_cache_config_file, $cache_enabled, $supercachedir, $cache_path;
632
633 if (wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file)) {
634 $cache_enabled = false;
635 }
636 wp_super_cache_disable();
637 sleep( 1 ); // allow existing processes to write to the supercachedir and then delete it
638 if (function_exists ('prune_super_cache') && is_dir( $supercachedir ) ) {
639 prune_super_cache( $cache_path, true );
640 }
641 }
642 function wp_super_cache_enable() {
643 global $supercachedir, $wp_cache_config_file, $super_cache_enabled;
644
645 if( is_dir( $supercachedir . ".disabled" ) )
646 rename( $supercachedir . ".disabled", $supercachedir );
647 wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = true;', $wp_cache_config_file);
648 $super_cache_enabled = true;
649 }
650
651 function wp_super_cache_disable() {
652 global $supercachedir, $wp_cache_config_file, $super_cache_enabled;
653
654 wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = false;', $wp_cache_config_file);
655 if( is_dir( $supercachedir ) )
656 rename( $supercachedir, $supercachedir . ".disabled" );
657 $super_cache_enabled = false;
658 }
659
660 function wp_cache_is_enabled() {
661 global $wp_cache_config_file;
662
663 if(get_option('gzipcompression')) {
664 echo "<b>Warning</b>: GZIP compression is enabled in Wordpress, wp-cache will be bypassed until you disable gzip compression.<br />";
665 return false;
666 }
667 $lines = file($wp_cache_config_file);
668 foreach($lines as $line) {
669 if (preg_match('/^ *\$cache_enabled *= *true *;/', $line))
670 return true;
671 }
672 return false;
673 }
674
675
676 function wp_cache_replace_line($old, $new, $my_file) {
677 if (!is_writable($my_file)) {
678 echo "Error: file $my_file is not writable.<br />\n";
679 return false;
680 }
681 $found = false;
682 $lines = file($my_file);
683 foreach($lines as $line) {
684 if ( preg_match("/$old/", $line)) {
685 $found = true;
686 break;
687 }
688 }
689 if ($found) {
690 $fd = fopen($my_file, 'w');
691 foreach($lines as $line) {
692 if ( !preg_match("/$old/", $line))
693 fputs($fd, $line);
694 else {
695 fputs($fd, "$new //Added by WP-Cache Manager\n");
696 }
697 }
698 fclose($fd);
699 return true;
700 }
701 $fd = fopen($my_file, 'w');
702 $done = false;
703 foreach($lines as $line) {
704 if ( $done || !preg_match('/^define|\$|\?>/', $line))
705 fputs($fd, $line);
706 else {
707 fputs($fd, "$new //Added by WP-Cache Manager\n");
708 fputs($fd, $line);
709 $done = true;
710 }
711 }
712 fclose($fd);
713 return true;
714 /*
715 copy($my_file, $my_file . "-prev");
716 rename($my_file . '-new', $my_file);
717 */
718 }
719
720 function wp_cache_verify_cache_dir() {
721 global $cache_path;
722
723 $dir = dirname($cache_path);
724 if ( !file_exists($cache_path) ) {
725 if ( !is_writable( $dir ) || !($dir = mkdir( $cache_path ) ) ) {
726 echo "<b>Error:</b> Your cache directory (<b>$cache_path</b>) did not exist and couldn't be created by the web server. <br /> Check $dir permissions.";
727 return false;
728 }
729 }
730 if ( !is_writable($cache_path)) {
731 echo "<b>Error:</b> Your cache directory (<b>$cache_path</b>) or <b>$dir</b> need to be writable for this plugin to work. <br /> Double-check it.";
732 return false;
733 }
734
735 if ( '/' != substr($cache_path, -1)) {
736 $cache_path .= '/';
737 }
738
739 @mkdir( $cache_path . 'meta' );
740
741 return true;
742 }
743
744 function wp_cache_verify_config_file() {
745 global $wp_cache_config_file, $wp_cache_config_file_sample;
746
747 $new = false;
748 $dir = dirname($wp_cache_config_file);
749
750 if ( file_exists($wp_cache_config_file) ) {
751 $lines = join( ' ', file( $wp_cache_config_file ) );
752 if( strpos( $lines, 'WPCACHEHOME' ) === false ) {
753 if( is_writable( $wp_cache_config_file ) ) {
754 @unlink( $wp_cache_config_file );
755 } else {
756 echo "<b>Error:</b> Your WP-Cache config file (<b>$wp_cache_config_file</b>) is out of date and not writable by the Web server.<br />Please delete it and refresh this page.";
757 return false;
758 }
759 }
760 } elseif( !is_writable($dir)) {
761 echo "<b>Error:</b> Configuration file missing and wp-content directory (<b>$dir</b>) is not writable by the Web server.<br />Check its permissions.";
762 return false;
763 }
764
765 if ( !file_exists($wp_cache_config_file) ) {
766 if ( !file_exists($wp_cache_config_file_sample) ) {
767 echo "<b>Error:</b> Sample WP-Cache config file (<b>$wp_cache_config_file_sample</b>) does not exist.<br />Verify you installation.";
768 return false;
769 }
770 copy($wp_cache_config_file_sample, $wp_cache_config_file);
771 if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
772 wp_cache_replace_line('WPCACHEHOME', "define( 'WPCACHEHOME', ABSPATH . " . str_replace( '\\', '/', str_replace( ABSPATH, ' "', dirname(__FILE__) ) ) . "/\" );", $wp_cache_config_file);
773 } elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
774 wp_cache_replace_line('WPCACHEHOME', "define( 'WPCACHEHOME', ABSPATH . " . str_replace( '\\', '/', str_replace( ABSPATH, ' "', dirname(__FILE__) ) ) . "/wp-super-cache/\" );", $wp_cache_config_file);
775 }
776 $new = true;
777 }
778 require($wp_cache_config_file);
779 return true;
780 }
781
782 function wp_cache_check_link() {
783 global $wp_cache_link, $wp_cache_file;
784
785 if( file_exists($wp_cache_link) ) {
786 if( strpos( join( "\n", file( $wp_cache_link ) ), 'WPCACHEHOME' ) ) {
787 // read the file and verify it's a super-cache file and not the wp-cache one.
788 return true;
789 } else {
790 // remove the old version
791 @unlink($wp_cache_link);
792 }
793 }
794
795 $ret = true;
796 if ( basename(@readlink($wp_cache_link)) != basename($wp_cache_file)) {
797 @unlink($wp_cache_link);
798 if( function_exists( 'symlink' ) ) {
799 if( !@symlink ($wp_cache_file, $wp_cache_link) ) {
800 $ret = false;
801 }
802 } elseif( !@copy( $wp_cache_file, $wp_cache_link ) ) {
803 $ret = false;
804 }
805 if( !$ret ) {
806 echo "<code>advanced-cache.php</code> does not exist<br />";
807 echo "Create it by executing: <br /><code>ln -s $wp_cache_file $wp_cache_link</code><br /> in your server<br />";
808 echo "Or by copying $wp_cache_file to $wp_cache_link.<br />";
809 return false;
810 }
811 }
812 return true;
813 }
814
815 function wp_cache_check_global_config() {
816
817 $global = ABSPATH . 'wp-config.php';
818
819 $lines = file($global);
820 foreach($lines as $line) {
821 if (preg_match('/^ *define *\( *\'WP_CACHE\' *, *true *\) *;/', $line)) {
822 return true;
823 }
824 }
825 $line = 'define(\'WP_CACHE\', true);';
826 if (!is_writable($global) || !wp_cache_replace_line('define *\( *\'WP_CACHE\'', $line, $global) ) {
827 echo "<b>Error: WP_CACHE is not enabled</b> in your <code>wp-config.php</code> file and I couldn't modified it.<br />";
828 echo "Edit <code>$global</code> and add the following line: <br /><code>define('WP_CACHE', true);</code><br />Otherwise, <b>WP-Cache will not be executed</b> by Wordpress core. <br />";
829 return false;
830 }
831 return true;
832 }
833
834 function wp_cache_files() {
835 global $cache_path, $file_prefix, $cache_max_time, $super_cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled;
836
837 if ( '/' != substr($cache_path, -1)) {
838 $cache_path .= '/';
839 }
840
841 if ( $valid_nonce ) {
842 if(isset($_REQUEST['wp_delete_cache'])) {
843 wp_cache_clean_cache($file_prefix);
844 }
845 if(isset($_REQUEST['wp_delete_cache_file'])) {
846 wp_cache_clean_cache($_REQUEST['wp_delete_cache_file']);
847 }
848 if(isset($_REQUEST['wp_delete_expired'])) {
849 wp_cache_clean_expired($file_prefix);
850 }
851 }
852 if(isset($_REQUEST['wp_list_cache'])) {
853 $list_files = true;
854 $list_mess = "Update list";
855 } else
856 $list_mess = "List files";
857
858 echo '<br /><a name="list"></a><fieldset style="border: 1px solid #aaa" class="options"><legend>Cache contents</legend>';
859 /*
860 echo '<form name="wp_cache_content_list" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
861 echo '<input type="hidden" name="wp_list_cache" />';
862 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="'.$list_mess.' &raquo;" /></div>';
863 echo "</form>\n";
864 */
865
866 $list_files = false; // it doesn't list supercached files, and removing single pages is buggy
867 $count = 0;
868 $expired = 0;
869 $now = time();
870 if ( ($handle = @opendir( $cache_path . 'meta/' )) ) {
871 if ($list_files) echo "<table cellspacing=\"0\" cellpadding=\"5\">";
872 while ( false !== ($file = readdir($handle))) {
873 if ( preg_match("/^$file_prefix.*\.meta/", $file) ) {
874 $this_expired = false;
875 $content_file = preg_replace("/meta$/", "html", $file);
876 $mtime = filemtime($cache_path . 'meta/' . $file);
877 if ( ! ($fsize = @filesize($cache_path.$content_file)) )
878 continue; // .meta does not exists
879 $fsize = intval($fsize/1024);
880 $age = $now - $mtime;
881 if ( $age > $cache_max_time) {
882 $expired++;
883 $this_expired = true;
884 }
885 $count++;
886 if ($list_files) {
887 $meta = new CacheMeta;
888 $meta = unserialize(file_get_contents($cache_path . 'meta/' . $file));
889 echo $flip ? '<tr style="background: #EAEAEA;">' : '<tr>';
890 $flip = !$flip;
891 echo '<td><a href="http://' . $meta->uri . '" target="_blank" >';
892 echo $meta->uri . "</a></td>";
893 if ($this_expired) echo "<td><span style='color:red'>$age secs</span></td>";
894 else echo "<td>$age secs</td>";
895 echo "<td>$fsize KB</td>";
896 echo '<td><form name="wp_delete_cache_file" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
897 echo '<input type="hidden" name="wp_list_cache" />';
898 echo '<input type="hidden" name="wp_delete_cache_file" value="'.preg_replace("/^(.*)\.meta$/", "$1", $file).'" />';
899 echo '<div class="submit"><input id="deletepost" ' . SUBMITDISABLED . 'type="submit" value="Remove" /></div>';
900 wp_nonce_field('wp-cache');
901 echo "</form></td></tr>\n";
902 }
903 }
904 }
905 closedir($handle);
906 if ($list_files) echo "</table>";
907 }
908 if( $cache_enabled == true && $super_cache_enabled == true ) {
909 $now = time();
910 $sizes = array( 'expired' => 0, 'cached' => 0, 'ts' => 0 );
911
912 if (is_dir($supercachedir)) {
913 $entries = glob($supercachedir. '/*');
914 foreach ($entries as $entry) {
915 if ($entry != '.' && $entry != '..') {
916 $sizes = wpsc_dirsize( $entry, $sizes );
917 }
918 }
919 } else {
920 if(is_file($supercachedir) && filemtime( $supercachedir ) + $super_cache_max_time <= $now )
921 $sizes[ 'expired' ] ++;
922 }
923 $sizes[ 'ts' ] = time();
924 }
925
926 echo "<p><strong>WP-Cache</strong></p>";
927 echo "<ul><li>$count cached pages</li>";
928 echo "<li>$expired expired pages</li></ul>";
929 if( $cache_enabled == true && $super_cache_enabled == true ) {
930 echo "<p><strong>WP-Super-Cache</strong></p>";
931 echo "<ul><li>" . intval($sizes['cached']/2) . " cached pages</li>";
932 $age = intval(($now - $sizes['ts'])/60);
933 echo "<li>" . intval($sizes['expired']/2) . " expired pages.</li></ul>";
934 }
935
936 echo '<form name="wp_cache_content_expired" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
937 echo '<input type="hidden" name="wp_delete_expired" />';
938 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Delete expired &raquo;" /></div>';
939 wp_nonce_field('wp-cache');
940 echo "</form>\n";
941
942
943 echo '<form name="wp_cache_content_delete" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
944 echo '<input type="hidden" name="wp_delete_cache" />';
945 echo '<div class="submit"><input id="deletepost" type="submit" ' . SUBMITDISABLED . 'value="Delete cache &raquo;" /></div>';
946 wp_nonce_field('wp-cache');
947 echo "</form>\n";
948
949 echo '</fieldset>';
950 }
951
952 function wpsc_dirsize($directory, $sizes) {
953 global $super_cache_max_time;
954 $now = time();
955
956 if (is_dir($directory)) {
957 $entries = glob($directory. '/*');
958 if( is_array( $entries ) && !empty( $entries ) ) foreach ($entries as $entry) {
959 if ($entry != '.' && $entry != '..') {
960 $sizes = wpsc_dirsize($entry, $sizes);
961 }
962 }
963 } else {
964 if(is_file($directory) ) {
965 if( filemtime( $directory ) + $super_cache_max_time <= $now ) {
966 $sizes[ 'expired' ]+=1;
967 } else {
968 $sizes[ 'cached' ]+=1;
969 }
970 }
971 }
972 return $sizes;
973 }
974
975
976 function wp_cache_clean_cache($file_prefix) {
977 global $cache_path, $supercachedir;
978
979 // If phase2 was compiled, use its function to avoid race-conditions
980 if(function_exists('wp_cache_phase2_clean_cache')) {
981 if (function_exists ('prune_super_cache')) {
982 if( is_dir( $supercachedir ) ) {
983 prune_super_cache( $supercachedir, true );
984 } elseif( is_dir( $supercachedir . '.disabled' ) ) {
985 prune_super_cache( $supercachedir . '.disabled', true );
986 }
987 prune_super_cache( $cache_path, true );
988 $_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
989 }
990 return wp_cache_phase2_clean_cache($file_prefix);
991 }
992
993 $expr = "/^$file_prefix/";
994 if ( ($handle = opendir( $cache_path )) ) {
995 while ( false !== ($file = readdir($handle))) {
996 if ( preg_match($expr, $file) ) {
997 unlink($cache_path . $file);
998 unlink($cache_path . 'meta/' . str_replace( '.html', '.term', $file ) );
999 }
1000 }
1001 closedir($handle);
1002 }
1003 }
1004
1005 function wp_cache_clean_expired($file_prefix) {
1006 global $cache_path, $cache_max_time;
1007
1008 // If phase2 was compiled, use its function to avoid race-conditions
1009 if(function_exists('wp_cache_phase2_clean_expired')) {
1010 if (function_exists ('prune_super_cache')) {
1011 $dir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]);
1012 if( is_dir( $dir ) ) {
1013 prune_super_cache( $dir );
1014 } elseif( is_dir( $dir . '.disabled' ) ) {
1015 prune_super_cache( $dir . '.disabled' );
1016 }
1017 $_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
1018 }
1019 return wp_cache_phase2_clean_expired($file_prefix);
1020 }
1021
1022 $expr = "/^$file_prefix/";
1023 $now = time();
1024 if ( ($handle = opendir( $cache_path )) ) {
1025 while ( false !== ($file = readdir($handle))) {
1026 if ( preg_match($expr, $file) &&
1027 (filemtime($cache_path . $file) + $cache_max_time) <= $now) {
1028 unlink($cache_path . $file);
1029 unlink($cache_path . 'meta/' . str_replace( '.html', '.term', $file ) );
1030 }
1031 }
1032 closedir($handle);
1033 }
1034 }
1035
1036 add_action('admin_menu', 'wp_cache_add_pages');
1037
1038 function wpsc_remove_marker( $filename, $marker ) {
1039 if (!file_exists( $filename ) || is_writeable( $filename ) ) {
1040 if (!file_exists( $filename ) ) {
1041 return '';
1042 } else {
1043 $markerdata = explode( "\n", implode( '', file( $filename ) ) );
1044 }
1045
1046 $f = fopen( $filename, 'w' );
1047 $foundit = false;
1048 if ( $markerdata ) {
1049 $state = true;
1050 foreach ( $markerdata as $n => $markerline ) {
1051 if (strpos($markerline, '# BEGIN ' . $marker) !== false)
1052 $state = false;
1053 if ( $state ) {
1054 if ( $n + 1 < count( $markerdata ) )
1055 fwrite( $f, "{$markerline}\n" );
1056 else
1057 fwrite( $f, "{$markerline}" );
1058 }
1059 if (strpos($markerline, '# END ' . $marker) !== false) {
1060 $state = true;
1061 }
1062 }
1063 }
1064 return true;
1065 } else {
1066 return false;
1067 }
1068 }
1069
1070 function wp_super_cache_footer() {
1071 ?><p><?php bloginfo('name'); ?> is Digg proof thanks to caching by <a href="http://ocaoimh.ie/wp-super-cache/">WP Super Cache</a>!</p><?php
1072 }
1073 if( isset( $wp_cache_hello_world ) && $wp_cache_hello_world )
1074 add_action( 'wp_footer', 'wp_super_cache_footer' );
1075
1076 if( get_option( 'gzipcompression' ) )
1077 update_option( 'gzipcompression', 0 );
1078
1079 ?>
1080