WP Super Cache - Version 0.5

Version Description

Download this release

Release Info

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

Code changes from version 0.4 to 0.5

Changelog.txt CHANGED
@@ -1,3 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  2007-11-12 15:23 donncha
2
 
3
  * readme.txt, wp-cache.php: Bump version
1
+ 2007-11-26 11:11 donncha
2
+
3
+ * readme.txt: Bump version
4
+
5
+ 2007-11-26 11:07 donncha
6
+
7
+ * readme.txt: Warn about safe mode
8
+
9
+ 2007-11-26 10:56 donncha
10
+
11
+ * wp-cache.php: Print a warning message if PHP safe mode is
12
+ enabled.
13
+ Super Cache plugins will fail silently if advanced-cache.php is
14
+ not loaded
15
+ Updated "Directly Cached Files" text
16
+
17
+ 2007-11-16 21:56 donncha
18
+
19
+ * plugins/searchengine.php, wp-cache-phase1.php,
20
+ wp-cache-phase2.php, wp-cache.php: Added »
21
+ Updated formatting of admin backend
22
+ Added "direct caching" of pages.
23
+
24
+ 2007-11-12 21:23 donncha
25
+
26
+ * wp-cache-phase2.php, wp-cache.php: PHP 5's mkdir() doesn't like
27
+ slashes, http://ie2.php.net/manual/en/function.mkdir.php#73848 -
28
+ props Tummmbler
29
+
30
+ 2007-11-12 15:26 donncha
31
+
32
+ * Changelog.txt: Updated changelog
33
+
34
  2007-11-12 15:23 donncha
35
 
36
  * readme.txt, wp-cache.php: Bump version
plugins/searchengine.php CHANGED
@@ -68,9 +68,9 @@ function wp_supercache_searchengine_admin() {
68
  }
69
  echo '.</strong> (requires <a href="http://ocaoimh.ie/no-adverts-for-friends/">friendsadverts.php</a> too)<div class="submit">';
70
  if( $cache_no_adverts_for_friends == 'no' ) {
71
- echo '<input type="submit" name="cache_no_adverts_for_friends" value="Enable" />';
72
  } else {
73
- echo '<input type="submit" name="cache_no_adverts_for_friends" value="Disable" />';
74
  }
75
  echo "</div></form>\n";
76
 
68
  }
69
  echo '.</strong> (requires <a href="http://ocaoimh.ie/no-adverts-for-friends/">friendsadverts.php</a> too)<div class="submit">';
70
  if( $cache_no_adverts_for_friends == 'no' ) {
71
+ echo '<input type="submit" name="cache_no_adverts_for_friends" value="Enable &raquo;" />';
72
  } else {
73
+ echo '<input type="submit" name="cache_no_adverts_for_friends" value="Disable &raquo;" />';
74
  }
75
  echo "</div></form>\n";
76
 
readme.txt CHANGED
@@ -2,40 +2,23 @@
2
  Contributors: donncha
3
  Tags: performance,caching,wp-cache
4
  Tested up to: 2.3.1
5
- Stable tag: 0.4
6
 
7
  A modification of WP-Cache that produces static html files.
8
 
9
  == Description ==
10
- A modification of WP-Cache that produces static html files. After a html file
11
- is generated your webserver will serve that file instead of processing the
12
- comparatively heavier and more expensive WordPress PHP scripts.
13
 
14
- However, because a user's details are displayed in the comment form after
15
- they leave a comment, the plugin will only serve static html files to:
16
 
17
  1. Users who are not logged in.
18
  2. Users who have not left a comment on your blog.
19
  3. Or users who have not viewed a password protected post.
20
 
21
- The good news is that probably more than 99% of your visitors don't do any of
22
- the above! Those users who don't see the static files will still benefit
23
- because they will see regular WP-Cache cached files and your server won't be
24
- as busy as before. This plugin should help your server cope with a front page
25
- appearance on digg.com or other social networking site.
26
-
27
- This plugin is a modified version of the WP-Cache 2 plugin by Ricardo Galli Granada.
28
- His plugin is still available. We're standing on the shoulders of giants and benefiting
29
- from the power of the GPL here. Thanks Ricardo for creating such a great plugin!
30
- See the following URLs for more info on WP-Cache 2
31
-
32
- 1. http://mnm.uib.es/gallir/wp-cache-2/
33
- 2. http://wordpress.org/extend/plugins/wp-cache/
34
-
35
- Download: http://wordpress.org/extend/plugins/wp-super-cache/download/
36
 
37
  == Installation ==
38
- 1. You must have mod_mime, mod_rewrite and fancy permalinks enabled for this plugin to work.
39
  2. If you have WP-Cache installed already, please disable it. Edit wp-config.php and make sure the WP_CACHE define is deleted, and remove the files wp-content/wp-cache-config.php and wp-content/advanced-cache.php. These will be recreated when you install this plugin.
40
  3. Upload this directory to your plugins directory. It will create a 'wp-content/plugins/wp-super-cache/' directory.
41
  4. If you are using WordPress MU you will need to install this in 'wp-content/mu-plugins/wp-super-cache/' and the file wp-cache.php must be copied into the mu-plugins directory.
@@ -81,6 +64,7 @@ If things don't work when you installed the plugin here are a few things to chec
81
  6. Look in wp-content/cache/supercache/. Are there directories and files there?
82
  7. Anything in your php error_log?
83
  8. If your browser keeps asking you to save the file after the super cache is installed you must disable Super Cache compression. Go to the Options->WP Super Cache page and disable it there.
 
84
 
85
  == Custom Caching ==
86
  It is now possible to hook into the caching process using the add_cacheacton() function.
2
  Contributors: donncha
3
  Tags: performance,caching,wp-cache
4
  Tested up to: 2.3.1
5
+ Stable tag: 0.5
6
 
7
  A modification of WP-Cache that produces static html files.
8
 
9
  == Description ==
10
+ This plugin generates static html files from your dynamic WordPress blog. After a html file is generated your webserver will serve that file instead of processing the comparatively heavier and more expensive WordPress PHP scripts.
 
 
11
 
12
+ However, because a user's details are displayed in the comment form after they leave a comment, the plugin will only serve static html files to:
 
13
 
14
  1. Users who are not logged in.
15
  2. Users who have not left a comment on your blog.
16
  3. Or users who have not viewed a password protected post.
17
 
18
+ The good news is that probably more than 99% of your visitors don't do any of the above! Those users who don't see the static files will still benefit because they will see regular WP-Cache cached files and your server won't be as busy as before. This plugin should help your server cope with a front page appearance on digg.com or other social networking site.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  == Installation ==
21
+ 1. You must have mod mime, mod rewrite and fancy permalinks enabled. PHP safe mode should be disabled.
22
  2. If you have WP-Cache installed already, please disable it. Edit wp-config.php and make sure the WP_CACHE define is deleted, and remove the files wp-content/wp-cache-config.php and wp-content/advanced-cache.php. These will be recreated when you install this plugin.
23
  3. Upload this directory to your plugins directory. It will create a 'wp-content/plugins/wp-super-cache/' directory.
24
  4. If you are using WordPress MU you will need to install this in 'wp-content/mu-plugins/wp-super-cache/' and the file wp-cache.php must be copied into the mu-plugins directory.
64
  6. Look in wp-content/cache/supercache/. Are there directories and files there?
65
  7. Anything in your php error_log?
66
  8. If your browser keeps asking you to save the file after the super cache is installed you must disable Super Cache compression. Go to the Options->WP Super Cache page and disable it there.
67
+ 9. The plugin does not work very well when PHP's safe mode is active. This must be disabled by your administrator.
68
 
69
  == Custom Caching ==
70
  It is now possible to hook into the caching process using the add_cacheacton() function.
wp-cache-phase1.php CHANGED
@@ -85,7 +85,6 @@ function wp_cache_postload() {
85
  }
86
 
87
  function wp_cache_get_cookies_values() {
88
- global $wp_supercache_actions, $passingthrough, $nevershowads;
89
  $string = '';
90
  while ($key = key($_COOKIE)) {
91
  if (preg_match("/^wp-postpass|^wordpress|^comment_author_email_/", $key)) {
85
  }
86
 
87
  function wp_cache_get_cookies_values() {
 
88
  $string = '';
89
  while ($key = key($_COOKIE)) {
90
  if (preg_match("/^wp-postpass|^wordpress|^comment_author_email_/", $key)) {
wp-cache-phase2.php CHANGED
@@ -121,7 +121,7 @@ function wp_cache_writers_exit() {
121
  function wp_cache_ob_callback($buffer) {
122
  global $cache_path, $cache_filename, $meta_file, $wp_start_time, $supercachedir;
123
  global $new_cache, $wp_cache_meta_object, $file_expired, $blog_id, $cache_compression;
124
- global $wp_cache_gzip_encoding, $super_cache_enabled;
125
 
126
  /* Mode paranoic, check for closing tags
127
  * we avoid caching incomplete files */
@@ -142,8 +142,12 @@ function wp_cache_ob_callback($buffer) {
142
  the file was expired and its mtime is less than 5 seconds
143
  */
144
  if( !((!$file_expired && $mtime) || ($mtime && $file_expired && (time() - $mtime) < 5)) ) {
145
- $dir = strtolower(preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"])).preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_SERVER['REQUEST_URI']) ); // To avoid XSS attacs
 
146
  $dir = trailingslashit( $cache_path . 'supercache/' . $dir );
 
 
 
147
  $supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]);
148
  if( !empty( $_GET ) || is_feed() || ( $super_cache_enabled == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) ) )
149
  $super_cache_enabled = false;
@@ -354,7 +358,7 @@ function wp_cache_shutdown_callback() {
354
  wp_cache_writers_entry();
355
  $fr = @fopen($cache_path . 'meta/' . $meta_file, 'w');
356
  if( !$fr )
357
- @mkdir( $cache_path . 'meta/' );
358
  $fr = fopen($cache_path . 'meta/' . $meta_file, 'w');
359
  fputs($fr, $serial);
360
  fclose($fr);
121
  function wp_cache_ob_callback($buffer) {
122
  global $cache_path, $cache_filename, $meta_file, $wp_start_time, $supercachedir;
123
  global $new_cache, $wp_cache_meta_object, $file_expired, $blog_id, $cache_compression;
124
+ global $wp_cache_gzip_encoding, $super_cache_enabled, $cached_direct_pages;
125
 
126
  /* Mode paranoic, check for closing tags
127
  * we avoid caching incomplete files */
142
  the file was expired and its mtime is less than 5 seconds
143
  */
144
  if( !((!$file_expired && $mtime) || ($mtime && $file_expired && (time() - $mtime) < 5)) ) {
145
+ $uri = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_SERVER['REQUEST_URI']) );
146
+ $dir = strtolower(preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"])) . $uri; // To avoid XSS attacs
147
  $dir = trailingslashit( $cache_path . 'supercache/' . $dir );
148
+ if( is_array( $cached_direct_pages ) && in_array( $_SERVER[ 'REQUEST_URI' ], $cached_direct_pages ) ) {
149
+ $dir = trailingslashit( ABSPATH . $uri );
150
+ }
151
  $supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]);
152
  if( !empty( $_GET ) || is_feed() || ( $super_cache_enabled == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) ) )
153
  $super_cache_enabled = false;
358
  wp_cache_writers_entry();
359
  $fr = @fopen($cache_path . 'meta/' . $meta_file, 'w');
360
  if( !$fr )
361
+ @mkdir( $cache_path . 'meta' );
362
  $fr = fopen($cache_path . 'meta/' . $meta_file, 'w');
363
  fputs($fr, $serial);
364
  fclose($fr);
wp-cache.php CHANGED
@@ -78,6 +78,15 @@ function wp_cache_manager() {
78
 
79
  echo '<div class="wrap">';
80
  echo "<h2>WP Super Cache Manager</h2>\n";
 
 
 
 
 
 
 
 
 
81
  if(isset($_REQUEST['wp_restore_config']) && $valid_nonce) {
82
  unlink($wp_cache_config_file);
83
  echo '<strong>Configuration file changed, some values might be wrong. Load the page again from the "Options" menu to reset them.</strong>';
@@ -126,17 +135,23 @@ function wp_cache_manager() {
126
  }
127
  }
128
 
129
- ?><fieldset class="options">
130
  <legend>WP Super Cache Status</legend><?php
131
  echo '<form name="wp_manager" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
132
  ?>
133
  <label><input type='radio' name='wp_cache_status' value='all' <?php if( $cache_enabled == true && $super_cache_enabled == true ) { echo 'checked=checked'; } ?>> WP Cache and Super Cache enabled</label><br />
134
  <label><input type='radio' name='wp_cache_status' value='none' <?php if( $cache_enabled == false ) { echo 'checked=checked'; } ?>> WP Cache and Super Cache disabled</label><br />
135
  <label><input type='radio' name='wp_cache_status' value='wpcache' <?php if( $cache_enabled == true && $super_cache_enabled == false ) { echo 'checked=checked'; } ?>> Super Cache Disabled</label><br />
136
- </fieldset>
 
 
 
 
 
137
 
138
- <fieldset class="options">
139
  <legend>Super Cache Compression</legend>
 
140
  <label><input type="radio" name="cache_compression" value="1" <?php if( $cache_compression ) { echo "checked=checked"; } ?>> Enabled</label>
141
  <label><input type="radio" name="cache_compression" value="0" <?php if( !$cache_compression ) { echo "checked=checked"; } ?>> Disabled</label>
142
  <p>Compression is disabled by default because some hosts have problems with compressed files. Switching this on and off clears the cache.</p>
@@ -186,15 +201,14 @@ function wp_cache_manager() {
186
  } elseif( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && $cache_compression ) {
187
  ?><p><strong>Super Cache compression is now enabled.</strong></p><?php
188
  }
189
- echo '<div class="submit"><input type="submit"value="Update" /></div>';
190
  wp_nonce_field('wp-cache');
191
  echo "</form>\n";
192
  ?></fieldset><?php
193
- wp_lock_down();
194
 
195
  wp_cache_edit_max_time();
196
 
197
- echo '<a name="files"></a><fieldset class="options"><legend>Accepted filenames, rejected URIs</legend>';
198
  wp_cache_edit_rejected();
199
  echo "<br />\n";
200
  wp_cache_edit_accepted();
@@ -202,15 +216,15 @@ function wp_cache_manager() {
202
 
203
  wp_cache_edit_rejected_ua();
204
 
 
 
205
  wp_cache_files();
206
 
207
  wp_cache_restore();
208
 
209
  ob_start();
210
  if( defined( 'WP_CACHE' ) ) {
211
- if( !function_exists( 'do_cacheaction' ) ) {
212
- die( 'Install is not complete. Please verify that:<ul><li> wp-content/advanced-cache.php is a symlink or a copy of ' . WPCACHEHOME . '/wp-cache-phase1.php</li><li> ' . ABSPATH . 'wp-config.php includes the line "<code>define( "WP_CACHE", true );</code>"</li></ul>' );
213
- } else {
214
  do_cacheaction( 'cache_admin_page' );
215
  }
216
  }
@@ -227,10 +241,10 @@ function wp_cache_manager() {
227
  }
228
 
229
  function wp_cache_restore() {
230
- echo '<fieldset class="options"><legend>Configuration messed up?</legend>';
231
  echo '<form name="wp_restore" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
232
  echo '<input type="hidden" name="wp_restore_config" />';
233
- echo '<div class="submit"><input type="submit" id="deletepost" value="Restore default configuration" /></div>';
234
  wp_nonce_field('wp-cache');
235
  echo "</form>\n";
236
  echo '</fieldset>';
@@ -244,7 +258,7 @@ if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) )
244
  add_action( 'comment_form', 'comment_form_lockdown_message' );
245
 
246
  function wp_lock_down() {
247
- global $cache_path, $wp_cache_config_file, $valid_nonce;
248
 
249
  if(isset($_POST['wp_lock_down']) && $valid_nonce) {
250
  $wp_lock_down = $_POST['wp_lock_down'] == '1' ? '1' : '0';
@@ -260,7 +274,7 @@ function wp_lock_down() {
260
  $wp_lock_down = '0';
261
  }
262
  }
263
- ?><fieldset class="options">
264
  <legend>Lock Down: <span style='color: #f00'><?php echo $wp_lock_down == '0' ? 'disabled' : 'enabled'; ?></span></legend>
265
  <p>Prepare your server for an expected spike in traffic by enabling the lock down. When this is enabled, new comments on a post will not refresh the cached static files.</p><?php
266
  if( $wp_lock_down == '1' ) {
@@ -272,12 +286,127 @@ function wp_lock_down() {
272
  $new_lockdown_desc = $wp_lock_down == '1' ? 'Disable' : 'Enable';
273
  echo '<form name="wp_lock_down" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
274
  echo "<input type='hidden' name='wp_lock_down' value='{$new_lockdown}' />";
275
- echo "<div class='submit'><input type='submit' value='{$new_lockdown_desc} Lock Down' /></div>";
276
  wp_nonce_field('wp-cache');
277
  echo "</form>\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  ?></fieldset><?php
279
  }
280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281
  function wp_cache_edit_max_time () {
282
  global $super_cache_max_time, $cache_max_time, $wp_cache_config_file, $valid_nonce;
283
 
@@ -298,14 +427,14 @@ function wp_cache_edit_max_time () {
298
  wp_cache_replace_line('^ *\$super_cache_max_time', "\$super_cache_max_time = $super_cache_max_time;", $wp_cache_config_file);
299
  }
300
  }
301
- ?><fieldset class="options">
302
  <legend>Expiry Time</legend><?php
303
  echo '<form name="wp_edit_max_time" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
304
  echo '<label for="wp_max_time">Expire time:</label> ';
305
  echo "<input type=\"text\" size=6 name=\"wp_max_time\" value=\"$cache_max_time\" /> seconds<br />";
306
  echo '<label for="super_cache_max_time">Super Cache Expire time:</label> ';
307
  echo "<input type=\"text\" size=6 name=\"super_cache_max_time\" value=\"$super_cache_max_time\" /> seconds";
308
- echo '<div class="submit"><input type="submit" value="Change expiration" /></div>';
309
  wp_nonce_field('wp-cache');
310
  echo "</form>\n";
311
  ?></fieldset><?php
@@ -330,7 +459,7 @@ function wp_cache_edit_rejected_ua() {
330
  }
331
 
332
 
333
- echo '<a name="user-agents"></a><fieldset class="options"><legend>Rejected User Agents</legend>';
334
  echo "<p>Strings in the HTTP 'User Agent' header that prevent WP-Cache from
335
  caching bot, spiders, and crawlers' requests.
336
  Note that cached files are still sent to these request if they already exists.</p>\n";
@@ -341,7 +470,7 @@ function wp_cache_edit_rejected_ua() {
341
  echo wp_specialchars($ua) . "\n";
342
  }
343
  echo '</textarea> ';
344
- echo '<div class="submit"><input type="submit" value="Save UA strings" /></div>';
345
  wp_nonce_field('wp-cache');
346
  echo '</form>';
347
  echo "</fieldset>\n";
@@ -365,7 +494,7 @@ function wp_cache_edit_rejected() {
365
  echo wp_specialchars($file) . "\n";
366
  }
367
  echo '</textarea> ';
368
- echo '<div class="submit"><input type="submit" value="Save strings" /></div>';
369
  wp_nonce_field('wp-cache');
370
  echo "</form>\n";
371
  }
@@ -387,7 +516,7 @@ function wp_cache_edit_accepted() {
387
  echo wp_specialchars($file) . "\n";
388
  }
389
  echo '</textarea> ';
390
- echo '<div class="submit"><input type="submit" value="Save files" /></div>';
391
  wp_nonce_field('wp-cache');
392
  echo "</form>\n";
393
  }
@@ -514,7 +643,7 @@ function wp_cache_verify_cache_dir() {
514
  $cache_path .= '/';
515
  }
516
 
517
- @mkdir( $cache_path . 'meta/' );
518
 
519
  return true;
520
  }
@@ -638,10 +767,10 @@ function wp_cache_files() {
638
  } else
639
  $list_mess = "List files";
640
 
641
- echo '<a name="list"></a><fieldset class="options"><legend>Cache contents</legend>';
642
  echo '<form name="wp_cache_content_list" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
643
  echo '<input type="hidden" name="wp_list_cache" />';
644
- echo '<div class="submit"><input type="submit" value="'.$list_mess.'" /></div>';
645
  echo "</form>\n";
646
 
647
  $count = 0;
@@ -717,21 +846,21 @@ function wp_cache_files() {
717
 
718
  echo '<form name="wp_cache_content_expired" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
719
  echo '<input type="hidden" name="wp_delete_expired" />';
720
- echo '<div class="submit"><input type="submit" value="Delete expired" /></div>';
721
  wp_nonce_field('wp-cache');
722
  echo "</form>\n";
723
 
724
 
725
  echo '<form name="wp_cache_content_delete" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
726
  echo '<input type="hidden" name="wp_delete_cache" />';
727
- echo '<div class="submit"><input id="deletepost" type="submit" value="Delete cache" /></div>';
728
 
729
  wp_nonce_field('wp-cache');
730
  echo "</form>\n";
731
 
732
  echo '<form name="wp_super_cache_stats" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
733
  echo '<input type="hidden" name="super_cache_stats" value="1" />';
734
- echo '<div class="submit"><input type="submit" value="Regenerate Super Cache Stats" /></div>';
735
  wp_nonce_field('wp-cache');
736
  echo "</form>\n";
737
  echo '</fieldset>';
78
 
79
  echo '<div class="wrap">';
80
  echo "<h2>WP Super Cache Manager</h2>\n";
81
+ if( ini_get( 'safe_mode' ) ) {
82
+ ?><h3>Warning! PHP safe mode enabled!</h3>
83
+ <p>You may experience problems running this plugin because SAFE MODE is enabled. <?php
84
+ if( !ini_get( 'safe_mode_gid' ) ) {
85
+ ?>Your server is set up to check the owner of PHP scripts before allowing them to read and write files.</p><p>You or an administrator may be able to make it work by changing the group owner of the plugin scripts to match that of the web server user. The group owner of the wp-content/cache/ directory must also be changed. See the <a href='http://php.net/features.safe-mode'>safe mode manual page</a> for further details.</p><?php
86
+ } else {
87
+ ?>You or an administrator must disable this. See the <a href='http://php.net/features.safe-mode'>safe mode manual page</a> for further details. This cannot be disabled in a .htaccess file unfortunately. It must be done in the php.ini config file.</p><?php
88
+ }
89
+ }
90
  if(isset($_REQUEST['wp_restore_config']) && $valid_nonce) {
91
  unlink($wp_cache_config_file);
92
  echo '<strong>Configuration file changed, some values might be wrong. Load the page again from the "Options" menu to reset them.</strong>';
135
  }
136
  }
137
 
138
+ ?><fieldset style='border: 1px solid #aaa' class="options">
139
  <legend>WP Super Cache Status</legend><?php
140
  echo '<form name="wp_manager" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
141
  ?>
142
  <label><input type='radio' name='wp_cache_status' value='all' <?php if( $cache_enabled == true && $super_cache_enabled == true ) { echo 'checked=checked'; } ?>> WP Cache and Super Cache enabled</label><br />
143
  <label><input type='radio' name='wp_cache_status' value='none' <?php if( $cache_enabled == false ) { echo 'checked=checked'; } ?>> WP Cache and Super Cache disabled</label><br />
144
  <label><input type='radio' name='wp_cache_status' value='wpcache' <?php if( $cache_enabled == true && $super_cache_enabled == false ) { echo 'checked=checked'; } ?>> Super Cache Disabled</label><br />
145
+ <?php
146
+ echo '<div class="submit"><input type="submit"value="Update Status &raquo;" /></div>';
147
+ wp_nonce_field('wp-cache');
148
+ ?>
149
+ </form>
150
+ </fieldset><br />
151
 
152
+ <fieldset style='border: 1px solid #aaa' class="options">
153
  <legend>Super Cache Compression</legend>
154
+ <form name="wp_manager" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post">
155
  <label><input type="radio" name="cache_compression" value="1" <?php if( $cache_compression ) { echo "checked=checked"; } ?>> Enabled</label>
156
  <label><input type="radio" name="cache_compression" value="0" <?php if( !$cache_compression ) { echo "checked=checked"; } ?>> Disabled</label>
157
  <p>Compression is disabled by default because some hosts have problems with compressed files. Switching this on and off clears the cache.</p>
201
  } elseif( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && $cache_compression ) {
202
  ?><p><strong>Super Cache compression is now enabled.</strong></p><?php
203
  }
204
+ echo '<div class="submit"><input type="submit"value="Update Compression &raquo;" /></div>';
205
  wp_nonce_field('wp-cache');
206
  echo "</form>\n";
207
  ?></fieldset><?php
 
208
 
209
  wp_cache_edit_max_time();
210
 
211
+ echo '<br /><a name="files"></a><fieldset style="border: 1px solid #aaa" class="options"><legend>Accepted filenames, rejected URIs</legend>';
212
  wp_cache_edit_rejected();
213
  echo "<br />\n";
214
  wp_cache_edit_accepted();
216
 
217
  wp_cache_edit_rejected_ua();
218
 
219
+ wp_lock_down();
220
+
221
  wp_cache_files();
222
 
223
  wp_cache_restore();
224
 
225
  ob_start();
226
  if( defined( 'WP_CACHE' ) ) {
227
+ if( function_exists( 'do_cacheaction' ) ) {
 
 
228
  do_cacheaction( 'cache_admin_page' );
229
  }
230
  }
241
  }
242
 
243
  function wp_cache_restore() {
244
+ echo '<br /><fieldset style="border: 1px solid #aaa" class="options"><legend>Configuration messed up?</legend>';
245
  echo '<form name="wp_restore" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
246
  echo '<input type="hidden" name="wp_restore_config" />';
247
+ echo '<div class="submit"><input type="submit" id="deletepost" value="Restore default configuration &raquo;" /></div>';
248
  wp_nonce_field('wp-cache');
249
  echo "</form>\n";
250
  echo '</fieldset>';
258
  add_action( 'comment_form', 'comment_form_lockdown_message' );
259
 
260
  function wp_lock_down() {
261
+ global $wpdb, $cache_path, $wp_cache_config_file, $valid_nonce, $cached_direct_pages;
262
 
263
  if(isset($_POST['wp_lock_down']) && $valid_nonce) {
264
  $wp_lock_down = $_POST['wp_lock_down'] == '1' ? '1' : '0';
274
  $wp_lock_down = '0';
275
  }
276
  }
277
+ ?><br /><fieldset style='border: 1px solid #aaa' class="options">
278
  <legend>Lock Down: <span style='color: #f00'><?php echo $wp_lock_down == '0' ? 'disabled' : 'enabled'; ?></span></legend>
279
  <p>Prepare your server for an expected spike in traffic by enabling the lock down. When this is enabled, new comments on a post will not refresh the cached static files.</p><?php
280
  if( $wp_lock_down == '1' ) {
286
  $new_lockdown_desc = $wp_lock_down == '1' ? 'Disable' : 'Enable';
287
  echo '<form name="wp_lock_down" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
288
  echo "<input type='hidden' name='wp_lock_down' value='{$new_lockdown}' />";
289
+ echo "<div class='submit'><input type='submit' value='{$new_lockdown_desc} Lock Down &raquo;' /></div>";
290
  wp_nonce_field('wp-cache');
291
  echo "</form>\n";
292
+
293
+ ?></fieldset><br /><?php
294
+ ?><fieldset style='border: 1px solid #aaa' class="options">
295
+ <legend>Directly Cached Files (advanced use only)</legend><?php
296
+
297
+ $out = '';
298
+ if( $valid_nonce && is_array( $_POST[ 'direct_pages' ] ) && !empty( $_POST[ 'direct_pages' ] ) ) {
299
+ $expiredfiles = array_diff( $cached_direct_pages, $_POST[ 'direct_pages' ] );
300
+ unset( $cached_direct_pages );
301
+ foreach( $_POST[ 'direct_pages' ] as $page ) {
302
+ $page = $wpdb->escape( $page );
303
+ if( $page != '' ) {
304
+ $cached_direct_pages[] = $page;
305
+ $out .= "'$page', ";
306
+ }
307
+ }
308
+ if( $out == '' ) {
309
+ $out = "'', ";
310
+ }
311
+ }
312
+ if( $valid_nonce && $_POST[ 'new_direct_page' ] && '' != $_POST[ 'new_direct_page' ] ) {
313
+ $page = str_replace( get_option( 'siteurl' ), '', $_POST[ 'new_direct_page' ] );
314
+ $page = $wpdb->escape( $page );
315
+ if( in_array( $page, $cached_direct_pages ) == false ) {
316
+ $cached_direct_pages[] = $page;
317
+ $out .= "'$page', ";
318
+ }
319
+ }
320
+
321
+ if( $out != '' ) {
322
+ $out = substr( $out, 0, -2 );
323
+ $out = '$cached_direct_pages = array( ' . $out . ' );';
324
+ wp_cache_replace_line('^ *\$cached_direct_pages', "$out", $wp_cache_config_file);
325
+ prune_super_cache( $cache_path, true );
326
+ }
327
+
328
+ if( !empty( $expiredfiles ) ) {
329
+ foreach( $expiredfiles as $file ) {
330
+ if( $file != '' ) {
331
+ $firstfolder = explode( '/', $file );
332
+ $firstfolder = ABSPATH . $firstfolder[1];
333
+ $file = ABSPATH . $file;
334
+ unlink( trailingslashit( $file ) . 'index.html' );
335
+ RecursiveFolderDelete( trailingslashit( $firstfolder ) );
336
+ }
337
+ }
338
+ }
339
+
340
+ if( $valid_nonce && $_POST[ 'deletepage' ] ) {
341
+ $page = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_POST['deletepage']) );
342
+ $pagefile = ABSPATH . $page . 'index.html';
343
+ $firstfolder = explode( '/', $page );
344
+ $firstfolder = ABSPATH . $firstfolder[1];
345
+ $page = ABSPATH . $page;
346
+ if( is_file( $pagefile ) && is_writable( $pagefile ) && is_writable( $firstfolder ) ) {
347
+ unlink( $pagefile );
348
+ RecursiveFolderDelete( $firstfolder );
349
+ echo "<strong>$pagefile removed!</strong><br />";
350
+ prune_super_cache( $cache_path, true );
351
+ }
352
+ }
353
+
354
+ $readonly = '';
355
+ if( !is_writeable( ABSPATH ) ) {
356
+ $readonly = 'READONLY';
357
+ ?><p><strong style='color: #a00'>WARNING! You must make <?php echo ABSPATH ?> writable to enable this feature. As this is a security risk please make it readonly after your page is generated.</strong></p><?php
358
+ } else {
359
+ ?><p><strong style='color: #a00'>WARNING! <?php echo ABSPATH ?> is writable. Please make it readonly after your page is generated as this is a security risk.</strong></p><?php
360
+ }
361
+ echo '<form name="direct_page" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
362
+ if( is_array( $cached_direct_pages ) ) {
363
+ $out = '';
364
+ foreach( $cached_direct_pages as $page ) {
365
+ if( $page == '' )
366
+ continue;
367
+ $generated = '';
368
+ if( is_file( ABSPATH . $page . '/index.html' ) )
369
+ $generated = '<input type="Submit" name="deletepage" value="' . $page . '">';
370
+ $out .= "<tr><td><input type='text' $readonly name='direct_pages[]' size='30' value='$page' /></td><td>$generated</td></tr>";
371
+ }
372
+ if( $out != '' ) {
373
+ ?><table><tr><th>Existing direct page</th><th>Delete cached file</th></tr><?php
374
+ echo "$out</table>";
375
+ }
376
+ }
377
+ if( $readonly != 'READONLY' )
378
+ echo "Add direct page: <input type='text' $readonly name='new_direct_page' size='30' value='' /><br />";
379
+
380
+ echo "<p>Directly cached files are files created directly off " . ABSPATH . " where your blog lives. This feature is only useful if you are expecting a major Digg or Slashdot level of traffic to one post or page.</p>";
381
+ if( $readonly != 'READONLY' ) {
382
+ echo "<p>For example: to cache <em>'" . trailingslashit( get_option( 'siteurl' ) ) . "about/'</em>, you would enter '" . trailingslashit( get_option( 'siteurl' ) ) . "about/' or '/about/'. The cached file will be generated the next time an anonymous user visits that page.</p>";
383
+ echo "<p>Make the textbox blank to remove it from the list of direct pages and delete the cached file.</p>";
384
+ }
385
+
386
+ wp_nonce_field('wp-cache');
387
+ if( $readonly != 'READONLY' )
388
+ echo "<div class='submit'><input type='submit' value='Update direct pages &raquo;' /></div>";
389
+ echo "</form>\n";
390
  ?></fieldset><?php
391
  }
392
 
393
+ function RecursiveFolderDelete ( $folderPath ) { // from http://www.php.net/manual/en/function.rmdir.php
394
+ if ( is_dir ( $folderPath ) ) {
395
+ $dh = opendir($folderPath);
396
+ while (false !== ($value = readdir($dh))) {
397
+ if ( $value != "." && $value != ".." ) {
398
+ $value = $folderPath . "/" . $value;
399
+ if ( is_dir ( $value ) ) {
400
+ RecursiveFolderDelete ( $value );
401
+ }
402
+ }
403
+ }
404
+ return rmdir ( $folderPath );
405
+ } else {
406
+ return FALSE;
407
+ }
408
+ }
409
+
410
  function wp_cache_edit_max_time () {
411
  global $super_cache_max_time, $cache_max_time, $wp_cache_config_file, $valid_nonce;
412
 
427
  wp_cache_replace_line('^ *\$super_cache_max_time', "\$super_cache_max_time = $super_cache_max_time;", $wp_cache_config_file);
428
  }
429
  }
430
+ ?><br /><fieldset style='border: 1px solid #aaa' class="options">
431
  <legend>Expiry Time</legend><?php
432
  echo '<form name="wp_edit_max_time" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
433
  echo '<label for="wp_max_time">Expire time:</label> ';
434
  echo "<input type=\"text\" size=6 name=\"wp_max_time\" value=\"$cache_max_time\" /> seconds<br />";
435
  echo '<label for="super_cache_max_time">Super Cache Expire time:</label> ';
436
  echo "<input type=\"text\" size=6 name=\"super_cache_max_time\" value=\"$super_cache_max_time\" /> seconds";
437
+ echo '<div class="submit"><input type="submit" value="Change expiration &raquo;" /></div>';
438
  wp_nonce_field('wp-cache');
439
  echo "</form>\n";
440
  ?></fieldset><?php
459
  }
460
 
461
 
462
+ echo '<br /><a name="user-agents"></a><fieldset style="border: 1px solid #aaa" class="options"><legend>Rejected User Agents</legend>';
463
  echo "<p>Strings in the HTTP 'User Agent' header that prevent WP-Cache from
464
  caching bot, spiders, and crawlers' requests.
465
  Note that cached files are still sent to these request if they already exists.</p>\n";
470
  echo wp_specialchars($ua) . "\n";
471
  }
472
  echo '</textarea> ';
473
+ echo '<div class="submit"><input type="submit" value="Save UA strings &raquo;" /></div>';
474
  wp_nonce_field('wp-cache');
475
  echo '</form>';
476
  echo "</fieldset>\n";
494
  echo wp_specialchars($file) . "\n";
495
  }
496
  echo '</textarea> ';
497
+ echo '<div class="submit"><input type="submit" value="Save strings &raquo;" /></div>';
498
  wp_nonce_field('wp-cache');
499
  echo "</form>\n";
500
  }
516
  echo wp_specialchars($file) . "\n";
517
  }
518
  echo '</textarea> ';
519
+ echo '<div class="submit"><input type="submit" value=" &raquo;Save files &raquo;" /></div>';
520
  wp_nonce_field('wp-cache');
521
  echo "</form>\n";
522
  }
643
  $cache_path .= '/';
644
  }
645
 
646
+ @mkdir( $cache_path . 'meta' );
647
 
648
  return true;
649
  }
767
  } else
768
  $list_mess = "List files";
769
 
770
+ echo '<br /><a name="list"></a><fieldset style="border: 1px solid #aaa" class="options"><legend>Cache contents</legend>';
771
  echo '<form name="wp_cache_content_list" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
772
  echo '<input type="hidden" name="wp_list_cache" />';
773
+ echo '<div class="submit"><input type="submit" value="'.$list_mess.' &raquo;" /></div>';
774
  echo "</form>\n";
775
 
776
  $count = 0;
846
 
847
  echo '<form name="wp_cache_content_expired" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
848
  echo '<input type="hidden" name="wp_delete_expired" />';
849
+ echo '<div class="submit"><input type="submit" value="Delete expired &raquo;" /></div>';
850
  wp_nonce_field('wp-cache');
851
  echo "</form>\n";
852
 
853
 
854
  echo '<form name="wp_cache_content_delete" action="'. $_SERVER["REQUEST_URI"] . '#list" method="post">';
855
  echo '<input type="hidden" name="wp_delete_cache" />';
856
+ echo '<div class="submit"><input id="deletepost" type="submit" value="Delete cache &raquo;" /></div>';
857
 
858
  wp_nonce_field('wp-cache');
859
  echo "</form>\n";
860
 
861
  echo '<form name="wp_super_cache_stats" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
862
  echo '<input type="hidden" name="super_cache_stats" value="1" />';
863
+ echo '<div class="submit"><input type="submit" value="Regenerate Super Cache Stats &raquo;" /></div>';
864
  wp_nonce_field('wp-cache');
865
  echo "</form>\n";
866
  echo '</fieldset>';