Version Description
Download this release
Release Info
Developer | donncha |
Plugin | WP Super Cache |
Version | 0.4 |
Comparing to | |
See all releases |
Code changes from version 0.3.1 to 0.4
- Changelog.txt +124 -0
- plugins/searchengine.php +2 -2
- readme.txt +23 -56
- wp-cache-phase1.php +2 -5
- wp-cache-phase2.php +47 -41
- wp-cache.php +160 -54
Changelog.txt
CHANGED
@@ -1,3 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
2007-11-07 15:27 donncha
|
2 |
|
3 |
* readme.txt: Bump version to 0.3.1 (getting to 1.0 far too
|
1 |
+
2007-11-12 15:23 donncha
|
2 |
+
|
3 |
+
* readme.txt, wp-cache.php: Bump version
|
4 |
+
Update readme docs
|
5 |
+
Add options page for wpmu site admins
|
6 |
+
|
7 |
+
2007-11-12 11:32 donncha
|
8 |
+
|
9 |
+
* wp-cache.php: Check if cache config file is out of date
|
10 |
+
|
11 |
+
2007-11-12 11:14 donncha
|
12 |
+
|
13 |
+
* wp-cache-phase2.php, wp-cache.php: Hide some warning messages
|
14 |
+
Don't super cache $_GET requests
|
15 |
+
Use wp_mkdir_p() instead of mkpath()
|
16 |
+
Don't delete meta, supercache or .htaccess
|
17 |
+
|
18 |
+
2007-11-11 10:05 donncha
|
19 |
+
|
20 |
+
* wp-cache.php: Don't want to check for .gz files twice!
|
21 |
+
|
22 |
+
2007-11-11 08:06 donncha
|
23 |
+
|
24 |
+
* wp-cache.php: Added 'comment moderation' message when blog locked
|
25 |
+
down.
|
26 |
+
Formatting changes
|
27 |
+
Use 'manage_options' instead of administrator because viper
|
28 |
+
changed his role names :)
|
29 |
+
|
30 |
+
2007-11-11 01:13 donncha
|
31 |
+
|
32 |
+
* wp-cache.php: If .htaccess updating fails, inform the user
|
33 |
+
|
34 |
+
2007-11-11 00:20 donncha
|
35 |
+
|
36 |
+
* wp-cache-phase2.php, wp-cache.php: Added "Lockdown" function so
|
37 |
+
static files won't be deleted by comments
|
38 |
+
Minor changes to admin page formatting
|
39 |
+
get_settings to get_option
|
40 |
+
|
41 |
+
2007-11-10 21:06 donncha
|
42 |
+
|
43 |
+
* wp-cache.php: Spell out radio boxes a bit more.
|
44 |
+
Modified .htaccess rules so search pages aren't served from super
|
45 |
+
cache
|
46 |
+
Actually insert_with_markers instead of echoing the command!
|
47 |
+
Tell user rules have been updated
|
48 |
+
Disable super cache *before* renaming directory. Sleep for a
|
49 |
+
second before
|
50 |
+
deleting to allow other processes to finish
|
51 |
+
|
52 |
+
2007-11-10 20:03 donncha
|
53 |
+
|
54 |
+
* wp-cache-phase2.php: Make sure the .htaccess isn't deleted
|
55 |
+
|
56 |
+
2007-11-10 09:28 donncha
|
57 |
+
|
58 |
+
* wp-cache-phase2.php: Don't remove super-cache file until comment
|
59 |
+
is approved
|
60 |
+
|
61 |
+
2007-11-10 07:19 donncha
|
62 |
+
|
63 |
+
* wp-cache.php: Check that WP_CACHE is defined before checking for
|
64 |
+
do_cacheaction.
|
65 |
+
Better instructions for verifying a new install
|
66 |
+
|
67 |
+
2007-11-09 21:33 donncha
|
68 |
+
|
69 |
+
* wp-cache.php: Define WPCACHEHOME properly, thanks tummbler for
|
70 |
+
testing!
|
71 |
+
|
72 |
+
2007-11-09 17:09 donncha
|
73 |
+
|
74 |
+
* wp-cache-phase2.php: Don't super-cache WordPress searches. May
|
75 |
+
need to extend that to any GET activity
|
76 |
+
|
77 |
+
2007-11-09 15:01 donncha
|
78 |
+
|
79 |
+
* wp-cache-phase2.php: Change preg_match delimiter so slashes work
|
80 |
+
again
|
81 |
+
|
82 |
+
2007-11-09 14:41 donncha
|
83 |
+
|
84 |
+
* readme.txt: Updated documentation
|
85 |
+
|
86 |
+
2007-11-09 14:27 donncha
|
87 |
+
|
88 |
+
* wp-cache.php: Use get_mod_rewrite() to detect if that module is
|
89 |
+
loaded
|
90 |
+
Automatically populate the .htaccess file if it's writable
|
91 |
+
Add gzip encoding rules to the cache dir, props Dennis @
|
92 |
+
http://allmybrain.com/2007/11/08/making-wp-super-cache-gzip-compression-work/
|
93 |
+
Replace Windows folder deliminator, "\" with "/" in WPCACHEHOME,
|
94 |
+
props Computer Guru @
|
95 |
+
http://neosmart.net/blog/2007/getting-wordpress-super-cache-to-run-on-a-windows-iis-or-apache-server/
|
96 |
+
|
97 |
+
2007-11-09 01:19 donncha
|
98 |
+
|
99 |
+
* wp-cache-phase2.php: Move is_feed() check earlier.
|
100 |
+
Check that mkpath() path is in $cache_path
|
101 |
+
|
102 |
+
2007-11-08 21:57 donncha
|
103 |
+
|
104 |
+
* wp-cache.php: Single quote ABSPATH
|
105 |
+
Check advanced-cache.php for version, remove if necessary, fixed
|
106 |
+
create conditions
|
107 |
+
|
108 |
+
2007-11-08 21:55 donncha
|
109 |
+
|
110 |
+
* wp-cache-phase1.php: realpath() two filenames
|
111 |
+
|
112 |
+
2007-11-08 21:53 donncha
|
113 |
+
|
114 |
+
* readme.txt: Fix subdirectory .htaccess rules, props Computer Guru
|
115 |
+
|
116 |
+
2007-11-08 21:51 donncha
|
117 |
+
|
118 |
+
* plugins/searchengine.php: Hide setcookie errors
|
119 |
+
Return correct string
|
120 |
+
|
121 |
+
2007-11-07 15:38 donncha
|
122 |
+
|
123 |
+
* Changelog.txt: Added Changelog.txt
|
124 |
+
|
125 |
2007-11-07 15:27 donncha
|
126 |
|
127 |
* readme.txt: Bump version to 0.3.1 (getting to 1.0 far too
|
plugins/searchengine.php
CHANGED
@@ -22,7 +22,7 @@ function wp_supercache_searchengine( $string ) {
|
|
22 |
}
|
23 |
if( $se ) {
|
24 |
$string = 'searchengine';
|
25 |
-
setcookie( '7a1254cba80da02d5478d91cfd0a873a', 1, time()+3600, '/' );
|
26 |
}
|
27 |
}
|
28 |
}
|
@@ -38,7 +38,7 @@ function searchenginesupercache( $user_info ) {
|
|
38 |
} else {
|
39 |
return false;
|
40 |
}
|
41 |
-
return $
|
42 |
}
|
43 |
|
44 |
function searchengine_phase2_actions() {
|
22 |
}
|
23 |
if( $se ) {
|
24 |
$string = 'searchengine';
|
25 |
+
@setcookie( '7a1254cba80da02d5478d91cfd0a873a', 1, time()+3600, '/' );
|
26 |
}
|
27 |
}
|
28 |
}
|
38 |
} else {
|
39 |
return false;
|
40 |
}
|
41 |
+
return $user_info;
|
42 |
}
|
43 |
|
44 |
function searchengine_phase2_actions() {
|
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.
|
6 |
|
7 |
A modification of WP-Cache that produces static html files.
|
8 |
|
@@ -10,12 +10,19 @@ A modification of WP-Cache that produces static html files.
|
|
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 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
This plugin is a modified version of the WP-Cache 2 plugin by Ricardo Galli Granada.
|
21 |
His plugin is still available. We're standing on the shoulders of giants and benefiting
|
@@ -25,66 +32,22 @@ See the following URLs for more info on WP-Cache 2
|
|
25 |
1. http://mnm.uib.es/gallir/wp-cache-2/
|
26 |
2. http://wordpress.org/extend/plugins/wp-cache/
|
27 |
|
28 |
-
|
29 |
-
or a Slashdotting has been to manually save copies of dynamically generated pages,
|
30 |
-
and place them in directories that match the permalinks structure.
|
31 |
-
|
32 |
-
This method of performance enhancement does help servers handle a higher load
|
33 |
-
without crashing, but is only effective when an oncoming rush of traffic can be
|
34 |
-
anticipated.
|
35 |
-
|
36 |
-
WP-Cache alone, while helpful, is not adequate in many cases, so this modification
|
37 |
-
was created to effectively mimic the manual page caching method, but to handle it
|
38 |
-
in an automated fashion.
|
39 |
-
|
40 |
-
Original WP-Cache by Ricardo Galli Granada, http://mnm.uib.es/gallir/
|
41 |
-
WP Super Cache by Donncha O Caoimh, http://ocaoimh.ie/
|
42 |
|
43 |
== Installation ==
|
44 |
-
1. You must have fancy permalinks enabled for this to work.
|
45 |
-
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
|
46 |
3. Upload this directory to your plugins directory. It will create a 'wp-content/plugins/wp-super-cache/' directory.
|
47 |
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.
|
48 |
5. WordPress users should go to their Plugins page and activate "WP Super Cache".
|
49 |
6. Now go to Options->WP Super Cache and enable caching. If you see an error message or a blank screen you may need to fix it. See the "FAQ" section later in this readme for instructions.
|
50 |
-
7.
|
51 |
-
|
52 |
-
RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
|
53 |
-
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
|
54 |
-
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
|
55 |
-
RewriteCond %{HTTP:Accept-Encoding} gzip
|
56 |
-
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz -f
|
57 |
-
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz [L]
|
58 |
-
|
59 |
-
RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
|
60 |
-
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
|
61 |
-
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
|
62 |
-
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html -f
|
63 |
-
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1index.html [L]
|
64 |
-
|
65 |
-
That code must be inserted above the standard WordPress rewrite rules.
|
66 |
-
If your blog isn't located at the root of your server, you must add that directory
|
67 |
-
to the rules. For example, if your blog is in the directory "/blog/":
|
68 |
-
|
69 |
-
RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
|
70 |
-
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
|
71 |
-
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
|
72 |
-
RewriteCond %{HTTP:Accept-Encoding} gzip
|
73 |
-
RewriteCond %{DOCUMENT_ROOT}/blog/wp-content/cache/supercache/%{HTTP_HOST}/blog/$1index.html.gz -f
|
74 |
-
RewriteRule ^(.*) /blog/wp-content/cache/supercache/%{HTTP_HOST}/blog/$1index.html.gz [L]
|
75 |
-
|
76 |
-
RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
|
77 |
-
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
|
78 |
-
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
|
79 |
-
RewriteCond %{DOCUMENT_ROOT}/blog/wp-content/cache/supercache/%{HTTP_HOST}/blog/$1index.html -f
|
80 |
-
RewriteRule ^(.*) /blog/wp-content/cache/supercache/%{HTTP_HOST}/$1/blog/index.html [L]
|
81 |
-
|
82 |
-
Your .htaccess should look similar to this:
|
83 |
|
84 |
-----------------.htaccess-----------------
|
85 |
RewriteEngine On
|
86 |
RewriteBase /
|
87 |
|
|
|
88 |
RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
|
89 |
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
|
90 |
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
|
@@ -92,6 +55,7 @@ Your .htaccess should look similar to this:
|
|
92 |
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz -f
|
93 |
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz [L]
|
94 |
|
|
|
95 |
RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
|
96 |
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
|
97 |
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
|
@@ -102,6 +66,9 @@ Your .htaccess should look similar to this:
|
|
102 |
RewriteCond %{REQUEST_FILENAME} !-d
|
103 |
RewriteRule . /index.php [L]
|
104 |
-----------------.htaccess-----------------
|
|
|
|
|
|
|
105 |
|
106 |
== Frequently Asked Questions ==
|
107 |
If things don't work when you installed the plugin here are a few things to check:
|
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 |
|
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
|
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.
|
42 |
5. WordPress users should go to their Plugins page and activate "WP Super Cache".
|
43 |
6. Now go to Options->WP Super Cache and enable caching. If you see an error message or a blank screen you may need to fix it. See the "FAQ" section later in this readme for instructions.
|
44 |
+
7. mod_rewrite rules will be inserted into your .htaccess file. Look in your web root directory for this file. It should look similar to this:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
-----------------.htaccess-----------------
|
47 |
RewriteEngine On
|
48 |
RewriteBase /
|
49 |
|
50 |
+
RewriteCond %{QUERY_STRING} !.*s=.*
|
51 |
RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
|
52 |
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
|
53 |
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
|
55 |
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz -f
|
56 |
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz [L]
|
57 |
|
58 |
+
RewriteCond %{QUERY_STRING} !.*s=.*
|
59 |
RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
|
60 |
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
|
61 |
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
|
66 |
RewriteCond %{REQUEST_FILENAME} !-d
|
67 |
RewriteRule . /index.php [L]
|
68 |
-----------------.htaccess-----------------
|
69 |
+
8. After you have enabled the plugin, look for "wp-content/cache/.htaccess". If it's not there you must create it. It should read:
|
70 |
+
AddEncoding x-gzip .gz
|
71 |
+
AddType text/html .gz
|
72 |
|
73 |
== Frequently Asked Questions ==
|
74 |
If things don't work when you installed the plugin here are a few things to check:
|
wp-cache-phase1.php
CHANGED
@@ -25,11 +25,8 @@ if (!$cache_enabled || $_SERVER["REQUEST_METHOD"] == 'POST')
|
|
25 |
return;
|
26 |
|
27 |
$file_expired = false;
|
28 |
-
|
29 |
-
|
30 |
$cache_filename = '';
|
31 |
$meta_file = '';
|
32 |
-
|
33 |
$wp_cache_gzip_encoding = '';
|
34 |
|
35 |
function gzip_accepted(){
|
@@ -49,8 +46,8 @@ $key = $blogcacheid . md5($_SERVER['HTTP_HOST'].preg_replace('/#.*$/', '', $_SER
|
|
49 |
|
50 |
$cache_filename = $file_prefix . $key . '.html';
|
51 |
$meta_file = $file_prefix . $key . '.meta';
|
52 |
-
$cache_file = $cache_path . $cache_filename;
|
53 |
-
$meta_pathname = $cache_path . 'meta/' . $meta_file;
|
54 |
|
55 |
$wp_start_time = microtime();
|
56 |
if( ($mtime = @filemtime($meta_pathname)) ) {
|
25 |
return;
|
26 |
|
27 |
$file_expired = false;
|
|
|
|
|
28 |
$cache_filename = '';
|
29 |
$meta_file = '';
|
|
|
30 |
$wp_cache_gzip_encoding = '';
|
31 |
|
32 |
function gzip_accepted(){
|
46 |
|
47 |
$cache_filename = $file_prefix . $key . '.html';
|
48 |
$meta_file = $file_prefix . $key . '.meta';
|
49 |
+
$cache_file = realpath( $cache_path . $cache_filename );
|
50 |
+
$meta_pathname = realpath( $cache_path . 'meta/' . $meta_file );
|
51 |
|
52 |
$wp_start_time = microtime();
|
53 |
if( ($mtime = @filemtime($meta_pathname)) ) {
|
wp-cache-phase2.php
CHANGED
@@ -12,7 +12,7 @@ function wp_cache_phase2() {
|
|
12 |
global $wp_cache_gzip_encoding;
|
13 |
|
14 |
wp_cache_mutex_init();
|
15 |
-
if(function_exists('add_action')) {
|
16 |
// Post ID is received
|
17 |
add_action('publish_post', 'wp_cache_post_change', 0);
|
18 |
add_action('edit_post', 'wp_cache_post_change', 0);
|
@@ -64,7 +64,7 @@ function wp_cache_is_rejected($uri) {
|
|
64 |
if (strstr($uri, '/wp-admin/'))
|
65 |
return true; // we don't allow caching of wp-admin for security reasons
|
66 |
foreach ($cache_rejected_uri as $expr) {
|
67 |
-
if( preg_match( "
|
68 |
return true;
|
69 |
}
|
70 |
return false;
|
@@ -123,7 +123,6 @@ function wp_cache_ob_callback($buffer) {
|
|
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 |
-
|
127 |
/* Mode paranoic, check for closing tags
|
128 |
* we avoid caching incomplete files */
|
129 |
if (is_404() || !preg_match('/(<\/html>|<\/rss>|<\/feed>)/i',$buffer) ) {
|
@@ -146,25 +145,22 @@ function wp_cache_ob_callback($buffer) {
|
|
146 |
$dir = strtolower(preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"])).preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_SERVER['REQUEST_URI']) ); // To avoid XSS attacs
|
147 |
$dir = trailingslashit( $cache_path . 'supercache/' . $dir );
|
148 |
$supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]);
|
149 |
-
if( $super_cache_enabled == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) )
|
150 |
$super_cache_enabled = false;
|
151 |
-
}
|
152 |
|
153 |
$fr = @fopen($cache_path . $cache_filename, 'w');
|
154 |
if (!$fr)
|
155 |
$buffer = "Couldn't write to: " . $cache_path . $cache_filename . "\n";
|
156 |
if( $super_cache_enabled ) {
|
157 |
-
if( is_dir( $dir ) == false )
|
158 |
-
@
|
159 |
|
160 |
$user_info = wp_cache_get_cookies_values();
|
161 |
$do_cache = apply_filters( 'do_createsupercache', $user_info );
|
162 |
if( $user_info == '' || $do_cache === true ) {
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
$gz = @gzopen("{$dir}index.html.gz", 'w3');
|
167 |
-
}
|
168 |
}
|
169 |
}
|
170 |
|
@@ -237,20 +233,31 @@ function prune_super_cache($directory, $force = false) {
|
|
237 |
|
238 |
$now = time();
|
239 |
|
|
|
|
|
240 |
if (is_dir($directory)) {
|
241 |
-
$
|
|
|
242 |
foreach ($entries as $entry) {
|
243 |
if ($entry != '.' && $entry != '..') {
|
244 |
prune_super_cache($entry, $force);
|
245 |
-
if(
|
246 |
-
|
247 |
-
|
|
|
|
|
|
|
248 |
}
|
249 |
}
|
250 |
}
|
251 |
} else {
|
252 |
-
if(
|
253 |
-
|
|
|
|
|
|
|
|
|
|
|
254 |
}
|
255 |
}
|
256 |
|
@@ -269,8 +276,9 @@ function wp_cache_phase2_clean_expired($file_prefix) {
|
|
269 |
continue;
|
270 |
}
|
271 |
if($file != '.' && $file != '..') {
|
272 |
-
if
|
273 |
-
|
|
|
274 |
} elseif( is_dir( $cache_path . $file ) ) {
|
275 |
prune_super_cache( $cache_path . $file );
|
276 |
}
|
@@ -334,7 +342,7 @@ function wp_cache_shutdown_callback() {
|
|
334 |
} else { // not a feed
|
335 |
$value = 'text/html';
|
336 |
}
|
337 |
-
$value .= "; charset=\"" .
|
338 |
|
339 |
@header("Content-Type: $value");
|
340 |
array_push($wp_cache_meta_object->headers, "Content-Type: $value");
|
@@ -344,7 +352,7 @@ function wp_cache_shutdown_callback() {
|
|
344 |
if ($new_cache) {
|
345 |
$serial = serialize($wp_cache_meta_object);
|
346 |
wp_cache_writers_entry();
|
347 |
-
$fr = fopen($cache_path . 'meta/' . $meta_file, 'w');
|
348 |
if( !$fr )
|
349 |
@mkdir( $cache_path . 'meta/' );
|
350 |
$fr = fopen($cache_path . 'meta/' . $meta_file, 'w');
|
@@ -367,12 +375,17 @@ function wp_cache_no_postid($id) {
|
|
367 |
}
|
368 |
|
369 |
function wp_cache_get_postid_from_comment($comment_id) {
|
|
|
370 |
$comment = get_commentdata($comment_id, 1, true);
|
371 |
$postid = $comment['comment_post_ID'];
|
372 |
// Do nothing if comment is not moderated
|
373 |
// http://ocaoimh.ie/2006/12/05/caching-wordpress-with-wp-cache-in-a-spam-filled-world
|
374 |
-
if( !preg_match('/wp-admin\//', $_SERVER['REQUEST_URI'])
|
375 |
-
|
|
|
|
|
|
|
|
|
376 |
// We must check it up again due to WP bugs calling two different actions
|
377 |
// for delete, for example both wp_set_comment_status and delete_comment
|
378 |
// are called when deleting a comment
|
@@ -383,22 +396,22 @@ function wp_cache_get_postid_from_comment($comment_id) {
|
|
383 |
}
|
384 |
|
385 |
function wp_cache_post_change($post_id) {
|
386 |
-
global $file_prefix;
|
387 |
-
global $cache_path;
|
388 |
-
global $blog_id;
|
389 |
-
global $blogcacheid;
|
390 |
static $last_processed = -1;
|
391 |
|
392 |
// Avoid cleaning twice the same pages
|
393 |
if ($post_id == $last_processed) return $post_id;
|
394 |
$last_processed = $post_id;
|
395 |
$permalink = trailingslashit( str_replace( get_option( 'siteurl' ), '', post_permalink( $post_id ) ) );
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
|
|
|
|
|
|
402 |
}
|
403 |
|
404 |
$meta = new CacheMeta;
|
@@ -444,11 +457,4 @@ function wp_cache_post_id() {
|
|
444 |
if ($_POST['p'] > 0) return $_POST['p'];
|
445 |
return 0;
|
446 |
}
|
447 |
-
|
448 |
-
if( !function_exists( 'mkpath' ) ) {
|
449 |
-
function mkpath($path) {
|
450 |
-
if(@mkdir($path, 0777) or file_exists($path)) return true;
|
451 |
-
return (mkpath(dirname($path)) and mkdir($path, 0777));
|
452 |
-
}
|
453 |
-
}
|
454 |
?>
|
12 |
global $wp_cache_gzip_encoding;
|
13 |
|
14 |
wp_cache_mutex_init();
|
15 |
+
if(function_exists('add_action') && ( !defined( 'WPLOCKDOWN' ) || ( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) == '0' ) ) ) {
|
16 |
// Post ID is received
|
17 |
add_action('publish_post', 'wp_cache_post_change', 0);
|
18 |
add_action('edit_post', 'wp_cache_post_change', 0);
|
64 |
if (strstr($uri, '/wp-admin/'))
|
65 |
return true; // we don't allow caching of wp-admin for security reasons
|
66 |
foreach ($cache_rejected_uri as $expr) {
|
67 |
+
if( preg_match( "~$expr~", $uri ) )
|
68 |
return true;
|
69 |
}
|
70 |
return false;
|
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 */
|
128 |
if (is_404() || !preg_match('/(<\/html>|<\/rss>|<\/feed>)/i',$buffer) ) {
|
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;
|
|
|
150 |
|
151 |
$fr = @fopen($cache_path . $cache_filename, 'w');
|
152 |
if (!$fr)
|
153 |
$buffer = "Couldn't write to: " . $cache_path . $cache_filename . "\n";
|
154 |
if( $super_cache_enabled ) {
|
155 |
+
if( @is_dir( $dir ) == false )
|
156 |
+
@wp_mkdir_p( $dir );
|
157 |
|
158 |
$user_info = wp_cache_get_cookies_values();
|
159 |
$do_cache = apply_filters( 'do_createsupercache', $user_info );
|
160 |
if( $user_info == '' || $do_cache === true ) {
|
161 |
+
$fr2 = @fopen("{$dir}index.html", 'w');
|
162 |
+
if( $cache_compression )
|
163 |
+
$gz = @gzopen("{$dir}index.html.gz", 'w3');
|
|
|
|
|
164 |
}
|
165 |
}
|
166 |
|
233 |
|
234 |
$now = time();
|
235 |
|
236 |
+
$protected_directories = array( $cache_path . '.htaccess', $cache_path . 'meta', $cache_path . 'supercache' );
|
237 |
+
|
238 |
if (is_dir($directory)) {
|
239 |
+
$directory = trailingslashit( $directory );
|
240 |
+
$entries = glob($directory. '*');
|
241 |
foreach ($entries as $entry) {
|
242 |
if ($entry != '.' && $entry != '..') {
|
243 |
prune_super_cache($entry, $force);
|
244 |
+
if( is_dir( $entry ) && ( $force || @filemtime( $entry ) + $super_cache_max_time <= $now ) ) {
|
245 |
+
$oktodelete = true;
|
246 |
+
if( in_array( $entry, $protected_directories ) )
|
247 |
+
$oktodelete = false;
|
248 |
+
if( $oktodelete )
|
249 |
+
@rmdir( addslashes( $entry ) );
|
250 |
}
|
251 |
}
|
252 |
}
|
253 |
} else {
|
254 |
+
if( is_file($directory) && ($force || filemtime( $directory ) + $super_cache_max_time <= $now ) ) {
|
255 |
+
$oktodelete = true;
|
256 |
+
if( in_array( $directory, $protected_directories ) )
|
257 |
+
$oktodelete = false;
|
258 |
+
if( $oktodelete )
|
259 |
+
@unlink( addslashes( $directory ) );
|
260 |
+
}
|
261 |
}
|
262 |
}
|
263 |
|
276 |
continue;
|
277 |
}
|
278 |
if($file != '.' && $file != '..') {
|
279 |
+
if( is_dir( $cache_path . $file ) == false && (filemtime($cache_path . $file) + $cache_max_time) <= $now ) {
|
280 |
+
if( substr( $file, -9 ) != '.htaccess' )
|
281 |
+
@unlink($cache_path . $file);
|
282 |
} elseif( is_dir( $cache_path . $file ) ) {
|
283 |
prune_super_cache( $cache_path . $file );
|
284 |
}
|
342 |
} else { // not a feed
|
343 |
$value = 'text/html';
|
344 |
}
|
345 |
+
$value .= "; charset=\"" . get_option('blog_charset') . "\"";
|
346 |
|
347 |
@header("Content-Type: $value");
|
348 |
array_push($wp_cache_meta_object->headers, "Content-Type: $value");
|
352 |
if ($new_cache) {
|
353 |
$serial = serialize($wp_cache_meta_object);
|
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');
|
375 |
}
|
376 |
|
377 |
function wp_cache_get_postid_from_comment($comment_id) {
|
378 |
+
global $super_cache_enabled;
|
379 |
$comment = get_commentdata($comment_id, 1, true);
|
380 |
$postid = $comment['comment_post_ID'];
|
381 |
// Do nothing if comment is not moderated
|
382 |
// http://ocaoimh.ie/2006/12/05/caching-wordpress-with-wp-cache-in-a-spam-filled-world
|
383 |
+
if( !preg_match('/wp-admin\//', $_SERVER['REQUEST_URI']) )
|
384 |
+
if( $comment['comment_approved'] == 'spam' ) { // changed from 1 to "spam"
|
385 |
+
return $post_id;
|
386 |
+
} elseif( $comment['comment_approved'] == '0' ) {
|
387 |
+
$super_cache_enabled = 0; // don't remove the super cache static file until comment is approved
|
388 |
+
}
|
389 |
// We must check it up again due to WP bugs calling two different actions
|
390 |
// for delete, for example both wp_set_comment_status and delete_comment
|
391 |
// are called when deleting a comment
|
396 |
}
|
397 |
|
398 |
function wp_cache_post_change($post_id) {
|
399 |
+
global $file_prefix, $cache_path, $blog_id, $blogcacheid, $super_cache_enabled;
|
|
|
|
|
|
|
400 |
static $last_processed = -1;
|
401 |
|
402 |
// Avoid cleaning twice the same pages
|
403 |
if ($post_id == $last_processed) return $post_id;
|
404 |
$last_processed = $post_id;
|
405 |
$permalink = trailingslashit( str_replace( get_option( 'siteurl' ), '', post_permalink( $post_id ) ) );
|
406 |
+
if( $super_cache_enabled ) {
|
407 |
+
$permalink = trailingslashit( str_replace( get_option( 'siteurl' ), '', post_permalink( $post_id ) ) );
|
408 |
+
$siteurl = str_replace( 'http://', '', get_option( 'siteurl' ) );
|
409 |
+
$dir = $cache_path . 'supercache/' . strtolower(preg_replace('/:.*$/', '', $siteurl ) );
|
410 |
+
$files_to_delete = array( $dir . '/index.html', $dir . '/feed/index.html', $dir . $permalink . 'index.html', $dir . $permalink . 'feed/index.html' );
|
411 |
+
foreach( $files_to_delete as $cache_file ) {
|
412 |
+
@unlink( $cache_file );
|
413 |
+
@unlink( $cache_file . '.gz' );
|
414 |
+
}
|
415 |
}
|
416 |
|
417 |
$meta = new CacheMeta;
|
457 |
if ($_POST['p'] > 0) return $_POST['p'];
|
458 |
return 0;
|
459 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
460 |
?>
|
wp-cache.php
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
/*
|
3 |
Plugin Name: WP Super Cache
|
4 |
Plugin URI: http://ocaoimh.ie/wp-super-cache/
|
5 |
-
Description: Very fast
|
6 |
-
Version: 0.
|
7 |
Author: Donncha O Caoimh
|
8 |
Author URI: http://ocaoimh.ie/
|
9 |
*/
|
@@ -56,10 +56,11 @@ function get_wpcachehome() {
|
|
56 |
function wp_cache_add_pages() {
|
57 |
if( function_exists( 'is_site_admin' ) ) {
|
58 |
if( is_site_admin() ) {
|
59 |
-
add_submenu_page('wpmu-admin.php', __('WP Super Cache'), __('WP Super Cache'), '
|
|
|
60 |
}
|
61 |
} else {
|
62 |
-
add_options_page('WP Super Cache', 'WP Super Cache', '
|
63 |
}
|
64 |
}
|
65 |
|
@@ -82,21 +83,24 @@ function wp_cache_manager() {
|
|
82 |
echo '<strong>Configuration file changed, some values might be wrong. Load the page again from the "Options" menu to reset them.</strong>';
|
83 |
}
|
84 |
|
85 |
-
echo '<a name="main"></a><fieldset class="options"><legend>Main options</legend>';
|
86 |
if ( !wp_cache_check_link() ||
|
87 |
!wp_cache_verify_config_file() ||
|
88 |
!wp_cache_verify_cache_dir() ) {
|
89 |
echo "<br>Cannot continue... fix previous problems and retry.<br />";
|
90 |
-
echo "</
|
91 |
return;
|
92 |
}
|
93 |
|
94 |
if (!wp_cache_check_global_config()) {
|
95 |
-
echo "</
|
96 |
return;
|
97 |
}
|
98 |
|
99 |
-
|
|
|
|
|
|
|
|
|
100 |
if ( $valid_nonce ) {
|
101 |
if( isset( $_POST[ 'wp_cache_status' ] ) ) {
|
102 |
switch( $_POST[ 'wp_cache_status' ] ) {
|
@@ -122,41 +126,73 @@ function wp_cache_manager() {
|
|
122 |
}
|
123 |
}
|
124 |
|
|
|
|
|
125 |
echo '<form name="wp_manager" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
|
126 |
?>
|
127 |
-
<label><input type='radio' name='wp_cache_status' value='all' <?php if( $cache_enabled == true && $super_cache_enabled == true ) { echo 'checked=checked'; } ?>>
|
128 |
-
<label><input type='radio' name='wp_cache_status' value='none' <?php if( $cache_enabled == false ) { echo 'checked=checked'; } ?>>
|
129 |
<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 />
|
130 |
-
|
|
|
|
|
|
|
131 |
<label><input type="radio" name="cache_compression" value="1" <?php if( $cache_compression ) { echo "checked=checked"; } ?>> Enabled</label>
|
132 |
<label><input type="radio" name="cache_compression" value="0" <?php if( !$cache_compression ) { echo "checked=checked"; } ?>> Disabled</label>
|
133 |
<p>Compression is disabled by default because some hosts have problems with compressed files. Switching this on and off clears the cache.</p>
|
134 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
if( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && !$cache_compression ) {
|
136 |
-
?><p><strong>Super Cache compression is now disabled
|
137 |
-
<blockquote style='background-color: #ff6'><code>RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$<br />
|
138 |
-
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$<br />
|
139 |
-
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$<br />
|
140 |
-
RewriteCond %{HTTP:Accept-Encoding} gzip<br />
|
141 |
-
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz -f<br />
|
142 |
-
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz [L]</code>
|
143 |
-
</blockquote><?php
|
144 |
} elseif( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && $cache_compression ) {
|
145 |
-
?><p><strong>Super Cache compression is now enabled
|
146 |
-
<blockquote style='background-color: #ff6'><code>RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$<br />
|
147 |
-
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$<br />
|
148 |
-
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$<br />
|
149 |
-
RewriteCond %{HTTP:Accept-Encoding} gzip<br />
|
150 |
-
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz -f<br />
|
151 |
-
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz [L]</code>
|
152 |
-
</blockquote><?php
|
153 |
}
|
154 |
echo '<div class="submit"><input type="submit"value="Update" /></div>';
|
155 |
wp_nonce_field('wp-cache');
|
156 |
echo "</form>\n";
|
|
|
|
|
157 |
|
158 |
wp_cache_edit_max_time();
|
159 |
-
echo '</fieldset>';
|
160 |
|
161 |
echo '<a name="files"></a><fieldset class="options"><legend>Accepted filenames, rejected URIs</legend>';
|
162 |
wp_cache_edit_rejected();
|
@@ -171,10 +207,12 @@ function wp_cache_manager() {
|
|
171 |
wp_cache_restore();
|
172 |
|
173 |
ob_start();
|
174 |
-
if(
|
175 |
-
|
176 |
-
|
177 |
-
|
|
|
|
|
178 |
}
|
179 |
$out = ob_get_contents();
|
180 |
ob_end_clean();
|
@@ -199,6 +237,47 @@ function wp_cache_restore() {
|
|
199 |
|
200 |
}
|
201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
function wp_cache_edit_max_time () {
|
203 |
global $super_cache_max_time, $cache_max_time, $wp_cache_config_file, $valid_nonce;
|
204 |
|
@@ -219,16 +298,17 @@ function wp_cache_edit_max_time () {
|
|
219 |
wp_cache_replace_line('^ *\$super_cache_max_time', "\$super_cache_max_time = $super_cache_max_time;", $wp_cache_config_file);
|
220 |
}
|
221 |
}
|
|
|
|
|
222 |
echo '<form name="wp_edit_max_time" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
|
223 |
-
echo '<label for="wp_max_time">Expire time
|
224 |
-
echo "<input type=\"text\" name=\"wp_max_time\" value=\"$cache_max_time\"
|
225 |
-
echo '<label for="super_cache_max_time">Super Cache Expire time
|
226 |
-
echo "<input type=\"text\" name=\"super_cache_max_time\" value=\"$super_cache_max_time\" />";
|
227 |
echo '<div class="submit"><input type="submit" value="Change expiration" /></div>';
|
228 |
wp_nonce_field('wp-cache');
|
229 |
echo "</form>\n";
|
230 |
-
|
231 |
-
|
232 |
}
|
233 |
|
234 |
function wp_cache_sanitize_value($text, & $array) {
|
@@ -315,7 +395,7 @@ function wp_cache_edit_accepted() {
|
|
315 |
function wp_cache_enable() {
|
316 |
global $wp_cache_config_file, $cache_enabled, $supercachedir;
|
317 |
|
318 |
-
if(
|
319 |
echo "<b>Error: GZIP compression is enabled, disable it if you want to enable wp-cache.</b><br /><br />";
|
320 |
return false;
|
321 |
}
|
@@ -345,16 +425,20 @@ function wp_super_cache_enable() {
|
|
345 |
function wp_super_cache_disable() {
|
346 |
global $supercachedir, $wp_cache_config_file, $super_cache_enabled;
|
347 |
|
|
|
348 |
if( is_dir( $supercachedir ) )
|
349 |
rename( $supercachedir, $supercachedir . ".disabled" );
|
350 |
-
wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = false;', $wp_cache_config_file);
|
351 |
$super_cache_enabled = false;
|
|
|
|
|
|
|
|
|
352 |
}
|
353 |
|
354 |
function wp_cache_is_enabled() {
|
355 |
global $wp_cache_config_file;
|
356 |
|
357 |
-
if(
|
358 |
echo "<b>Warning</b>: GZIP compression is enabled in Wordpress, wp-cache will be bypassed until you disable gzip compression.<br />";
|
359 |
return false;
|
360 |
}
|
@@ -445,6 +529,18 @@ function wp_cache_verify_config_file() {
|
|
445 |
echo "<b>Error:</b> wp-content directory (<b>$dir</b>) is not writable by the Web server.<br />Check its permissions.";
|
446 |
return false;
|
447 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
448 |
if ( !file_exists($wp_cache_config_file) ) {
|
449 |
if ( !file_exists($wp_cache_config_file_sample) ) {
|
450 |
echo "<b>Error:</b> Sample WP-Cache config file (<b>$wp_cache_config_file_sample</b>) does not exist.<br />Verify you installation.";
|
@@ -452,9 +548,9 @@ function wp_cache_verify_config_file() {
|
|
452 |
}
|
453 |
copy($wp_cache_config_file_sample, $wp_cache_config_file);
|
454 |
if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
|
455 |
-
wp_cache_replace_line('WPCACHEHOME', "define( 'WPCACHEHOME', " . str_replace(
|
456 |
} elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
|
457 |
-
wp_cache_replace_line('WPCACHEHOME', "define( 'WPCACHEHOME', " . str_replace(
|
458 |
}
|
459 |
$new = true;
|
460 |
}
|
@@ -468,21 +564,32 @@ function wp_cache_verify_config_file() {
|
|
468 |
|
469 |
function wp_cache_check_link() {
|
470 |
global $wp_cache_link, $wp_cache_file;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
471 |
|
|
|
472 |
if ( basename(@readlink($wp_cache_link)) != basename($wp_cache_file)) {
|
473 |
@unlink($wp_cache_link);
|
474 |
if( function_exists( 'symlink' ) ) {
|
475 |
-
|
476 |
-
|
477 |
-
echo "Create it by executing: <br /><code>ln -s $wp_cache_file $wp_cache_link</code><br /> in your server<br />";
|
478 |
-
return false;
|
479 |
-
} else {
|
480 |
-
if( !@copy( $wp_cache_file, $wp_cache_link ) ) {
|
481 |
-
echo "<code>advanced-cache.php</code> does not exist<br />";
|
482 |
-
echo "Create it by copying $wp_cache_file to $wp_cache_link<br /> in your server<br />";
|
483 |
-
return false;
|
484 |
}
|
|
|
|
|
485 |
}
|
|
|
|
|
|
|
|
|
|
|
486 |
}
|
487 |
}
|
488 |
return true;
|
@@ -540,7 +647,7 @@ function wp_cache_files() {
|
|
540 |
$count = 0;
|
541 |
$expired = 0;
|
542 |
$now = time();
|
543 |
-
if ( ($handle = opendir( $cache_path . 'meta/' )) ) {
|
544 |
if ($list_files) echo "<table cellspacing=\"0\" cellpadding=\"5\">";
|
545 |
while ( false !== ($file = readdir($handle))) {
|
546 |
if ( preg_match("/^$file_prefix.*\.meta/", $file) ) {
|
@@ -627,7 +734,6 @@ function wp_cache_files() {
|
|
627 |
echo '<div class="submit"><input type="submit" value="Regenerate Super Cache Stats" /></div>';
|
628 |
wp_nonce_field('wp-cache');
|
629 |
echo "</form>\n";
|
630 |
-
|
631 |
echo '</fieldset>';
|
632 |
}
|
633 |
|
2 |
/*
|
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.4
|
7 |
Author: Donncha O Caoimh
|
8 |
Author URI: http://ocaoimh.ie/
|
9 |
*/
|
56 |
function wp_cache_add_pages() {
|
57 |
if( function_exists( 'is_site_admin' ) ) {
|
58 |
if( is_site_admin() ) {
|
59 |
+
add_submenu_page('wpmu-admin.php', __('WP Super Cache'), __('WP Super Cache'), 'manage_options', __FILE__, 'wp_cache_manager');
|
60 |
+
add_options_page('WP Super Cache', 'WP Super Cache', 'manage_options', __FILE__, 'wp_cache_manager');
|
61 |
}
|
62 |
} else {
|
63 |
+
add_options_page('WP Super Cache', 'WP Super Cache', 'manage_options', __FILE__, 'wp_cache_manager');
|
64 |
}
|
65 |
}
|
66 |
|
83 |
echo '<strong>Configuration file changed, some values might be wrong. Load the page again from the "Options" menu to reset them.</strong>';
|
84 |
}
|
85 |
|
|
|
86 |
if ( !wp_cache_check_link() ||
|
87 |
!wp_cache_verify_config_file() ||
|
88 |
!wp_cache_verify_cache_dir() ) {
|
89 |
echo "<br>Cannot continue... fix previous problems and retry.<br />";
|
90 |
+
echo "</div>\n";
|
91 |
return;
|
92 |
}
|
93 |
|
94 |
if (!wp_cache_check_global_config()) {
|
95 |
+
echo "</div>\n";
|
96 |
return;
|
97 |
}
|
98 |
|
99 |
+
if( !got_mod_rewrite() ) {
|
100 |
+
?><h4>Mod rewrite is not installed! Super Cache will not fully work!</h4>
|
101 |
+
<p>mod_rewrite is required for serving Super Cache static files. You will still be able to use WP-Cache.</p><?php
|
102 |
+
}
|
103 |
+
|
104 |
if ( $valid_nonce ) {
|
105 |
if( isset( $_POST[ 'wp_cache_status' ] ) ) {
|
106 |
switch( $_POST[ 'wp_cache_status' ] ) {
|
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>
|
143 |
<?php
|
144 |
+
$home_path = get_home_path();
|
145 |
+
$home_root = parse_url(get_option('home'));
|
146 |
+
$home_root = trailingslashit($home_root['path']);
|
147 |
+
$wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) );
|
148 |
+
$wprules = str_replace( "RewriteEngine On\n", '', $wprules );
|
149 |
+
$wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
|
150 |
+
if( strpos( $wprules, 'supercache' ) == false ) { // only write the rules once
|
151 |
+
$rules = "<IfModule mod_rewrite.c>\n";
|
152 |
+
$rules .= "RewriteEngine On\n";
|
153 |
+
$rules .= "RewriteBase $home_root\n"; // props Chris Messina
|
154 |
+
$rules .= "RewriteCond %{QUERY_STRING} !.*s=.*\n";
|
155 |
+
$rules .= "RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$\n";
|
156 |
+
$rules .= "RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$\n";
|
157 |
+
$rules .= "RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$\n";
|
158 |
+
$rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
|
159 |
+
$rules .= "RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz -f\n";
|
160 |
+
$rules .= "RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz [L]\n\n";
|
161 |
+
|
162 |
+
$rules .= "RewriteCond %{QUERY_STRING} !.*s=.*\n";
|
163 |
+
$rules .= "RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$\n";
|
164 |
+
$rules .= "RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$\n";
|
165 |
+
$rules .= "RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$\n";
|
166 |
+
$rules .= "RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html -f\n";
|
167 |
+
$rules .= "RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1index.html [L]\n";
|
168 |
+
$rules .= $wprules . "\n";
|
169 |
+
$rules .= "</IfModule>";
|
170 |
+
if( insert_with_markers( $home_path.'.htaccess', 'WordPress', explode( "\n", $rules ) ) ) {
|
171 |
+
echo "<h4>Mod Rewrite rules updated!</h4>";
|
172 |
+
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";
|
173 |
+
} else {
|
174 |
+
echo "<h4>Mod Rewrite rules must be updated!</h4>";
|
175 |
+
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";
|
176 |
+
}
|
177 |
+
echo "<p><pre># BEGIN WordPress\n{$rules}# END WordPress</pre></p>\n";
|
178 |
+
}
|
179 |
+
// http://allmybrain.com/2007/11/08/making-wp-super-cache-gzip-compression-work/
|
180 |
+
$gziprules = "AddEncoding x-gzip .gz\n";
|
181 |
+
$gziprules .= "AddType text/html .gz";
|
182 |
+
$gziprules = insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $gziprules ) );
|
183 |
+
|
184 |
if( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && !$cache_compression ) {
|
185 |
+
?><p><strong>Super Cache compression is now disabled.</strong></p> <?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
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 |
}
|
217 |
$out = ob_get_contents();
|
218 |
ob_end_clean();
|
237 |
|
238 |
}
|
239 |
|
240 |
+
function comment_form_lockdown_message() {
|
241 |
+
?><p><?php _e( "Comment moderation is enabled. Your comment may take some time to appear." ); ?></p><?php
|
242 |
+
}
|
243 |
+
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';
|
251 |
+
wp_cache_replace_line('^.*WPLOCKDOWN', "define( 'WPLOCKDOWN', '$wp_lock_down' );", $wp_cache_config_file);
|
252 |
+
if( $wp_lock_down == '0' && function_exists( 'prune_super_cache' ) )
|
253 |
+
prune_super_cache( $cache_path, true ); // clear the cache after lockdown
|
254 |
+
|
255 |
+
}
|
256 |
+
if( !isset( $wp_lock_down ) ) {
|
257 |
+
if( defined( 'WPLOCKDOWN' ) ) {
|
258 |
+
$wp_lock_down = constant( 'WPLOCKDOWN' );
|
259 |
+
} else {
|
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' ) {
|
267 |
+
?><strong>WordPress is locked down. Super Cache static files will not be deleted when new comments are made.</strong><?php
|
268 |
+
} else {
|
269 |
+
?><strong>WordPress is not locked down. New comments will refresh Super Cache static files as normal.</strong><?php
|
270 |
+
}
|
271 |
+
$new_lockdown = $wp_lock_down == '1' ? '0' : '1';
|
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 |
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
|
|
|
312 |
}
|
313 |
|
314 |
function wp_cache_sanitize_value($text, & $array) {
|
395 |
function wp_cache_enable() {
|
396 |
global $wp_cache_config_file, $cache_enabled, $supercachedir;
|
397 |
|
398 |
+
if(get_option('gzipcompression')) {
|
399 |
echo "<b>Error: GZIP compression is enabled, disable it if you want to enable wp-cache.</b><br /><br />";
|
400 |
return false;
|
401 |
}
|
425 |
function wp_super_cache_disable() {
|
426 |
global $supercachedir, $wp_cache_config_file, $super_cache_enabled;
|
427 |
|
428 |
+
wp_cache_replace_line('^ *\$super_cache_enabled', '$super_cache_enabled = false;', $wp_cache_config_file);
|
429 |
if( is_dir( $supercachedir ) )
|
430 |
rename( $supercachedir, $supercachedir . ".disabled" );
|
|
|
431 |
$super_cache_enabled = false;
|
432 |
+
sleep( 1 ); // allow existing processes to write to the supercachedir and then delete it
|
433 |
+
if (function_exists ('prune_super_cache') && is_dir( $supercachedir ) ) {
|
434 |
+
prune_super_cache( $supercachedir, true );
|
435 |
+
}
|
436 |
}
|
437 |
|
438 |
function wp_cache_is_enabled() {
|
439 |
global $wp_cache_config_file;
|
440 |
|
441 |
+
if(get_option('gzipcompression')) {
|
442 |
echo "<b>Warning</b>: GZIP compression is enabled in Wordpress, wp-cache will be bypassed until you disable gzip compression.<br />";
|
443 |
return false;
|
444 |
}
|
529 |
echo "<b>Error:</b> wp-content directory (<b>$dir</b>) is not writable by the Web server.<br />Check its permissions.";
|
530 |
return false;
|
531 |
}
|
532 |
+
if ( file_exists($wp_cache_config_file) ) {
|
533 |
+
$lines = join( ' ', file( $wp_cache_config_file ) );
|
534 |
+
if( strpos( $lines, 'WPCACHEHOME' ) === false ) {
|
535 |
+
if( is_writable( $wp_cache_config_file ) ) {
|
536 |
+
@unlink( $wp_cache_config_file );
|
537 |
+
} else {
|
538 |
+
echo "<b>Error:</b> Your WP-Cache config file (<b>$wp_cache_config_file</b>) is out of date and not writable by the Web server.<br />Please delete it and refresh this page.";
|
539 |
+
return false;
|
540 |
+
}
|
541 |
+
}
|
542 |
+
}
|
543 |
+
|
544 |
if ( !file_exists($wp_cache_config_file) ) {
|
545 |
if ( !file_exists($wp_cache_config_file_sample) ) {
|
546 |
echo "<b>Error:</b> Sample WP-Cache config file (<b>$wp_cache_config_file_sample</b>) does not exist.<br />Verify you installation.";
|
548 |
}
|
549 |
copy($wp_cache_config_file_sample, $wp_cache_config_file);
|
550 |
if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) {
|
551 |
+
wp_cache_replace_line('WPCACHEHOME', "define( 'WPCACHEHOME', ABSPATH . " . str_replace( '\\', '/', str_replace( ABSPATH, ' "', dirname(__FILE__) ) ) . "/\" );", $wp_cache_config_file);
|
552 |
} elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
|
553 |
+
wp_cache_replace_line('WPCACHEHOME', "define( 'WPCACHEHOME', ABSPATH . " . str_replace( '\\', '/', str_replace( ABSPATH, ' "', dirname(__FILE__) ) ) . "/wp-super-cache/\" );", $wp_cache_config_file);
|
554 |
}
|
555 |
$new = true;
|
556 |
}
|
564 |
|
565 |
function wp_cache_check_link() {
|
566 |
global $wp_cache_link, $wp_cache_file;
|
567 |
+
|
568 |
+
if( file_exists($wp_cache_link) ) {
|
569 |
+
if( strpos( join( "\n", file( $wp_cache_link ) ), 'WPCACHEHOME' ) ) {
|
570 |
+
// read the file and verify it's a super-cache file and not the wp-cache one.
|
571 |
+
return true;
|
572 |
+
} else {
|
573 |
+
// remove the old version
|
574 |
+
@unlink($wp_cache_link);
|
575 |
+
}
|
576 |
+
}
|
577 |
|
578 |
+
$ret = true;
|
579 |
if ( basename(@readlink($wp_cache_link)) != basename($wp_cache_file)) {
|
580 |
@unlink($wp_cache_link);
|
581 |
if( function_exists( 'symlink' ) ) {
|
582 |
+
if( !@symlink ($wp_cache_file, $wp_cache_link) ) {
|
583 |
+
$ret = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
584 |
}
|
585 |
+
} elseif( !@copy( $wp_cache_file, $wp_cache_link ) ) {
|
586 |
+
$ret = false;
|
587 |
}
|
588 |
+
if( !$ret ) {
|
589 |
+
echo "<code>advanced-cache.php</code> does not exist<br />";
|
590 |
+
echo "Create it by executing: <br /><code>ln -s $wp_cache_file $wp_cache_link</code><br /> in your server<br />";
|
591 |
+
echo "Or by copying $wp_cache_file to $wp_cache_link.<br />";
|
592 |
+
return false;
|
593 |
}
|
594 |
}
|
595 |
return true;
|
647 |
$count = 0;
|
648 |
$expired = 0;
|
649 |
$now = time();
|
650 |
+
if ( ($handle = @opendir( $cache_path . 'meta/' )) ) {
|
651 |
if ($list_files) echo "<table cellspacing=\"0\" cellpadding=\"5\">";
|
652 |
while ( false !== ($file = readdir($handle))) {
|
653 |
if ( preg_match("/^$file_prefix.*\.meta/", $file) ) {
|
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>';
|
738 |
}
|
739 |
|