PluginProbe ʕ •ᴥ•ʔ
WP Super Cache / 0.9.3
WP Super Cache v0.9.3
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 17 years ago advanced-cache.php 17 years ago readme.txt 17 years ago wp-cache-base.php 18 years ago wp-cache-config-sample.php 17 years ago wp-cache-phase1.php 17 years ago wp-cache-phase2.php 17 years ago wp-cache.php 17 years ago
wp-cache.php
1415 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.3
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;
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 = wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache');
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 = '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 $_POST[ 'wp_cache_status' ] = 'wpcache';
259 }
260 wp_cache_replace_line('^ *\$wp_cache_mobile_enabled', "\$wp_cache_mobile_enabled = " . $wp_cache_mobile_enabled . ";", $wp_cache_config_file);
261 switch( $_POST[ 'wp_cache_status' ] ) {
262 case 'all':
263 wp_cache_enable();
264 break;
265 case 'none':
266 wp_cache_disable();
267 break;
268 case 'wpcache':
269 wp_cache_enable();
270 wp_super_cache_disable();
271 break;
272 }
273 if( isset( $_POST[ 'wp_cache_hello_world' ] ) ) {
274 $wp_cache_hello_world = 1;
275 } else {
276 $wp_cache_hello_world = 0;
277 }
278 wp_cache_replace_line('^ *\$wp_cache_hello_world', '$wp_cache_hello_world = ' . (int)$wp_cache_hello_world . ";", $wp_cache_config_file);
279 if( isset( $_POST[ 'wp_cache_clear_on_post_edit' ] ) ) {
280 $wp_cache_clear_on_post_edit = 1;
281 } else {
282 $wp_cache_clear_on_post_edit = 0;
283 }
284 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);
285 if( isset( $_POST[ 'cache_rebuild_files' ] ) ) {
286 $cache_rebuild_files = 1;
287 } else {
288 $cache_rebuild_files = 0;
289 }
290 wp_cache_replace_line('^ *\$cache_rebuild_files', "\$cache_rebuild_files = " . $cache_rebuild_files . ";", $wp_cache_config_file);
291 if( isset( $_POST[ 'wp_cache_mutex_disabled' ] ) ) {
292 $wp_cache_mutex_disabled = 0;
293 } else {
294 $wp_cache_mutex_disabled = 1;
295 }
296 wp_cache_replace_line('^ *\$wp_cache_mutex_disabled', "\$wp_cache_mutex_disabled = " . $wp_cache_mutex_disabled . ";", $wp_cache_config_file);
297 }
298 if( isset( $_POST[ 'cache_compression' ] ) && $_POST[ 'cache_compression' ] != $cache_compression ) {
299 $cache_compression_changed = true;
300 $cache_compression = intval( $_POST[ 'cache_compression' ] );
301 wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
302 if( function_exists( 'prune_super_cache' ) )
303 prune_super_cache ($cache_path, true);
304 delete_option( 'super_cache_meta' );
305 }
306 if( isset( $_POST[ 'wp_cache_hide_donation' ] ) && $_POST[ 'wp_cache_hide_donation' ] != $wp_cache_hide_donation ) {
307 $wp_cache_hide_donation = intval( $_POST[ 'wp_cache_hide_donation' ] );
308 wp_cache_replace_line('^ *\$wp_cache_hide_donation', "\$wp_cache_hide_donation = " . $wp_cache_hide_donation . ";", $wp_cache_config_file);
309 }
310 }
311
312 ?>
313 <table><td><fieldset class="options" id="show-this-fieldset">
314 <h3>WP Super Cache Status</h3><?php
315 echo '<form name="wp_manager" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
316 ?>
317 <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 />
318 <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 />
319 <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 />
320 <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>
321 <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>
322 <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>
323 <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>
324 <p><label><input type='checkbox' name='wp_cache_mobile_enabled' <?php if( $wp_cache_mobile_enabled ) echo "checked"; ?> value='1'> Mobile device support. Plugin will enter "Half-On" mode.</label></p>
325 <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>
326 <?php
327 echo "<div class='submit'><input type='submit' " . SUBMITDISABLED . " value='Update Status &raquo;' /></div>";
328 wp_nonce_field('wp-cache');
329 ?>
330 </form>
331 <?php
332 if( $super_cache_enabled && function_exists( 'apache_get_modules' ) ) {
333 $mods = apache_get_modules();
334 $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.' );
335 foreach( $required_modules as $req => $desc ) {
336 if( !in_array( $req, $mods ) ) {
337 $missing_mods[ $req ] = $desc;
338 }
339 }
340 if( is_array( $missing_mods ) ) {
341 echo "<h3>Missing Apache Modules</h3>";
342 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>";
343 echo "<ul>";
344 foreach( $missing_mods as $req => $desc ) {
345 echo "<li> $req - $desc</li>";
346 }
347 echo "</ul>";
348 }
349 }
350 ?>
351 </fieldset>
352 </td><td valign='top'>
353 <div style='background: #ffc; border: 1px solid #333; margin: 2px; padding: 5px'>
354 <h3 align='center'>Make WordPress Faster</h3>
355 <?php if( $wp_cache_hide_donation != 1 ) { ?>
356 <p><a href="http://ocaoimh.ie/wp-super-cache/?r=wpsc">WP Super Cache</a> makes your blog go faster. Think that's worth $10? Click the "Donate" button below.</p>
357 <p>Thanks!<br />Donncha O Caoimh.<br /></p>
358 <div align='center'>
359 <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
360 <input type="hidden" name="cmd" value="_s-xclick"/>
361 <input type="hidden" name="hosted_button_id" value="3244504"/>
362 <input type="image" src="https://www.paypal.com/en_GB/i/btn/btn_donate_SM.gif" border="0" name="submit" alt=""/>
363 <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"/><br />
364 </form>
365 <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>
366 </div>
367 <?php } else { ?>
368 <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 thanks to the GPL.</p>
369 <p>He blogs at <a href="http://ocaoimh.ie/?r=supercache">Holy Shmoly</a> and posts photos at <a href="http://inphotos.org/?r=supercache">In Photos.org</a>. You can say hi to him on <a href="http://twitter.com/donncha/">Twitter</a> too!</p>
370 <?php } ?>
371 </div>
372
373 </td></table>
374 <?php
375
376 wp_cache_files();
377
378 wsc_mod_rewrite();
379
380 wp_cache_edit_max_time();
381
382 echo '<a name="files"></a><fieldset class="options"><h3>Accepted Filenames &amp; Rejected URIs</h3>';
383 wp_cache_edit_rejected();
384 echo "\n";
385 wp_cache_edit_accepted();
386 echo '</fieldset>';
387
388 wp_cache_edit_rejected_ua();
389
390
391 wp_lock_down();
392
393 wp_cache_restore();
394
395 ob_start();
396 if( defined( 'WP_CACHE' ) ) {
397 if( function_exists( 'do_cacheaction' ) ) {
398 do_cacheaction( 'cache_admin_page' );
399 }
400 }
401 $out = ob_get_contents();
402 ob_end_clean();
403 if( SUBMITDISABLED == ' ' && $out != '' ) {
404 echo '<fieldset class="options"><h3>Cache Plugins</h3>';
405 echo $out;
406 echo '</fieldset>';
407 }
408
409 echo "</div>\n";
410 }
411
412 function wsc_mod_rewrite() {
413 global $super_cache_enabled, $cache_compression, $cache_compression_changed, $valid_nonce, $cache_path;
414 if( $super_cache_enabled == false )
415 return;
416 ?>
417 <fieldset class="options">
418 <h3>Super Cache Compression</h3>
419 <form name="wp_manager" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post">
420 <label><input type="radio" name="cache_compression" value="1" <?php if( $cache_compression ) { echo "checked=checked"; } ?>> Enabled</label>
421 <label><input type="radio" name="cache_compression" value="0" <?php if( !$cache_compression ) { echo "checked=checked"; } ?>> Disabled</label>
422 <p>Compression is disabled by default because some hosts have problems with compressed files. Switching this on and off clears the cache.</p>
423 <?php
424 if( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && !$cache_compression ) {
425 ?><p><strong>Super Cache compression is now disabled.</strong></p> <?php
426 } elseif( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && $cache_compression ) {
427 ?><p><strong>Super Cache compression is now enabled.</strong></p><?php
428 }
429 echo '<div class="submit"><input ' . SUBMITDISABLED . 'type="submit" value="Update Compression &raquo;" /></div>';
430 wp_nonce_field('wp-cache');
431 echo "</form>\n";
432 ?></fieldset>
433
434 <a name="modrewrite"></a><fieldset class="options">
435 <h3>Mod Rewrite Rules</h3><?php
436 $home_path = get_home_path();
437 $home_root = parse_url(get_bloginfo('url'));
438 $home_root = trailingslashit($home_root['path']);
439 $inst_root = str_replace( '//', '/', '/' . trailingslashit( str_replace( $_SERVER[ 'DOCUMENT_ROOT' ], '', str_replace( '\\', '/', WP_CONTENT_DIR ) ) ) );
440 $wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) );
441 $wprules = str_replace( "RewriteEngine On\n", '', $wprules );
442 $wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
443 $scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
444
445 if( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
446 $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*[^/]$";
447 $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*//.*$";
448 }
449 $condition_rules[] = "RewriteCond %{REQUEST_METHOD} !=POST";
450 $condition_rules[] = "RewriteCond %{QUERY_STRING} !.*=.*";
451 $condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$";
452 $condition_rules = apply_filters( 'supercacherewriteconditions', $condition_rules );
453
454 $rules = "<IfModule mod_rewrite.c>\n";
455 $rules .= "RewriteEngine On\n";
456 $rules .= "RewriteBase $home_root\n"; // props Chris Messina
457 $charset = get_option('blog_charset') == '' ? 'UTF-8' : get_option('blog_charset');
458 $rules .= "AddDefaultCharset {$charset}\n";
459 $rules .= "CONDITION_RULES";
460 $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
461 $rules .= "RewriteCond %{DOCUMENT_ROOT}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz -f\n";
462 $rules .= "RewriteRule ^(.*) {$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz [L]\n\n";
463
464 $rules .= "CONDITION_RULES";
465 $rules .= "RewriteCond %{DOCUMENT_ROOT}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html -f\n";
466 $rules .= "RewriteRule ^(.*) {$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html [L]\n";
467 $rules .= "</IfModule>\n";
468 $rules = apply_filters( 'supercacherewriterules', $rules );
469
470 $rules = str_replace( "CONDITION_RULES", implode( "\n", $condition_rules ) . "\n", $rules );
471
472 $dohtaccess = true;
473 if( function_exists( 'is_site_admin' ) ) {
474 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>";
475 } elseif( !$wprules || $wprules == '' ) {
476 echo "<h4 style='color: #a00'>Mod Rewrite rules cannot be updated!</h4>";
477 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:
478 <blockquote><code><em># BEGIN WordPress</em> RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] <em># END WordPress</em></code></blockquote>
479 Refresh this page when you have updated your .htaccess file.";
480 echo "</fieldset></div>";
481 return;
482 } elseif( strpos( $wprules, 'wordpressuser' ) ) { // Need to clear out old mod_rewrite rules
483 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>";
484 echo "</fieldset></div>";
485 return;
486 } elseif( $scrules != '' && strpos( $scrules, '%{REQUEST_URI} !^.*[^/]$' ) === false && substr( get_option( 'permalink_structure' ), -1 ) == '/' ) { // permalink structure has a trailing slash, need slash check in rules.
487 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.";
488 echo "To fix, you must edit your .htaccess file and add these two rules to the two groups of Super Cache rules:</p>";
489 echo "<blockquote><code>RewriteCond %{REQUEST_URI} !^.*[^/]$RewriteCond %{REQUEST_URI} !^.*//.*$</code></blockquote>";
490 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>";
491 $dohtaccess = false;
492 } elseif( strpos( $scrules, 'supercache' ) || strpos( $wprules, 'supercache' ) ) { // only write the rules once
493 $dohtaccess = false;
494 }
495 // cache/.htaccess rules
496 $gziprules = "<IfModule mod_mime.c>\n AddEncoding gzip .gz\n AddType text/html .gz\n</IfModule>\n";
497 $gziprules .= "<IfModule mod_deflate.c>\n SetEnvIfNoCase Request_URI \.gz$ no-gzip\n</IfModule>\n";
498 $gziprules .= "<IfModule mod_headers.c>\n Header set Cache-Control 'max-age=300, must-revalidate'\n</IfModule>\n";
499 $gziprules .= "<IfModule mod_expires.c>\n ExpiresActive On\n ExpiresByType text/html A300\n</IfModule>\n";
500 if( $dohtaccess && !$_POST[ 'updatehtaccess' ] ) {
501 if( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) {
502 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>";
503 echo "<p><pre># BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache</pre></p></div>";
504 } else {
505 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> ";
506 if( !function_exists( 'is_site_admin' ) ) {
507 echo "You must edit the file yourself add the following rules.";
508 } else {
509 echo "You can edit the file yourself add the following rules.";
510 }
511 echo " Make sure they appear before any existing WordPress rules.</p>";
512 echo "<pre># BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache</pre></p>";
513 echo "<p>Rules must be added to " . WP_CONTENT_DIR . "/cache/.htaccess too:</p>";
514 echo "<pre># BEGIN supercache\n" . wp_specialchars( $gziprules ) . "# END supercache</pre></p>";
515 if( !function_exists( 'is_site_admin' ) ) {
516 echo '<form name="updatehtaccess" action="'. $_SERVER["REQUEST_URI"] . '#modrewrite" method="post">';
517 echo '<input type="hidden" name="updatehtaccess" value="1" />';
518 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'id="updatehtaccess" value="Update Mod_Rewrite Rules &raquo;" /></div>';
519 wp_nonce_field('wp-cache');
520 echo "</form></div>\n";
521 }
522 }
523 } elseif( $dohtaccess && $valid_nonce && $_POST[ 'updatehtaccess' ] ) {
524 wpsc_remove_marker( $home_path.'.htaccess', 'WordPress' ); // remove original WP rules so SuperCache rules go on top
525 echo "<div style='padding:0 8px;color:#4f8a10;background-color:#dff2bf;border:1px solid #4f8a10;'>";
526 if( insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', explode( "\n", $rules ) ) && insert_with_markers( $home_path.'.htaccess', 'WordPress', explode( "\n", $wprules ) ) ) {
527 echo "<h4>Mod Rewrite rules updated!</h4>";
528 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";
529 } else {
530 echo "<h4>Mod Rewrite rules must be updated!</h4>";
531 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";
532 }
533 echo "<p><pre>" . wp_specialchars( $rules ) . "</pre></p>\n</div>";
534 } else {
535 ?>
536 <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 />
537 <a href="javascript:toggleLayer('rewriterules');" class="button">View Mod_Rewrite Rules</a>
538 <div id='rewriterules' style='display: none;'>
539 <?php echo "<p><pre># BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache</pre></p>\n";
540 echo "<p>Rules must be added to " . WP_CONTENT_DIR ."/cache/.htaccess too:</p>";
541 echo "<pre># BEGIN supercache\n" . wp_specialchars( $gziprules ) . "# END supercache</pre></p>"; ?>
542 </div>
543 <?php
544 }
545 // http://allmybrain.com/2007/11/08/making-wp-super-cache-gzip-compression-work/
546 if( !is_file( $cache_path . '.htaccess' ) ) {
547 $gziprules = insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $gziprules ) );
548 echo "<h4>Gzip encoding rules in {$cache_path}.htaccess created.</h4>";
549 }
550
551 ?></fieldset><?php
552 }
553
554 function wp_cache_restore() {
555 echo '<fieldset class="options"><h3>Fix Configuration</h3>';
556 echo '<form name="wp_restore" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
557 echo '<input type="hidden" name="wp_restore_config" />';
558 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'id="deletepost" value="Restore Default Configuration &raquo;" /></div>';
559 wp_nonce_field('wp-cache');
560 echo "</form>\n";
561 echo '</fieldset>';
562
563 }
564
565 function comment_form_lockdown_message() {
566 ?><p><?php _e( "Comment moderation is enabled. Your comment may take some time to appear." ); ?></p><?php
567 }
568 if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) )
569 add_action( 'comment_form', 'comment_form_lockdown_message' );
570
571 function wp_lock_down() {
572 global $wpdb, $cache_path, $wp_cache_config_file, $valid_nonce, $cached_direct_pages, $cache_enabled, $super_cache_enabled;
573
574 if(isset($_POST['wp_lock_down']) && $valid_nonce) {
575 $wp_lock_down = $_POST['wp_lock_down'] == '1' ? '1' : '0';
576 wp_cache_replace_line('^.*WPLOCKDOWN', "define( 'WPLOCKDOWN', '$wp_lock_down' );", $wp_cache_config_file);
577 if( $wp_lock_down == '0' && function_exists( 'prune_super_cache' ) )
578 prune_super_cache( $cache_path, true ); // clear the cache after lockdown
579
580 }
581 if( !isset( $wp_lock_down ) ) {
582 if( defined( 'WPLOCKDOWN' ) ) {
583 $wp_lock_down = constant( 'WPLOCKDOWN' );
584 } else {
585 $wp_lock_down = '0';
586 }
587 }
588 ?><fieldset class="options">
589 <h3>Lock Down: <?php echo $wp_lock_down == '0' ? '<span style="color:red">Disabled</span>' : '<span style="color:green">Enabled</span>'; ?></h3>
590 <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>
591 <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.
592 <blockquote><code>if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) ) {
593 &nbsp;&nbsp;&nbsp;&nbsp;echo "Sorry. My blog is locked down. Updates will appear shortly";
594 }</code></blockquote>
595 <?php
596 if( $wp_lock_down == '1' ) {
597 ?><p>WordPress is locked down. Super Cache static files will not be deleted when new comments are made.</p><?php
598 } else {
599 ?><p>WordPress is not locked down. New comments will refresh Super Cache static files as normal.</p><?php
600 }
601 $new_lockdown = $wp_lock_down == '1' ? '0' : '1';
602 $new_lockdown_desc = $wp_lock_down == '1' ? 'Disable' : 'Enable';
603 echo '<form name="wp_lock_down" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
604 echo "<input type='hidden' name='wp_lock_down' value='{$new_lockdown}' />";
605 echo "<div class='submit'><input type='submit' " . SUBMITDISABLED . " value='{$new_lockdown_desc} Lock Down &raquo;' /></div>";
606 wp_nonce_field('wp-cache');
607 echo "</form>\n";
608
609 ?></fieldset><?php
610 if( $cache_enabled == true && $super_cache_enabled == true ) {
611 ?><fieldset class="options">
612 <h3>Directly Cached Files</h3><?php
613
614 $out = '';
615 if( $valid_nonce && is_array( $_POST[ 'direct_pages' ] ) && !empty( $_POST[ 'direct_pages' ] ) ) {
616 $expiredfiles = array_diff( $cached_direct_pages, $_POST[ 'direct_pages' ] );
617 unset( $cached_direct_pages );
618 foreach( $_POST[ 'direct_pages' ] as $page ) {
619 $page = $wpdb->escape( $page );
620 if( $page != '' ) {
621 $cached_direct_pages[] = $page;
622 $out .= "'$page', ";
623 }
624 }
625 if( $out == '' ) {
626 $out = "'', ";
627 }
628 }
629 if( $valid_nonce && $_POST[ 'new_direct_page' ] && '' != $_POST[ 'new_direct_page' ] ) {
630 $page = str_replace( get_option( 'siteurl' ), '', $_POST[ 'new_direct_page' ] );
631 if( substr( $page, 0, 1 ) != '/' )
632 $page = '/' . $page;
633 $page = $wpdb->escape( $page );
634 if( in_array( $page, $cached_direct_pages ) == false ) {
635 $cached_direct_pages[] = $page;
636 $out .= "'$page', ";
637 }
638 }
639
640 if( $out != '' ) {
641 $out = substr( $out, 0, -2 );
642 $out = '$cached_direct_pages = array( ' . $out . ' );';
643 wp_cache_replace_line('^ *\$cached_direct_pages', "$out", $wp_cache_config_file);
644 prune_super_cache( $cache_path, true );
645 }
646
647 if( !empty( $expiredfiles ) ) {
648 foreach( $expiredfiles as $file ) {
649 if( $file != '' ) {
650 $firstfolder = explode( '/', $file );
651 $firstfolder = ABSPATH . $firstfolder[1];
652 $file = ABSPATH . $file;
653 @unlink( trailingslashit( $file ) . 'index.html' );
654 @unlink( trailingslashit( $file ) . 'index.html.gz' );
655 RecursiveFolderDelete( trailingslashit( $firstfolder ) );
656 }
657 }
658 }
659
660 if( $valid_nonce && $_POST[ 'deletepage' ] ) {
661 $page = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_POST['deletepage']) );
662 $pagefile = ABSPATH . $page . 'index.html';
663 $firstfolder = explode( '/', $page );
664 $firstfolder = ABSPATH . $firstfolder[1];
665 $page = ABSPATH . $page;
666 if( is_file( $pagefile ) && is_writeable_ACLSafe( $pagefile ) && is_writeable_ACLSafe( $firstfolder ) ) {
667 @unlink( $pagefile );
668 @unlink( $pagefile . '.gz' );
669 RecursiveFolderDelete( $firstfolder );
670 echo "<strong>$pagefile removed!</strong>";
671 prune_super_cache( $cache_path, true );
672 }
673 }
674
675 $readonly = '';
676 if( !is_writeable_ACLSafe( ABSPATH ) ) {
677 $readonly = 'READONLY';
678 ?><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
679 } else {
680 ?><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
681 }
682 echo '<form name="direct_page" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
683 if( is_array( $cached_direct_pages ) ) {
684 $out = '';
685 foreach( $cached_direct_pages as $page ) {
686 if( $page == '' )
687 continue;
688 $generated = '';
689 if( is_file( ABSPATH . $page . '/index.html' ) )
690 $generated = '<input type="Submit" name="deletepage" value="' . $page . '">';
691 $out .= "<tr><td><input type='text' $readonly name='direct_pages[]' size='30' value='$page' /></td><td>$generated</td></tr>";
692 }
693 if( $out != '' ) {
694 ?><table><tr><th>Existing direct page</th><th>Delete cached file</th></tr><?php
695 echo "$out</table>";
696 }
697 }
698 if( $readonly != 'READONLY' )
699 echo "Add direct page: <input type='text' $readonly name='new_direct_page' size='30' value='' />";
700
701 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>";
702 if( $readonly != 'READONLY' ) {
703 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>";
704 echo "<p>Make the textbox blank to remove it from the list of direct pages and delete the cached file.</p>";
705 }
706
707 wp_nonce_field('wp-cache');
708 if( $readonly != 'READONLY' )
709 echo "<div class='submit'><input type='submit' ' . SUBMITDISABLED . 'value='Update Direct Pages &raquo;' /></div>";
710 echo "</form>\n";
711 ?></fieldset><?php
712 } // if $super_cache_enabled
713 }
714
715 function RecursiveFolderDelete ( $folderPath ) { // from http://www.php.net/manual/en/function.rmdir.php
716 if( trailingslashit( constant( 'ABSPATH' ) ) == trailingslashit( $folderPath ) )
717 return false;
718 if ( @is_dir ( $folderPath ) ) {
719 $dh = @opendir($folderPath);
720 while (false !== ($value = @readdir($dh))) {
721 if ( $value != "." && $value != ".." ) {
722 $value = $folderPath . "/" . $value;
723 if ( @is_dir ( $value ) ) {
724 RecursiveFolderDelete ( $value );
725 }
726 }
727 }
728 return @rmdir ( $folderPath );
729 } else {
730 return FALSE;
731 }
732 }
733
734 function wp_cache_edit_max_time () {
735 global $cache_max_time, $wp_cache_config_file, $valid_nonce, $cache_enabled, $super_cache_enabled;
736
737 if( !isset( $cache_max_time ) )
738 $cache_max_time = 3600;
739
740 if(isset($_POST['wp_max_time']) && $valid_nonce) {
741 $max_time = (int)$_POST['wp_max_time'];
742 if ($max_time > 0) {
743 $cache_max_time = $max_time;
744 wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file);
745 }
746 }
747 ?><fieldset class="options">
748 <h3>Expiry Time &amp; Garbage Collection</h3><?php
749 echo '<form name="wp_edit_max_time" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
750 echo '<label for="wp_max_time">Expire time:</label> ';
751 echo "<input type=\"text\" size=6 name=\"wp_max_time\" value=\"$cache_max_time\" /> seconds";
752 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>";
753 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>";
754 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Change Expiration &raquo;" /></div>';
755 wp_nonce_field('wp-cache');
756 echo "</form>\n";
757 ?></fieldset><?php
758 }
759
760 function wp_cache_sanitize_value($text, & $array) {
761 $text = wp_specialchars(strip_tags($text));
762 $array = preg_split("/[\s,]+/", chop($text));
763 $text = var_export($array, true);
764 $text = preg_replace('/[\s]+/', ' ', $text);
765 return $text;
766 }
767
768 // from tehjosh at gamingg dot net http://uk2.php.net/manual/en/function.apache-request-headers.php#73964
769 // fixed bug in second substr()
770 if( !function_exists('apache_request_headers') ) {
771 function apache_request_headers() {
772 $headers = array();
773 foreach(array_keys($_SERVER) as $skey) {
774 if(substr($skey, 0, 5) == "HTTP_") {
775 $headername = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($skey, 5)))));
776 $headers[$headername] = $_SERVER[$skey];
777 }
778 }
779 return $headers;
780 }
781 }
782
783 function wp_cache_edit_rejected_ua() {
784 global $cache_rejected_user_agent, $wp_cache_config_file, $valid_nonce;
785
786 if (!function_exists('apache_request_headers')) return;
787
788 if(isset($_REQUEST['wp_rejected_user_agent']) && $valid_nonce) {
789 $text = wp_cache_sanitize_value($_REQUEST['wp_rejected_user_agent'], $cache_rejected_user_agent);
790 wp_cache_replace_line('^ *\$cache_rejected_user_agent', "\$cache_rejected_user_agent = $text;", $wp_cache_config_file);
791 }
792
793 echo '<a name="user-agents"></a><fieldset class="options"><h3>Rejected User Agents</h3>';
794 echo "<p>Strings in the HTTP 'User Agent' header that prevent WP-Cache from
795 caching bot, spiders, and crawlers' requests.
796 Note that cached files are still sent to these request if they already exists.</p>\n";
797 echo '<form name="wp_edit_rejected_user_agent" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
798 echo '<textarea name="wp_rejected_user_agent" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
799 foreach ($cache_rejected_user_agent as $ua) {
800 echo wp_specialchars($ua) . "\n";
801 }
802 echo '</textarea> ';
803 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Save UA Strings &raquo;" /></div>';
804 wp_nonce_field('wp-cache');
805 echo '</form>';
806 echo "</fieldset>\n";
807 }
808
809
810 function wp_cache_edit_rejected() {
811 global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file, $valid_nonce;
812
813 if(isset($_REQUEST['wp_rejected_uri']) && $valid_nonce) {
814 $text = wp_cache_sanitize_value($_REQUEST['wp_rejected_uri'], $cache_rejected_uri);
815 wp_cache_replace_line('^ *\$cache_rejected_uri', "\$cache_rejected_uri = $text;", $wp_cache_config_file);
816 }
817
818
819 echo '<form name="wp_edit_rejected" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
820 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";
821 echo '<textarea name="wp_rejected_uri" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
822 foreach ($cache_rejected_uri as $file) {
823 echo wp_specialchars($file) . "\n";
824 }
825 echo '</textarea> ';
826 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Save Strings &raquo;" /></div>';
827 wp_nonce_field('wp-cache');
828 echo "</form>\n";
829 }
830
831 function wp_cache_edit_accepted() {
832 global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file, $valid_nonce;
833
834 if(isset($_REQUEST['wp_accepted_files']) && $valid_nonce) {
835 $text = wp_cache_sanitize_value($_REQUEST['wp_accepted_files'], $cache_acceptable_files);
836 wp_cache_replace_line('^ *\$cache_acceptable_files', "\$cache_acceptable_files = $text;", $wp_cache_config_file);
837 }
838
839
840 echo '<div style="clear:both"></div><form name="wp_edit_accepted" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
841 echo "<p>Add here those filenames that can be cached, even if they match one of the rejected substring specified above.</p>\n";
842 echo '<textarea name="wp_accepted_files" cols="40" rows="8" style="width: 50%; font-size: 12px;" class="code">';
843 foreach ($cache_acceptable_files as $file) {
844 echo wp_specialchars($file) . "\n";
845 }
846 echo '</textarea> ';
847 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Save Files &raquo;" /></div>';
848 wp_nonce_field('wp-cache');
849 echo "</form>\n";
850 }
851
852 function wp_cache_enable() {
853 global $wp_cache_config_file, $cache_enabled, $supercachedir;
854
855 if(get_option('gzipcompression')) {
856 echo "<strong>Error: GZIP compression is enabled, disable it if you want to enable wp-cache.</strong>";
857 return false;
858 }
859 if( wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = true;', $wp_cache_config_file) ) {
860 $cache_enabled = true;
861 }
862 wp_super_cache_enable();
863 }
864
865 function wp_cache_disable() {
866 global $wp_cache_config_file, $cache_enabled;
867
868 if (wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file)) {
869 $cache_enabled = false;
870 }
871 wp_super_cache_disable();
872 }
873 function wp_super_cache_enable() {
874 global $supercachedir, $wp_cache_config_file, $super_cache_enabled;
875
876 if( is_dir( $supercachedir . ".disabled" ) )
877 if( is_dir( $supercachedir ) ) {
878 prune_super_cache( $supercachedir . ".disabled", true );
879 @unlink( $supercachedir . ".disabled" );
880 } else {
881 @rename( $supercachedir . ".disabled", $supercachedir );
882 }
883 wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = true;', $wp_cache_config_file);
884 $super_cache_enabled = true;
885 }
886
887 function wp_super_cache_disable() {
888 global $cache_path, $supercachedir, $wp_cache_config_file, $super_cache_enabled;
889
890 wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = false;', $wp_cache_config_file);
891 if( is_dir( $supercachedir ) )
892 @rename( $supercachedir, $supercachedir . ".disabled" );
893 $super_cache_enabled = false;
894 sleep( 1 ); // allow existing processes to write to the supercachedir and then delete it
895 if (function_exists ('prune_super_cache') && is_dir( $supercachedir ) ) {
896 prune_super_cache( $cache_path, true );
897 }
898 }
899
900 function wp_cache_is_enabled() {
901 global $wp_cache_config_file;
902
903 if(get_option('gzipcompression')) {
904 echo "<strong>Warning</strong>: GZIP compression is enabled in Wordpress, wp-cache will be bypassed until you disable gzip compression.";
905 return false;
906 }
907 $lines = file($wp_cache_config_file);
908 foreach($lines as $line) {
909 if (preg_match('/^ *\$cache_enabled *= *true *;/', $line))
910 return true;
911 }
912 return false;
913 }
914
915
916 function wp_cache_replace_line($old, $new, $my_file) {
917 if (!is_writeable_ACLSafe($my_file)) {
918 echo "Error: file $my_file is not writable.\n";
919 return false;
920 }
921 $found = false;
922 $lines = file($my_file);
923 foreach($lines as $line) {
924 if ( preg_match("/$old/", $line)) {
925 $found = true;
926 break;
927 }
928 }
929 if ($found) {
930 $fd = fopen($my_file, 'w');
931 foreach($lines as $line) {
932 if ( !preg_match("/$old/", $line))
933 fputs($fd, $line);
934 else {
935 fputs($fd, "$new //Added by WP-Cache Manager\n");
936 }
937 }
938 fclose($fd);
939 return true;
940 }
941 $fd = fopen($my_file, 'w');
942 $done = false;
943 foreach($lines as $line) {
944 if ( $done || !preg_match('/^define|\$|\?>/', $line))
945 fputs($fd, $line);
946 else {
947 fputs($fd, "$new //Added by WP-Cache Manager\n");
948 fputs($fd, $line);
949 $done = true;
950 }
951 }
952 fclose($fd);
953 return true;
954 }
955
956 function wp_cache_verify_cache_dir() {
957 global $cache_path, $blog_cache_dir, $blogcacheid;
958
959 $dir = dirname($cache_path);
960 if ( !file_exists($cache_path) ) {
961 if ( !is_writeable_ACLSafe( $dir ) || !($dir = mkdir( $cache_path ) ) ) {
962 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.";
963 return false;
964 }
965 }
966 if ( !is_writeable_ACLSafe($cache_path)) {
967 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.";
968 return false;
969 }
970
971 if ( '/' != substr($cache_path, -1)) {
972 $cache_path .= '/';
973 }
974
975 if( false == is_dir( $blog_cache_dir ) ) {
976 @mkdir( $cache_path . "blogs" );
977 if( $blog_cache_dir != $cache_path . "blogs/" )
978 @mkdir( $blog_cache_dir );
979 }
980
981 if( false == is_dir( $blog_cache_dir . 'meta' ) )
982 @mkdir( $blog_cache_dir . 'meta' );
983
984 return true;
985 }
986
987 function wp_cache_verify_config_file() {
988 global $wp_cache_config_file, $wp_cache_config_file_sample, $sem_id, $cache_path;
989
990 $new = false;
991 $dir = dirname($wp_cache_config_file);
992
993 if ( file_exists($wp_cache_config_file) ) {
994 $lines = join( ' ', file( $wp_cache_config_file ) );
995 if( strpos( $lines, 'WPCACHEHOME' ) === false ) {
996 if( is_writeable_ACLSafe( $wp_cache_config_file ) ) {
997 @unlink( $wp_cache_config_file );
998 } else {
999 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.";
1000 return false;
1001 }
1002 }
1003 } elseif( !is_writeable_ACLSafe($dir)) {
1004 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.";
1005 return false;
1006 }
1007
1008 if ( !file_exists($wp_cache_config_file) ) {
1009 if ( !file_exists($wp_cache_config_file_sample) ) {
1010 echo "<strong>Error:</strong> Sample WP-Cache config file (<strong>$wp_cache_config_file_sample</strong>) does not exist.Verify you installation.";
1011 return false;
1012 }
1013 copy($wp_cache_config_file_sample, $wp_cache_config_file);
1014 $dir = str_replace( str_replace( '\\', '/', WP_CONTENT_DIR ), '', str_replace( '\\', '/', dirname(__FILE__) ) );
1015 if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
1016 wp_cache_replace_line('WPCACHEHOME', "define( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/\" );", $wp_cache_config_file);
1017 } elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
1018 wp_cache_replace_line('WPCACHEHOME', "define( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/wp-super-cache/\" );", $wp_cache_config_file);
1019 }
1020 $new = true;
1021 }
1022 if( $sem_id == 5419 && $cache_path != '' ) {
1023 $sem_id = crc32( $_SERVER[ 'HTTP_HOST' ] . $cache_path ) & 0x7fffffff;
1024 wp_cache_replace_line('sem_id', '$sem_id = ' . $sem_id . ';', $wp_cache_config_file);
1025 }
1026 require($wp_cache_config_file);
1027 return true;
1028 }
1029
1030 function wp_cache_create_advanced_cache() {
1031 global $wp_cache_link, $wp_cache_file;
1032 $ret = true;
1033
1034 $file = file_get_contents( $wp_cache_file );
1035 $file = str_replace( 'CACHEHOME', constant( 'WPCACHEHOME' ), $file );
1036 $fp = @fopen( $wp_cache_link, 'w' );
1037 if( $fp ) {
1038 fputs( $fp, $file );
1039 fclose( $fp );
1040 } else {
1041 $ret = false;
1042 }
1043 return $ret;
1044 }
1045
1046 function wp_cache_check_link() {
1047 global $wp_cache_link, $wp_cache_file;
1048
1049 $ret = true;
1050 if( file_exists($wp_cache_link) ) {
1051 $file = file_get_contents( $wp_cache_link );
1052 if( strpos( $file, "WP SUPER CACHE 0.8.9.1" ) ) {
1053 return true;
1054 } else {
1055 if( !@unlink($wp_cache_link) ) {
1056 $ret = false;
1057 } else {
1058 $ret = wp_cache_create_advanced_cache();
1059 }
1060 }
1061 } else {
1062 $ret = wp_cache_create_advanced_cache();
1063 }
1064
1065 if( false == $ret ) {
1066 echo "<h3>Warning! <em>" . constant( 'WP_CONTENT_DIR' ) . "/advanced-cache.php</em> does not exist or cannot be updated.</h3>";
1067 echo "<p><ul><li>1. If it already exists please delete the file first.</li>";
1068 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>";
1069 echo "<li>3. Refresh this page to update <em>" . constant( 'WP_CONTENT_DIR' ) . "/advanced-cache.php</em></li></ul>";
1070 echo "If that doesn't work, make sure the file <em>" . constant( 'WP_CONTENT_DIR' ) . "/advanced-cache.php</em> doesn't exist:<ol>";
1071 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>";
1072 return false;
1073 }
1074 return true;
1075 }
1076
1077 function wp_cache_check_global_config() {
1078 if( defined( 'WP_CACHE' ) )
1079 return true;
1080
1081 if ( file_exists( ABSPATH . 'wp-config.php') ) {
1082 $global = ABSPATH . 'wp-config.php';
1083 } else {
1084 $global = dirname(ABSPATH) . '/wp-config.php';
1085 }
1086
1087 $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. ";
1088 $lines = file($global);
1089 foreach($lines as $line) {
1090 if (preg_match('/^\s*define\s*\(\s*\'WP_CACHE\'\s*,\s*(?i:TRUE|1)\s*\)\s*;/', $line)) {
1091 echo $howtoenable;
1092 return false;
1093 }
1094 }
1095 $line = 'define(\'WP_CACHE\', true);';
1096 if (!is_writeable_ACLSafe($global) || !wp_cache_replace_line('define *\( *\'WP_CACHE\'', $line, $global) ) {
1097 echo "<strong>Error: WP_CACHE is not enabled</strong> in your <code>wp-config.php</code> file and I couldn't modify it.";
1098 echo $howtoenable;
1099 return false;
1100 }
1101 return true;
1102 }
1103
1104 function wp_cache_files() {
1105 global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled, $blog_cache_dir;
1106
1107 if ( '/' != substr($cache_path, -1)) {
1108 $cache_path .= '/';
1109 }
1110
1111 if ( $valid_nonce ) {
1112 if(isset($_REQUEST['wp_delete_cache'])) {
1113 wp_cache_clean_cache($file_prefix);
1114 }
1115 if(isset($_REQUEST['wp_delete_cache_file'])) {
1116 wp_cache_clean_cache($_REQUEST['wp_delete_cache_file']);
1117 }
1118 if(isset($_REQUEST['wp_delete_expired'])) {
1119 wp_cache_clean_expired($file_prefix);
1120 }
1121 }
1122 if(isset($_REQUEST['wp_list_cache'])) {
1123 $list_files = true;
1124 $list_mess = "Update list";
1125 } else
1126 $list_mess = "List files";
1127
1128 echo '<fieldset class="options" id="show-this-fieldset"><h3>Cache Contents</h3>';
1129 /*
1130 echo '<form name="wp_cache_content_list" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
1131 echo '<input type="hidden" name="wp_list_cache" />';
1132 echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="'.$list_mess.' &raquo;" /></div>';
1133 echo "</form>\n";
1134 */
1135
1136 $list_files = false; // it doesn't list supercached files, and removing single pages is buggy
1137 $count = 0;
1138 $expired = 0;
1139 $now = time();
1140 if ( ($handle = @opendir( $blog_cache_dir . 'meta/' )) ) {
1141 if ($list_files) echo "<table cellspacing=\"0\" cellpadding=\"5\">";
1142 while ( false !== ($file = readdir($handle))) {
1143 if ( preg_match("/^$file_prefix.*\.meta/", $file) ) {
1144 $this_expired = false;
1145 $content_file = preg_replace("/meta$/", "html", $file);
1146 $mtime = filemtime( $blog_cache_dir . 'meta/' . $file );
1147 if ( ! ( $fsize = @filesize( $blog_cache_dir . $content_file ) ) )
1148 continue; // .meta does not exists
1149 $fsize = intval($fsize/1024);
1150 $age = $now - $mtime;
1151 if ( $age > $cache_max_time ) {
1152 $expired++;
1153 $this_expired = true;
1154 }
1155 $count++;
1156 /*
1157 if ($list_files) {
1158 $meta = new CacheMeta;
1159 $meta = unserialize(file_get_contents($cache_path . 'meta/' . $file));
1160 echo $flip ? '<tr style="background: #EAEAEA;">' : '<tr>';
1161 $flip = !$flip;
1162 echo '<td><a href="http://' . $meta->uri . '" target="_blank" >';
1163 echo $meta->uri . "</a></td>";
1164 if ($this_expired) echo "<td><span style='color:red'>$age secs</span></td>";
1165 else echo "<td>$age secs</td>";
1166 echo "<td>$fsize KB</td>";
1167 echo '<td><form name="wp_delete_cache_file" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
1168 echo '<input type="hidden" name="wp_list_cache" />';
1169 echo '<input type="hidden" name="wp_delete_cache_file" value="'.preg_replace("/^(.*)\.meta$/", "$1", $file).'" />';
1170 echo '<div class="submit"><input id="deletepost" ' . SUBMITDISABLED . 'type="submit" value="Remove" /></div>';
1171 wp_nonce_field('wp-cache');
1172 echo "</form></td></tr>\n";
1173 }
1174 */
1175 }
1176 }
1177 closedir($handle);
1178 if ($list_files) echo "</table>";
1179 }
1180 if( $cache_enabled == true && $super_cache_enabled == true ) {
1181 $now = time();
1182 $sizes = array( 'expired' => 0, 'cached' => 0, 'ts' => 0 );
1183
1184 if (is_dir($supercachedir)) {
1185 if( $dh = opendir( $supercachedir ) ) {
1186 while( ( $entry = readdir( $dh ) ) !== false ) {
1187 if ($entry != '.' && $entry != '..') {
1188 $sizes = wpsc_dirsize( trailingslashit( $supercachedir ) . $entry, $sizes );
1189 }
1190 }
1191 closedir($dh);
1192 }
1193 } else {
1194 if(is_file($supercachedir) && filemtime( $supercachedir ) + $cache_max_time <= $now )
1195 $sizes[ 'expired' ] ++;
1196 }
1197 $sizes[ 'ts' ] = time();
1198 }
1199
1200 echo "<p><strong>WP-Cache</strong></p>";
1201 echo "<ul><li>$count Cached Pages</li>";
1202 echo "<li>$expired Expired Pages</li></ul>";
1203 if( $cache_enabled == true && $super_cache_enabled == true ) {
1204 echo "<p><strong>WP-Super-Cache</strong></p>";
1205 echo "<ul><li>" . intval($sizes['cached']/2) . " Cached Pages</li>";
1206 $age = intval(($now - $sizes['ts'])/60);
1207 echo "<li>" . intval($sizes['expired']/2) . " Expired Pages</li></ul>";
1208 }
1209 $last_gc = get_option( "wpsupercache_gc_time" );
1210 if( $last_gc ) {
1211 $next_gc = $cache_max_time < 1800 ? $cache_max_time : 600;
1212 echo "<p><strong>Garbage Collection</strong><br />Last: " . date( "Y-m-d H:i:s", ( $last_gc + ( get_option( 'gmt_offset' ) * 3600 ) ) ) . "<br />";
1213 echo "Next: " . date( "Y-m-d H:i:s", ( $next_gc + $last_gc + ( get_option( 'gmt_offset' ) * 3600 ) ) ) . "</p>";
1214 }
1215
1216 echo "<p>Expired files are files older than $cache_max_time seconds. They are still used by the plugin and are deleted periodically.</p>";
1217 echo '<form name="wp_cache_content_expired" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
1218 echo '<input type="hidden" name="wp_delete_expired" />';
1219 echo '<div class="submit" style="float:left"><input type="submit" ' . SUBMITDISABLED . 'value="Delete Expired &raquo;" /></div>';
1220 wp_nonce_field('wp-cache');
1221 echo "</form>\n";
1222
1223 echo '<form name="wp_cache_content_delete" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
1224 echo '<input type="hidden" name="wp_delete_cache" />';
1225 echo '<div class="submit" style="float:left;margin-left:10px"><input id="deletepost" type="submit" ' . SUBMITDISABLED . 'value="Delete Cache &raquo;" /></div>';
1226 wp_nonce_field('wp-cache');
1227 echo "</form>\n";
1228
1229 echo '</fieldset>';
1230 }
1231
1232 function delete_cache_dashboard() {
1233 if( function_exists( 'is_site_admin' ) && !is_site_admin() )
1234 return false;
1235
1236 if( function_exists('current_user_can') && !current_user_can('manage_options') )
1237 return false;
1238
1239 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>";
1240 }
1241 add_action( 'dashmenu', 'delete_cache_dashboard' );
1242
1243 function wpsc_dirsize($directory, $sizes) {
1244 global $cache_max_time;
1245 $now = time();
1246
1247 if (is_dir($directory)) {
1248 if( $dh = opendir( $directory ) ) {
1249 while( ( $entry = readdir( $dh ) ) !== false ) {
1250 if ($entry != '.' && $entry != '..') {
1251 $sizes = wpsc_dirsize( trailingslashit( $directory ) . $entry, $sizes );
1252 }
1253 }
1254 closedir($dh);
1255 }
1256 } else {
1257 if(is_file($directory) ) {
1258 if( filemtime( $directory ) + $cache_max_time <= $now ) {
1259 $sizes[ 'expired' ]+=1;
1260 } else {
1261 $sizes[ 'cached' ]+=1;
1262 }
1263 }
1264 }
1265 return $sizes;
1266 }
1267
1268
1269 function wp_cache_clean_cache($file_prefix) {
1270 global $cache_path, $supercachedir, $blog_cache_dir;
1271
1272 // If phase2 was compiled, use its function to avoid race-conditions
1273 if(function_exists('wp_cache_phase2_clean_cache')) {
1274 if (function_exists ('prune_super_cache')) {
1275 if( is_dir( $supercachedir ) ) {
1276 prune_super_cache( $supercachedir, true );
1277 } elseif( is_dir( $supercachedir . '.disabled' ) ) {
1278 prune_super_cache( $supercachedir . '.disabled', true );
1279 }
1280 prune_super_cache( $cache_path, true );
1281 $_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
1282 }
1283 return wp_cache_phase2_clean_cache($file_prefix);
1284 }
1285
1286 $expr = "/^$file_prefix/";
1287 if ( ($handle = @opendir( $blog_cache_dir )) ) {
1288 while ( false !== ($file = readdir($handle))) {
1289 if ( preg_match($expr, $file) ) {
1290 @unlink( $blog_cache_dir . $file);
1291 @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
1292 }
1293 }
1294 closedir($handle);
1295 }
1296 }
1297
1298 function wp_cache_clean_expired($file_prefix) {
1299 global $cache_path, $cache_max_time, $blog_cache_dir;
1300
1301 // If phase2 was compiled, use its function to avoid race-conditions
1302 if(function_exists('wp_cache_phase2_clean_expired')) {
1303 if (function_exists ('prune_super_cache')) {
1304 $dir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]);
1305 if( is_dir( $dir ) ) {
1306 prune_super_cache( $dir );
1307 } elseif( is_dir( $dir . '.disabled' ) ) {
1308 prune_super_cache( $dir . '.disabled' );
1309 }
1310 $_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
1311 }
1312 return wp_cache_phase2_clean_expired($file_prefix);
1313 }
1314
1315 $expr = "/^$file_prefix/";
1316 $now = time();
1317 if ( ($handle = @opendir( $blog_cache_dir )) ) {
1318 while ( false !== ($file = readdir($handle))) {
1319 if ( preg_match( $expr, $file ) &&
1320 ( filemtime( $blog_cache_dir . $file ) + $cache_max_time ) <= $now ) {
1321 @unlink( $blog_cache_dir . $file );
1322 @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
1323 }
1324 }
1325 closedir($handle);
1326 }
1327 }
1328
1329 function wpsc_remove_marker( $filename, $marker ) {
1330 if (!file_exists( $filename ) || is_writeable_ACLSafe( $filename ) ) {
1331 if (!file_exists( $filename ) ) {
1332 return '';
1333 } else {
1334 $markerdata = explode( "\n", implode( '', file( $filename ) ) );
1335 }
1336
1337 $f = fopen( $filename, 'w' );
1338 $foundit = false;
1339 if ( $markerdata ) {
1340 $state = true;
1341 foreach ( $markerdata as $n => $markerline ) {
1342 if (strpos($markerline, '# BEGIN ' . $marker) !== false)
1343 $state = false;
1344 if ( $state ) {
1345 if ( $n + 1 < count( $markerdata ) )
1346 fwrite( $f, "{$markerline}\n" );
1347 else
1348 fwrite( $f, "{$markerline}" );
1349 }
1350 if (strpos($markerline, '# END ' . $marker) !== false) {
1351 $state = true;
1352 }
1353 }
1354 }
1355 return true;
1356 } else {
1357 return false;
1358 }
1359 }
1360
1361 function wp_super_cache_footer() {
1362 ?><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
1363 }
1364 if( isset( $wp_cache_hello_world ) && $wp_cache_hello_world )
1365 add_action( 'wp_footer', 'wp_super_cache_footer' );
1366
1367 if( get_option( 'gzipcompression' ) )
1368 update_option( 'gzipcompression', 0 );
1369
1370 // Catch 404 requests. Themes that use query_posts() destroy $wp_query->is_404
1371 function wp_cache_catch_404() {
1372 global $wp_cache_404;
1373 $wp_cache_404 = false;
1374 if( is_404() )
1375 $wp_cache_404 = true;
1376 }
1377 add_action( 'template_redirect', 'wp_cache_catch_404' );
1378
1379 function wp_cache_favorite_action( $actions ) {
1380 if( function_exists( 'is_site_admin' ) && !is_site_admin() )
1381 return $actions;
1382
1383 if( function_exists('current_user_can') && !current_user_can('manage_options') )
1384 return $actions;
1385
1386 $actions[ wp_nonce_url( 'options-general.php?page=wpsupercache&wp_delete_cache=1', 'wp-cache' ) ] = array( __( 'Delete Cache' ), 'manage_options' );
1387
1388 return $actions;
1389 }
1390 add_filter( 'favorite_actions', 'wp_cache_favorite_action' );
1391
1392 function wp_cache_plugin_notice( $plugin ) {
1393 global $cache_enabled;
1394 if( $plugin == 'wp-super-cache/wp-cache.php' && !$cache_enabled && function_exists( "admin_url" ) )
1395 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>';
1396 }
1397 add_action( 'after_plugin_row', 'wp_cache_plugin_notice' );
1398
1399 function wp_cache_plugin_actions( $links, $file ) {
1400 if( $file == 'wp-super-cache/wp-cache.php' && function_exists( "admin_url" ) ) {
1401 $settings_link = '<a href="' . admin_url( 'options-general.php?page=wpsupercache' ) . '">' . __('Settings') . '</a>';
1402 array_unshift( $links, $settings_link ); // before other links
1403 }
1404 return $links;
1405 }
1406 add_filter( 'plugin_action_links', 'wp_cache_plugin_actions', 10, 2 );
1407
1408 function wp_cache_admin_notice() {
1409 global $cache_enabled;
1410 if( substr( $_SERVER["PHP_SELF"], -11 ) == 'plugins.php' && !$cache_enabled && function_exists( "admin_url" ) )
1411 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>';
1412 }
1413 add_action( 'admin_notices', 'wp_cache_admin_notice' );
1414 ?>
1415