WP Super Cache - Version 0.5.2

Version Description

Download this release

Release Info

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

Code changes from version 0.5.1 to 0.5.2

Files changed (3) hide show
  1. readme.txt +1 -1
  2. wp-cache-phase2.php +28 -13
  3. wp-cache.php +109 -41
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: donncha
3
  Tags: performance,caching,wp-cache
4
  Tested up to: 2.3.1
5
- Stable tag: 0.5.1
6
 
7
  A modification of WP-Cache that produces static html files.
8
 
2
  Contributors: donncha
3
  Tags: performance,caching,wp-cache
4
  Tested up to: 2.3.1
5
+ Stable tag: 0.5.2
6
 
7
  A modification of WP-Cache that produces static html files.
8
 
wp-cache-phase2.php CHANGED
@@ -94,24 +94,33 @@ function wp_cache_mutex_init() {
94
  $use_flock = true;
95
  }
96
 
 
97
  if ($use_flock)
98
- $mutex = fopen($cache_path . $mutex_filename, 'w');
99
  else
100
- $mutex = sem_get($sem_id, 1, 0644 | IPC_CREAT, 1);
101
  }
102
 
103
  function wp_cache_writers_entry() {
104
  global $use_flock, $mutex, $cache_path, $mutex_filename;
105
 
 
 
 
106
  if ($use_flock)
107
  flock($mutex, LOCK_EX);
108
  else
109
  sem_acquire($mutex);
 
 
110
  }
111
 
112
  function wp_cache_writers_exit() {
113
  global $use_flock, $mutex, $cache_path, $mutex_filename;
114
 
 
 
 
115
  if ($use_flock)
116
  flock($mutex, LOCK_UN);
117
  else
@@ -134,7 +143,8 @@ function wp_cache_ob_callback($buffer) {
134
  $duration = sprintf("%0.3f", $duration);
135
  $buffer .= "\n<!-- Dynamic Page Served (once) in $duration seconds -->\n";
136
 
137
- wp_cache_writers_entry();
 
138
  $mtime = @filemtime($cache_path . $cache_filename);
139
  /* Return if:
140
  the file didn't exist before but it does exist now (another connection created)
@@ -217,11 +227,12 @@ function wp_cache_ob_callback($buffer) {
217
  function wp_cache_phase2_clean_cache($file_prefix) {
218
  global $cache_path;
219
 
220
- wp_cache_writers_entry();
 
221
  if ( ($handle = opendir( $cache_path )) ) {
222
  while ( false !== ($file = readdir($handle))) {
223
  if ( preg_match("/^$file_prefix/", $file) ) {
224
- unlink($cache_path . $file);
225
  }
226
  }
227
  closedir($handle);
@@ -239,10 +250,11 @@ function prune_super_cache($directory, $force = false) {
239
 
240
  $protected_directories = array( $cache_path . '.htaccess', $cache_path . 'meta', $cache_path . 'supercache' );
241
 
 
242
  if (is_dir($directory)) {
243
  $directory = trailingslashit( $directory );
244
  $entries = glob($directory. '*');
245
- foreach ($entries as $entry) {
246
  if ($entry != '.' && $entry != '..') {
247
  prune_super_cache($entry, $force);
248
  if( is_dir( $entry ) && ( $force || @filemtime( $entry ) + $super_cache_max_time <= $now ) ) {
@@ -269,7 +281,8 @@ function wp_cache_phase2_clean_expired($file_prefix) {
269
  global $cache_path, $cache_max_time;
270
 
271
  clearstatcache();
272
- wp_cache_writers_entry();
 
273
  $now = time();
274
  if ( ($handle = opendir( $cache_path )) ) {
275
  while ( false !== ($file = readdir($handle))) {
@@ -355,7 +368,8 @@ function wp_cache_shutdown_callback() {
355
  ob_end_flush();
356
  if ($new_cache) {
357
  $serial = serialize($wp_cache_meta_object);
358
- wp_cache_writers_entry();
 
359
  $fr = @fopen($cache_path . 'meta/' . $meta_file, 'w');
360
  if( !$fr )
361
  @mkdir( $cache_path . 'meta' );
@@ -420,7 +434,8 @@ function wp_cache_post_change($post_id) {
420
 
421
  $meta = new CacheMeta;
422
  $matches = array();
423
- wp_cache_writers_entry();
 
424
  if ( ($handle = opendir( $cache_path . 'meta/' )) ) {
425
  while ( false !== ($file = readdir($handle))) {
426
  if ( preg_match("/^({$file_prefix}{$blogcacheid}.*)\.meta/", $file, $matches) ) {
@@ -429,12 +444,12 @@ function wp_cache_post_change($post_id) {
429
  $meta = unserialize(@file_get_contents($meta_pathname));
430
  if ($post_id > 0 && $meta) {
431
  if ($meta->blog_id == $blog_id && (!$meta->post || $meta->post == $post_id) ) {
432
- unlink($meta_pathname);
433
- unlink($content_pathname);
434
  }
435
  } elseif ($meta->blog_id == $blog_id) {
436
- unlink($meta_pathname);
437
- unlink($content_pathname);
438
  }
439
 
440
  }
94
  $use_flock = true;
95
  }
96
 
97
+ $mutex = false;
98
  if ($use_flock)
99
+ $mutex = @fopen($cache_path . $mutex_filename, 'w');
100
  else
101
+ $mutex = @sem_get($sem_id, 1, 0644 | IPC_CREAT, 1);
102
  }
103
 
104
  function wp_cache_writers_entry() {
105
  global $use_flock, $mutex, $cache_path, $mutex_filename;
106
 
107
+ if( !$mutex )
108
+ return false;
109
+
110
  if ($use_flock)
111
  flock($mutex, LOCK_EX);
112
  else
113
  sem_acquire($mutex);
114
+
115
+ return true;
116
  }
117
 
118
  function wp_cache_writers_exit() {
119
  global $use_flock, $mutex, $cache_path, $mutex_filename;
120
 
121
+ if( !$mutex )
122
+ return false;
123
+
124
  if ($use_flock)
125
  flock($mutex, LOCK_UN);
126
  else
143
  $duration = sprintf("%0.3f", $duration);
144
  $buffer .= "\n<!-- Dynamic Page Served (once) in $duration seconds -->\n";
145
 
146
+ if( !wp_cache_writers_entry() )
147
+ return false;
148
  $mtime = @filemtime($cache_path . $cache_filename);
149
  /* Return if:
150
  the file didn't exist before but it does exist now (another connection created)
227
  function wp_cache_phase2_clean_cache($file_prefix) {
228
  global $cache_path;
229
 
230
+ if( !wp_cache_writers_entry() )
231
+ return false;
232
  if ( ($handle = opendir( $cache_path )) ) {
233
  while ( false !== ($file = readdir($handle))) {
234
  if ( preg_match("/^$file_prefix/", $file) ) {
235
+ @unlink($cache_path . $file);
236
  }
237
  }
238
  closedir($handle);
250
 
251
  $protected_directories = array( $cache_path . '.htaccess', $cache_path . 'meta', $cache_path . 'supercache' );
252
 
253
+ $oktodelete = false;
254
  if (is_dir($directory)) {
255
  $directory = trailingslashit( $directory );
256
  $entries = glob($directory. '*');
257
+ if( is_array( $entries ) && !empty( $entries ) ) foreach ($entries as $entry) {
258
  if ($entry != '.' && $entry != '..') {
259
  prune_super_cache($entry, $force);
260
  if( is_dir( $entry ) && ( $force || @filemtime( $entry ) + $super_cache_max_time <= $now ) ) {
281
  global $cache_path, $cache_max_time;
282
 
283
  clearstatcache();
284
+ if( !wp_cache_writers_entry() )
285
+ return false;
286
  $now = time();
287
  if ( ($handle = opendir( $cache_path )) ) {
288
  while ( false !== ($file = readdir($handle))) {
368
  ob_end_flush();
369
  if ($new_cache) {
370
  $serial = serialize($wp_cache_meta_object);
371
+ if( !wp_cache_writers_entry() )
372
+ return false;
373
  $fr = @fopen($cache_path . 'meta/' . $meta_file, 'w');
374
  if( !$fr )
375
  @mkdir( $cache_path . 'meta' );
434
 
435
  $meta = new CacheMeta;
436
  $matches = array();
437
+ if( !wp_cache_writers_entry() )
438
+ return $post_id;
439
  if ( ($handle = opendir( $cache_path . 'meta/' )) ) {
440
  while ( false !== ($file = readdir($handle))) {
441
  if ( preg_match("/^({$file_prefix}{$blogcacheid}.*)\.meta/", $file, $matches) ) {
444
  $meta = unserialize(@file_get_contents($meta_pathname));
445
  if ($post_id > 0 && $meta) {
446
  if ($meta->blog_id == $blog_id && (!$meta->post || $meta->post == $post_id) ) {
447
+ @unlink($meta_pathname);
448
+ @unlink($content_pathname);
449
  }
450
  } elseif ($meta->blog_id == $blog_id) {
451
+ @unlink($meta_pathname);
452
+ @unlink($content_pathname);
453
  }
454
 
455
  }
wp-cache.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP Super Cache
4
  Plugin URI: http://ocaoimh.ie/wp-super-cache/
5
  Description: Very fast caching module for WordPress. Once enabled, you must <a href="options-general.php?page=wp-super-cache/wp-cache.php">enable the cache</a>. Based on WP-Cache by <a href="http://mnm.uib.es/gallir/">Ricardo Galli Granada</a>.
6
- Version: 0.5.1
7
  Author: Donncha O Caoimh
8
  Author URI: http://ocaoimh.ie/
9
  */
@@ -65,7 +65,7 @@ function wp_cache_add_pages() {
65
  }
66
 
67
  function wp_cache_manager() {
68
- global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled;
69
 
70
  if( function_exists( 'is_site_admin' ) )
71
  if( !is_site_admin() )
@@ -106,11 +106,23 @@ function wp_cache_manager() {
106
  }
107
 
108
  if( !got_mod_rewrite() ) {
109
- ?><h4>Mod rewrite is not installed! Super Cache will not fully work!</h4>
110
- <p>mod_rewrite is required for serving Super Cache static files. You will still be able to use WP-Cache.</p><?php
 
 
 
 
 
111
  }
112
 
113
  if ( $valid_nonce ) {
 
 
 
 
 
 
 
114
  if( isset( $_POST[ 'wp_cache_status' ] ) ) {
115
  switch( $_POST[ 'wp_cache_status' ] ) {
116
  case 'all':
@@ -142,6 +154,7 @@ function wp_cache_manager() {
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');
@@ -156,32 +169,55 @@ function wp_cache_manager() {
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>
158
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
159
  $home_path = get_home_path();
160
  $home_root = parse_url(get_option('home'));
161
  $home_root = trailingslashit($home_root['path']);
162
  $wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) );
163
  $wprules = str_replace( "RewriteEngine On\n", '', $wprules );
164
  $wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
165
- if( strpos( $wprules, 'supercache' ) == false ) { // only write the rules once
166
- $rules = "<IfModule mod_rewrite.c>\n";
167
- $rules .= "RewriteEngine On\n";
168
- $rules .= "RewriteBase $home_root\n"; // props Chris Messina
169
- $rules .= "RewriteCond %{QUERY_STRING} !.*s=.*\n";
170
- $rules .= "RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$\n";
171
- $rules .= "RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$\n";
172
- $rules .= "RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$\n";
173
- $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
174
- $rules .= "RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz -f\n";
175
- $rules .= "RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz [L]\n\n";
176
-
177
- $rules .= "RewriteCond %{QUERY_STRING} !.*s=.*\n";
178
- $rules .= "RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$\n";
179
- $rules .= "RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$\n";
180
- $rules .= "RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$\n";
181
- $rules .= "RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html -f\n";
182
- $rules .= "RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1index.html [L]\n";
183
- $rules .= $wprules . "\n";
184
- $rules .= "</IfModule>";
 
 
 
 
 
 
 
 
 
 
 
185
  if( insert_with_markers( $home_path.'.htaccess', 'WordPress', explode( "\n", $rules ) ) ) {
186
  echo "<h4>Mod Rewrite rules updated!</h4>";
187
  echo "<p><strong>" . ABSPATH . ".htaccess has been updated with the necessary mod_rewrite rules. Please verify they are correct. The file should look like this:</strong></p>\n";
@@ -190,20 +226,42 @@ function wp_cache_manager() {
190
  echo "<p><strong> Your " . ABSPATH . ".htaccess is not writable by the webserver and must be updated with the necessary mod_rewrite rules. The new rules go above the regular WordPress rules as shown in the code below:</strong></p>\n";
191
  }
192
  echo "<p><pre># BEGIN WordPress\n{$rules}# END WordPress</pre></p>\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  }
194
  // http://allmybrain.com/2007/11/08/making-wp-super-cache-gzip-compression-work/
195
- $gziprules = "AddEncoding x-gzip .gz\n";
196
- $gziprules .= "AddType text/html .gz";
197
- $gziprules = insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $gziprules ) );
198
-
199
- if( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && !$cache_compression ) {
200
- ?><p><strong>Super Cache compression is now disabled.</strong></p> <?php
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();
@@ -316,6 +374,8 @@ function wp_lock_down() {
316
  }
317
  if( $valid_nonce && $_POST[ 'new_direct_page' ] && '' != $_POST[ 'new_direct_page' ] ) {
318
  $page = str_replace( get_option( 'siteurl' ), '', $_POST[ 'new_direct_page' ] );
 
 
319
  $page = $wpdb->escape( $page );
320
  if( in_array( $page, $cached_direct_pages ) == false ) {
321
  $cached_direct_pages[] = $page;
@@ -396,17 +456,19 @@ function wp_lock_down() {
396
  }
397
 
398
  function RecursiveFolderDelete ( $folderPath ) { // from http://www.php.net/manual/en/function.rmdir.php
399
- if ( is_dir ( $folderPath ) ) {
400
- $dh = opendir($folderPath);
401
- while (false !== ($value = readdir($dh))) {
 
 
402
  if ( $value != "." && $value != ".." ) {
403
  $value = $folderPath . "/" . $value;
404
- if ( is_dir ( $value ) ) {
405
  RecursiveFolderDelete ( $value );
406
  }
407
  }
408
  }
409
- return rmdir ( $folderPath );
410
  } else {
411
  return FALSE;
412
  }
@@ -877,7 +939,7 @@ function wpsc_dirsize($directory, $sizes) {
877
 
878
  if (is_dir($directory)) {
879
  $entries = glob($directory. '/*');
880
- foreach ($entries as $entry) {
881
  if ($entry != '.' && $entry != '..') {
882
  $sizes = wpsc_dirsize($entry, $sizes);
883
  }
@@ -957,6 +1019,12 @@ function wp_cache_clean_expired($file_prefix) {
957
 
958
  add_action('admin_menu', 'wp_cache_add_pages');
959
 
 
 
 
 
 
 
960
  if( get_option( 'gzipcompression' ) )
961
  update_option( 'gzipcompression', 0 );
962
 
3
  Plugin Name: WP Super Cache
4
  Plugin URI: http://ocaoimh.ie/wp-super-cache/
5
  Description: Very fast caching module for WordPress. Once enabled, you must <a href="options-general.php?page=wp-super-cache/wp-cache.php">enable the cache</a>. Based on WP-Cache by <a href="http://mnm.uib.es/gallir/">Ricardo Galli Granada</a>.
6
+ Version: 0.5.2
7
  Author: Donncha O Caoimh
8
  Author URI: http://ocaoimh.ie/
9
  */
65
  }
66
 
67
  function wp_cache_manager() {
68
+ global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled, $wp_cache_hello_world;
69
 
70
  if( function_exists( 'is_site_admin' ) )
71
  if( !is_site_admin() )
106
  }
107
 
108
  if( !got_mod_rewrite() ) {
109
+ ?><h4 style='color: #a00'>Mod rewrite may not be installed!</h4>
110
+ <p>It appears that mod_rewrite is not installed. Sometimes this check isn't 100% reliable, especially if you are not using Apache. Please verify that the mod_rewrite module is loaded. It is required for serving Super Cache static files. You will still be able to use WP-Cache.</p><?php
111
+ }
112
+
113
+ if( is_writeable( ABSPATH ) ) {
114
+ ?><h4 style='color: #a00'>Warning! <?php echo ABSPATH; ?> is writeable!</h4>
115
+ <p>Your blog root directory is writeable by the webserver. Unless you are creating direct cached files it is recommended that this be changed to read-only.</p><?php
116
  }
117
 
118
  if ( $valid_nonce ) {
119
+ if( isset( $_POST[ 'wp_cache_hello_world' ] ) ) {
120
+ $wp_cache_hello_world = (int)$_POST[ 'wp_cache_hello_world' ];
121
+ } else {
122
+ $wp_cache_hello_world = 0;
123
+ }
124
+ wp_cache_replace_line('^ *\$wp_cache_hello_world', '$wp_cache_hello_world = ' . (int)$wp_cache_hello_world . ";", $wp_cache_config_file);
125
+
126
  if( isset( $_POST[ 'wp_cache_status' ] ) ) {
127
  switch( $_POST[ 'wp_cache_status' ] ) {
128
  case 'all':
154
  <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 />
155
  <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 />
156
  <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 />
157
+ <p><label><input type='checkbox' name='wp_cache_hello_world' <?php if( $wp_cache_hello_world ) echo "checked"; ?> value='1'> Proudly tell the world your server is Digg proof! (places a message in your blog's footer)</label></p>
158
  <?php
159
  echo '<div class="submit"><input type="submit"value="Update Status &raquo;" /></div>';
160
  wp_nonce_field('wp-cache');
169
  <label><input type="radio" name="cache_compression" value="0" <?php if( !$cache_compression ) { echo "checked=checked"; } ?>> Disabled</label>
170
  <p>Compression is disabled by default because some hosts have problems with compressed files. Switching this on and off clears the cache.</p>
171
  <?php
172
+ if( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && !$cache_compression ) {
173
+ ?><p><strong>Super Cache compression is now disabled.</strong></p> <?php
174
+ } elseif( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && $cache_compression ) {
175
+ ?><p><strong>Super Cache compression is now enabled.</strong></p><?php
176
+ }
177
+ echo '<div class="submit"><input type="submit"value="Update Compression &raquo;" /></div>';
178
+ wp_nonce_field('wp-cache');
179
+ echo "</form>\n";
180
+ ?></fieldset><br />
181
+
182
+ <fieldset style='border: 1px solid #aaa' class="options">
183
+ <legend>Mod Rewrite Rules</legend><?php
184
  $home_path = get_home_path();
185
  $home_root = parse_url(get_option('home'));
186
  $home_root = trailingslashit($home_root['path']);
187
  $wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) );
188
  $wprules = str_replace( "RewriteEngine On\n", '', $wprules );
189
  $wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
190
+
191
+ $dohtaccess = false;
192
+ if( !$wprules || $wprules == '' ) {
193
+ echo "<h4 style='color: #a00'>Mod Rewrite rules not updated!</h4>";
194
+ echo "<p>You must have <strong>BEGIN</strong> and <strong>END</strong> markers in {$home_path}.htaccess for the auto update to work. They look like this and surround the main WordPress mod_rewrite rules:
195
+ <blockquote><code><em># BEGIN WordPress</em><br /> RewriteCond %{REQUEST_FILENAME} !-f<br /> RewriteCond %{REQUEST_FILENAME} !-d<br /> RewriteRule . /index.php [L]<br /> <em># END WordPress</em></code></blockquote>
196
+ Refresh this page when you have updated your .htaccess file to add the Super Cache rules.";
197
+ } elseif( strpos( $wprules, 'supercache' ) == false ) { // only write the rules once
198
+ $dohtaccess = true;
199
+ }
200
+ $rules = "<IfModule mod_rewrite.c>\n";
201
+ $rules .= "RewriteEngine On\n";
202
+ $rules .= "RewriteBase $home_root\n"; // props Chris Messina
203
+ $rules .= "RewriteCond %{QUERY_STRING} !.*s=.*\n";
204
+ $rules .= "RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$\n";
205
+ $rules .= "RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$\n";
206
+ $rules .= "RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$\n";
207
+ $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
208
+ $rules .= "RewriteCond %{DOCUMENT_ROOT}{$home_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}$1index.html.gz -f\n";
209
+ $rules .= "RewriteRule ^(.*) {$home_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}$1index.html.gz [L]\n\n";
210
+
211
+ $rules .= "RewriteCond %{QUERY_STRING} !.*s=.*\n";
212
+ $rules .= "RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$\n";
213
+ $rules .= "RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$\n";
214
+ $rules .= "RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$\n";
215
+ $rules .= "RewriteCond %{DOCUMENT_ROOT}{$home_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}$1index.html -f\n";
216
+ $rules .= "RewriteRule ^(.*) {$home_root}wp-content/cache/supercache/%{HTTP_HOST}{$home_root}$1index.html [L]\n";
217
+ $rules .= "WPRULES\n";
218
+ $rules .= "</IfModule>";
219
+ if( $dohtaccess ) {
220
+ $rules = str_replace( 'WPRULES', $wprules, $rules );
221
  if( insert_with_markers( $home_path.'.htaccess', 'WordPress', explode( "\n", $rules ) ) ) {
222
  echo "<h4>Mod Rewrite rules updated!</h4>";
223
  echo "<p><strong>" . ABSPATH . ".htaccess has been updated with the necessary mod_rewrite rules. Please verify they are correct. The file should look like this:</strong></p>\n";
226
  echo "<p><strong> Your " . ABSPATH . ".htaccess is not writable by the webserver and must be updated with the necessary mod_rewrite rules. The new rules go above the regular WordPress rules as shown in the code below:</strong></p>\n";
227
  }
228
  echo "<p><pre># BEGIN WordPress\n{$rules}# END WordPress</pre></p>\n";
229
+ } else {
230
+ $rules = str_replace( 'WPRULES', '', $rules );
231
+ /* http://www.netlobo.com/div_hiding.html */
232
+ ?>
233
+ <script type='text/javascript'>
234
+ <!--
235
+ function toggleLayer( whichLayer ) {
236
+ var elem, vis;
237
+ if( document.getElementById ) // this is the way the standards work
238
+ elem = document.getElementById( whichLayer );
239
+ else if( document.all ) // this is the way old msie versions work
240
+ elem = document.all[whichLayer];
241
+ else if( document.layers ) // this is the way nn4 works
242
+ elem = document.layers[whichLayer];
243
+ vis = elem.style;
244
+ // if the style.display value is blank we try to figure it out here
245
+ if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
246
+ vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
247
+ vis.display = (vis.display==''||vis.display=='block')?'none':'block';
248
+ }
249
+ // -->
250
+ </script>
251
+ <p>WP Super Cache has modified your <?php echo ABSPATH ?>.htaccess file. Click the following link to see the lines added. If you have upgraded the plugin make sure these rules match. <a href="javascript:toggleLayer('rewriterules');" title="See your mod_rewrite rules">View mod_rewrite rules</a>
252
+ <div id='rewriterules' style='display: none;'>
253
+ <?php echo "<p><pre># BEGIN WordPress\n{$rules}# END WordPress</pre></p>\n"; ?>
254
+ </div>
255
+ <?php
256
  }
257
  // http://allmybrain.com/2007/11/08/making-wp-super-cache-gzip-compression-work/
258
+ if( !is_file( $cache_path . '.htaccess' ) ) {
259
+ $gziprules = "AddEncoding x-gzip .gz\n";
260
+ $gziprules .= "AddType text/html .gz";
261
+ $gziprules = insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $gziprules ) );
262
+ echo "<h4>Gzip encoding rules in {$cache_path}.htaccess created.</h4>";
 
 
 
263
  }
264
+
 
 
265
  ?></fieldset><?php
266
 
267
  wp_cache_edit_max_time();
374
  }
375
  if( $valid_nonce && $_POST[ 'new_direct_page' ] && '' != $_POST[ 'new_direct_page' ] ) {
376
  $page = str_replace( get_option( 'siteurl' ), '', $_POST[ 'new_direct_page' ] );
377
+ if( substr( $page, 0, 1 ) != '/' )
378
+ $page = '/' . $page;
379
  $page = $wpdb->escape( $page );
380
  if( in_array( $page, $cached_direct_pages ) == false ) {
381
  $cached_direct_pages[] = $page;
456
  }
457
 
458
  function RecursiveFolderDelete ( $folderPath ) { // from http://www.php.net/manual/en/function.rmdir.php
459
+ if( trailingslashit( constant( 'ABSPATH' ) ) == trailingslashit( $folderPath ) )
460
+ return false;
461
+ if ( @is_dir ( $folderPath ) ) {
462
+ $dh = @opendir($folderPath);
463
+ while (false !== ($value = @readdir($dh))) {
464
  if ( $value != "." && $value != ".." ) {
465
  $value = $folderPath . "/" . $value;
466
+ if ( @is_dir ( $value ) ) {
467
  RecursiveFolderDelete ( $value );
468
  }
469
  }
470
  }
471
+ return @rmdir ( $folderPath );
472
  } else {
473
  return FALSE;
474
  }
939
 
940
  if (is_dir($directory)) {
941
  $entries = glob($directory. '/*');
942
+ if( is_array( $entries ) && !empty( $entries ) ) foreach ($entries as $entry) {
943
  if ($entry != '.' && $entry != '..') {
944
  $sizes = wpsc_dirsize($entry, $sizes);
945
  }
1019
 
1020
  add_action('admin_menu', 'wp_cache_add_pages');
1021
 
1022
+ function wp_super_cache_footer() {
1023
+ ?><p><?php bloginfo('name'); ?> is Digg proof thanks to caching by <a href="http://ocaoimh.ie/wp-super-cache/">WP Super Cache</a>!</p><?php
1024
+ }
1025
+ if( isset( $wp_cache_hello_world ) && $wp_cache_hello_world )
1026
+ add_action( 'wp_footer', 'wp_super_cache_footer' );
1027
+
1028
  if( get_option( 'gzipcompression' ) )
1029
  update_option( 'gzipcompression', 0 );
1030