WP Super Cache - Version 0.9.3

Version Description

Download this release

Release Info

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

Code changes from version 0.9.2 to 0.9.3

Changelog.txt CHANGED
@@ -1,3 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  2009-03-30 16:12 donncha
2
 
3
  * wp-cache-phase2.php: Added an "auto reject" list of URIs
1
+ 2009-04-05 08:25 donncha
2
+
3
+ * wp-cache-phase2.php: Hide any potential opendir warnings
4
+
5
+ 2009-04-04 11:40 donncha
6
+
7
+ * Changelog.txt: Updated Changelog to 0.9.3
8
+
9
+ 2009-04-04 11:40 donncha
10
+
11
+ * readme.txt, wp-cache.php: Bump version number to 0.9.3
12
+
13
+ 2009-04-04 11:23 donncha
14
+
15
+ * wp-cache.php: Minor change in cache rebuild and mutex option text
16
+
17
+ 2009-04-04 11:15 donncha
18
+
19
+ * wp-cache-phase1.php: Cache files for single blogs go in cache/,
20
+ MU cache files go in cache/blogs/
21
+
22
+ 2009-04-03 15:01 donncha
23
+
24
+ * wp-cache-config-sample.php, wp-cache.php: "Cache rebuild" feature
25
+ is now on by default
26
+ File locks are off by default
27
+ Change language on admin page to "Enable file locking" instead of
28
+ "Disable..."
29
+
30
+ 2009-04-02 19:56 donncha
31
+
32
+ * wp-cache-phase2.php: Get rid of more get_option() calls in the
33
+ shutdown function
34
+
35
+ 2009-04-02 13:42 donncha
36
+
37
+ * wp-cache-phase1.php, wp-cache-phase2.php, wp-cache.php: Added a
38
+ blog cache dir. WordPress MU blogs will be cached into different
39
+ directories.
40
+ Regular WP will cache into cache/blogs/ instead of cache/
41
+
42
+ 2009-04-02 13:41 donncha
43
+
44
+ * readme.txt: Update docs:
45
+ 1. new signature on page.
46
+ 2. Minor text changes
47
+
48
+ 2009-04-02 11:49 donncha
49
+
50
+ * wp-cache-phase2.php: Removed errlog
51
+
52
+ 2009-04-02 11:09 donncha
53
+
54
+ * wp-cache-phase2.php: Check if rejected uri expr is a blank. See
55
+ http://justinblanton.com/2009/03/broken-wp-super-cache
56
+
57
+ 2009-04-01 11:46 donncha
58
+
59
+ * wp-cache-phase2.php: Added "wp_cache_rebuild_or_delete()"
60
+ function to delete or create rebuild cache files
61
+
62
+ 2009-03-31 10:56 donncha
63
+
64
+ * readme.txt: Minor docs update
65
+
66
+ 2009-03-31 10:53 donncha
67
+
68
+ * readme.txt: Updated docs to stress that wp-cached files are "good
69
+ enough" for most people.
70
+
71
+ 2009-03-31 10:46 donncha
72
+
73
+ * advanced-cache.php, readme.txt: Added "wpcache_broken_message()"
74
+ and code to catch when path in advanced-cache.php is broken.
75
+
76
+ 2009-03-31 10:32 donncha
77
+
78
+ * wp-cache.php: Check if admin_url exists. Not everyone updates
79
+ WordPress.
80
+
81
+ 2009-03-31 10:31 donncha
82
+
83
+ * wp-cache-phase2.php: In post change, remove corrupted or obsolete
84
+ meta and cache files
85
+
86
+ 2009-03-31 10:30 donncha
87
+
88
+ * Changelog.txt: Updated changelog.txt
89
+
90
  2009-03-30 16:12 donncha
91
 
92
  * wp-cache-phase2.php: Added an "auto reject" list of URIs
advanced-cache.php CHANGED
@@ -1,4 +1,8 @@
1
  <?php
2
  # WP SUPER CACHE 0.8.9.1
3
- include_once( 'CACHEHOME' . 'wp-cache-phase1.php' );
 
 
 
 
4
  ?>
1
  <?php
2
  # WP SUPER CACHE 0.8.9.1
3
+ function wpcache_broken_message() {
4
+ echo "<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->";
5
+ }
6
+ if( !include_once( 'CACHEHOME' . 'wp-cache-phase1.php' ) )
7
+ register_shutdown_function( 'wpcache_broken_message' );
8
  ?>
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: donncha
3
  Tags: performance,caching,wp-cache,wp-super-cache,cache
4
  Tested up to: 2.7.1
5
- Stable tag: 0.9.2
6
  Requires at least: 2.6
7
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3244504
8
 
@@ -19,8 +19,8 @@ However, because a user's details are displayed in the comment form after they l
19
 
20
  The good news is that probably more than 99% of your visitors don't do any of the above! Those users who don't see the static files will still benefit because they will see regular WP-Cache cached files and your server won't be as busy as before. This plugin should help your server cope with a front page appearance on digg.com or other social networking site.
21
 
22
- As this plugin is based on the older WP-Cache plugin you can switch off the Super Cache static html caching. Caching will still be performed, but every request will require loading the PHP engine. In normal circumstances this isn't that bad, but if your server is underpowered, or you're experiencing heavy traffic you may run into trouble.
23
- Super Cached html files will be server more quickly than PHP generated cached files so there's very little reason not to use the Super Cache feature.
24
 
25
  See the [WP Super Cache homepage](http://ocaoimh.ie/wp-super-cache/) for further information.
26
 
@@ -92,7 +92,7 @@ The [changelog](http://svn.wp-plugins.org/wp-super-cache/trunk/Changelog.txt) is
92
  5. Remove the directory wp-content/cache/
93
  6. Remove the directory wp-super-cache from your plugins directory.
94
 
95
- If all else fails and your site is broken and you want to disable the plugin:
96
  1. Remove the WP_CACHE define from wp-config.php. It looks like `define( 'WP_CACHE', true );`
97
  2. Remove the rules (see above) that the plugin wrote to the .htaccess file in your root directory.
98
  3. Delete the wp-super-cache folder in the plugins folder.
@@ -102,7 +102,7 @@ If all else fails and your site is broken and you want to disable the plugin:
102
 
103
  = How do I know my blog is being cached? =
104
 
105
- View the source of any page on your site. When a page is first created, you'll see the text "Dynamic Page Served (once) in X.XXXXX seconds" and "Cached page generated by WP-Super-Cache on YYYY-MM-DD HH:MM:SS" at the end of the source code. On reload, a cached page will show the same timestamp so wait a few seconds before checking. If you have compression enabled, the text "Compression = gzip" will be added. If compression is disabled and the page is served as a static html file, the text "super cache" will be added. The only other way to check if your cached file was served by PHP script or from the static cache is by looking at the HTTP headers. WP-Cache (PHP) cached pages will have the header "WP-Super-Cache: WP-Cache". I used the <a href="https://addons.mozilla.org/en-US/firefox/addon/3829">Live HTTP Headers</a> extension for Firefox to examine the headers. You should also check your cache directory in wp-content/cache/supercache/hostname/ for static cache files.
106
 
107
  = Why is WP-Super-Cache better than WP-Cache? =
108
 
@@ -118,7 +118,7 @@ No, it will do the opposite in fact. Super Cache files are compressed and stored
118
 
119
  = Why doesn't WP UserOnline, Popularity Contest, WP Postratings or plugin X not work or update on my blog now? =
120
 
121
- This plugin caches entire pages and some plugins expect they can run PHP code every time a page loads. To fix this, the plugin needs to use Javascript or AJAX methods to update. If the plugin displays information on the page, that must be a Javascript request too.
122
 
123
  = Why doesn't the plugin cache requests by search engine bots by default? =
124
 
@@ -134,7 +134,7 @@ If things don't work when you installed the plugin here are a few things to chec
134
 
135
  1. Is wp-content writable by the web server?
136
  2. Is there a wp-content/wp-cache-config.php ? If not, copy the file wp-super-cache/wp-cache-config-sample.php to wp-content/wp-cache-config.php and make sure WPCACHEHOME points at the right place. "plugins" should be "mu-plugins" if you're using WordPress MU.
137
- 3. Is there a wp-content/advanced-cache.php ? If not, then you must copy wp-super-cache/advanced-cache.php into wp-content/. You should edit the file and change the path so it points at the wp-super-cache folder.
138
  4. If pages are not cached at all, remove wp-content/advanced-cache.php and recreate it, following the advice above.
139
  5. Make sure the following line is in wp-config.php and it is ABOVE the "require_once(ABSPATH.'wp-settings.php');" line:
140
 
@@ -154,7 +154,7 @@ If things don't work when you installed the plugin here are a few things to chec
154
  `127.0.0.1 myhostname.com`
155
  A line like "127.0.0.1 localhost localhost.localdomain" is ok.
156
  17. If old pages are being served to your visitors via the supercache, you may be missing Apache modules (or their equivalents if you don't use Apache). 3 modules are required: mod_mime, mod_headers and mod_expires. The last two are especially important for making sure browsers load new versions of existing pages on your site.
157
- 18. Open the file wp-content/advanced-cache.php in your favourite editor. Is the path to wp-cache-phase1.php correct? If it is not the caching engine will not load.
158
 
159
  == Custom Caching ==
160
  It is now possible to hook into the caching process using the add_cacheaction() function.
2
  Contributors: donncha
3
  Tags: performance,caching,wp-cache,wp-super-cache,cache
4
  Tested up to: 2.7.1
5
+ Stable tag: 0.9.3
6
  Requires at least: 2.6
7
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3244504
8
 
19
 
20
  The good news is that probably more than 99% of your visitors don't do any of the above! Those users who don't see the static files will still benefit because they will see regular WP-Cache cached files and your server won't be as busy as before. This plugin should help your server cope with a front page appearance on digg.com or other social networking site.
21
 
22
+ If for some reason "supercaching" doesn't work on your server then don't worry. Caching will still be performed, but every request will require loading the PHP engine. In normal circumstances this isn't bad at all! Visitors to your site will notice no slowdown or difference. Supercache really comes into it's own if your server is underpowered, or you're experiencing heavy traffic.
23
+ Super Cached html files will be served more quickly than PHP generated cached files but in every day use, the difference isn't noticeable.
24
 
25
  See the [WP Super Cache homepage](http://ocaoimh.ie/wp-super-cache/) for further information.
26
 
92
  5. Remove the directory wp-content/cache/
93
  6. Remove the directory wp-super-cache from your plugins directory.
94
 
95
+ == If all else fails and your site is broken ==
96
  1. Remove the WP_CACHE define from wp-config.php. It looks like `define( 'WP_CACHE', true );`
97
  2. Remove the rules (see above) that the plugin wrote to the .htaccess file in your root directory.
98
  3. Delete the wp-super-cache folder in the plugins folder.
102
 
103
  = How do I know my blog is being cached? =
104
 
105
+ View the source of any page on your site. When a page is first created, you'll see the text "Dynamic page generated in XXXX seconds." and "Cached page generated by WP-Super-Cache on YYYY-MM-DD HH:MM:SS" at the end of the source code. On reload, a cached page will show the same timestamp so wait a few seconds before checking. If you have compression enabled, the text "Compression = gzip" will be added. If compression is disabled and the page is served as a static html file, the text "super cache" will be added. The only other way to check if your cached file was served by PHP script or from the static cache is by looking at the HTTP headers. WP-Cache (PHP) cached pages will have the header "WP-Super-Cache: WP-Cache". I used the <a href="https://addons.mozilla.org/en-US/firefox/addon/3829">Live HTTP Headers</a> extension for Firefox to examine the headers. You should also check your cache directory in wp-content/cache/supercache/hostname/ for static cache files.
106
 
107
  = Why is WP-Super-Cache better than WP-Cache? =
108
 
118
 
119
  = Why doesn't WP UserOnline, Popularity Contest, WP Postratings or plugin X not work or update on my blog now? =
120
 
121
+ This plugin caches entire pages and some plugins think they can run PHP code every time a page loads. To fix this, the plugin needs to use Javascript or AJAX methods to update. If the plugin displays information on the page, that must be a Javascript request too.
122
 
123
  = Why doesn't the plugin cache requests by search engine bots by default? =
124
 
134
 
135
  1. Is wp-content writable by the web server?
136
  2. Is there a wp-content/wp-cache-config.php ? If not, copy the file wp-super-cache/wp-cache-config-sample.php to wp-content/wp-cache-config.php and make sure WPCACHEHOME points at the right place. "plugins" should be "mu-plugins" if you're using WordPress MU.
137
+ 3. Is there a wp-content/advanced-cache.php ? If not, then you must copy wp-super-cache/advanced-cache.php into wp-content/. You must edit the file and change the path so it points at the wp-super-cache folder.
138
  4. If pages are not cached at all, remove wp-content/advanced-cache.php and recreate it, following the advice above.
139
  5. Make sure the following line is in wp-config.php and it is ABOVE the "require_once(ABSPATH.'wp-settings.php');" line:
140
 
154
  `127.0.0.1 myhostname.com`
155
  A line like "127.0.0.1 localhost localhost.localdomain" is ok.
156
  17. If old pages are being served to your visitors via the supercache, you may be missing Apache modules (or their equivalents if you don't use Apache). 3 modules are required: mod_mime, mod_headers and mod_expires. The last two are especially important for making sure browsers load new versions of existing pages on your site.
157
+ 18. The error message, "WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed!" appears at the end of every page. Open the file wp-content/advanced-cache.php in your favourite editor. Is the path to wp-cache-phase1.php correct? If it is not the caching engine will not load.
158
 
159
  == Custom Caching ==
160
  It is now possible to hook into the caching process using the add_cacheaction() function.
wp-cache-config-sample.php CHANGED
@@ -43,10 +43,7 @@ $cache_acceptable_files = array( 'wp-comments-popup.php', 'wp-links-opml.php', '
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');
45
 
46
- // Change this to 1 to enable experimental code that tries to serve slightly
47
- // out of date content to anon users while a new supercache file is being
48
- // generated.
49
- $cache_rebuild_files = 0;
50
 
51
  // DEBUG mode. Change this to your email address to be sent debug emails.
52
  // Remove comment (//) to enable and add back to disable.
@@ -55,7 +52,7 @@ $cache_rebuild_files = 0;
55
  // Disable the file locking system.
56
  // If you are experiencing problems with clearing or creating cache files
57
  // uncommenting this may help.
58
- //$wp_cache_mutex_disabled = 1;
59
 
60
  // Just modify it if you have conflicts with semaphores
61
  $sem_id = 5419;
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');
45
 
46
+ $cache_rebuild_files = 1;
 
 
 
47
 
48
  // DEBUG mode. Change this to your email address to be sent debug emails.
49
  // Remove comment (//) to enable and add back to disable.
52
  // Disable the file locking system.
53
  // If you are experiencing problems with clearing or creating cache files
54
  // uncommenting this may help.
55
+ $wp_cache_mutex_disabled = 1;
56
 
57
  // Just modify it if you have conflicts with semaphores
58
  $sem_id = 5419;
wp-cache-phase1.php CHANGED
@@ -10,6 +10,12 @@ if( !defined( 'WPCACHEHOME' ) )
10
 
11
  include( WPCACHEHOME . 'wp-cache-base.php');
12
 
 
 
 
 
 
 
13
  if(defined('DOING_CRON')) {
14
  require_once( WPCACHEHOME . 'wp-cache-phase2.php');
15
  return;
@@ -57,10 +63,19 @@ add_cacheaction( 'wp_cache_key', 'wp_cache_check_mobile' );
57
 
58
  $key = $blogcacheid . md5( do_cacheaction( 'wp_cache_key', $_SERVER['HTTP_HOST'].preg_replace('/#.*$/', '', str_replace( '/index.php', '/', $_SERVER['REQUEST_URI'] ) ).$wp_cache_gzip_encoding.wp_cache_get_cookies_values() ) );
59
 
 
 
 
 
 
 
 
 
 
60
  $cache_filename = $file_prefix . $key . '.html';
61
  $meta_file = $file_prefix . $key . '.meta';
62
- $cache_file = realpath( $cache_path . $cache_filename );
63
- $meta_pathname = realpath( $cache_path . 'meta/' . $meta_file );
64
 
65
  $wp_start_time = microtime();
66
  if( file_exists( $cache_file ) && ($mtime = @filemtime($meta_pathname)) ) {
10
 
11
  include( WPCACHEHOME . 'wp-cache-base.php');
12
 
13
+ if( $blogcacheid != '' ) {
14
+ $blog_cache_dir = str_replace( '//', '/', $cache_path . "blogs/" . $blogcacheid . '/' );
15
+ } else {
16
+ $blog_cache_dir = $cache_path;
17
+ }
18
+
19
  if(defined('DOING_CRON')) {
20
  require_once( WPCACHEHOME . 'wp-cache-phase2.php');
21
  return;
63
 
64
  $key = $blogcacheid . md5( do_cacheaction( 'wp_cache_key', $_SERVER['HTTP_HOST'].preg_replace('/#.*$/', '', str_replace( '/index.php', '/', $_SERVER['REQUEST_URI'] ) ).$wp_cache_gzip_encoding.wp_cache_get_cookies_values() ) );
65
 
66
+ if( false == @is_dir( $blog_cache_dir ) ) {
67
+ @mkdir( $cache_path . "blogs" );
68
+ @mkdir( $blog_cache_dir );
69
+ }
70
+
71
+ if( false == @is_dir( $blog_cache_dir . 'meta' ) )
72
+ @mkdir( $blog_cache_dir . 'meta' );
73
+
74
+
75
  $cache_filename = $file_prefix . $key . '.html';
76
  $meta_file = $file_prefix . $key . '.meta';
77
+ $cache_file = realpath( $blog_cache_dir . $cache_filename );
78
+ $meta_pathname = realpath( $blog_cache_dir . 'meta/' . $meta_file );
79
 
80
  $wp_start_time = microtime();
81
  if( file_exists( $cache_file ) && ($mtime = @filemtime($meta_pathname)) ) {
wp-cache-phase2.php CHANGED
@@ -1,9 +1,11 @@
1
  <?php
2
 
3
  function wp_cache_phase2() {
4
- global $cache_filename, $cache_acceptable_files, $wp_cache_gzip_encoding, $super_cache_enabled, $cache_rebuild_files, $wp_cache_gmt_offset;
 
5
 
6
- $wp_cache_gmt_offset = get_option( 'gmt_offset' ); // caching for later use when wpdb is gone. http://wordpress.org/support/topic/224349
 
7
 
8
  wp_cache_mutex_init();
9
  if(function_exists('add_action') && ( !defined( 'WPLOCKDOWN' ) || ( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) == '0' ) ) ) {
@@ -59,6 +61,27 @@ function wp_cache_phase2() {
59
  }
60
  }
61
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  }
63
 
64
  function wp_cache_get_response_headers() {
@@ -86,7 +109,7 @@ function wp_cache_is_rejected($uri) {
86
  return true; // we don't allow caching of wp-admin for security reasons
87
  }
88
  foreach ($cache_rejected_uri as $expr) {
89
- if( preg_match( "~$expr~", $uri ) )
90
  return true;
91
  }
92
  return false;
@@ -107,7 +130,7 @@ function wp_cache_user_agent_is_rejected() {
107
 
108
 
109
  function wp_cache_mutex_init() {
110
- global $use_flock, $mutex, $cache_path, $mutex_filename, $sem_id;
111
 
112
  if(!is_bool($use_flock)) {
113
  if(function_exists('sem_get'))
@@ -118,7 +141,7 @@ function wp_cache_mutex_init() {
118
 
119
  $mutex = false;
120
  if ($use_flock)
121
- $mutex = @fopen($cache_path . $mutex_filename, 'w');
122
  else
123
  $mutex = @sem_get($sem_id, 1, 0644 | IPC_CREAT, 1);
124
  }
@@ -181,6 +204,7 @@ function wp_cache_get_ob(&$buffer) {
181
  global $new_cache, $wp_cache_meta, $file_expired, $blog_id, $cache_compression;
182
  global $wp_cache_gzip_encoding, $super_cache_enabled, $cached_direct_pages;
183
  global $wp_cache_404, $gzsize, $supercacheonly, $wp_cache_gzip_first, $wp_cache_gmt_offset;
 
184
 
185
  $new_cache = true;
186
  $wp_cache_meta = '';
@@ -210,7 +234,7 @@ function wp_cache_get_ob(&$buffer) {
210
  return $buffer;
211
  }
212
 
213
- $mtime = @filemtime($cache_path . $cache_filename);
214
  /* Return if:
215
  the file didn't exist before but it does exist now (another connection created)
216
  OR
@@ -310,10 +334,11 @@ function wp_cache_get_ob(&$buffer) {
310
  }
311
  $new_cache = true;
312
  if( $fr ) {
 
313
  fclose($fr);
314
- if( !@rename( $tmp_wpcache_filename, $cache_path . $cache_filename ) ) {
315
- @unlink( $cache_path . $cache_filename );
316
- @rename( $tmp_wpcache_filename, $cache_path . $cache_filename );
317
  }
318
  }
319
  if( $fr2 ) {
@@ -343,14 +368,14 @@ function wp_cache_get_ob(&$buffer) {
343
  }
344
 
345
  function wp_cache_phase2_clean_cache($file_prefix) {
346
- global $cache_path;
347
 
348
  if( !wp_cache_writers_entry() )
349
  return false;
350
- if ( ($handle = @opendir( $cache_path )) ) {
351
  while ( false !== ($file = @readdir($handle))) {
352
  if ( preg_match("/^$file_prefix/", $file) )
353
- @unlink($cache_path . $file);
354
  }
355
  closedir($handle);
356
  }
@@ -358,7 +383,7 @@ function wp_cache_phase2_clean_cache($file_prefix) {
358
  }
359
 
360
  function prune_super_cache( $directory, $force = false, $rename = false ) {
361
- global $cache_max_time, $cache_path, $super_cache_enabled, $cache_rebuild_files;
362
 
363
  if( !is_admin() && $super_cache_enabled == 0 )
364
  return false;
@@ -368,7 +393,7 @@ function prune_super_cache( $directory, $force = false, $rename = false ) {
368
 
369
  $now = time();
370
 
371
- $protected_directories = array( $cache_path . '.htaccess', $cache_path . 'meta', $cache_path . 'supercache' );
372
 
373
  $oktodelete = false;
374
  if (is_dir($directory)) {
@@ -406,37 +431,45 @@ function prune_super_cache( $directory, $force = false, $rename = false ) {
406
  if( $oktodelete && !$rename ) {
407
  @unlink( $directory );
408
  } elseif( $oktodelete && $rename ) {
409
- if( $cache_rebuild_files && substr( $directory, -14 ) != '.needs-rebuild' ) {
410
- if( @rename($directory, $directory . '.needs-rebuild') ) {
411
- @touch( $directory . '.needs-rebuild' );
412
- }
413
- } else {
414
- @unlink( $directory );
415
- }
416
 
 
 
 
 
 
 
 
 
 
417
  }
 
 
418
  }
419
  }
420
 
421
  function wp_cache_phase2_clean_expired($file_prefix) {
422
- global $cache_path, $cache_max_time;
423
 
424
  clearstatcache();
425
  if( !wp_cache_writers_entry() )
426
  return false;
427
  $now = time();
428
- if ( ($handle = opendir( $cache_path )) ) {
429
  while ( false !== ($file = readdir($handle))) {
430
  if ( preg_match("/^$file_prefix/", $file) &&
431
- (@filemtime($cache_path . $file) + $cache_max_time) <= $now ) {
432
- @unlink($cache_path . $file);
433
- @unlink($cache_path . 'meta/' . str_replace( '.html', '.meta', $file ) );
434
  continue;
435
  }
436
  if($file != '.' && $file != '..') {
437
- if( is_dir( $cache_path . $file ) == false && (@filemtime($cache_path . $file) + $cache_max_time) <= $now ) {
438
  if( substr( $file, -9 ) != '.htaccess' )
439
- @unlink($cache_path . $file);
440
  }
441
  }
442
  }
@@ -449,9 +482,8 @@ function wp_cache_phase2_clean_expired($file_prefix) {
449
  }
450
 
451
  function wp_cache_shutdown_callback() {
452
- global $cache_path, $cache_max_time, $file_expired, $file_prefix, $meta_file, $new_cache, $wp_cache_meta, $known_headers, $blog_id, $wp_cache_gzip_encoding, $gzsize, $cache_filename, $supercacheonly;
453
-
454
- $supercacheonly = false;
455
 
456
  $wp_cache_meta[ 'uri' ] = $_SERVER["SERVER_NAME"].preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER['REQUEST_URI']); // To avoid XSS attacks
457
  $wp_cache_meta[ 'blog_id' ] = $blog_id;
@@ -492,7 +524,7 @@ function wp_cache_shutdown_callback() {
492
  } else { // not a feed
493
  $value = 'text/html';
494
  }
495
- $value .= "; charset=\"" . get_option('blog_charset') . "\"";
496
 
497
  @header("Content-Type: $value");
498
  $wp_cache_meta[ 'headers' ][ 'Content-Type' ] = "Content-Type: $value";
@@ -506,43 +538,24 @@ function wp_cache_shutdown_callback() {
506
 
507
  $serial = serialize($wp_cache_meta);
508
  if( wp_cache_writers_entry() ) {
509
- $tmp_meta_filename = $cache_path . 'meta/' . uniqid( mt_rand(), true ) . '.tmp';
510
  $fr = @fopen( $tmp_meta_filename, 'w');
511
  if( !$fr )
512
- @mkdir( $cache_path . 'meta' );
513
  $fr = fopen( $tmp_meta_filename, 'w');
514
  fputs($fr, $serial);
515
  fclose($fr);
516
  @chmod( $tmp_meta_filename, 0666 & ~umask());
517
- if( !@rename( $tmp_meta_filename, $cache_path . 'meta/' . $meta_file ) ) {
518
- unlink( $cache_path . 'meta/' . $meta_file );
519
- rename( $tmp_meta_filename, $cache_path . 'meta/' . $meta_file );
520
  }
521
  wp_cache_writers_exit();
522
  }
523
  }
524
-
525
- if( !isset( $cache_max_time ) )
526
- $cache_max_time = 600;
527
- $last_gc = get_option( "wpsupercache_gc_time" );
528
-
529
- if( !$last_gc ) {
530
- update_option( 'wpsupercache_gc_time', time() );
531
- }
532
-
533
- $next_gc = $cache_max_time < 1800 ? $cache_max_time : 600;
534
- if( $last_gc < ( time() - $next_gc ) ) {
535
- update_option( 'wpsupercache_gc_time', time() );
536
-
537
- global $wp_cache_shutdown_gc;
538
- if( isset( $wp_cache_shutdown_gc ) && $wp_cache_shutdown_gc == 1 ) {
539
- do_action( 'wp_cache_gc' );
540
- } else {
541
- // we delete expired files, using a wordpress cron event
542
- // since flush() does not guarantee hand-off to client - problem on Win32 and suPHP
543
- if(!wp_next_scheduled('wp_cache_gc')) wp_schedule_single_event(time() + 10 , 'wp_cache_gc');
544
- }
545
- }
546
  }
547
 
548
  function wp_cache_no_postid($id) {
@@ -571,9 +584,9 @@ function wp_cache_get_postid_from_comment($comment_id) {
571
  }
572
 
573
  function wp_cache_post_edit($post_id) {
574
- global $wp_cache_clear_on_post_edit, $cache_path;
575
  if( $wp_cache_clear_on_post_edit ) {
576
- prune_super_cache( $cache_path, true );
577
  } else {
578
  wp_cache_post_change( $post_id );
579
  }
@@ -594,7 +607,7 @@ function wp_cache_post_id_gc( $siteurl, $post_id ) {
594
  }
595
 
596
  function wp_cache_post_change($post_id) {
597
- global $file_prefix, $cache_path, $blog_id, $blogcacheid, $super_cache_enabled;
598
  static $last_processed = -1;
599
 
600
  if ($post_id == $last_processed) return $post_id;
@@ -616,26 +629,29 @@ function wp_cache_post_change($post_id) {
616
  }
617
 
618
  $matches = array();
619
- if ( ($handle = opendir( $cache_path . 'meta/' )) ) {
620
  while ( false !== ($file = readdir($handle))) {
621
  if ( preg_match("/^({$file_prefix}{$blogcacheid}.*)\.meta/", $file, $matches) ) {
622
- $meta_pathname = $cache_path . 'meta/' . $file;
623
- $content_pathname = $cache_path . $matches[1] . ".html";
624
  $meta = unserialize(@file_get_contents($meta_pathname));
625
- if( false == is_array( $meta ) )
 
 
626
  continue;
 
627
  if ($post_id > 0 && $meta) {
628
  if ($meta[ 'blog_id' ] == $blog_id && (!$meta[ 'post' ] || $meta[ 'post' ] == $post_id) ) {
629
  @unlink($meta_pathname);
630
  @unlink($content_pathname);
631
- @unlink($cache_path . 'supercache/' . trailingslashit( $meta[ 'uri' ] ) . 'index.html');
632
- @unlink($cache_path . 'supercache/' . trailingslashit( $meta[ 'uri' ] ) . 'index.html.gz');
633
  }
634
  } elseif ($meta[ 'blog_id' ] == $blog_id) {
635
  @unlink($meta_pathname);
636
  @unlink($content_pathname);
637
- @unlink($cache_path . 'supercache/' . trailingslashit( $meta[ 'uri' ] ) . 'index.html');
638
- @unlink($cache_path . 'supercache/' . trailingslashit( $meta[ 'uri' ] ) . 'index.html.gz');
639
  }
640
 
641
  }
1
  <?php
2
 
3
  function wp_cache_phase2() {
4
+ global $cache_filename, $cache_acceptable_files, $wp_cache_gzip_encoding, $super_cache_enabled, $cache_rebuild_files, $wp_cache_gmt_offset, $wp_cache_blog_charset, $wp_cache_last_gc;
5
+ global $cache_max_time;
6
 
7
+ $wp_cache_gmt_offset = get_option( 'gmt_offset' ); // caching for later use when wpdb is gone. http://wordpress.org/support/topic/224349
8
+ $wp_cache_blog_charset = get_option( 'blog_charset' );
9
 
10
  wp_cache_mutex_init();
11
  if(function_exists('add_action') && ( !defined( 'WPLOCKDOWN' ) || ( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) == '0' ) ) ) {
61
  }
62
  }
63
  }
64
+
65
+ if( !isset( $cache_max_time ) )
66
+ $cache_max_time = 600;
67
+ $last_gc = get_option( "wpsupercache_gc_time" );
68
+
69
+ if( !$last_gc ) {
70
+ update_option( 'wpsupercache_gc_time', time() );
71
+ }
72
+ $next_gc = $cache_max_time < 1800 ? $cache_max_time : 600;
73
+ if( $last_gc < ( time() - $next_gc ) ) {
74
+ update_option( 'wpsupercache_gc_time', time() );
75
+
76
+ global $wp_cache_shutdown_gc;
77
+ if( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) {
78
+ if(!wp_next_scheduled('wp_cache_gc')) wp_schedule_single_event(time() + 10 , 'wp_cache_gc');
79
+ } else {
80
+ global $time_to_gc_cache;
81
+ $time_to_gc_cache = 1; // tell the "shutdown gc" to run!
82
+ }
83
+ }
84
+
85
  }
86
 
87
  function wp_cache_get_response_headers() {
109
  return true; // we don't allow caching of wp-admin for security reasons
110
  }
111
  foreach ($cache_rejected_uri as $expr) {
112
+ if( $expr != '' && preg_match( "~$expr~", $uri ) )
113
  return true;
114
  }
115
  return false;
130
 
131
 
132
  function wp_cache_mutex_init() {
133
+ global $use_flock, $mutex, $cache_path, $mutex_filename, $sem_id, $blog_cache_dir;
134
 
135
  if(!is_bool($use_flock)) {
136
  if(function_exists('sem_get'))
141
 
142
  $mutex = false;
143
  if ($use_flock)
144
+ $mutex = @fopen($blog_cache_dir . $mutex_filename, 'w');
145
  else
146
  $mutex = @sem_get($sem_id, 1, 0644 | IPC_CREAT, 1);
147
  }
204
  global $new_cache, $wp_cache_meta, $file_expired, $blog_id, $cache_compression;
205
  global $wp_cache_gzip_encoding, $super_cache_enabled, $cached_direct_pages;
206
  global $wp_cache_404, $gzsize, $supercacheonly, $wp_cache_gzip_first, $wp_cache_gmt_offset;
207
+ global $blog_cache_dir;
208
 
209
  $new_cache = true;
210
  $wp_cache_meta = '';
234
  return $buffer;
235
  }
236
 
237
+ $mtime = @filemtime( $blog_cache_dir . $cache_filename );
238
  /* Return if:
239
  the file didn't exist before but it does exist now (another connection created)
240
  OR
334
  }
335
  $new_cache = true;
336
  if( $fr ) {
337
+ $supercacheonly = false;
338
  fclose($fr);
339
+ if( !rename( $tmp_wpcache_filename, $blog_cache_dir . $cache_filename ) ) {
340
+ unlink( $blog_cache_dir . $cache_filename );
341
+ rename( $tmp_wpcache_filename, $blog_cache_dir . $cache_filename );
342
  }
343
  }
344
  if( $fr2 ) {
368
  }
369
 
370
  function wp_cache_phase2_clean_cache($file_prefix) {
371
+ global $cache_path, $blog_cache_dir;
372
 
373
  if( !wp_cache_writers_entry() )
374
  return false;
375
+ if ( ( $handle = @opendir( $blog_cache_dir ) ) ) {
376
  while ( false !== ($file = @readdir($handle))) {
377
  if ( preg_match("/^$file_prefix/", $file) )
378
+ @unlink( $blog_cache_dir . $file );
379
  }
380
  closedir($handle);
381
  }
383
  }
384
 
385
  function prune_super_cache( $directory, $force = false, $rename = false ) {
386
+ global $cache_max_time, $cache_path, $super_cache_enabled, $cache_rebuild_files, $blog_cache_dir;
387
 
388
  if( !is_admin() && $super_cache_enabled == 0 )
389
  return false;
393
 
394
  $now = time();
395
 
396
+ $protected_directories = array( $cache_path . '.htaccess', $cache_path . $blog_cache_dir . 'meta', $cache_path . 'supercache' );
397
 
398
  $oktodelete = false;
399
  if (is_dir($directory)) {
431
  if( $oktodelete && !$rename ) {
432
  @unlink( $directory );
433
  } elseif( $oktodelete && $rename ) {
434
+ wp_cache_rebuild_or_delete( $directory );
435
+ }
436
+ }
437
+ }
 
 
 
438
 
439
+ function wp_cache_rebuild_or_delete( $file ) {
440
+ global $cache_rebuild_files;
441
+ if( strpos( $file, '?' ) !== false )
442
+ $file = substr( $file, 0, strpos( $file, '?' ) );
443
+ if( $cache_rebuild_files && substr( $file, -14 ) != '.needs-rebuild' ) {
444
+ if( @rename($file, $file . '.needs-rebuild') ) {
445
+ @touch( $file . '.needs-rebuild' );
446
+ } else {
447
+ @unlink( $file );
448
  }
449
+ } else {
450
+ @unlink( $file );
451
  }
452
  }
453
 
454
  function wp_cache_phase2_clean_expired($file_prefix) {
455
+ global $cache_path, $cache_max_time, $blog_cache_dir;
456
 
457
  clearstatcache();
458
  if( !wp_cache_writers_entry() )
459
  return false;
460
  $now = time();
461
+ if ( ( $handle = @opendir( $blog_cache_dir ) ) ) {
462
  while ( false !== ($file = readdir($handle))) {
463
  if ( preg_match("/^$file_prefix/", $file) &&
464
+ (@filemtime( $blog_cache_dir . $file) + $cache_max_time) <= $now ) {
465
+ @unlink( $blog_cache_dir . $file );
466
+ @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
467
  continue;
468
  }
469
  if($file != '.' && $file != '..') {
470
+ if( is_dir( $blog_cache_dir . $file ) == false && (@filemtime($blog_cache_dir . $file) + $cache_max_time) <= $now ) {
471
  if( substr( $file, -9 ) != '.htaccess' )
472
+ @unlink($blog_cache_dir . $file);
473
  }
474
  }
475
  }
482
  }
483
 
484
  function wp_cache_shutdown_callback() {
485
+ global $cache_path, $cache_max_time, $file_expired, $file_prefix, $meta_file, $new_cache, $wp_cache_meta, $known_headers, $blog_id, $wp_cache_gzip_encoding, $gzsize, $cache_filename, $supercacheonly, $blog_cache_dir;
486
+ global $wp_cache_blog_charset;
 
487
 
488
  $wp_cache_meta[ 'uri' ] = $_SERVER["SERVER_NAME"].preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER['REQUEST_URI']); // To avoid XSS attacks
489
  $wp_cache_meta[ 'blog_id' ] = $blog_id;
524
  } else { // not a feed
525
  $value = 'text/html';
526
  }
527
+ $value .= "; charset=\"" . $wp_cache_blog_charset . "\"";
528
 
529
  @header("Content-Type: $value");
530
  $wp_cache_meta[ 'headers' ][ 'Content-Type' ] = "Content-Type: $value";
538
 
539
  $serial = serialize($wp_cache_meta);
540
  if( wp_cache_writers_entry() ) {
541
+ $tmp_meta_filename = $blog_cache_dir . 'meta/' . uniqid( mt_rand(), true ) . '.tmp';
542
  $fr = @fopen( $tmp_meta_filename, 'w');
543
  if( !$fr )
544
+ @mkdir( $blog_cache_dir . 'meta' );
545
  $fr = fopen( $tmp_meta_filename, 'w');
546
  fputs($fr, $serial);
547
  fclose($fr);
548
  @chmod( $tmp_meta_filename, 0666 & ~umask());
549
+ if( !@rename( $tmp_meta_filename, $blog_cache_dir . 'meta/' . $meta_file ) ) {
550
+ unlink( $blog_cache_dir . 'meta/' . $meta_file );
551
+ rename( $tmp_meta_filename, $blog_cache_dir . 'meta/' . $meta_file );
552
  }
553
  wp_cache_writers_exit();
554
  }
555
  }
556
+ global $time_to_gc_cache;
557
+ if( isset( $time_to_gc_cache ) && $time_to_gc_cache == 1 )
558
+ do_action( 'wp_cache_gc' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
559
  }
560
 
561
  function wp_cache_no_postid($id) {
584
  }
585
 
586
  function wp_cache_post_edit($post_id) {
587
+ global $wp_cache_clear_on_post_edit, $cache_path, $blog_cache_dir;
588
  if( $wp_cache_clear_on_post_edit ) {
589
+ prune_super_cache( $blog_cache_dir, true );
590
  } else {
591
  wp_cache_post_change( $post_id );
592
  }
607
  }
608
 
609
  function wp_cache_post_change($post_id) {
610
+ global $file_prefix, $cache_path, $blog_id, $super_cache_enabled, $blog_cache_dir, $blogcacheid;
611
  static $last_processed = -1;
612
 
613
  if ($post_id == $last_processed) return $post_id;
629
  }
630
 
631
  $matches = array();
632
+ if ( ($handle = @opendir( $blog_cache_dir . 'meta/' )) ) {
633
  while ( false !== ($file = readdir($handle))) {
634
  if ( preg_match("/^({$file_prefix}{$blogcacheid}.*)\.meta/", $file, $matches) ) {
635
+ $meta_pathname = $blog_cache_dir . 'meta/' . $file;
636
+ $content_pathname = $blog_cache_dir . $matches[1] . ".html";
637
  $meta = unserialize(@file_get_contents($meta_pathname));
638
+ if( false == is_array( $meta ) ) {
639
+ @unlink($meta_pathname);
640
+ @unlink($content_pathname);
641
  continue;
642
+ }
643
  if ($post_id > 0 && $meta) {
644
  if ($meta[ 'blog_id' ] == $blog_id && (!$meta[ 'post' ] || $meta[ 'post' ] == $post_id) ) {
645
  @unlink($meta_pathname);
646
  @unlink($content_pathname);
647
+ @wp_cache_rebuild_or_delete($cache_path . 'supercache/' . trailingslashit( $meta[ 'uri' ] ) . 'index.html');
648
+ @wp_cache_rebuild_or_delete($cache_path . 'supercache/' . trailingslashit( $meta[ 'uri' ] ) . 'index.html.gz');
649
  }
650
  } elseif ($meta[ 'blog_id' ] == $blog_id) {
651
  @unlink($meta_pathname);
652
  @unlink($content_pathname);
653
+ @wp_cache_rebuild_or_delete($cache_path . 'supercache/' . trailingslashit( $meta[ 'uri' ] ) . 'index.html');
654
+ @wp_cache_rebuild_or_delete($cache_path . 'supercache/' . trailingslashit( $meta[ 'uri' ] ) . 'index.html.gz');
655
  }
656
 
657
  }
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 plugin for WordPress.
6
- Version: 0.9.2
7
  Author: Donncha O Caoimh
8
  Author URI: http://ocaoimh.ie/
9
  */
@@ -289,9 +289,9 @@ jQuery(document).ready(function(){
289
  }
290
  wp_cache_replace_line('^ *\$cache_rebuild_files', "\$cache_rebuild_files = " . $cache_rebuild_files . ";", $wp_cache_config_file);
291
  if( isset( $_POST[ 'wp_cache_mutex_disabled' ] ) ) {
292
- $wp_cache_mutex_disabled = 1;
293
- } else {
294
  $wp_cache_mutex_disabled = 0;
 
 
295
  }
296
  wp_cache_replace_line('^ *\$wp_cache_mutex_disabled', "\$wp_cache_mutex_disabled = " . $wp_cache_mutex_disabled . ";", $wp_cache_config_file);
297
  }
@@ -319,8 +319,8 @@ jQuery(document).ready(function(){
319
  <label><input type='radio' name='wp_cache_status' value='none' <?php if( $cache_enabled == false ) { echo 'checked=checked'; } ?>> <strong>OFF</strong> <span class="setting-description">WP Cache and Super Cache disabled</span></label><br />
320
  <p><label><input type='checkbox' name='wp_cache_hello_world' <?php if( $wp_cache_hello_world ) echo "checked"; ?> value='1'> Proudly tell the world your server is Digg proof! (places a message in your blog's footer)</label></p>
321
  <p><label><input type='checkbox' name='wp_cache_clear_on_post_edit' <?php if( $wp_cache_clear_on_post_edit ) echo "checked"; ?> value='1'> Clear all cache files when a post or page is published. (This may significantly slow down saving of posts.)</label></p>
322
- <p><label><input type='checkbox' name='cache_rebuild_files' <?php if( $cache_rebuild_files ) echo "checked"; ?> value='1'> Enable the "cache rebuild" feature. Serve a supercache file to anonymous users while a new file is being generated. Recommended for <em>very</em> busy websites with lots of comments. Makes "directly cached pages" and "Lockdown mode" obsolete.</label></p>
323
- <p><label><input type='checkbox' name='wp_cache_mutex_disabled' <?php if( $wp_cache_mutex_disabled ) echo "checked"; ?> value='1'> Disable file locking. If you experience problems with mutex or file locks this will help but may cause increased server load.</label></p>
324
  <p><label><input type='checkbox' name='wp_cache_mobile_enabled' <?php if( $wp_cache_mobile_enabled ) echo "checked"; ?> value='1'> Mobile device support. Plugin will enter "Half-On" mode.</label></p>
325
  <p><strong>Note:</strong> If uninstalling this plugin, make sure the directory <em><?php echo WP_CONTENT_DIR; ?></em> is writeable by the webserver so the files <em>advanced-cache.php</em> and <em>cache-config.php</em> can be deleted automatically. (Making sure those files are writeable too is probably a good idea!)</p>
326
  <?php
@@ -351,9 +351,9 @@ jQuery(document).ready(function(){
351
  </fieldset>
352
  </td><td valign='top'>
353
  <div style='background: #ffc; border: 1px solid #333; margin: 2px; padding: 5px'>
354
- <h3 align='center'>Makes WordPress Faster</h3>
355
  <?php if( $wp_cache_hide_donation != 1 ) { ?>
356
- <p><a href="http://ocaoimh.ie/wp-super-cache/?r=wpsc">WP Super Cache</a> makes your blog go faster. Think that's worth $5? Click the "Donate" button below.</p>
357
  <p>Thanks!<br />Donncha O Caoimh.<br /></p>
358
  <div align='center'>
359
  <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
@@ -954,7 +954,7 @@ function wp_cache_replace_line($old, $new, $my_file) {
954
  }
955
 
956
  function wp_cache_verify_cache_dir() {
957
- global $cache_path;
958
 
959
  $dir = dirname($cache_path);
960
  if ( !file_exists($cache_path) ) {
@@ -972,7 +972,14 @@ function wp_cache_verify_cache_dir() {
972
  $cache_path .= '/';
973
  }
974
 
975
- @mkdir( $cache_path . 'meta' );
 
 
 
 
 
 
 
976
 
977
  return true;
978
  }
@@ -1095,7 +1102,7 @@ function wp_cache_check_global_config() {
1095
  }
1096
 
1097
  function wp_cache_files() {
1098
- global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled;
1099
 
1100
  if ( '/' != substr($cache_path, -1)) {
1101
  $cache_path .= '/';
@@ -1130,18 +1137,18 @@ function wp_cache_files() {
1130
  $count = 0;
1131
  $expired = 0;
1132
  $now = time();
1133
- if ( ($handle = @opendir( $cache_path . 'meta/' )) ) {
1134
  if ($list_files) echo "<table cellspacing=\"0\" cellpadding=\"5\">";
1135
  while ( false !== ($file = readdir($handle))) {
1136
  if ( preg_match("/^$file_prefix.*\.meta/", $file) ) {
1137
  $this_expired = false;
1138
  $content_file = preg_replace("/meta$/", "html", $file);
1139
- $mtime = filemtime($cache_path . 'meta/' . $file);
1140
- if ( ! ($fsize = @filesize($cache_path.$content_file)) )
1141
  continue; // .meta does not exists
1142
  $fsize = intval($fsize/1024);
1143
  $age = $now - $mtime;
1144
- if ( $age > $cache_max_time) {
1145
  $expired++;
1146
  $this_expired = true;
1147
  }
@@ -1260,7 +1267,7 @@ function wpsc_dirsize($directory, $sizes) {
1260
 
1261
 
1262
  function wp_cache_clean_cache($file_prefix) {
1263
- global $cache_path, $supercachedir;
1264
 
1265
  // If phase2 was compiled, use its function to avoid race-conditions
1266
  if(function_exists('wp_cache_phase2_clean_cache')) {
@@ -1277,11 +1284,11 @@ function wp_cache_clean_cache($file_prefix) {
1277
  }
1278
 
1279
  $expr = "/^$file_prefix/";
1280
- if ( ($handle = opendir( $cache_path )) ) {
1281
  while ( false !== ($file = readdir($handle))) {
1282
  if ( preg_match($expr, $file) ) {
1283
- @unlink($cache_path . $file);
1284
- @unlink($cache_path . 'meta/' . str_replace( '.html', '.meta', $file ) );
1285
  }
1286
  }
1287
  closedir($handle);
@@ -1289,7 +1296,7 @@ function wp_cache_clean_cache($file_prefix) {
1289
  }
1290
 
1291
  function wp_cache_clean_expired($file_prefix) {
1292
- global $cache_path, $cache_max_time;
1293
 
1294
  // If phase2 was compiled, use its function to avoid race-conditions
1295
  if(function_exists('wp_cache_phase2_clean_expired')) {
@@ -1307,12 +1314,12 @@ function wp_cache_clean_expired($file_prefix) {
1307
 
1308
  $expr = "/^$file_prefix/";
1309
  $now = time();
1310
- if ( ($handle = opendir( $cache_path )) ) {
1311
  while ( false !== ($file = readdir($handle))) {
1312
- if ( preg_match($expr, $file) &&
1313
- (filemtime($cache_path . $file) + $cache_max_time) <= $now) {
1314
- @unlink($cache_path . $file);
1315
- @unlink($cache_path . 'meta/' . str_replace( '.html', '.meta', $file ) );
1316
  }
1317
  }
1318
  closedir($handle);
@@ -1384,13 +1391,13 @@ add_filter( 'favorite_actions', 'wp_cache_favorite_action' );
1384
 
1385
  function wp_cache_plugin_notice( $plugin ) {
1386
  global $cache_enabled;
1387
- if( $plugin == 'wp-super-cache/wp-cache.php' && !$cache_enabled )
1388
  echo '<td colspan="5" class="plugin-update">WP Super Cache must be configured. Go to <a href="' . admin_url( 'options-general.php?page=wpsupercache' ) . '">the admin page</a> to enable and configure the plugin.</td>';
1389
  }
1390
  add_action( 'after_plugin_row', 'wp_cache_plugin_notice' );
1391
 
1392
  function wp_cache_plugin_actions( $links, $file ) {
1393
- if( $file == 'wp-super-cache/wp-cache.php' ) {
1394
  $settings_link = '<a href="' . admin_url( 'options-general.php?page=wpsupercache' ) . '">' . __('Settings') . '</a>';
1395
  array_unshift( $links, $settings_link ); // before other links
1396
  }
@@ -1400,7 +1407,7 @@ add_filter( 'plugin_action_links', 'wp_cache_plugin_actions', 10, 2 );
1400
 
1401
  function wp_cache_admin_notice() {
1402
  global $cache_enabled;
1403
- if( substr( $_SERVER["PHP_SELF"], -11 ) == 'plugins.php' && !$cache_enabled )
1404
  echo '<div class="error"><p><strong>' . sprintf( __('WP Super Cache is disabled. Please go to the <a href="%s">plugin admin page</a> to enable caching.' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '</strong></p></div>';
1405
  }
1406
  add_action( 'admin_notices', 'wp_cache_admin_notice' );
3
  Plugin Name: WP Super Cache
4
  Plugin URI: http://ocaoimh.ie/wp-super-cache/
5
  Description: Very fast caching plugin for WordPress.
6
+ Version: 0.9.3
7
  Author: Donncha O Caoimh
8
  Author URI: http://ocaoimh.ie/
9
  */
289
  }
290
  wp_cache_replace_line('^ *\$cache_rebuild_files', "\$cache_rebuild_files = " . $cache_rebuild_files . ";", $wp_cache_config_file);
291
  if( isset( $_POST[ 'wp_cache_mutex_disabled' ] ) ) {
 
 
292
  $wp_cache_mutex_disabled = 0;
293
+ } else {
294
+ $wp_cache_mutex_disabled = 1;
295
  }
296
  wp_cache_replace_line('^ *\$wp_cache_mutex_disabled', "\$wp_cache_mutex_disabled = " . $wp_cache_mutex_disabled . ";", $wp_cache_config_file);
297
  }
319
  <label><input type='radio' name='wp_cache_status' value='none' <?php if( $cache_enabled == false ) { echo 'checked=checked'; } ?>> <strong>OFF</strong> <span class="setting-description">WP Cache and Super Cache disabled</span></label><br />
320
  <p><label><input type='checkbox' name='wp_cache_hello_world' <?php if( $wp_cache_hello_world ) echo "checked"; ?> value='1'> Proudly tell the world your server is Digg proof! (places a message in your blog's footer)</label></p>
321
  <p><label><input type='checkbox' name='wp_cache_clear_on_post_edit' <?php if( $wp_cache_clear_on_post_edit ) echo "checked"; ?> value='1'> Clear all cache files when a post or page is published. (This may significantly slow down saving of posts.)</label></p>
322
+ <p><label><input type='checkbox' name='cache_rebuild_files' <?php if( $cache_rebuild_files ) echo "checked"; ?> value='1'> Cache rebuild. Serve a supercache file to anonymous users while a new file is being generated. Recommended for <em>very</em> busy websites with lots of comments. Makes "directly cached pages" and "Lockdown mode" obsolete.</label></p>
323
+ <p><label><input type='checkbox' name='wp_cache_mutex_disabled' <?php if( !$wp_cache_mutex_disabled ) echo "checked"; ?> value='0'> Coarse file locking. You probably don't need this but it may help if your server is underpowered. Warning! <em>May cause your server to lock up in very rare cases!</em></label></p>
324
  <p><label><input type='checkbox' name='wp_cache_mobile_enabled' <?php if( $wp_cache_mobile_enabled ) echo "checked"; ?> value='1'> Mobile device support. Plugin will enter "Half-On" mode.</label></p>
325
  <p><strong>Note:</strong> If uninstalling this plugin, make sure the directory <em><?php echo WP_CONTENT_DIR; ?></em> is writeable by the webserver so the files <em>advanced-cache.php</em> and <em>cache-config.php</em> can be deleted automatically. (Making sure those files are writeable too is probably a good idea!)</p>
326
  <?php
351
  </fieldset>
352
  </td><td valign='top'>
353
  <div style='background: #ffc; border: 1px solid #333; margin: 2px; padding: 5px'>
354
+ <h3 align='center'>Make WordPress Faster</h3>
355
  <?php if( $wp_cache_hide_donation != 1 ) { ?>
356
+ <p><a href="http://ocaoimh.ie/wp-super-cache/?r=wpsc">WP Super Cache</a> makes your blog go faster. Think that's worth $10? Click the "Donate" button below.</p>
357
  <p>Thanks!<br />Donncha O Caoimh.<br /></p>
358
  <div align='center'>
359
  <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
954
  }
955
 
956
  function wp_cache_verify_cache_dir() {
957
+ global $cache_path, $blog_cache_dir, $blogcacheid;
958
 
959
  $dir = dirname($cache_path);
960
  if ( !file_exists($cache_path) ) {
972
  $cache_path .= '/';
973
  }
974
 
975
+ if( false == is_dir( $blog_cache_dir ) ) {
976
+ @mkdir( $cache_path . "blogs" );
977
+ if( $blog_cache_dir != $cache_path . "blogs/" )
978
+ @mkdir( $blog_cache_dir );
979
+ }
980
+
981
+ if( false == is_dir( $blog_cache_dir . 'meta' ) )
982
+ @mkdir( $blog_cache_dir . 'meta' );
983
 
984
  return true;
985
  }
1102
  }
1103
 
1104
  function wp_cache_files() {
1105
+ global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled, $blog_cache_dir;
1106
 
1107
  if ( '/' != substr($cache_path, -1)) {
1108
  $cache_path .= '/';
1137
  $count = 0;
1138
  $expired = 0;
1139
  $now = time();
1140
+ if ( ($handle = @opendir( $blog_cache_dir . 'meta/' )) ) {
1141
  if ($list_files) echo "<table cellspacing=\"0\" cellpadding=\"5\">";
1142
  while ( false !== ($file = readdir($handle))) {
1143
  if ( preg_match("/^$file_prefix.*\.meta/", $file) ) {
1144
  $this_expired = false;
1145
  $content_file = preg_replace("/meta$/", "html", $file);
1146
+ $mtime = filemtime( $blog_cache_dir . 'meta/' . $file );
1147
+ if ( ! ( $fsize = @filesize( $blog_cache_dir . $content_file ) ) )
1148
  continue; // .meta does not exists
1149
  $fsize = intval($fsize/1024);
1150
  $age = $now - $mtime;
1151
+ if ( $age > $cache_max_time ) {
1152
  $expired++;
1153
  $this_expired = true;
1154
  }
1267
 
1268
 
1269
  function wp_cache_clean_cache($file_prefix) {
1270
+ global $cache_path, $supercachedir, $blog_cache_dir;
1271
 
1272
  // If phase2 was compiled, use its function to avoid race-conditions
1273
  if(function_exists('wp_cache_phase2_clean_cache')) {
1284
  }
1285
 
1286
  $expr = "/^$file_prefix/";
1287
+ if ( ($handle = @opendir( $blog_cache_dir )) ) {
1288
  while ( false !== ($file = readdir($handle))) {
1289
  if ( preg_match($expr, $file) ) {
1290
+ @unlink( $blog_cache_dir . $file);
1291
+ @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
1292
  }
1293
  }
1294
  closedir($handle);
1296
  }
1297
 
1298
  function wp_cache_clean_expired($file_prefix) {
1299
+ global $cache_path, $cache_max_time, $blog_cache_dir;
1300
 
1301
  // If phase2 was compiled, use its function to avoid race-conditions
1302
  if(function_exists('wp_cache_phase2_clean_expired')) {
1314
 
1315
  $expr = "/^$file_prefix/";
1316
  $now = time();
1317
+ if ( ($handle = @opendir( $blog_cache_dir )) ) {
1318
  while ( false !== ($file = readdir($handle))) {
1319
+ if ( preg_match( $expr, $file ) &&
1320
+ ( filemtime( $blog_cache_dir . $file ) + $cache_max_time ) <= $now ) {
1321
+ @unlink( $blog_cache_dir . $file );
1322
+ @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
1323
  }
1324
  }
1325
  closedir($handle);
1391
 
1392
  function wp_cache_plugin_notice( $plugin ) {
1393
  global $cache_enabled;
1394
+ if( $plugin == 'wp-super-cache/wp-cache.php' && !$cache_enabled && function_exists( "admin_url" ) )
1395
  echo '<td colspan="5" class="plugin-update">WP Super Cache must be configured. Go to <a href="' . admin_url( 'options-general.php?page=wpsupercache' ) . '">the admin page</a> to enable and configure the plugin.</td>';
1396
  }
1397
  add_action( 'after_plugin_row', 'wp_cache_plugin_notice' );
1398
 
1399
  function wp_cache_plugin_actions( $links, $file ) {
1400
+ if( $file == 'wp-super-cache/wp-cache.php' && function_exists( "admin_url" ) ) {
1401
  $settings_link = '<a href="' . admin_url( 'options-general.php?page=wpsupercache' ) . '">' . __('Settings') . '</a>';
1402
  array_unshift( $links, $settings_link ); // before other links
1403
  }
1407
 
1408
  function wp_cache_admin_notice() {
1409
  global $cache_enabled;
1410
+ if( substr( $_SERVER["PHP_SELF"], -11 ) == 'plugins.php' && !$cache_enabled && function_exists( "admin_url" ) )
1411
  echo '<div class="error"><p><strong>' . sprintf( __('WP Super Cache is disabled. Please go to the <a href="%s">plugin admin page</a> to enable caching.' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '</strong></p></div>';
1412
  }
1413
  add_action( 'admin_notices', 'wp_cache_admin_notice' );