WP Super Cache - Version 0.9.5

Version Description

  • Show next and last GC times in minutes, not local time.
  • Don't serve wp_cache cache files to rejected user agents. Supercache files are still served to them.
  • If enabled, mobile support now serves php cached files to mobile clients and static cached files to everyone else.
  • Added checks for "WPSC_DISABLE_COMPRESSION" and "WPSC_DISABLE_LOCKING" constants to disable compression and file locking. For hosting companies primarily.
  • Added check for DONOTCACHEPAGE constant to avoid caching a page.
  • Use PHP_DOCUMENT_ROOT when creating .htaccess if necessary.
Download this release

Release Info

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

Code changes from version 0.9.4.3 to 0.9.5

Files changed (6) hide show
  1. Changelog.txt +131 -0
  2. readme.txt +22 -11
  3. wp-cache-config-sample.php +3 -2
  4. wp-cache-phase1.php +21 -12
  5. wp-cache-phase2.php +38 -51
  6. wp-cache.php +62 -22
Changelog.txt CHANGED
@@ -1,3 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  2009-04-25 06:30 donncha
2
 
3
  * readme.txt, wp-cache.php: Bumped version number to 0.9.4.3
1
+ 2009-07-17 15:30 donncha
2
+
3
+ * readme.txt: Added changelog to readme.txt
4
+
5
+ 2009-07-17 15:22 donncha
6
+
7
+ * readme.txt, wp-cache.php: Bump version to 0.9.5
8
+ Bump tested version to 2.8.1
9
+
10
+ 2009-07-17 15:19 donncha
11
+
12
+ * wp-cache-phase1.php, wp-cache-phase2.php, wp-cache.php: Don't
13
+ serve wp_cached cache files to rejected USER AGENTs
14
+
15
+ 2009-07-17 15:08 donncha
16
+
17
+ * wp-cache.php: Show next and last GC times in minutes, not local
18
+ times
19
+
20
+ 2009-07-02 17:21 donncha
21
+
22
+ * wp-cache-phase2.php: Rearrange checks for cache files.
23
+
24
+ 2009-06-25 21:01 donncha
25
+
26
+ * wp-cache-phase2.php: Hide filemtime warnings
27
+
28
+ 2009-06-19 15:07 donncha
29
+
30
+ * wp-cache-phase1.php: Don't check the filesize or mtime
31
+
32
+ 2009-06-19 13:02 donncha
33
+
34
+ * wp-cache-phase1.php, wp-cache-phase2.php: Don't check file age
35
+ when serving cached content - it will be deleted by ordinary
36
+ updates or by garbage collection
37
+ Check file age of each cache file only when regenerating (and
38
+ only to check if file was recently recreated)
39
+
40
+ 2009-06-19 09:03 donncha
41
+
42
+ * wp-cache.php: Updated blurb
43
+
44
+ 2009-06-19 09:01 donncha
45
+
46
+ * Changelog.txt: Updated changelog
47
+
48
+ 2009-06-18 12:34 donncha
49
+
50
+ * wp-cache-phase2.php: Typos in closing and unlink commands
51
+
52
+ 2009-06-12 10:47 donncha
53
+
54
+ * readme.txt, wp-cache-config-sample.php, wp-cache-phase1.php,
55
+ wp-cache.php: Bump tested version to 2.8
56
+ Applied patch to fix PHP warnings by Matt Martz,
57
+ http://sivel.net/
58
+
59
+ 2009-06-10 22:46 donncha
60
+
61
+ * wp-cache-phase1.php: Forgot the mobile whitelist
62
+
63
+ 2009-06-05 17:04 donncha
64
+
65
+ * wp-cache-phase1.php: Use cookies action instead of cache_key so
66
+ that supercache files aren't generated by anon mobile users
67
+
68
+ 2009-06-05 15:12 donncha
69
+
70
+ * wp-cache-config-sample.php, wp-cache.php: Added "Android" mobile
71
+ user agent, thanks Matt Martz/sivel
72
+
73
+ 2009-06-05 12:27 donncha
74
+
75
+ * readme.txt, wp-cache.php: Don't force the plugin into "half on"
76
+ mode if mobile support selected.
77
+ Added rewrite rules so that mobile devices are ignored by static
78
+ cache.
79
+ Thanks Vladimir Prelovac for bugging me about this.
80
+
81
+ 2009-05-29 08:40 donncha
82
+
83
+ * wp-cache-phase1.php: Ignore the WP test cookie, props Jay @
84
+ http://jay.gooby.org/post/nginx-wp-super-cache-not-writing-cache-files-solved
85
+
86
+ 2009-05-26 09:55 donncha
87
+
88
+ * wp-cache-phase2.php: Use blog's html type rather than text/html,
89
+ props Weston Ruter
90
+
91
+ 2009-05-26 09:25 donncha
92
+
93
+ * wp-cache-phase1.php, wp-cache-phase2.php: Cache the REQUEST_URI
94
+ in $wp_cache_request_uri in case a plugin overwrites it.
95
+
96
+ 2009-05-21 13:12 donncha
97
+
98
+ * wp-cache.php: Add newlines to mod_rewrite rules
99
+
100
+ 2009-05-19 11:21 donncha
101
+
102
+ * readme.txt: Updated recent changes list
103
+
104
+ 2009-05-19 11:18 donncha
105
+
106
+ * readme.txt: Updated docs for DONOTCACHEPAGE constant
107
+
108
+ 2009-05-19 11:15 donncha
109
+
110
+ * wp-cache.php: Added "WPSC_DISABLE_COMPRESSION" constant so
111
+ hosting companies can disable compression in wp-super-cache
112
+
113
+ 2009-05-19 11:04 donncha
114
+
115
+ * wp-cache.php: Added "WPSC_DISABLE_LOCKING" constant so hosting
116
+ companies can disable file locking sitewide
117
+
118
+ 2009-05-19 10:19 donncha
119
+
120
+ * wp-cache-phase2.php: Added "DONOTCACHEPAGE" constant so plugins
121
+ can specify pages that should not be cached.
122
+
123
+ 2009-05-11 13:35 donncha
124
+
125
+ * wp-cache.php: Use PHP_DOCUMENT_ROOT in .htaccess rules if set,
126
+ props Adrian Ott @ Mosso
127
+
128
+ 2009-04-25 06:30 donncha
129
+
130
+ * Changelog.txt: Updated changelog
131
+
132
  2009-04-25 06:30 donncha
133
 
134
  * readme.txt, wp-cache.php: Bumped version number to 0.9.4.3
readme.txt CHANGED
@@ -1,8 +1,8 @@
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.4.3
6
  Requires at least: 2.6
7
  Donate link: http://ocaoimh.ie/wordpress-plugins/gifts-and-donations/
8
 
@@ -11,15 +11,6 @@ A very fast caching engine for WordPress that produces static html files.
11
  == Description ==
12
  This plugin generates static html files from your dynamic WordPress blog. After a html file is generated your webserver will serve that file instead of processing the comparatively heavier and more expensive WordPress PHP scripts.
13
 
14
- = Recent Changes =
15
-
16
- 1. Added "Don't cache for logged in users" option.
17
- 2. Display file size stats on admin page.
18
- 3. Clear the cache when profile page is updated.
19
- 4. Don't cache post previews.
20
- 5. Added backslashes to rejected URI regex list.
21
- 6. Fixed problems with posts and comments not refreshing.
22
-
23
  The static html files will be served to the vast majority of your users, but because a user's details are displayed in the comment form after they leave a comment those requests are handled by PHP. Static files are served to:
24
 
25
  1. Users who are not logged in.
@@ -35,6 +26,24 @@ See the [WP Super Cache homepage](http://ocaoimh.ie/wp-super-cache/) for further
35
 
36
  The [changelog](http://svn.wp-plugins.org/wp-super-cache/trunk/Changelog.txt) is a good place to start if you want to know what has changed since you last downloaded the plugin.
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  == Installation ==
39
  1. You should have the Apache mod mime and mod rewrite modules installed and WordPress fancy permalinks enabled. PHP safe mode should be disabled. If any of those are missing or off you can still use the slower WP-Cache part of the plugin.
40
  2. If you have WP-Cache installed already, please disable it. Edit wp-config.php and make sure the WP_CACHE define is deleted, and remove the files wp-content/wp-cache-config.php and wp-content/advanced-cache.php. These will be recreated when you install this plugin.
@@ -52,6 +61,7 @@ The [changelog](http://svn.wp-plugins.org/wp-super-cache/trunk/Changelog.txt) is
52
  `RewriteCond %{QUERY_STRING} !.*=.*`
53
  `RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$`
54
  `RewriteCond %{HTTP:Accept-Encoding} gzip`
 
55
  `RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f`
56
  `RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]`
57
 
@@ -59,6 +69,7 @@ The [changelog](http://svn.wp-plugins.org/wp-super-cache/trunk/Changelog.txt) is
59
  `RewriteCond %{QUERY_STRING} !.*=.*`
60
  `RewriteCond %{QUERY_STRING} !.*attachment_id=.*`
61
  `RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$`
 
62
  `RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f`
63
  `RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L]`
64
 
1
  === WP Super Cache ===
2
  Contributors: donncha
3
  Tags: performance,caching,wp-cache,wp-super-cache,cache
4
+ Tested up to: 2.8.1
5
+ Stable tag: 0.9.5
6
  Requires at least: 2.6
7
  Donate link: http://ocaoimh.ie/wordpress-plugins/gifts-and-donations/
8
 
11
  == Description ==
12
  This plugin generates static html files from your dynamic WordPress blog. After a html file is generated your webserver will serve that file instead of processing the comparatively heavier and more expensive WordPress PHP scripts.
13
 
 
 
 
 
 
 
 
 
 
14
  The static html files will be served to the vast majority of your users, but because a user's details are displayed in the comment form after they leave a comment those requests are handled by PHP. Static files are served to:
15
 
16
  1. Users who are not logged in.
26
 
27
  The [changelog](http://svn.wp-plugins.org/wp-super-cache/trunk/Changelog.txt) is a good place to start if you want to know what has changed since you last downloaded the plugin.
28
 
29
+ == Changelog ==
30
+
31
+ = 0.9.5 =
32
+ * Show next and last GC times in minutes, not local time.
33
+ * Don't serve wp_cache cache files to rejected user agents. Supercache files are still served to them.
34
+ * If enabled, mobile support now serves php cached files to mobile clients and static cached files to everyone else.
35
+ * Added checks for "WPSC_DISABLE_COMPRESSION" and "WPSC_DISABLE_LOCKING" constants to disable compression and file locking. For hosting companies primarily.
36
+ * Added check for DONOTCACHEPAGE constant to avoid caching a page.
37
+ * Use PHP_DOCUMENT_ROOT when creating .htaccess if necessary.
38
+
39
+ = 0.9.4.3 =
40
+ 1. Added "Don't cache for logged in users" option.
41
+ 2. Display file size stats on admin page.
42
+ 3. Clear the cache when profile page is updated.
43
+ 4. Don't cache post previews.
44
+ 5. Added backslashes to rejected URI regex list.
45
+ 6. Fixed problems with posts and comments not refreshing.
46
+
47
  == Installation ==
48
  1. You should have the Apache mod mime and mod rewrite modules installed and WordPress fancy permalinks enabled. PHP safe mode should be disabled. If any of those are missing or off you can still use the slower WP-Cache part of the plugin.
49
  2. If you have WP-Cache installed already, please disable it. Edit wp-config.php and make sure the WP_CACHE define is deleted, and remove the files wp-content/wp-cache-config.php and wp-content/advanced-cache.php. These will be recreated when you install this plugin.
61
  `RewriteCond %{QUERY_STRING} !.*=.*`
62
  `RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$`
63
  `RewriteCond %{HTTP:Accept-Encoding} gzip`
64
+ `RewriteCond %{HTTP_user_agent} !^.*(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).*`
65
  `RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f`
66
  `RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]`
67
 
69
  `RewriteCond %{QUERY_STRING} !.*=.*`
70
  `RewriteCond %{QUERY_STRING} !.*attachment_id=.*`
71
  `RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$`
72
+ `RewriteCond %{HTTP_user_agent} !^.*(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).*`
73
  `RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f`
74
  `RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L]`
75
 
wp-cache-config-sample.php CHANGED
@@ -5,7 +5,8 @@ WP-Cache Config Sample File
5
  See wp-cache.php for author details.
6
  */
7
 
8
- define( 'WPCACHEHOME', WP_CONTENT_DIR . '/plugins/wp-super-cache/' );
 
9
 
10
  $cache_compression = 0; // Super cache compression
11
  $cache_enabled = false;
@@ -63,7 +64,7 @@ if ( '/' != substr($cache_path, -1)) {
63
 
64
  $wp_cache_mobile = 0;
65
  $wp_cache_mobile_whitelist = 'Stand Alone/QNws';
66
- $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';
67
 
68
  // gzip the first page generated for clients that support it.
69
  $wp_cache_gzip_first = 0;
5
  See wp-cache.php for author details.
6
  */
7
 
8
+ if ( ! defined('WPCACHEHOME') )
9
+ define( 'WPCACHEHOME', WP_CONTENT_DIR . '/plugins/wp-super-cache/' );
10
 
11
  $cache_compression = 0; // Super cache compression
12
  $cache_enabled = false;
64
 
65
  $wp_cache_mobile = 0;
66
  $wp_cache_mobile_whitelist = 'Stand Alone/QNws';
67
+ $wp_cache_mobile_browsers = 'Android, 2.0 MMP, 240x320, AvantGo, BlackBerry, Blazer, Cellphone, Danger, DoCoMo, Elaine/3.0, EudoraWeb, hiptop, IEMobile, iPhone, iPod, KYOCERA/WX310K, LG/U990, MIDP-2.0, MMEF20, MOT-V, NetFront, Newt, Nintendo Wii, Nitro, Nokia, Opera Mini, Palm, Playstation Portable, portalmmm, Proxinet, ProxiNet, SHARP-TQ-GX10, Small, SonyEricsson, Symbian OS, SymbianOS, TS21i-10, UP.Browser, UP.Link, Windows CE, WinWAP';
68
 
69
  // gzip the first page generated for clients that support it.
70
  $wp_cache_gzip_first = 0;
wp-cache-phase1.php CHANGED
@@ -59,9 +59,11 @@ if ($cache_compression) {
59
  $wp_cache_gzip_encoding = gzip_accepted();
60
  }
61
 
62
- add_cacheaction( 'wp_cache_key', 'wp_cache_check_mobile' );
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" );
@@ -78,9 +80,7 @@ $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)) ) {
82
- if ($mtime + $cache_max_time > time() ) {
83
-
84
  if (! ($meta = unserialize(@file_get_contents($meta_pathname))) )
85
  return true;
86
  if( is_array( $meta ) == false ) {
@@ -101,22 +101,18 @@ if( file_exists( $cache_file ) && ($mtime = @filemtime($meta_pathname)) ) {
101
  header($header);
102
  }
103
  header( 'WP-Super-Cache: WP-Cache' );
104
- if ( !($content_size = @filesize($cache_file)) > 0 || $mtime < @filemtime($cache_file))
105
- return true;
106
  if ( $meta[ 'dynamic' ] ) {
107
  include($cache_file);
108
  } else {
109
  readfile( $cache_file );
110
  }
111
  die();
112
- }
113
- $file_expired = true; // To signal this file was expired
114
  }
115
 
116
  function wp_cache_postload() {
117
  global $cache_enabled;
118
 
119
- if ( !$cache_enabled || $_GET[ 'preview' ] )
120
  return true;
121
  require_once( WPCACHEHOME . 'wp-cache-phase2.php');
122
  wp_cache_phase2();
@@ -125,7 +121,7 @@ function wp_cache_postload() {
125
  function wp_cache_get_cookies_values() {
126
  $string = '';
127
  while ($key = key($_COOKIE)) {
128
- if (preg_match("/^wp-postpass|^wordpress|^comment_author_/", $key)) {
129
  $string .= $_COOKIE[$key] . ",";
130
  }
131
  next($_COOKIE);
@@ -156,7 +152,7 @@ function do_cacheaction( $action, $value = '' ) {
156
 
157
  // From http://wordpress.org/extend/plugins/wordpress-mobile-edition/ by Alex King
158
  function wp_cache_check_mobile( $cache_key ) {
159
- global $wp_cache_mobile_enabled, $wp_cache_mobile_browser, $wp_cache_mobile_browsers;
160
  if( !isset( $wp_cache_mobile_enabled ) || false == $wp_cache_mobile_enabled )
161
  return $cache_key;
162
 
@@ -187,4 +183,17 @@ function wp_cache_debug( $message ) {
187
  mail( $wp_cache_debug, '[' . addslashes( $_SERVER[ 'HTTP_HOST' ] ) . "] WP Super Cache Debug", $message );
188
  }
189
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  ?>
59
  $wp_cache_gzip_encoding = gzip_accepted();
60
  }
61
 
62
+ add_cacheaction( 'wp_cache_get_cookies_values', 'wp_cache_check_mobile' );
63
 
64
+ $wp_cache_request_uri = $_SERVER[ 'REQUEST_URI' ]; // Cache this in case any plugin modifies it.
65
+
66
+ $key = $blogcacheid . md5( do_cacheaction( 'wp_cache_key', $_SERVER['HTTP_HOST'].preg_replace('/#.*$/', '', str_replace( '/index.php', '/', $wp_cache_request_uri ) ).$wp_cache_gzip_encoding.wp_cache_get_cookies_values() ) );
67
 
68
  if( false == @is_dir( $blog_cache_dir ) ) {
69
  @mkdir( $cache_path . "blogs" );
80
  $meta_pathname = realpath( $blog_cache_dir . 'meta/' . $meta_file );
81
 
82
  $wp_start_time = microtime();
83
+ if( file_exists( $cache_file ) && !wp_cache_user_agent_is_rejected() ) {
 
 
84
  if (! ($meta = unserialize(@file_get_contents($meta_pathname))) )
85
  return true;
86
  if( is_array( $meta ) == false ) {
101
  header($header);
102
  }
103
  header( 'WP-Super-Cache: WP-Cache' );
 
 
104
  if ( $meta[ 'dynamic' ] ) {
105
  include($cache_file);
106
  } else {
107
  readfile( $cache_file );
108
  }
109
  die();
 
 
110
  }
111
 
112
  function wp_cache_postload() {
113
  global $cache_enabled;
114
 
115
+ if ( !$cache_enabled || isset( $_GET[ 'preview' ] ) )
116
  return true;
117
  require_once( WPCACHEHOME . 'wp-cache-phase2.php');
118
  wp_cache_phase2();
121
  function wp_cache_get_cookies_values() {
122
  $string = '';
123
  while ($key = key($_COOKIE)) {
124
+ if ( preg_match( "/^wp-postpass|^wordpress|^comment_author_/", $key ) && $_COOKIE[ $key ] != 'WP Cookie check' ) {
125
  $string .= $_COOKIE[$key] . ",";
126
  }
127
  next($_COOKIE);
152
 
153
  // From http://wordpress.org/extend/plugins/wordpress-mobile-edition/ by Alex King
154
  function wp_cache_check_mobile( $cache_key ) {
155
+ global $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_mobile_whitelist;
156
  if( !isset( $wp_cache_mobile_enabled ) || false == $wp_cache_mobile_enabled )
157
  return $cache_key;
158
 
183
  mail( $wp_cache_debug, '[' . addslashes( $_SERVER[ 'HTTP_HOST' ] ) . "] WP Super Cache Debug", $message );
184
  }
185
 
186
+ function wp_cache_user_agent_is_rejected() {
187
+ global $cache_rejected_user_agent;
188
+
189
+ if (!function_exists('apache_request_headers')) return false;
190
+ $headers = apache_request_headers();
191
+ if (!isset($headers["User-Agent"])) return false;
192
+ foreach ($cache_rejected_user_agent as $expr) {
193
+ if (strlen($expr) > 0 && stristr($headers["User-Agent"], $expr))
194
+ return true;
195
+ }
196
+ return false;
197
+ }
198
+
199
  ?>
wp-cache-phase2.php CHANGED
@@ -2,7 +2,7 @@
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, $wp_cache_not_logged_in;
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' );
@@ -36,7 +36,7 @@ function wp_cache_phase2() {
36
  if( $_SERVER["REQUEST_METHOD"] == 'POST' || get_option('gzipcompression'))
37
  return false;
38
  $script = basename($_SERVER['PHP_SELF']);
39
- if (!in_array($script, $cache_acceptable_files) && wp_cache_is_rejected($_SERVER["REQUEST_URI"]))
40
  return false;
41
  if (wp_cache_user_agent_is_rejected()) return;
42
  if($wp_cache_gzip_encoding)
@@ -119,20 +119,6 @@ function wp_cache_is_rejected($uri) {
119
  return false;
120
  }
121
 
122
- function wp_cache_user_agent_is_rejected() {
123
- global $cache_rejected_user_agent;
124
-
125
- if (!function_exists('apache_request_headers')) return false;
126
- $headers = apache_request_headers();
127
- if (!isset($headers["User-Agent"])) return false;
128
- foreach ($cache_rejected_user_agent as $expr) {
129
- if (strlen($expr) > 0 && stristr($headers["User-Agent"], $expr))
130
- return true;
131
- }
132
- return false;
133
- }
134
-
135
-
136
  function wp_cache_mutex_init() {
137
  global $use_flock, $mutex, $cache_path, $mutex_filename, $sem_id, $blog_cache_dir;
138
 
@@ -183,8 +169,8 @@ function wp_cache_writers_exit() {
183
  }
184
 
185
  function get_current_url_supercache_dir() {
186
- global $cached_direct_pages, $cache_path;
187
- $uri = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '/index.php', '/', str_replace( '..', '', preg_replace("/(\?.*)?$/", '', $_SERVER['REQUEST_URI'] ) ) ) );
188
  $uri = str_replace( '\\', '', $uri );
189
  $dir = strtolower(preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"])) . $uri; // To avoid XSS attacks
190
  $dir = apply_filters( 'supercache_dir', $dir );
@@ -197,6 +183,8 @@ function get_current_url_supercache_dir() {
197
  }
198
 
199
  function wp_cache_ob_callback( $buffer ) {
 
 
200
  $buffer = &wp_cache_get_ob( $buffer );
201
  wp_cache_shutdown_callback();
202
  return $buffer;
@@ -208,7 +196,7 @@ function wp_cache_get_ob(&$buffer) {
208
  global $new_cache, $wp_cache_meta, $file_expired, $blog_id, $cache_compression;
209
  global $wp_cache_gzip_encoding, $super_cache_enabled, $cached_direct_pages;
210
  global $wp_cache_404, $gzsize, $supercacheonly, $wp_cache_gzip_first, $wp_cache_gmt_offset;
211
- global $blog_cache_dir;
212
 
213
  $new_cache = true;
214
  $wp_cache_meta = '';
@@ -238,13 +226,7 @@ function wp_cache_get_ob(&$buffer) {
238
  return $buffer;
239
  }
240
 
241
- $mtime = @filemtime( $blog_cache_dir . $cache_filename );
242
- /* Return if:
243
- the file didn't exist before but it does exist now (another connection created)
244
- OR
245
- the file was expired and its mtime is less than 5 seconds
246
- */
247
- if( !((!$file_expired && $mtime) || ($mtime && $file_expired && (time() - $mtime) < 5)) ) {
248
  $dir = get_current_url_supercache_dir();
249
  $supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]);
250
  if( !empty( $_GET ) || is_feed() || ( $super_cache_enabled == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) ) )
@@ -258,10 +240,12 @@ function wp_cache_get_ob(&$buffer) {
258
  $supercacheonly = true;
259
 
260
  if( !$supercacheonly ) {
261
- $fr = @fopen($tmp_wpcache_filename, 'w');
262
- if (!$fr) {
263
- $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $cache_path ) . $cache_filename . " -->\n";
264
- return $buffer;
 
 
265
  }
266
  }
267
  if( $super_cache_enabled ) {
@@ -274,22 +258,23 @@ function wp_cache_get_ob(&$buffer) {
274
 
275
  $cache_fname = "{$dir}index.html";
276
  $tmp_cache_filename = $dir . uniqid( mt_rand(), true ) . '.tmp';
277
- $fr2 = @fopen( $tmp_cache_filename, 'w' );
278
- if (!$fr2) {
279
- $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . " -->\n";
280
- @fclose( $fr );
281
- @nlink( $tmp_wpcache_filename );
282
- return $buffer;
283
- }
284
- if( $cache_compression ) {
285
- $gz = @fopen( $tmp_cache_filename . ".gz", 'w');
286
- if (!$gz) {
287
- $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz -->\n";
288
- @close( $fr );
289
- @nlink( $tmp_wpcache_filename );
290
- @close( $fr2 );
291
- @nlink( $tmp_cache_filename );
292
  return $buffer;
 
 
 
 
 
 
 
 
 
 
293
  }
294
  }
295
  }
@@ -359,7 +344,7 @@ function wp_cache_get_ob(&$buffer) {
359
  @rename( $tmp_cache_filename . '.gz', $cache_fname . '.gz' );
360
  }
361
  }
362
- }
363
  wp_cache_writers_exit();
364
  if ( !headers_sent() && isset( $wp_cache_gzip_first ) && 1 == $wp_cache_gzip_first && $wp_cache_gzip_encoding && $gzdata) {
365
  header( 'Content-Encoding: ' . $wp_cache_gzip_encoding );
@@ -487,9 +472,9 @@ function wp_cache_phase2_clean_expired($file_prefix) {
487
 
488
  function wp_cache_shutdown_callback() {
489
  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;
490
- global $wp_cache_blog_charset;
491
 
492
- $wp_cache_meta[ 'uri' ] = $_SERVER["SERVER_NAME"].preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER['REQUEST_URI']); // To avoid XSS attacks
493
  $wp_cache_meta[ 'blog_id' ] = $blog_id;
494
  $wp_cache_meta[ 'post' ] = wp_cache_post_id();
495
 
@@ -526,7 +511,9 @@ function wp_cache_shutdown_callback() {
526
  $value = "application/rss+xml";
527
  }
528
  } else { // not a feed
529
- $value = 'text/html';
 
 
530
  }
531
  $value .= "; charset=\"" . $wp_cache_blog_charset . "\"";
532
 
@@ -567,12 +554,12 @@ function wp_cache_no_postid($id) {
567
  }
568
 
569
  function wp_cache_get_postid_from_comment($comment_id) {
570
- global $super_cache_enabled;
571
  $comment = get_comment($comment_id, ARRAY_A);
572
  $postid = $comment['comment_post_ID'];
573
  // Do nothing if comment is not moderated
574
  // http://ocaoimh.ie/2006/12/05/caching-wordpress-with-wp-cache-in-a-spam-filled-world
575
- if( !preg_match('/wp-admin\//', $_SERVER['REQUEST_URI']) )
576
  if( $comment['comment_approved'] == 'spam' ) { // changed from 1 to "spam"
577
  return $postid;
578
  } elseif( $comment['comment_approved'] == '0' ) {
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, $wp_cache_not_logged_in, $wp_cache_request_uri;
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' );
36
  if( $_SERVER["REQUEST_METHOD"] == 'POST' || get_option('gzipcompression'))
37
  return false;
38
  $script = basename($_SERVER['PHP_SELF']);
39
+ if (!in_array($script, $cache_acceptable_files) && wp_cache_is_rejected($wp_cache_request_uri))
40
  return false;
41
  if (wp_cache_user_agent_is_rejected()) return;
42
  if($wp_cache_gzip_encoding)
119
  return false;
120
  }
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  function wp_cache_mutex_init() {
123
  global $use_flock, $mutex, $cache_path, $mutex_filename, $sem_id, $blog_cache_dir;
124
 
169
  }
170
 
171
  function get_current_url_supercache_dir() {
172
+ global $cached_direct_pages, $cache_path, $wp_cache_request_uri;
173
+ $uri = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '/index.php', '/', str_replace( '..', '', preg_replace("/(\?.*)?$/", '', $wp_cache_request_uri ) ) ) );
174
  $uri = str_replace( '\\', '', $uri );
175
  $dir = strtolower(preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"])) . $uri; // To avoid XSS attacks
176
  $dir = apply_filters( 'supercache_dir', $dir );
183
  }
184
 
185
  function wp_cache_ob_callback( $buffer ) {
186
+ if( defined( 'DONOTCACHEPAGE' ) )
187
+ return $buffer;
188
  $buffer = &wp_cache_get_ob( $buffer );
189
  wp_cache_shutdown_callback();
190
  return $buffer;
196
  global $new_cache, $wp_cache_meta, $file_expired, $blog_id, $cache_compression;
197
  global $wp_cache_gzip_encoding, $super_cache_enabled, $cached_direct_pages;
198
  global $wp_cache_404, $gzsize, $supercacheonly, $wp_cache_gzip_first, $wp_cache_gmt_offset;
199
+ global $blog_cache_dir, $wp_cache_request_uri;
200
 
201
  $new_cache = true;
202
  $wp_cache_meta = '';
226
  return $buffer;
227
  }
228
 
229
+ //if( !((!$file_expired && $mtime) || ($mtime && $file_expired && (time() - $mtime) < 5)) ) {
 
 
 
 
 
 
230
  $dir = get_current_url_supercache_dir();
231
  $supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]);
232
  if( !empty( $_GET ) || is_feed() || ( $super_cache_enabled == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) ) )
240
  $supercacheonly = true;
241
 
242
  if( !$supercacheonly ) {
243
+ if ( !@file_exists( $blog_cache_dir . $cache_filename ) || ( @file_exists( $blog_cache_dir . $cache_filename ) && ( time() - @filemtime( $blog_cache_dir . $cache_filename ) ) > 5 ) ) {
244
+ $fr = @fopen($tmp_wpcache_filename, 'w');
245
+ if (!$fr) {
246
+ $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $cache_path ) . $cache_filename . " -->\n";
247
+ return $buffer;
248
+ }
249
  }
250
  }
251
  if( $super_cache_enabled ) {
258
 
259
  $cache_fname = "{$dir}index.html";
260
  $tmp_cache_filename = $dir . uniqid( mt_rand(), true ) . '.tmp';
261
+ if ( !@file_exists( $cache_fname ) || ( @file_exists( $cache_fname ) && ( time() - @filemtime( $blog_cache_dir . $cache_filename ) ) > 5 ) ) {
262
+ $fr2 = @fopen( $tmp_cache_filename, 'w' );
263
+ if (!$fr2) {
264
+ $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . " -->\n";
265
+ @fclose( $fr );
266
+ @unlink( $tmp_wpcache_filename );
 
 
 
 
 
 
 
 
 
267
  return $buffer;
268
+ } elseif( $cache_compression ) {
269
+ $gz = @fopen( $tmp_cache_filename . ".gz", 'w');
270
+ if (!$gz) {
271
+ $buffer .= "<!-- File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz -->\n";
272
+ @fclose( $fr );
273
+ @unlink( $tmp_wpcache_filename );
274
+ @fclose( $fr2 );
275
+ @unlink( $tmp_cache_filename );
276
+ return $buffer;
277
+ }
278
  }
279
  }
280
  }
344
  @rename( $tmp_cache_filename . '.gz', $cache_fname . '.gz' );
345
  }
346
  }
347
+ //}
348
  wp_cache_writers_exit();
349
  if ( !headers_sent() && isset( $wp_cache_gzip_first ) && 1 == $wp_cache_gzip_first && $wp_cache_gzip_encoding && $gzdata) {
350
  header( 'Content-Encoding: ' . $wp_cache_gzip_encoding );
472
 
473
  function wp_cache_shutdown_callback() {
474
  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;
475
+ global $wp_cache_blog_charset, $wp_cache_request_uri;
476
 
477
+ $wp_cache_meta[ 'uri' ] = $_SERVER["SERVER_NAME"].preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', $wp_cache_request_uri); // To avoid XSS attacks
478
  $wp_cache_meta[ 'blog_id' ] = $blog_id;
479
  $wp_cache_meta[ 'post' ] = wp_cache_post_id();
480
 
511
  $value = "application/rss+xml";
512
  }
513
  } else { // not a feed
514
+ $value = get_option( 'html_type' );
515
+ if( $value == '' )
516
+ $value = 'text/html';
517
  }
518
  $value .= "; charset=\"" . $wp_cache_blog_charset . "\"";
519
 
554
  }
555
 
556
  function wp_cache_get_postid_from_comment($comment_id) {
557
+ global $super_cache_enabled, $wp_cache_request_uri;
558
  $comment = get_comment($comment_id, ARRAY_A);
559
  $postid = $comment['comment_post_ID'];
560
  // Do nothing if comment is not moderated
561
  // http://ocaoimh.ie/2006/12/05/caching-wordpress-with-wp-cache-in-a-spam-filled-world
562
+ if( !preg_match('/wp-admin\//', $wp_cache_request_uri) )
563
  if( $comment['comment_approved'] == 'spam' ) { // changed from 1 to "spam"
564
  return $postid;
565
  } elseif( $comment['comment_approved'] == '0' ) {
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.4.3
7
  Author: Donncha O Caoimh
8
  Author URI: http://ocaoimh.ie/
9
  */
@@ -124,7 +124,7 @@ function wp_cache_manager() {
124
  if( !isset( $cache_rebuild_files ) )
125
  $cache_rebuild_files = 0;
126
 
127
- $valid_nonce = wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache');
128
  /* http://www.netlobo.com/div_hiding.html */
129
  ?>
130
  <script type='text/javascript'>
@@ -254,8 +254,7 @@ jQuery(document).ready(function(){
254
  if( !isset( $wp_cache_mobile_whitelist ) )
255
  wp_cache_replace_line('^ *\$wp_cache_mobile_whitelist', "\$wp_cache_mobile_whitelist = 'Stand Alone/QNws';", $wp_cache_config_file);
256
  if( false == isset( $wp_cache_mobile_browsers ) )
257
- wp_cache_replace_line('^ *\$wp_cache_mobile_browsers', "\$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';", $wp_cache_config_file);
258
- $_POST[ 'wp_cache_status' ] = 'wpcache';
259
  }
260
  wp_cache_replace_line('^ *\$wp_cache_mobile_enabled', "\$wp_cache_mobile_enabled = " . $wp_cache_mobile_enabled . ";", $wp_cache_config_file);
261
  switch( $_POST[ 'wp_cache_status' ] ) {
@@ -293,6 +292,9 @@ jQuery(document).ready(function(){
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
  if( isset( $_POST[ 'wp_cache_not_logged_in' ] ) ) {
298
  if( $wp_cache_not_logged_in == 0 && function_exists( 'prune_super_cache' ) )
@@ -303,7 +305,11 @@ jQuery(document).ready(function(){
303
  }
304
  wp_cache_replace_line('^ *\$wp_cache_not_logged_in', "\$wp_cache_not_logged_in = " . $wp_cache_not_logged_in . ";", $wp_cache_config_file);
305
  }
306
- if( isset( $_POST[ 'cache_compression' ] ) && $_POST[ 'cache_compression' ] != $cache_compression ) {
 
 
 
 
307
  $cache_compression_changed = true;
308
  $cache_compression = intval( $_POST[ 'cache_compression' ] );
309
  wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
@@ -329,8 +335,20 @@ jQuery(document).ready(function(){
329
  <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>
330
  <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>
331
  <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>
332
- <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>
333
- <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>
 
 
 
 
 
 
 
 
 
 
 
 
334
  <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>
335
  <?php
336
  echo "<div class='submit'><input type='submit' " . SUBMITDISABLED . " value='Update Status &raquo;' /></div>";
@@ -346,7 +364,7 @@ jQuery(document).ready(function(){
346
  $missing_mods[ $req ] = $desc;
347
  }
348
  }
349
- if( is_array( $missing_mods ) ) {
350
  echo "<h3>Missing Apache Modules</h3>";
351
  echo "<p>The following Apache modules are missing. The plugin will work in half-on mode without them. In full Supercache mode, your visitors may see corrupted pages or out of date content however.</p>";
352
  echo "<ul>";
@@ -362,8 +380,10 @@ jQuery(document).ready(function(){
362
  <div style='background: #ffc; border: 1px solid #333; margin: 2px; padding: 5px'>
363
  <h3 align='center'>Make WordPress Faster</h3>
364
  <?php if( $wp_cache_hide_donation != 1 ) { ?>
365
- <p><a href="http://ocaoimh.ie/wp-super-cache/?r=wpsc">WP Super Cache</a> makes your blog go faster. That has to be worth $10 or a small gift. Click the "Donate" button below or take a quick peek at my <a href="http://ocaoimh.ie/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy5hbWF6b24uY28udWsvZ3AvcmVnaXN0cnkvMzVaQ0dJVTJBSDROQg==">wishlist</a>.</p>
366
- <p>Thanks!<br />Donncha O Caoimh.<br /></p>
 
 
367
  <div align='center'>
368
  <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
369
  <input type="hidden" name="cmd" value="_s-xclick"/>
@@ -422,6 +442,7 @@ function wsc_mod_rewrite() {
422
  global $super_cache_enabled, $cache_compression, $cache_compression_changed, $valid_nonce, $cache_path;
423
  if( $super_cache_enabled == false )
424
  return;
 
425
  ?>
426
  <fieldset class="options">
427
  <h3>Super Cache Compression</h3>
@@ -439,13 +460,22 @@ function wsc_mod_rewrite() {
439
  wp_nonce_field('wp-cache');
440
  echo "</form>\n";
441
  ?></fieldset>
 
442
 
443
  <a name="modrewrite"></a><fieldset class="options">
444
  <h3>Mod Rewrite Rules</h3><?php
 
 
 
 
 
 
 
445
  $home_path = get_home_path();
446
  $home_root = parse_url(get_bloginfo('url'));
447
  $home_root = trailingslashit($home_root['path']);
448
- $inst_root = str_replace( '//', '/', '/' . trailingslashit( str_replace( $_SERVER[ 'DOCUMENT_ROOT' ], '', str_replace( '\\', '/', WP_CONTENT_DIR ) ) ) );
 
449
  $wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) );
450
  $wprules = str_replace( "RewriteEngine On\n", '', $wprules );
451
  $wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
@@ -458,6 +488,7 @@ function wsc_mod_rewrite() {
458
  $condition_rules[] = "RewriteCond %{REQUEST_METHOD} !=POST";
459
  $condition_rules[] = "RewriteCond %{QUERY_STRING} !.*=.*";
460
  $condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$";
 
461
  $condition_rules = apply_filters( 'supercacherewriteconditions', $condition_rules );
462
 
463
  $rules = "<IfModule mod_rewrite.c>\n";
@@ -467,11 +498,11 @@ function wsc_mod_rewrite() {
467
  $rules .= "AddDefaultCharset {$charset}\n";
468
  $rules .= "CONDITION_RULES";
469
  $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
470
- $rules .= "RewriteCond %{DOCUMENT_ROOT}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz -f\n";
471
  $rules .= "RewriteRule ^(.*) {$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz [L]\n\n";
472
 
473
  $rules .= "CONDITION_RULES";
474
- $rules .= "RewriteCond %{DOCUMENT_ROOT}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html -f\n";
475
  $rules .= "RewriteRule ^(.*) {$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html [L]\n";
476
  $rules .= "</IfModule>\n";
477
  $rules = apply_filters( 'supercacherewriterules', $rules );
@@ -484,7 +515,7 @@ function wsc_mod_rewrite() {
484
  } elseif( !$wprules || $wprules == '' ) {
485
  echo "<h4 style='color: #a00'>Mod Rewrite rules cannot be updated!</h4>";
486
  echo "<p>You must have <strong>BEGIN</strong> and <strong>END</strong> markers in {$home_path}.htaccess for the auto update to work. They look like this and surround the main WordPress mod_rewrite rules:
487
- <blockquote><code><em># BEGIN WordPress</em> RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] <em># END WordPress</em></code></blockquote>
488
  Refresh this page when you have updated your .htaccess file.";
489
  echo "</fieldset></div>";
490
  return;
@@ -802,7 +833,7 @@ function wp_cache_edit_rejected_ua() {
802
  echo '<a name="user-agents"></a><fieldset class="options"><h3>Rejected User Agents</h3>';
803
  echo "<p>Strings in the HTTP 'User Agent' header that prevent WP-Cache from
804
  caching bot, spiders, and crawlers' requests.
805
- Note that cached files are still sent to these request if they already exists.</p>\n";
806
  echo '<form name="wp_edit_rejected_user_agent" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
807
  echo '<textarea name="wp_rejected_user_agent" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
808
  foreach ($cache_rejected_user_agent as $ua) {
@@ -950,9 +981,9 @@ function wp_cache_replace_line($old, $new, $my_file) {
950
  $fd = fopen($my_file, 'w');
951
  $done = false;
952
  foreach($lines as $line) {
953
- if ( $done || !preg_match('/^define|\$|\?>/', $line))
954
  fputs($fd, $line);
955
- else {
956
  fputs($fd, "$new //Added by WP-Cache Manager\n");
957
  fputs($fd, $line);
958
  $done = true;
@@ -1022,9 +1053,9 @@ function wp_cache_verify_config_file() {
1022
  copy($wp_cache_config_file_sample, $wp_cache_config_file);
1023
  $dir = str_replace( str_replace( '\\', '/', WP_CONTENT_DIR ), '', str_replace( '\\', '/', dirname(__FILE__) ) );
1024
  if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
1025
- wp_cache_replace_line('WPCACHEHOME', "define( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/\" );", $wp_cache_config_file);
1026
  } elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
1027
- wp_cache_replace_line('WPCACHEHOME', "define( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/wp-super-cache/\" );", $wp_cache_config_file);
1028
  }
1029
  $new = true;
1030
  }
@@ -1240,8 +1271,9 @@ function wp_cache_files() {
1240
  $last_gc = get_option( "wpsupercache_gc_time" );
1241
  if( $last_gc ) {
1242
  $next_gc = $cache_max_time < 1800 ? $cache_max_time : 600;
1243
- echo "<p><strong>Garbage Collection</strong><br />Last: " . date( "Y-m-d H:i:s", ( $last_gc + ( get_option( 'gmt_offset' ) * 3600 ) ) ) . "<br />";
1244
- echo "Next: " . date( "Y-m-d H:i:s", ( $next_gc + $last_gc + ( get_option( 'gmt_offset' ) * 3600 ) ) ) . "</p>";
 
1245
  }
1246
 
1247
  echo "<p>Expired files are files older than $cache_max_time seconds. They are still used by the plugin and are deleted periodically.</p>";
@@ -1291,7 +1323,10 @@ function wpsc_dirsize($directory, $sizes) {
1291
  } else {
1292
  $sizes[ 'cached' ]+=1;
1293
  }
1294
- $sizes[ 'fsize' ] += @filesize( $directory );
 
 
 
1295
  }
1296
  }
1297
  return $sizes;
@@ -1437,6 +1472,11 @@ function wp_cache_plugin_actions( $links, $file ) {
1437
  }
1438
  add_filter( 'plugin_action_links', 'wp_cache_plugin_actions', 10, 2 );
1439
 
 
 
 
 
 
1440
  function wp_cache_admin_notice() {
1441
  global $cache_enabled;
1442
  if( substr( $_SERVER["PHP_SELF"], -11 ) == 'plugins.php' && !$cache_enabled && function_exists( "admin_url" ) )
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.5
7
  Author: Donncha O Caoimh
8
  Author URI: http://ocaoimh.ie/
9
  */
124
  if( !isset( $cache_rebuild_files ) )
125
  $cache_rebuild_files = 0;
126
 
127
+ $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
128
  /* http://www.netlobo.com/div_hiding.html */
129
  ?>
130
  <script type='text/javascript'>
254
  if( !isset( $wp_cache_mobile_whitelist ) )
255
  wp_cache_replace_line('^ *\$wp_cache_mobile_whitelist', "\$wp_cache_mobile_whitelist = 'Stand Alone/QNws';", $wp_cache_config_file);
256
  if( false == isset( $wp_cache_mobile_browsers ) )
257
+ wp_cache_replace_line('^ *\$wp_cache_mobile_browsers', "\$wp_cache_mobile_browsers = 'Android, 2.0 MMP, 240x320, AvantGo, BlackBerry, Blazer, Cellphone, Danger, DoCoMo, Elaine/3.0, EudoraWeb, hiptop, IEMobile, iPhone, iPod, KYOCERA/WX310K, LG/U990, MIDP-2.0, MMEF20, MOT-V, NetFront, Newt, Nintendo Wii, Nitro, Nokia, Opera Mini, Palm, Playstation Portable, portalmmm, Proxinet, ProxiNet, SHARP-TQ-GX10, Small, SonyEricsson, Symbian OS, SymbianOS, TS21i-10, UP.Browser, UP.Link, Windows CE, WinWAP';", $wp_cache_config_file);
 
258
  }
259
  wp_cache_replace_line('^ *\$wp_cache_mobile_enabled', "\$wp_cache_mobile_enabled = " . $wp_cache_mobile_enabled . ";", $wp_cache_config_file);
260
  switch( $_POST[ 'wp_cache_status' ] ) {
292
  } else {
293
  $wp_cache_mutex_disabled = 1;
294
  }
295
+ if( defined( 'WPSC_DISABLE_LOCKING' ) ) {
296
+ $wp_cache_mutex_disabled = 1;
297
+ }
298
  wp_cache_replace_line('^ *\$wp_cache_mutex_disabled', "\$wp_cache_mutex_disabled = " . $wp_cache_mutex_disabled . ";", $wp_cache_config_file);
299
  if( isset( $_POST[ 'wp_cache_not_logged_in' ] ) ) {
300
  if( $wp_cache_not_logged_in == 0 && function_exists( 'prune_super_cache' ) )
305
  }
306
  wp_cache_replace_line('^ *\$wp_cache_not_logged_in', "\$wp_cache_not_logged_in = " . $wp_cache_not_logged_in . ";", $wp_cache_config_file);
307
  }
308
+ if( defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
309
+ $cache_compression_changed = false;
310
+ $cache_compression = 0;
311
+ wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
312
+ } elseif( isset( $_POST[ 'cache_compression' ] ) && $_POST[ 'cache_compression' ] != $cache_compression ) {
313
  $cache_compression_changed = true;
314
  $cache_compression = intval( $_POST[ 'cache_compression' ] );
315
  wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
335
  <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>
336
  <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>
337
  <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>
338
+ <?php if( false == defined( 'WPSC_DISABLE_LOCKING' ) ) { ?>
339
+ <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>
340
+ <?php } ?>
341
+ <p><label><input type='checkbox' name='wp_cache_mobile_enabled' <?php if( $wp_cache_mobile_enabled ) echo "checked"; ?> value='1'> Mobile device support.</label>
342
+ <?php
343
+ $home_path = trailingslashit( get_home_path() );
344
+ if ( false === strpos( implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) ), 'SHARP-TQ-GX10' ) ) { // we don't have the rewrite rules
345
+ ?>
346
+ <blockquote><p>Mobile support requires extra rules in your .htaccess file, or you can set the plugin to half-on mode. Here's your options (in order of difficulty):
347
+ <ol><li> 1. Set the plugin to half on mode and enable mobile support.</li>
348
+ <li> 2. Delete the plugin mod_rewrite rules in <?php echo $home_path; ?>.htaccess enclosed by <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code> and let the plugin regenerate them by reloading this page.</li>
349
+ <li> 3. Add the rules yourself. Edit <?php echo $home_path; ?>.htaccess and find the block of code enclosed by the lines <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code>. There are two sections that look very similar. Just below the line <code>%{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$</code> add this line: (do it twice, once for each section)</p>
350
+ <div style='border: 1px solid #333; width:400px; overflow: scroll'><pre>RewriteCond %{HTTP_user_agent} !^.*(Android|2.0\ MMP|240x320|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|hiptop|IEMobile|iPhone|iPod|KYOCERA/WX310K|LG/U990|MIDP-2.0|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|Playstation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|Windows\ CE|WinWAP).*</pre></div></li></ol></blockquote>
351
+ <?php } ?>
352
  <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>
353
  <?php
354
  echo "<div class='submit'><input type='submit' " . SUBMITDISABLED . " value='Update Status &raquo;' /></div>";
364
  $missing_mods[ $req ] = $desc;
365
  }
366
  }
367
+ if( isset( $missing_mods) && is_array( $missing_mods ) ) {
368
  echo "<h3>Missing Apache Modules</h3>";
369
  echo "<p>The following Apache modules are missing. The plugin will work in half-on mode without them. In full Supercache mode, your visitors may see corrupted pages or out of date content however.</p>";
370
  echo "<ul>";
380
  <div style='background: #ffc; border: 1px solid #333; margin: 2px; padding: 5px'>
381
  <h3 align='center'>Make WordPress Faster</h3>
382
  <?php if( $wp_cache_hide_donation != 1 ) { ?>
383
+ <p><a href="http://ocaoimh.ie/wp-super-cache/?r=wpsc">WP Super Cache</a> really makes your blog go faster. Make it go faster<sup>*</sup> by buying me an <a href="https://www.amazon.co.uk/gp/gc/order-email/ref=g_gc-dp_lp_email">Amazon gift card</a>! Make it out to "donncha@ocaoimh.ie". A £10 card would be nice but it's up to you how much you think this plugin is worth to you.</p>
384
+ <p>If Amazon isn't your thing, there's also PayPal. Click the "Donate" button below or take a quick peek at my <a href="http://ocaoimh.ie/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3d3dy5hbWF6b24uY28udWsvZ3AvcmVnaXN0cnkvMzVaQ0dJVTJBSDROQg==">wishlist</a>.</p>
385
+ <p>Thanks in advance!<br />Donncha<br />
386
+ <small>* Ok, it won't go any faster but you'll make this plugin author very happy!</small></p>
387
  <div align='center'>
388
  <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
389
  <input type="hidden" name="cmd" value="_s-xclick"/>
442
  global $super_cache_enabled, $cache_compression, $cache_compression_changed, $valid_nonce, $cache_path;
443
  if( $super_cache_enabled == false )
444
  return;
445
+ if( false == defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
446
  ?>
447
  <fieldset class="options">
448
  <h3>Super Cache Compression</h3>
460
  wp_nonce_field('wp-cache');
461
  echo "</form>\n";
462
  ?></fieldset>
463
+ <?php } ?>
464
 
465
  <a name="modrewrite"></a><fieldset class="options">
466
  <h3>Mod Rewrite Rules</h3><?php
467
+ if ( isset( $_SERVER[ "PHP_DOCUMENT_ROOT" ] ) ) {
468
+ $document_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
469
+ $apache_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
470
+ } else {
471
+ $document_root = $_SERVER[ "DOCUMENT_ROOT" ];
472
+ $apache_root = '%{DOCUMENT_ROOT}';
473
+ }
474
  $home_path = get_home_path();
475
  $home_root = parse_url(get_bloginfo('url'));
476
  $home_root = trailingslashit($home_root['path']);
477
+ $home_root = isset( $home_root['path'] ) ? trailingslashit( $home_root['path'] ) : '/';
478
+ $inst_root = str_replace( '//', '/', '/' . trailingslashit( str_replace( $document_root, '', str_replace( '\\', '/', WP_CONTENT_DIR ) ) ) );
479
  $wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) );
480
  $wprules = str_replace( "RewriteEngine On\n", '', $wprules );
481
  $wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
488
  $condition_rules[] = "RewriteCond %{REQUEST_METHOD} !=POST";
489
  $condition_rules[] = "RewriteCond %{QUERY_STRING} !.*=.*";
490
  $condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$";
491
+ $condition_rules[] = "RewriteCond %{HTTP_user_agent} !^.*(Android|2.0\\ MMP|240x320|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|hiptop|IEMobile|iPhone|iPod|KYOCERA/WX310K|LG/U990|MIDP-2.0|MMEF20|MOT-V|NetFront|Newt|Nintendo\\ Wii|Nitro|Nokia|Opera\\ Mini|Palm|Playstation\\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|Small|SonyEricsson|Symbian\\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|Windows\\ CE|WinWAP).*";
492
  $condition_rules = apply_filters( 'supercacherewriteconditions', $condition_rules );
493
 
494
  $rules = "<IfModule mod_rewrite.c>\n";
498
  $rules .= "AddDefaultCharset {$charset}\n";
499
  $rules .= "CONDITION_RULES";
500
  $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
501
+ $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz -f\n";
502
  $rules .= "RewriteRule ^(.*) {$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html.gz [L]\n\n";
503
 
504
  $rules .= "CONDITION_RULES";
505
+ $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html -f\n";
506
  $rules .= "RewriteRule ^(.*) {$inst_root}cache/supercache/%{HTTP_HOST}{$home_root}$1/index.html [L]\n";
507
  $rules .= "</IfModule>\n";
508
  $rules = apply_filters( 'supercacherewriterules', $rules );
515
  } elseif( !$wprules || $wprules == '' ) {
516
  echo "<h4 style='color: #a00'>Mod Rewrite rules cannot be updated!</h4>";
517
  echo "<p>You must have <strong>BEGIN</strong> and <strong>END</strong> markers in {$home_path}.htaccess for the auto update to work. They look like this and surround the main WordPress mod_rewrite rules:
518
+ <blockquote><pre><em># BEGIN WordPress</em>\n RewriteCond %{REQUEST_FILENAME} !-f\n RewriteCond %{REQUEST_FILENAME} !-d\n RewriteRule . /index.php [L]\n <em># END WordPress</em></pre></blockquote>
519
  Refresh this page when you have updated your .htaccess file.";
520
  echo "</fieldset></div>";
521
  return;
833
  echo '<a name="user-agents"></a><fieldset class="options"><h3>Rejected User Agents</h3>';
834
  echo "<p>Strings in the HTTP 'User Agent' header that prevent WP-Cache from
835
  caching bot, spiders, and crawlers' requests.
836
+ Note that super cached files are still sent to these agents if they already exists.</p>\n";
837
  echo '<form name="wp_edit_rejected_user_agent" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
838
  echo '<textarea name="wp_rejected_user_agent" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
839
  foreach ($cache_rejected_user_agent as $ua) {
981
  $fd = fopen($my_file, 'w');
982
  $done = false;
983
  foreach($lines as $line) {
984
+ if ( $done || !preg_match('/^(if\ \(\ \!\ )?define|\$|\?>/', $line) ) {
985
  fputs($fd, $line);
986
+ } else {
987
  fputs($fd, "$new //Added by WP-Cache Manager\n");
988
  fputs($fd, $line);
989
  $done = true;
1053
  copy($wp_cache_config_file_sample, $wp_cache_config_file);
1054
  $dir = str_replace( str_replace( '\\', '/', WP_CONTENT_DIR ), '', str_replace( '\\', '/', dirname(__FILE__) ) );
1055
  if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
1056
+ wp_cache_replace_line('define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/\" );", $wp_cache_config_file);
1057
  } elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
1058
+ wp_cache_replace_line('define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/wp-super-cache/\" );", $wp_cache_config_file);
1059
  }
1060
  $new = true;
1061
  }
1271
  $last_gc = get_option( "wpsupercache_gc_time" );
1272
  if( $last_gc ) {
1273
  $next_gc = $cache_max_time < 1800 ? $cache_max_time : 600;
1274
+ $next_gc_mins = ( time() - $last_gc );
1275
+ echo "<p><strong>Garbage Collection</strong><br />Last GC was <strong>" . date( 'i:s', $next_gc_mins ) . "</strong> minutes ago<br />";
1276
+ echo "Next GC in <strong>" . date( 'i:s', $next_gc - $next_gc_mins ) . "</strong> minutes</p>";
1277
  }
1278
 
1279
  echo "<p>Expired files are files older than $cache_max_time seconds. They are still used by the plugin and are deleted periodically.</p>";
1323
  } else {
1324
  $sizes[ 'cached' ]+=1;
1325
  }
1326
+ if ( ! isset( $sizes[ 'fsize' ] ) )
1327
+ $sizes[ 'fsize' ] = @filesize( $directory );
1328
+ else
1329
+ $sizes[ 'fsize' ] += @filesize( $directory );
1330
  }
1331
  }
1332
  return $sizes;
1472
  }
1473
  add_filter( 'plugin_action_links', 'wp_cache_plugin_actions', 10, 2 );
1474
 
1475
+ function wpsc_author_url( $url ) {
1476
+ return clean_url( $url );
1477
+ }
1478
+ add_filter( 'get_comment_author_url' , 'wpsc_author_url' );
1479
+
1480
  function wp_cache_admin_notice() {
1481
  global $cache_enabled;
1482
  if( substr( $_SERVER["PHP_SELF"], -11 ) == 'plugins.php' && !$cache_enabled && function_exists( "admin_url" ) )