WP Super Cache - Version 0.9.1

Version Description

Download this release

Release Info

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

Code changes from version 0.9 to 0.9.1

Changelog.txt CHANGED
@@ -1,3 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  2009-01-27 06:17 donncha
2
 
3
  * readme.txt, wp-cache.php: Bump version to 0.9
1
+ 2009-02-26 11:53 donncha
2
+
3
+ * Changelog.txt: Updated changelog
4
+
5
+ 2009-02-26 11:51 donncha
6
+
7
+ * readme.txt, wp-cache.php: Bump version to 0.9.1
8
+
9
+ 2009-02-26 11:35 donncha
10
+
11
+ * readme.txt: Updated docs on "expired pages" and the required
12
+ modules needed to serve new data
13
+
14
+ 2009-02-26 11:23 donncha
15
+
16
+ * wp-cache.php: Remove "experimental" heading.
17
+
18
+ 2009-02-26 11:07 donncha
19
+
20
+ * wp-cache.php: Added "About the author" box to admin page.
21
+
22
+ 2009-02-19 16:07 donncha
23
+
24
+ * wp-cache.php: Make the donation box hidable.
25
+
26
+ 2009-02-19 15:46 donncha
27
+
28
+ * wp-cache.php: Added donation button, yes my html skills suck.
29
+
30
+ 2009-02-19 15:00 donncha
31
+
32
+ * wp-cache.php: Match IP against 192.168 instead of 192.
33
+
34
+ 2009-02-19 13:43 donncha
35
+
36
+ * readme.txt, wp-cache.php: Added checks for hostname = 127.x.x.x
37
+ or 192.x.x.x or if available uses wp_remote_get() to load
38
+ wp-cron.php
39
+ Gives warning if checks fail
40
+ Updated readme.txt with docs on how to resolve. Thanks to Joost
41
+ de Valk for help debugging this. http://yoast.com/wp-cron-issues/
42
+
43
+ 2009-02-19 13:34 donncha
44
+
45
+ * wp-cache-phase2.php: Hide file op warning.
46
+ Removed register_shutdown command that's not used any more
47
+
48
+ 2009-02-19 11:48 donncha
49
+
50
+ * wp-cache.php: Hide rename warning. Possibly related to no global
51
+ lock.
52
+
53
+ 2009-02-17 13:04 donncha
54
+
55
+ * Changelog.txt: Updated changelog
56
+
57
+ 2009-02-17 12:58 donncha
58
+
59
+ * wp-cache-phase2.php: Don't show no HTML tag warning for
60
+ robots.txt, http://wordpress.org/support/topic/243904?replies=1
61
+
62
+ 2009-02-17 12:36 donncha
63
+
64
+ * wp-cache.php: Clear the supercache folder when it's disabled.
65
+ Remove the .disabled folder if a supercache folder exists.
66
+ Show Last and Next garbage collection times as UTC
67
+ Added an admin notice on the plugins page if wp-super-cache
68
+ caching is disabled
69
+ Add plugin notice below plugin row if caching is disabled
70
+
71
+ 2009-02-17 12:34 donncha
72
+
73
+ * wp-cache-phase2.php: Hide some filemtime() warnings. Without a
74
+ global file lock we'll get more of these.
75
+
76
+ 2009-02-17 12:33 donncha
77
+
78
+ * plugins/badbehaviour.php: Disable the supercache if Bad Behaviour
79
+ support is enabled.
80
+
81
+ 2009-02-14 11:48 donncha
82
+
83
+ * readme.txt: Updated tag and added Donation link
84
+
85
+ 2009-02-06 10:48 donncha
86
+
87
+ * wp-cache-phase1.php, wp-cache-phase2.php: Just use the output
88
+ buffer, no shutdown functions.
89
+
90
+ 2009-02-05 20:53 donncha
91
+
92
+ * wp-cache-phase2.php: No need to call this callback twice!
93
+
94
+ 2009-02-05 15:32 donncha
95
+
96
+ * wp-cache-config-sample.php: Remove any slashes left in the
97
+ blogcacheid
98
+
99
+ 2009-02-05 13:36 donncha
100
+
101
+ * wp-cache.php: Replace blashslashes in WP_CONTENT_DIR here,
102
+ possible Win32 fix
103
+
104
+ 2009-02-05 10:20 donncha
105
+
106
+ * readme.txt: Added "UserOnline" to the list of plugins that don't
107
+ update when a page is cached
108
+
109
+ 2009-02-05 09:55 donncha
110
+
111
+ * wp-cache.php: Replace backslashes in WP_CONTENT_DIR too. Win32
112
+ fix. props Chris (beerfan)
113
+
114
+ 2009-02-04 21:49 donncha
115
+
116
+ * wp-cache-config-sample.php, wp-cache-phase2.php: Added
117
+ $wp_cache_shutdown_gc config option to use shutdown instead of
118
+ wp-cron
119
+ Added comments on config options
120
+
121
+ 2009-02-04 20:38 donncha
122
+
123
+ * wp-cache-phase2.php: Don't create empty supercache directories.
124
+
125
+ 2009-02-04 10:25 donncha
126
+
127
+ * readme.txt: Troubleshooting updates: advanced-cache.php, cache on
128
+ NFS warning
129
+
130
+ 2009-02-03 21:53 donncha
131
+
132
+ * plugins/badbehaviour.php, wp-cache-phase1.php: Things act strange
133
+ when a function has a require_once(), even if it's never reached
134
+
135
+ 2009-02-03 21:41 donncha
136
+
137
+ * plugins/badbehaviour.php, plugins/searchengine.php,
138
+ wp-cache-config-sample.php, wp-cache-phase1.php: Added Bad
139
+ Behaviour plugin
140
+ Allow SuperCache plugin directory to be relocated. See
141
+ $wp_cache_plugins_dir in config file.
142
+ Fixed updating Active status of searchengine plugin
143
+ Added new cacheactions:
144
+ 'wp_cache_served_cache_file' activated just before headers are
145
+ sent for an existing cache file.
146
+ 'wp_cache_file_contents' filter that every wp-cache cache file is
147
+ sent through. (ignoring mfunc)
148
+
149
+ 2009-02-03 12:11 donncha
150
+
151
+ * wp-cache-phase1.php: Clean and echo the buffer
152
+
153
+ 2009-02-03 11:49 donncha
154
+
155
+ * wp-cache-phase1.php, wp-cache-phase2.php: Register supercache
156
+ shutdown function right at the start of the process so it's
157
+ executed before WP objects are destroyed
158
+
159
+ 2009-02-02 15:48 donncha
160
+
161
+ * wp-cache-phase2.php: Don't register shutdown function, call it
162
+ from the output buffer callback.
163
+
164
+ 2009-02-02 09:58 donncha
165
+
166
+ * wp-cache-phase2.php: Don't read files into an array, reverting
167
+ [86134]
168
+
169
+ 2009-01-29 17:19 donncha
170
+
171
+ * wp-cache.php: Remove double slashes from inst_root
172
+
173
+ 2009-01-29 16:28 donncha
174
+
175
+ * wp-cache.php: Guess the install root properly
176
+
177
+ 2009-01-29 14:25 donncha
178
+
179
+ * wp-cache-phase2.php: Revert prune_super_cache and
180
+ garbage_collection code.
181
+
182
+ 2009-01-29 06:41 donncha
183
+
184
+ * wp-cache.php: Fix caching for blogs installed in sub dirs. See
185
+ http://wordpress.org/support/topic/238022?replies=6
186
+
187
+ 2009-01-27 19:57 donncha
188
+
189
+ * wp-cache-phase2.php: Only rename the tmp cache file when it's
190
+ created.
191
+ Hide warnings about renames and unlinks
192
+
193
+ 2009-01-27 06:18 donncha
194
+
195
+ * Changelog.txt: Updated changelog
196
+
197
  2009-01-27 06:17 donncha
198
 
199
  * readme.txt, wp-cache.php: Bump version to 0.9
plugins/badbehaviour.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function wp_supercache_badbehaviour( $file ) {
4
+ global $cache_badbehaviour;
5
+
6
+ if( $cache_badbehaviour != 1 )
7
+ return $file;
8
+ wp_supercache_badbehaviour_include();
9
+ return $file;
10
+ }
11
+ add_cacheaction( 'wp_cache_served_cache_file', 'wp_supercache_badbehaviour' );
12
+
13
+ function wp_supercache_badbehaviour_include() {
14
+ require_once( WP_CONTENT_DIR . '/plugins/Bad-Behavior/bad-behavior-generic.php' );
15
+ }
16
+
17
+ function wp_supercache_badbehaviour_admin() {
18
+ global $cache_badbehaviour, $wp_cache_config_file, $valid_nonce;
19
+
20
+ $cache_badbehaviour = $cache_badbehaviour == '' ? 'no' : $cache_badbehaviour;
21
+
22
+ $err = false;
23
+
24
+ if(isset($_POST['cache_badbehaviour']) && $valid_nonce) {
25
+ if( !file_exists( WP_CONTENT_DIR . '/plugins/Bad-Behavior/bad-behavior-generic.php' ) ) {
26
+ $_POST[ 'cache_badbehaviour' ] = 'Disable';
27
+ $err = 'Bad Behaviour not found. Please check your install.';
28
+ }
29
+ $cache_badbehaviour = $_POST['cache_badbehaviour'] == 'Disable' ? 0 : 1;
30
+ wp_cache_replace_line('^ *\$cache_badbehaviour', "\$cache_badbehaviour = $cache_badbehaviour;", $wp_cache_config_file);
31
+ }
32
+ echo '<form name="wp_supercache_badbehaviour_admin" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
33
+ wp_nonce_field('wp-cache');
34
+ echo '<strong>Bad Behaviour support is ';
35
+ if( $cache_badbehaviour == 0 ) {
36
+ echo 'disabled';
37
+ } else {
38
+ echo 'enabled';
39
+ wp_super_cache_disable();
40
+ }
41
+ echo '.</strong> (Only half-on caching supported and requires <a href="http://www.bad-behavior.ioerror.us/">Bad Behaviour</a> in "' . WP_CONTENT_DIR . '/plugins/Bad-Behaviour/") ';
42
+ if( $cache_badbehaviour == 0 ) {
43
+ echo '<input type="submit" name="cache_badbehaviour" value="Enable" />';
44
+ } else {
45
+ echo '<input type="submit" name="cache_badbehaviour" value="Disable" />';
46
+ }
47
+ echo "</form>\n";
48
+ if( $err )
49
+ echo "<p><strong>Warning!</strong> $err</p>";
50
+
51
+ }
52
+ add_cacheaction( 'cache_admin_page', 'wp_supercache_badbehaviour_admin' );
53
+
54
+ ?>
plugins/searchengine.php CHANGED
@@ -71,9 +71,9 @@ function wp_supercache_searchengine_admin() {
71
  }
72
  echo '.</strong> (requires <a href="http://ocaoimh.ie/no-adverts-for-friends/">friendsadverts.php</a> too) ';
73
  if( $cache_no_adverts_for_friends == 'no' ) {
74
- echo '<input type="submit" name="cache_no_adverts_for_friends" value="Enable &raquo;" />';
75
  } else {
76
- echo '<input type="submit" name="cache_no_adverts_for_friends" value="Disable &raquo;" />';
77
  }
78
  echo "</form>\n";
79
 
71
  }
72
  echo '.</strong> (requires <a href="http://ocaoimh.ie/no-adverts-for-friends/">friendsadverts.php</a> too) ';
73
  if( $cache_no_adverts_for_friends == 'no' ) {
74
+ echo '<input type="submit" name="cache_no_adverts_for_friends" value="Enable" />';
75
  } else {
76
+ echo '<input type="submit" name="cache_no_adverts_for_friends" value="Disable" />';
77
  }
78
  echo "</form>\n";
79
 
readme.txt CHANGED
@@ -1,9 +1,10 @@
1
  === WP Super Cache ===
2
  Contributors: donncha
3
- Tags: performance,caching,wp-cache,wp-super-cache
4
- Tested up to: 2.7
5
- Stable tag: 0.9
6
  Requires at least: 2.2
 
7
 
8
  A very fast caching engine for WordPress that produces static html files.
9
 
@@ -99,7 +100,7 @@ Comments will show as soon as they are moderated, depending on the comment polic
99
 
100
  No, it will do the opposite in fact. Super Cache files are compressed and stored that way so the heavy compression is done only once. These files are generally much smaller and are sent to a visitor's browser much more quickly than uncompressed html. As a result, your server spends less time talking over the network which saves CPU time and bandwidth, and can also serve the next request much more quickly.
101
 
102
- = Why doesn't Popularity Contest, WP Postratings or plugin X not work or update on my blog now? =
103
 
104
  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.
105
 
@@ -126,9 +127,7 @@ If things don't work when you installed the plugin here are a few things to chec
126
 
127
  1. Is wp-content writable by the web server?
128
  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.
129
- 3. Is there a wp-content/advanced-cache.php ? If not, then you must copy wp-super-cache/advanced-cache.php to it with this command while in the wp-content folder. (WordPress MU users should replace "plugins" with "mu-plugins".)
130
-
131
- `cp plugins/wp-super-cache/advanced-cache.php advanced-cache.php`
132
  4. If pages are not cached at all, remove wp-content/advanced-cache.php and recreate it, following the advice above.
133
  5. Make sure the following line is in wp-config.php and it is ABOVE the "require_once(ABSPATH.'wp-settings.php');" line:
134
 
@@ -142,6 +141,12 @@ If things don't work when you installed the plugin here are a few things to chec
142
  12. Private Server users at Dreamhost should edit wp-content/wp-cache-config.php and set the cache dir to "/tmp/" if they are getting errors about increasing CPU usage. See this [discussion](http://wordpress.org/support/topic/145895?replies=42) for more.
143
  13. File locking errors such as "failed to acquire key 0x152b: Permission denied in..." or "Page not cached by WP Super Cache. Could not get mutex lock." are a sign that you may have to use file locking. Edit wp-content/wp-cache-config.php and uncomment "$use_flock = true" or set $sem_id to a different value. You can also disable file locking from the Admin screen as a last resort.
144
  14. Make sure cache/wp_cache_mutex.lock is writeable by the web server.
 
 
 
 
 
 
145
 
146
  == Custom Caching ==
147
  It is now possible to hook into the caching process using the add_cacheaction() function.
1
  === WP Super Cache ===
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.1
6
  Requires at least: 2.2
7
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3244504
8
 
9
  A very fast caching engine for WordPress that produces static html files.
10
 
100
 
101
  No, it will do the opposite in fact. Super Cache files are compressed and stored that way so the heavy compression is done only once. These files are generally much smaller and are sent to a visitor's browser much more quickly than uncompressed html. As a result, your server spends less time talking over the network which saves CPU time and bandwidth, and can also serve the next request much more quickly.
102
 
103
+ = Why doesn't WP UserOnline, Popularity Contest, WP Postratings or plugin X not work or update on my blog now? =
104
 
105
  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.
106
 
127
 
128
  1. Is wp-content writable by the web server?
129
  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.
130
+ 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.
 
 
131
  4. If pages are not cached at all, remove wp-content/advanced-cache.php and recreate it, following the advice above.
132
  5. Make sure the following line is in wp-config.php and it is ABOVE the "require_once(ABSPATH.'wp-settings.php');" line:
133
 
141
  12. Private Server users at Dreamhost should edit wp-content/wp-cache-config.php and set the cache dir to "/tmp/" if they are getting errors about increasing CPU usage. See this [discussion](http://wordpress.org/support/topic/145895?replies=42) for more.
142
  13. File locking errors such as "failed to acquire key 0x152b: Permission denied in..." or "Page not cached by WP Super Cache. Could not get mutex lock." are a sign that you may have to use file locking. Edit wp-content/wp-cache-config.php and uncomment "$use_flock = true" or set $sem_id to a different value. You can also disable file locking from the Admin screen as a last resort.
143
  14. Make sure cache/wp_cache_mutex.lock is writeable by the web server.
144
+ 15. The cache folder cannot be put on an NFS or Samba or NAS share. It has to be on a local disk. File locking and deleting expired files will not work properly unless the cache folder is on the local machine.
145
+ 16. Garbage collection of old cache files won't work if WordPress can't find wp-cron.php. If your hostname resolves to 127.0.0.1 it could be preventing the garbage collection from working. Check your access_logs for wp-cron.php entries. Do they return a 404 (file not found) or 200 code? If it's 404 or you don't see wp-cron.php anywhere WordPress may be looking for that script in the wrong place. You should speak to your server administator to correct this or edit /etc/hosts on Unix servers and remove the following line. Your hostname must resolve to the external IP address other servers on the network/Internet use. See http://yoast.com/wp-cron-issues/ for more.
146
+
147
+ `127.0.0.1 myhostname.com`
148
+ A line like "127.0.0.1 localhost localhost.localdomain" is ok.
149
+ 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.
150
 
151
  == Custom Caching ==
152
  It is now possible to hook into the caching process using the add_cacheaction() function.
wp-cache-config-sample.php CHANGED
@@ -33,6 +33,7 @@ if( defined( 'VHOST' ) ) {
33
  if ( '/' == substr($blogcacheid, -1))
34
  $blogcacheid = substr($blogcacheid, 0, -1);
35
  }
 
36
  }
37
  }
38
 
@@ -67,5 +68,10 @@ $wp_cache_mobile = 0;
67
  $wp_cache_mobile_whitelist = 'Stand Alone/QNws';
68
  $wp_cache_mobile_browsers = '2.0 MMP, 240x320, AvantGo, BlackBerry, Blazer, Cellphone, Danger, DoCoMo, Elaine/3.0, EudoraWeb, hiptop, IEMobile, iPhone, iPod, KYOCERA/WX310K, LG/U990, MIDP-2.0, MMEF20, MOT-V, NetFront, Newt, Nintendo Wii, Nitro, Nokia, Opera Mini, Palm, Playstation Portable, portalmmm, Proxinet, ProxiNet, SHARP-TQ-GX10, Small, SonyEricsson, Symbian OS, SymbianOS, TS21i-10, UP.Browser, UP.Link, Windows CE, WinWAP';
69
 
 
70
  $wp_cache_gzip_first = 0;
 
 
 
 
71
  ?>
33
  if ( '/' == substr($blogcacheid, -1))
34
  $blogcacheid = substr($blogcacheid, 0, -1);
35
  }
36
+ $blogcacheid = str_replace( '/', '', $blogcacheid );
37
  }
38
  }
39
 
68
  $wp_cache_mobile_whitelist = 'Stand Alone/QNws';
69
  $wp_cache_mobile_browsers = '2.0 MMP, 240x320, AvantGo, BlackBerry, Blazer, Cellphone, Danger, DoCoMo, Elaine/3.0, EudoraWeb, hiptop, IEMobile, iPhone, iPod, KYOCERA/WX310K, LG/U990, MIDP-2.0, MMEF20, MOT-V, NetFront, Newt, Nintendo Wii, Nitro, Nokia, Opera Mini, Palm, Playstation Portable, portalmmm, Proxinet, ProxiNet, SHARP-TQ-GX10, Small, SonyEricsson, Symbian OS, SymbianOS, TS21i-10, UP.Browser, UP.Link, Windows CE, WinWAP';
70
 
71
+ // gzip the first page generated for clients that support it.
72
  $wp_cache_gzip_first = 0;
73
+ // change to relocate the supercache plugins directory
74
+ $wp_cache_plugins_dir = WPCACHEHOME . 'plugins';
75
+ // set to 1 to do garbage collection during normal process shutdown instead of wp-cron
76
+ $wp_cache_shutdown_gc = 0;
77
  ?>
wp-cache-phase1.php CHANGED
@@ -9,6 +9,7 @@ if( !defined( 'WPCACHEHOME' ) )
9
  define('WPCACHEHOME', dirname(__FILE__).'/');
10
 
11
  include( WPCACHEHOME . 'wp-cache-base.php');
 
12
 
13
  if(defined('DOING_CRON')) {
14
  require_once( WPCACHEHOME . 'wp-cache-phase2.php');
@@ -20,7 +21,9 @@ $new_cache = false;
20
 
21
  // Don't change variables behind this point
22
 
23
- $plugins = glob( WPCACHEHOME . 'plugins/*.php' );
 
 
24
  if( is_array( $plugins ) ) {
25
  foreach ( $plugins as $plugin ) {
26
  if( is_file( $plugin ) )
@@ -66,6 +69,7 @@ if( file_exists( $cache_file ) && ($mtime = @filemtime($meta_pathname)) ) {
66
  $meta = new CacheMeta;
67
  if (! ($meta = unserialize(@file_get_contents($meta_pathname))) )
68
  return;
 
69
  // Sometimes the gzip headers are lost. If this is a gzip capable client, send those headers.
70
  if( $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $meta->headers ) ) {
71
  array_push($meta->headers, 'Content-Encoding: ' . $wp_cache_gzip_encoding);
@@ -84,14 +88,27 @@ if( file_exists( $cache_file ) && ($mtime = @filemtime($meta_pathname)) ) {
84
  if ($meta->dynamic) {
85
  include($cache_file);
86
  } else {
87
- if(!@readfile ($cache_file))
88
- return;
89
  }
90
- die;
91
  }
92
  $file_expired = true; // To signal this file was expired
93
  }
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  function wp_cache_postload() {
96
  global $cache_enabled;
97
 
9
  define('WPCACHEHOME', dirname(__FILE__).'/');
10
 
11
  include( WPCACHEHOME . 'wp-cache-base.php');
12
+ $wp_cache_meta_object = new CacheMeta;
13
 
14
  if(defined('DOING_CRON')) {
15
  require_once( WPCACHEHOME . 'wp-cache-phase2.php');
21
 
22
  // Don't change variables behind this point
23
 
24
+ if( !isset( $wp_cache_plugins_dir ) )
25
+ $wp_cache_plugins_dir = WPCACHEHOME . 'plugins';
26
+ $plugins = glob( $wp_cache_plugins_dir . '/*.php' );
27
  if( is_array( $plugins ) ) {
28
  foreach ( $plugins as $plugin ) {
29
  if( is_file( $plugin ) )
69
  $meta = new CacheMeta;
70
  if (! ($meta = unserialize(@file_get_contents($meta_pathname))) )
71
  return;
72
+ $file = do_cacheaction( 'wp_cache_served_cache_file', $cache_file );
73
  // Sometimes the gzip headers are lost. If this is a gzip capable client, send those headers.
74
  if( $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $meta->headers ) ) {
75
  array_push($meta->headers, 'Content-Encoding: ' . $wp_cache_gzip_encoding);
88
  if ($meta->dynamic) {
89
  include($cache_file);
90
  } else {
91
+ echo do_cacheaction( 'wp_cache_file_contents', file_get_contents( $cache_file ) );
 
92
  }
93
+ die();
94
  }
95
  $file_expired = true; // To signal this file was expired
96
  }
97
 
98
+ /*register_shutdown_function( 'wp_cache_do_output' );
99
+
100
+ function wp_cache_do_output() {
101
+ global $wp_cache_do_output;
102
+ if( !$wp_cache_do_output ) {
103
+ return false;
104
+ }
105
+ $buffer = ob_get_contents();
106
+ ob_end_clean();
107
+ $buffer = wp_cache_get_ob( $buffer );
108
+ wp_cache_shutdown_callback();
109
+ echo $buffer;
110
+ }*/
111
+
112
  function wp_cache_postload() {
113
  global $cache_enabled;
114
 
wp-cache-phase2.php CHANGED
@@ -1,7 +1,9 @@
1
  <?php
2
 
3
  function wp_cache_phase2() {
4
- global $cache_filename, $cache_acceptable_files, $wp_cache_meta_object, $wp_cache_gzip_encoding, $super_cache_enabled, $cache_rebuild_files;
 
 
5
 
6
  wp_cache_mutex_init();
7
  if(function_exists('add_action') && ( !defined( 'WPLOCKDOWN' ) || ( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) == '0' ) ) ) {
@@ -30,14 +32,11 @@ function wp_cache_phase2() {
30
  if (!in_array($script, $cache_acceptable_files) && wp_cache_is_rejected($_SERVER["REQUEST_URI"]))
31
  return;
32
  if (wp_cache_user_agent_is_rejected()) return;
33
- if( !is_object( $wp_cache_meta_object ) ) {
34
- $wp_cache_meta_object = new CacheMeta;
35
- }
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
 
42
  // restore old supercache file temporarily
43
  if( $super_cache_enabled && $cache_rebuild_files ) {
@@ -47,7 +46,7 @@ function wp_cache_phase2() {
47
  $dir = get_current_url_supercache_dir();
48
  $files_to_check = array( $dir . 'index.html', $dir . 'index.html.gz' );
49
  foreach( $files_to_check as $cache_file ) {
50
- if( !file_exists( $cache_file . '.needs-rebuild' ) )
51
  continue;
52
  $mtime = @filemtime($cache_file . '.needs-rebuild');
53
  if( $mtime && (time() - $mtime) < 30 ) {
@@ -60,7 +59,6 @@ function wp_cache_phase2() {
60
  }
61
  }
62
  }
63
- register_shutdown_function('wp_cache_shutdown_callback');
64
  }
65
 
66
  function wp_cache_get_response_headers() {
@@ -168,11 +166,18 @@ function get_current_url_supercache_dir() {
168
  return $dir;
169
  }
170
 
171
- function wp_cache_ob_callback($buffer) {
 
 
 
 
 
 
 
172
  global $cache_path, $cache_filename, $meta_file, $wp_start_time, $supercachedir;
173
  global $new_cache, $wp_cache_meta_object, $file_expired, $blog_id, $cache_compression;
174
  global $wp_cache_gzip_encoding, $super_cache_enabled, $cached_direct_pages;
175
- global $wp_cache_404, $gzsize, $supercacheonly, $wp_cache_gzip_first;
176
 
177
  $new_cache = true;
178
 
@@ -185,7 +190,8 @@ function wp_cache_ob_callback($buffer) {
185
 
186
  if (!preg_match('/(<\/html>|<\/rss>|<\/feed>)/i',$buffer) ) {
187
  $new_cache = false;
188
- $buffer .= "\n<!-- Page not cached by WP Super Cache. No closing HTML tag. Check your theme. -->\n";
 
189
  }
190
 
191
  if( !$new_cache )
@@ -227,12 +233,13 @@ function wp_cache_ob_callback($buffer) {
227
  }
228
  }
229
  if( $super_cache_enabled ) {
230
- if( @is_dir( $dir ) == false )
231
- @wp_mkdir_p( $dir );
232
-
233
  $user_info = wp_cache_get_cookies_values();
234
  $do_cache = apply_filters( 'do_createsupercache', $user_info );
235
  if( $user_info == '' || $do_cache === true ) {
 
 
 
 
236
  $cache_fname = "{$dir}index.html";
237
  $tmp_cache_filename = $dir . uniqid( mt_rand(), true ) . '.tmp';
238
  $fr2 = @fopen( $tmp_cache_filename, 'w' );
@@ -274,7 +281,7 @@ function wp_cache_ob_callback($buffer) {
274
  fputs($gz, gzencode( $store . '<!-- super cache gz -->', 1, FORCE_GZIP ) );
275
  } else {
276
  $buffer = apply_filters( 'wpsupercache_buffer', $buffer );
277
- $log = "<!-- Cached page generated by WP-Super-Cache on " . current_time( 'mysql' ) . " -->\n";
278
 
279
  if( $gz || $wp_cache_gzip_encoding ) {
280
  $gzdata = gzencode( $buffer . $log . "<!-- Compression = gzip -->", 3, FORCE_GZIP );
@@ -339,35 +346,16 @@ function wp_cache_phase2_clean_cache($file_prefix) {
339
  return false;
340
  if ( ($handle = @opendir( $cache_path )) ) {
341
  while ( false !== ($file = @readdir($handle))) {
342
- if ( preg_match("/^$file_prefix/", $file) ) {
343
- $files[] = $file;
344
- }
345
  }
346
  closedir($handle);
347
- if( is_array( $files ) )
348
- reset( $files );
349
- foreach( (array)$files as $file ) {
350
- @unlink($cache_path . $file);
351
- }
352
  }
353
  wp_cache_writers_exit();
354
  }
355
 
356
  function prune_super_cache( $directory, $force = false, $rename = false ) {
357
- global $gc_file_counter;
358
- $c = 0;
359
- while( $c < 200 ) {
360
- $gc_file_counter = 0;
361
- sc_garbage_collection( $directory, $force, $rename );
362
- $c++;
363
- if( $gc_file_counter == 0 )
364
- $c = 200;
365
- }
366
- }
367
-
368
- function sc_garbage_collection( $directory, $force = false, $rename = false ) {
369
  global $cache_max_time, $cache_path, $super_cache_enabled, $cache_rebuild_files;
370
- global $gc_file_counter;
371
 
372
  if( !is_admin() && $super_cache_enabled == 0 )
373
  return false;
@@ -386,17 +374,8 @@ function sc_garbage_collection( $directory, $force = false, $rename = false ) {
386
  while( ( $entry = @readdir( $dh ) ) !== false ) {
387
  if ($entry == '.' || $entry == '..')
388
  continue;
389
- if( $gc_file_counter < 100 )
390
- $files[] = $entry;
391
- }
392
- closedir($dh);
393
- if( is_array( $files ) )
394
- reset( $files );
395
- foreach( (array)$files as $entry ) {
396
  $entry = $directory . $entry;
397
- if( $gc_file_counter < 100 ) {
398
- sc_garbage_collection( $entry, $force, $rename );
399
- }
400
  // If entry is a directory, AND it's not a protected one, AND we're either forcing the delete, OR the file is out of date,
401
  if( is_dir( $entry ) && !in_array( $entry, $protected_directories ) && ( $force || @filemtime( $entry ) + $cache_max_time <= $now ) ) {
402
  // if the directory isn't empty can't delete it
@@ -411,29 +390,25 @@ function sc_garbage_collection( $directory, $force = false, $rename = false ) {
411
  }
412
  if( $donotdelete )
413
  continue;
414
- if( !$rename ) {
415
  @rmdir( $entry );
416
- $gc_file_counter++;
417
- }
418
  }
419
  }
 
420
  }
421
- } elseif( is_file($directory) && ($force || filemtime( $directory ) + $cache_max_time <= $now ) ) {
422
  $oktodelete = true;
423
  if( in_array( $directory, $protected_directories ) )
424
  $oktodelete = false;
425
  if( $oktodelete && !$rename ) {
426
  @unlink( $directory );
427
- $gc_file_counter++;
428
  } elseif( $oktodelete && $rename ) {
429
  if( $cache_rebuild_files && substr( $directory, -14 ) != '.needs-rebuild' ) {
430
  if( @rename($directory, $directory . '.needs-rebuild') ) {
431
  @touch( $directory . '.needs-rebuild' );
432
- $gc_file_counter++;
433
  }
434
  } else {
435
  @unlink( $directory );
436
- $gc_file_counter++;
437
  }
438
 
439
  }
@@ -449,25 +424,20 @@ function wp_cache_phase2_clean_expired($file_prefix) {
449
  $now = time();
450
  if ( ($handle = opendir( $cache_path )) ) {
451
  while ( false !== ($file = readdir($handle))) {
452
- $files[] = $file;
453
- }
454
- closedir($handle);
455
- if( is_array( $files ) )
456
- reset( $files );
457
- foreach( (array)$files as $file ) {
458
  if ( preg_match("/^$file_prefix/", $file) &&
459
- (filemtime($cache_path . $file) + $cache_max_time) <= $now ) {
460
  @unlink($cache_path . $file);
461
  @unlink($cache_path . 'meta/' . str_replace( '.html', '.meta', $file ) );
462
  continue;
463
  }
464
  if($file != '.' && $file != '..') {
465
- if( is_dir( $cache_path . $file ) == false && (filemtime($cache_path . $file) + $cache_max_time) <= $now ) {
466
  if( substr( $file, -9 ) != '.htaccess' )
467
  @unlink($cache_path . $file);
468
  }
469
  }
470
  }
 
471
  prune_super_cache( $cache_path . 'supercache' );
472
  }
473
 
@@ -534,8 +504,6 @@ function wp_cache_shutdown_callback() {
534
  array_push($wp_cache_meta_object->headers, "Content-Type: $value");
535
  }
536
 
537
- @ob_end_flush();
538
- flush(); //Ensure we send data to the client
539
  if ( ! $supercacheonly && $new_cache ) {
540
  if( $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $wp_cache_meta_object->headers ) ) {
541
  array_push($wp_cache_meta_object->headers, 'Content-Encoding: ' . $wp_cache_gzip_encoding);
@@ -575,9 +543,14 @@ function wp_cache_shutdown_callback() {
575
  return;
576
  update_option( 'wpsupercache_gc_time', time() );
577
 
578
- // we delete expired files, using a wordpress cron event
579
- // since flush() does not guarantee hand-off to client - problem on Win32 and suPHP
580
- if(!wp_next_scheduled('wp_cache_gc')) wp_schedule_single_event(time() + 10 , 'wp_cache_gc');
 
 
 
 
 
581
  }
582
 
583
  function wp_cache_no_postid($id) {
@@ -642,12 +615,6 @@ function wp_cache_post_change($post_id) {
642
  $matches = array();
643
  if ( ($handle = opendir( $cache_path . 'meta/' )) ) {
644
  while ( false !== ($file = readdir($handle))) {
645
- $files[] = $file;
646
- }
647
- closedir($handle);
648
- if( is_array( $files ) )
649
- reset( $files );
650
- foreach( (array)$files as $file ) {
651
  if ( preg_match("/^({$file_prefix}{$blogcacheid}.*)\.meta/", $file, $matches) ) {
652
  $meta_pathname = $cache_path . 'meta/' . $file;
653
  $content_pathname = $cache_path . $matches[1] . ".html";
@@ -664,6 +631,7 @@ function wp_cache_post_change($post_id) {
664
 
665
  }
666
  }
 
667
  }
668
  wp_cache_writers_exit();
669
  return $post_id;
1
  <?php
2
 
3
  function wp_cache_phase2() {
4
+ global $cache_filename, $cache_acceptable_files, $wp_cache_meta_object, $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' ) ) ) {
32
  if (!in_array($script, $cache_acceptable_files) && wp_cache_is_rejected($_SERVER["REQUEST_URI"]))
33
  return;
34
  if (wp_cache_user_agent_is_rejected()) return;
 
 
 
35
  if($wp_cache_gzip_encoding)
36
  header('Vary: Accept-Encoding, Cookie');
37
  else
38
  header('Vary: Cookie');
39
+ ob_start( 'wp_cache_ob_callback' );
40
 
41
  // restore old supercache file temporarily
42
  if( $super_cache_enabled && $cache_rebuild_files ) {
46
  $dir = get_current_url_supercache_dir();
47
  $files_to_check = array( $dir . 'index.html', $dir . 'index.html.gz' );
48
  foreach( $files_to_check as $cache_file ) {
49
+ if( !@file_exists( $cache_file . '.needs-rebuild' ) )
50
  continue;
51
  $mtime = @filemtime($cache_file . '.needs-rebuild');
52
  if( $mtime && (time() - $mtime) < 30 ) {
59
  }
60
  }
61
  }
 
62
  }
63
 
64
  function wp_cache_get_response_headers() {
166
  return $dir;
167
  }
168
 
169
+ function wp_cache_ob_callback( $buffer ) {
170
+ $buffer = wp_cache_get_ob( $buffer );
171
+ wp_cache_shutdown_callback();
172
+ return $buffer;
173
+ }
174
+
175
+
176
+ function wp_cache_get_ob($buffer) {
177
  global $cache_path, $cache_filename, $meta_file, $wp_start_time, $supercachedir;
178
  global $new_cache, $wp_cache_meta_object, $file_expired, $blog_id, $cache_compression;
179
  global $wp_cache_gzip_encoding, $super_cache_enabled, $cached_direct_pages;
180
+ global $wp_cache_404, $gzsize, $supercacheonly, $wp_cache_gzip_first, $wp_cache_gmt_offset;
181
 
182
  $new_cache = true;
183
 
190
 
191
  if (!preg_match('/(<\/html>|<\/rss>|<\/feed>)/i',$buffer) ) {
192
  $new_cache = false;
193
+ if( false === strpos( $_SERVER[ 'REQUEST_URI' ], 'robots.txt' ) )
194
+ $buffer .= "\n<!-- Page not cached by WP Super Cache. No closing HTML tag. Check your theme. -->\n";
195
  }
196
 
197
  if( !$new_cache )
233
  }
234
  }
235
  if( $super_cache_enabled ) {
 
 
 
236
  $user_info = wp_cache_get_cookies_values();
237
  $do_cache = apply_filters( 'do_createsupercache', $user_info );
238
  if( $user_info == '' || $do_cache === true ) {
239
+
240
+ if( @is_dir( $dir ) == false )
241
+ @wp_mkdir_p( $dir );
242
+
243
  $cache_fname = "{$dir}index.html";
244
  $tmp_cache_filename = $dir . uniqid( mt_rand(), true ) . '.tmp';
245
  $fr2 = @fopen( $tmp_cache_filename, 'w' );
281
  fputs($gz, gzencode( $store . '<!-- super cache gz -->', 1, FORCE_GZIP ) );
282
  } else {
283
  $buffer = apply_filters( 'wpsupercache_buffer', $buffer );
284
+ $log = "<!-- Cached page generated by WP-Super-Cache on " . gmdate('Y-m-d H:i:s', (time() + ( $wp_cache_gmt_offset * 3600))) . " -->\n";
285
 
286
  if( $gz || $wp_cache_gzip_encoding ) {
287
  $gzdata = gzencode( $buffer . $log . "<!-- Compression = gzip -->", 3, FORCE_GZIP );
346
  return false;
347
  if ( ($handle = @opendir( $cache_path )) ) {
348
  while ( false !== ($file = @readdir($handle))) {
349
+ if ( preg_match("/^$file_prefix/", $file) )
350
+ @unlink($cache_path . $file);
 
351
  }
352
  closedir($handle);
 
 
 
 
 
353
  }
354
  wp_cache_writers_exit();
355
  }
356
 
357
  function prune_super_cache( $directory, $force = false, $rename = false ) {
 
 
 
 
 
 
 
 
 
 
 
 
358
  global $cache_max_time, $cache_path, $super_cache_enabled, $cache_rebuild_files;
 
359
 
360
  if( !is_admin() && $super_cache_enabled == 0 )
361
  return false;
374
  while( ( $entry = @readdir( $dh ) ) !== false ) {
375
  if ($entry == '.' || $entry == '..')
376
  continue;
 
 
 
 
 
 
 
377
  $entry = $directory . $entry;
378
+ prune_super_cache( $entry, $force, $rename );
 
 
379
  // If entry is a directory, AND it's not a protected one, AND we're either forcing the delete, OR the file is out of date,
380
  if( is_dir( $entry ) && !in_array( $entry, $protected_directories ) && ( $force || @filemtime( $entry ) + $cache_max_time <= $now ) ) {
381
  // if the directory isn't empty can't delete it
390
  }
391
  if( $donotdelete )
392
  continue;
393
+ if( !$rename )
394
  @rmdir( $entry );
 
 
395
  }
396
  }
397
+ closedir($dh);
398
  }
399
+ } elseif( is_file($directory) && ($force || @filemtime( $directory ) + $cache_max_time <= $now ) ) {
400
  $oktodelete = true;
401
  if( in_array( $directory, $protected_directories ) )
402
  $oktodelete = false;
403
  if( $oktodelete && !$rename ) {
404
  @unlink( $directory );
 
405
  } elseif( $oktodelete && $rename ) {
406
  if( $cache_rebuild_files && substr( $directory, -14 ) != '.needs-rebuild' ) {
407
  if( @rename($directory, $directory . '.needs-rebuild') ) {
408
  @touch( $directory . '.needs-rebuild' );
 
409
  }
410
  } else {
411
  @unlink( $directory );
 
412
  }
413
 
414
  }
424
  $now = time();
425
  if ( ($handle = opendir( $cache_path )) ) {
426
  while ( false !== ($file = readdir($handle))) {
 
 
 
 
 
 
427
  if ( preg_match("/^$file_prefix/", $file) &&
428
+ (@filemtime($cache_path . $file) + $cache_max_time) <= $now ) {
429
  @unlink($cache_path . $file);
430
  @unlink($cache_path . 'meta/' . str_replace( '.html', '.meta', $file ) );
431
  continue;
432
  }
433
  if($file != '.' && $file != '..') {
434
+ if( is_dir( $cache_path . $file ) == false && (@filemtime($cache_path . $file) + $cache_max_time) <= $now ) {
435
  if( substr( $file, -9 ) != '.htaccess' )
436
  @unlink($cache_path . $file);
437
  }
438
  }
439
  }
440
+ closedir($handle);
441
  prune_super_cache( $cache_path . 'supercache' );
442
  }
443
 
504
  array_push($wp_cache_meta_object->headers, "Content-Type: $value");
505
  }
506
 
 
 
507
  if ( ! $supercacheonly && $new_cache ) {
508
  if( $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $wp_cache_meta_object->headers ) ) {
509
  array_push($wp_cache_meta_object->headers, 'Content-Encoding: ' . $wp_cache_gzip_encoding);
543
  return;
544
  update_option( 'wpsupercache_gc_time', time() );
545
 
546
+ global $wp_cache_shutdown_gc;
547
+ if( isset( $wp_cache_shutdown_gc ) && $wp_cache_shutdown_gc == 1 ) {
548
+ do_action( 'wp_cache_gc' );
549
+ } else {
550
+ // we delete expired files, using a wordpress cron event
551
+ // since flush() does not guarantee hand-off to client - problem on Win32 and suPHP
552
+ if(!wp_next_scheduled('wp_cache_gc')) wp_schedule_single_event(time() + 10 , 'wp_cache_gc');
553
+ }
554
  }
555
 
556
  function wp_cache_no_postid($id) {
615
  $matches = array();
616
  if ( ($handle = opendir( $cache_path . 'meta/' )) ) {
617
  while ( false !== ($file = readdir($handle))) {
 
 
 
 
 
 
618
  if ( preg_match("/^({$file_prefix}{$blogcacheid}.*)\.meta/", $file, $matches) ) {
619
  $meta_pathname = $cache_path . 'meta/' . $file;
620
  $content_pathname = $cache_path . $matches[1] . ".html";
631
 
632
  }
633
  }
634
+ closedir($handle);
635
  }
636
  wp_cache_writers_exit();
637
  return $post_id;
wp-cache.php CHANGED
@@ -2,8 +2,8 @@
2
  /*
3
  Plugin Name: WP Super Cache
4
  Plugin URI: http://ocaoimh.ie/wp-super-cache/
5
- Description: Very fast caching module for WordPress.
6
- Version: 0.9
7
  Author: Donncha O Caoimh
8
  Author URI: http://ocaoimh.ie/
9
  */
@@ -110,7 +110,9 @@ function wp_cache_add_pages() {
110
  add_action('admin_menu', 'wp_cache_add_pages');
111
 
112
  function wp_cache_manager() {
113
- global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled, $wp_cache_hello_world, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_mobile_enabled, $wp_cache_mobile_whitelist, $wp_cache_mobile_browsers;
 
 
114
 
115
  if( function_exists( 'is_site_admin' ) )
116
  if( !is_site_admin() )
@@ -178,6 +180,39 @@ jQuery(document).ready(function(){
178
  echo "</div>\n";
179
  return;
180
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
 
182
  if( $cache_enabled == true && $super_cache_enabled == true && !got_mod_rewrite() ) {
183
  ?><h4 style='color: #a00'>Mod rewrite may not be installed!</h4>
@@ -268,9 +303,14 @@ jQuery(document).ready(function(){
268
  prune_super_cache ($cache_path, true);
269
  delete_option( 'super_cache_meta' );
270
  }
 
 
 
 
271
  }
272
 
273
- ?><fieldset class="options" id="show-this-fieldset">
 
274
  <h3>WP Super Cache Status</h3><?php
275
  echo '<form name="wp_manager" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
276
  ?>
@@ -279,8 +319,7 @@ jQuery(document).ready(function(){
279
  <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 />
280
  <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>
281
  <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>
282
- <h4>Experimental Features</h4>
283
- <p><label><input type='checkbox' name='cache_rebuild_files' <?php if( $cache_rebuild_files ) echo "checked"; ?> value='1'> Enable experimental "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.</label></p>
284
  <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 may help but may cause increased server load.</label></p>
285
  <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>
286
  <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>
@@ -310,6 +349,28 @@ jQuery(document).ready(function(){
310
  }
311
  ?>
312
  </fieldset>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
  <?php
314
 
315
  wp_cache_files();
@@ -375,9 +436,7 @@ function wsc_mod_rewrite() {
375
  $home_path = get_home_path();
376
  $home_root = parse_url(get_bloginfo('url'));
377
  $home_root = trailingslashit($home_root['path']);
378
- //$inst_root = parse_url(get_bloginfo('wpurl'));
379
- //$inst_root = trailingslashit($inst_root['path']);
380
- $inst_root = trailingslashit( str_replace( get_option('siteurl'), '', WP_CONTENT_URL ) );
381
  $wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) );
382
  $wprules = str_replace( "RewriteEngine On\n", '', $wprules );
383
  $wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
@@ -804,33 +863,38 @@ function wp_cache_enable() {
804
  }
805
 
806
  function wp_cache_disable() {
807
- global $cache_path, $wp_cache_config_file, $cache_enabled, $supercachedir, $cache_path;
808
 
809
  if (wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file)) {
810
  $cache_enabled = false;
811
  }
812
  wp_super_cache_disable();
813
- sleep( 1 ); // allow existing processes to write to the supercachedir and then delete it
814
- if (function_exists ('prune_super_cache') && is_dir( $supercachedir ) ) {
815
- prune_super_cache( $cache_path, true );
816
- }
817
  }
818
  function wp_super_cache_enable() {
819
  global $supercachedir, $wp_cache_config_file, $super_cache_enabled;
820
 
821
  if( is_dir( $supercachedir . ".disabled" ) )
822
- rename( $supercachedir . ".disabled", $supercachedir );
 
 
 
 
 
823
  wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = true;', $wp_cache_config_file);
824
  $super_cache_enabled = true;
825
  }
826
 
827
  function wp_super_cache_disable() {
828
- global $supercachedir, $wp_cache_config_file, $super_cache_enabled;
829
 
830
  wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = false;', $wp_cache_config_file);
831
  if( is_dir( $supercachedir ) )
832
- rename( $supercachedir, $supercachedir . ".disabled" );
833
  $super_cache_enabled = false;
 
 
 
 
834
  }
835
 
836
  function wp_cache_is_enabled() {
@@ -887,10 +951,6 @@ function wp_cache_replace_line($old, $new, $my_file) {
887
  }
888
  fclose($fd);
889
  return true;
890
- /*
891
- copy($my_file, $my_file . "-prev");
892
- rename($my_file . '-new', $my_file);
893
- */
894
  }
895
 
896
  function wp_cache_verify_cache_dir() {
@@ -944,7 +1004,7 @@ function wp_cache_verify_config_file() {
944
  return false;
945
  }
946
  copy($wp_cache_config_file_sample, $wp_cache_config_file);
947
- $dir = str_replace( '\\', '/', str_replace( WP_CONTENT_DIR, '', dirname(__FILE__) ) );
948
  if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
949
  wp_cache_replace_line('WPCACHEHOME', "define( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/\" );", $wp_cache_config_file);
950
  } elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
@@ -1140,8 +1200,8 @@ function wp_cache_files() {
1140
  $last_gc = get_option( "wpsupercache_gc_time" );
1141
  if( $last_gc ) {
1142
  $next_gc = $cache_max_time < 1800 ? $cache_max_time : 600;
1143
- echo "<p><strong>Garbage Collection</strong><br />Last: " . date( "Y-m-d H:i:s", $last_gc ) . "<br />";
1144
- echo "Next: " . date( "Y-m-d H:i:s", $next_gc + $last_gc ) . "</p>";
1145
  }
1146
 
1147
  echo "<p>Expired files are files older than $cache_max_time seconds. They are still used by the plugin and are deleted periodically.</p>";
@@ -1320,4 +1380,19 @@ function wp_cache_favorite_action( $actions ) {
1320
  }
1321
  add_filter( 'favorite_actions', 'wp_cache_favorite_action' );
1322
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1323
  ?>
2
  /*
3
  Plugin Name: WP Super Cache
4
  Plugin URI: http://ocaoimh.ie/wp-super-cache/
5
+ Description: Very fast caching plugin for WordPress.
6
+ Version: 0.9.1
7
  Author: Donncha O Caoimh
8
  Author URI: http://ocaoimh.ie/
9
  */
110
  add_action('admin_menu', 'wp_cache_add_pages');
111
 
112
  function wp_cache_manager() {
113
+ global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled, $wp_cache_hello_world;
114
+ global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_mobile_enabled, $wp_cache_mobile_whitelist, $wp_cache_mobile_browsers;
115
+ global $wp_cache_cron_check, $wp_cache_debug, $wp_cache_hide_donation;
116
 
117
  if( function_exists( 'is_site_admin' ) )
118
  if( !is_site_admin() )
180
  echo "</div>\n";
181
  return;
182
  }
183
+ if( $wp_cache_debug || !$wp_cache_cron_check ) {
184
+ if( function_exists( "wp_remote_get" ) == false ) {
185
+ $hostname = str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'siteurl' ) ) );
186
+ if( strpos( $hostname, '/' ) )
187
+ $hostname = substr( $hostname, 0, strpos( $hostname, '/' ) );
188
+ $ip = gethostbyname( $hostname );
189
+ if( substr( $ip, 0, 3 ) == '127' || substr( $ip, 0, 7 ) == '192.168' ) {
190
+ ?><h3>Warning! Your hostname "<?php echo $hostname; ?>" resolves to <?php echo $ip; ?></h3>
191
+ <div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'>
192
+ <p>Your server thinks your hostname resolves to <?php echo $ip; ?>. Some services such as garbage collection by this plugin, and WordPress scheduled posts may not operate correctly.</p>
193
+ <p>Please see entry 16 in the <a href="http://wordpress.org/extend/plugins/wp-super-cache/faq/">Troubleshooting section</a> of the readme.txt</p>
194
+ </div>
195
+ <?php
196
+ } else {
197
+ wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
198
+ }
199
+ } else {
200
+ $cron_url = get_option( 'siteurl' ) . '/wp-cron.php?check=' . wp_hash('187425');
201
+ $cron = wp_remote_get($cron_url, array('timeout' => 0.01, 'blocking' => true));
202
+ if( is_array( $cron ) ) {
203
+ if( $cron[ 'response' ][ 'code' ] == '404' ) {
204
+ ?><h3>Warning! wp-cron.php not found!</h3>
205
+ <div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'>
206
+ <p>Unfortunately WordPress cannot find the file wp-cron.php. This script is required for the the correct operation of garbage collection by this plugin, WordPress scheduled posts as well as other critical activities.</p>
207
+ <p>Please see entry 16 in the <a href="http://wordpress.org/extend/plugins/wp-super-cache/faq/">Troubleshooting section</a> of the readme.txt</p>
208
+ </div>
209
+ <?php
210
+ } else {
211
+ wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
212
+ }
213
+ }
214
+ }
215
+ }
216
 
217
  if( $cache_enabled == true && $super_cache_enabled == true && !got_mod_rewrite() ) {
218
  ?><h4 style='color: #a00'>Mod rewrite may not be installed!</h4>
303
  prune_super_cache ($cache_path, true);
304
  delete_option( 'super_cache_meta' );
305
  }
306
+ if( isset( $_POST[ 'wp_cache_hide_donation' ] ) && $_POST[ 'wp_cache_hide_donation' ] != $wp_cache_hide_donation ) {
307
+ $wp_cache_hide_donation = intval( $_POST[ 'wp_cache_hide_donation' ] );
308
+ wp_cache_replace_line('^ *\$wp_cache_hide_donation', "\$wp_cache_hide_donation = " . $wp_cache_hide_donation . ";", $wp_cache_config_file);
309
+ }
310
  }
311
 
312
+ ?>
313
+ <table><td><fieldset class="options" id="show-this-fieldset">
314
  <h3>WP Super Cache Status</h3><?php
315
  echo '<form name="wp_manager" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
316
  ?>
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 may 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>
349
  }
350
  ?>
351
  </fieldset>
352
+ </td><td valign='top'>
353
+ <div style='background: #ffc; border: 1px solid #333; margin: 2px; padding: 5px'>
354
+ <h3 align='center'>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">
360
+ <input type="hidden" name="cmd" value="_s-xclick"/>
361
+ <input type="hidden" name="hosted_button_id" value="3244504"/>
362
+ <input type="image" src="https://www.paypal.com/en_GB/i/btn/btn_donate_SM.gif" border="0" name="submit" alt=""/>
363
+ <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"/><br />
364
+ </form>
365
+ <p>Don't show me this again. <form action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post"><input type='hidden' name='wp_cache_hide_donation' value='1' /><input type='submit' value='Hide' /><?php wp_nonce_field('wp-cache'); ?></form></p>
366
+ </div>
367
+ <?php } else { ?>
368
+ <p><a href="http://ocaoimh.ie/wp-super-cache/?r=supercache">WP Super Cache</a> is maintained and developed by <a href="http://ocaoimh.ie/?r=supercache">Donncha O Caoimh</a> with contributions from many others thanks to the GPL.</p>
369
+ <p>He blogs at <a href="http://ocaoimh.ie/?r=supercache">Holy Shmoly</a> and posts photos at <a href="http://inphotos.org/?r=supercache">In Photos.org</a>. You can say hi to him on <a href="http://twitter.com/donncha/">Twitter</a> too!</p>
370
+ <?php } ?>
371
+ </div>
372
+
373
+ </td></table>
374
  <?php
375
 
376
  wp_cache_files();
436
  $home_path = get_home_path();
437
  $home_root = parse_url(get_bloginfo('url'));
438
  $home_root = trailingslashit($home_root['path']);
439
+ $inst_root = str_replace( '//', '/', '/' . trailingslashit( str_replace( $_SERVER[ 'DOCUMENT_ROOT' ], '', str_replace( '\\', '/', WP_CONTENT_DIR ) ) ) );
 
 
440
  $wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) );
441
  $wprules = str_replace( "RewriteEngine On\n", '', $wprules );
442
  $wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
863
  }
864
 
865
  function wp_cache_disable() {
866
+ global $wp_cache_config_file, $cache_enabled;
867
 
868
  if (wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file)) {
869
  $cache_enabled = false;
870
  }
871
  wp_super_cache_disable();
 
 
 
 
872
  }
873
  function wp_super_cache_enable() {
874
  global $supercachedir, $wp_cache_config_file, $super_cache_enabled;
875
 
876
  if( is_dir( $supercachedir . ".disabled" ) )
877
+ if( is_dir( $supercachedir ) ) {
878
+ prune_super_cache( $supercachedir . ".disabled", true );
879
+ @unlink( $supercachedir . ".disabled" );
880
+ } else {
881
+ @rename( $supercachedir . ".disabled", $supercachedir );
882
+ }
883
  wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = true;', $wp_cache_config_file);
884
  $super_cache_enabled = true;
885
  }
886
 
887
  function wp_super_cache_disable() {
888
+ global $cache_path, $supercachedir, $wp_cache_config_file, $super_cache_enabled;
889
 
890
  wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = false;', $wp_cache_config_file);
891
  if( is_dir( $supercachedir ) )
892
+ @rename( $supercachedir, $supercachedir . ".disabled" );
893
  $super_cache_enabled = false;
894
+ sleep( 1 ); // allow existing processes to write to the supercachedir and then delete it
895
+ if (function_exists ('prune_super_cache') && is_dir( $supercachedir ) ) {
896
+ prune_super_cache( $cache_path, true );
897
+ }
898
  }
899
 
900
  function wp_cache_is_enabled() {
951
  }
952
  fclose($fd);
953
  return true;
 
 
 
 
954
  }
955
 
956
  function wp_cache_verify_cache_dir() {
1004
  return false;
1005
  }
1006
  copy($wp_cache_config_file_sample, $wp_cache_config_file);
1007
+ $dir = str_replace( str_replace( '\\', '/', WP_CONTENT_DIR ), '', str_replace( '\\', '/', dirname(__FILE__) ) );
1008
  if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
1009
  wp_cache_replace_line('WPCACHEHOME', "define( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/\" );", $wp_cache_config_file);
1010
  } elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
1200
  $last_gc = get_option( "wpsupercache_gc_time" );
1201
  if( $last_gc ) {
1202
  $next_gc = $cache_max_time < 1800 ? $cache_max_time : 600;
1203
+ echo "<p><strong>Garbage Collection</strong><br />Last: " . date( "Y-m-d H:i:s", ( $last_gc + ( get_option( 'gmt_offset' ) * 3600 ) ) ) . "<br />";
1204
+ echo "Next: " . date( "Y-m-d H:i:s", ( $next_gc + $last_gc + ( get_option( 'gmt_offset' ) * 3600 ) ) ) . "</p>";
1205
  }
1206
 
1207
  echo "<p>Expired files are files older than $cache_max_time seconds. They are still used by the plugin and are deleted periodically.</p>";
1380
  }
1381
  add_filter( 'favorite_actions', 'wp_cache_favorite_action' );
1382
 
1383
+ function wp_cache_plugin_notice( $plugin ) {
1384
+ global $cache_enabled;
1385
+ if( $plugin == 'wp-super-cache/wp-cache.php' ) {
1386
+ if( !$cache_enabled )
1387
+ 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>';
1388
+ }
1389
+ }
1390
+ add_action( 'after_plugin_row', 'wp_cache_plugin_notice' );
1391
+
1392
+ function wp_cache_admin_notice() {
1393
+ global $cache_enabled;
1394
+ if( substr( $_SERVER["PHP_SELF"], -11 ) == 'plugins.php' && !$cache_enabled )
1395
+ add_action('admin_notices', create_function('', '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.\', \'wpsupercache\') ,\'' . admin_url( 'options-general.php?page=wpsupercache' ) . '\') . \'</strong></p></div>\';') );
1396
+ }
1397
+ add_action( 'admin_init', 'wp_cache_admin_notice' );
1398
  ?>