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