WP Super Cache - Version 0.6.7

Version Description

Download this release

Release Info

Developer donncha
Plugin Icon 128x128 WP Super Cache
Version 0.6.7
Comparing to
See all releases

Code changes from version 0.6.6 to 0.6.7

Changelog.txt CHANGED
@@ -1,3 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  2008-07-31 10:47 donncha
2
 
3
  * readme.txt, wp-cache.php: Bump version numbers
1
+ 2008-08-20 10:49 donncha
2
+
3
+ * readme.txt, wp-cache.php: Bump version number to 0.6.7
4
+
5
+ 2008-08-20 09:38 donncha
6
+
7
+ * wp-cache.php: Added CRs
8
+
9
+ 2008-08-20 09:01 donncha
10
+
11
+ * wp-cache.php: Added apache_request_headers() as suggested in
12
+ http://wordpress.org/support/topic/197053
13
+
14
+ 2008-08-19 16:27 donncha
15
+
16
+ * plugins/searchengine.php, wp-cache.php: Updated styling with the
17
+ help of the simple trackback validation plugin
18
+
19
+ 2008-08-19 15:11 donncha
20
+
21
+ * wp-cache-config-sample.php: Don't include rss files in cacheable
22
+ list
23
+
24
+ 2008-08-19 15:05 donncha
25
+
26
+ * wp-cache.php: Added "deactivation hook" to remove
27
+ advanced-cache.php and wp-cache-config.php and cached files.
28
+
29
+ 2008-08-14 10:39 donncha
30
+
31
+ * wp-cache-phase1.php: Only include once
32
+
33
+ 2008-08-14 09:14 donncha
34
+
35
+ * wp-cache-phase1.php, wp-cache-phase2.php: Cron fixed from Mike
36
+
37
+ 2008-08-13 12:52 donncha
38
+
39
+ * wp-cache-phase2.php, wp-cache.php: Fixes from Mike Beggs:
40
+ Use custom is_writeable() that works in Win32 NTFS
41
+ Update "Vary" header
42
+ Let WP Cron handle cache cleaning.
43
+ Don't let mod_deflate try to compress gzipped cached files
44
+
45
+ 2008-08-09 10:13 donncha
46
+
47
+ * wp-cache-phase2.php: Use get_comment(), props Lazy @
48
+ http://www.lazybrain.de/
49
+
50
+ 2008-07-31 15:53 donncha
51
+
52
+ * Changelog.txt: Updated changelog
53
+
54
  2008-07-31 10:47 donncha
55
 
56
  * readme.txt, wp-cache.php: Bump version numbers
plugins/searchengine.php CHANGED
@@ -66,13 +66,13 @@ function wp_supercache_searchengine_admin() {
66
  } else {
67
  echo 'enabled';
68
  }
69
- echo '.</strong> (requires <a href="http://ocaoimh.ie/no-adverts-for-friends/">friendsadverts.php</a> too)<div class="submit">';
70
  if( $cache_no_adverts_for_friends == 'no' ) {
71
  echo '<input type="submit" name="cache_no_adverts_for_friends" value="Enable &raquo;" />';
72
  } else {
73
  echo '<input type="submit" name="cache_no_adverts_for_friends" value="Disable &raquo;" />';
74
  }
75
- echo "</div></form>\n";
76
 
77
  }
78
  add_cacheaction( 'cache_admin_page', 'wp_supercache_searchengine_admin' );
66
  } else {
67
  echo 'enabled';
68
  }
69
+ echo '.</strong> (requires <a href="http://ocaoimh.ie/no-adverts-for-friends/">friendsadverts.php</a> too) ';
70
  if( $cache_no_adverts_for_friends == 'no' ) {
71
  echo '<input type="submit" name="cache_no_adverts_for_friends" value="Enable &raquo;" />';
72
  } else {
73
  echo '<input type="submit" name="cache_no_adverts_for_friends" value="Disable &raquo;" />';
74
  }
75
+ echo "</form>\n";
76
 
77
  }
78
  add_cacheaction( 'cache_admin_page', 'wp_supercache_searchengine_admin' );
readme.txt CHANGED
@@ -1,8 +1,8 @@
1
  === WP Super Cache ===
2
  Contributors: donncha
3
  Tags: performance,caching,wp-cache
4
- Tested up to: 2.6
5
- Stable tag: 0.6.6
6
  Requires at least: 2.2
7
 
8
  A very fast caching engine for WordPress that produces static html files.
1
  === WP Super Cache ===
2
  Contributors: donncha
3
  Tags: performance,caching,wp-cache
4
+ Tested up to: 2.6.1
5
+ Stable tag: 0.6.7
6
  Requires at least: 2.2
7
 
8
  A very fast caching engine for WordPress that produces static html files.
wp-cache-config-sample.php CHANGED
@@ -38,7 +38,7 @@ if( defined( 'VHOST' ) ) {
38
  }
39
 
40
  // Array of files that have 'wp-' but should still be cached
41
- $cache_acceptable_files = array( 'wp-atom.php', 'wp-comments-popup.php', 'wp-commentsrss2.php', 'wp-links-opml.php', 'wp-locations.php', 'wp-rdf.php', 'wp-rss.php', 'wp-rss2.php');
42
 
43
  $cache_rejected_uri = array('wp-.*.php', 'index.php');
44
  $cache_rejected_user_agent = array ( 0 => 'bot', 1 => 'ia_archive', 2 => 'slurp', 3 => 'crawl', 4 => 'spider');
38
  }
39
 
40
  // Array of files that have 'wp-' but should still be cached
41
+ $cache_acceptable_files = array( 'wp-comments-popup.php', 'wp-links-opml.php', 'wp-locations.php' );
42
 
43
  $cache_rejected_uri = array('wp-.*.php', 'index.php');
44
  $cache_rejected_user_agent = array ( 0 => 'bot', 1 => 'ia_archive', 2 => 'slurp', 3 => 'crawl', 4 => 'spider');
wp-cache-phase1.php CHANGED
@@ -10,6 +10,11 @@ if( !defined( 'WPCACHEHOME' ) )
10
 
11
  include( WPCACHEHOME . 'wp-cache-base.php');
12
 
 
 
 
 
 
13
  $mutex_filename = 'wp_cache_mutex.lock';
14
  $new_cache = false;
15
 
@@ -85,7 +90,7 @@ function wp_cache_postload() {
85
 
86
  if (!$cache_enabled)
87
  return;
88
- require( WPCACHEHOME . 'wp-cache-phase2.php');
89
  wp_cache_phase2();
90
  }
91
 
10
 
11
  include( WPCACHEHOME . 'wp-cache-base.php');
12
 
13
+ if(defined('DOING_CRON')) {
14
+ require_once( WPCACHEHOME . 'wp-cache-phase2.php');
15
+ return;
16
+ }
17
+
18
  $mutex_filename = 'wp_cache_mutex.lock';
19
  $new_cache = false;
20
 
90
 
91
  if (!$cache_enabled)
92
  return;
93
+ require_once( WPCACHEHOME . 'wp-cache-phase2.php');
94
  wp_cache_phase2();
95
  }
96
 
wp-cache-phase2.php CHANGED
@@ -21,6 +21,8 @@ function wp_cache_phase2() {
21
  add_action('delete_comment', 'wp_cache_no_postid', 0);
22
  add_action('switch_theme', 'wp_cache_no_postid', 0);
23
 
 
 
24
  do_cacheaction( 'add_cacheaction' );
25
  }
26
  if( $_SERVER["REQUEST_METHOD"] == 'POST' || get_option('gzipcompression'))
@@ -31,6 +33,10 @@ function wp_cache_phase2() {
31
  return;
32
  if (wp_cache_user_agent_is_rejected()) return;
33
  $wp_cache_meta_object = new CacheMeta;
 
 
 
 
34
  ob_start('wp_cache_ob_callback');
35
  register_shutdown_function('wp_cache_shutdown_callback');
36
  }
@@ -211,11 +217,12 @@ function wp_cache_ob_callback($buffer) {
211
  $gzsize = strlen($gzdata);
212
 
213
  array_push($wp_cache_meta_object->headers, 'Content-Encoding: ' . $wp_cache_gzip_encoding);
214
- array_push($wp_cache_meta_object->headers, 'Vary: Accept-Encoding');
215
  array_push($wp_cache_meta_object->headers, 'Content-Length: ' . strlen($gzdata));
216
  // Return uncompressed data & store compressed for later use
217
  fputs($fr, $gzdata);
218
  }else{ // no compression
 
219
  fputs($fr, $buffer.$log);
220
  }
221
  if( $fr2 )
@@ -374,6 +381,7 @@ function wp_cache_shutdown_callback() {
374
  }
375
 
376
  @ob_end_flush();
 
377
  if ($new_cache) {
378
  $serial = serialize($wp_cache_meta_object);
379
  if( !wp_cache_writers_entry() )
@@ -392,9 +400,9 @@ function wp_cache_shutdown_callback() {
392
  if( mt_rand( 0, $wp_cache_gc ) != 1 )
393
  return;
394
 
395
- // we delete expired files
396
- flush(); //Ensure we send data to the client
397
- wp_cache_phase2_clean_expired($file_prefix);
398
  }
399
 
400
  function wp_cache_no_postid($id) {
@@ -403,7 +411,7 @@ function wp_cache_no_postid($id) {
403
 
404
  function wp_cache_get_postid_from_comment($comment_id) {
405
  global $super_cache_enabled;
406
- $comment = get_commentdata($comment_id, 1, true);
407
  $postid = $comment['comment_post_ID'];
408
  // Do nothing if comment is not moderated
409
  // http://ocaoimh.ie/2006/12/05/caching-wordpress-with-wp-cache-in-a-spam-filled-world
@@ -489,4 +497,10 @@ function wp_cache_post_id() {
489
  if (isset( $_POST[ 'p' ] ) && $_POST['p'] > 0) return $_POST['p'];
490
  return 0;
491
  }
 
 
 
 
 
 
492
  ?>
21
  add_action('delete_comment', 'wp_cache_no_postid', 0);
22
  add_action('switch_theme', 'wp_cache_no_postid', 0);
23
 
24
+ add_action('wp_cache_gc','wp_cache_gc_cron');
25
+
26
  do_cacheaction( 'add_cacheaction' );
27
  }
28
  if( $_SERVER["REQUEST_METHOD"] == 'POST' || get_option('gzipcompression'))
33
  return;
34
  if (wp_cache_user_agent_is_rejected()) return;
35
  $wp_cache_meta_object = new CacheMeta;
36
+ if($wp_cache_gzip_encoding)
37
+ header('Vary: Accept-Encoding, Cookie');
38
+ else
39
+ header('Vary: Cookie');
40
  ob_start('wp_cache_ob_callback');
41
  register_shutdown_function('wp_cache_shutdown_callback');
42
  }
217
  $gzsize = strlen($gzdata);
218
 
219
  array_push($wp_cache_meta_object->headers, 'Content-Encoding: ' . $wp_cache_gzip_encoding);
220
+ array_push($wp_cache_meta_object->headers, 'Vary: Accept-Encoding, Cookie');
221
  array_push($wp_cache_meta_object->headers, 'Content-Length: ' . strlen($gzdata));
222
  // Return uncompressed data & store compressed for later use
223
  fputs($fr, $gzdata);
224
  }else{ // no compression
225
+ array_push($wp_cache_meta_object->headers, 'Vary: Cookie');
226
  fputs($fr, $buffer.$log);
227
  }
228
  if( $fr2 )
381
  }
382
 
383
  @ob_end_flush();
384
+ flush(); //Ensure we send data to the client
385
  if ($new_cache) {
386
  $serial = serialize($wp_cache_meta_object);
387
  if( !wp_cache_writers_entry() )
400
  if( mt_rand( 0, $wp_cache_gc ) != 1 )
401
  return;
402
 
403
+ // we delete expired files, using a wordpress cron event
404
+ // since flush() does not guarantee hand-off to client - problem on Win32 and suPHP
405
+ if(!wp_next_scheduled('wp_cache_gc')) wp_schedule_single_event(time() + 10 , 'wp_cache_gc');
406
  }
407
 
408
  function wp_cache_no_postid($id) {
411
 
412
  function wp_cache_get_postid_from_comment($comment_id) {
413
  global $super_cache_enabled;
414
+ $comment = get_comment($comment_ID, ARRAY_A);
415
  $postid = $comment['comment_post_ID'];
416
  // Do nothing if comment is not moderated
417
  // http://ocaoimh.ie/2006/12/05/caching-wordpress-with-wp-cache-in-a-spam-filled-world
497
  if (isset( $_POST[ 'p' ] ) && $_POST['p'] > 0) return $_POST['p'];
498
  return 0;
499
  }
500
+
501
+ function wp_cache_gc_cron() {
502
+ global $file_prefix;
503
+ wp_cache_phase2_clean_expired($file_prefix);
504
+ }
505
+
506
  ?>
wp-cache.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP Super Cache
4
  Plugin URI: http://ocaoimh.ie/wp-super-cache/
5
  Description: Very fast caching module for WordPress. Once enabled, you must <a href="options-general.php?page=wp-super-cache/wp-cache.php">enable the cache</a>. Based on WP-Cache by <a href="http://mnm.uib.es/gallir/">Ricardo Galli Granada</a>.
6
- Version: 0.6.6
7
  Author: Donncha O Caoimh
8
  Author URI: http://ocaoimh.ie/
9
  */
@@ -47,6 +47,27 @@ $wp_cache_file = WPCACHEHOME . 'wp-cache-phase1.php';
47
 
48
  include(WPCACHEHOME . 'wp-cache-base.php');
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  function get_wpcachehome() {
51
  if( defined( 'WPCACHEHOME' ) == false ) {
52
  if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
@@ -59,6 +80,19 @@ function get_wpcachehome() {
59
  }
60
  }
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  function wp_cache_add_pages() {
63
  if( function_exists( 'is_site_admin' ) ) {
64
  if( is_site_admin() ) {
@@ -102,6 +136,10 @@ function toggleLayer( whichLayer ) {
102
  }
103
  // -->
104
  </script>
 
 
 
 
105
  <?php
106
  echo '<div class="wrap">';
107
  echo "<h2>WP Super Cache Manager</h2>\n";
@@ -137,7 +175,7 @@ function toggleLayer( whichLayer ) {
137
  <p>It appears that mod_rewrite is not installed. Sometimes this check isn't 100% reliable, especially if you are not using Apache. Please verify that the mod_rewrite module is loaded. It is required for serving Super Cache static files. You will still be able to use WP-Cache.</p><?php
138
  }
139
 
140
- if( !is_writable($wp_cache_config_file) ) {
141
  define( "SUBMITDISABLED", 'disabled style="color: #aaa" ' );
142
  ?><h4 style='text-align:center; color: #a00'>Read Only Mode. Configuration cannot be changed. <a href="javascript:toggleLayer('readonlywarning');" title="Why your configuration may not be changed">Why</a></h4>
143
  <div id='readonlywarning' style='border: 1px solid #aaa; margin: 2px; padding: 2px; display: none;'>
@@ -152,7 +190,7 @@ function toggleLayer( whichLayer ) {
152
 
153
  // Server could be running as the owner of the wp-content directory. Therefore, if it's
154
  // writable, issue a warning only if the permissions aren't 755.
155
- if( is_writable( WP_CONTENT_DIR . '/' ) ) {
156
  $wp_content_stat = stat(WP_CONTENT_DIR . '/');
157
  $wp_content_mode = ($wp_content_stat['mode'] & 0777);
158
  if( $wp_content_mode != 0755 ) {
@@ -192,24 +230,25 @@ function toggleLayer( whichLayer ) {
192
  }
193
  }
194
 
195
- ?><fieldset style='border: 1px solid #aaa' class="options">
196
- <legend>WP Super Cache Status</legend><?php
197
  echo '<form name="wp_manager" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
198
  ?>
199
  <label><input type='radio' name='wp_cache_status' value='all' <?php if( $cache_enabled == true && $super_cache_enabled == true ) { echo 'checked=checked'; } ?>> <strong>ON</strong> (WP Cache and Super Cache enabled)</label><br />
200
  <label><input type='radio' name='wp_cache_status' value='none' <?php if( $cache_enabled == false ) { echo 'checked=checked'; } ?>> <strong>OFF</strong> (WP Cache and Super Cache disabled)</label><br />
201
  <label><input type='radio' name='wp_cache_status' value='wpcache' <?php if( $cache_enabled == true && $super_cache_enabled == false ) { echo 'checked=checked'; } ?>> <strong>HALF ON</strong> (Super Cache Disabled, only legacy WP-Cache caching.)</label><br />
202
  <p><label><input type='checkbox' name='wp_cache_hello_world' <?php if( $wp_cache_hello_world ) echo "checked"; ?> value='1'> Proudly tell the world your server is Digg proof! (places a message in your blog's footer)</label></p>
 
203
  <?php
204
- echo "<div class='submit'><input " . SUBMITDISABLED . "type='submit' value='Update Status &raquo;' /></div>";
205
  wp_nonce_field('wp-cache');
206
  ?>
207
  </form>
208
  </fieldset>
209
 
210
  <?php if( $cache_enabled == true && $super_cache_enabled == true ) { ?>
211
- <br /><fieldset style='border: 1px solid #aaa' class="options">
212
- <legend>Super Cache Compression</legend>
213
  <form name="wp_manager" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post">
214
  <label><input type="radio" name="cache_compression" value="1" <?php if( $cache_compression ) { echo "checked=checked"; } ?>> Enabled</label>
215
  <label><input type="radio" name="cache_compression" value="0" <?php if( !$cache_compression ) { echo "checked=checked"; } ?>> Disabled</label>
@@ -220,13 +259,13 @@ function toggleLayer( whichLayer ) {
220
  } elseif( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && $cache_compression ) {
221
  ?><p><strong>Super Cache compression is now enabled.</strong></p><?php
222
  }
223
- echo '<div class="submit"><input ' . SUBMITDISABLED . 'type="submit" value="Update Compression &raquo;" /></div>';
224
  wp_nonce_field('wp-cache');
225
  echo "</form>\n";
226
  ?></fieldset><br />
227
 
228
- <fieldset style='border: 1px solid #aaa' class="options">
229
- <legend>Mod Rewrite Rules</legend><?php
230
  $home_path = get_home_path();
231
  $home_root = parse_url(get_bloginfo('url'));
232
  $home_root = trailingslashit($home_root['path']);
@@ -244,7 +283,7 @@ function toggleLayer( whichLayer ) {
244
  <blockquote><code><em># BEGIN WordPress</em><br /> RewriteCond %{REQUEST_FILENAME} !-f<br /> RewriteCond %{REQUEST_FILENAME} !-d<br /> RewriteRule . /index.php [L]<br /> <em># END WordPress</em></code></blockquote>
245
  Refresh this page when you have updated your .htaccess file.";
246
  } elseif( strpos( $wprules, 'wordpressuser' ) ) { // Need to clear out old mod_rewrite rules
247
- echo "<p><strong>Thank you for upgrading.</strong> The mod_rewrite rules changed since you last installed this plugin. Unfortunately you must remove the old supercache rules before the new ones are updated. Refresh this page when you have edited your .htaccess file. If you wish to manually upgrade, change the following line: <blockquote><code>RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*\$</code></blockquote> so it looks like this: <blockquote><code>RewriteCond %{HTTP_COOKIE} !^.*wordpress.*\$</code></blockquote> The only change is 'wordpressuser' becomes 'wordpress'. This is a WordPress 2.5 change but it's backwards compatible with older versions if you're brave enough to use them.</p>";
248
  echo "</fieldset>";
249
  echo "</div>\n";
250
  return;
@@ -261,7 +300,7 @@ function toggleLayer( whichLayer ) {
261
  $rules .= "RewriteCond %{QUERY_STRING} !.*p=.*\n";
262
  $rules .= "RewriteCond %{QUERY_STRING} !.*attachment_id=.*\n";
263
  $rules .= "RewriteCond %{QUERY_STRING} !.*wp-subscription-manager=.*\n";
264
- $rules .= "RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$\n";
265
  $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
266
  $rules .= "RewriteCond %{DOCUMENT_ROOT}{$inst_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz -f\n";
267
  $rules .= "RewriteRule ^(.*) {$inst_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz [L]\n\n";
@@ -271,7 +310,7 @@ function toggleLayer( whichLayer ) {
271
  $rules .= "RewriteCond %{QUERY_STRING} !.*p=.*\n";
272
  $rules .= "RewriteCond %{QUERY_STRING} !.*attachment_id=.*\n";
273
  $rules .= "RewriteCond %{QUERY_STRING} !.*wp-subscription-manager=.*\n";
274
- $rules .= "RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$\n";
275
  $rules .= "RewriteCond %{DOCUMENT_ROOT}{$inst_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html -f\n";
276
  $rules .= "RewriteRule ^(.*) {$inst_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html [L]\n";
277
  $rules .= "</IfModule>\n";
@@ -280,7 +319,7 @@ function toggleLayer( whichLayer ) {
280
  echo "<pre>" . wp_specialchars( $rules ) . "</pre></p>";
281
  echo '<form name="updatehtaccess" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
282
  echo '<input type="hidden" name="updatehtaccess" value="1" />';
283
- echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'id="updatehtaccess" value="Update mod_rewrite rules &raquo;" /></div>';
284
  wp_nonce_field('wp-cache');
285
  echo "</form>\n";
286
  } elseif( $dohtaccess && $valid_nonce && $_POST[ 'updatehtaccess' ] ) {
@@ -304,7 +343,10 @@ function toggleLayer( whichLayer ) {
304
  // http://allmybrain.com/2007/11/08/making-wp-super-cache-gzip-compression-work/
305
  if( !is_file( $cache_path . '.htaccess' ) ) {
306
  $gziprules = "AddEncoding x-gzip .gz\n";
307
- $gziprules .= "AddType text/html .gz";
 
 
 
308
  $gziprules = insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $gziprules ) );
309
  echo "<h4>Gzip encoding rules in {$cache_path}.htaccess created.</h4>";
310
  }
@@ -315,7 +357,7 @@ function toggleLayer( whichLayer ) {
315
 
316
  wp_cache_edit_max_time();
317
 
318
- echo '<br /><a name="files"></a><fieldset style="border: 1px solid #aaa" class="options"><legend>Accepted filenames, rejected URIs</legend>';
319
  wp_cache_edit_rejected();
320
  echo "<br />\n";
321
  wp_cache_edit_accepted();
@@ -339,7 +381,7 @@ function toggleLayer( whichLayer ) {
339
  $out = ob_get_contents();
340
  ob_end_clean();
341
  if( SUBMITDISABLED == ' ' && $out != '' ) {
342
- echo '<fieldset class="options"><legend>Cache Plugins</legend>';
343
  echo $out;
344
  echo '</fieldset>';
345
  }
@@ -349,10 +391,10 @@ function toggleLayer( whichLayer ) {
349
  }
350
 
351
  function wp_cache_restore() {
352
- echo '<br /><fieldset style="border: 1px solid #aaa" class="options"><legend>Configuration messed up?</legend>';
353
  echo '<form name="wp_restore" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
354
  echo '<input type="hidden" name="wp_restore_config" />';
355
- echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'id="deletepost" value="Restore default configuration &raquo;" /></div>';
356
  wp_nonce_field('wp-cache');
357
  echo "</form>\n";
358
  echo '</fieldset>';
@@ -382,8 +424,8 @@ function wp_lock_down() {
382
  $wp_lock_down = '0';
383
  }
384
  }
385
- ?><br /><br /><fieldset style='border: 1px solid #aaa' class="options">
386
- <legend>Lock Down: <span style='color: #f00'><?php echo $wp_lock_down == '0' ? 'disabled' : 'enabled'; ?></span> (advanced use only)</legend>
387
  <p>Prepare your server for an expected spike in traffic by enabling the lock down. When this is enabled, new comments on a post will not refresh the cached static files.</p>
388
  <p>Developers: Make your plugin lock down compatible by checking the 'WPLOCKDOWN' constant. The following code will make sure your plugin respects the WPLOCKDOWN setting.
389
  <blockquote><code>if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) ) { <br />
@@ -399,14 +441,14 @@ function wp_lock_down() {
399
  $new_lockdown_desc = $wp_lock_down == '1' ? 'Disable' : 'Enable';
400
  echo '<form name="wp_lock_down" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
401
  echo "<input type='hidden' name='wp_lock_down' value='{$new_lockdown}' />";
402
- echo "<div class='submit'><input type='submit' " . SUBMITDISABLED . "value='{$new_lockdown_desc} Lock Down &raquo;' /></div>";
403
  wp_nonce_field('wp-cache');
404
  echo "</form>\n";
405
 
406
  ?></fieldset><br /><?php
407
  if( $cache_enabled == true && $super_cache_enabled == true ) {
408
- ?><fieldset style='border: 1px solid #aaa' class="options">
409
- <legend>Directly Cached Files (advanced use only)</legend><?php
410
 
411
  $out = '';
412
  if( $valid_nonce && is_array( $_POST[ 'direct_pages' ] ) && !empty( $_POST[ 'direct_pages' ] ) ) {
@@ -460,7 +502,7 @@ function wp_lock_down() {
460
  $firstfolder = explode( '/', $page );
461
  $firstfolder = ABSPATH . $firstfolder[1];
462
  $page = ABSPATH . $page;
463
- if( is_file( $pagefile ) && is_writable( $pagefile ) && is_writable( $firstfolder ) ) {
464
  @unlink( $pagefile );
465
  @unlink( $pagefile . '.gz' );
466
  RecursiveFolderDelete( $firstfolder );
@@ -470,7 +512,7 @@ function wp_lock_down() {
470
  }
471
 
472
  $readonly = '';
473
- if( !is_writeable( ABSPATH ) ) {
474
  $readonly = 'READONLY';
475
  ?><p><strong style='color: #a00'>WARNING! You must make <?php echo ABSPATH ?> writable to enable this feature. As this is a security risk please make it readonly after your page is generated.</strong></p><?php
476
  } else {
@@ -552,8 +594,8 @@ function wp_cache_edit_max_time () {
552
  $wp_cache_gc = (int)$_POST['wp_cache_gc'];
553
  wp_cache_replace_line('^ *\$wp_cache_gc', "\$wp_cache_gc = $wp_cache_gc;", $wp_cache_config_file);
554
  }
555
- ?><br /><fieldset style='border: 1px solid #aaa' class="options">
556
- <legend>Expiry Time</legend><?php
557
  echo '<form name="wp_edit_max_time" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
558
  echo '<label for="wp_max_time">Expire time:</label> ';
559
  echo "<input type=\"text\" size=6 name=\"wp_max_time\" value=\"$cache_max_time\" /> seconds<br />";
@@ -570,7 +612,7 @@ function wp_cache_edit_max_time () {
570
  echo "<li><input type='radio' name='wp_cache_gc' value='2000'" . ( $wp_cache_gc == 2000 ? ' checked' : '' ) . " /> 2000 requests</li>\n";
571
  echo "<li><input type='radio' name='wp_cache_gc' value='5000'" . ( $wp_cache_gc == 5000 ? ' checked' : '' ) . " /> 5000 requests (very seldom)</li></ul>\n";
572
  echo "<p>Checking for and deleting expired files is expensive, but it's expensive leaving them there too. On a very busy site you can leave this fairly high. Experiment with different values and visit this page to see how many expired files remain at different times during the day.</p><p>Simple rule of thumb: divide your number of daily page views by 5 and pick the closest number above.</p>";
573
- echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Change expiration &raquo;" /></div>';
574
  wp_nonce_field('wp-cache');
575
  echo "</form>\n";
576
  ?></fieldset><?php
@@ -584,6 +626,21 @@ function wp_cache_sanitize_value($text, & $array) {
584
  return $text;
585
  }
586
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
587
  function wp_cache_edit_rejected_ua() {
588
  global $cache_rejected_user_agent, $wp_cache_config_file, $valid_nonce;
589
 
@@ -595,18 +652,18 @@ function wp_cache_edit_rejected_ua() {
595
  }
596
 
597
 
598
- echo '<br /><a name="user-agents"></a><fieldset style="border: 1px solid #aaa" class="options"><legend>Rejected User Agents</legend>';
599
  echo "<p>Strings in the HTTP 'User Agent' header that prevent WP-Cache from
600
  caching bot, spiders, and crawlers' requests.
601
  Note that cached files are still sent to these request if they already exists.</p>\n";
602
  echo '<form name="wp_edit_rejected_user_agent" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
603
- echo '<label for="wp_rejected_user_agent">Rejected UA strings</label>';
604
- echo '<textarea name="wp_rejected_user_agent" cols="40" rows="4" style="width: 70%; font-size: 12px;" class="code">';
605
  foreach ($cache_rejected_user_agent as $ua) {
606
  echo wp_specialchars($ua) . "\n";
607
  }
608
  echo '</textarea> ';
609
- echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Save UA strings &raquo;" /></div>';
610
  wp_nonce_field('wp-cache');
611
  echo '</form>';
612
  echo "</fieldset>\n";
@@ -622,15 +679,15 @@ function wp_cache_edit_rejected() {
622
  }
623
 
624
 
625
- echo "<p>Add here strings (not a filename) that forces a page not to be cached. For example, if your URLs include year and you dont want to cache last year posts, it's enough to specify the year, i.e. '/2004/'. WP-Cache will search if that string is part of the URI and if so, it will not cache that page.</p>\n";
626
  echo '<form name="wp_edit_rejected" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
627
- echo '<label for="wp_rejected_uri">Rejected URIs</label>';
628
- echo '<textarea name="wp_rejected_uri" cols="40" rows="4" style="width: 70%; font-size: 12px;" class="code">';
 
629
  foreach ($cache_rejected_uri as $file) {
630
  echo wp_specialchars($file) . "\n";
631
  }
632
  echo '</textarea> ';
633
- echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Save strings &raquo;" /></div>';
634
  wp_nonce_field('wp-cache');
635
  echo "</form>\n";
636
  }
@@ -644,15 +701,15 @@ function wp_cache_edit_accepted() {
644
  }
645
 
646
 
 
 
647
  echo "<p>Add here those filenames that can be cached, even if they match one of the rejected substring specified above.</p>\n";
648
- echo '<form name="wp_edit_accepted" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
649
- echo '<label for="wp_accepted_files">Accepted files</label>';
650
- echo '<textarea name="wp_accepted_files" cols="40" rows="8" style="width: 70%; font-size: 12px;" class="code">';
651
  foreach ($cache_acceptable_files as $file) {
652
  echo wp_specialchars($file) . "\n";
653
  }
654
  echo '</textarea> ';
655
- echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Save files &raquo;" /></div>';
656
  wp_nonce_field('wp-cache');
657
  echo "</form>\n";
658
  }
@@ -717,7 +774,7 @@ function wp_cache_is_enabled() {
717
 
718
 
719
  function wp_cache_replace_line($old, $new, $my_file) {
720
- if (!is_writable($my_file)) {
721
  echo "Error: file $my_file is not writable.<br />\n";
722
  return false;
723
  }
@@ -765,12 +822,12 @@ function wp_cache_verify_cache_dir() {
765
 
766
  $dir = dirname($cache_path);
767
  if ( !file_exists($cache_path) ) {
768
- if ( !is_writable( $dir ) || !($dir = mkdir( $cache_path ) ) ) {
769
  echo "<b>Error:</b> Your cache directory (<b>$cache_path</b>) did not exist and couldn't be created by the web server. <br /> Check $dir permissions.";
770
  return false;
771
  }
772
  }
773
- if ( !is_writable($cache_path)) {
774
  echo "<b>Error:</b> Your cache directory (<b>$cache_path</b>) or <b>$dir</b> need to be writable for this plugin to work. <br /> Double-check it.";
775
  return false;
776
  }
@@ -793,14 +850,14 @@ function wp_cache_verify_config_file() {
793
  if ( file_exists($wp_cache_config_file) ) {
794
  $lines = join( ' ', file( $wp_cache_config_file ) );
795
  if( strpos( $lines, 'WPCACHEHOME' ) === false ) {
796
- if( is_writable( $wp_cache_config_file ) ) {
797
  @unlink( $wp_cache_config_file );
798
  } else {
799
  echo "<b>Error:</b> Your WP-Cache config file (<b>$wp_cache_config_file</b>) is out of date and not writable by the Web server.<br />Please delete it and refresh this page.";
800
  return false;
801
  }
802
  }
803
- } elseif( !is_writable($dir)) {
804
  echo "<b>Error:</b> Configuration file missing and " . WP_CONTENT_DIR . " directory (<b>$dir</b>) is not writable by the Web server.<br />Check its permissions.";
805
  return false;
806
  }
@@ -870,7 +927,7 @@ function wp_cache_check_global_config() {
870
  }
871
  }
872
  $line = 'define(\'WP_CACHE\', true);';
873
- if (!is_writable($global) || !wp_cache_replace_line('define *\( *\'WP_CACHE\'', $line, $global) ) {
874
  echo "<b>Error: WP_CACHE is not enabled</b> in your <code>wp-config.php</code> file and I couldn't modified it.<br />";
875
  echo "Edit <code>$global</code> and add the following line: <br /><code>define('WP_CACHE', true);</code><br />Otherwise, <b>WP-Cache will not be executed</b> by Wordpress core. <br />";
876
  return false;
@@ -902,11 +959,11 @@ function wp_cache_files() {
902
  } else
903
  $list_mess = "List files";
904
 
905
- echo '<br /><a name="list"></a><fieldset style="border: 1px solid #aaa" class="options"><legend>Cache contents</legend>';
906
  /*
907
  echo '<form name="wp_cache_content_list" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
908
  echo '<input type="hidden" name="wp_list_cache" />';
909
- echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="'.$list_mess.' &raquo;" /></div>';
910
  echo "</form>\n";
911
  */
912
 
@@ -943,7 +1000,7 @@ function wp_cache_files() {
943
  echo '<td><form name="wp_delete_cache_file" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
944
  echo '<input type="hidden" name="wp_list_cache" />';
945
  echo '<input type="hidden" name="wp_delete_cache_file" value="'.preg_replace("/^(.*)\.meta$/", "$1", $file).'" />';
946
- echo '<div class="submit"><input id="deletepost" ' . SUBMITDISABLED . 'type="submit" value="Remove" /></div>';
947
  wp_nonce_field('wp-cache');
948
  echo "</form></td></tr>\n";
949
  }
@@ -970,11 +1027,11 @@ function wp_cache_files() {
970
  $sizes[ 'ts' ] = time();
971
  }
972
 
973
- echo "<p><strong>WP-Cache</strong></p>";
974
  echo "<ul><li>$count cached pages</li>";
975
  echo "<li>$expired expired pages</li></ul>";
976
  if( $cache_enabled == true && $super_cache_enabled == true ) {
977
- echo "<p><strong>WP-Super-Cache</strong></p>";
978
  echo "<ul><li>" . intval($sizes['cached']/2) . " cached pages</li>";
979
  $age = intval(($now - $sizes['ts'])/60);
980
  echo "<li>" . intval($sizes['expired']/2) . " expired pages.</li></ul>";
@@ -982,14 +1039,14 @@ function wp_cache_files() {
982
 
983
  echo '<form name="wp_cache_content_expired" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
984
  echo '<input type="hidden" name="wp_delete_expired" />';
985
- echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'value="Delete expired &raquo;" /></div>';
986
  wp_nonce_field('wp-cache');
987
  echo "</form>\n";
988
 
989
 
990
  echo '<form name="wp_cache_content_delete" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
991
  echo '<input type="hidden" name="wp_delete_cache" />';
992
- echo '<div class="submit"><input id="deletepost" type="submit" ' . SUBMITDISABLED . 'value="Delete cache &raquo;" /></div>';
993
  wp_nonce_field('wp-cache');
994
  echo "</form>\n";
995
 
@@ -1081,7 +1138,7 @@ function wp_cache_clean_expired($file_prefix) {
1081
  }
1082
 
1083
  function wpsc_remove_marker( $filename, $marker ) {
1084
- if (!file_exists( $filename ) || is_writeable( $filename ) ) {
1085
  if (!file_exists( $filename ) ) {
1086
  return '';
1087
  } else {
3
  Plugin Name: WP Super Cache
4
  Plugin URI: http://ocaoimh.ie/wp-super-cache/
5
  Description: Very fast caching module for WordPress. Once enabled, you must <a href="options-general.php?page=wp-super-cache/wp-cache.php">enable the cache</a>. Based on WP-Cache by <a href="http://mnm.uib.es/gallir/">Ricardo Galli Granada</a>.
6
+ Version: 0.6.7
7
  Author: Donncha O Caoimh
8
  Author URI: http://ocaoimh.ie/
9
  */
47
 
48
  include(WPCACHEHOME . 'wp-cache-base.php');
49
 
50
+
51
+ // from legolas558 d0t users dot sf dot net at http://www.php.net/is_writable
52
+ function is_writeable_ACLSafe($path) {
53
+
54
+ // PHP's is_writable does not work with Win32 NTFS
55
+
56
+ if ($path{strlen($path)-1}=='/') // recursively return a temporary file path
57
+ return is_writeable_ACLSafe($path.uniqid(mt_rand()).'.tmp');
58
+ else if (is_dir($path))
59
+ return is_writeable_ACLSafe($path.'/'.uniqid(mt_rand()).'.tmp');
60
+ // check tmp file for read/write capabilities
61
+ $rm = file_exists($path);
62
+ $f = @fopen($path, 'a');
63
+ if ($f===false)
64
+ return false;
65
+ fclose($f);
66
+ if (!$rm)
67
+ unlink($path);
68
+ return true;
69
+ }
70
+
71
  function get_wpcachehome() {
72
  if( defined( 'WPCACHEHOME' ) == false ) {
73
  if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
80
  }
81
  }
82
 
83
+ function wpsupercache_deactivate() {
84
+ global $wp_cache_config_file, $wp_cache_link, $cache_path;
85
+ $files = array( $wp_cache_config_file, $wp_cache_link );
86
+ foreach( $files as $file ) {
87
+ if( file_exists( $file ) )
88
+ unlink( $file );
89
+ }
90
+ if( !function_exists( 'prune_super_cache' ) )
91
+ include_once( 'wp-cache-phase2.php' );
92
+ prune_super_cache ($cache_path, true);
93
+ }
94
+ register_deactivation_hook( __FILE__, 'wpsupercache_deactivate' );
95
+
96
  function wp_cache_add_pages() {
97
  if( function_exists( 'is_site_admin' ) ) {
98
  if( is_site_admin() ) {
136
  }
137
  // -->
138
  </script>
139
+ <style type="text/css">
140
+ /* Taken from http://sw-guide.de/wordpress/plugins/simple-trackback-validation/ */
141
+ .wrap h3 { color: black; background-color: #e5f3ff; padding: 4px 8px; }
142
+ </style>
143
  <?php
144
  echo '<div class="wrap">';
145
  echo "<h2>WP Super Cache Manager</h2>\n";
175
  <p>It appears that mod_rewrite is not installed. Sometimes this check isn't 100% reliable, especially if you are not using Apache. Please verify that the mod_rewrite module is loaded. It is required for serving Super Cache static files. You will still be able to use WP-Cache.</p><?php
176
  }
177
 
178
+ if( !is_writeable_ACLSafe($wp_cache_config_file) ) {
179
  define( "SUBMITDISABLED", 'disabled style="color: #aaa" ' );
180
  ?><h4 style='text-align:center; color: #a00'>Read Only Mode. Configuration cannot be changed. <a href="javascript:toggleLayer('readonlywarning');" title="Why your configuration may not be changed">Why</a></h4>
181
  <div id='readonlywarning' style='border: 1px solid #aaa; margin: 2px; padding: 2px; display: none;'>
190
 
191
  // Server could be running as the owner of the wp-content directory. Therefore, if it's
192
  // writable, issue a warning only if the permissions aren't 755.
193
+ if( is_writeable_ACLSafe( WP_CONTENT_DIR . '/' ) ) {
194
  $wp_content_stat = stat(WP_CONTENT_DIR . '/');
195
  $wp_content_mode = ($wp_content_stat['mode'] & 0777);
196
  if( $wp_content_mode != 0755 ) {
230
  }
231
  }
232
 
233
+ ?><fieldset class="options">
234
+ <h3>WP Super Cache Status</h3><?php
235
  echo '<form name="wp_manager" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
236
  ?>
237
  <label><input type='radio' name='wp_cache_status' value='all' <?php if( $cache_enabled == true && $super_cache_enabled == true ) { echo 'checked=checked'; } ?>> <strong>ON</strong> (WP Cache and Super Cache enabled)</label><br />
238
  <label><input type='radio' name='wp_cache_status' value='none' <?php if( $cache_enabled == false ) { echo 'checked=checked'; } ?>> <strong>OFF</strong> (WP Cache and Super Cache disabled)</label><br />
239
  <label><input type='radio' name='wp_cache_status' value='wpcache' <?php if( $cache_enabled == true && $super_cache_enabled == false ) { echo 'checked=checked'; } ?>> <strong>HALF ON</strong> (Super Cache Disabled, only legacy WP-Cache caching.)</label><br />
240
  <p><label><input type='checkbox' name='wp_cache_hello_world' <?php if( $wp_cache_hello_world ) echo "checked"; ?> value='1'> Proudly tell the world your server is Digg proof! (places a message in your blog's footer)</label></p>
241
+ <p>Note: if uninstalling this plugin, make sure the directory <em><?php echo WP_CONTENT_DIR; ?></em> is writeable by the webserver so the files <em>advanced-cache.php</em> and <em>cache-config.php</em> can be deleted automatically. (Making sure those files are writeable too is probably a good idea!)</p>
242
  <?php
243
+ echo "<div><input type='submit' " . SUBMITDISABLED . " value='Update Status &raquo;' /></div>";
244
  wp_nonce_field('wp-cache');
245
  ?>
246
  </form>
247
  </fieldset>
248
 
249
  <?php if( $cache_enabled == true && $super_cache_enabled == true ) { ?>
250
+ <br /><fieldset class="options">
251
+ <h3>Super Cache Compression</h3>
252
  <form name="wp_manager" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post">
253
  <label><input type="radio" name="cache_compression" value="1" <?php if( $cache_compression ) { echo "checked=checked"; } ?>> Enabled</label>
254
  <label><input type="radio" name="cache_compression" value="0" <?php if( !$cache_compression ) { echo "checked=checked"; } ?>> Disabled</label>
259
  } elseif( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && $cache_compression ) {
260
  ?><p><strong>Super Cache compression is now enabled.</strong></p><?php
261
  }
262
+ echo '<div><input ' . SUBMITDISABLED . 'type="submit" value="Update Compression &raquo;" /></div>';
263
  wp_nonce_field('wp-cache');
264
  echo "</form>\n";
265
  ?></fieldset><br />
266
 
267
+ <fieldset class="options">
268
+ <h3>Mod Rewrite Rules</h3><?php
269
  $home_path = get_home_path();
270
  $home_root = parse_url(get_bloginfo('url'));
271
  $home_root = trailingslashit($home_root['path']);
283
  <blockquote><code><em># BEGIN WordPress</em><br /> RewriteCond %{REQUEST_FILENAME} !-f<br /> RewriteCond %{REQUEST_FILENAME} !-d<br /> RewriteRule . /index.php [L]<br /> <em># END WordPress</em></code></blockquote>
284
  Refresh this page when you have updated your .htaccess file.";
285
  } elseif( strpos( $wprules, 'wordpressuser' ) ) { // Need to clear out old mod_rewrite rules
286
+ echo "<p><strong>Thank you for upgrading.</strong> The mod_rewrite rules changed since you last installed this plugin. Unfortunately you must remove the old supercache rules before the new ones are updated. Refresh this page when you have edited your .htaccess file. If you wish to manually upgrade, change the following line: <blockquote><code>RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*\$</code></blockquote> so it looks like this: <blockquote><code>RewriteCond %{HTTP:Cookie} !^.*wordpress.*\$</code></blockquote> The only changes are 'HTTP_COOKIE' becomes 'HTTP:Cookie' and 'wordpressuser' becomes 'wordpress'. This is a WordPress 2.5 change but it's backwards compatible with older versions if you're brave enough to use them.</p>";
287
  echo "</fieldset>";
288
  echo "</div>\n";
289
  return;
300
  $rules .= "RewriteCond %{QUERY_STRING} !.*p=.*\n";
301
  $rules .= "RewriteCond %{QUERY_STRING} !.*attachment_id=.*\n";
302
  $rules .= "RewriteCond %{QUERY_STRING} !.*wp-subscription-manager=.*\n";
303
+ $rules .= "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$\n";
304
  $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
305
  $rules .= "RewriteCond %{DOCUMENT_ROOT}{$inst_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz -f\n";
306
  $rules .= "RewriteRule ^(.*) {$inst_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz [L]\n\n";
310
  $rules .= "RewriteCond %{QUERY_STRING} !.*p=.*\n";
311
  $rules .= "RewriteCond %{QUERY_STRING} !.*attachment_id=.*\n";
312
  $rules .= "RewriteCond %{QUERY_STRING} !.*wp-subscription-manager=.*\n";
313
+ $rules .= "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$\n";
314
  $rules .= "RewriteCond %{DOCUMENT_ROOT}{$inst_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html -f\n";
315
  $rules .= "RewriteRule ^(.*) {$inst_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html [L]\n";
316
  $rules .= "</IfModule>\n";
319
  echo "<pre>" . wp_specialchars( $rules ) . "</pre></p>";
320
  echo '<form name="updatehtaccess" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
321
  echo '<input type="hidden" name="updatehtaccess" value="1" />';
322
+ echo '<div><input type="submit" ' . SUBMITDISABLED . 'id="updatehtaccess" value="Update mod_rewrite rules &raquo;" /></div>';
323
  wp_nonce_field('wp-cache');
324
  echo "</form>\n";
325
  } elseif( $dohtaccess && $valid_nonce && $_POST[ 'updatehtaccess' ] ) {
343
  // http://allmybrain.com/2007/11/08/making-wp-super-cache-gzip-compression-work/
344
  if( !is_file( $cache_path . '.htaccess' ) ) {
345
  $gziprules = "AddEncoding x-gzip .gz\n";
346
+ $gziprules .= "AddType text/html .gz\n";
347
+ $gziprules .= "<IfModule mod_deflate.c>\n";
348
+ $gziprules .= " SetEnvIfNoCase Request_URI \.gz$ no-gzip\n";
349
+ $gziprules .= "</IfModule>";
350
  $gziprules = insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $gziprules ) );
351
  echo "<h4>Gzip encoding rules in {$cache_path}.htaccess created.</h4>";
352
  }
357
 
358
  wp_cache_edit_max_time();
359
 
360
+ echo '<br /><a name="files"></a><fieldset class="options"><h3>Accepted filenames, rejected URIs</h3>';
361
  wp_cache_edit_rejected();
362
  echo "<br />\n";
363
  wp_cache_edit_accepted();
381
  $out = ob_get_contents();
382
  ob_end_clean();
383
  if( SUBMITDISABLED == ' ' && $out != '' ) {
384
+ echo '<fieldset class="options"><h3>Cache Plugins</h3>';
385
  echo $out;
386
  echo '</fieldset>';
387
  }
391
  }
392
 
393
  function wp_cache_restore() {
394
+ echo '<br /><fieldset class="options"><h3>Configuration messed up?</h3>';
395
  echo '<form name="wp_restore" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
396
  echo '<input type="hidden" name="wp_restore_config" />';
397
+ echo '<div><input type="submit" ' . SUBMITDISABLED . 'id="deletepost" value="Restore default configuration &raquo;" /></div>';
398
  wp_nonce_field('wp-cache');
399
  echo "</form>\n";
400
  echo '</fieldset>';
424
  $wp_lock_down = '0';
425
  }
426
  }
427
+ ?><br /><br /><fieldset class="options">
428
+ <h3>Lock Down: <span style='color: #f00'><?php echo $wp_lock_down == '0' ? 'disabled' : 'enabled'; ?></span> (advanced use only)</h3>
429
  <p>Prepare your server for an expected spike in traffic by enabling the lock down. When this is enabled, new comments on a post will not refresh the cached static files.</p>
430
  <p>Developers: Make your plugin lock down compatible by checking the 'WPLOCKDOWN' constant. The following code will make sure your plugin respects the WPLOCKDOWN setting.
431
  <blockquote><code>if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) ) { <br />
441
  $new_lockdown_desc = $wp_lock_down == '1' ? 'Disable' : 'Enable';
442
  echo '<form name="wp_lock_down" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
443
  echo "<input type='hidden' name='wp_lock_down' value='{$new_lockdown}' />";
444
+ echo "<div><input type='submit' " . SUBMITDISABLED . " value='{$new_lockdown_desc} Lock Down &raquo;' /></div>";
445
  wp_nonce_field('wp-cache');
446
  echo "</form>\n";
447
 
448
  ?></fieldset><br /><?php
449
  if( $cache_enabled == true && $super_cache_enabled == true ) {
450
+ ?><fieldset class="options">
451
+ <h3>Directly Cached Files (advanced use only)</h3><?php
452
 
453
  $out = '';
454
  if( $valid_nonce && is_array( $_POST[ 'direct_pages' ] ) && !empty( $_POST[ 'direct_pages' ] ) ) {
502
  $firstfolder = explode( '/', $page );
503
  $firstfolder = ABSPATH . $firstfolder[1];
504
  $page = ABSPATH . $page;
505
+ if( is_file( $pagefile ) && is_writeable_ACLSafe( $pagefile ) && is_writeable_ACLSafe( $firstfolder ) ) {
506
  @unlink( $pagefile );
507
  @unlink( $pagefile . '.gz' );
508
  RecursiveFolderDelete( $firstfolder );
512
  }
513
 
514
  $readonly = '';
515
+ if( !is_writeable_ACLSafe( ABSPATH ) ) {
516
  $readonly = 'READONLY';
517
  ?><p><strong style='color: #a00'>WARNING! You must make <?php echo ABSPATH ?> writable to enable this feature. As this is a security risk please make it readonly after your page is generated.</strong></p><?php
518
  } else {
594
  $wp_cache_gc = (int)$_POST['wp_cache_gc'];
595
  wp_cache_replace_line('^ *\$wp_cache_gc', "\$wp_cache_gc = $wp_cache_gc;", $wp_cache_config_file);
596
  }
597
+ ?><br /><fieldset class="options">
598
+ <h3>Expiry Time and Garbage Collection</h3><?php
599
  echo '<form name="wp_edit_max_time" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
600
  echo '<label for="wp_max_time">Expire time:</label> ';
601
  echo "<input type=\"text\" size=6 name=\"wp_max_time\" value=\"$cache_max_time\" /> seconds<br />";
612
  echo "<li><input type='radio' name='wp_cache_gc' value='2000'" . ( $wp_cache_gc == 2000 ? ' checked' : '' ) . " /> 2000 requests</li>\n";
613
  echo "<li><input type='radio' name='wp_cache_gc' value='5000'" . ( $wp_cache_gc == 5000 ? ' checked' : '' ) . " /> 5000 requests (very seldom)</li></ul>\n";
614
  echo "<p>Checking for and deleting expired files is expensive, but it's expensive leaving them there too. On a very busy site you can leave this fairly high. Experiment with different values and visit this page to see how many expired files remain at different times during the day.</p><p>Simple rule of thumb: divide your number of daily page views by 5 and pick the closest number above.</p>";
615
+ echo '<div><input type="submit" ' . SUBMITDISABLED . 'value="Change expiration &raquo;" /></div>';
616
  wp_nonce_field('wp-cache');
617
  echo "</form>\n";
618
  ?></fieldset><?php
626
  return $text;
627
  }
628
 
629
+ // from tehjosh at gamingg dot net http://uk2.php.net/manual/en/function.apache-request-headers.php#73964
630
+ // fixed bug in second substr()
631
+ if( !function_exists('apache_request_headers') ) {
632
+ function apache_request_headers() {
633
+ $headers = array();
634
+ foreach(array_keys($_SERVER) as $skey) {
635
+ if(substr($skey, 0, 5) == "HTTP_") {
636
+ $headername = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($skey, 5)))));
637
+ $headers[$headername] = $_SERVER[$skey];
638
+ }
639
+ }
640
+ return $headers;
641
+ }
642
+ }
643
+
644
  function wp_cache_edit_rejected_ua() {
645
  global $cache_rejected_user_agent, $wp_cache_config_file, $valid_nonce;
646
 
652
  }
653
 
654
 
655
+ echo '<br /><a name="user-agents"></a><fieldset class="options"><h3>Rejected User Agents</h3>';
656
  echo "<p>Strings in the HTTP 'User Agent' header that prevent WP-Cache from
657
  caching bot, spiders, and crawlers' requests.
658
  Note that cached files are still sent to these request if they already exists.</p>\n";
659
  echo '<form name="wp_edit_rejected_user_agent" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
660
+ echo '<label for="wp_rejected_user_agent"><h4>Rejected UA strings</h4></label>';
661
+ echo '<textarea name="wp_rejected_user_agent" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
662
  foreach ($cache_rejected_user_agent as $ua) {
663
  echo wp_specialchars($ua) . "\n";
664
  }
665
  echo '</textarea> ';
666
+ echo '<div><input type="submit" ' . SUBMITDISABLED . 'value="Save UA strings &raquo;" /></div>';
667
  wp_nonce_field('wp-cache');
668
  echo '</form>';
669
  echo "</fieldset>\n";
679
  }
680
 
681
 
 
682
  echo '<form name="wp_edit_rejected" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
683
+ echo '<label for="wp_rejected_uri"><h4>Rejected URIs</h4></label>';
684
+ echo "<p>Add here strings (not a filename) that forces a page not to be cached. For example, if your URLs include year and you dont want to cache last year posts, it's enough to specify the year, i.e. '/2004/'. WP-Cache will search if that string is part of the URI and if so, it will not cache that page.</p>\n";
685
+ echo '<textarea name="wp_rejected_uri" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
686
  foreach ($cache_rejected_uri as $file) {
687
  echo wp_specialchars($file) . "\n";
688
  }
689
  echo '</textarea> ';
690
+ echo '<div><input type="submit" ' . SUBMITDISABLED . 'value="Save strings &raquo;" /></div>';
691
  wp_nonce_field('wp-cache');
692
  echo "</form>\n";
693
  }
701
  }
702
 
703
 
704
+ echo '<br clear="all" /><form name="wp_edit_accepted" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
705
+ echo '<h4>Accepted files</h4>';
706
  echo "<p>Add here those filenames that can be cached, even if they match one of the rejected substring specified above.</p>\n";
707
+ echo '<textarea name="wp_accepted_files" cols="40" rows="8" style="width: 50%; font-size: 12px;" class="code">';
 
 
708
  foreach ($cache_acceptable_files as $file) {
709
  echo wp_specialchars($file) . "\n";
710
  }
711
  echo '</textarea> ';
712
+ echo '<div><input type="submit" ' . SUBMITDISABLED . 'value="Save files &raquo;" /></div>';
713
  wp_nonce_field('wp-cache');
714
  echo "</form>\n";
715
  }
774
 
775
 
776
  function wp_cache_replace_line($old, $new, $my_file) {
777
+ if (!is_writeable_ACLSafe($my_file)) {
778
  echo "Error: file $my_file is not writable.<br />\n";
779
  return false;
780
  }
822
 
823
  $dir = dirname($cache_path);
824
  if ( !file_exists($cache_path) ) {
825
+ if ( !is_writeable_ACLSafe( $dir ) || !($dir = mkdir( $cache_path ) ) ) {
826
  echo "<b>Error:</b> Your cache directory (<b>$cache_path</b>) did not exist and couldn't be created by the web server. <br /> Check $dir permissions.";
827
  return false;
828
  }
829
  }
830
+ if ( !is_writeable_ACLSafe($cache_path)) {
831
  echo "<b>Error:</b> Your cache directory (<b>$cache_path</b>) or <b>$dir</b> need to be writable for this plugin to work. <br /> Double-check it.";
832
  return false;
833
  }
850
  if ( file_exists($wp_cache_config_file) ) {
851
  $lines = join( ' ', file( $wp_cache_config_file ) );
852
  if( strpos( $lines, 'WPCACHEHOME' ) === false ) {
853
+ if( is_writeable_ACLSafe( $wp_cache_config_file ) ) {
854
  @unlink( $wp_cache_config_file );
855
  } else {
856
  echo "<b>Error:</b> Your WP-Cache config file (<b>$wp_cache_config_file</b>) is out of date and not writable by the Web server.<br />Please delete it and refresh this page.";
857
  return false;
858
  }
859
  }
860
+ } elseif( !is_writeable_ACLSafe($dir)) {
861
  echo "<b>Error:</b> Configuration file missing and " . WP_CONTENT_DIR . " directory (<b>$dir</b>) is not writable by the Web server.<br />Check its permissions.";
862
  return false;
863
  }
927
  }
928
  }
929
  $line = 'define(\'WP_CACHE\', true);';
930
+ if (!is_writeable_ACLSafe($global) || !wp_cache_replace_line('define *\( *\'WP_CACHE\'', $line, $global) ) {
931
  echo "<b>Error: WP_CACHE is not enabled</b> in your <code>wp-config.php</code> file and I couldn't modified it.<br />";
932
  echo "Edit <code>$global</code> and add the following line: <br /><code>define('WP_CACHE', true);</code><br />Otherwise, <b>WP-Cache will not be executed</b> by Wordpress core. <br />";
933
  return false;
959
  } else
960
  $list_mess = "List files";
961
 
962
+ echo '<br /><a name="list"></a><fieldset class="options"><h3>Cache Contents</h3>';
963
  /*
964
  echo '<form name="wp_cache_content_list" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
965
  echo '<input type="hidden" name="wp_list_cache" />';
966
+ echo '<div><input type="submit" ' . SUBMITDISABLED . 'value="'.$list_mess.' &raquo;" /></div>';
967
  echo "</form>\n";
968
  */
969
 
1000
  echo '<td><form name="wp_delete_cache_file" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
1001
  echo '<input type="hidden" name="wp_list_cache" />';
1002
  echo '<input type="hidden" name="wp_delete_cache_file" value="'.preg_replace("/^(.*)\.meta$/", "$1", $file).'" />';
1003
+ echo '<div><input id="deletepost" ' . SUBMITDISABLED . 'type="submit" value="Remove" /></div>';
1004
  wp_nonce_field('wp-cache');
1005
  echo "</form></td></tr>\n";
1006
  }
1027
  $sizes[ 'ts' ] = time();
1028
  }
1029
 
1030
+ echo "<p><h4>WP-Cache</h4></p>";
1031
  echo "<ul><li>$count cached pages</li>";
1032
  echo "<li>$expired expired pages</li></ul>";
1033
  if( $cache_enabled == true && $super_cache_enabled == true ) {
1034
+ echo "<p><h4>WP-Super-Cache</h4></p>";
1035
  echo "<ul><li>" . intval($sizes['cached']/2) . " cached pages</li>";
1036
  $age = intval(($now - $sizes['ts'])/60);
1037
  echo "<li>" . intval($sizes['expired']/2) . " expired pages.</li></ul>";
1039
 
1040
  echo '<form name="wp_cache_content_expired" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
1041
  echo '<input type="hidden" name="wp_delete_expired" />';
1042
+ echo '<div><input type="submit" ' . SUBMITDISABLED . 'value="Delete expired &raquo;" /></div>';
1043
  wp_nonce_field('wp-cache');
1044
  echo "</form>\n";
1045
 
1046
 
1047
  echo '<form name="wp_cache_content_delete" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
1048
  echo '<input type="hidden" name="wp_delete_cache" />';
1049
+ echo '<div><input id="deletepost" type="submit" ' . SUBMITDISABLED . 'value="Delete cache &raquo;" /></div>';
1050
  wp_nonce_field('wp-cache');
1051
  echo "</form>\n";
1052
 
1138
  }
1139
 
1140
  function wpsc_remove_marker( $filename, $marker ) {
1141
+ if (!file_exists( $filename ) || is_writeable_ACLSafe( $filename ) ) {
1142
  if (!file_exists( $filename ) ) {
1143
  return '';
1144
  } else {