WP Super Cache - Version 0.8

Version Description

Download this release

Release Info

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

Code changes from version 0.7.1 to 0.8

Changelog.txt CHANGED
@@ -1,3 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  2008-08-28 11:29 donncha
2
 
3
  * readme.txt, wp-cache.php: Bump the version number to 0.7.1
1
+ 2008-09-23 13:05 donncha
2
+
3
+ * readme.txt, wp-cache.php: Bump the version to 0.8
4
+
5
+ 2008-09-23 13:01 donncha
6
+
7
+ * wp-cache-phase1.php: Comment: reminder to update .htaccess rules
8
+ if get_cookie cacheaction is used.
9
+
10
+ 2008-09-23 12:58 donncha
11
+
12
+ * wp-cache-phase1.php: Don't return if the $string is not ''
13
+
14
+ 2008-09-23 12:50 donncha
15
+
16
+ * wp-cache.php: Generate a semaphore id based on hostname and cache
17
+ path, props Tigertech
18
+ http://wordpress.org/support/topic/205195?replies=4#post-857610
19
+
20
+ 2008-09-23 11:14 donncha
21
+
22
+ * wp-cache.php: Make the expiry cleanup list an unordered list
23
+
24
+ 2008-09-23 11:06 donncha
25
+
26
+ * wp-cache-phase2.php: siteurl -> home for those who run WP in a
27
+ different place
28
+
29
+ 2008-09-23 10:44 donncha
30
+
31
+ * wp-cache-config-sample.php, wp-cache-phase2.php, wp-cache.php: No
32
+ need for $super_cache_max_time
33
+
34
+ 2008-09-23 10:39 donncha
35
+
36
+ * wp-cache-phase2.php: On post change:
37
+ 1. Clear all files from permalink in supercache directory.
38
+ 2. Clear siteurl/page/ permalinks.
39
+ 3. Clear supercache files when corresponding php meta files are
40
+ removed.
41
+
42
+ 2008-09-18 09:45 donncha
43
+
44
+ * wp-cache.php: Show mod_rewrite rules when .htaccess is RO, props
45
+ Matt @ http://mattsblog.ca/
46
+
47
+ 2008-09-17 16:29 donncha
48
+
49
+ * wp-cache-phase2.php, wp-cache.php: Decrease the chance of
50
+ cleanup.
51
+
52
+ 2008-09-17 11:01 donncha
53
+
54
+ * wp-cache.php: Don't server cached static files when url contains
55
+ "=". Should avoid lots of problems with query strings
56
+
57
+ 2008-09-17 11:00 donncha
58
+
59
+ * wp-cache-phase2.php: Replace the siteurl correctly for those who
60
+ have installed in a subdir, but access from the directory above.
61
+ Thanks Viper007Bond.
62
+
63
+ 2008-09-16 13:01 donncha
64
+
65
+ * wp-cache.php: Check for WordPress MU because .htaccess can't be
66
+ updated.
67
+ Set cache control and expiry headers of supercached files. Cached
68
+ for 5 minutes, but with "must-revalidate"
69
+
70
+ 2008-09-06 11:00 donncha
71
+
72
+ * wp-cache-phase2.php: Write cache files to a temporary file first,
73
+ then rename. Rename should be atomic.
74
+
75
+ 2008-08-28 11:30 donncha
76
+
77
+ * Changelog.txt: Updated changelog
78
+
79
  2008-08-28 11:29 donncha
80
 
81
  * readme.txt, wp-cache.php: Bump the version number to 0.7.1
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.1
5
- Stable tag: 0.7.1
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.2
5
+ Stable tag: 0.8
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
@@ -12,7 +12,6 @@ $cache_enabled = false;
12
  $super_cache_enabled = false;
13
  $cache_max_time = 3600; //in seconds
14
  //$use_flock = true; // Set it true or false if you know what to use
15
- $super_cache_max_time = 21600; // in seconds
16
  $cache_path = WP_CONTENT_DIR . '/cache/';
17
  $file_prefix = 'wp-cache-';
18
 
12
  $super_cache_enabled = false;
13
  $cache_max_time = 3600; //in seconds
14
  //$use_flock = true; // Set it true or false if you know what to use
 
15
  $cache_path = WP_CONTENT_DIR . '/cache/';
16
  $file_prefix = 'wp-cache-';
17
 
wp-cache-phase1.php CHANGED
@@ -103,9 +103,8 @@ function wp_cache_get_cookies_values() {
103
  next($_COOKIE);
104
  }
105
  reset($_COOKIE);
106
- if( $string != '' )
107
- return $string;
108
 
 
109
  $string = do_cacheaction( 'wp_cache_get_cookies_values', $string );
110
  return $string;
111
  }
103
  next($_COOKIE);
104
  }
105
  reset($_COOKIE);
 
 
106
 
107
+ // If you use this hook, make sure you update your .htaccess rules with the same conditions
108
  $string = do_cacheaction( 'wp_cache_get_cookies_values', $string );
109
  return $string;
110
  }
wp-cache-phase2.php CHANGED
@@ -188,9 +188,11 @@ function wp_cache_ob_callback($buffer) {
188
  $user_info = wp_cache_get_cookies_values();
189
  $do_cache = apply_filters( 'do_createsupercache', $user_info );
190
  if( $user_info == '' || $do_cache === true ) {
191
- $fr2 = @fopen("{$dir}index.html", 'w');
 
 
192
  if( $cache_compression )
193
- $gz = @gzopen("{$dir}index.html.gz", 'w3');
194
  }
195
  }
196
 
@@ -232,10 +234,14 @@ function wp_cache_ob_callback($buffer) {
232
  }
233
  $new_cache = true;
234
  fclose($fr);
235
- if( $fr2 )
236
  fclose($fr2);
237
- if( $gz )
 
 
238
  fclose($gz);
 
 
239
  }
240
  wp_cache_writers_exit();
241
  return $buffer;
@@ -258,10 +264,10 @@ function wp_cache_phase2_clean_cache($file_prefix) {
258
  }
259
 
260
  function prune_super_cache($directory, $force = false) {
261
- global $super_cache_max_time, $cache_path;
262
 
263
- if( !isset( $super_cache_max_time ) )
264
- $super_cache_max_time = 21600;
265
 
266
  $now = time();
267
 
@@ -274,7 +280,7 @@ function prune_super_cache($directory, $force = false) {
274
  if( is_array( $entries ) && !empty( $entries ) ) foreach ($entries as $entry) {
275
  if ($entry != '.' && $entry != '..') {
276
  prune_super_cache($entry, $force);
277
- if( is_dir( $entry ) && ( $force || @filemtime( $entry ) + $super_cache_max_time <= $now ) ) {
278
  $oktodelete = true;
279
  if( in_array( $entry, $protected_directories ) )
280
  $oktodelete = false;
@@ -284,7 +290,7 @@ function prune_super_cache($directory, $force = false) {
284
  }
285
  }
286
  } else {
287
- if( is_file($directory) && ($force || filemtime( $directory ) + $super_cache_max_time <= $now ) ) {
288
  $oktodelete = true;
289
  if( in_array( $directory, $protected_directories ) )
290
  $oktodelete = false;
@@ -396,7 +402,7 @@ function wp_cache_shutdown_callback() {
396
  }
397
 
398
  if( !isset( $wp_cache_gc ) )
399
- $wp_cache_gc = 100;
400
  if( mt_rand( 0, $wp_cache_gc ) != 1 )
401
  return;
402
 
@@ -438,18 +444,15 @@ function wp_cache_post_change($post_id) {
438
  $last_processed = $post_id;
439
  $permalink = trailingslashit( str_replace( get_option( 'siteurl' ), '', post_permalink( $post_id ) ) );
440
  if( $super_cache_enabled ) {
441
- $siteurl = strtolower( preg_replace( '/:.*$/', '', str_replace( 'http://', '', get_option( 'siteurl' ) ) ) );
442
  if( $post_id == 0 ) {
443
  prune_super_cache( $cache_path . 'supercache/' . $siteurl );
444
  } else {
445
- $permalink = trailingslashit( str_replace( get_option( 'siteurl' ), '', post_permalink( $post_id ) ) );
446
  $dir = $cache_path . 'supercache/' . $siteurl;
447
- $files_to_delete = array( $dir . '/index.html', $dir . '/feed/index.html', $dir . $permalink . 'index.html', $dir . $permalink . 'feed/index.html' );
448
- foreach( $files_to_delete as $cache_file ) {
449
- @unlink( $cache_file );
450
- @unlink( $cache_file . '.gz' );
451
- }
452
- prune_super_cache( $dir . $permalink, true ); // remove pages under permalink.
453
  }
454
  }
455
 
@@ -467,6 +470,8 @@ function wp_cache_post_change($post_id) {
467
  if ($meta->blog_id == $blog_id && (!$meta->post || $meta->post == $post_id) ) {
468
  @unlink($meta_pathname);
469
  @unlink($content_pathname);
 
 
470
  }
471
  } elseif ($meta->blog_id == $blog_id) {
472
  @unlink($meta_pathname);
188
  $user_info = wp_cache_get_cookies_values();
189
  $do_cache = apply_filters( 'do_createsupercache', $user_info );
190
  if( $user_info == '' || $do_cache === true ) {
191
+ $cache_fname = "{$dir}index.html";
192
+ $tmp_cache_filename = tempnam( $dir, "wpsupercache");
193
+ $fr2 = @fopen( $tmp_cache_filename, 'w' );
194
  if( $cache_compression )
195
+ $gz = @gzopen( $tmp_cache_filename . ".gz", 'w3');
196
  }
197
  }
198
 
234
  }
235
  $new_cache = true;
236
  fclose($fr);
237
+ if( $fr2 ) {
238
  fclose($fr2);
239
+ rename( $tmp_cache_filename, $cache_fname );
240
+ }
241
+ if( $gz ) {
242
  fclose($gz);
243
+ rename( $tmp_cache_filename . '.gz', $cache_fname . '.gz' );
244
+ }
245
  }
246
  wp_cache_writers_exit();
247
  return $buffer;
264
  }
265
 
266
  function prune_super_cache($directory, $force = false) {
267
+ global $cache_max_time, $cache_path;
268
 
269
+ if( !isset( $cache_max_time ) )
270
+ $cache_max_time = 3600;
271
 
272
  $now = time();
273
 
280
  if( is_array( $entries ) && !empty( $entries ) ) foreach ($entries as $entry) {
281
  if ($entry != '.' && $entry != '..') {
282
  prune_super_cache($entry, $force);
283
+ if( is_dir( $entry ) && ( $force || @filemtime( $entry ) + $cache_max_time <= $now ) ) {
284
  $oktodelete = true;
285
  if( in_array( $entry, $protected_directories ) )
286
  $oktodelete = false;
290
  }
291
  }
292
  } else {
293
+ if( is_file($directory) && ($force || filemtime( $directory ) + $cache_max_time <= $now ) ) {
294
  $oktodelete = true;
295
  if( in_array( $directory, $protected_directories ) )
296
  $oktodelete = false;
402
  }
403
 
404
  if( !isset( $wp_cache_gc ) )
405
+ $wp_cache_gc = 1000;
406
  if( mt_rand( 0, $wp_cache_gc ) != 1 )
407
  return;
408
 
444
  $last_processed = $post_id;
445
  $permalink = trailingslashit( str_replace( get_option( 'siteurl' ), '', post_permalink( $post_id ) ) );
446
  if( $super_cache_enabled ) {
447
+ $siteurl = trailingslashit( strtolower( preg_replace( '/:.*$/', '', str_replace( 'http://', '', get_option( 'home' ) ) ) ) );
448
  if( $post_id == 0 ) {
449
  prune_super_cache( $cache_path . 'supercache/' . $siteurl );
450
  } else {
451
+ $permalink = trailingslashit( str_replace( get_option( 'home' ), '', post_permalink( $post_id ) ) );
452
  $dir = $cache_path . 'supercache/' . $siteurl;
453
+ prune_super_cache( $dir . $permalink, true );
454
+ @rmdir( $dir . $permalink );
455
+ prune_super_cache( $dir . 'page/', true );
 
 
 
456
  }
457
  }
458
 
470
  if ($meta->blog_id == $blog_id && (!$meta->post || $meta->post == $post_id) ) {
471
  @unlink($meta_pathname);
472
  @unlink($content_pathname);
473
+ @unlink( $cache_path . 'supercache/' . trailingslashit( $meta->uri ) . 'index.html' );
474
+ @unlink( $cache_path . 'supercache/' . trailingslashit( $meta->uri ) . 'index.html.gz' );
475
  }
476
  } elseif ($meta->blog_id == $blog_id) {
477
  @unlink($meta_pathname);
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 activated, you must <a href="options-general.php?page=wpsupercache">enable the cache</a>. Based on WP-Cache by <a href="http://mnm.uib.es/gallir/">Ricardo Galli Granada</a>.
6
- Version: 0.7.1
7
  Author: Donncha O Caoimh
8
  Author URI: http://ocaoimh.ie/
9
  */
@@ -316,36 +316,12 @@ function wsc_mod_rewrite() {
316
  $wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
317
  $scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
318
 
319
- $dohtaccess = true;
320
- if( !$wprules || $wprules == '' ) {
321
- echo "<h4 style='color: #a00'>Mod Rewrite rules cannot be updated!</h4>";
322
- echo "<p>You must have <strong>BEGIN</strong> and <strong>END</strong> markers in {$home_path}.htaccess for the auto update to work. They look like this and surround the main WordPress mod_rewrite rules:
323
- <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>
324
- Refresh this page when you have updated your .htaccess file.";
325
- echo "</fieldset></div>";
326
- return;
327
- } elseif( strpos( $wprules, 'wordpressuser' ) ) { // Need to clear out old mod_rewrite rules
328
- 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>";
329
- echo "</fieldset></div>";
330
- return;
331
- } elseif( $scrules != '' && strpos( $scrules, '%{REQUEST_URI} !^.*[^/]$' ) === false && substr( get_option( 'permalink_structure' ), -1 ) == '/' ) { // permalink structure has a trailing slash, need slash check in rules.
332
- echo "<div style='padding: 2px; background: #ff0'><h4>Trailing slash check required.</h4><p>It looks like your blog has URLs that end with a '/'. Unfortunately since you installed this plugin a duplicate content bug has been found where URLs not ending in a '/' end serve the same content as those with the '/' and do not redirect to the proper URL.<br />";
333
- echo "To fix, you must edit your .htaccess file and add these two rules to the two groups of Super Cache rules:</p>";
334
- echo "<blockquote><code>RewriteCond %{REQUEST_URI} !^.*[^/]$<br />RewriteCond %{REQUEST_URI} !^.*//.*$<br /></code></blockquote>";
335
- echo "<p>You can see where the rules go and examine the complete rules by clicking the 'View mod_rewrite rules' link below.</p></div>";
336
- $dohtaccess = false;
337
- } elseif( strpos( $scrules, 'supercache' ) || strpos( $wprules, 'supercache' ) ) { // only write the rules once
338
- $dohtaccess = false;
339
- }
340
  if( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
341
  $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*[^/]$";
342
  $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*//.*$";
343
  }
344
  $condition_rules[] = "RewriteCond %{REQUEST_METHOD} !=POST";
345
- $condition_rules[] = "RewriteCond %{QUERY_STRING} !.*s=.*";
346
- $condition_rules[] = "RewriteCond %{QUERY_STRING} !.*p=.*";
347
- $condition_rules[] = "RewriteCond %{QUERY_STRING} !.*attachment_id=.*";
348
- $condition_rules[] = "RewriteCond %{QUERY_STRING} !.*wp-subscription-manager=.*";
349
  $condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$";
350
  $condition_rules = apply_filters( 'supercacherewriteconditions', $condition_rules );
351
 
@@ -366,9 +342,34 @@ function wsc_mod_rewrite() {
366
  $rules = apply_filters( 'supercacherewriterules', $rules );
367
 
368
  $rules = str_replace( "CONDITION_RULES", implode( "\n", $condition_rules ) . "\n", $rules );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
369
  if( $dohtaccess && !$_POST[ 'updatehtaccess' ] ) {
370
  if( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) {
371
- echo "<div style='padding: 2px; background: #ff0'><h4>Cannot update .htaccess</h4><p>The file <code>{$home_path}.htaccess</code> cannot be modified by the web server. Please correct this using the chmod command or your ftp client.</p><p>Refresh this page when the file permissions have been modified.</p></div>";
 
372
  } else {
373
  echo "<div style='padding: 2px; background: #ff0'><p>To serve static html files your server must have the correct mod_rewrite rules added to a file called <code>{$home_path}.htaccess</code><br /> This can be done automatically by clicking the <em>'Update mod_rewrite rules &raquo;'</em> button or you can edit the file yourself and add the following rules. Make sure they appear before any existing WordPress rules.";
374
  echo "<pre># BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache</pre></p>";
@@ -399,11 +400,10 @@ function wsc_mod_rewrite() {
399
  }
400
  // http://allmybrain.com/2007/11/08/making-wp-super-cache-gzip-compression-work/
401
  if( !is_file( $cache_path . '.htaccess' ) ) {
402
- $gziprules = "AddEncoding x-gzip .gz\n";
403
- $gziprules .= "AddType text/html .gz\n";
404
- $gziprules .= "<IfModule mod_deflate.c>\n";
405
- $gziprules .= " SetEnvIfNoCase Request_URI \.gz$ no-gzip\n";
406
- $gziprules .= "</IfModule>";
407
  $gziprules = insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $gziprules ) );
408
  echo "<h4>Gzip encoding rules in {$cache_path}.htaccess created.</h4>";
409
  }
@@ -592,10 +592,10 @@ function RecursiveFolderDelete ( $folderPath ) { // from http://www.php.net/manu
592
  }
593
 
594
  function wp_cache_edit_max_time () {
595
- global $super_cache_max_time, $cache_max_time, $wp_cache_config_file, $valid_nonce, $cache_enabled, $super_cache_enabled, $wp_cache_gc;
596
 
597
- if( !isset( $super_cache_max_time ) )
598
- $super_cache_max_time = 3600;
599
 
600
  if(isset($_POST['wp_max_time']) && $valid_nonce) {
601
  $max_time = (int)$_POST['wp_max_time'];
@@ -604,13 +604,6 @@ function wp_cache_edit_max_time () {
604
  wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file);
605
  }
606
  }
607
- if(isset($_POST['super_cache_max_time']) && $valid_nonce) {
608
- $max_time = (int)$_POST['super_cache_max_time'];
609
- if ($max_time > 0) {
610
- $super_cache_max_time = $max_time;
611
- wp_cache_replace_line('^ *\$super_cache_max_time', "\$super_cache_max_time = $super_cache_max_time;", $wp_cache_config_file);
612
- }
613
- }
614
  if(isset($_POST['wp_cache_gc']) && $valid_nonce) {
615
  $wp_cache_gc = (int)$_POST['wp_cache_gc'];
616
  wp_cache_replace_line('^ *\$wp_cache_gc', "\$wp_cache_gc = $wp_cache_gc;", $wp_cache_config_file);
@@ -620,18 +613,12 @@ function wp_cache_edit_max_time () {
620
  echo '<form name="wp_edit_max_time" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
621
  echo '<label for="wp_max_time">Expire time:</label> ';
622
  echo "<input type=\"text\" size=6 name=\"wp_max_time\" value=\"$cache_max_time\" /> seconds<br />";
623
- if( $cache_enabled == true && $super_cache_enabled == true ) {
624
- echo '<label for="super_cache_max_time">Super Cache Expire time:</label> ';
625
- echo "<input type=\"text\" size=6 name=\"super_cache_max_time\" value=\"$super_cache_max_time\" /> seconds";
626
- }
627
  if( !isset( $wp_cache_gc ) )
628
- $wp_cache_gc = 100;
629
  echo "<h4>Garbage Collection</h4><p>How often should expired files be deleted? Once every:</p>";
630
- echo "<ul><li><input type='radio' name='wp_cache_gc' value='100'" . ( $wp_cache_gc == 100 ? ' checked' : '' ) . " /> 100 requests (very often)</li>\n";
631
- echo "<li><input type='radio' name='wp_cache_gc' value='500'" . ( $wp_cache_gc == 500 ? ' checked' : '' ) . " /> 500 requests</li>\n";
632
- echo "<li><input type='radio' name='wp_cache_gc' value='1000'" . ( $wp_cache_gc == 1000 ? ' checked' : '' ) . " /> 1000 requests</li>\n";
633
- echo "<li><input type='radio' name='wp_cache_gc' value='2000'" . ( $wp_cache_gc == 2000 ? ' checked' : '' ) . " /> 2000 requests</li>\n";
634
- echo "<li><input type='radio' name='wp_cache_gc' value='5000'" . ( $wp_cache_gc == 5000 ? ' checked' : '' ) . " /> 5000 requests (very seldom)</li></ul>\n";
635
  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>";
636
  echo '<div><input type="submit" ' . SUBMITDISABLED . 'value="Change expiration &raquo;" /></div>';
637
  wp_nonce_field('wp-cache');
@@ -863,7 +850,7 @@ function wp_cache_verify_cache_dir() {
863
  }
864
 
865
  function wp_cache_verify_config_file() {
866
- global $wp_cache_config_file, $wp_cache_config_file_sample;
867
 
868
  $new = false;
869
  $dir = dirname($wp_cache_config_file);
@@ -896,6 +883,10 @@ function wp_cache_verify_config_file() {
896
  }
897
  $new = true;
898
  }
 
 
 
 
899
  require($wp_cache_config_file);
900
  return true;
901
  }
@@ -957,7 +948,7 @@ function wp_cache_check_global_config() {
957
  }
958
 
959
  function wp_cache_files() {
960
- global $cache_path, $file_prefix, $cache_max_time, $super_cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled;
961
 
962
  if ( '/' != substr($cache_path, -1)) {
963
  $cache_path .= '/';
@@ -1042,7 +1033,7 @@ function wp_cache_files() {
1042
  }
1043
  }
1044
  } else {
1045
- if(is_file($supercachedir) && filemtime( $supercachedir ) + $super_cache_max_time <= $now )
1046
  $sizes[ 'expired' ] ++;
1047
  }
1048
  $sizes[ 'ts' ] = time();
@@ -1075,7 +1066,7 @@ function wp_cache_files() {
1075
  }
1076
 
1077
  function wpsc_dirsize($directory, $sizes) {
1078
- global $super_cache_max_time;
1079
  $now = time();
1080
 
1081
  if (is_dir($directory)) {
@@ -1087,7 +1078,7 @@ function wpsc_dirsize($directory, $sizes) {
1087
  }
1088
  } else {
1089
  if(is_file($directory) ) {
1090
- if( filemtime( $directory ) + $super_cache_max_time <= $now ) {
1091
  $sizes[ 'expired' ]+=1;
1092
  } else {
1093
  $sizes[ 'cached' ]+=1;
3
  Plugin Name: WP Super Cache
4
  Plugin URI: http://ocaoimh.ie/wp-super-cache/
5
  Description: Very fast caching module for WordPress. Once activated, you must <a href="options-general.php?page=wpsupercache">enable the cache</a>. Based on WP-Cache by <a href="http://mnm.uib.es/gallir/">Ricardo Galli Granada</a>.
6
+ Version: 0.8
7
  Author: Donncha O Caoimh
8
  Author URI: http://ocaoimh.ie/
9
  */
316
  $wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
317
  $scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
318
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
  if( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
320
  $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*[^/]$";
321
  $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*//.*$";
322
  }
323
  $condition_rules[] = "RewriteCond %{REQUEST_METHOD} !=POST";
324
+ $condition_rules[] = "RewriteCond %{QUERY_STRING} !.*=.*";
 
 
 
325
  $condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$";
326
  $condition_rules = apply_filters( 'supercacherewriteconditions', $condition_rules );
327
 
342
  $rules = apply_filters( 'supercacherewriterules', $rules );
343
 
344
  $rules = str_replace( "CONDITION_RULES", implode( "\n", $condition_rules ) . "\n", $rules );
345
+
346
+ $dohtaccess = true;
347
+ if( function_exists( 'is_site_admin' ) ) {
348
+ echo "<h4 style='color: #a00'>WordPress MU Detected</h4><p>Unfortunately the rewrite rules cannot be updated automatically when running WordPress MU. Please open your .htaccess and add the following mod_rewrite rules above any other rules in that file.</p>";
349
+ } elseif( !$wprules || $wprules == '' ) {
350
+ echo "<h4 style='color: #a00'>Mod Rewrite rules cannot be updated!</h4>";
351
+ echo "<p>You must have <strong>BEGIN</strong> and <strong>END</strong> markers in {$home_path}.htaccess for the auto update to work. They look like this and surround the main WordPress mod_rewrite rules:
352
+ <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>
353
+ Refresh this page when you have updated your .htaccess file.";
354
+ echo "</fieldset></div>";
355
+ return;
356
+ } elseif( strpos( $wprules, 'wordpressuser' ) ) { // Need to clear out old mod_rewrite rules
357
+ 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>";
358
+ echo "</fieldset></div>";
359
+ return;
360
+ } elseif( $scrules != '' && strpos( $scrules, '%{REQUEST_URI} !^.*[^/]$' ) === false && substr( get_option( 'permalink_structure' ), -1 ) == '/' ) { // permalink structure has a trailing slash, need slash check in rules.
361
+ echo "<div style='padding: 2px; background: #ff0'><h4>Trailing slash check required.</h4><p>It looks like your blog has URLs that end with a '/'. Unfortunately since you installed this plugin a duplicate content bug has been found where URLs not ending in a '/' end serve the same content as those with the '/' and do not redirect to the proper URL.<br />";
362
+ echo "To fix, you must edit your .htaccess file and add these two rules to the two groups of Super Cache rules:</p>";
363
+ echo "<blockquote><code>RewriteCond %{REQUEST_URI} !^.*[^/]$<br />RewriteCond %{REQUEST_URI} !^.*//.*$<br /></code></blockquote>";
364
+ echo "<p>You can see where the rules go and examine the complete rules by clicking the 'View mod_rewrite rules' link below.</p></div>";
365
+ $dohtaccess = false;
366
+ } elseif( strpos( $scrules, 'supercache' ) || strpos( $wprules, 'supercache' ) ) { // only write the rules once
367
+ $dohtaccess = false;
368
+ }
369
  if( $dohtaccess && !$_POST[ 'updatehtaccess' ] ) {
370
  if( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) {
371
+ echo "<div style='padding: 2px; background: #ff0'><h4>Cannot update .htaccess</h4><p>The file <code>{$home_path}.htaccess</code> cannot be modified by the web server. Please correct this using the chmod command or your ftp client.</p><p>Refresh this page when the file permissions have been modified.</p><p>Alternatively, you can edit your <code>{$home_path}.htaccess</code> file manually and add the following code (before any WordPress rules):</p>";
372
+ echo "<p><pre># BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache</pre></p></div>";
373
  } else {
374
  echo "<div style='padding: 2px; background: #ff0'><p>To serve static html files your server must have the correct mod_rewrite rules added to a file called <code>{$home_path}.htaccess</code><br /> This can be done automatically by clicking the <em>'Update mod_rewrite rules &raquo;'</em> button or you can edit the file yourself and add the following rules. Make sure they appear before any existing WordPress rules.";
375
  echo "<pre># BEGIN WPSuperCache\n" . wp_specialchars( $rules ) . "# END WPSuperCache</pre></p>";
400
  }
401
  // http://allmybrain.com/2007/11/08/making-wp-super-cache-gzip-compression-work/
402
  if( !is_file( $cache_path . '.htaccess' ) ) {
403
+ $gziprules = "<IfModule mod_mime.c>\n AddEncoding x-gzip .gz\n AddType text/html .gz\n</IfModule>\n";
404
+ $gziprules .= "<IfModule mod_deflate.c>\n SetEnvIfNoCase Request_URI \.gz$ no-gzip\n</IfModule>\n";
405
+ $gziprules .= "<IfModule mod_headers.c>\n Header set Cache-Control 'max-age=300, must-revalidate'\n</IfModule>\n";
406
+ $gziprules .= "<IfModule mod_expires.c>\n ExpiresActive On\n ExpiresByType text/html A300\n</IfModule>\n";
 
407
  $gziprules = insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $gziprules ) );
408
  echo "<h4>Gzip encoding rules in {$cache_path}.htaccess created.</h4>";
409
  }
592
  }
593
 
594
  function wp_cache_edit_max_time () {
595
+ global $cache_max_time, $wp_cache_config_file, $valid_nonce, $cache_enabled, $super_cache_enabled, $wp_cache_gc;
596
 
597
+ if( !isset( $cache_max_time ) )
598
+ $cache_max_time = 3600;
599
 
600
  if(isset($_POST['wp_max_time']) && $valid_nonce) {
601
  $max_time = (int)$_POST['wp_max_time'];
604
  wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file);
605
  }
606
  }
 
 
 
 
 
 
 
607
  if(isset($_POST['wp_cache_gc']) && $valid_nonce) {
608
  $wp_cache_gc = (int)$_POST['wp_cache_gc'];
609
  wp_cache_replace_line('^ *\$wp_cache_gc', "\$wp_cache_gc = $wp_cache_gc;", $wp_cache_config_file);
613
  echo '<form name="wp_edit_max_time" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
614
  echo '<label for="wp_max_time">Expire time:</label> ';
615
  echo "<input type=\"text\" size=6 name=\"wp_max_time\" value=\"$cache_max_time\" /> seconds<br />";
 
 
 
 
616
  if( !isset( $wp_cache_gc ) )
617
+ $wp_cache_gc = 1000;
618
  echo "<h4>Garbage Collection</h4><p>How often should expired files be deleted? Once every:</p>";
619
+ echo "<ul><li><input type='radio' name='wp_cache_gc' value='1000'" . ( $wp_cache_gc == 1000 ? ' checked=checked' : '' ) . " /> 1000 requests</li>\n";
620
+ echo "<li><input type='radio' name='wp_cache_gc' value='2000'" . ( $wp_cache_gc == 2000 ? ' checked=checked' : '' ) . " /> 2000 requests</li>\n";
621
+ echo "<li><input type='radio' name='wp_cache_gc' value='5000'" . ( $wp_cache_gc == 5000 ? ' checked=checked' : '' ) . " /> 5000 requests</li></ul>\n";
 
 
622
  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>";
623
  echo '<div><input type="submit" ' . SUBMITDISABLED . 'value="Change expiration &raquo;" /></div>';
624
  wp_nonce_field('wp-cache');
850
  }
851
 
852
  function wp_cache_verify_config_file() {
853
+ global $wp_cache_config_file, $wp_cache_config_file_sample, $sem_id, $cache_path;
854
 
855
  $new = false;
856
  $dir = dirname($wp_cache_config_file);
883
  }
884
  $new = true;
885
  }
886
+ if( $sem_id == 5419 && $cache_path != '' ) {
887
+ $sem_id = crc32( $_SERVER[ 'HTTP_HOST' ] . $cache_path ) & 0x7fffffff;
888
+ wp_cache_replace_line('sem_id', '$sem_id = ' . $sem_id . ';', $wp_cache_config_file);
889
+ }
890
  require($wp_cache_config_file);
891
  return true;
892
  }
948
  }
949
 
950
  function wp_cache_files() {
951
+ global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled;
952
 
953
  if ( '/' != substr($cache_path, -1)) {
954
  $cache_path .= '/';
1033
  }
1034
  }
1035
  } else {
1036
+ if(is_file($supercachedir) && filemtime( $supercachedir ) + $cache_max_time <= $now )
1037
  $sizes[ 'expired' ] ++;
1038
  }
1039
  $sizes[ 'ts' ] = time();
1066
  }
1067
 
1068
  function wpsc_dirsize($directory, $sizes) {
1069
+ global $cache_max_time;
1070
  $now = time();
1071
 
1072
  if (is_dir($directory)) {
1078
  }
1079
  } else {
1080
  if(is_file($directory) ) {
1081
+ if( filemtime( $directory ) + $cache_max_time <= $now ) {
1082
  $sizes[ 'expired' ]+=1;
1083
  } else {
1084
  $sizes[ 'cached' ]+=1;