WP Super Cache - Version 1.4.5

Version Description

Security and bugfix release fixing an XSS bug in the settings page, hide cache files, and prevent PHP Object Injection in meta files.

=

Download this release

Release Info

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

Code changes from version 1.4.4 to 1.4.5

Changelog.txt CHANGED
@@ -1,3 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  2015-04-04 12:13 donncha
2
 
3
  * readme.txt: Updated changelog
1
+ 2015-09-25 10:55 donncha
2
+
3
+ * readme.txt, wp-cache.php: Bump version to release 1.4.5 and add
4
+ changelog
5
+
6
+ 2015-09-24 15:37 donncha
7
+
8
+ * wp-cache-base.php, wp-cache-phase1.php, wp-cache-phase2.php,
9
+ wp-cache.php: * Add index.html files and "-index" directives to
10
+ stop indexing of directories
11
+ * Sanitise input on settings page
12
+ * MD5 the cookie, use JSON to encode meta files, and rename them
13
+ to .php
14
+
15
+ 2015-09-24 11:37 donncha
16
+
17
+ * readme.txt: Changed homepage link and ocaoimh.ie to z9.io
18
+
19
+ 2015-09-24 11:33 donncha
20
+
21
+ * readme.txt: Minor update to the description of cache rebuild
22
+ feature.
23
+
24
+ 2015-09-24 10:39 donncha
25
+
26
+ * wp-cache-phase2.php: Reduce "needs rebuild" time to 10 seconds,
27
+ so those pages refresh faster.
28
+
29
+ 2015-08-28 16:28 donncha
30
+
31
+ * wp-cache-phase1.php: Because sometimes your editing in HTTPS
32
+ while your site is on HTTP. Thanks kraftbj
33
+
34
+ 2015-08-25 21:42 kraftbj
35
+
36
+ * wp-cache-phase2.php: Swap post_permalink with get_permalink. Both
37
+ are exactly the same and old enough to not impact any users.
38
+ post_permalink slated for deprecation in 4.4.
39
+
40
+ 2015-08-10 14:06 donncha
41
+
42
+ * wp-cache-phase2.php: Avoid PHP warnings, props @daneodekirk
43
+
44
+ 2015-08-10 13:25 donncha
45
+
46
+ * wp-cache.php: Use $wpdb->blogid rather than get_current_blog_id
47
+ as the former returns 0 on single site installs. Props
48
+ @daneodekirk
49
+
50
+ 2015-07-30 10:13 donncha
51
+
52
+ * Changelog.txt, readme.txt: Updated changelog
53
+
54
+ 2015-07-29 13:08 donncha
55
+
56
+ * wp-cache-phase2.php: Remove this function call as it's not
57
+ defined. Ref:
58
+ https://github.com/Automattic/wp-super-cache/commit/4f3229009e5c6c8487dd883910ea076a8e3b7e26
59
+
60
+ 2015-07-27 16:36 kraftbj
61
+
62
+ * wp-cache.php: Don't flush settings for expiry time and garbage
63
+ collection. See
64
+ https://github.com/Automattic/wp-super-cache/pull/49
65
+
66
+ 2015-07-27 16:28 donncha
67
+
68
+ * wp-cache-base.php: Remove CacheMeta class as it's not used any
69
+ more and caused APC errors. Ref:
70
+ https://github.com/Automattic/wp-super-cache/pull/21
71
+
72
+ 2015-07-24 15:21 kraftbj
73
+
74
+ * wp-cache.php: Check if listfile isset to prevent PHP warning.
75
+
76
+ 2015-07-23 13:56 donncha
77
+
78
+ * wp-cache.php: Remember the settings on the advanced settings page
79
+ when submitting the easy settings form. Thanks Jeremy Herve for
80
+ the bug report!
81
+
82
+ 2015-07-22 15:52 donncha
83
+
84
+ * Changelog.txt, readme.txt: Updated changelog
85
+
86
+ 2015-07-22 11:25 donncha
87
+
88
+ * wp-cache-phase2.php: Fixed typo in debug log entry
89
+
90
+ 2015-07-15 11:56 donncha
91
+
92
+ * wp-cache.php: * Added uninstall function as well as deactivate
93
+ function. The deactivate function does not delete the config file
94
+ but it does disable caching because scheduled jobs must be
95
+ enabled in the settings page when the config file is used on
96
+ activation again.
97
+ * Fixed a bug where deactivating the plugin without visiting the
98
+ settings page causes a fatal error so the plugin can't be
99
+ deactivated
100
+
101
+ 2015-07-02 14:19 donncha
102
+
103
+ * wp-cache-phase2.php: Minor changes to debugging
104
+
105
+ 2015-07-02 13:58 donncha
106
+
107
+ * wp-cache-phase2.php: * prune_super_cache: exit immediately if the
108
+ file to be deleted doesn't exist
109
+ * Add extra debugging
110
+
111
+ 2015-07-02 12:10 donncha
112
+
113
+ * wp-cache-phase2.php: Remove https from the home url as well
114
+
115
+ 2015-07-01 16:37 donncha
116
+
117
+ * wp-cache-phase2.php: As so many checks for "should we cache this
118
+ page?" were put to the end of page generation the rebuild system
119
+ was broken. This fixes it by deleting the rebuild files created
120
+ earlier if the current page isn't to be cached (and thus creating
121
+ new cache files)
122
+
123
+ 2015-07-01 15:46 donncha
124
+
125
+ * wp-cache-phase1.php: Always make sure supercachedirs have
126
+ trailing slashes
127
+
128
+ 2015-07-01 15:30 donncha
129
+
130
+ * wp-cache-phase1.php: Cache the output of
131
+ wp_cache_get_cookies_values() for repeat calls
132
+
133
+ 2015-07-01 14:59 donncha
134
+
135
+ * wp-cache-phase1.php: Use the pid to help logging on busy servers
136
+
137
+ 2015-07-01 14:51 donncha
138
+
139
+ * plugins/domain-mapping.php: Suercache urls end in slashes
140
+
141
+ 2015-06-23 15:32 kraftbj
142
+
143
+ * wp-cache-phase1.php: Check for If-Modified-Since before using it
144
+ as it is not always defined.
145
+
146
+ 2015-06-03 02:36 kraftbj
147
+
148
+ * advanced-cache.php: Do not display broken messages for XMLRPC,
149
+ REST, AJAX requests.
150
+
151
+ 2015-05-15 14:12 kraftbj
152
+
153
+ * wp-cache-phase2.php, wp-cache.php: Fix improper site_url usage
154
+ * Update site_url to home_url in another e-mail subject
155
+ * Use admin_url instead of constructing URL from site_url
156
+
157
+ 2015-05-15 14:08 kraftbj
158
+
159
+ * wp-cache.php: Use home_url in Preload Cron e-mails.
160
+
161
+ 2015-05-15 11:13 donncha
162
+
163
+ * wp-cache-phase1.php, wp-cache-phase2.php: Revert 1149165 as it's
164
+ not needed any more.
165
+
166
+ 2015-05-15 11:02 donncha
167
+
168
+ * readme.txt: Bump the tested to version number to 4.2.2
169
+
170
+ 2015-05-13 21:01 kraftbj
171
+
172
+ * wp-cache.php: Improve the 1&1 hosting workaround to reduce false
173
+ positives.
174
+
175
+ 2015-05-01 13:53 donncha
176
+
177
+ * wp-cache.php: Check if it's an array to avoid PHP warning
178
+
179
+ 2015-05-01 13:51 donncha
180
+
181
+ * wp-cache-phase2.php: Added some extra debugging
182
+
183
+ 2015-04-29 16:55 kraftbj
184
+
185
+ * readme.txt: Condense changelog to keep it nice and short :)
186
+
187
+ 2015-04-29 15:58 kraftbj
188
+
189
+ * readme.txt: Update changelog to keep pace with trunk.
190
+
191
+ 2015-04-29 15:45 donncha
192
+
193
+ * wp-cache-phase1.php, wp-cache-phase2.php: Check if mb_strlen()
194
+ exists before WordPress loads so it doesn't use the limited
195
+ mb_strlen compat function in WordPress 4.2. Ref:
196
+ https://wordpress.org/support/topic/421-initial-blank-page-load?replies=11
197
+
198
+ 2015-04-28 15:53 kraftbj
199
+
200
+ * readme.txt: Add previous commits to readme.txt as a running
201
+ changelog to make it easier to compile for next release.
202
+
203
+ 2015-04-28 15:24 kraftbj
204
+
205
+ * wp-cache.php: Preload Cron E-mail Updates
206
+
207
+ 2015-04-28 15:17 kraftbj
208
+
209
+ * wp-cache.php: Preload only public post types. See
210
+ https://github.com/Automattic/wp-super-cache/pull/18
211
+
212
+ 2015-04-21 18:22 kraftbj
213
+
214
+ * readme.txt: Tested to tag bump to 4.2
215
+
216
+ 2015-04-07 16:00 donncha
217
+
218
+ * wp-cache-phase2.php: Don't disable supercache caching on CRON
219
+ requests. Fixes problems clearing front page cache on scheduled
220
+ posts
221
+
222
+ 2015-04-04 22:57 donncha
223
+
224
+ * wp-cache-phase1.php: Fix the log_message, finally. Props
225
+ webaware.
226
+
227
+ 2015-04-04 12:17 donncha
228
+
229
+ * Changelog.txt: Updated changelog
230
+
231
  2015-04-04 12:13 donncha
232
 
233
  * readme.txt: Updated changelog
advanced-cache.php CHANGED
@@ -5,8 +5,14 @@ function wpcache_broken_message() {
5
  if ( isset( $wp_cache_config_file ) == false )
6
  return '';
7
 
8
- if ( false == strpos( $_SERVER[ 'REQUEST_URI' ], 'wp-admin' ) )
 
 
 
 
 
9
  echo "<!-- WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory. -->";
 
10
  }
11
 
12
  if ( false == defined( 'WPCACHEHOME' ) ) {
5
  if ( isset( $wp_cache_config_file ) == false )
6
  return '';
7
 
8
+ $doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
9
+ $xmlrpc_request = defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST;
10
+ $rest_request = defined( 'REST_REQUEST' ) && REST_REQUEST;
11
+
12
+ $skip_output = ( $doing_ajax || $xmlrpc_request || $rest_request );
13
+ if ( false == strpos( $_SERVER[ 'REQUEST_URI' ], 'wp-admin' ) && !$skip_output ) {
14
  echo "<!-- WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory. -->";
15
+ }
16
  }
17
 
18
  if ( false == defined( 'WPCACHEHOME' ) ) {
plugins/domain-mapping.php CHANGED
@@ -41,7 +41,7 @@ function domain_mapping_supercachedir( $dir ) {
41
 
42
  $protocol = ( isset( $_SERVER['HTTPS' ] ) && 'on' == strtolower( $_SERVER['HTTPS' ] ) ) ? 'https://' : 'http://';
43
  $siteurl = str_replace( $protocol, '', $siteurl );
44
- return $cache_path . 'supercache/' . $siteurl;
45
  }
46
 
47
  function domain_mapping_actions() {
41
 
42
  $protocol = ( isset( $_SERVER['HTTPS' ] ) && 'on' == strtolower( $_SERVER['HTTPS' ] ) ) ? 'https://' : 'http://';
43
  $siteurl = str_replace( $protocol, '', $siteurl );
44
+ return trailingslashit( $cache_path . 'supercache/' . $siteurl );
45
  }
46
 
47
  function domain_mapping_actions() {
readme.txt CHANGED
@@ -1,8 +1,8 @@
1
  === WP Super Cache ===
2
- Contributors: donncha, automattic
3
  Tags: performance,caching,wp-cache,wp-super-cache,cache
4
- Tested up to: 4.2.2
5
- Stable tag: 1.4.4
6
  Requires at least: 3.0
7
 
8
  A very fast caching engine for WordPress that produces static html files.
@@ -46,7 +46,7 @@ If you are not using legacy mode caching consider deleting the contents of the "
46
  Likewise, preload as many posts as you can and enable "Preload Mode". Garbage collection will still occur but it won't affect the preloaded files. If you don't care about sidebar widgets updating often set the preload interval to 2880 minutes (2 days) so all your posts aren't recached very often. When the preload occurs the cache files for the post being refreshed is deleted and then regenerated. Afterwards a garbage collection of all old files is performed to clean out stale cache files.
47
  With preloading on cached files will still be deleted when posts are made or edited or comments made.
48
 
49
- See the [WP Super Cache homepage](http://ocaoimh.ie/wp-super-cache/) for further information. [Developer documentation](http://ocaoimh.ie/wp-super-cache-developers/) is also available for those who need to interact with the cache or write plugins.
50
 
51
  There's a [GIT repository](https://github.com/Automattic/wp-super-cache) too if you want to contribute a patch.
52
 
@@ -58,10 +58,26 @@ The cache directory, usually wp-content/cache/ is only for temporary files. Do n
58
 
59
  == Upgrade Notice ==
60
 
61
- = 1.4.4 =
62
- Security release fixing an XSS bug in the settings page, and fix for fatal error in output handler.
63
 
64
  == Changelog ==
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  = 1.4.4 =
66
  * Fixed fatal error in output handler if GET parameters present in query. Props webaware.
67
  * Fixed debug log. It wasn't logging the right message.
@@ -409,7 +425,7 @@ There are 2 ways of doing this. You can use Javascript to draw the part of the p
409
 
410
  WP Super Cache 1.4 introduced a cacheaction filter called wpsc_cachedata. The cached page to be displayed goes through this filter and allows modification of the page. If the page contains a placeholder tag the filter can be used to replace that tag with your dynamically generated html.
411
  The function that hooks on to the wpsc_cachedata filter should be put in a file in the WP Super Cache plugins folder unless you use the late_init feature. An example plugin is included. Edit [dynamic-cache-test.php](http://svn.wp-plugins.org/wp-super-cache/trunk/plugins/dynamic-cache-test.php) to see the example code.
412
- There are two example functions there. There's a simple function that replaces a string (or tag) you define when the cached page is served. The other example function uses an output buffer to generate the dynamic content. Due to a limitation in how PHP works the output buffer code MUST run before the wpsc_cachedata filter is hit, at least for when a page is cached. It doesn't matter when serving cached pages. See [this post](http://ocaoimh.ie/y/6j) for a more technical and longer explanation.
413
  To execute WordPress functions you must enable the 'Late init' feature on the advanced settings page.
414
 
415
  = How do I use WordPress functions in cached dynamic pages? =
@@ -427,7 +443,7 @@ WordPress deletes the plugin folder when it updates a plugin. This is the same w
427
 
428
  = What does the Cache Rebuild feature do? =
429
 
430
- When a visitor leaves a comment the cached file for that page is deleted and the next visitor recreates the cached page. A page takes time to load so what happens if it receives 100 visitors during this time? There won't be a cached page so WordPress will serve a fresh page for each user and the plugin will try to create a cached page for each of those 100 visitors causing a huge load on your server. This feature stops this happening. The cached page is not cleared when a comment is left. It is marked for rebuilding instead. The next visitor will regenerate the cached page while the old page is served to the other 99 visitors. The page is eventually loaded by the first visitor and the cached page updated. See [this post](http://ocaoimh.ie/2009/01/23/wp-super-cache-089/) for more.
431
 
432
  = Why doesn't the plugin cache requests by search engine bots by default? =
433
 
@@ -452,7 +468,7 @@ Try the Cacheability Engine at http://www.ircache.net/cgi-bin/cacheability.py or
452
 
453
  = How should I best use the utm_source tracking tools in Google Analytics with this plugin? =
454
 
455
- That tracking adds a query string to each url linked from various sources like Twitter and feedreaders. Unfortunately it stops pages being supercached. See [Joost's comment here](http://ocaoimh.ie/remove-unused-utmsource-urls/#comment-672813) for how to turn it into an anchor tag which can be supercached.
456
 
457
  = The plugin complains that wp-content is writable! htdocs is writable! =
458
 
@@ -556,13 +572,13 @@ There is one regular WordPress filter too. Use the "do_createsupercache" filter
556
  to customize the checks made before caching. The filter accepts one parameter.
557
  The output of WP-Cache's wp_cache_get_cookies_values() function.
558
 
559
- See plugins/searchengine.php as an example I use for my [No Adverts for Friends](http://ocaoimh.ie/no-adverts-for-friends/) plugin.
560
 
561
  == Links ==
562
  [WP Widget Cache](http://wordpress.org/plugins/wp-widget-cache/) is another caching plugin for WordPress. This plugin caches the output of widgets and may significantly speed up dynamic page generation times.
563
 
564
  == Updates ==
565
- Updates to the plugin will be posted here, to [Holy Shmoly!](http://ocaoimh.ie/) and the [WP Super Cache homepage](http://ocaoimh.ie/wp-super-cache/) will always link to the newest version.
566
 
567
  == Thanks ==
568
  I would sincerely like to thank [John Pozadzides](http://onemansblog.com/) for giving me the idea for this, for writing the "How it works" section and for testing the plugin through 2 front page appearances on digg.com
1
  === WP Super Cache ===
2
+ Contributors: donncha, automattic, kraftbj
3
  Tags: performance,caching,wp-cache,wp-super-cache,cache
4
+ Tested up to: 4.3.1
5
+ Stable tag: 1.4.5
6
  Requires at least: 3.0
7
 
8
  A very fast caching engine for WordPress that produces static html files.
46
  Likewise, preload as many posts as you can and enable "Preload Mode". Garbage collection will still occur but it won't affect the preloaded files. If you don't care about sidebar widgets updating often set the preload interval to 2880 minutes (2 days) so all your posts aren't recached very often. When the preload occurs the cache files for the post being refreshed is deleted and then regenerated. Afterwards a garbage collection of all old files is performed to clean out stale cache files.
47
  With preloading on cached files will still be deleted when posts are made or edited or comments made.
48
 
49
+ See the [WP Super Cache homepage](https://wordpress.org/plugins/wp-super-cache/) for further information. [Developer documentation](http://z9.io/wp-super-cache-developers/) is also available for those who need to interact with the cache or write plugins.
50
 
51
  There's a [GIT repository](https://github.com/Automattic/wp-super-cache) too if you want to contribute a patch.
52
 
58
 
59
  == Upgrade Notice ==
60
 
61
+ = 1.4.5 =
62
+ Security and bugfix release fixing an XSS bug in the settings page, hide cache files, and prevent PHP Object Injection in meta files.
63
 
64
  == Changelog ==
65
+
66
+ = 1.4.5 =
67
+ * Enhancement: Only preload public post types. Props webaware.
68
+ * Added an uninstall function that deletes the config file. Deactivate function doesn't delete it any more.
69
+ * Possible to deactivate the plugin without visiting the settings page now.
70
+ * Fixed the cache rebuild system. Rebuild files now survive longer than the request that generate them.
71
+ * Minor optimisations: prune_super_cache() exits immediately if the file doesn't exist. The output of wp_cache_get_cookies_values() is now cached.
72
+ * Added PHP pid to the debug log to aid debugging.
73
+ * Various small bug fixes.
74
+ * Fixed reset of expiry time and GC settings when updating advanced settings.
75
+ * Removed CacheMeta class to avoid APC errors. It's not used any more.
76
+ * Fixed reset of advanced settings when using "easy" settings page.
77
+ * Fixed XSS in settings page.
78
+ * Hide cache files when servers display directory indexes.
79
+ * Prevent PHP object injection through use of serialize().
80
+
81
  = 1.4.4 =
82
  * Fixed fatal error in output handler if GET parameters present in query. Props webaware.
83
  * Fixed debug log. It wasn't logging the right message.
425
 
426
  WP Super Cache 1.4 introduced a cacheaction filter called wpsc_cachedata. The cached page to be displayed goes through this filter and allows modification of the page. If the page contains a placeholder tag the filter can be used to replace that tag with your dynamically generated html.
427
  The function that hooks on to the wpsc_cachedata filter should be put in a file in the WP Super Cache plugins folder unless you use the late_init feature. An example plugin is included. Edit [dynamic-cache-test.php](http://svn.wp-plugins.org/wp-super-cache/trunk/plugins/dynamic-cache-test.php) to see the example code.
428
+ There are two example functions there. There's a simple function that replaces a string (or tag) you define when the cached page is served. The other example function uses an output buffer to generate the dynamic content. Due to a limitation in how PHP works the output buffer code MUST run before the wpsc_cachedata filter is hit, at least for when a page is cached. It doesn't matter when serving cached pages. See [this post](http://z9.io/y/6j) for a more technical and longer explanation.
429
  To execute WordPress functions you must enable the 'Late init' feature on the advanced settings page.
430
 
431
  = How do I use WordPress functions in cached dynamic pages? =
443
 
444
  = What does the Cache Rebuild feature do? =
445
 
446
+ When a visitor leaves a comment the cached file for that page is deleted and the next visitor recreates the cached page. A page takes time to load so what happens if it receives 100 visitors during this time? There won't be a cached page so WordPress will serve a fresh page for each user and the plugin will try to create a cached page for each of those 100 visitors causing a huge load on your server. This feature stops this happening. The cached page is not cleared when a comment is left. It is marked for rebuilding instead. The next visitor within the next 10 seconds will regenerate the cached page while the old page is served to the other 99 visitors. The page is eventually loaded by the first visitor and the cached page updated. See [this post](http://z9.io/2009/01/23/wp-super-cache-089/) for more.
447
 
448
  = Why doesn't the plugin cache requests by search engine bots by default? =
449
 
468
 
469
  = How should I best use the utm_source tracking tools in Google Analytics with this plugin? =
470
 
471
+ That tracking adds a query string to each url linked from various sources like Twitter and feedreaders. Unfortunately it stops pages being supercached. See [Joost's comment here](http://z9.io/remove-unused-utmsource-urls/#comment-672813) for how to turn it into an anchor tag which can be supercached.
472
 
473
  = The plugin complains that wp-content is writable! htdocs is writable! =
474
 
572
  to customize the checks made before caching. The filter accepts one parameter.
573
  The output of WP-Cache's wp_cache_get_cookies_values() function.
574
 
575
+ See plugins/searchengine.php as an example I use for my [No Adverts for Friends](http://z9.io/no-adverts-for-friends/) plugin.
576
 
577
  == Links ==
578
  [WP Widget Cache](http://wordpress.org/plugins/wp-widget-cache/) is another caching plugin for WordPress. This plugin caches the output of widgets and may significantly speed up dynamic page generation times.
579
 
580
  == Updates ==
581
+ Updates to the plugin will be posted here, to [Holy Shmoly!](http://z9.io/) and the [WP Super Cache homepage](https://wordpress.org/plugins/wp-super-cache/) will always link to the newest version.
582
 
583
  == Thanks ==
584
  I would sincerely like to thank [John Pozadzides](http://onemansblog.com/) for giving me the idea for this, for writing the "How it works" section and for testing the plugin through 2 front page appearances on digg.com
wp-cache-base.php CHANGED
@@ -1,15 +1,6 @@
1
  <?php
2
  $known_headers = array("Last-Modified", "Expires", "Content-Type", "Content-type", "X-Pingback", "ETag", "Cache-Control", "Pragma");
3
 
4
- if (!class_exists('CacheMeta')) {
5
- class CacheMeta {
6
- var $dynamic = false;
7
- var $headers = array();
8
- var $uri = '';
9
- var $post = 0;
10
- }
11
- }
12
-
13
  $WPSC_HTTP_HOST = htmlentities( $_SERVER[ 'HTTP_HOST' ] );
14
 
15
  // We want to be able to identify each blog in a WordPress MU install
@@ -21,7 +12,7 @@ if ( defined( 'VHOST' ) || ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_AL
21
  } else {
22
  if ( isset( $base ) == false )
23
  $base = '';
24
- $request_uri = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_SERVER['REQUEST_URI'] ) );
25
  if( strpos( $request_uri, '/', 1 ) ) {
26
  if( $base == '/' ) {
27
  $blogcacheid = substr( $request_uri, 1, strpos( $request_uri, '/', 1 ) - 1 );
1
  <?php
2
  $known_headers = array("Last-Modified", "Expires", "Content-Type", "Content-type", "X-Pingback", "ETag", "Cache-Control", "Pragma");
3
 
 
 
 
 
 
 
 
 
 
4
  $WPSC_HTTP_HOST = htmlentities( $_SERVER[ 'HTTP_HOST' ] );
5
 
6
  // We want to be able to identify each blog in a WordPress MU install
12
  } else {
13
  if ( isset( $base ) == false )
14
  $base = '';
15
+ $request_uri = str_replace( '..', '', preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER['REQUEST_URI'] ) );
16
  if( strpos( $request_uri, '/', 1 ) ) {
17
  if( $base == '/' ) {
18
  $blogcacheid = substr( $request_uri, 1, strpos( $request_uri, '/', 1 ) - 1 );
wp-cache-phase1.php CHANGED
@@ -111,8 +111,8 @@ function wp_super_cache_init() {
111
  $key = $blogcacheid . md5( $wp_cache_key );
112
  $wp_cache_key = $blogcacheid . $wp_cache_key;
113
 
114
- $cache_filename = $file_prefix . $key . '.html';
115
- $meta_file = $file_prefix . $key . '.meta';
116
  $cache_file = realpath( $blog_cache_dir . $cache_filename );
117
  $meta_pathname = realpath( $blog_cache_dir . 'meta/' . $meta_file );
118
  return compact( 'key', 'cache_filename', 'meta_file', 'cache_file', 'meta_pathname' );
@@ -131,13 +131,13 @@ function wp_cache_serve_cache_file() {
131
  }
132
 
133
  if ( $wp_cache_no_cache_for_get && false == empty( $_GET ) ) {
134
- wp_cache_debug( "Non empty GET request. Caching disabled on settings page. " . serialize( $_GET ), 1 );
135
  return false;
136
  }
137
 
138
  if ( $wp_cache_object_cache && wp_cache_get_cookies_values() == '' ) {
139
  if ( !empty( $_GET ) ) {
140
- wp_cache_debug( "Non empty GET request. Not serving request from object cache. " . serialize( $_GET ), 1 );
141
  return false;
142
  }
143
 
@@ -148,14 +148,14 @@ function wp_cache_serve_cache_file() {
148
  $meta_filename .= ".gz";
149
  }
150
  $cache = wp_cache_get( $oc_key, 'supercache' );
151
- $meta = unserialize( wp_cache_get( $meta_filename, 'supercache' ) );
152
  if ( is_array( $meta ) == false ) {
153
  wp_cache_debug( "Meta array from object cache corrupt. Ignoring cache.", 1 );
154
  return true;
155
  }
156
  } elseif ( file_exists( $cache_file ) ) {
157
  wp_cache_debug( "wp-cache file exists: $cache_file", 5 );
158
- if ( !( $meta = unserialize( @file_get_contents( $meta_pathname) ) ) ) {
159
  wp_cache_debug( "couldn't load wp-cache meta file", 5 );
160
  return true;
161
  }
@@ -173,7 +173,7 @@ function wp_cache_serve_cache_file() {
173
  wp_cache_debug( "No Super Cache file found for current URL: $file" );
174
  return false;
175
  } elseif ( false == empty( $_GET ) ) {
176
- wp_cache_debug( "GET array not empty. Cannot serve a supercache file. " . serialize( $_GET ) );
177
  return false;
178
  } elseif ( wp_cache_get_cookies_values() != '' ) {
179
  wp_cache_debug( "Cookies found. Cannot serve a supercache file. " . wp_cache_get_cookies_values() );
@@ -232,7 +232,7 @@ function wp_cache_serve_cache_file() {
232
  if ( $wp_cache_mfunc_enabled == 0 && $wp_supercache_304 ) {
233
  if ( function_exists( 'apache_request_headers' ) ) {
234
  $request = apache_request_headers();
235
- $remote_mod_time = $request[ 'If-Modified-Since' ];
236
  } else {
237
  if ( isset( $_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ] ) )
238
  $remote_mod_time = $_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ];
@@ -294,7 +294,7 @@ function wp_cache_serve_cache_file() {
294
  wp_cache_debug( "Serving wp-cache dynamic file", 5 );
295
  if ( $ungzip ) {
296
  // attempt to uncompress the cached file just in case it's gzipped
297
- $cache = file_get_contents( $cache_file );
298
  $uncompressed = @gzuncompress( $cache );
299
  if ( $uncompressed ) {
300
  wp_cache_debug( "Uncompressed gzipped cache file from wp-cache", 1 );
@@ -304,12 +304,12 @@ function wp_cache_serve_cache_file() {
304
  echo do_cacheaction( 'wpsc_cachedata', $cache );
305
  }
306
  } else {
307
- echo do_cacheaction( 'wpsc_cachedata', file_get_contents( $cache_file ) );
308
  }
309
  } else {
310
  wp_cache_debug( "Serving wp-cache static file", 5 );
311
  if ( $ungzip ) {
312
- $cache = file_get_contents( $cache_file );
313
  $uncompressed = gzuncompress( $cache );
314
  if ( $uncompressed ) {
315
  wp_cache_debug( "Uncompressed gzipped cache file from wp-cache", 1 );
@@ -318,7 +318,7 @@ function wp_cache_serve_cache_file() {
318
  echo $cache;
319
  }
320
  } else {
321
- readfile( $cache_file );
322
  }
323
  }
324
  wp_cache_debug( "exit request", 5 );
@@ -326,6 +326,10 @@ function wp_cache_serve_cache_file() {
326
  }
327
  }
328
 
 
 
 
 
329
  if(defined('DOING_CRON')) {
330
  extract( wp_super_cache_init() );
331
  return true;
@@ -357,7 +361,13 @@ function wp_cache_late_loader() {
357
  }
358
 
359
  function wp_cache_get_cookies_values() {
360
- $string = '';
 
 
 
 
 
 
361
  $regex = "/^wp-postpass|^comment_author_";
362
  if ( defined( 'LOGGED_IN_COOKIE' ) )
363
  $regex .= "|^" . preg_quote( constant( 'LOGGED_IN_COOKIE' ) );
@@ -375,6 +385,10 @@ function wp_cache_get_cookies_values() {
375
 
376
  // If you use this hook, make sure you update your .htaccess rules with the same conditions
377
  $string = do_cacheaction( 'wp_cache_get_cookies_values', $string );
 
 
 
 
378
  return $string;
379
  }
380
 
@@ -506,11 +520,11 @@ function wp_cache_debug( $message, $level = 1 ) {
506
  return false;
507
 
508
  // Log message: Date URI Message
509
- $log_messase = date('H:i:s') . " {$_SERVER['REQUEST_URI']} {$message}\n\r";
510
  // path to the log file in the cache folder
511
  $log_file = $cache_path . str_replace('/', '', str_replace('..', '', $wp_cache_debug_log));
512
 
513
- error_log( $message, 3, $log_file );
514
  }
515
 
516
  function wp_cache_user_agent_is_rejected() {
@@ -535,7 +549,7 @@ function get_supercache_dir( $blog_id = 0 ) {
535
  } else {
536
  $home = get_blog_option( $blog_id, 'home' );
537
  }
538
- return apply_filters( 'wp_super_cache_supercachedir', $cache_path . 'supercache/' . trailingslashit( strtolower( preg_replace( '/:.*$/', '', str_replace( 'http://', '', str_replace( 'https://', '', $home ) ) ) ) ) );
539
  }
540
  function get_current_url_supercache_dir( $post_id = 0 ) {
541
  global $cached_direct_pages, $cache_path, $wp_cache_request_uri, $WPSC_HTTP_HOST, $wp_cache_home_path;
@@ -566,13 +580,10 @@ function get_current_url_supercache_dir( $post_id = 0 ) {
566
  $uri = '';
567
  }
568
  } else {
569
- if ( isset( $_SERVER[ 'HTTPS' ] ) )
570
- $protocol = ( 'on' == strtolower( $_SERVER[ 'HTTPS' ] ) ) ? 'https://' : 'http://';
571
- else
572
- $protocol = 'http://';
573
  wp_cache_debug( "get_current_url_supercache_dir: Removing SERVER_NAME ({$WPSC_HTTP_HOST}) and $protocol from permalink ($permalink). Is the url right?", 1 );
574
  $uri = str_replace( $WPSC_HTTP_HOST, '', $permalink );
575
- $uri = str_replace( $protocol, '', $uri );
 
576
  }
577
  } else {
578
  $uri = str_replace( $site_url, '', $permalink );
@@ -582,8 +593,7 @@ function get_current_url_supercache_dir( $post_id = 0 ) {
582
  } else {
583
  $uri = strtolower( $wp_cache_request_uri );
584
  }
585
- $uri = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '/index.php', '/', str_replace( '..', '', preg_replace("/(\?.*)?$/", '', $uri ) ) ) );
586
- $uri = str_replace( '\\', '', $uri );
587
  $dir = preg_replace( '/:.*$/', '', $WPSC_HTTP_HOST ) . $uri; // To avoid XSS attacks
588
  if ( function_exists( "apply_filters" ) ) {
589
  $dir = apply_filters( 'supercache_dir', $dir );
@@ -594,7 +604,7 @@ function get_current_url_supercache_dir( $post_id = 0 ) {
594
  if( is_array( $cached_direct_pages ) && in_array( $_SERVER[ 'REQUEST_URI' ], $cached_direct_pages ) ) {
595
  $dir = ABSPATH . $uri . '/';
596
  }
597
- $dir = str_replace( '//', '/', $dir );
598
  wp_cache_debug( "supercache dir: $dir", 5 );
599
  if ( $DONOTREMEMBER == 0 )
600
  $saved_supercache_dir[ $post_id ] = $dir;
@@ -602,7 +612,11 @@ function get_current_url_supercache_dir( $post_id = 0 ) {
602
  }
603
 
604
  function get_all_supercache_filenames( $dir = '' ) {
605
- global $wp_cache_mobile_enabled;
 
 
 
 
606
 
607
  $filenames = array( 'index.html', 'index-https.html', 'index.html.php' );
608
 
@@ -696,4 +710,33 @@ function wp_supercache_cache_for_admins() {
696
  }
697
  }
698
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
699
  ?>
111
  $key = $blogcacheid . md5( $wp_cache_key );
112
  $wp_cache_key = $blogcacheid . $wp_cache_key;
113
 
114
+ $cache_filename = $file_prefix . $key . '.php';
115
+ $meta_file = $file_prefix . $key . '.php';
116
  $cache_file = realpath( $blog_cache_dir . $cache_filename );
117
  $meta_pathname = realpath( $blog_cache_dir . 'meta/' . $meta_file );
118
  return compact( 'key', 'cache_filename', 'meta_file', 'cache_file', 'meta_pathname' );
131
  }
132
 
133
  if ( $wp_cache_no_cache_for_get && false == empty( $_GET ) ) {
134
+ wp_cache_debug( "Non empty GET request. Caching disabled on settings page. " . json_encode( $_GET ), 1 );
135
  return false;
136
  }
137
 
138
  if ( $wp_cache_object_cache && wp_cache_get_cookies_values() == '' ) {
139
  if ( !empty( $_GET ) ) {
140
+ wp_cache_debug( "Non empty GET request. Not serving request from object cache. " . json_encode( $_GET ), 1 );
141
  return false;
142
  }
143
 
148
  $meta_filename .= ".gz";
149
  }
150
  $cache = wp_cache_get( $oc_key, 'supercache' );
151
+ $meta = json_decode( wp_cache_get( $meta_filename, 'supercache' ), true );
152
  if ( is_array( $meta ) == false ) {
153
  wp_cache_debug( "Meta array from object cache corrupt. Ignoring cache.", 1 );
154
  return true;
155
  }
156
  } elseif ( file_exists( $cache_file ) ) {
157
  wp_cache_debug( "wp-cache file exists: $cache_file", 5 );
158
+ if ( !( $meta = json_decode( wp_cache_get_legacy_cache( $meta_pathname ), true ) ) ) {
159
  wp_cache_debug( "couldn't load wp-cache meta file", 5 );
160
  return true;
161
  }
173
  wp_cache_debug( "No Super Cache file found for current URL: $file" );
174
  return false;
175
  } elseif ( false == empty( $_GET ) ) {
176
+ wp_cache_debug( "GET array not empty. Cannot serve a supercache file. " . json_encode( $_GET ) );
177
  return false;
178
  } elseif ( wp_cache_get_cookies_values() != '' ) {
179
  wp_cache_debug( "Cookies found. Cannot serve a supercache file. " . wp_cache_get_cookies_values() );
232
  if ( $wp_cache_mfunc_enabled == 0 && $wp_supercache_304 ) {
233
  if ( function_exists( 'apache_request_headers' ) ) {
234
  $request = apache_request_headers();
235
+ $remote_mod_time = ( isset ( $request[ 'If-Modified-Since' ] ) ) ? $request[ 'If-Modified-Since' ] : 0;
236
  } else {
237
  if ( isset( $_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ] ) )
238
  $remote_mod_time = $_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ];
294
  wp_cache_debug( "Serving wp-cache dynamic file", 5 );
295
  if ( $ungzip ) {
296
  // attempt to uncompress the cached file just in case it's gzipped
297
+ $cache = wp_cache_get_legacy_cache( $cache_file );
298
  $uncompressed = @gzuncompress( $cache );
299
  if ( $uncompressed ) {
300
  wp_cache_debug( "Uncompressed gzipped cache file from wp-cache", 1 );
304
  echo do_cacheaction( 'wpsc_cachedata', $cache );
305
  }
306
  } else {
307
+ echo do_cacheaction( 'wpsc_cachedata', wp_cache_get_legacy_cache( $cache_file ) );
308
  }
309
  } else {
310
  wp_cache_debug( "Serving wp-cache static file", 5 );
311
  if ( $ungzip ) {
312
+ $cache = wp_cache_get_legacy_cache( $cache_file );
313
  $uncompressed = gzuncompress( $cache );
314
  if ( $uncompressed ) {
315
  wp_cache_debug( "Uncompressed gzipped cache file from wp-cache", 1 );
318
  echo $cache;
319
  }
320
  } else {
321
+ echo( wp_cache_get_legacy_cache( $cache_file ) );
322
  }
323
  }
324
  wp_cache_debug( "exit request", 5 );
326
  }
327
  }
328
 
329
+ function wp_cache_get_legacy_cache( $cache_file ) {
330
+ return substr( @file_get_contents( $cache_file ), 15 );
331
+ }
332
+
333
  if(defined('DOING_CRON')) {
334
  extract( wp_super_cache_init() );
335
  return true;
361
  }
362
 
363
  function wp_cache_get_cookies_values() {
364
+ static $string = '';
365
+
366
+ if ( $string != '' ) {
367
+ wp_cache_debug( "wp_cache_get_cookies_values: cached: $string" );
368
+ return $string;
369
+ }
370
+
371
  $regex = "/^wp-postpass|^comment_author_";
372
  if ( defined( 'LOGGED_IN_COOKIE' ) )
373
  $regex .= "|^" . preg_quote( constant( 'LOGGED_IN_COOKIE' ) );
385
 
386
  // If you use this hook, make sure you update your .htaccess rules with the same conditions
387
  $string = do_cacheaction( 'wp_cache_get_cookies_values', $string );
388
+ if ( $string != '' )
389
+ $string = md5( $string );
390
+
391
+ wp_cache_debug( "wp_cache_get_cookies_values: return: $string", 5 );
392
  return $string;
393
  }
394
 
520
  return false;
521
 
522
  // Log message: Date URI Message
523
+ $log_message = date('H:i:s') . " " . getmypid() . " {$_SERVER['REQUEST_URI']} {$message}\n\r";
524
  // path to the log file in the cache folder
525
  $log_file = $cache_path . str_replace('/', '', str_replace('..', '', $wp_cache_debug_log));
526
 
527
+ error_log( $log_message, 3, $log_file );
528
  }
529
 
530
  function wp_cache_user_agent_is_rejected() {
549
  } else {
550
  $home = get_blog_option( $blog_id, 'home' );
551
  }
552
+ return trailingslashit( apply_filters( 'wp_super_cache_supercachedir', $cache_path . 'supercache/' . trailingslashit( strtolower( preg_replace( '/:.*$/', '', str_replace( 'http://', '', str_replace( 'https://', '', $home ) ) ) ) ) ) );
553
  }
554
  function get_current_url_supercache_dir( $post_id = 0 ) {
555
  global $cached_direct_pages, $cache_path, $wp_cache_request_uri, $WPSC_HTTP_HOST, $wp_cache_home_path;
580
  $uri = '';
581
  }
582
  } else {
 
 
 
 
583
  wp_cache_debug( "get_current_url_supercache_dir: Removing SERVER_NAME ({$WPSC_HTTP_HOST}) and $protocol from permalink ($permalink). Is the url right?", 1 );
584
  $uri = str_replace( $WPSC_HTTP_HOST, '', $permalink );
585
+ $uri = str_replace( 'http://', '', $uri );
586
+ $uri = str_replace( 'https://', '', $uri );
587
  }
588
  } else {
589
  $uri = str_replace( $site_url, '', $permalink );
593
  } else {
594
  $uri = strtolower( $wp_cache_request_uri );
595
  }
596
+ $uri = wpsc_deep_replace( array( '..', '\\', 'index.php', ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace( "/(\?.*)?$/", '', $uri ) ) );
 
597
  $dir = preg_replace( '/:.*$/', '', $WPSC_HTTP_HOST ) . $uri; // To avoid XSS attacks
598
  if ( function_exists( "apply_filters" ) ) {
599
  $dir = apply_filters( 'supercache_dir', $dir );
604
  if( is_array( $cached_direct_pages ) && in_array( $_SERVER[ 'REQUEST_URI' ], $cached_direct_pages ) ) {
605
  $dir = ABSPATH . $uri . '/';
606
  }
607
+ $dir = str_replace( '..', '', str_replace( '//', '/', $dir ) );
608
  wp_cache_debug( "supercache dir: $dir", 5 );
609
  if ( $DONOTREMEMBER == 0 )
610
  $saved_supercache_dir[ $post_id ] = $dir;
612
  }
613
 
614
  function get_all_supercache_filenames( $dir = '' ) {
615
+ global $wp_cache_mobile_enabled, $cache_path;
616
+
617
+ $dir = realpath( $dir );
618
+ if ( substr( $dir, 0, strlen( $cache_path ) ) != $cache_path )
619
+ return array();
620
 
621
  $filenames = array( 'index.html', 'index-https.html', 'index.html.php' );
622
 
710
  }
711
  }
712
 
713
+ /* returns true/false depending on location of $dir. */
714
+ function wp_cache_confirm_delete( $dir ) {
715
+ global $cache_path, $blog_cache_dir;
716
+ // don't allow cache_path, blog cache dir, blog meta dir, supercache.
717
+ $dir = realpath( $dir );
718
+ if (
719
+ $dir == $cache_path ||
720
+ $dir == $blog_cache_dir ||
721
+ $dir == $blog_cache_dir . "meta/" ||
722
+ $dir == $cache_path . "supercache"
723
+ ) {
724
+ return false;
725
+ } else {
726
+ return true;
727
+ }
728
+ }
729
+
730
+ // copy of _deep_replace() to be used before WordPress loads
731
+ function wpsc_deep_replace( $search, $subject ) {
732
+ $subject = (string) $subject;
733
+
734
+ $count = 1;
735
+ while ( $count ) {
736
+ $subject = str_replace( $search, '', $subject, $count );
737
+ }
738
+
739
+ return $subject;
740
+ }
741
+
742
  ?>
wp-cache-phase2.php CHANGED
@@ -51,8 +51,8 @@ function wp_cache_phase2() {
51
  return false;
52
  }
53
 
54
- if ( !empty( $_GET ) ) {
55
- wp_cache_debug( 'Supercache caching disabled. Only using wp-cache. Non empty GET request. ' . serialize( $_GET ), 5 );
56
  $super_cache_enabled = false;
57
  }
58
 
@@ -75,14 +75,18 @@ function wp_cache_phase2() {
75
  }
76
 
77
  function wpcache_do_rebuild( $dir ) {
 
78
  $dir = trailingslashit( $dir );
 
 
 
79
  $files_to_check = get_all_supercache_filenames( $dir );
80
  foreach( $files_to_check as $cache_file ) {
81
  $cache_file = $dir . $cache_file;
82
  if( !@file_exists( $cache_file . '.needs-rebuild' ) )
83
  continue;
84
  $mtime = @filemtime($cache_file . '.needs-rebuild');
85
- if( $mtime && (time() - $mtime) < 30 ) {
86
  wp_cache_debug( "Rebuild file renamed to cache file temporarily: $cache_file", 3 );
87
  @rename( $cache_file . '.needs-rebuild', $cache_file );
88
  }
@@ -239,7 +243,7 @@ function wp_super_cache_query_vars() {
239
  }
240
 
241
  function wp_cache_ob_callback( $buffer ) {
242
- global $wp_cache_pages, $wp_query, $wp_super_cache_query, $cache_acceptable_files, $wp_cache_no_cache_for_get, $wp_cache_object_cache, $wp_cache_request_uri;
243
  $buffer = apply_filters( 'wp_cache_ob_callback_filter', $buffer );
244
 
245
  $script = basename($_SERVER['PHP_SELF']);
@@ -250,7 +254,7 @@ function wp_cache_ob_callback( $buffer ) {
250
  wp_cache_debug( 'DONOTCACHEPAGE defined. Caching disabled.', 2 );
251
  $cache_this_page = false;
252
  } elseif ( $wp_cache_no_cache_for_get && false == empty( $_GET ) && false == defined( 'DOING_CRON' ) ) {
253
- wp_cache_debug( "Non empty GET request. Caching disabled on settings page. " . serialize( $_GET ), 1 );
254
  $cache_this_page = false;
255
  } elseif ( $_SERVER["REQUEST_METHOD"] == 'POST' || !empty( $_POST ) || get_option( 'gzipcompression' ) ) {
256
  wp_cache_debug( 'Not caching POST request.', 5 );
@@ -310,6 +314,18 @@ function wp_cache_ob_callback( $buffer ) {
310
  wp_cache_shutdown_callback();
311
  return $buffer;
312
  } else {
 
 
 
 
 
 
 
 
 
 
 
 
313
  return wp_cache_maybe_dynamic( $buffer );
314
  }
315
  }
@@ -540,7 +556,7 @@ function wp_cache_get_ob(&$buffer) {
540
  if ( $fr ) { // legacy caching
541
  wp_cache_debug( "Writing dynamic buffer to legacy file." );
542
  wp_cache_add_to_buffer( $buffer, "Dynamic Legacy Super Cache" );
543
- fputs( $fr, $buffer );
544
  } elseif ( isset( $fr2 ) ) { // supercache active
545
  wp_cache_debug( "Writing dynamic buffer to supercache file." );
546
  wp_cache_add_to_buffer( $buffer, "Dynamic Super Cache" );
@@ -570,7 +586,7 @@ function wp_cache_get_ob(&$buffer) {
570
  // Return uncompressed data & store compressed for later use
571
  if ( $fr ) {
572
  wp_cache_debug( "Writing gzipped buffer to wp-cache cache file.", 5 );
573
- fputs($fr, $gzdata);
574
  } elseif ( $cache_enabled && $wp_cache_object_cache ) {
575
  wp_cache_set( $oc_key . ".gz", $gzdata, 'supercache', $cache_max_time );
576
  $added_cache = 1;
@@ -582,7 +598,7 @@ function wp_cache_get_ob(&$buffer) {
582
  $added_cache = 1;
583
  } elseif ( $fr ) {
584
  wp_cache_debug( "Writing non-gzipped buffer to wp-cache cache file." );
585
- fputs($fr, $buffer);
586
  }
587
  }
588
  if ( $fr2 ) {
@@ -674,14 +690,21 @@ function wp_cache_phase2_clean_cache($file_prefix) {
674
 
675
  if( !wp_cache_writers_entry() )
676
  return false;
677
- wp_cache_debug( "Cleaning cache in $blog_cache_dir", 3 );
678
- if ( ( $handle = @opendir( $blog_cache_dir ) ) ) {
679
  while ( false !== ($file = @readdir($handle))) {
680
- if ( preg_match("/^$file_prefix/", $file) ) {
681
- $meta = unserialize( file_get_contents( $blog_cache_dir . 'meta/' . $file ) );
682
- if ( $meta[ 'blog_id' ] == $wpdb->blogid ) {
683
- @unlink( $blog_cache_dir . $file );
 
684
  @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
 
 
 
 
 
 
685
  }
686
  }
687
  }
@@ -694,12 +717,23 @@ function prune_super_cache( $directory, $force = false, $rename = false ) {
694
  global $cache_max_time, $cache_path, $cache_rebuild_files, $blog_cache_dir;
695
  static $log = 0;
696
 
 
 
 
 
697
  if( !isset( $cache_max_time ) )
698
  $cache_max_time = 3600;
699
 
700
  $now = time();
701
 
702
- $protected_directories = array( $cache_path . '.htaccess', $cache_path . $blog_cache_dir . 'meta', $cache_path . 'supercache' );
 
 
 
 
 
 
 
703
 
704
  $oktodelete = false;
705
  if (is_dir($directory)) {
@@ -734,14 +768,18 @@ function prune_super_cache( $directory, $force = false, $rename = false ) {
734
  wp_cache_debug( "gc: deleted $entry, older than $cache_max_time seconds", 2 );
735
  }
736
  }
 
 
737
  }
738
  }
739
  closedir($dh);
740
  }
741
  } elseif( is_file($directory) && ($force || @filemtime( $directory ) + $cache_max_time <= $now ) ) {
742
  $oktodelete = true;
743
- if( in_array( $directory, $protected_directories ) )
 
744
  $oktodelete = false;
 
745
  if( $oktodelete && !$rename ) {
746
  wp_cache_debug( "prune_super_cache: deleted $directory", 5 );
747
  @unlink( $directory );
@@ -750,7 +788,11 @@ function prune_super_cache( $directory, $force = false, $rename = false ) {
750
  wp_cache_debug( "prune_super_cache: wp_cache_rebuild_or_delete( $directory )", 5 );
751
  wp_cache_rebuild_or_delete( $directory );
752
  $log++;
 
 
753
  }
 
 
754
  }
755
  return $log;
756
  }
@@ -762,7 +804,7 @@ function wp_cache_rebuild_or_delete( $file ) {
762
  if( $cache_rebuild_files && substr( $file, -14 ) != '.needs-rebuild' ) {
763
  if( @rename($file, $file . '.needs-rebuild') ) {
764
  @touch( $file . '.needs-rebuild' );
765
- wp_cache_debug( "rebuild_or_gc: rename to {$file}.needs-rebuild", 2 );
766
  } else {
767
  @unlink( $file );
768
  wp_cache_debug( "rebuild_or_gc: deleted $file", 2 );
@@ -781,18 +823,19 @@ function wp_cache_phase2_clean_expired( $file_prefix, $force = false ) {
781
  return false;
782
  $now = time();
783
  wp_cache_debug( "Cleaning expired cache files in $blog_cache_dir", 2 );
 
784
  if ( ( $handle = @opendir( $blog_cache_dir ) ) ) {
785
  while ( false !== ($file = readdir($handle))) {
786
  if ( preg_match("/^$file_prefix/", $file) &&
787
  (@filemtime( $blog_cache_dir . $file) + $cache_max_time) <= $now ) {
788
  @unlink( $blog_cache_dir . $file );
789
  @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
790
- wp_cache_debug( "Deleting $blog_cache_dir{$file} (plus meta)", 5 );
791
  continue;
792
  }
793
  if($file != '.' && $file != '..') {
794
  if( is_dir( $blog_cache_dir . $file ) == false && (@filemtime($blog_cache_dir . $file) + $cache_max_time) <= $now ) {
795
- if( substr( $file, -9 ) != '.htaccess' ) {
796
  @unlink($blog_cache_dir . $file);
797
  wp_cache_debug( "Deleting $blog_cache_dir{$file}, older than $cache_max_time seconds", 5 );
798
  }
@@ -875,7 +918,7 @@ function wp_cache_shutdown_callback() {
875
  $wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: Accept-Encoding, Cookie';
876
  }
877
 
878
- $serial = serialize($wp_cache_meta);
879
  if( wp_cache_writers_entry() ) {
880
  wp_cache_debug( "Writing meta file: {$blog_cache_dir}meta/{$meta_file}", 2 );
881
  if ( false == $wp_cache_object_cache ) {
@@ -1046,7 +1089,7 @@ function wp_cache_post_edit($post_id) {
1046
  // Some users are inexplicibly seeing this error on scheduled posts.
1047
  // define this constant to disable the post status check.
1048
  if ( false == defined( 'WPSCFORCEUPDATE' ) && $post->post_status != 'publish' ) {
1049
- wp_cache_debug( "wp_cache_post_edit: draft post, not deleting any cache files.", 4 );
1050
  return $post_id;
1051
  }
1052
 
@@ -1076,9 +1119,9 @@ function wp_cache_post_id_gc( $siteurl, $post_id, $all = 'all' ) {
1076
  if( $post_id == 0 )
1077
  return;
1078
 
1079
- $permalink = trailingslashit( str_replace( get_option( 'home' ), '', post_permalink( $post_id ) ) );
1080
  $dir = get_current_url_supercache_dir( $post_id );
1081
- wp_cache_debug( "wp_cache_post_id_gc post_id: $post_id " . post_permalink( $post_id ) . " clearing cache in $dir.", 4 );
1082
  if ( $all == 'all' ) {
1083
  prune_super_cache( $dir, true, true );
1084
  do_action( 'gc_cache', 'prune', $permalink );
@@ -1131,70 +1174,87 @@ function wp_cache_post_change( $post_id ) {
1131
  if ( $wp_cache_object_cache )
1132
  reset_oc_version();
1133
 
1134
- $permalink = trailingslashit( str_replace( get_option( 'siteurl' ), '', post_permalink( $post_id ) ) );
1135
  if( $super_cache_enabled ) {
1136
  $dir = get_supercache_dir();
1137
- $siteurl = trailingslashit( strtolower( preg_replace( '/:.*$/', '', str_replace( 'http://', '', get_option( 'home' ) ) ) ) );
1138
  // make sure the front page has a rebuild file
1139
  wp_cache_post_id_gc( $siteurl, $post_id );
1140
  if ( $all == true ) {
1141
- wp_cache_debug( "Post change: deleting cache files in " . $cache_path . 'supercache/' . $siteurl, 4 );
1142
  $files_to_check = get_all_supercache_filenames( $dir );
1143
  foreach( $files_to_check as $cache_file ) {
 
1144
  prune_super_cache( $dir . $cache_file, true, true );
1145
  }
1146
  do_action( 'gc_cache', 'prune', 'homepage' );
 
 
1147
  }
1148
  if( $all == true && get_option( 'show_on_front' ) == 'page' ) {
1149
  wp_cache_debug( "Post change: deleting page_on_front and page_for_posts pages.", 4 );
1150
  wp_cache_debug( "Post change: page_on_front " . get_option( 'page_on_front' ), 4 );
1151
  wp_cache_post_id_gc( $siteurl, get_option( 'page_on_front' ), 'single' );
1152
- $permalink = trailingslashit( str_replace( get_option( 'home' ), '', post_permalink( get_option( 'page_for_posts' ) ) ) );
1153
  $files_to_check = get_all_supercache_filenames( $dir . $permalink );
1154
  foreach( $files_to_check as $cache_file ) {
1155
  prune_super_cache( $dir . $permalink . $cache_file, true, true );
1156
  }
1157
  do_action( 'gc_cache', 'prune', $permalink );
 
 
1158
  }
1159
  }
1160
 
1161
- $matches = array();
1162
- if ( ($handle = @opendir( $blog_cache_dir . 'meta/' )) ) {
 
1163
  while ( false !== ($file = readdir($handle))) {
1164
- if ( preg_match("/^({$file_prefix}{$blogcacheid}.*)\.meta/", $file, $matches) ) {
1165
- $meta_pathname = $blog_cache_dir . 'meta/' . $file;
1166
- $content_pathname = $blog_cache_dir . $matches[1] . ".html";
1167
- $meta = unserialize(@file_get_contents($meta_pathname));
1168
- if( false == is_array( $meta ) ) {
1169
- wp_cache_debug( "Post change cleaning up stray file: $content_pathname", 4 );
1170
- @unlink($meta_pathname);
1171
- @unlink($content_pathname);
1172
  continue;
1173
- }
1174
- if ($post_id > 0 && $meta) {
1175
- $permalink = trailingslashit( str_replace( get_option( 'home' ), '', post_permalink( $post_id ) ) );
1176
- if ( $meta[ 'blog_id' ] == $blog_id && ( ( $all == true && !$meta[ 'post' ] ) || $meta[ 'post' ] == $post_id) ) {
1177
- wp_cache_debug( "Post change: deleting post cache files for {$meta[ 'uri' ]}: $content_pathname", 4 );
1178
- @unlink($meta_pathname);
1179
- @unlink($content_pathname);
1180
- if ( $super_cache_enabled == true ) {
1181
- @prune_super_cache( $dir . $permalink, true, true );
1182
- do_action( 'gc_cache', 'rebuild', $permalink );
1183
- }
1184
  }
1185
- } elseif ($meta[ 'blog_id' ] == $blog_id) {
1186
- wp_cache_debug( "Post change: deleting cache files for {$meta[ 'uri' ]}: $content_pathname", 4 );
1187
- @unlink($meta_pathname);
1188
- @unlink($content_pathname);
1189
- if ( $super_cache_enabled == true ) {
1190
- $files_to_check = get_all_supercache_filenames( $dir . $meta[ 'uri' ] );
1191
- foreach( $files_to_check as $cache_file ) {
1192
- @wp_cache_rebuild_or_delete( $dir . trailingslashit( $meta[ 'uri' ] ) . $cache_file );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1193
  }
1194
- do_action( 'gc_cache', 'rebuild', trailingslashit( $meta[ 'uri' ] ) );
1195
  }
1196
  }
1197
-
1198
  }
1199
  }
1200
  closedir($handle);
@@ -1284,7 +1344,7 @@ function wp_cache_gc_cron() {
1284
 
1285
  $msg = "Hi,\n\nThe WP Super Cache Garbage Collector has now run, deleting " . (int)$num . " files and directories.\nIf you want to switch off these emails please see the WP Super Cache Advanced Settings\npage on your blog.\n\n{$msg}\nRegards,\nThe Garbage Collector.";
1286
 
1287
- wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] WP Super Cache GC Report', 'wp-super-cache' ), site_url() ), $msg );
1288
  }
1289
  @unlink( $gc_flag );
1290
  wp_cache_debug( 'GC completed. GC flag deleted.', 5 );
51
  return false;
52
  }
53
 
54
+ if ( !empty( $_GET ) && !defined( "DOING_CRON" ) ) {
55
+ wp_cache_debug( 'Supercache caching disabled. Only using wp-cache. Non empty GET request. ' . json_encode( $_GET ), 5 );
56
  $super_cache_enabled = false;
57
  }
58
 
75
  }
76
 
77
  function wpcache_do_rebuild( $dir ) {
78
+ global $do_rebuild_list;
79
  $dir = trailingslashit( $dir );
80
+ if ( isset( $do_rebuild_list[ $dir ] ) )
81
+ return false;
82
+ $do_rebuild_list[ $dir ] = 1;
83
  $files_to_check = get_all_supercache_filenames( $dir );
84
  foreach( $files_to_check as $cache_file ) {
85
  $cache_file = $dir . $cache_file;
86
  if( !@file_exists( $cache_file . '.needs-rebuild' ) )
87
  continue;
88
  $mtime = @filemtime($cache_file . '.needs-rebuild');
89
+ if( $mtime && (time() - $mtime) < 10 ) {
90
  wp_cache_debug( "Rebuild file renamed to cache file temporarily: $cache_file", 3 );
91
  @rename( $cache_file . '.needs-rebuild', $cache_file );
92
  }
243
  }
244
 
245
  function wp_cache_ob_callback( $buffer ) {
246
+ global $wp_cache_pages, $wp_query, $wp_super_cache_query, $cache_acceptable_files, $wp_cache_no_cache_for_get, $wp_cache_object_cache, $wp_cache_request_uri, $do_rebuild_list;
247
  $buffer = apply_filters( 'wp_cache_ob_callback_filter', $buffer );
248
 
249
  $script = basename($_SERVER['PHP_SELF']);
254
  wp_cache_debug( 'DONOTCACHEPAGE defined. Caching disabled.', 2 );
255
  $cache_this_page = false;
256
  } elseif ( $wp_cache_no_cache_for_get && false == empty( $_GET ) && false == defined( 'DOING_CRON' ) ) {
257
+ wp_cache_debug( "Non empty GET request. Caching disabled on settings page. " . json_encode( $_GET ), 1 );
258
  $cache_this_page = false;
259
  } elseif ( $_SERVER["REQUEST_METHOD"] == 'POST' || !empty( $_POST ) || get_option( 'gzipcompression' ) ) {
260
  wp_cache_debug( 'Not caching POST request.', 5 );
314
  wp_cache_shutdown_callback();
315
  return $buffer;
316
  } else {
317
+ if ( is_array( $do_rebuild_list ) && false == empty( $do_rebuild_list ) ) {
318
+ foreach( $do_rebuild_list as $dir => $n ) {
319
+ if ( wp_cache_confirm_delete( $dir ) ) {
320
+ wp_cache_debug( 'wp_cache_ob_callback clearing rebuilt files in ' . $dir );
321
+ $files_to_check = get_all_supercache_filenames( $dir );
322
+ foreach( $files_to_check as $cache_file ) {
323
+ $cache_file = $dir . $cache_file;
324
+ @unlink( $cache_file );
325
+ }
326
+ }
327
+ }
328
+ }
329
  return wp_cache_maybe_dynamic( $buffer );
330
  }
331
  }
556
  if ( $fr ) { // legacy caching
557
  wp_cache_debug( "Writing dynamic buffer to legacy file." );
558
  wp_cache_add_to_buffer( $buffer, "Dynamic Legacy Super Cache" );
559
+ fputs( $fr, '<?php die(); ?>' . $buffer );
560
  } elseif ( isset( $fr2 ) ) { // supercache active
561
  wp_cache_debug( "Writing dynamic buffer to supercache file." );
562
  wp_cache_add_to_buffer( $buffer, "Dynamic Super Cache" );
586
  // Return uncompressed data & store compressed for later use
587
  if ( $fr ) {
588
  wp_cache_debug( "Writing gzipped buffer to wp-cache cache file.", 5 );
589
+ fputs($fr, '<?php die(); ?>' . $gzdata);
590
  } elseif ( $cache_enabled && $wp_cache_object_cache ) {
591
  wp_cache_set( $oc_key . ".gz", $gzdata, 'supercache', $cache_max_time );
592
  $added_cache = 1;
598
  $added_cache = 1;
599
  } elseif ( $fr ) {
600
  wp_cache_debug( "Writing non-gzipped buffer to wp-cache cache file." );
601
+ fputs($fr, '<?php die(); ?>' . $buffer);
602
  }
603
  }
604
  if ( $fr2 ) {
690
 
691
  if( !wp_cache_writers_entry() )
692
  return false;
693
+ wp_cache_debug( "wp_cache_phase2_clean_cache: Cleaning cache in $blog_cache_dir" );
694
+ if ( $handle = @opendir( $blog_cache_dir ) ) {
695
  while ( false !== ($file = @readdir($handle))) {
696
+ if ( strpos( $file, $file_prefix ) !== false ) {
697
+ if ( strpos( $file, '.html' ) ) {
698
+ // delete old legacy files immediately
699
+ wp_cache_debug( "wp_cache_phase2_clean_cache: Deleting obsolete legacy cache+meta files: $file" );
700
+ @unlink( $blog_cache_dir . $file);
701
  @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
702
+ } else {
703
+ $meta = json_decode( wp_cache_get_legacy_cache( $blog_cache_dir . 'meta/' . $file ), true );
704
+ if ( $meta[ 'blog_id' ] == $wpdb->blogid ) {
705
+ @unlink( $blog_cache_dir . $file );
706
+ @unlink( $blog_cache_dir . 'meta/' . $file );
707
+ }
708
  }
709
  }
710
  }
717
  global $cache_max_time, $cache_path, $cache_rebuild_files, $blog_cache_dir;
718
  static $log = 0;
719
 
720
+ if ( false == @file_exists( $directory ) ) {
721
+ wp_cache_debug( "prune_super_cache: exiting as file/dir does not exist: $directory" );
722
+ return $log;
723
+ }
724
  if( !isset( $cache_max_time ) )
725
  $cache_max_time = 3600;
726
 
727
  $now = time();
728
 
729
+ $protected_directories = array( $cache_path . '.htaccess',
730
+ $cache_path . "index.html",
731
+ $cache_path . $blog_cache_dir,
732
+ $cache_path . $blog_cache_dir . "index.html",
733
+ $cache_path . $blog_cache_dir . 'meta',
734
+ $cache_path . $blog_cache_dir . 'meta/index.html',
735
+ $cache_path . 'supercache/index.html',
736
+ $cache_path . 'supercache' );
737
 
738
  $oktodelete = false;
739
  if (is_dir($directory)) {
768
  wp_cache_debug( "gc: deleted $entry, older than $cache_max_time seconds", 2 );
769
  }
770
  }
771
+ } elseif ( in_array( $entry, $protected_directories ) ) {
772
+ wp_cache_debug( "gc: could not delete $entry as it's protected.", 2 );
773
  }
774
  }
775
  closedir($dh);
776
  }
777
  } elseif( is_file($directory) && ($force || @filemtime( $directory ) + $cache_max_time <= $now ) ) {
778
  $oktodelete = true;
779
+ if ( in_array( $directory, $protected_directories ) ) {
780
+ wp_cache_debug( "gc: could not delete $directory as it's protected.", 2 );
781
  $oktodelete = false;
782
+ }
783
  if( $oktodelete && !$rename ) {
784
  wp_cache_debug( "prune_super_cache: deleted $directory", 5 );
785
  @unlink( $directory );
788
  wp_cache_debug( "prune_super_cache: wp_cache_rebuild_or_delete( $directory )", 5 );
789
  wp_cache_rebuild_or_delete( $directory );
790
  $log++;
791
+ } else {
792
+ wp_cache_debug( "prune_super_cache: did not delete file: $directory" );
793
  }
794
+ } else {
795
+ wp_cache_debug( "prune_super_cache: did not delete file as it wasn't a directory or file and not forced to delete new file: $directory" );
796
  }
797
  return $log;
798
  }
804
  if( $cache_rebuild_files && substr( $file, -14 ) != '.needs-rebuild' ) {
805
  if( @rename($file, $file . '.needs-rebuild') ) {
806
  @touch( $file . '.needs-rebuild' );
807
+ wp_cache_debug( "rebuild_or_gc: rename file to {$file}.needs-rebuild", 2 );
808
  } else {
809
  @unlink( $file );
810
  wp_cache_debug( "rebuild_or_gc: deleted $file", 2 );
823
  return false;
824
  $now = time();
825
  wp_cache_debug( "Cleaning expired cache files in $blog_cache_dir", 2 );
826
+ $deleted = 0;
827
  if ( ( $handle = @opendir( $blog_cache_dir ) ) ) {
828
  while ( false !== ($file = readdir($handle))) {
829
  if ( preg_match("/^$file_prefix/", $file) &&
830
  (@filemtime( $blog_cache_dir . $file) + $cache_max_time) <= $now ) {
831
  @unlink( $blog_cache_dir . $file );
832
  @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
833
+ wp_cache_debug( "wp_cache_phase2_clean_expired: Deleting obsolete legacy cache+meta files: $file" );
834
  continue;
835
  }
836
  if($file != '.' && $file != '..') {
837
  if( is_dir( $blog_cache_dir . $file ) == false && (@filemtime($blog_cache_dir . $file) + $cache_max_time) <= $now ) {
838
+ if ( substr( $file, -9 ) != '.htaccess' && $file != 'index.html' ) {
839
  @unlink($blog_cache_dir . $file);
840
  wp_cache_debug( "Deleting $blog_cache_dir{$file}, older than $cache_max_time seconds", 5 );
841
  }
918
  $wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: Accept-Encoding, Cookie';
919
  }
920
 
921
+ $serial = '<?php die(); ?>' . json_encode( $wp_cache_meta );
922
  if( wp_cache_writers_entry() ) {
923
  wp_cache_debug( "Writing meta file: {$blog_cache_dir}meta/{$meta_file}", 2 );
924
  if ( false == $wp_cache_object_cache ) {
1089
  // Some users are inexplicibly seeing this error on scheduled posts.
1090
  // define this constant to disable the post status check.
1091
  if ( false == defined( 'WPSCFORCEUPDATE' ) && $post->post_status != 'publish' ) {
1092
+ wp_cache_debug( "wp_cache_post_edit: draft post, not deleting any cache files. status: " . $post->post_status, 4 );
1093
  return $post_id;
1094
  }
1095
 
1119
  if( $post_id == 0 )
1120
  return;
1121
 
1122
+ $permalink = trailingslashit( str_replace( get_option( 'home' ), '', get_permalink( $post_id ) ) );
1123
  $dir = get_current_url_supercache_dir( $post_id );
1124
+ wp_cache_debug( "wp_cache_post_id_gc post_id: $post_id " . get_permalink( $post_id ) . " clearing cache in $dir.", 4 );
1125
  if ( $all == 'all' ) {
1126
  prune_super_cache( $dir, true, true );
1127
  do_action( 'gc_cache', 'prune', $permalink );
1174
  if ( $wp_cache_object_cache )
1175
  reset_oc_version();
1176
 
1177
+ $permalink = trailingslashit( str_replace( get_option( 'siteurl' ), '', get_permalink( $post_id ) ) );
1178
  if( $super_cache_enabled ) {
1179
  $dir = get_supercache_dir();
1180
+ $siteurl = trailingslashit( strtolower( preg_replace( '/:.*$/', '', str_replace( 'https://', '', str_replace( 'http://', '', get_option( 'home' ) ) ) ) ) );
1181
  // make sure the front page has a rebuild file
1182
  wp_cache_post_id_gc( $siteurl, $post_id );
1183
  if ( $all == true ) {
1184
+ wp_cache_debug( "Post change: supercache enabled: deleting cache files in " . $cache_path . 'supercache/' . $siteurl, 4 );
1185
  $files_to_check = get_all_supercache_filenames( $dir );
1186
  foreach( $files_to_check as $cache_file ) {
1187
+ wp_cache_debug( "Post change: deleting cache file: " . $dir . $cache_file, 4 );
1188
  prune_super_cache( $dir . $cache_file, true, true );
1189
  }
1190
  do_action( 'gc_cache', 'prune', 'homepage' );
1191
+ } else {
1192
+ wp_cache_debug( "wp_cache_post_change: not deleting all pages.", 4 );
1193
  }
1194
  if( $all == true && get_option( 'show_on_front' ) == 'page' ) {
1195
  wp_cache_debug( "Post change: deleting page_on_front and page_for_posts pages.", 4 );
1196
  wp_cache_debug( "Post change: page_on_front " . get_option( 'page_on_front' ), 4 );
1197
  wp_cache_post_id_gc( $siteurl, get_option( 'page_on_front' ), 'single' );
1198
+ $permalink = trailingslashit( str_replace( get_option( 'home' ), '', get_permalink( get_option( 'page_for_posts' ) ) ) );
1199
  $files_to_check = get_all_supercache_filenames( $dir . $permalink );
1200
  foreach( $files_to_check as $cache_file ) {
1201
  prune_super_cache( $dir . $permalink . $cache_file, true, true );
1202
  }
1203
  do_action( 'gc_cache', 'prune', $permalink );
1204
+ } else {
1205
+ wp_cache_debug( "wp_cache_post_change: not deleting front static page.", 4 );
1206
  }
1207
  }
1208
 
1209
+ wp_cache_debug( "wp_cache_post_change: checking {$blog_cache_dir}meta/", 4 );
1210
+ $supercache_files_deleted = false;
1211
+ if ( $handle = @opendir( $blog_cache_dir ) ) {
1212
  while ( false !== ($file = readdir($handle))) {
1213
+ if ( strpos( $file, $file_prefix ) !== false ) {
1214
+ if ( strpos( $file, '.html' ) ) {
1215
+ // delete old legacy files immediately
1216
+ wp_cache_debug( "wp_cache_post_change: Deleting obsolete legacy cache+meta files: $file" );
1217
+ @unlink( $blog_cache_dir . $file);
1218
+ @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
 
 
1219
  continue;
1220
+ } else {
1221
+ $meta = json_decode( wp_cache_get_legacy_cache( $blog_cache_dir . 'meta/' . $file ), true );
1222
+ if( false == is_array( $meta ) ) {
1223
+ wp_cache_debug( "Post change cleaning up stray file: $file", 4 );
1224
+ @unlink( $blog_cache_dir . 'meta/' . $file );
1225
+ @unlink( $blog_cache_dir . $file );
1226
+ continue;
 
 
 
 
1227
  }
1228
+ if ( $post_id > 0 && $meta ) {
1229
+ $permalink = trailingslashit( str_replace( get_option( 'home' ), '', get_permalink( $post_id ) ) );
1230
+ if ( $meta[ 'blog_id' ] == $blog_id && ( ( $all == true && !$meta[ 'post' ] ) || $meta[ 'post' ] == $post_id) ) {
1231
+ wp_cache_debug( "Post change: deleting post wp-cache files for {$meta[ 'uri' ]}: $file", 4 );
1232
+ @unlink( $blog_cache_dir . 'meta/' . $file );
1233
+ @unlink( $blog_cache_dir . $file );
1234
+ if ( false == $supercache_files_deleted && $super_cache_enabled == true ) {
1235
+ $files_to_check = get_all_supercache_filenames( $dir . $permalink );
1236
+ wp_cache_debug( "Post change: deleting supercache files for {$permalink}: $file " . print_r( $files_to_check, 1 ), 4 );
1237
+ foreach( $files_to_check as $cache_file ) {
1238
+ @wp_cache_rebuild_or_delete( $dir . trailingslashit( $permalink ) . $cache_file );
1239
+ }
1240
+ $supercache_files_deleted = true;
1241
+ do_action( 'gc_cache', 'rebuild', $permalink );
1242
+ }
1243
+ }
1244
+ } elseif ( $meta[ 'blog_id' ] == $blog_id ) {
1245
+ wp_cache_debug( "Post change: deleting wp-cache files for {$meta[ 'uri' ]}: $file", 4 );
1246
+ @unlink( $blog_cache_dir . 'meta/' . $file );
1247
+ @unlink( $blog_cache_dir . $file );
1248
+ if ( $super_cache_enabled == true ) {
1249
+ $files_to_check = get_all_supercache_filenames( $dir . $meta[ 'uri' ] );
1250
+ wp_cache_debug( "Post change: deleting supercache files for {$meta[ 'uri' ]}: $file " . print_r( $files_to_check, 1 ), 4 );
1251
+ foreach( $files_to_check as $cache_file ) {
1252
+ @wp_cache_rebuild_or_delete( $dir . trailingslashit( $meta[ 'uri' ] ) . $cache_file );
1253
+ }
1254
+ do_action( 'gc_cache', 'rebuild', trailingslashit( $meta[ 'uri' ] ) );
1255
  }
 
1256
  }
1257
  }
 
1258
  }
1259
  }
1260
  closedir($handle);
1344
 
1345
  $msg = "Hi,\n\nThe WP Super Cache Garbage Collector has now run, deleting " . (int)$num . " files and directories.\nIf you want to switch off these emails please see the WP Super Cache Advanced Settings\npage on your blog.\n\n{$msg}\nRegards,\nThe Garbage Collector.";
1346
 
1347
+ wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] WP Super Cache GC Report', 'wp-super-cache' ), home_url() ), $msg );
1348
  }
1349
  @unlink( $gc_flag );
1350
  wp_cache_debug( 'GC completed. GC flag deleted.', 5 );
wp-cache.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP Super Cache
4
  Plugin URI: http://wordpress.org/plugins/wp-super-cache/
5
  Description: Very fast caching plugin for WordPress.
6
- Version: 1.4.4
7
  Author: Automattic
8
  Author URI: http://automattic.com/
9
  License: GPL2+
@@ -113,16 +113,19 @@ function get_wpcachehome() {
113
  }
114
  }
115
 
116
- function wpsupercache_deactivate() {
117
  global $wp_cache_config_file, $wp_cache_link, $cache_path;
118
  $files = array( $wp_cache_config_file, $wp_cache_link );
119
  foreach( $files as $file ) {
120
- if( file_exists( $file ) )
121
  unlink( $file );
122
  }
123
- if( !function_exists( 'prune_super_cache' ) )
 
 
124
  include_once( 'wp-cache-phase2.php' );
125
- prune_super_cache ($cache_path, true);
 
126
  @unlink( $cache_path . '.htaccess' );
127
  @unlink( $cache_path . 'meta' );
128
  @unlink( $cache_path . 'supercache' );
@@ -130,10 +133,33 @@ function wpsupercache_deactivate() {
130
  wp_clear_scheduled_hook( 'wp_cache_gc' );
131
  wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
132
  wp_cache_disable_plugin();
 
133
  }
134
- register_uninstall_hook( __FILE__, 'wpsupercache_deactivate' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
 
136
  function wpsupercache_activate() {
 
137
  }
138
  register_activation_hook( __FILE__, 'wpsupercache_activate' );
139
 
@@ -396,7 +422,11 @@ function admin_bar_delete_page() {
396
  if ( function_exists('current_user_can') && false == current_user_can('delete_others_posts') )
397
  return false;
398
  if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'delcachepage' && ( isset( $_GET[ '_wpnonce' ] ) ? wp_verify_nonce( $_REQUEST[ '_wpnonce' ], 'delete-cache' ) : false ) ) {
399
- $path = trailingslashit( get_supercache_dir() . preg_replace( '/:.*$/', '', $_GET[ 'path' ] ) );
 
 
 
 
400
  $files = get_all_supercache_filenames( $path );
401
  foreach( $files as $cache_file )
402
  prune_super_cache( $path . $cache_file, true );
@@ -432,6 +462,8 @@ function wp_cache_manager_updates() {
432
  $_POST[ 'super_cache_enabled' ] = 2; // PHP
433
  $_POST[ 'cache_rebuild_files' ] = 1;
434
  unset( $_POST[ 'cache_compression' ] );
 
 
435
  //
436
  // set up garbage collection with some default settings
437
  if ( ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) {
@@ -453,9 +485,31 @@ function wp_cache_manager_updates() {
453
  wp_clear_scheduled_hook( 'wp_cache_gc' );
454
  wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
455
  }
 
 
 
 
 
 
456
  }
457
 
458
  if( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'scupdates' ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
459
 
460
  if( isset( $_POST[ 'wp_super_cache_late_init' ] ) ) {
461
  $wp_super_cache_late_init = 1;
@@ -947,8 +1001,8 @@ jQuery(document).ready(function(){
947
  <fieldset>
948
  <legend class="hidden">Caching</legend>
949
  <label><input type='checkbox' name='wp_cache_status' value='all' <?php if ( $cache_enabled == true ) { echo 'checked=checked'; } ?>> <?php _e( 'Cache hits to this website for quick access.', 'wp-super-cache' ); echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?></label><br /><br />
950
- <label><input type='radio' name='super_cache_enabled' <?php if( $super_cache_enabled ) echo "checked"; ?> value='1'> <?php printf( __( 'Use mod_rewrite to serve cache files.', 'wp-super-cache' ), 'http://wordpress.org/plugins/wordpress-mobile-edition/' ); echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?></label><br />
951
- <label><input type='radio' name='super_cache_enabled' <?php if( $wp_cache_mod_rewrite == 0 ) echo "checked"; ?> value='2'> <?php printf( __( 'Use PHP to serve cache files.', 'wp-super-cache' ), 'http://wordpress.org/plugins/wordpress-mobile-edition/' ); ?></label><br />
952
  <label><input type='radio' name='super_cache_enabled' <?php if( $super_cache_enabled == false ) echo "checked"; ?> value='0'> <?php _e( 'Legacy page caching.', 'wp-super-cache' ); ?></label><br />
953
  <em><?php _e( 'Mod_rewrite is fastest, PHP is almost as fast and easier to get working, while legacy caching is slower again, but more flexible and also easy to get working. New users should use PHP caching.', 'wp-super-cache' ); ?></em><br />
954
  </legend>
@@ -1012,7 +1066,36 @@ jQuery(document).ready(function(){
1012
  ?><label><input type='checkbox' name='wp_cache_object_cache' <?php if( $wp_cache_object_cache ) echo "checked"; ?> value='1'> <?php echo __( 'Use object cache to store cached files.', 'wp-super-cache' ) . ' ' . __( '(Experimental)', 'wp-super-cache' ); ?></label><?php
1013
  }?>
1014
  <?php printf( __( '<strong>DO NOT CACHE PAGE</strong> secret key: <a href="%s">%s</a>', 'wp-super-cache' ), trailingslashit( get_bloginfo( 'url' ) ) . "?donotcachepage={$cache_page_secret}", $cache_page_secret ); ?>
1015
- </legend>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1016
  </fieldset>
1017
  </td>
1018
  </tr>
@@ -1459,7 +1542,7 @@ function wp_lock_down() {
1459
  if( substr( $page, 0, 1 ) != '/' )
1460
  $page = '/' . $page;
1461
  $page = esc_sql( $page );
1462
- if( in_array( $page, $cached_direct_pages ) == false ) {
1463
  $cached_direct_pages[] = $page;
1464
  $out .= "'$page', ";
1465
  }
@@ -1486,8 +1569,11 @@ function wp_lock_down() {
1486
  }
1487
 
1488
  if( $valid_nonce && array_key_exists('deletepage', $_POST) && $_POST[ 'deletepage' ] ) {
1489
- $page = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_POST['deletepage']) );
1490
- $pagefile = ABSPATH . $page . 'index.html';
 
 
 
1491
  $firstfolder = explode( '/', $page );
1492
  $firstfolder = ABSPATH . $firstfolder[1];
1493
  $page = ABSPATH . $page;
@@ -1567,67 +1653,71 @@ function wp_cache_edit_max_time () {
1567
  global $cache_max_time, $wp_cache_config_file, $valid_nonce, $cache_enabled, $super_cache_enabled, $cache_schedule_type, $cache_scheduled_time, $cache_schedule_interval, $cache_time_interval, $cache_gc_email_me, $wp_cache_preload_on;
1568
 
1569
  $timezone_format = _x('Y-m-d G:i:s', 'timezone date format');
 
 
1570
 
1571
- if( !isset( $cache_schedule_type ) ) {
1572
- $cache_schedule_type = 'interval';
1573
- wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
1574
- }
1575
-
1576
- if( !isset( $cache_scheduled_time ) ) {
1577
- $cache_scheduled_time = '00:00';
1578
- wp_cache_replace_line('^ *\$cache_scheduled_time', "\$cache_scheduled_time = '$cache_scheduled_time';", $wp_cache_config_file);
1579
- }
1580
-
1581
- if( !isset( $cache_max_time ) ) {
1582
- $cache_max_time = 3600;
1583
- wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file);
1584
- }
1585
-
1586
- if ( !isset( $cache_time_interval ) ) {
1587
- $cache_time_interval = $cache_max_time;
1588
- wp_cache_replace_line('^ *\$cache_time_interval', "\$cache_time_interval = '$cache_time_interval';", $wp_cache_config_file);
1589
- }
1590
-
1591
- if ( isset( $_POST['wp_max_time'] ) && $valid_nonce ) {
1592
- $cache_max_time = (int)$_POST['wp_max_time'];
1593
- wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file);
1594
- // schedule gc watcher
1595
- if ( false == wp_next_scheduled( 'wp_cache_gc_watcher' ) )
1596
- wp_schedule_event( time()+600, 'hourly', 'wp_cache_gc_watcher' );
1597
- }
1598
-
1599
- if ( isset( $_POST[ 'cache_gc_email_me' ] ) && $valid_nonce ) {
1600
- $cache_gc_email_me = 1;
1601
- wp_cache_replace_line('^ *\$cache_gc_email_me', "\$cache_gc_email_me = $cache_gc_email_me;", $wp_cache_config_file);
1602
- } elseif ( $valid_nonce ) {
1603
- $cache_gc_email_me = 0;
1604
- wp_cache_replace_line('^ *\$cache_gc_email_me', "\$cache_gc_email_me = $cache_gc_email_me;", $wp_cache_config_file);
1605
- }
1606
- if ( isset( $_POST[ 'cache_schedule_type' ] ) && $_POST[ 'cache_schedule_type' ] == 'interval' && isset( $_POST['cache_time_interval'] ) && $valid_nonce ) {
1607
- wp_clear_scheduled_hook( 'wp_cache_gc' );
1608
- $cache_schedule_type = 'interval';
1609
- if ( (int)$_POST[ 'cache_time_interval' ] == 0 )
1610
- $_POST[ 'cache_time_interval' ] = 600;
1611
- $cache_time_interval = (int)$_POST[ 'cache_time_interval' ];
1612
- wp_schedule_single_event( time() + $cache_time_interval, 'wp_cache_gc' );
1613
- wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
1614
- wp_cache_replace_line('^ *\$cache_time_interval', "\$cache_time_interval = '$cache_time_interval';", $wp_cache_config_file);
1615
- } elseif ( $valid_nonce ) { // clock
1616
- wp_clear_scheduled_hook( 'wp_cache_gc' );
1617
- $cache_schedule_type = 'time';
1618
- if ( !isset( $_POST[ 'cache_scheduled_time' ] ) || $_POST[ 'cache_scheduled_time' ] == '' )
1619
- $_POST[ 'cache_scheduled_time' ] = '00:00';
1620
- $cache_scheduled_time = $_POST[ 'cache_scheduled_time' ];
1621
- $schedules = wp_get_schedules();
1622
- if ( !isset( $cache_schedule_interval ) )
1623
- $cache_schedule_interval = 'daily';
1624
- if ( isset( $schedules[ $_POST[ 'cache_schedule_interval' ] ] ) )
1625
- $cache_schedule_interval = $_POST[ 'cache_schedule_interval' ];
1626
- wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
1627
- wp_cache_replace_line('^ *\$cache_schedule_interval', "\$cache_schedule_interval = '{$cache_schedule_interval}';", $wp_cache_config_file);
1628
- wp_cache_replace_line('^ *\$cache_scheduled_time', "\$cache_scheduled_time = '$cache_scheduled_time';", $wp_cache_config_file);
1629
- wp_schedule_event( strtotime( $cache_scheduled_time ), $cache_schedule_interval, 'wp_cache_gc' );
 
1630
  }
 
1631
  ?><fieldset class="options">
1632
  <a name='expirytime'></a>
1633
  <h3><?php _e( 'Expiry Time &amp; Garbage Collection', 'wp-super-cache' ); ?></h3><?php
@@ -1659,6 +1749,7 @@ function wp_cache_edit_max_time () {
1659
  });";
1660
  echo "</script>";
1661
  echo '<form name="wp_edit_max_time" action="#expirytime" method="post">';
 
1662
  echo '<table class="form-table">';
1663
  echo '<tr><td><label for="wp_max_time"><strong>' . __( 'Cache Timeout', 'wp-super-cache' ) . '</strong></label></td>';
1664
  echo "<td><input type='text' id='wp_max_time' size=6 name='wp_max_time' value='$cache_max_time' /> " . __( "seconds", 'wp-super-cache' ) . "</td></tr>\n";
@@ -2013,6 +2104,163 @@ function wp_cache_replace_line($old, $new, $my_file) {
2013
  return true;
2014
  }
2015
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2016
  function wp_cache_verify_cache_dir() {
2017
  global $cache_path, $blog_cache_dir, $blogcacheid;
2018
 
@@ -2041,6 +2289,7 @@ function wp_cache_verify_cache_dir() {
2041
  if( false == is_dir( $blog_cache_dir . 'meta' ) )
2042
  @mkdir( $blog_cache_dir . 'meta' );
2043
 
 
2044
  return true;
2045
  }
2046
 
@@ -2212,38 +2461,43 @@ function wp_cache_files() {
2212
  $count = 0;
2213
  $expired = 0;
2214
  $now = time();
2215
- if ( ($handle = @opendir( $blog_cache_dir . 'meta/' )) ) {
2216
  $wp_cache_fsize = 0;
2217
  if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletewpcache' ) {
2218
- $deleteuri = preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '/index.php', '/', str_replace( '..', '', preg_replace("/(\?.*)?$/", '', base64_decode( $_GET[ 'uri' ] ) ) ) ) );
2219
- $deleteuri = str_replace( '\\', '', $deleteuri );
2220
  } else {
2221
  $deleteuri = '';
2222
  }
2223
 
2224
  if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletesupercache' ) {
2225
- $supercacheuri = preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '/index.php', '/', str_replace( '..', '', preg_replace("/(\?.*)?$/", '', base64_decode( $_GET[ 'uri' ] ) ) ) ) );
2226
- $supercacheuri = trailingslashit( str_replace( '\\', '', $supercacheuri ) );
2227
- printf( __( "Deleting supercache file: <strong>%s</strong><br />", 'wp-super-cache' ), $supercacheuri );
2228
- @unlink( $cache_path . 'supercache/' . $supercacheuri . 'index.html' );
2229
- @unlink( $cache_path . 'supercache/' . $supercacheuri . 'index.html.gz' );
2230
- prune_super_cache( $cache_path . 'supercache/' . $supercacheuri . 'page', true );
2231
- @rmdir( $cache_path . 'supercache/' . $supercacheuri );
2232
- }
2233
- while( false !== ($file = readdir($handle))) {
2234
- if ( preg_match("/^$file_prefix.*\.meta/", $file) ) {
2235
- $content_file = preg_replace("/meta$/", "html", $file);
 
 
 
 
 
2236
  $mtime = filemtime( $blog_cache_dir . 'meta/' . $file );
2237
- if ( ! ( $fsize = @filesize( $blog_cache_dir . $content_file ) ) )
2238
- continue; // .meta does not exists
 
2239
 
2240
  $age = $now - $mtime;
2241
  if ( $valid_nonce && isset( $_GET[ 'listfiles' ] ) ) {
2242
- $meta = unserialize( file_get_contents( $blog_cache_dir . 'meta/' . $file ) );
2243
  if ( $deleteuri != '' && $meta[ 'uri' ] == $deleteuri ) {
2244
- printf( __( "Deleting wp-cache file: <strong>%s</strong><br />", 'wp-super-cache' ), $deleteuri );
2245
  @unlink( $blog_cache_dir . 'meta/' . $file );
2246
- @unlink( $blog_cache_dir . $content_file );
2247
  continue;
2248
  }
2249
  $meta[ 'age' ] = $age;
@@ -2297,10 +2551,10 @@ function wp_cache_files() {
2297
  $filem = @filemtime( $supercachedir );
2298
  if ( false == $wp_cache_preload_on && is_file( $supercachedir ) && $cache_max_time > 0 && $filem + $cache_max_time <= $now ) {
2299
  $sizes[ 'expired' ] ++;
2300
- if ( $valid_nonce && $_GET[ 'listfiles' ] )
2301
  $sizes[ 'expired_list' ][ str_replace( $cache_path . 'supercache/' , '', $supercachedir ) ] = $now - $filem;
2302
  } else {
2303
- if ( $valid_nonce && $_GET[ 'listfiles' ] && $filem )
2304
  $sizes[ 'cached_list' ][ str_replace( $cache_path . 'supercache/' , '', $supercachedir ) ] = $now - $filem;
2305
  }
2306
  }
@@ -2516,14 +2770,29 @@ function wp_cache_clean_cache( $file_prefix, $all = false ) {
2516
 
2517
  function wp_cache_clean_legacy_files( $dir, $file_prefix ) {
2518
  global $wpdb;
2519
- if ( $handle = @opendir( $dir . 'meta/' ) ) {
2520
- while ( false !== ($file = readdir($handle))) {
2521
- if ( preg_match( "/^$file_prefix/", $file ) ) {
2522
- $meta = unserialize( file_get_contents( $dir . 'meta/' . $file ) );
2523
- if ( ( defined( 'VHOST' ) || ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) ) && $meta[ 'blog_id' ] != $wpdb->blogid )
2524
- continue;
2525
- @unlink( $dir . 'meta/' . $file);
2526
- @unlink( $dir . str_replace( '.meta', '.html', $file ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2527
  }
2528
  }
2529
  closedir($handle);
@@ -2551,14 +2820,17 @@ function wp_cache_clean_expired($file_prefix) {
2551
  return wp_cache_phase2_clean_expired($file_prefix);
2552
  }
2553
 
2554
- $expr = "/^$file_prefix/";
2555
  $now = time();
2556
- if ( ($handle = @opendir( $blog_cache_dir )) ) {
2557
- while ( false !== ($file = readdir($handle))) {
2558
- if ( preg_match( $expr, $file ) &&
2559
- ( filemtime( $blog_cache_dir . $file ) + $cache_max_time ) <= $now ) {
2560
- @unlink( $blog_cache_dir . $file );
2561
- @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
 
 
 
 
2562
  }
2563
  }
2564
  closedir($handle);
@@ -2657,7 +2929,7 @@ function wp_cache_admin_notice() {
2657
  add_action( 'admin_notices', 'wp_cache_admin_notice' );
2658
 
2659
  function wp_cache_check_site() {
2660
- global $wp_super_cache_front_page_check, $wp_super_cache_front_page_clear, $wp_super_cache_front_page_text, $wp_super_cache_front_page_notification;
2661
 
2662
  if ( !isset( $wp_super_cache_front_page_check ) || ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 0 ) ) {
2663
  return false;
@@ -2671,25 +2943,25 @@ function wp_cache_check_site() {
2671
  // Check for gzipped front page
2672
  if ( $front_page[ 'headers' ][ 'content-type' ] == 'application/x-gzip' ) {
2673
  if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) {
2674
- wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Please clear cache!', 'wp-super-cache' ), site_url() ), sprintf( __( "Please visit %s to clear the cache as the front page of your site is now downloading!", 'wp-super-cache' ), trailingslashit( site_url() ) . "wp-admin/options-general.php?page=wpsupercache" ) );
2675
  } else {
2676
- wp_cache_clear_cache( get_current_blog_id() );
2677
- wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Cache Cleared!', 'wp-super-cache' ), site_url() ), sprintf( __( "The cache on your blog has been cleared because the front page of your site is now downloading. Please visit %s to verify the cache has been cleared.", 'wp-super-cache' ), trailingslashit( site_url() ) . "wp-admin/options-general.php?page=wpsupercache" ) );
2678
  }
2679
  }
2680
 
2681
  // Check for broken front page
2682
  if ( isset( $wp_super_cache_front_page_text ) && $wp_super_cache_front_page_text != '' && false === strpos( $front_page[ 'body' ], $wp_super_cache_front_page_text ) ) {
2683
  if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) {
2684
- wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is not correct! Please clear cache!', 'wp-super-cache' ), site_url() ), sprintf( __( 'Please visit %1$s to clear the cache as the front page of your site is not correct and missing the text, "%2$s"!', 'wp-super-cache' ), trailingslashit( site_url() ) . "wp-admin/options-general.php?page=wpsupercache", $wp_super_cache_front_page_text ) );
2685
  } else {
2686
- wp_cache_clear_cache( get_current_blog_id() );
2687
- wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is not correct! Cache Cleared!', 'wp-super-cache' ), site_url() ), sprintf( __( 'The cache on your blog has been cleared because the front page of your site is missing the text "%2$s". Please visit %1$s to verify the cache has been cleared.', 'wp-super-cache' ), trailingslashit( site_url() ) . "wp-admin/options-general.php?page=wpsupercache", $wp_super_cache_front_page_text ) );
2688
  }
2689
  }
2690
  }
2691
  if ( isset( $wp_super_cache_front_page_notification ) && $wp_super_cache_front_page_notification == 1 ) {
2692
- wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page check!', 'wp-super-cache' ), site_url() ), sprintf( __( "WP Super Cache has checked the front page of your blog. Please visit %s if you would like to disable this.", 'wp-super-cache' ) . "\n\n", trailingslashit( site_url() ) . "wp-admin/options-general.php?page=wpsupercache#debug" ) . print_r( $front_page, 1 ) );
2693
  }
2694
 
2695
  if ( !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
@@ -2774,7 +3046,7 @@ function wpsc_get_htaccess_info() {
2774
  $apache_root = '%{DOCUMENT_ROOT}';
2775
  }
2776
  $content_dir_root = $document_root;
2777
- if ( strpos( $document_root, '/kunden/' ) === 0 ) {
2778
  // http://wordpress.org/support/topic/plugin-wp-super-cache-how-to-get-mod_rewrite-working-on-1and1-shared-hosting?replies=1
2779
  // On 1and1, PHP's directory structure starts with '/homepages'. The
2780
  // Apache directory structure has an extra '/kunden' before it.
@@ -2857,6 +3129,7 @@ function wpsc_get_htaccess_info() {
2857
  $gziprules .= "<IfModule mod_deflate.c>\n SetEnvIfNoCase Request_URI \.gz$ no-gzip\n</IfModule>\n";
2858
  $gziprules .= "<IfModule mod_headers.c>\n Header set Vary \"Accept-Encoding, Cookie\"\n Header set Cache-Control 'max-age=3, must-revalidate'\n</IfModule>\n";
2859
  $gziprules .= "<IfModule mod_expires.c>\n ExpiresActive On\n ExpiresByType text/html A3\n</IfModule>\n";
 
2860
  return array( "document_root" => $document_root, "apache_root" => $apache_root, "home_path" => $home_path, "home_root" => $home_root, "home_root_lc" => $home_root_lc, "inst_root" => $inst_root, "wprules" => $wprules, "scrules" => $scrules, "condition_rules" => $condition_rules, "rules" => $rules, "gziprules" => $gziprules );
2861
  }
2862
 
@@ -2877,7 +3150,6 @@ function clear_post_supercache( $post_id ) {
2877
 
2878
  function wp_cron_preload_cache() {
2879
  global $wpdb, $wp_cache_preload_interval, $wp_cache_preload_posts, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $cache_path, $wp_cache_preload_taxonomies;
2880
- global $WPSC_HTTP_HOST;
2881
 
2882
  if ( get_option( 'preload_cache_stop' ) ) {
2883
  delete_option( 'preload_cache_stop' );
@@ -2909,7 +3181,7 @@ function wp_cron_preload_cache() {
2909
  update_option( 'preload_cache_counter', array( 'c' => ( $c + 100 ), 't' => time() ) );
2910
 
2911
  if ( $wp_cache_preload_email_me && $c == 0 )
2912
- wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Started', 'wp-super-cache' ), site_url(), '' ), ' ' );
2913
 
2914
  if ( $wp_cache_preload_posts == 'all' || $c < $wp_cache_preload_posts ) {
2915
  wp_cache_debug( "wp_cron_preload_cache: doing taxonomy preload.", 5 );
@@ -2939,7 +3211,7 @@ function wp_cron_preload_cache() {
2939
  if ( count( $details ) != 1 && $details[ 0 ] != '' ) {
2940
  $rows = array_splice( $details, 0, 50 );
2941
  if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume == 'many' )
2942
- wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Refreshing %2$s taxonomy from %3$d to %4$d', 'wp-super-cache' ), site_url(), $taxonomy, $c, ($c+100) ), 'Refreshing: ' . print_r( $rows, 1 ) );
2943
  foreach( (array)$rows as $url ) {
2944
  set_time_limit( 60 );
2945
  if ( $url == '' )
@@ -2968,7 +3240,10 @@ function wp_cron_preload_cache() {
2968
  }
2969
 
2970
  if ( $wp_cache_preload_posts == 'all' || $c < $wp_cache_preload_posts ) {
2971
- $posts = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE ( post_type != 'revision' AND post_type != 'nav_menu_item' ) AND post_status = 'publish' ORDER BY ID ASC LIMIT $c, 100" );
 
 
 
2972
  wp_cache_debug( "wp_cron_preload_cache: got 100 posts from position $c.", 5 );
2973
  } else {
2974
  wp_cache_debug( "wp_cron_preload_cache: no more posts to get. Limit ($wp_cache_preload_posts) reached.", 5 );
@@ -2985,7 +3260,7 @@ function wp_cron_preload_cache() {
2985
  $page_on_front = $page_for_posts = 0;
2986
  }
2987
  if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume == 'many' )
2988
- wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Refreshing posts from %2$d to %3$d', 'wp-super-cache' ), site_url(), $c, ($c+100) ), ' ' );
2989
  $msg = '';
2990
  $count = $c + 1;
2991
  $permalink_counter_msg = $cache_path . "preload_permalink.txt";
@@ -3006,7 +3281,7 @@ function wp_cron_preload_cache() {
3006
  @unlink( $cache_path . "stop_preload.txt" );
3007
  update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
3008
  if ( $wp_cache_preload_email_me )
3009
- wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Stopped', 'wp-super-cache' ), site_url(), '' ), ' ' );
3010
  return true;
3011
  }
3012
  $msg .= "$url\n";
@@ -3016,7 +3291,7 @@ function wp_cron_preload_cache() {
3016
  $count++;
3017
  }
3018
  if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume != 'less' )
3019
- wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] %2$d posts refreshed', 'wp-super-cache' ), $WPSC_HTTP_HOST, ($c+100) ), __( "Refreshed the following posts:", 'wp-super-cache' ) . "\n$msg" );
3020
  if ( defined( 'DOING_CRON' ) ) {
3021
  wp_cache_debug( "wp_cron_preload_cache: scheduling the next preload in 30 seconds.", 5 );
3022
  wp_schedule_single_event( time() + 30, 'wp_cache_preload_hook' );
@@ -3037,7 +3312,7 @@ function wp_cron_preload_cache() {
3037
  $cache_max_time = 86400; // fool the GC into expiring really old files
3038
  }
3039
  if ( $wp_cache_preload_email_me )
3040
- wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Cache Preload Completed', 'wp-super-cache' ), site_url() ), __( "Cleaning up old supercache files.", 'wp-super-cache' ) . "\n" . $msg );
3041
  wp_cache_debug( "wp_cron_preload_cache: clean expired cache files older than $cache_max_time seconds.", 5 );
3042
  wp_cache_phase2_clean_expired( $file_prefix, true ); // force cleanup of old files.
3043
  }
@@ -3086,7 +3361,7 @@ function check_up_on_preloading() {
3086
  }
3087
  add_action( 'init', 'check_up_on_preloading' ); // sometimes preloading stops working. Kickstart it.
3088
 
3089
- function wp_cache_disable_plugin() {
3090
  global $wp_cache_config_file, $wp_rewrite;
3091
  if ( file_exists( ABSPATH . 'wp-config.php') ) {
3092
  $global_config_file = ABSPATH . 'wp-config.php';
@@ -3103,7 +3378,7 @@ function wp_cache_disable_plugin() {
3103
  if ( false == @unlink( WP_CONTENT_DIR . "/advanced-cache.php" ) )
3104
  $file_not_deleted[] = 'advanced-cache.php';
3105
  }
3106
- if ( @file_exists( WP_CONTENT_DIR . "/wp-cache-config.php" ) ) {
3107
  if ( false == unlink( WP_CONTENT_DIR . "/wp-cache-config.php" ) )
3108
  $file_not_deleted[] = 'wp-cache-config.php';
3109
  }
3
  Plugin Name: WP Super Cache
4
  Plugin URI: http://wordpress.org/plugins/wp-super-cache/
5
  Description: Very fast caching plugin for WordPress.
6
+ Version: 1.4.5
7
  Author: Automattic
8
  Author URI: http://automattic.com/
9
  License: GPL2+
113
  }
114
  }
115
 
116
+ function wpsupercache_uninstall() {
117
  global $wp_cache_config_file, $wp_cache_link, $cache_path;
118
  $files = array( $wp_cache_config_file, $wp_cache_link );
119
  foreach( $files as $file ) {
120
+ if ( file_exists( $file ) )
121
  unlink( $file );
122
  }
123
+ if ( !function_exists( 'wp_cache_debug' ) )
124
+ include_once( 'wp-cache-phase1.php' );
125
+ if ( !function_exists( 'prune_super_cache' ) )
126
  include_once( 'wp-cache-phase2.php' );
127
+ prune_super_cache( $cache_path, true );
128
+ wp_cache_remove_index();
129
  @unlink( $cache_path . '.htaccess' );
130
  @unlink( $cache_path . 'meta' );
131
  @unlink( $cache_path . 'supercache' );
133
  wp_clear_scheduled_hook( 'wp_cache_gc' );
134
  wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
135
  wp_cache_disable_plugin();
136
+ delete_site_option( 'wp_super_cache_index_detected' );
137
  }
138
+ register_uninstall_hook( __FILE__, 'wpsupercache_uninstall' );
139
+
140
+ function wpsupercache_deactivate() {
141
+ global $wp_cache_config_file, $wp_cache_link, $cache_path;
142
+ if ( file_exists( $wp_cache_link ) )
143
+ unlink( $wp_cache_link );
144
+ if ( !function_exists( 'wp_cache_debug' ) )
145
+ include_once( 'wp-cache-phase1.php' );
146
+ if ( !function_exists( 'prune_super_cache' ) )
147
+ include_once( 'wp-cache-phase2.php' );
148
+ prune_super_cache( $cache_path, true );
149
+ wp_cache_remove_index();
150
+ @unlink( $cache_path . '.htaccess' );
151
+ @unlink( $cache_path . 'meta' );
152
+ @unlink( $cache_path . 'supercache' );
153
+ wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
154
+ wp_clear_scheduled_hook( 'wp_cache_gc' );
155
+ wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
156
+ wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file);
157
+ wp_cache_disable_plugin( false ); // don't delete configuration file
158
+ }
159
+ register_deactivation_hook( __FILE__, 'wpsupercache_deactivate' );
160
 
161
  function wpsupercache_activate() {
162
+ wp_schedule_single_event( time() + 10, 'wp_cache_add_site_cache_index' );
163
  }
164
  register_activation_hook( __FILE__, 'wpsupercache_activate' );
165
 
422
  if ( function_exists('current_user_can') && false == current_user_can('delete_others_posts') )
423
  return false;
424
  if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'delcachepage' && ( isset( $_GET[ '_wpnonce' ] ) ? wp_verify_nonce( $_REQUEST[ '_wpnonce' ], 'delete-cache' ) : false ) ) {
425
+ $path = realpath( trailingslashit( get_supercache_dir() . str_replace( '..', '', preg_replace( '/:.*$/', '', $_GET[ 'path' ] ) ) ) ) . '/';
426
+ if ( $path == '/' )
427
+ return false; // Directory not found. Probably not cached.
428
+ if ( false == wp_cache_confirm_delete( $path ) || substr( $path, 0, strlen( get_supercache_dir() ) ) != get_supercache_dir() )
429
+ die( "Could not delete directory" );
430
  $files = get_all_supercache_filenames( $path );
431
  foreach( $files as $cache_file )
432
  prune_super_cache( $path . $cache_file, true );
462
  $_POST[ 'super_cache_enabled' ] = 2; // PHP
463
  $_POST[ 'cache_rebuild_files' ] = 1;
464
  unset( $_POST[ 'cache_compression' ] );
465
+ if ( $cache_path != WP_CONTENT_DIR . '/cache/' )
466
+ $_POST[ 'wp_cache_location' ] = $cache_path;
467
  //
468
  // set up garbage collection with some default settings
469
  if ( ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) {
485
  wp_clear_scheduled_hook( 'wp_cache_gc' );
486
  wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
487
  }
488
+ $advanced_settings = array( 'wp_super_cache_late_init', 'wp_cache_disable_utf8', 'wp_cache_no_cache_for_get', 'wp_supercache_304', 'wp_cache_mfunc_enabled', 'wp_cache_mobile_enabled', 'wp_cache_front_page_checks', 'wp_supercache_cache_list', 'wp_cache_hello_world', 'wp_cache_clear_on_post_edit', 'wp_cache_not_logged_in', 'wp_cache_make_known_anon','wp_cache_object_cache', 'wp_cache_refresh_single_only', 'cache_compression', 'wp_cache_mutex_disabled' );
489
+ foreach( $advanced_settings as $setting ) {
490
+ if ( isset( $$setting ) && $$setting == 1 ) {
491
+ $_POST[ $setting ] = 1;
492
+ }
493
+ }
494
  }
495
 
496
  if( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'scupdates' ) {
497
+ if( isset( $_POST[ 'wp_cache_location' ] ) && $_POST[ 'wp_cache_location' ] != '' ) {
498
+ $dir = realpath( trailingslashit( dirname( $_POST[ 'wp_cache_location' ] ) ) );
499
+ if ( $dir == false )
500
+ $dir = WP_CONTENT_DIR . '/cache/';
501
+ else
502
+ $dir = trailingslashit( $dir ) . wpsc_deep_replace( array( '..', '\\' ), basename( $_POST[ 'wp_cache_location' ] ) );
503
+ $new_cache_path = $dir;
504
+ } else {
505
+ $new_cache_path = WP_CONTENT_DIR . '/cache/';
506
+ }
507
+ if ( $new_cache_path != $cache_path ) {
508
+ if ( file_exists( $new_cache_path ) == false )
509
+ rename( $cache_path, $new_cache_path );
510
+ $cache_path = $new_cache_path;
511
+ wp_cache_replace_line('^ *\$cache_path', "\$cache_path = '" . $cache_path . "';", $wp_cache_config_file);
512
+ }
513
 
514
  if( isset( $_POST[ 'wp_super_cache_late_init' ] ) ) {
515
  $wp_super_cache_late_init = 1;
1001
  <fieldset>
1002
  <legend class="hidden">Caching</legend>
1003
  <label><input type='checkbox' name='wp_cache_status' value='all' <?php if ( $cache_enabled == true ) { echo 'checked=checked'; } ?>> <?php _e( 'Cache hits to this website for quick access.', 'wp-super-cache' ); echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?></label><br /><br />
1004
+ <label><input type='radio' name='super_cache_enabled' <?php if( $super_cache_enabled && $wp_cache_mod_rewrite == 1 ) echo "checked"; ?> value='1'> <?php _e( 'Use mod_rewrite to serve cache files.', 'wp-super-cache' ); ?></label><br />
1005
+ <label><input type='radio' name='super_cache_enabled' <?php if( $wp_cache_mod_rewrite == 0 ) echo "checked"; ?> value='2'> <?php _e( 'Use PHP to serve cache files.', 'wp-super-cache' ); echo " <em>(" . __( "Recommended", "wp-super-cache" ) . ")</em>"; ?></label><br />
1006
  <label><input type='radio' name='super_cache_enabled' <?php if( $super_cache_enabled == false ) echo "checked"; ?> value='0'> <?php _e( 'Legacy page caching.', 'wp-super-cache' ); ?></label><br />
1007
  <em><?php _e( 'Mod_rewrite is fastest, PHP is almost as fast and easier to get working, while legacy caching is slower again, but more flexible and also easy to get working. New users should use PHP caching.', 'wp-super-cache' ); ?></em><br />
1008
  </legend>
1066
  ?><label><input type='checkbox' name='wp_cache_object_cache' <?php if( $wp_cache_object_cache ) echo "checked"; ?> value='1'> <?php echo __( 'Use object cache to store cached files.', 'wp-super-cache' ) . ' ' . __( '(Experimental)', 'wp-super-cache' ); ?></label><?php
1067
  }?>
1068
  <?php printf( __( '<strong>DO NOT CACHE PAGE</strong> secret key: <a href="%s">%s</a>', 'wp-super-cache' ), trailingslashit( get_bloginfo( 'url' ) ) . "?donotcachepage={$cache_page_secret}", $cache_page_secret ); ?>
1069
+ </fieldset>
1070
+ </td>
1071
+ </tr>
1072
+ <tr valign="top">
1073
+ <th scope="row"><label for="wp_cache_location"><?php _e( 'Cache Location', 'wp-super-cache' ); ?></label></th>
1074
+ <td>
1075
+ <fieldset>
1076
+ <legend class="hidden">Cache Location</legend>
1077
+ <input type='text' size=80 name='wp_cache_location' value='<?php echo esc_attr( $cache_path ); ?>' />
1078
+ <p><?php printf( __( 'Change the location of your cache files. The default is WP_CONTENT_DIR . /cache/ which translates to %s.', 'wp-super-cache' ), WP_CONTENT_DIR . '/cache/' ); ?></p>
1079
+ <ol><li><?php _e( 'You must give the full path to the directory.', 'wp-super-cache' ); ?></li>
1080
+ <li><?php _e( 'If the directory does not exist it will be created so make sure your webserver user has write access to the parent directory. The parent directory must exist.', 'wp-super-cache' ); ?></li>
1081
+ <li><?php _e( 'If the new cache directory does not exist, it will be created and the contents of the old cache directory will be moved there. Otherwise, the old cache directory will be left where it is.', 'wp-super-cache' ); ?></li>
1082
+ <li><?php _e( 'Submit a blank entry to set it to the default directory, WP_CONTENT_DIR . /cache/.', 'wp-super-cache' ); ?></li>
1083
+ <?php if ( get_site_option( 'wp_super_cache_index_detected' ) && strlen( $cache_path ) > strlen( ABSPATH ) && ABSPATH == substr( $cache_path, 0, strlen( ABSPATH ) ) ) {
1084
+ $msg = __( 'The plugin detected a bare directory index in your cache directory which would let visitors see your cache files directly and might expose private posts.', 'wp-super-cache' );
1085
+ if ( $super_cache_enabled && $wp_cache_mod_rewrite == 1 ) {
1086
+ $msg .= ' ' . __( 'You are using mod_rewrite to serve cache files so the plugin has added <q>Options -Indexes</q> to the .htaccess file in the cache directory to disable indexes. However if that does not work you should contact your system administrator or support and ask for them to be disabled, or use PHP mode and move the cache outside of the web root.' );
1087
+ } else {
1088
+ $msg .= ' <strong>' . sprintf( __( 'index.html files have been added in key directories but unless directory indexes are disabled it is probably better to store the cache files outside of the web root of %s' ), ABSPATH ) . '</strong>';
1089
+ }
1090
+ echo "<li>$msg</li>";
1091
+ } ?>
1092
+
1093
+
1094
+ <?php if ( $super_cache_enabled && $wp_cache_mod_rewrite == 1 ) { ?>
1095
+ <li><?php printf( __( 'Since you are using mod_rewrite to serve cache files you must choose a directory in your web root which is <q>%s</q> and update the mod_rewrite rules in the .htaccess file.', 'wp-super-cache' ), ABSPATH ); ?></li>
1096
+ <?php } ?>
1097
+ </ol>
1098
+ <p><?php _e( '', 'wp-super-cache' ); ?></p>
1099
  </fieldset>
1100
  </td>
1101
  </tr>
1542
  if( substr( $page, 0, 1 ) != '/' )
1543
  $page = '/' . $page;
1544
  $page = esc_sql( $page );
1545
+ if ( false == is_array( $cached_direct_pages ) || in_array( $page, $cached_direct_pages ) == false ) {
1546
  $cached_direct_pages[] = $page;
1547
  $out .= "'$page', ";
1548
  }
1569
  }
1570
 
1571
  if( $valid_nonce && array_key_exists('deletepage', $_POST) && $_POST[ 'deletepage' ] ) {
1572
+ $page = str_replace( '..', '', preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', $_POST['deletepage'] ) ) . '/';
1573
+ $pagefile = realpath( ABSPATH . $page . 'index.html' );
1574
+ if ( substr( $pagefile, 0, strlen( ABSPATH ) ) != ABSPATH || false == wp_cache_confirm_delete( ABSPATH . $page ) ) {
1575
+ die( __( 'Cannot delete directory', 'wp-super-cache' ) );
1576
+ }
1577
  $firstfolder = explode( '/', $page );
1578
  $firstfolder = ABSPATH . $firstfolder[1];
1579
  $page = ABSPATH . $page;
1653
  global $cache_max_time, $wp_cache_config_file, $valid_nonce, $cache_enabled, $super_cache_enabled, $cache_schedule_type, $cache_scheduled_time, $cache_schedule_interval, $cache_time_interval, $cache_gc_email_me, $wp_cache_preload_on;
1654
 
1655
  $timezone_format = _x('Y-m-d G:i:s', 'timezone date format');
1656
+
1657
+ if ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'expirytime' ) {
1658
 
1659
+ if( !isset( $cache_schedule_type ) ) {
1660
+ $cache_schedule_type = 'interval';
1661
+ wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
1662
+ }
1663
+
1664
+ if( !isset( $cache_scheduled_time ) ) {
1665
+ $cache_scheduled_time = '00:00';
1666
+ wp_cache_replace_line('^ *\$cache_scheduled_time', "\$cache_scheduled_time = '$cache_scheduled_time';", $wp_cache_config_file);
1667
+ }
1668
+
1669
+ if( !isset( $cache_max_time ) ) {
1670
+ $cache_max_time = 3600;
1671
+ wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file);
1672
+ }
1673
+
1674
+ if ( !isset( $cache_time_interval ) ) {
1675
+ $cache_time_interval = $cache_max_time;
1676
+ wp_cache_replace_line('^ *\$cache_time_interval', "\$cache_time_interval = '$cache_time_interval';", $wp_cache_config_file);
1677
+ }
1678
+
1679
+ if ( isset( $_POST['wp_max_time'] ) && $valid_nonce ) {
1680
+ $cache_max_time = (int)$_POST['wp_max_time'];
1681
+ wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file);
1682
+ // schedule gc watcher
1683
+ if ( false == wp_next_scheduled( 'wp_cache_gc_watcher' ) )
1684
+ wp_schedule_event( time()+600, 'hourly', 'wp_cache_gc_watcher' );
1685
+ }
1686
+
1687
+ if ( isset( $_POST[ 'cache_gc_email_me' ] ) && $valid_nonce ) {
1688
+ $cache_gc_email_me = 1;
1689
+ wp_cache_replace_line('^ *\$cache_gc_email_me', "\$cache_gc_email_me = $cache_gc_email_me;", $wp_cache_config_file);
1690
+ } elseif ( $valid_nonce ) {
1691
+ $cache_gc_email_me = 0;
1692
+ wp_cache_replace_line('^ *\$cache_gc_email_me', "\$cache_gc_email_me = $cache_gc_email_me;", $wp_cache_config_file);
1693
+ }
1694
+ if ( isset( $_POST[ 'cache_schedule_type' ] ) && $_POST[ 'cache_schedule_type' ] == 'interval' && isset( $_POST['cache_time_interval'] ) && $valid_nonce ) {
1695
+ wp_clear_scheduled_hook( 'wp_cache_gc' );
1696
+ $cache_schedule_type = 'interval';
1697
+ if ( (int)$_POST[ 'cache_time_interval' ] == 0 )
1698
+ $_POST[ 'cache_time_interval' ] = 600;
1699
+ $cache_time_interval = (int)$_POST[ 'cache_time_interval' ];
1700
+ wp_schedule_single_event( time() + $cache_time_interval, 'wp_cache_gc' );
1701
+ wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
1702
+ wp_cache_replace_line('^ *\$cache_time_interval', "\$cache_time_interval = '$cache_time_interval';", $wp_cache_config_file);
1703
+ } elseif ( $valid_nonce ) { // clock
1704
+ wp_clear_scheduled_hook( 'wp_cache_gc' );
1705
+ $cache_schedule_type = 'time';
1706
+ if ( !isset( $_POST[ 'cache_scheduled_time' ] ) || $_POST[ 'cache_scheduled_time' ] == '' )
1707
+ $_POST[ 'cache_scheduled_time' ] = '00:00';
1708
+ $cache_scheduled_time = $_POST[ 'cache_scheduled_time' ];
1709
+ $schedules = wp_get_schedules();
1710
+ if ( !isset( $cache_schedule_interval ) )
1711
+ $cache_schedule_interval = 'daily';
1712
+ if ( isset( $schedules[ $_POST[ 'cache_schedule_interval' ] ] ) )
1713
+ $cache_schedule_interval = $_POST[ 'cache_schedule_interval' ];
1714
+ wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
1715
+ wp_cache_replace_line('^ *\$cache_schedule_interval', "\$cache_schedule_interval = '{$cache_schedule_interval}';", $wp_cache_config_file);
1716
+ wp_cache_replace_line('^ *\$cache_scheduled_time', "\$cache_scheduled_time = '$cache_scheduled_time';", $wp_cache_config_file);
1717
+ wp_schedule_event( strtotime( $cache_scheduled_time ), $cache_schedule_interval, 'wp_cache_gc' );
1718
+ }
1719
  }
1720
+
1721
  ?><fieldset class="options">
1722
  <a name='expirytime'></a>
1723
  <h3><?php _e( 'Expiry Time &amp; Garbage Collection', 'wp-super-cache' ); ?></h3><?php
1749
  });";
1750
  echo "</script>";
1751
  echo '<form name="wp_edit_max_time" action="#expirytime" method="post">';
1752
+ echo '<input name="action" value="expirytime" type="hidden" />';
1753
  echo '<table class="form-table">';
1754
  echo '<tr><td><label for="wp_max_time"><strong>' . __( 'Cache Timeout', 'wp-super-cache' ) . '</strong></label></td>';
1755
  echo "<td><input type='text' id='wp_max_time' size=6 name='wp_max_time' value='$cache_max_time' /> " . __( "seconds", 'wp-super-cache' ) . "</td></tr>\n";
2104
  return true;
2105
  }
2106
 
2107
+ function wp_cache_remove_index() {
2108
+ global $cache_path;
2109
+ @unlink( $cache_path . "index.html" );
2110
+ @unlink( $cache_path . "supercache/index.html" );
2111
+ @unlink( $cache_path . "blogs/index.html" );
2112
+ if ( is_dir( $cache_path . "blogs" ) ) {
2113
+ $dir = new DirectoryIterator( $cache_path . "blogs" );
2114
+ foreach( $dir as $fileinfo ) {
2115
+ if ( $fileinfo->isDot() ) {
2116
+ continue;
2117
+ }
2118
+ if ( $fileinfo->isDir() ) {
2119
+ $directory = $cache_path . "blogs/" . $fileinfo->getFilename();
2120
+ if ( is_file( $directory . "/index.html" ) ) {
2121
+ unlink( $directory . "/index.html" );
2122
+ }
2123
+ if ( is_dir( $directory . "/meta" ) ) {
2124
+ if ( is_file( $directory . "/meta/index.html" ) ) {
2125
+ unlink( $directory . "/index.html" );
2126
+ }
2127
+ }
2128
+ }
2129
+ }
2130
+ }
2131
+ }
2132
+
2133
+ function wp_cache_index_notice() {
2134
+ global $current_user, $wp_version, $wp_cache_not_logged_in, $cache_path;
2135
+
2136
+ if ( false == wpsupercache_site_admin() )
2137
+ return false;
2138
+ if ( false == get_site_option( 'wp_super_cache_index_detected' ) )
2139
+ return false;
2140
+
2141
+ if ( strlen( $cache_path ) < strlen( ABSPATH )
2142
+ || ABSPATH != substr( $cache_path, 0, strlen( ABSPATH ) ) )
2143
+ return false; // cache stored outside web root
2144
+
2145
+ if ( get_site_option( 'wp_super_cache_index_detected' ) == 2 ) {
2146
+ update_site_option( 'wp_super_cache_index_detected', 3 );
2147
+ echo "<div class='error' style='padding: 10px 10px 50px 10px'>";
2148
+ echo "<h1>" . __( 'WP Super Cache Warning!', 'wp-super-cache' ) . '</h1>';
2149
+ echo '<p>' . __( 'All users of this site have been logged out to refresh their login cookies.', 'wp-super-cache' ) . '</p>';
2150
+ echo '</div>';
2151
+ return false;
2152
+ } elseif ( get_site_option( 'wp_super_cache_index_detected' ) != 3 ) {
2153
+ echo "<div id='wpsc-index-warning' class='error notice' style='padding: 10px 10px 50px 10px'>";
2154
+ echo "<h1>" . __( 'WP Super Cache Warning!', 'wp-super-cache' ) . '</h1>';
2155
+ echo '<p>' . __( 'Your server is configured to show files and directories which may expose sensitive data such as login cookies to attackers in the cache directories. That has been fixed by adding a file named index.html to each directory. If you use PHP or legacy caching consider moving the location of the cache directory on the Advanced Settings page.', 'wp-super-cache' ) . '</p>';
2156
+ echo "<p><strong>";
2157
+ _e( 'If you just installed WP Super Cache for the first time you can dismiss this message. Otherwise you should probably refresh the login cookies of all logged in WordPress users here by clicking the logout link below.', 'wp-super-cache' );
2158
+ echo "</strong></p>";
2159
+ if ( -1 == version_compare( $wp_version, '4.0' ) ) {
2160
+ echo '<p>' . __( 'Your site is using a very old version of WordPress. When you update to the latest version everyone will be logged out and cookie information updated.', 'wp-super-cache' ) . '</p>';
2161
+ } else {
2162
+ echo '<p>' . __( 'The logout link will log out all WordPress users on this site except you. Your authentication cookie will be updated but you will not be logged out.', 'wp-super-cache' ) . '</p>';
2163
+ }
2164
+ echo "<a id='wpsc-dismiss' href='#'>" . __( 'Dismiss', 'wp-super-cache' ) . "</a>";
2165
+ if ( 1 == version_compare( $wp_version, '4.0' ) ) {
2166
+ echo " | <a href='" . wp_nonce_url( admin_url( '?action=wpsclogout' ), 'wpsc_logout' ) . "'>" . __( 'Logout', 'wp-super-cache' ) . "</a>";
2167
+ }
2168
+ echo "</div>";
2169
+ ?>
2170
+ <script type='text/javascript'>
2171
+ <!--
2172
+ jQuery(document).ready(function(){
2173
+ jQuery('#wpsc-dismiss').click(function() {
2174
+ jQuery.ajax({
2175
+ type: "post",url: "admin-ajax.php",data: { action: 'wpsc-index-dismiss', _ajax_nonce: '<?php echo wp_create_nonce( 'wpsc-index-dismiss' ); ?>' },
2176
+ beforeSend: function() {jQuery("#wpsc-index-warning").fadeOut('slow');},
2177
+ });
2178
+ })
2179
+ })
2180
+ //-->
2181
+ </script>
2182
+ <?php
2183
+ }
2184
+ }
2185
+ add_action( 'admin_notices', 'wp_cache_index_notice' );
2186
+
2187
+ function wpsc_dismiss_indexhtml_warning() {
2188
+ check_ajax_referer( "wpsc-index-dismiss" );
2189
+ update_site_option( 'wp_super_cache_index_detected', 3 );
2190
+ die();
2191
+ }
2192
+ add_action( 'wp_ajax_wpsc-index-dismiss', 'wpsc_dismiss_indexhtml_warning' );
2193
+
2194
+ function wp_cache_logout_all() {
2195
+ global $current_user;
2196
+ if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'wpsclogout' && wp_verify_nonce( $_GET[ '_wpnonce' ], 'wpsc_logout' ) ) {
2197
+ $user_id = $current_user->ID;
2198
+ WP_Session_Tokens::destroy_all_for_all_users();
2199
+ wp_set_auth_cookie( $user_id, false, is_ssl() );
2200
+ update_site_option( 'wp_super_cache_index_detected', 2 );
2201
+ wp_redirect( admin_url() );
2202
+ }
2203
+ }
2204
+ if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'wpsclogout' )
2205
+ add_action( 'admin_init', 'wp_cache_logout_all' );
2206
+
2207
+ function wp_cache_add_index_protection() {
2208
+ global $cache_path, $blog_cache_dir, $blogcacheid;
2209
+
2210
+ if ( is_dir( $cache_path ) && false == is_file( "$cache_path/index.html" ) ) {
2211
+ $page = wp_remote_get( home_url( "/wp-content/cache/" ) );
2212
+ if ( false == is_wp_error( $page ) ) {
2213
+ if ( false == get_site_option( 'wp_super_cache_index_detected' )
2214
+ && $page[ 'response' ][ 'code' ] == 200
2215
+ && stripos( $page[ 'body' ], 'index of' ) ) {
2216
+ add_site_option( 'wp_super_cache_index_detected', 1 ); // only show this once
2217
+ }
2218
+ }
2219
+ insert_with_markers( $cache_path . '.htaccess', "INDEX", array( 'Options -Indexes' ) );
2220
+ }
2221
+
2222
+ $directories = array( $cache_path, $cache_path . '/supercache/', $cache_path . '/blogs/', $blog_cache_dir, $blog_cache_dir . "/meta" );
2223
+ foreach( $directories as $dir ) {
2224
+ if ( false == is_dir( $dir ) )
2225
+ @mkdir( $dir );
2226
+ if ( is_dir( $dir ) && false == is_file( "$dir/index.html" ) ) {
2227
+ $fp = @fopen( "$dir/index.html", 'w' );
2228
+ if ( $fp )
2229
+ fclose( $fp );
2230
+ }
2231
+ }
2232
+ }
2233
+
2234
+ function wp_cache_add_site_cache_index() {
2235
+ global $cache_path;
2236
+
2237
+ wp_cache_add_index_protection(); // root and supercache
2238
+
2239
+ if ( is_dir( $cache_path . "blogs" ) ) {
2240
+ $dir = new DirectoryIterator( $cache_path . "blogs" );
2241
+ foreach( $dir as $fileinfo ) {
2242
+ if ( $fileinfo->isDot() ) {
2243
+ continue;
2244
+ }
2245
+ if ( $fileinfo->isDir() ) {
2246
+ $directory = $cache_path . "blogs/" . $fileinfo->getFilename();
2247
+ if ( false == is_file( $directory . "/index.html" ) ) {
2248
+ $fp = @fopen( $directory . "/index.html", 'w' );
2249
+ if ( $fp )
2250
+ fclose( $fp );
2251
+ }
2252
+ if ( is_dir( $directory . "/meta" ) ) {
2253
+ if ( false == is_file( $directory . "/meta/index.html" ) ) {
2254
+ $fp = @fopen( $directory . "/meta/index.html", 'w' );
2255
+ if ( $fp )
2256
+ fclose( $fp );
2257
+ }
2258
+ }
2259
+ }
2260
+ }
2261
+ }
2262
+ }
2263
+
2264
  function wp_cache_verify_cache_dir() {
2265
  global $cache_path, $blog_cache_dir, $blogcacheid;
2266
 
2289
  if( false == is_dir( $blog_cache_dir . 'meta' ) )
2290
  @mkdir( $blog_cache_dir . 'meta' );
2291
 
2292
+ wp_cache_add_index_protection();
2293
  return true;
2294
  }
2295
 
2461
  $count = 0;
2462
  $expired = 0;
2463
  $now = time();
2464
+ if ( ( $handle = @opendir( $blog_cache_dir ) ) ) {
2465
  $wp_cache_fsize = 0;
2466
  if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletewpcache' ) {
2467
+ $deleteuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', base64_decode( $_GET[ 'uri' ] ) ) );
 
2468
  } else {
2469
  $deleteuri = '';
2470
  }
2471
 
2472
  if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletesupercache' ) {
2473
+ $supercacheuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace("/(\?.*)?$/", '', base64_decode( $_GET[ 'uri' ] ) ) ) );
2474
+ $supercacheuri = trailingslashit( realpath( $cache_path . 'supercache/' . $supercacheuri ) );
2475
+ if ( wp_cache_confirm_delete( $supercacheuri ) ) {
2476
+ printf( __( "Deleting supercache file: <strong>%s</strong><br />", 'wp-super-cache' ), $supercacheuri );
2477
+ @unlink( $supercacheuri . 'index.html' );
2478
+ @unlink( $supercacheuri . 'index.html.gz' );
2479
+ prune_super_cache( $supercacheuri . 'page', true );
2480
+ @rmdir( $supercacheuri );
2481
+ }
2482
+ }
2483
+ while( false !== ( $file = readdir( $handle ) ) ) {
2484
+ if ( strpos( $file, $file_prefix ) !== false && substr( $file, -4 ) == '.php' ) {
2485
+ if ( false == file_exists( $blog_cache_dir . 'meta/' . $file ) ) {
2486
+ @unlink( $blog_cache_dir . $file );
2487
+ continue; // meta does not exist
2488
+ }
2489
  $mtime = filemtime( $blog_cache_dir . 'meta/' . $file );
2490
+ $fsize = @filesize( $blog_cache_dir . $file );
2491
+ if ( $fsize > 0 )
2492
+ $fsize = $fsize - 15; // die() command takes 15 bytes at the start of the file
2493
 
2494
  $age = $now - $mtime;
2495
  if ( $valid_nonce && isset( $_GET[ 'listfiles' ] ) ) {
2496
+ $meta = json_decode( wp_cache_get_legacy_cache( $blog_cache_dir . 'meta/' . $file ), true );
2497
  if ( $deleteuri != '' && $meta[ 'uri' ] == $deleteuri ) {
2498
+ printf( __( "Deleting wp-cache file: <strong>%s</strong><br />", 'wp-super-cache' ), esc_html( $deleteuri ) );
2499
  @unlink( $blog_cache_dir . 'meta/' . $file );
2500
+ @unlink( $blog_cache_dir . $file );
2501
  continue;
2502
  }
2503
  $meta[ 'age' ] = $age;
2551
  $filem = @filemtime( $supercachedir );
2552
  if ( false == $wp_cache_preload_on && is_file( $supercachedir ) && $cache_max_time > 0 && $filem + $cache_max_time <= $now ) {
2553
  $sizes[ 'expired' ] ++;
2554
+ if ( $valid_nonce && isset( $_GET[ 'listfiles' ] ) )
2555
  $sizes[ 'expired_list' ][ str_replace( $cache_path . 'supercache/' , '', $supercachedir ) ] = $now - $filem;
2556
  } else {
2557
+ if ( $valid_nonce && isset( $_GET[ 'listfiles' ] ) && $filem )
2558
  $sizes[ 'cached_list' ][ str_replace( $cache_path . 'supercache/' , '', $supercachedir ) ] = $now - $filem;
2559
  }
2560
  }
2770
 
2771
  function wp_cache_clean_legacy_files( $dir, $file_prefix ) {
2772
  global $wpdb;
2773
+
2774
+ $dir = trailingslashit( $dir );
2775
+ if ( @is_dir( $dir . 'meta' ) == false )
2776
+ return false;
2777
+
2778
+ if ( $handle = @opendir( $dir ) ) {
2779
+ while ( false !== ( $file = readdir( $handle ) ) ) {
2780
+ if ( is_file( $dir . $file ) == false || $file == 'index.html' ) {
2781
+ continue;
2782
+ }
2783
+
2784
+ if ( strpos( $file, $file_prefix ) !== false ) {
2785
+ if ( strpos( $file, '.html' ) ) {
2786
+ // delete old legacy files immediately
2787
+ @unlink( $dir . $file);
2788
+ @unlink( $dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
2789
+ } else {
2790
+ $meta = json_decode( wp_cache_get_legacy_cache( $dir . 'meta/' . $file ), true );
2791
+ if ( ( defined( 'VHOST' ) || ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) ) && $meta[ 'blog_id' ] != $wpdb->blogid )
2792
+ continue;
2793
+ @unlink( $dir . $file);
2794
+ @unlink( $dir . 'meta/' . $file);
2795
+ }
2796
  }
2797
  }
2798
  closedir($handle);
2820
  return wp_cache_phase2_clean_expired($file_prefix);
2821
  }
2822
 
 
2823
  $now = time();
2824
+ if ( $handle = @opendir( $blog_cache_dir ) ) {
2825
+ while ( false !== ( $file = readdir( $handle ) ) ) {
2826
+ if ( strpos( $file, $file_prefix ) !== false ) {
2827
+ if ( strpos( $file, '.html' ) ) {
2828
+ @unlink( $blog_cache_dir . $file);
2829
+ @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
2830
+ } elseif ( ( filemtime( $blog_cache_dir . $file ) + $cache_max_time ) <= $now ) {
2831
+ @unlink( $blog_cache_dir . $file );
2832
+ @unlink( $blog_cache_dir . 'meta/' . $file );
2833
+ }
2834
  }
2835
  }
2836
  closedir($handle);
2929
  add_action( 'admin_notices', 'wp_cache_admin_notice' );
2930
 
2931
  function wp_cache_check_site() {
2932
+ global $wp_super_cache_front_page_check, $wp_super_cache_front_page_clear, $wp_super_cache_front_page_text, $wp_super_cache_front_page_notification, $wpdb;
2933
 
2934
  if ( !isset( $wp_super_cache_front_page_check ) || ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 0 ) ) {
2935
  return false;
2943
  // Check for gzipped front page
2944
  if ( $front_page[ 'headers' ][ 'content-type' ] == 'application/x-gzip' ) {
2945
  if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) {
2946
+ wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Please clear cache!', 'wp-super-cache' ), home_url() ), sprintf( __( "Please visit %s to clear the cache as the front page of your site is now downloading!", 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) );
2947
  } else {
2948
+ wp_cache_clear_cache( $wpdb->blogid );
2949
+ wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Cache Cleared!', 'wp-super-cache' ), home_url() ), sprintf( __( "The cache on your blog has been cleared because the front page of your site is now downloading. Please visit %s to verify the cache has been cleared.", 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) );
2950
  }
2951
  }
2952
 
2953
  // Check for broken front page
2954
  if ( isset( $wp_super_cache_front_page_text ) && $wp_super_cache_front_page_text != '' && false === strpos( $front_page[ 'body' ], $wp_super_cache_front_page_text ) ) {
2955
  if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) {
2956
+ wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is not correct! Please clear cache!', 'wp-super-cache' ), home_url() ), sprintf( __( 'Please visit %1$s to clear the cache as the front page of your site is not correct and missing the text, "%2$s"!', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ), $wp_super_cache_front_page_text ) );
2957
  } else {
2958
+ wp_cache_clear_cache( $wpdb->blogid );
2959
+ wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is not correct! Cache Cleared!', 'wp-super-cache' ), home_url() ), sprintf( __( 'The cache on your blog has been cleared because the front page of your site is missing the text "%2$s". Please visit %1$s to verify the cache has been cleared.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ), $wp_super_cache_front_page_text ) );
2960
  }
2961
  }
2962
  }
2963
  if ( isset( $wp_super_cache_front_page_notification ) && $wp_super_cache_front_page_notification == 1 ) {
2964
+ wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page check!', 'wp-super-cache' ), home_url() ), sprintf( __( "WP Super Cache has checked the front page of your blog. Please visit %s if you would like to disable this.", 'wp-super-cache' ) . "\n\n", admin_url( 'options-general.php?page=wpsupercache' ) ) );
2965
  }
2966
 
2967
  if ( !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
3046
  $apache_root = '%{DOCUMENT_ROOT}';
3047
  }
3048
  $content_dir_root = $document_root;
3049
+ if ( strpos( $document_root, '/kunden/homepages/' ) === 0 ) {
3050
  // http://wordpress.org/support/topic/plugin-wp-super-cache-how-to-get-mod_rewrite-working-on-1and1-shared-hosting?replies=1
3051
  // On 1and1, PHP's directory structure starts with '/homepages'. The
3052
  // Apache directory structure has an extra '/kunden' before it.
3129
  $gziprules .= "<IfModule mod_deflate.c>\n SetEnvIfNoCase Request_URI \.gz$ no-gzip\n</IfModule>\n";
3130
  $gziprules .= "<IfModule mod_headers.c>\n Header set Vary \"Accept-Encoding, Cookie\"\n Header set Cache-Control 'max-age=3, must-revalidate'\n</IfModule>\n";
3131
  $gziprules .= "<IfModule mod_expires.c>\n ExpiresActive On\n ExpiresByType text/html A3\n</IfModule>\n";
3132
+ $gziprules .= "Options -Indexes\n";
3133
  return array( "document_root" => $document_root, "apache_root" => $apache_root, "home_path" => $home_path, "home_root" => $home_root, "home_root_lc" => $home_root_lc, "inst_root" => $inst_root, "wprules" => $wprules, "scrules" => $scrules, "condition_rules" => $condition_rules, "rules" => $rules, "gziprules" => $gziprules );
3134
  }
3135
 
3150
 
3151
  function wp_cron_preload_cache() {
3152
  global $wpdb, $wp_cache_preload_interval, $wp_cache_preload_posts, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $cache_path, $wp_cache_preload_taxonomies;
 
3153
 
3154
  if ( get_option( 'preload_cache_stop' ) ) {
3155
  delete_option( 'preload_cache_stop' );
3181
  update_option( 'preload_cache_counter', array( 'c' => ( $c + 100 ), 't' => time() ) );
3182
 
3183
  if ( $wp_cache_preload_email_me && $c == 0 )
3184
+ wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Started', 'wp-super-cache' ), home_url(), '' ), ' ' );
3185
 
3186
  if ( $wp_cache_preload_posts == 'all' || $c < $wp_cache_preload_posts ) {
3187
  wp_cache_debug( "wp_cron_preload_cache: doing taxonomy preload.", 5 );
3211
  if ( count( $details ) != 1 && $details[ 0 ] != '' ) {
3212
  $rows = array_splice( $details, 0, 50 );
3213
  if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume == 'many' )
3214
+ wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Refreshing %2$s taxonomy from %3$d to %4$d', 'wp-super-cache' ), home_url(), $taxonomy, $c, ($c+100) ), 'Refreshing: ' . print_r( $rows, 1 ) );
3215
  foreach( (array)$rows as $url ) {
3216
  set_time_limit( 60 );
3217
  if ( $url == '' )
3240
  }
3241
 
3242
  if ( $wp_cache_preload_posts == 'all' || $c < $wp_cache_preload_posts ) {
3243
+ $types = get_post_types( array( 'public' => true, 'publicly_queryable' => true ), 'names', 'or' );
3244
+ $types = array_map( 'esc_sql', $types );
3245
+ $types = "'" . implode( "','", $types ) . "'";
3246
+ $posts = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE ( post_type IN ( $types ) ) AND post_status = 'publish' ORDER BY ID ASC LIMIT $c, 100" );
3247
  wp_cache_debug( "wp_cron_preload_cache: got 100 posts from position $c.", 5 );
3248
  } else {
3249
  wp_cache_debug( "wp_cron_preload_cache: no more posts to get. Limit ($wp_cache_preload_posts) reached.", 5 );
3260
  $page_on_front = $page_for_posts = 0;
3261
  }
3262
  if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume == 'many' )
3263
+ wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Refreshing posts from %2$d to %3$d', 'wp-super-cache' ), home_url(), $c, ($c+100) ), ' ' );
3264
  $msg = '';
3265
  $count = $c + 1;
3266
  $permalink_counter_msg = $cache_path . "preload_permalink.txt";
3281
  @unlink( $cache_path . "stop_preload.txt" );
3282
  update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
3283
  if ( $wp_cache_preload_email_me )
3284
+ wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Stopped', 'wp-super-cache' ), home_url(), '' ), ' ' );
3285
  return true;
3286
  }
3287
  $msg .= "$url\n";
3291
  $count++;
3292
  }
3293
  if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume != 'less' )
3294
+ wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] %2$d posts refreshed', 'wp-super-cache' ), home_url(), ($c+100) ), __( "Refreshed the following posts:", 'wp-super-cache' ) . "\n$msg" );
3295
  if ( defined( 'DOING_CRON' ) ) {
3296
  wp_cache_debug( "wp_cron_preload_cache: scheduling the next preload in 30 seconds.", 5 );
3297
  wp_schedule_single_event( time() + 30, 'wp_cache_preload_hook' );
3312
  $cache_max_time = 86400; // fool the GC into expiring really old files
3313
  }
3314
  if ( $wp_cache_preload_email_me )
3315
+ wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Cache Preload Completed', 'wp-super-cache' ), home_url() ), __( "Cleaning up old supercache files.", 'wp-super-cache' ) . "\n" . $msg );
3316
  wp_cache_debug( "wp_cron_preload_cache: clean expired cache files older than $cache_max_time seconds.", 5 );
3317
  wp_cache_phase2_clean_expired( $file_prefix, true ); // force cleanup of old files.
3318
  }
3361
  }
3362
  add_action( 'init', 'check_up_on_preloading' ); // sometimes preloading stops working. Kickstart it.
3363
 
3364
+ function wp_cache_disable_plugin( $delete_config_file = true ) {
3365
  global $wp_cache_config_file, $wp_rewrite;
3366
  if ( file_exists( ABSPATH . 'wp-config.php') ) {
3367
  $global_config_file = ABSPATH . 'wp-config.php';
3378
  if ( false == @unlink( WP_CONTENT_DIR . "/advanced-cache.php" ) )
3379
  $file_not_deleted[] = 'advanced-cache.php';
3380
  }
3381
+ if ( $delete_config_file && @file_exists( WP_CONTENT_DIR . "/wp-cache-config.php" ) ) {
3382
  if ( false == unlink( WP_CONTENT_DIR . "/wp-cache-config.php" ) )
3383
  $file_not_deleted[] = 'wp-cache-config.php';
3384
  }