W3 Total Cache - Version 0.9.2.3

Version Description

  • Added additional CloudFlare IP range
  • Fixed bug in html tidy encoding
  • Fixed bug with NetDNA / MaxCDN purging
  • Improved handling of markers in .htaccess files - easier upgrades
  • Improved cache busting logic
  • Improved numerous notifications and user interface behaviors
  • Improved AWS S3 and Cloudfront reliability
  • Improved reliability of minify auto mode
Download this release

Release Info

Developer fredericktownes
Plugin Icon 128x128 W3 Total Cache
Version 0.9.2.3
Comparing to
See all releases

Code changes from version 0.9.2.2 to 0.9.2.3

Files changed (60) hide show
  1. db/mssql.php +1255 -0
  2. inc/compat.php +44 -0
  3. inc/css/lightbox.css +38 -4
  4. inc/define.php +72 -33
  5. inc/js/lightbox.js +38 -42
  6. inc/js/options.js +43 -17
  7. inc/lightbox/minify_recommendations.phtml +18 -17
  8. inc/lightbox/self_test.phtml +28 -19
  9. inc/options/common/header.phtml +1 -1
  10. inc/options/general.phtml +2 -2
  11. inc/options/minify.phtml +8 -8
  12. inc/options/pgcache.phtml +6 -6
  13. lib/Minify/Minify.php +89 -97
  14. lib/Minify/Minify/CSS/UriRewriter.php +1 -1
  15. lib/Minify/Minify/Cache/File.php +9 -6
  16. lib/Minify/Minify/Controller/Files.php +11 -11
  17. lib/Minify/Minify/Controller/Groups.php +17 -17
  18. lib/Minify/Minify/Controller/MinApp.php +14 -14
  19. lib/Minify/Minify/HTMLTidy.php +2 -0
  20. lib/Minify/Minify/ImportProcessor.php +2 -3
  21. lib/Minify/Minify/Logger.php +11 -12
  22. lib/S3.php +141 -46
  23. lib/W3/Cache.php +6 -6
  24. lib/W3/Cache/File.php +21 -16
  25. lib/W3/Cache/File/Cleaner.php +139 -0
  26. lib/W3/Cache/File/Cleaner/Generic.php +61 -0
  27. lib/W3/Cache/File/{PgCache.php → Generic.php} +8 -24
  28. lib/W3/Cache/File/Manager.php +0 -75
  29. lib/W3/Cache/File/Minify/Manager.php +0 -37
  30. lib/W3/Cache/File/PgCache/Manager.php +0 -37
  31. lib/W3/Cache/Memcached.php +4 -0
  32. lib/W3/Cdn.php +1 -1
  33. lib/W3/Cdn/Azure.php +10 -5
  34. lib/W3/Cdn/Base.php +8 -4
  35. lib/W3/Cdn/Ftp.php +11 -6
  36. lib/W3/Cdn/Mirror.php +6 -2
  37. lib/W3/Cdn/Mirror/Cotendo.php +9 -7
  38. lib/W3/Cdn/Mirror/Netdna.php +29 -4
  39. lib/W3/Cdn/Rscf.php +9 -5
  40. lib/W3/Cdn/S3.php +9 -5
  41. lib/W3/Cdn/S3/Cf.php +23 -17
  42. lib/W3/CloudFlare.php +2 -1
  43. lib/W3/Config.php +19 -7
  44. lib/W3/Db.php +59 -102
  45. lib/W3/Minifier.php +5 -28
  46. lib/W3/Minify.php +182 -87
  47. lib/W3/ObjectCache.php +11 -3
  48. lib/W3/PgCache.php +11 -4
  49. lib/W3/Plugin/BrowserCache.php +85 -21
  50. lib/W3/Plugin/Cdn.php +37 -22
  51. lib/W3/Plugin/DbCache.php +3 -3
  52. lib/W3/Plugin/Minify.php +118 -31
  53. lib/W3/Plugin/ObjectCache.php +3 -3
  54. lib/W3/Plugin/PgCache.php +157 -50
  55. lib/W3/Plugin/TotalCache.php +354 -140
  56. lib/W3/Request.php +1 -1
  57. lib/W3/Varnish.php +1 -1
  58. readme.txt +19 -4
  59. w3-total-cache.php +1 -1
  60. wp-content/db.php +5 -3
db/mssql.php ADDED
@@ -0,0 +1,1255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+
5
+ http://code.google.com/p/wordpress-mssql/
6
+
7
+ Contributors: Aizu Ikmal Ahmad & Iwani Khalid
8
+ Requires at least: 2.3.0
9
+ Tested up to: 2.7.1
10
+ Development Status: Alpha
11
+ Database Abstraction Class: ezSQL by Justin Vincent (http://php.justinvincent.com)
12
+
13
+ How to install MS-SQL support for Wordpress
14
+
15
+ 1. Download Wordpress ( http://wordpress.org/wordpress-2.7.1-IIS-RC1.zip )
16
+ 2. Then, upload it on your webhosting that supports MSSQL and IIS like how you would usually do it
17
+ 3. Download our Magic Plugin at ( http://code.google.com/p/wordpress-mssql/ )
18
+ 4. Then upload that db.php to your wp-contents folder
19
+ 5. Edit the MSSQL database setting in db.php file according to your MSSQL settings 6. You're done :D
20
+
21
+ At this moment, this workaround works for these functions, to where we have debugged and tested
22
+
23
+ * Basic submit, edit, manage posts and pages
24
+ * Comments system
25
+ * Dynamic sidebar
26
+ * Changing themes
27
+ * Installing plugins
28
+ * Long text retrieval
29
+
30
+ What we didn't have time to debug
31
+
32
+ * Pagination
33
+ * Categories > Posts retrieval
34
+ * Dates / Time of posts
35
+ * Others which we look forward to debug later :D
36
+
37
+ */
38
+
39
+ // ==================================================================
40
+ // Author: Justin Vincent (justin@visunet.ie)
41
+ // Web: http://php.justinvincent.com
42
+ // Name: ezSQL
43
+ // Desc: Class to make it very easy to deal with MS SQL database connections.
44
+ //
45
+ // N.B. ezSQL was converted for use with MS SQL
46
+ // by Tom De Bruyne (tom@challenge.be).
47
+ //
48
+ // !! IMPORTANT !!
49
+ //
50
+ // Please send me a mail telling me what you think of ezSQL
51
+ // and what your using it for!! Cheers. [ justin@visunet.ie ]
52
+ //
53
+ // ==================================================================
54
+ // User Settings -- CHANGE HERE
55
+
56
+ ini_set ('mssql.textlimit','2147483647');
57
+ ini_set ('mssql.textsize','2147483647');
58
+
59
+ define("EZSQL_DB_USER", "tretinoin_wpuser"); // <-- MS SQL Server db user
60
+ define("EZSQL_DB_PASSWORD", "83h93hdi."); // <-- MS SQL Server db password
61
+ define("EZSQL_DB_NAME", "tretinoin_wordpress"); // <-- MS SQL Server db pname
62
+ define("EZSQL_DB_HOST", "lamp2win"); // <-- MS SQL Server server host
63
+
64
+ // ==================================================================
65
+ // ezSQL Constants
66
+ define("EZSQL_VERSION","1.26");
67
+ define("OBJECT","OBJECT",true);
68
+ define("ARRAY_A","ARRAY_A",true);
69
+ define("ARRAY_N","ARRAY_N",true);
70
+
71
+ // ==================================================================
72
+ // The Main Class
73
+
74
+ class W3_Db_Driver {
75
+
76
+ var $debug_called;
77
+ var $vardump_called;
78
+ var $show_errors = false;
79
+ var $num_queries = 0;
80
+ var $debug_all = false;
81
+ var $last_query;
82
+ var $col_info;
83
+
84
+ var $suppress_errors = false;
85
+ var $last_error = '';
86
+ var $queries;
87
+ var $prefix = '';
88
+ var $ready = false;
89
+ var $posts;
90
+ var $users;
91
+ var $categories;
92
+ var $post2cat;
93
+ var $comments;
94
+ var $links;
95
+ var $options;
96
+ var $postmeta;
97
+ var $usermeta;
98
+ var $terms;
99
+ var $term_taxonomy;
100
+ var $term_relationships;
101
+ var $tables = array('users', 'usermeta', 'posts', 'categories', 'post2cat', 'comments', 'links', 'link2cat', 'options',
102
+ 'postmeta', 'terms', 'term_taxonomy', 'term_relationships');
103
+
104
+ var $charset;
105
+ var $collate;
106
+
107
+
108
+
109
+
110
+ // ==================================================================
111
+ // DB Constructor - connects to the server and selects a database
112
+
113
+
114
+
115
+ function W3_Db_Driver($dbuser, $dbpassword, $dbname, $dbhost)
116
+ {
117
+
118
+ $this->dbh = mssql_connect($dbhost, $dbuser, $dbpassword);
119
+
120
+ if ( ! $this->dbh ) {
121
+ $this->print_error("<ol><b>Error establishing a database connection!</b><li>Are you sure you have the correct user/password?<li>Are you sure that you have typed the correct hostname?<li>Are you sure that the database server is running?</ol>");
122
+ }
123
+
124
+ $this->select($dbname);
125
+
126
+ }
127
+
128
+ // ==================================================================
129
+ // Select a DB (if another one needs to be selected)
130
+
131
+ function select($db)
132
+ {
133
+ mssql_select_db ($db);
134
+ }
135
+
136
+
137
+ // ==================================================================
138
+ // Basic Query - see docs for more detail
139
+
140
+ function query($query)
141
+ {
142
+
143
+ $query = trim($query);
144
+ $query = str_replace('`',"'",$query);
145
+
146
+ $query = str_replace('\012',"\n",$query);
147
+ $query = str_replace('\015',"\r",$query);
148
+
149
+ //$query = str_replace("\n",'',$query);
150
+ //$query = str_replace("\r",'',$query);
151
+
152
+ //$query = $this->escape($query);
153
+ //$query = str_replace('"','\"',$query);
154
+ //$query = str_replace("'","\'",$query);
155
+
156
+
157
+ if(substr($query,0,7) == 'SELECT '){
158
+
159
+ dbug($query,'SELECT : ORIGINAL QUERY ::::::: ','orange');
160
+
161
+ $query_arr = explode('LIMIT',$query);
162
+ if($query_arr[0] AND $query_arr[1]){
163
+
164
+ $query_one = str_replace('SELECT ','',$query_arr[0]);
165
+
166
+ $top_arr = explode(' ',$query_arr[1]);
167
+
168
+ if($top_arr[1] && $top_arr[2]){
169
+ $query = 'SELECT TOP '.$top_arr[2].' '.$query_one;
170
+ }else{
171
+ $query = 'SELECT TOP '.$top_arr[1].' '.$query_one;
172
+ }
173
+
174
+
175
+
176
+ /*
177
+
178
+ // TO BE DEVELOP
179
+
180
+ //LIMIT 1, 3
181
+
182
+ SELECT * FROM (
183
+ SELECT TOP 3 * FROM
184
+ (SELECT TOP (1+3) * FROM wp_posts WHERE 1=1 AND post_type = 'post' AND (post_status = 'publish' OR post_status = 'private') ORDER BY post_date DESC)
185
+ AS table1 ORDER BY post_date ASC
186
+ ) AS table2 ORDER BY post_date DESC
187
+
188
+ */
189
+
190
+ //pre($query_arr);
191
+ //exit();
192
+
193
+
194
+ }
195
+
196
+
197
+ if(substr($query,0,23) == "SELECT TOP 1 comment_ID"){
198
+ $query = str_replace(' = ',' = ',$query);
199
+ }
200
+
201
+
202
+ /* DUMP DIRTY SWEPT TEST */
203
+ $query = str_replace('wp_posts.','',$query);
204
+
205
+
206
+ /*
207
+ hacks for query;
208
+ - SELECT * FROM wp_posts WHERE (post_type = 'page' AND post_status = 'publish') ORDER BY menu_order, post_title ASC
209
+ - SELECT * FROM wp_posts WHERE 1=1 AND post_type = 'page' AND (post_status = 'publish' OR post_status = 'future' OR post_status = 'draft' OR post_status = 'pending' OR post_status = 'private') ORDER BY menu_order,post_title asc
210
+ notes;
211
+ somehow Wordpress developer create this 'post_title' date-type as 'text' in database. the post_title should be varchar since the amount of character in title is generally less then 255 char.
212
+ and in ms-sql, text cannot be sorted. so this is a big mistake. haihhh...
213
+ */
214
+ $pattern = '/post_title asc/is';
215
+ $replacement = 'cast(post_title as varchar(500)) ASC';
216
+ $query = preg_replace($pattern, $replacement, $query);
217
+
218
+
219
+
220
+
221
+ /*
222
+ hacks for query;
223
+ - SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM wp_posts WHERE post_type = 'post' ORDER BY post_date DESC
224
+ notes;
225
+ this is one another hacks for SELECT DISTINCT call.
226
+ The above query tries to sort by the column post_date. Because the keyword DISTINCT is also specified, column post_date must appear in the SELECT list
227
+ expected return;
228
+ - SELECT DISTINCT post_date, YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM wp_posts WHERE post_type = 'post' ORDER BY post_date DESC
229
+ */
230
+ if(substr($query,0,15) == "SELECT DISTINCT"){
231
+ $string = $query;
232
+ $pattern = '/SELECT DISTINCT (.*)? ORDER BY (.*)? (asc|desc)/i';
233
+ $replacement = 'cast(post_title as varchar(500)) ASC';
234
+ preg_match_all($pattern, $string, $result);
235
+ $order_by_col = $result[2][0];
236
+ $col_calls = $result[1][0];
237
+ $order_by_prop = $result[3][0];
238
+ $query = 'SELECT DISTINCT '.$order_by_col.', '.$col_calls.' ORDER BY '.$order_by_col.' '.$order_by_prop;
239
+ }
240
+
241
+
242
+
243
+
244
+ /*
245
+ hacks for query;
246
+ - SELECT user_id FROM wp_usermeta WHERE meta_key = 'wp_user_level' AND meta_value != '0'
247
+ notes;
248
+ replace != into NOT <col_name> LIKE
249
+ expected return;
250
+ - SELECT user_id FROM wp_usermeta WHERE meta_key = 'wp_user_level' AND NOT meta_value LIKE '0'
251
+ */
252
+ $pattern = "/ (?:[a-z][a-z0-9_]*)? \!\= /is";
253
+ preg_match_all($pattern, $query, $result);
254
+ $result_arr = $result[0];
255
+ $query = str_replace('!=','',$query);
256
+ foreach($result_arr as $result_item){
257
+ $result_item = str_replace('!=','',$result_item);
258
+ $result_item = trim($result_item);
259
+ $query = str_replace($result_item,' NOT '.$result_item.' LIKE ',$query);
260
+ }
261
+
262
+
263
+
264
+ /*
265
+ hacks for;
266
+ - SQL have 'GROUP BY'
267
+ - SELECT DISTINCT post_date, YEAR(post_date) AS year, MONTH(post_date) AS month, count(ID) as posts FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish
268
+ GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC
269
+ */
270
+ if (preg_match("/GROUP BY/i", $query)) {
271
+ $pattern = '/SELECT (.*) GROUP BY (.*)? ORDER BY (.*)/i';
272
+ preg_match($pattern, $string, $output);
273
+
274
+ $query0 = 'SELECT '.$output[1].' ORDER BY '.$output[3];
275
+ }
276
+
277
+
278
+ $query = str_replace('SQL_CALC_FOUND_ROWS',' ',$query);
279
+ if (preg_match("/SELECT FOUND_ROWS()/i", $query)) {
280
+ $last_query = $this->last_query;
281
+ $last_query_one_arr = explode('TOP',$last_query);
282
+ $last_query_two = trim($last_query_one_arr[1]);
283
+ $last_query_three_arr = explode(' ',$last_query_two);
284
+ $last_query_four = str_replace($last_query_three_arr[0],'',$last_query_two);
285
+ $query = 'SELECT '.$last_query_four;
286
+ }
287
+
288
+ dbug($query,'SELECT : MODDED QUERY :::::::: ','orange');
289
+
290
+ }elseif(substr($query,0,7) == 'INSERT '){
291
+
292
+ dbug($query,'INSERT : ORIGINAL QUERY ::::::::: ','purple');
293
+
294
+ $pattern = '/INSERT INTO (.*)?\((.*)\).*?VALUES.*?\((.*)\)/is';
295
+ preg_match_all($pattern, $query, $output);
296
+ $insert_table = trim($output[1][0]);
297
+ $insert_cols = trim($output[2][0]);
298
+ $insert_values = trim($output[3][0]);
299
+
300
+ /* STRIP QUOTE FROM COLS NAME */
301
+ $insert_cols = str_replace("'",'',$insert_cols);
302
+
303
+ $query = $this->prepare($query);
304
+
305
+ /* PROCESS THE $insert_values. NEED TO REPLACE THE INNER QUOTES */
306
+ preg_match_all("/([0-9]+|\'(.*?)\'[ ]*?),/is", $insert_values.',', $output);
307
+
308
+ $insert_values_arr = array(); //PREPARE THE NEW FRESH VALUES
309
+ foreach($output[0] as $insert_values_item){
310
+ if(substr(trim($insert_values_item),0,1) == "'"){
311
+ $insert_values_item = substr($insert_values_item,1); // TAKE OUT THE FIRST 1 CHAR, WHICH IS QUOTE
312
+ }
313
+ $insert_values_item = trim($insert_values_item); // TRIM THE WHITESPACE
314
+ if(substr(trim($insert_values_item),-1) == ","){
315
+ $insert_values_item = substr($insert_values_item,0,-1); // TAKE OUT THE LAST 1 CHAR, WHICH IS COMMA
316
+ }
317
+ if(substr(trim($insert_values_item),-1) == "'"){
318
+ $insert_values_item = substr($insert_values_item,0,-1); // TAKE OUT THE LAST 1 CHAR, WHICH IS QUOTE
319
+ }
320
+ $insert_values_item = str_replace("'","''",$insert_values_item); // NOW WE PUT THE EXTRA QUOTE ON IT
321
+ $insert_values_item = trim($insert_values_item); // TRIM THE WHITESPACE
322
+ $insert_values_item = "'".$insert_values_item."'"; // WRAP THE VALUES WITH OUR SINGLE-QUOTE
323
+ $insert_values_arr[] = $insert_values_item;
324
+ }
325
+
326
+ $insert_values = implode(',',$insert_values_arr);
327
+
328
+
329
+ /* CONSTRUCT NEW INSERT CALL */
330
+ $query = 'INSERT INTO '.$insert_table.' ('.$insert_cols.') VALUES ('.$insert_values.');';
331
+
332
+
333
+ dbug($query,'INSERT : MODDED QUERY :::::::::: ','purple');
334
+
335
+ }elseif(substr($query,0,7) == 'UPDATE '){
336
+
337
+
338
+ dbug($query,'UPDATE : ORIGINAL QUERY ::::::::: ','blue');
339
+
340
+
341
+ $pattern = '/UPDATE ([A-Za-z0-9_-]+) SET (.*)? WHERE (.*)?/is';
342
+ preg_match_all($pattern, $query, $output);
343
+ $update_table = trim($output[1][0]);
344
+ $update_values = trim($output[2][0]);
345
+ $update_where = trim($output[3][0]);
346
+
347
+ preg_match_all("/(.*?)[ *]?=[ *]?(\'(.*?)\'|[0-9]+),/is", $update_values.',', $output_vals);
348
+
349
+ $update_vals_colname = $output_vals[1];
350
+ $update_vals_values = $output_vals[2];
351
+
352
+
353
+ $update_vals_colname_mod = array();
354
+ foreach($update_vals_colname as $update_vals_colname_item){
355
+ $update_vals_colname_item = str_replace("'",'',$update_vals_colname_item); // GREEDY REPLACE ALL QUOTES. NO QUOTES ALLOWED IN COL NAME
356
+ $update_vals_colname_item = trim($update_vals_colname_item); // TRIM THE WHITESPACE
357
+ $update_vals_colname_mod[] = $update_vals_colname_item;
358
+ }
359
+
360
+ $update_vals_values_mod = array();
361
+ foreach($update_vals_values as $update_vals_values_item){
362
+ if(substr(trim($update_vals_values_item),0,1) == "'"){
363
+ $update_vals_values_item = substr($update_vals_values_item,1); // TAKE OUT THE FIRST 1 CHAR, WHICH IS QUOTE
364
+ }
365
+ if(substr(trim($update_vals_values_item),-1) == "'"){
366
+ $update_vals_values_item = substr($update_vals_values_item,0,-1); // TAKE OUT THE LAST 1 CHAR, WHICH IS QUOTE
367
+ }
368
+ $update_vals_values_item = trim($update_vals_values_item); // TRIM THE WHITESPACE
369
+ $update_vals_values_item = str_replace("'","''",$update_vals_values_item); // ADD ADDITIONAL QUOTE TO ESCAPE IT IN MSSQL
370
+ $update_vals_values_mod[] = $update_vals_values_item;
371
+ }
372
+
373
+ $update_values_modded = array_combine($update_vals_colname_mod,$update_vals_values_mod);
374
+
375
+ $update_values = '';
376
+ $update_values_prepare_arr = '';
377
+ $update_values_item = '';
378
+ foreach($update_values_modded as $update_values_item_colname => $update_values_item_value){
379
+ $update_values_prepare_arr[] = $update_values_item_colname." = '".$update_values_item_value."'";
380
+ }
381
+
382
+
383
+ $update_values = implode(',',$update_values_prepare_arr);
384
+
385
+
386
+
387
+
388
+
389
+ /* CONSTRUCT NEW UPDATE CALL */
390
+ $query = 'UPDATE '.$update_table.' SET '.$update_values.' WHERE '.$update_where.';';
391
+
392
+
393
+
394
+
395
+
396
+
397
+
398
+
399
+
400
+
401
+ dbug($query,'UPDATE : MODDED QUERY :::::::::: ','blue');
402
+
403
+ }elseif(substr($query,0,7) == 'DELETE '){
404
+
405
+
406
+
407
+ dbug($query,'DELETE','orange');
408
+
409
+ }elseif(substr($query,0,7) == 'CREATE '){
410
+
411
+ $query_two = str_replace('auto_increment','IDENTITY(1,1)',$query);
412
+ $query_two = str_replace('tinytext','text',$query_two);
413
+ $query_two = str_replace('longtext','text',$query_two);
414
+ $query_two = str_replace('mediumtext','text',$query_two);
415
+ $query_two = str_replace('unsigned ','',$query_two);
416
+ $query_three = preg_replace('/bigint\(\d+\)/i','int',$query_two);
417
+ $query_three = preg_replace('/int\(\d+\)/i','int',$query_three);
418
+ $query_four_arr = explode('PRIMARY KEY',$query_three);
419
+ $query_five = $query_four_arr[0].' ';
420
+ $query_six = $query_four_arr[1];
421
+ $query_seven_arr = explode('),',$query_six);
422
+ $query_eight_arr = explode('(',$query);
423
+ $query_nine = trim($query_eight_arr[0]);
424
+ $query_ten = str_replace($query_nine,'',$query_five);
425
+ $table_name = trim(str_replace('CREATE TABLE','',$query_nine));
426
+
427
+
428
+ $create_table_header = "
429
+ IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[tretinoin_wpuser].[".$table_name."]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
430
+ DROP TABLE [tretinoin_wpuser].[".$table_name."]
431
+ GO
432
+ CREATE TABLE [tretinoin_wpuser].[".$table_name."]";
433
+
434
+ $create_table_header_simple = "CREATE TABLE [tretinoin_wpuser].[".$table_name."]
435
+
436
+ ";
437
+
438
+ $query = $create_table_header_simple . $query_ten . ' PRIMARY KEY ' . $query_seven_arr[0] .'))';
439
+
440
+ dbug($query,'CREATE','purple');
441
+
442
+ }elseif(substr($query,0,5) == 'SHOW '){
443
+
444
+ $query = str_replace('SHOW TABLES;','',$query);
445
+
446
+ dbug($query,'SHOW','yellow');
447
+
448
+ }else{
449
+
450
+
451
+ dbug($query);
452
+
453
+ }
454
+
455
+
456
+
457
+ // For reg expressions
458
+ $query = trim($query);
459
+
460
+ // Flush cached values..
461
+ $this->flush();
462
+
463
+ // Log how the function was called
464
+ $this->func_call = "\$db->query(\"$query\")";
465
+
466
+ // Keep track of the last query for debug..
467
+ $this->last_query = $query;
468
+
469
+ // Perform the query via std mssql_query function..
470
+
471
+
472
+ if(substr($query,0,7) == 'SELECT '){
473
+ $this->result_check = @mssql_query($query, $this->dbh);
474
+ }elseif(substr($query,0,7) == 'INSERT '){
475
+
476
+ }elseif(substr($query,0,7) == 'UPDATE '){
477
+ $this->result_check = @mssql_query($query, $this->dbh);
478
+ }elseif(substr($query,0,7) == 'DELETE '){
479
+
480
+ }elseif(substr($query,0,7) == 'CREATE '){
481
+
482
+ }elseif(substr($query,0,5) == 'SHOW '){
483
+
484
+ }
485
+
486
+
487
+
488
+
489
+ // Unfortunately, PHP fuctions for MS SQL currently don't offer a decent way
490
+ // to retrieve errors from MS SQL
491
+ // Make sure not to run a query between the actual query and this one !
492
+
493
+ $get_errorcode = "SELECT @@ERROR as errorcode";
494
+ $error_res = @mssql_query($get_errorcode, $this->dbh);
495
+ $errorcode = @mssql_result($error_res, 0, "errorcode");
496
+
497
+ // ERROR LIST
498
+ // 402 : The data types text and varchar are incompatible in the equal to operator.
499
+ // 306 : The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.
500
+
501
+
502
+ if ($errorcode == '402') {
503
+ $query_two = str_replace(' = ',' LIKE ',$query);
504
+
505
+
506
+ /* NEED MORE IMPROVEMENT HERE */
507
+
508
+
509
+
510
+ }else{
511
+ $query_two = $query;
512
+ }
513
+ dbug($query,$errorcode,'green');
514
+
515
+
516
+ $this->result = @mssql_query($query_two, $this->dbh);
517
+ $this->num_queries++;
518
+
519
+
520
+ // If there was an insert, delete or update see how many rows were affected
521
+ // (Also, If there there was an insert take note of the last OID
522
+ $query_type = array("insert","delete","update","replace");
523
+
524
+ // loop through the above array
525
+ foreach ( $query_type as $word )
526
+ {
527
+ // This is true if the query starts with insert, delete or update
528
+ if ( preg_match("/^$word\s+/i",$query) )
529
+ {
530
+ $this->rows_affected = @mssql_rows_affected ($this->dbh);
531
+
532
+ // This gets the insert ID
533
+ if ( $word == "insert" || $word == "replace" )
534
+ {
535
+ $get_last_ident = "SELECT @@IDENTITY as id";
536
+ $last_res = @mssql_query($get_last_ident, $this->dbh);
537
+ $this->insert_id = @mssql_result($last_res, 0, "id");
538
+
539
+ // If insert id then return it - true evaluation
540
+ return $this->insert_id;
541
+ }
542
+
543
+ // Set to false if there was no insert id
544
+ $this->result = false;
545
+ }
546
+ }
547
+
548
+
549
+ if ($errorcode <> 0) {
550
+ // there is an error
551
+ $this->print_error();
552
+ }
553
+ else
554
+ {
555
+
556
+ // =======================================================
557
+ // Take note of column info
558
+
559
+ $i=0;
560
+ while ($i < @mssql_num_fields($this->result))
561
+ {
562
+ $this->col_info[$i]->name = @mssql_field_name($this->result,$i);
563
+ $this->col_info[$i]->type = @mssql_field_type($this->result,$i);
564
+ $this->col_info[$i]->size = @mssql_field_length($this->result,$i);
565
+ $i++;
566
+ }
567
+
568
+ // =======================================================
569
+ // Store Query Results
570
+
571
+ $i=0;
572
+ while ( $row_arr = @mssql_fetch_array($this->result) )
573
+ {
574
+
575
+ $row = array_to_object($row_arr);
576
+ $this->last_result[$i] = $row;
577
+
578
+ // Store relults as an objects within main array
579
+
580
+
581
+ $i++;
582
+ }
583
+
584
+ if($i == 0){
585
+ $this->last_result = array();
586
+ }
587
+
588
+ //pre($this->last_result);
589
+
590
+ // Log number of rows the query returned
591
+ $this->num_rows = $i;
592
+
593
+ //}
594
+
595
+ @mssql_free_result($this->result);
596
+
597
+ // If this was a select..
598
+ if ( preg_match("/^(select|show|desc)\s+/i",$query) )
599
+ {
600
+
601
+ // If debug ALL queries
602
+ $this->debug_all ? $this->debug() : null ;
603
+
604
+ // If there were results then return true for $db->query
605
+ if ( $i )
606
+ {
607
+ return true;
608
+ }
609
+ else
610
+ {
611
+ return false;
612
+ }
613
+ }
614
+ else
615
+ {
616
+ // If debug ALL queries
617
+ $this->debug_all ? $this->debug() : null ;
618
+
619
+ // Update insert etc. was good..
620
+ return true;
621
+ }
622
+
623
+ }
624
+ }
625
+
626
+
627
+
628
+
629
+ // ====================================================================
630
+ // Format a string correctly for safe insert under all PHP conditions
631
+
632
+ function escape($str)
633
+ {
634
+
635
+ // This deals with quote escaping
636
+ //$str = str_replace("'","''",$str);
637
+ //$str = str_replace("\'","'",$str);
638
+
639
+ //$str = mysql_real_escape_string($str);
640
+
641
+ //$str = str_replace("'", "''", $str);
642
+ //$str = addslashes($str);
643
+
644
+ //dbug($str,'ESCAPE RUN TWICE','red');
645
+
646
+ // These values need to be escaped for ms sql
647
+ $escape = array ( "\n"=>"\\\\012","\r"=>"\\\\015");
648
+
649
+ // Firstly unescape
650
+ /*
651
+ foreach ( $escape as $match => $replace )
652
+ {
653
+ $str = str_replace($match,$replace,$str);
654
+ }
655
+ */
656
+ return $str;
657
+
658
+ }
659
+
660
+ // ==================================================================
661
+ // Print SQL/DB error.
662
+
663
+ function print_error($str = "")
664
+ {
665
+ // All erros go to the global error array $EZSQL_ERROR..
666
+ global $EZSQL_ERROR;
667
+
668
+ // if no special error, take last mssql error
669
+ if ( !$str ) $str = mssql_get_last_message();
670
+
671
+ // Log this error to the global array..
672
+ $EZSQL_ERROR[] = array
673
+ (
674
+ "query" => $this->last_query,
675
+ "error_str" => $str
676
+ );
677
+
678
+ // Is error output turned on or not..
679
+ if ( $this->show_errors )
680
+ {
681
+ // If there is an error then take note of it
682
+ /*
683
+ print "<blockquote><font face=arial size=2 color=ff0000>";
684
+ print "<b>SQL/DB Error --</b> ";
685
+ print "[<font color=000000>".$this->last_query."</font>]";
686
+ print "[<font color=000077>$str</font>]";
687
+ print "</font></blockquote>";
688
+ */
689
+
690
+ dbug($this->last_query.'<br />'.$str,'ERROR','red');
691
+ return false;
692
+ }
693
+ else
694
+ {
695
+ return false;
696
+ }
697
+
698
+
699
+
700
+
701
+
702
+ }
703
+
704
+ // ==================================================================
705
+ // Turn error handling on or off..
706
+
707
+ function show_errors()
708
+ {
709
+ $this->show_errors = true;
710
+ }
711
+
712
+ function hide_errors()
713
+ {
714
+ $this->show_errors = false;
715
+ }
716
+
717
+ // ==================================================================
718
+ // Kill cached query results
719
+
720
+ function flush()
721
+ {
722
+
723
+ // Get rid of these
724
+ $this->last_result = null;
725
+ $this->col_info = null;
726
+ $this->last_query = null;
727
+
728
+ }
729
+
730
+
731
+
732
+ // ==================================================================
733
+ // Get one variable from the DB - see docs for more detail
734
+
735
+ function get_var($query=null,$x=0,$y=0)
736
+ {
737
+
738
+ // Log how the function was called
739
+ $this->func_call = "\$db->get_var(\"$query\",$x,$y)";
740
+
741
+ // If there is a query then perform it if not then use cached results..
742
+ if ( $query )
743
+ {
744
+ $this->query($query);
745
+ }
746
+
747
+ // Extract var out of cached results based x,y vals
748
+ if ( $this->last_result[$y] )
749
+ {
750
+ $values = array_values(get_object_vars($this->last_result[$y]));
751
+ }
752
+
753
+ // If there is a value return it else return null
754
+ return (isset($values[$x]) && $values[$x]!=='')?$values[$x]:null;
755
+ }
756
+
757
+ // ==================================================================
758
+ // Get one row from the DB - see docs for more detail
759
+
760
+ function get_row($query=null,$output=OBJECT,$y=0)
761
+ {
762
+
763
+ // Log how the function was called
764
+ $this->func_call = "\$db->get_row(\"$query\",$output,$y)";
765
+
766
+ // If there is a query then perform it if not then use cached results..
767
+ if ( $query )
768
+ {
769
+ $this->query($query);
770
+ }
771
+
772
+ // If the output is an object then return object using the row offset..
773
+ if ( $output == OBJECT )
774
+ {
775
+ return $this->last_result[$y]?$this->last_result[$y]:null;
776
+ }
777
+ // If the output is an associative array then return row as such..
778
+ elseif ( $output == ARRAY_A )
779
+ {
780
+ return $this->last_result[$y]?get_object_vars($this->last_result[$y]):null;
781
+ }
782
+ // If the output is an numerical array then return row as such..
783
+ elseif ( $output == ARRAY_N )
784
+ {
785
+ return $this->last_result[$y]?array_values(get_object_vars($this->last_result[$y])):null;
786
+ }
787
+ // If invalid output type was specified..
788
+ else
789
+ {
790
+ $this->print_error(" \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N");
791
+ }
792
+
793
+ }
794
+
795
+ // ==================================================================
796
+ // Function to get 1 column from the cached result set based in X index
797
+ // se docs for usage and info
798
+
799
+ function get_col($query=null,$x=0)
800
+ {
801
+
802
+ // If there is a query then perform it if not then use cached results..
803
+ if ( $query )
804
+ {
805
+ $this->query($query);
806
+ }
807
+
808
+ // Extract the column values
809
+ for ( $i=0; $i < count($this->last_result); $i++ )
810
+ {
811
+ $new_array[$i] = $this->get_var(null,$x,$i);
812
+ }
813
+
814
+ if($i == 0){
815
+ $new_array = array();
816
+ }
817
+
818
+ return $new_array;
819
+ }
820
+
821
+ // ==================================================================
822
+ // Return the the query as a result set - see docs for more details
823
+
824
+ function get_results($query=null, $output = OBJECT)
825
+ {
826
+
827
+ // Log how the function was called
828
+ $this->func_call = "\$db->get_results(\"$query\", $output)";
829
+
830
+ // If there is a query then perform it if not then use cached results..
831
+ if ( $query )
832
+ {
833
+ $this->query($query);
834
+ }
835
+
836
+ // Send back array of objects. Each row is an object
837
+ if ( $output == OBJECT )
838
+ {
839
+
840
+ $out = get_object_vars($this->last_result);
841
+
842
+ return $this->last_result;
843
+ }
844
+ elseif ( $output == ARRAY_A || $output == ARRAY_N )
845
+ {
846
+ if ( $this->last_result )
847
+ {
848
+ $i=0;
849
+ foreach( $this->last_result as $row )
850
+ {
851
+
852
+ $new_array[$i] = get_object_vars($row);
853
+
854
+ if ( $output == ARRAY_N )
855
+ {
856
+ $new_array[$i] = array_values($new_array[$i]);
857
+ }
858
+
859
+ $i++;
860
+ }
861
+
862
+ return $new_array;
863
+ }
864
+ else
865
+ {
866
+ return null;
867
+ }
868
+ }
869
+ }
870
+
871
+
872
+ // ==================================================================
873
+ // Function to get column meta data info pertaining to the last query
874
+ // see docs for more info and usage
875
+
876
+ function get_col_info($info_type="name",$col_offset=-1)
877
+ {
878
+
879
+ if ( $this->col_info )
880
+ {
881
+ if ( $col_offset == -1 )
882
+ {
883
+ $i=0;
884
+ foreach($this->col_info as $col )
885
+ {
886
+ $new_array[$i] = $col->{$info_type};
887
+ $i++;
888
+ }
889
+ return $new_array;
890
+ }
891
+ else
892
+ {
893
+ return $this->col_info[$col_offset]->{$info_type};
894
+ }
895
+
896
+ }
897
+
898
+ }
899
+
900
+
901
+ // ==================================================================
902
+ // Dumps the contents of any input variable to screen in a nicely
903
+ // formatted and easy to understand way - any type: Object, Var or Array
904
+
905
+ function vardump($mixed='')
906
+ {
907
+
908
+ echo "<p><table><tr><td bgcolor=ffffff><blockquote><font color=000090>";
909
+ echo "<pre><font face=arial>";
910
+
911
+ if ( ! $this->vardump_called )
912
+ {
913
+ echo "<font color=800080><b>ezSQL</b> (v".EZSQL_VERSION.") <b>Variable Dump..</b></font>\n\n";
914
+ }
915
+
916
+ $var_type = gettype ($mixed);
917
+ print_r(($mixed?$mixed:"<font color=red>No Value / False</font>"));
918
+ echo "\n\n<b>Type:</b> " . ucfirst($var_type) . "\n";
919
+ echo "<b>Last Query</b> [$this->num_queries]<b>:</b> ".($this->last_query?$this->last_query:"NULL")."\n";
920
+ echo "<b>Last Function Call:</b> " . ($this->func_call?$this->func_call:"None")."\n";
921
+ echo "<b>Last Rows Returned:</b> ".count($this->last_result)."\n";
922
+ echo "</font></pre></font></blockquote></td></tr></table>".$this->donation();
923
+ echo "\n<hr size=1 noshade color=dddddd>";
924
+
925
+ $this->vardump_called = true;
926
+
927
+ }
928
+
929
+ // Alias for the above function
930
+ function dumpvar($mixed)
931
+ {
932
+ $this->vardump($mixed);
933
+ }
934
+
935
+ // ==================================================================
936
+ // Displays the last query string that was sent to the database & a
937
+ // table listing results (if there were any).
938
+ // (abstracted into a seperate file to save server overhead).
939
+
940
+ function debug()
941
+ {
942
+
943
+ echo "<blockquote>";
944
+
945
+ // Only show ezSQL credits once..
946
+ if ( ! $this->debug_called )
947
+ {
948
+ echo "<font color=800080 face=arial size=2><b>ezSQL</b> (v".EZSQL_VERSION.") <b>Debug..</b></font><p>\n";
949
+ }
950
+ echo "<font face=arial size=2 color=000099><b>Query</b> [$this->num_queries] <b>--</b> ";
951
+ echo "[<font color=000000><b>$this->last_query</b></font>]</font><p>";
952
+
953
+ echo "<font face=arial size=2 color=000099><b>Query Result..</b></font>";
954
+ echo "<blockquote>";
955
+
956
+ if ( $this->col_info )
957
+ {
958
+
959
+ // =====================================================
960
+ // Results top rows
961
+
962
+ echo "<table cellpadding=5 cellspacing=1 bgcolor=555555>";
963
+ echo "<tr bgcolor=eeeeee><td nowrap valign=bottom><font color=555599 face=arial size=2><b>(row)</b></font></td>";
964
+
965
+
966
+ for ( $i=0; $i < count($this->col_info); $i++ )
967
+ {
968
+ echo "<td nowrap align=left valign=top><font size=1 color=555599 face=arial>{$this->col_info[$i]->type} {$this->col_info[$i]->max_length}</font><br><span style='font-family: arial; font-size: 10pt; font-weight: bold;'>{$this->col_info[$i]->name}</span></td>";
969
+ }
970
+
971
+ echo "</tr>";
972
+
973
+ // ======================================================
974
+ // print main results
975
+
976
+ if ( $this->last_result )
977
+ {
978
+
979
+ $i=0;
980
+ foreach ( $this->get_results(null,ARRAY_N) as $one_row )
981
+ {
982
+ $i++;
983
+ echo "<tr bgcolor=ffffff><td bgcolor=eeeeee nowrap align=middle><font size=2 color=555599 face=arial>$i</font></td>";
984
+
985
+ foreach ( $one_row as $item )
986
+ {
987
+ echo "<td nowrap><font face=arial size=2>$item</font></td>";
988
+ }
989
+
990
+ echo "</tr>";
991
+ }
992
+
993
+ } // if last result
994
+ else
995
+ {
996
+ echo "<tr bgcolor=ffffff><td colspan=".(count($this->col_info)+1)."><font face=arial size=2>No Results</font></td></tr>";
997
+ }
998
+
999
+ echo "</table>";
1000
+
1001
+ } // if col_info
1002
+ else
1003
+ {
1004
+ echo "<font face=arial size=2>No Results</font>";
1005
+ }
1006
+
1007
+ echo "</blockquote></blockquote>".$this->donation()."<hr noshade color=dddddd size=1>";
1008
+
1009
+
1010
+ $this->debug_called = true;
1011
+ }
1012
+
1013
+ // =======================================================
1014
+ // Naughty little function to ask for some remuniration!
1015
+
1016
+ function donation()
1017
+ {
1018
+ return "<font size=1 face=arial color=000000>If ezSQL has helped <a href=\"https://www.paypal.com/xclick/business=justin%40justinvincent.com&item_name=ezSQL&no_note=1&tax=0\" style=\"color: 0000CC;\">make a donation!?</a> &nbsp;&nbsp;[ go on! you know you want to! ]</font>";
1019
+ }
1020
+
1021
+
1022
+
1023
+
1024
+ /**
1025
+ * Sets the table prefix for the WordPress .
1026
+ *
1027
+ * Also allows for the CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE to
1028
+ * override the WordPress users and usersmeta tables.
1029
+ *
1030
+ * @since 2.5.0
1031
+ *
1032
+ * @param string $prefix Alphanumeric name for the new prefix.
1033
+ * @return string Old prefix
1034
+ */
1035
+ function set_prefix($prefix) {
1036
+
1037
+ if ( preg_match('|[^a-z0-9_]|i', $prefix) )
1038
+ return new WP_Error('invalid_db_prefix', /*WP_I18N_DB_BAD_PREFIX*/'Invalid database prefix'/*/WP_I18N_DB_BAD_PREFIX*/);
1039
+
1040
+ $old_prefix = $this->prefix;
1041
+ $this->prefix = $prefix;
1042
+
1043
+ foreach ( (array) $this->tables as $table )
1044
+ $this->$table = $this->prefix . $table;
1045
+
1046
+ if ( defined('CUSTOM_USER_TABLE') )
1047
+ $this->users = CUSTOM_USER_TABLE;
1048
+
1049
+ if ( defined('CUSTOM_USER_META_TABLE') )
1050
+ $this->usermeta = CUSTOM_USER_META_TABLE;
1051
+
1052
+ return $old_prefix;
1053
+ }
1054
+
1055
+
1056
+ /**
1057
+ * Whether to suppress database errors.
1058
+ *
1059
+ * @param unknown_type $suppress
1060
+ * @return unknown
1061
+ */
1062
+ function suppress_errors( $suppress = true ) {
1063
+ $errors = $this->suppress_errors;
1064
+ $this->suppress_errors = $suppress;
1065
+ return $errors;
1066
+ }
1067
+
1068
+
1069
+ /**
1070
+ * Escapes content by reference for insertion into the database, for security
1071
+ *
1072
+ * @since 2.3.0
1073
+ *
1074
+ * @param string $s
1075
+ */
1076
+ function escape_by_ref(&$s) {
1077
+ $s = $this->escape($s);
1078
+ }
1079
+
1080
+ /**
1081
+ * Generic function to determine if a database supports a particular feature
1082
+ * @param string $db_cap the feature
1083
+ * @param false|string|resource $dbh_or_table the databaese (the current database, the database housing the specified table, or the database of the mysql resource)
1084
+ * @return bool
1085
+ */
1086
+ function has_cap( $db_cap ) {
1087
+
1088
+
1089
+ return false;
1090
+ }
1091
+
1092
+ /**
1093
+ * Insert an array of data into a table.
1094
+ *
1095
+ * @since 2.5.0
1096
+ *
1097
+ * @param string $table WARNING: not sanitized!
1098
+ * @param array $data Should not already be SQL-escaped
1099
+ * @return mixed Results of $this->query()
1100
+ */
1101
+ function insert($table, $data) {
1102
+ $data = add_magic_quotes($data);
1103
+ $fields = array_keys($data);
1104
+ return $this->query("INSERT INTO $table (`" . implode('`,`',$fields) . "`) VALUES ('".implode("','",$data)."')");
1105
+ }
1106
+
1107
+ /**
1108
+ * Prepares a SQL query for safe use, using sprintf() syntax.
1109
+ *
1110
+ * @link http://php.net/sprintf See for syntax to use for query string.
1111
+ * @since 2.3.0
1112
+ *
1113
+ * @param null|string $args If string, first parameter must be query statement
1114
+ * @param mixed $args,... If additional parameters, they will be set inserted into the query.
1115
+ * @return null|string Sanitized query string
1116
+ */
1117
+ function prepare($args=null) {
1118
+ if ( is_null( $args ) )
1119
+ return;
1120
+ $args = func_get_args();
1121
+ $query = array_shift($args);
1122
+ $query = str_replace("'%s'", '%s', $query); // in case someone mistakenly already singlequoted it
1123
+ $query = str_replace('"%s"', '%s', $query); // doublequote unquoting
1124
+ $query = str_replace('%s', "'%s'", $query); // quote the strings
1125
+ array_walk($args, array(&$this, 'escape_by_ref'));
1126
+ return @vsprintf($query, $args);
1127
+ }
1128
+
1129
+
1130
+
1131
+ /**
1132
+ * Update a row in the table with an array of data.
1133
+ *
1134
+ * @since 2.5.0
1135
+ *
1136
+ * @param string $table WARNING: not sanitized!
1137
+ * @param array $data Should not already be SQL-escaped
1138
+ * @param array $where A named array of WHERE column => value relationships. Multiple member pairs will be joined with ANDs. WARNING: the column names are not currently sanitized!
1139
+ * @return mixed Results of $this->query()
1140
+ */
1141
+ function update($table, $data, $where){
1142
+ $data = add_magic_quotes($data);
1143
+ $bits = $wheres = array();
1144
+ foreach ( (array) array_keys($data) as $k )
1145
+ $bits[] = "`$k` = '$data[$k]'";
1146
+
1147
+ if ( is_array( $where ) )
1148
+ foreach ( $where as $c => $v ){
1149
+ $v = str_replace("'","'",$v);
1150
+ //$wheres[] = "$c = '" . $this->escape( $v ) . "'";
1151
+ $wheres[] = "$c = '" . $v . "'";
1152
+ }
1153
+ else
1154
+ return false;
1155
+
1156
+ return $this->query( "UPDATE $table SET " . implode( ', ', $bits ) . ' WHERE ' . implode( ' AND ', $wheres ) );
1157
+ }
1158
+
1159
+ /**
1160
+ * Whether or not MySQL database is minimal required version.
1161
+ *
1162
+ * @since 2.5.0
1163
+ * @uses $wp_version
1164
+ *
1165
+ * @return WP_Error
1166
+ */
1167
+ function check_database_version()
1168
+ {
1169
+ global $wp_version;
1170
+ // Make sure the server has MySQL 4.0
1171
+ /*
1172
+ if ( version_compare($this->db_version(), '4.0.0', '<') )
1173
+ return new WP_Error('database_version',sprintf(__('<strong>ERROR</strong>: WordPress %s requires MySQL 4.0.0 or higher'), $wp_version));
1174
+
1175
+ */
1176
+
1177
+ }
1178
+
1179
+
1180
+
1181
+
1182
+
1183
+
1184
+
1185
+
1186
+
1187
+
1188
+
1189
+
1190
+
1191
+
1192
+
1193
+
1194
+
1195
+
1196
+
1197
+
1198
+
1199
+ }
1200
+
1201
+ // automatically create a new $db object
1202
+
1203
+ //$wpdb = new db(EZSQL_DB_USER, EZSQL_DB_PASSWORD, EZSQL_DB_NAME, EZSQL_DB_HOST);
1204
+
1205
+
1206
+
1207
+
1208
+ function array_to_object($array = array()) {
1209
+ if (!empty($array)) {
1210
+ $data = false;
1211
+
1212
+ foreach ($array as $akey => $aval) {
1213
+ if(!is_numeric($akey)){
1214
+ $data -> {$akey} = trim($aval);
1215
+ }
1216
+ }
1217
+
1218
+ return $data;
1219
+ }
1220
+
1221
+ return false;
1222
+ }
1223
+
1224
+ function pre($sting_to_pre = '',$ob=false){
1225
+
1226
+ if($sting_to_pre){
1227
+
1228
+ if($ob){
1229
+
1230
+ ob_start();
1231
+ echo '<pre>';
1232
+ print_r($sting_to_pre);
1233
+ echo '</pre>';
1234
+ $the_return = ob_get_contents();
1235
+ ob_end_clean();
1236
+ return $the_return;
1237
+
1238
+ }else{
1239
+ echo '<pre>';
1240
+ print_r($sting_to_pre);
1241
+ echo '</pre>';
1242
+ }
1243
+
1244
+ }
1245
+ }
1246
+
1247
+ function dbug($val,$prepend='',$prepend_color='red'){
1248
+
1249
+ /*
1250
+ $fp = fopen('E:\wwwusr\vhosts\tretinoin.dev.lamp2win.com\httpdocs\debug\log.txt', 'a');
1251
+ fwrite($fp, '<span style="color:'.$prepend_color.';"><b>'.$prepend.'</b></span> '.$val."\n");
1252
+ fclose($fp);
1253
+ */
1254
+ }
1255
+ ?>
inc/compat.php CHANGED
@@ -39,3 +39,47 @@ if (!function_exists('json_decode')) {
39
  return (is_array($data) ? array_map(__FUNCTION__, $data) : $data);
40
  }
41
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  return (is_array($data) ? array_map(__FUNCTION__, $data) : $data);
40
  }
41
  }
42
+
43
+ if (!function_exists('fnmatch')) {
44
+ define('FNM_PATHNAME', 1);
45
+ define('FNM_NOESCAPE', 2);
46
+ define('FNM_PERIOD', 4);
47
+ define('FNM_CASEFOLD', 16);
48
+
49
+ function fnmatch($pattern, $string, $flags = 0) {
50
+ $modifiers = null;
51
+ $transforms = array(
52
+ '\*' => '.*',
53
+ '\?' => '.',
54
+ '\[\!' => '[^',
55
+ '\[' => '[',
56
+ '\]' => ']',
57
+ '\.' => '\.',
58
+ '\\' => '\\\\'
59
+ );
60
+
61
+ // Forward slash in string must be in pattern:
62
+ if ($flags & FNM_PATHNAME) {
63
+ $transforms['\*'] = '[^/]*';
64
+ }
65
+
66
+ // Back slash should not be escaped:
67
+ if ($flags & FNM_NOESCAPE) {
68
+ unset($transforms['\\']);
69
+ }
70
+
71
+ // Perform case insensitive match:
72
+ if ($flags & FNM_CASEFOLD) {
73
+ $modifiers .= 'i';
74
+ }
75
+
76
+ // Period at start must be the same as pattern:
77
+ if ($flags & FNM_PERIOD) {
78
+ if (strpos($string, '.') === 0 && strpos($pattern, '.') !== 0) return false;
79
+ }
80
+
81
+ $pattern = '~^' . strtr(preg_quote($pattern, '~'), $transforms) . '$~' . $modifiers;
82
+
83
+ return (boolean) preg_match($pattern, $string);
84
+ }
85
+ }
inc/css/lightbox.css CHANGED
@@ -5,19 +5,23 @@
5
  .lightbox {
6
  position: absolute;
7
  background: #fdfdfd;
8
- padding: 10px 20px;
9
  border: 1px solid #bbb;
10
  border-radius: 11px;
11
  -webkit-border-radius: 11px;
12
  -moz-border-radius: 11px;
13
  }
14
 
 
 
 
 
15
  .lightbox-close {
16
  cursor: pointer;
17
  position: absolute;
18
  text-decoration: underline;
19
- top: 25px;
20
  right: 20px;
 
21
  }
22
 
23
  .lightbox-loader {
@@ -26,9 +30,30 @@
26
  background-repeat: no-repeat;
27
  }
28
 
 
 
 
 
29
  #recom_container {
 
 
30
  overflow: auto;
31
- height: 475px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  }
33
 
34
  th.minify-files-add, td.minify-files-add {
@@ -41,14 +66,23 @@ th.minify-files-add, td.minify-files-add {
41
  }
42
 
43
  #w3tc-self-test {
44
- height: 490px;
 
45
  overflow: auto;
 
 
46
  }
47
 
48
  #w3tc-self-test ul {
49
  list-style: none;
50
  }
51
 
 
 
 
 
 
 
52
  .w3tc-self-test-hint {
53
  font-size: 0.8em;
54
  font-style: italic;
5
  .lightbox {
6
  position: absolute;
7
  background: #fdfdfd;
8
+ padding: 20px;
9
  border: 1px solid #bbb;
10
  border-radius: 11px;
11
  -webkit-border-radius: 11px;
12
  -moz-border-radius: 11px;
13
  }
14
 
15
+ .lightbox h3 {
16
+ margin-top: 0;
17
+ }
18
+
19
  .lightbox-close {
20
  cursor: pointer;
21
  position: absolute;
22
  text-decoration: underline;
 
23
  right: 20px;
24
+ z-index: 9999;
25
  }
26
 
27
  .lightbox-loader {
30
  background-repeat: no-repeat;
31
  }
32
 
33
+ .lightbox-content {
34
+ position: relative;
35
+ }
36
+
37
  #recom_container {
38
+ top: 90px;
39
+ bottom: 120px;
40
  overflow: auto;
41
+ position: absolute;
42
+ width: 100%;
43
+ }
44
+
45
+ #recom_container_bottom {
46
+ bottom: 0;
47
+ width: 100%;
48
+ position: absolute;
49
+ }
50
+
51
+ #recom_container_bottom p {
52
+ margin-top: 0;
53
+ }
54
+
55
+ #recom_container_bottom fieldset {
56
+ margin: 0;
57
  }
58
 
59
  th.minify-files-add, td.minify-files-add {
66
  }
67
 
68
  #w3tc-self-test {
69
+ top: 170px;
70
+ bottom: 40px;
71
  overflow: auto;
72
+ position: absolute;
73
+ width: 100%;
74
  }
75
 
76
  #w3tc-self-test ul {
77
  list-style: none;
78
  }
79
 
80
+ #w3tc-self-test-bottom {
81
+ bottom: 0;
82
+ width: 100%;
83
+ position: absolute;
84
+ }
85
+
86
  .w3tc-self-test-hint {
87
  font-size: 0.8em;
88
  font-style: italic;
inc/define.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
 
3
- define('W3TC_VERSION', '0.9.2.2');
4
  define('W3TC_POWERED_BY', 'W3 Total Cache/' . W3TC_VERSION);
5
  define('W3TC_EMAIL', 'w3tc@w3-edge.com');
6
  define('W3TC_PAYPAL_URL', 'https://www.paypal.com/cgi-bin/webscr');
7
- define('W3TC_PAYPAL_BUSINESS', 'w3tc@w3-edge.com');
8
  define('W3TC_LINK_URL', 'http://www.w3-edge.com/wordpress-plugins/');
9
  define('W3TC_LINK_NAME', 'WordPress Plugins');
10
  define('W3TC_FEED_URL', 'http://feeds.feedburner.com/W3TOTALCACHE');
@@ -24,6 +24,7 @@ define('W3TC_LIB_CSSTIDY_DIR', W3TC_LIB_DIR . '/CSSTidy');
24
  define('W3TC_LIB_MICROSOFT_DIR', W3TC_LIB_DIR . '/Microsoft');
25
  define('W3TC_LIB_NUSOAP_DIR', W3TC_LIB_DIR . '/Nusoap');
26
  define('W3TC_PLUGINS_DIR', W3TC_DIR . '/plugins');
 
27
  define('W3TC_INSTALL_DIR', W3TC_DIR . '/wp-content');
28
  define('W3TC_INSTALL_MINIFY_DIR', W3TC_INSTALL_DIR . '/w3tc/min');
29
 
@@ -56,22 +57,26 @@ define('W3TC_CDN_LOG_FILE', W3TC_LOG_DIR . '/cdn.log');
56
  define('W3TC_VARNISH_LOG_FILE', W3TC_LOG_DIR . '/varnish.log');
57
 
58
  define('W3TC_MARKER_BEGIN_WORDPRESS', '# BEGIN WordPress');
59
- define('W3TC_MARKER_BEGIN_SUPERCACHE', '# BEGIN WPSuperCache');
60
  define('W3TC_MARKER_BEGIN_PGCACHE_CORE', '# BEGIN W3TC Page Cache core');
61
  define('W3TC_MARKER_BEGIN_PGCACHE_CACHE', '# BEGIN W3TC Page Cache cache');
 
 
62
  define('W3TC_MARKER_BEGIN_BROWSERCACHE_CACHE', '# BEGIN W3TC Browser Cache');
63
  define('W3TC_MARKER_BEGIN_BROWSERCACHE_NO404WP', '# BEGIN W3TC Skip 404 error handling by WordPress for static files');
64
  define('W3TC_MARKER_BEGIN_MINIFY_CORE', '# BEGIN W3TC Minify core');
65
  define('W3TC_MARKER_BEGIN_MINIFY_CACHE', '# BEGIN W3TC Minify cache');
 
66
 
67
  define('W3TC_MARKER_END_WORDPRESS', '# END WordPress');
68
- define('W3TC_MARKER_END_SUPERCACHE', '# END WPSuperCache');
69
  define('W3TC_MARKER_END_PGCACHE_CORE', '# END W3TC Page Cache core');
70
  define('W3TC_MARKER_END_PGCACHE_CACHE', '# END W3TC Page Cache cache');
 
 
71
  define('W3TC_MARKER_END_BROWSERCACHE_CACHE', '# END W3TC Browser Cache');
72
  define('W3TC_MARKER_END_BROWSERCACHE_NO404WP', '# END W3TC Skip 404 error handling by WordPress for static files');
73
  define('W3TC_MARKER_END_MINIFY_CORE', '# END W3TC Minify core');
74
  define('W3TC_MARKER_END_MINIFY_CACHE', '# END W3TC Minify cache');
 
75
 
76
  define('W3TC_INSTALL_FILE_ADVANCED_CACHE', W3TC_INSTALL_DIR . '/advanced-cache.php');
77
  define('W3TC_INSTALL_FILE_DB', W3TC_INSTALL_DIR . '/db.php');
@@ -178,7 +183,7 @@ function w3_microtime() {
178
  *
179
  * @param string $path
180
  * @param integer $mask
181
- * @param string
182
  * @return boolean
183
  */
184
  function w3_mkdir($path, $mask = 0777, $curr_path = '') {
@@ -208,6 +213,7 @@ function w3_mkdir($path, $mask = 0777, $curr_path = '') {
208
  *
209
  * @param string $path
210
  * @param array $exclude
 
211
  * @return void
212
  */
213
  function w3_rmdir($path, $exclude = array(), $remove = true) {
@@ -215,15 +221,23 @@ function w3_rmdir($path, $exclude = array(), $remove = true) {
215
 
216
  if ($dir) {
217
  while (($entry = @readdir($dir)) !== false) {
218
- $full_path = $path . '/' . $entry;
 
 
219
 
220
- if ($entry != '.' && $entry != '..' && !in_array($full_path, $exclude)) {
221
- if (@is_dir($full_path)) {
222
- w3_rmdir($full_path, $exclude);
223
- } else {
224
- @unlink($full_path);
225
  }
226
  }
 
 
 
 
 
 
 
 
227
  }
228
 
229
  @closedir($dir);
@@ -320,7 +334,7 @@ function w3_is_network() {
320
  * @return boolean
321
  */
322
  function w3_is_url($url) {
323
- return preg_match('~^https?://~', $url);
324
  }
325
 
326
  /**
@@ -384,7 +398,7 @@ function w3_is_preview_mode() {
384
  /**
385
  * Check if file is write-able
386
  *
387
- * @param string $path
388
  * @return boolean
389
  */
390
  function w3_is_writable($file) {
@@ -571,7 +585,7 @@ function w3_get_blogname() {
571
  * Returns blogname from URI
572
  *
573
  * @param string $uri
574
- * @param string
575
  */
576
  function w3_get_blogname_from_uri($uri) {
577
  $blogname = '';
@@ -613,10 +627,10 @@ function w3_get_blog_id() {
613
  * @return string
614
  */
615
  function w3_get_url_regexp($url) {
616
- $url = preg_replace('~https?://~i', '', $url);
617
  $url = preg_replace('~^www\.~i', '', $url);
618
 
619
- $regexp = 'https?://(www\.)?' . w3_preg_quote($url);
620
 
621
  return $regexp;
622
  }
@@ -1138,16 +1152,20 @@ function w3_can_check_rules() {
1138
  * @return boolean
1139
  */
1140
  function w3_can_modify_rules($path) {
1141
- if (w3_is_apache()) {
1142
- switch ($path) {
1143
- case w3_get_pgcache_rules_cache_path():
1144
- case w3_get_minify_rules_core_path():
1145
- case w3_get_minify_rules_cache_path():
1146
- return true;
 
 
1147
  }
 
 
1148
  }
1149
 
1150
- return false;
1151
  }
1152
 
1153
  /**
@@ -1245,7 +1263,7 @@ function w3_normalize_file_minify($file) {
1245
  * @return string
1246
  */
1247
  function w3_normalize_file_minify2($file) {
1248
- $file = w3_remove_wp_query($file);
1249
  $file = w3_normalize_file_minify($file);
1250
  $file = w3_translate_file($file);
1251
 
@@ -1275,8 +1293,8 @@ function w3_translate_file($file) {
1275
  * @param string $url
1276
  * @return string
1277
  */
1278
- function w3_remove_wp_query($url) {
1279
- $url = preg_replace('~[&\?]?ver=[a-z0-9-_\.]*~i', '', $url);
1280
 
1281
  return $url;
1282
  }
@@ -1295,9 +1313,10 @@ function w3_path($path) {
1295
  }
1296
 
1297
  /**
1298
- * Returns realpath of given path
1299
  *
1300
  * @param string $path
 
1301
  */
1302
  function w3_realpath($path) {
1303
  $path = w3_path($path);
@@ -1495,6 +1514,7 @@ function w3_http_request($method, $url, $data = '', $auth = '', $check_status =
1495
  * @param string $url
1496
  * @param string $auth
1497
  * $param boolean $check_status
 
1498
  * @return string
1499
  */
1500
  function w3_http_get($url, $auth = '', $check_status = true) {
@@ -1516,9 +1536,11 @@ function w3_http_post($url, $data = '', $auth = '', $check_status = true) {
1516
 
1517
  /**
1518
  * Send PURGE request to Varnish server
 
1519
  * @param string $url
1520
  * @param string $auth
1521
  * $param boolean $check_status
 
1522
  * @return string
1523
  */
1524
  function w3_http_purge($url, $auth = '', $check_status = true) {
@@ -1542,6 +1564,10 @@ function w3_http_date($time) {
1542
  * @return boolean
1543
  */
1544
  function w3_download($url, $file) {
 
 
 
 
1545
  $data = w3_http_get($url);
1546
 
1547
  if ($data !== false) {
@@ -1582,9 +1608,11 @@ function w3_upload_info() {
1582
 
1583
  /**
1584
  * Formats URL
 
1585
  * @param string $url
1586
  * @param array $params
1587
  * @param boolean $skip_empty
 
1588
  * @return string
1589
  */
1590
  function w3_url_format($url = '', $params = array(), $skip_empty = false, $separator = '&') {
@@ -1685,7 +1713,7 @@ function w3_url_query($params = array(), $skip_empty = false, $separator = '&')
1685
  * Redirects to URL
1686
  *
1687
  * @param string $url
1688
- * @param string $params
1689
  * @return string
1690
  */
1691
  function w3_redirect($url = '', $params = array()) {
@@ -1727,7 +1755,7 @@ function w3_get_engine_name($engine) {
1727
  $engine_name = 'disk';
1728
  break;
1729
 
1730
- case 'file_pgcache':
1731
  $engine_name = 'disk (enhanced)';
1732
  break;
1733
 
@@ -1883,7 +1911,8 @@ function w3_get_mime_type($file) {
1883
  /**
1884
  * Quotes regular expression string
1885
  *
1886
- * @param string $regexp
 
1887
  * @return string
1888
  */
1889
  function w3_preg_quote($string, $delimiter = null) {
@@ -1986,12 +2015,24 @@ function w3_clean_rules($rules) {
1986
  * @return string
1987
  */
1988
  function w3_erase_rules($rules, $start, $end) {
1989
- $rules = preg_replace('~' . w3_preg_quote($start) . '.*?' . w3_preg_quote($end) . "\n*~s", '', $rules);
1990
  $rules = w3_trim_rules($rules);
1991
 
1992
  return $rules;
1993
  }
1994
 
 
 
 
 
 
 
 
 
 
 
 
 
1995
  /**
1996
  * Extracts JS files from content
1997
  *
@@ -2008,7 +2049,6 @@ function w3_extract_js($content) {
2008
  $files = $matches[1];
2009
  }
2010
 
2011
- $files = array_filter($files, create_function('$el', 'return (strstr($el, W3TC_CONTENT_MINIFY_DIR_NAME) ? false : true);'));
2012
  $files = array_values(array_unique($files));
2013
 
2014
  return $files;
@@ -2047,7 +2087,6 @@ function w3_extract_css($content) {
2047
  $files = array_merge($files, $matches[2]);
2048
  }
2049
 
2050
- $files = array_filter($files, create_function('$el', 'return (strstr($el, W3TC_CONTENT_MINIFY_DIR_NAME) ? false : true);'));
2051
  $files = array_values(array_unique($files));
2052
 
2053
  return $files;
1
  <?php
2
 
3
+ define('W3TC_VERSION', '0.9.2.3');
4
  define('W3TC_POWERED_BY', 'W3 Total Cache/' . W3TC_VERSION);
5
  define('W3TC_EMAIL', 'w3tc@w3-edge.com');
6
  define('W3TC_PAYPAL_URL', 'https://www.paypal.com/cgi-bin/webscr');
7
+ define('W3TC_PAYPAL_BUSINESS', 'w3tc-team@w3-edge.com');
8
  define('W3TC_LINK_URL', 'http://www.w3-edge.com/wordpress-plugins/');
9
  define('W3TC_LINK_NAME', 'WordPress Plugins');
10
  define('W3TC_FEED_URL', 'http://feeds.feedburner.com/W3TOTALCACHE');
24
  define('W3TC_LIB_MICROSOFT_DIR', W3TC_LIB_DIR . '/Microsoft');
25
  define('W3TC_LIB_NUSOAP_DIR', W3TC_LIB_DIR . '/Nusoap');
26
  define('W3TC_PLUGINS_DIR', W3TC_DIR . '/plugins');
27
+ define('W3TC_DB_DIR', W3TC_DIR . '/db');
28
  define('W3TC_INSTALL_DIR', W3TC_DIR . '/wp-content');
29
  define('W3TC_INSTALL_MINIFY_DIR', W3TC_INSTALL_DIR . '/w3tc/min');
30
 
57
  define('W3TC_VARNISH_LOG_FILE', W3TC_LOG_DIR . '/varnish.log');
58
 
59
  define('W3TC_MARKER_BEGIN_WORDPRESS', '# BEGIN WordPress');
 
60
  define('W3TC_MARKER_BEGIN_PGCACHE_CORE', '# BEGIN W3TC Page Cache core');
61
  define('W3TC_MARKER_BEGIN_PGCACHE_CACHE', '# BEGIN W3TC Page Cache cache');
62
+ define('W3TC_MARKER_BEGIN_PGCACHE_LEGACY', '# BEGIN W3TC Page Cache');
63
+ define('W3TC_MARKER_BEGIN_PGCACHE_WPSC', '# BEGIN WPSuperCache');
64
  define('W3TC_MARKER_BEGIN_BROWSERCACHE_CACHE', '# BEGIN W3TC Browser Cache');
65
  define('W3TC_MARKER_BEGIN_BROWSERCACHE_NO404WP', '# BEGIN W3TC Skip 404 error handling by WordPress for static files');
66
  define('W3TC_MARKER_BEGIN_MINIFY_CORE', '# BEGIN W3TC Minify core');
67
  define('W3TC_MARKER_BEGIN_MINIFY_CACHE', '# BEGIN W3TC Minify cache');
68
+ define('W3TC_MARKER_BEGIN_MINIFY_LEGACY', '# BEGIN W3TC Minify');
69
 
70
  define('W3TC_MARKER_END_WORDPRESS', '# END WordPress');
 
71
  define('W3TC_MARKER_END_PGCACHE_CORE', '# END W3TC Page Cache core');
72
  define('W3TC_MARKER_END_PGCACHE_CACHE', '# END W3TC Page Cache cache');
73
+ define('W3TC_MARKER_END_PGCACHE_LEGACY', '# END W3TC Page Cache');
74
+ define('W3TC_MARKER_END_PGCACHE_WPSC', '# END WPSuperCache');
75
  define('W3TC_MARKER_END_BROWSERCACHE_CACHE', '# END W3TC Browser Cache');
76
  define('W3TC_MARKER_END_BROWSERCACHE_NO404WP', '# END W3TC Skip 404 error handling by WordPress for static files');
77
  define('W3TC_MARKER_END_MINIFY_CORE', '# END W3TC Minify core');
78
  define('W3TC_MARKER_END_MINIFY_CACHE', '# END W3TC Minify cache');
79
+ define('W3TC_MARKER_END_MINIFY_LEGACY', '# END W3TC Minify');
80
 
81
  define('W3TC_INSTALL_FILE_ADVANCED_CACHE', W3TC_INSTALL_DIR . '/advanced-cache.php');
82
  define('W3TC_INSTALL_FILE_DB', W3TC_INSTALL_DIR . '/db.php');
183
  *
184
  * @param string $path
185
  * @param integer $mask
186
+ * @param string $curr_path
187
  * @return boolean
188
  */
189
  function w3_mkdir($path, $mask = 0777, $curr_path = '') {
213
  *
214
  * @param string $path
215
  * @param array $exclude
216
+ * @param bool $remove
217
  * @return void
218
  */
219
  function w3_rmdir($path, $exclude = array(), $remove = true) {
221
 
222
  if ($dir) {
223
  while (($entry = @readdir($dir)) !== false) {
224
+ if ($entry == '.' || $entry == '..') {
225
+ continue;
226
+ }
227
 
228
+ foreach ($exclude as $mask) {
229
+ if (fnmatch($mask, basename($entry))) {
230
+ continue 2;
 
 
231
  }
232
  }
233
+
234
+ $full_path = $path . DIRECTORY_SEPARATOR . $entry;
235
+
236
+ if (@is_dir($full_path)) {
237
+ w3_rmdir($full_path, $exclude);
238
+ } else {
239
+ @unlink($full_path);
240
+ }
241
  }
242
 
243
  @closedir($dir);
334
  * @return boolean
335
  */
336
  function w3_is_url($url) {
337
+ return preg_match('~^(https?:)?//~', $url);
338
  }
339
 
340
  /**
398
  /**
399
  * Check if file is write-able
400
  *
401
+ * @param string $file
402
  * @return boolean
403
  */
404
  function w3_is_writable($file) {
585
  * Returns blogname from URI
586
  *
587
  * @param string $uri
588
+ * @return string
589
  */
590
  function w3_get_blogname_from_uri($uri) {
591
  $blogname = '';
627
  * @return string
628
  */
629
  function w3_get_url_regexp($url) {
630
+ $url = preg_replace('~(https?:)?//~i', '', $url);
631
  $url = preg_replace('~^www\.~i', '', $url);
632
 
633
+ $regexp = '(https?:)?//(www\.)?' . w3_preg_quote($url);
634
 
635
  return $regexp;
636
  }
1152
  * @return boolean
1153
  */
1154
  function w3_can_modify_rules($path) {
1155
+ if (w3_is_network()) {
1156
+ if (w3_is_apache()) {
1157
+ switch ($path) {
1158
+ case w3_get_pgcache_rules_cache_path():
1159
+ case w3_get_minify_rules_core_path():
1160
+ case w3_get_minify_rules_cache_path():
1161
+ return true;
1162
+ }
1163
  }
1164
+
1165
+ return false;
1166
  }
1167
 
1168
+ return true;
1169
  }
1170
 
1171
  /**
1263
  * @return string
1264
  */
1265
  function w3_normalize_file_minify2($file) {
1266
+ $file = w3_remove_query($file);
1267
  $file = w3_normalize_file_minify($file);
1268
  $file = w3_translate_file($file);
1269
 
1293
  * @param string $url
1294
  * @return string
1295
  */
1296
+ function w3_remove_query($url) {
1297
+ $url = preg_replace('~[&\?]+(ver=[a-z0-9-_\.]+|[0-9-]+)~i', '', $url);
1298
 
1299
  return $url;
1300
  }
1313
  }
1314
 
1315
  /**
1316
+ * Returns real path of given path
1317
  *
1318
  * @param string $path
1319
+ * @return string
1320
  */
1321
  function w3_realpath($path) {
1322
  $path = w3_path($path);
1514
  * @param string $url
1515
  * @param string $auth
1516
  * $param boolean $check_status
1517
+ * @param bool $check_status
1518
  * @return string
1519
  */
1520
  function w3_http_get($url, $auth = '', $check_status = true) {
1536
 
1537
  /**
1538
  * Send PURGE request to Varnish server
1539
+ *
1540
  * @param string $url
1541
  * @param string $auth
1542
  * $param boolean $check_status
1543
+ * @param bool $check_status
1544
  * @return string
1545
  */
1546
  function w3_http_purge($url, $auth = '', $check_status = true) {
1564
  * @return boolean
1565
  */
1566
  function w3_download($url, $file) {
1567
+ if (strpos($url, '//') === 0) {
1568
+ $url = (w3_is_https() ? 'https:' : 'http:') . $url;
1569
+ }
1570
+
1571
  $data = w3_http_get($url);
1572
 
1573
  if ($data !== false) {
1608
 
1609
  /**
1610
  * Formats URL
1611
+ *
1612
  * @param string $url
1613
  * @param array $params
1614
  * @param boolean $skip_empty
1615
+ * @param string $separator
1616
  * @return string
1617
  */
1618
  function w3_url_format($url = '', $params = array(), $skip_empty = false, $separator = '&') {
1713
  * Redirects to URL
1714
  *
1715
  * @param string $url
1716
+ * @param array $params
1717
  * @return string
1718
  */
1719
  function w3_redirect($url = '', $params = array()) {
1755
  $engine_name = 'disk';
1756
  break;
1757
 
1758
+ case 'file_generic':
1759
  $engine_name = 'disk (enhanced)';
1760
  break;
1761
 
1911
  /**
1912
  * Quotes regular expression string
1913
  *
1914
+ * @param string $string
1915
+ * @param string $delimiter
1916
  * @return string
1917
  */
1918
  function w3_preg_quote($string, $delimiter = null) {
2015
  * @return string
2016
  */
2017
  function w3_erase_rules($rules, $start, $end) {
2018
+ $rules = preg_replace('~' . w3_preg_quote($start) . "\n.*?" . w3_preg_quote($end) . "\n*~s", '', $rules);
2019
  $rules = w3_trim_rules($rules);
2020
 
2021
  return $rules;
2022
  }
2023
 
2024
+ /**
2025
+ * Check if rules exist
2026
+ *
2027
+ * @param string $rules
2028
+ * @param string $start
2029
+ * @param string $end
2030
+ * @return int
2031
+ */
2032
+ function w3_has_rules($rules, $start, $end) {
2033
+ return preg_match('~' . w3_preg_quote($start) . "\n.*?" . w3_preg_quote($end) . "\n*~s", $rules);
2034
+ }
2035
+
2036
  /**
2037
  * Extracts JS files from content
2038
  *
2049
  $files = $matches[1];
2050
  }
2051
 
 
2052
  $files = array_values(array_unique($files));
2053
 
2054
  return $files;
2087
  $files = array_merge($files, $matches[2]);
2088
  }
2089
 
 
2090
  $files = array_values(array_unique($files));
2091
 
2092
  return $files;
inc/js/lightbox.js CHANGED
@@ -33,30 +33,29 @@ var W3tc_Lightbox = {
33
 
34
  open: function(options) {
35
  this.options = jQuery.extend({
36
- width: 400,
37
- height: 300,
38
- offsetTop: 100,
 
 
 
 
 
39
  content: null,
40
  url: null,
41
  callback: null
42
  }, options);
43
 
44
  this.create();
45
-
46
- this.container.css({
47
- width: this.options.width,
48
- height: this.options.height
49
- });
50
 
51
  if (this.options.content) {
52
- this.content(options.content);
53
  } else if (this.options.url) {
54
  this.load(this.options.url, this.options.callback);
55
  }
56
 
57
- W3tc_Overlay.show(this);
58
-
59
- this.resize();
60
  this.container.show();
61
  },
62
 
@@ -66,14 +65,34 @@ var W3tc_Lightbox = {
66
  },
67
 
68
  resize: function() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  this.container.css({
70
- top: this.window.scrollTop() + this.options.offsetTop,
71
- left: this.window.scrollLeft() + this.window.width() / 2 - this.container.width() / 2
72
  });
73
 
74
  jQuery('.lightbox-content', this.container).css({
75
- width: this.width(),
76
- height: this.height()
77
  });
78
  },
79
 
@@ -169,7 +188,7 @@ var W3tc_Overlay = {
169
  function w3tc_lightbox_support_us() {
170
  W3tc_Lightbox.open({
171
  width: 500,
172
- height: 230,
173
  url: 'admin.php?page=w3tc_general&w3tc_action=support_us'
174
  });
175
  }
@@ -177,20 +196,8 @@ function w3tc_lightbox_support_us() {
177
  var w3tc_minify_recommendations_checked = {};
178
 
179
  function w3tc_lightbox_minify_recommendations() {
180
- var min_height = 200;
181
- var max_height = 1200;
182
-
183
- var height = jQuery(window).height() - 220;
184
-
185
- if (height < min_height) {
186
- height = min_height;
187
- } else if (height > max_height) {
188
- height = max_height;
189
- }
190
-
191
  W3tc_Lightbox.open({
192
  width: 1000,
193
- height: height,
194
  url: 'admin.php?page=w3tc_minify&w3tc_action=minify_recommendations',
195
  callback: function(lightbox) {
196
  var theme = jQuery('#recom_theme').val();
@@ -297,20 +304,9 @@ function w3tc_lightbox_minify_recommendations() {
297
  }
298
 
299
  function w3tc_lightbox_self_test() {
300
- var min_height = 200;
301
- var max_height = 1000;
302
-
303
- var height = jQuery(window).height() - 220;
304
-
305
- if (height < min_height) {
306
- height = min_height;
307
- } else if (height > max_height) {
308
- height = max_height;
309
- }
310
-
311
  W3tc_Lightbox.open({
312
  width: 800,
313
- height: height,
314
  url: 'admin.php?page=w3tc_general&w3tc_action=self_test',
315
  callback: function(lightbox) {
316
  jQuery('.button-primary', lightbox.container).click(function() {
@@ -323,7 +319,7 @@ function w3tc_lightbox_self_test() {
323
  function w3tc_lightbox_cdn_s3_bucket_location(type) {
324
  W3tc_Lightbox.open({
325
  width: 500,
326
- height: 150,
327
  url: 'admin.php?page=w3tc_general&w3tc_action=cdn_s3_bucket_location&type=' + type,
328
  callback: function(lightbox) {
329
  jQuery('.button', lightbox.container).click(function() {
33
 
34
  open: function(options) {
35
  this.options = jQuery.extend({
36
+ width: 0,
37
+ height: 0,
38
+ maxWidth: 0,
39
+ maxHeight: 0,
40
+ minWidth: 0,
41
+ minHeight: 0,
42
+ widthPercent: 0.6,
43
+ heightPercent: 0.8,
44
  content: null,
45
  url: null,
46
  callback: null
47
  }, options);
48
 
49
  this.create();
50
+ this.resize();
 
 
 
 
51
 
52
  if (this.options.content) {
53
+ this.content(this.options.content);
54
  } else if (this.options.url) {
55
  this.load(this.options.url, this.options.callback);
56
  }
57
 
58
+ W3tc_Overlay.show();
 
 
59
  this.container.show();
60
  },
61
 
65
  },
66
 
67
  resize: function() {
68
+ var width = (this.options.width ? this.options.width : this.window.width() * this.options.widthPercent);
69
+ var height = (this.options.height ? this.options.height : this.window.height() * this.options.heightPercent);
70
+
71
+ if (this.options.maxWidth && width > this.options.maxWidth) {
72
+ width = this.options.maxWidth;
73
+ } else if (width < this.options.minWidth) {
74
+ width = this.options.minWidth;
75
+ }
76
+
77
+ if (this.options.maxHeight && height > this.options.maxHeight) {
78
+ height = this.options.maxHeight;
79
+ } else if (height < this.options.minHeight) {
80
+ height = this.options.minHeight;
81
+ }
82
+
83
+ this.container.css({
84
+ width: width,
85
+ height: height
86
+ });
87
+
88
  this.container.css({
89
+ top: this.window.scrollTop() + this.window.height() / 2 - this.container.outerHeight() / 2,
90
+ left: this.window.scrollLeft() + this.window.width() / 2 - this.container.outerWidth() / 2
91
  });
92
 
93
  jQuery('.lightbox-content', this.container).css({
94
+ width: width,
95
+ height: height
96
  });
97
  },
98
 
188
  function w3tc_lightbox_support_us() {
189
  W3tc_Lightbox.open({
190
  width: 500,
191
+ height: 200,
192
  url: 'admin.php?page=w3tc_general&w3tc_action=support_us'
193
  });
194
  }
196
  var w3tc_minify_recommendations_checked = {};
197
 
198
  function w3tc_lightbox_minify_recommendations() {
 
 
 
 
 
 
 
 
 
 
 
199
  W3tc_Lightbox.open({
200
  width: 1000,
 
201
  url: 'admin.php?page=w3tc_minify&w3tc_action=minify_recommendations',
202
  callback: function(lightbox) {
203
  var theme = jQuery('#recom_theme').val();
304
  }
305
 
306
  function w3tc_lightbox_self_test() {
 
 
 
 
 
 
 
 
 
 
 
307
  W3tc_Lightbox.open({
308
  width: 800,
309
+ minHeight: 300,
310
  url: 'admin.php?page=w3tc_general&w3tc_action=self_test',
311
  callback: function(lightbox) {
312
  jQuery('.button-primary', lightbox.container).click(function() {
319
  function w3tc_lightbox_cdn_s3_bucket_location(type) {
320
  W3tc_Lightbox.open({
321
  width: 500,
322
+ height: 130,
323
  url: 'admin.php?page=w3tc_general&w3tc_action=cdn_s3_bucket_location&type=' + type,
324
  callback: function(lightbox) {
325
  jQuery('.button', lightbox.container).click(function() {
inc/js/options.js CHANGED
@@ -73,7 +73,7 @@ function w3tc_minify_js_file_add(theme, template, location, file) {
73
  }
74
  select.val(template);
75
  jQuery(append).find('.js_file_location').val(location);
76
- jQuery('#js_files').append(append);
77
  w3tc_minify_js_file_clear();
78
  }
79
 
@@ -85,7 +85,7 @@ function w3tc_minify_css_file_add(theme, template, file) {
85
  select.append(jQuery('<option />').val(i).html(minify_templates[theme][i]));
86
  }
87
  select.val(template);
88
- jQuery('#css_files').append(append);
89
  w3tc_minify_css_file_clear();
90
  }
91
 
@@ -389,7 +389,7 @@ jQuery(function() {
389
 
390
  var qindex = v.indexOf('?');
391
  if (qindex != -1) {
392
- if (!/^https?:\/\//.test(v)) {
393
  query_js.push(g);
394
  }
395
  v = v.substr(0, qindex);
@@ -417,7 +417,7 @@ jQuery(function() {
417
 
418
  var qindex = v.indexOf('?');
419
  if (qindex != -1) {
420
- if (!/^https?:\/\//.test(v)) {
421
  query_css.push(g);
422
  }
423
  v = v.substr(0, qindex);
@@ -499,6 +499,7 @@ jQuery(function() {
499
  jQuery.extend(params, {
500
  engine: 'mirror'
501
  });
 
502
  if (cnames.length) {
503
  params['config[domain][]'] = cnames;
504
  }
@@ -506,8 +507,11 @@ jQuery(function() {
506
 
507
  case me.hasClass('cdn_netdna'):
508
  jQuery.extend(params, {
509
- engine: 'netdna'
 
 
510
  });
 
511
  if (cnames.length) {
512
  params['config[domain][]'] = cnames;
513
  }
@@ -517,6 +521,7 @@ jQuery(function() {
517
  jQuery.extend(params, {
518
  engine: 'cotendo'
519
  });
 
520
  if (cnames.length) {
521
  params['config[domain][]'] = cnames;
522
  }
@@ -531,6 +536,7 @@ jQuery(function() {
531
  'config[pass]': jQuery('#cdn_ftp_pass').val(),
532
  'config[pasv]': jQuery('#cdn_ftp_pasv:checked').size()
533
  });
 
534
  if (cnames.length) {
535
  params['config[domain][]'] = cnames;
536
  }
@@ -543,6 +549,7 @@ jQuery(function() {
543
  'config[secret]': jQuery('#cdn_s3_secret').val(),
544
  'config[bucket]': jQuery('#cdn_s3_bucket').val()
545
  });
 
546
  if (cnames.length) {
547
  params['config[cname][]'] = cnames;
548
  }
@@ -556,6 +563,7 @@ jQuery(function() {
556
  'config[bucket]': jQuery('#cdn_cf_bucket').val(),
557
  'config[id]': jQuery('#cdn_cf_id').val()
558
  });
 
559
  if (cnames.length) {
560
  params['config[cname][]'] = cnames;
561
  }
@@ -569,6 +577,7 @@ jQuery(function() {
569
  'config[origin]': jQuery('#cdn_cf2_origin').val(),
570
  'config[id]': jQuery('#cdn_cf2_id').val()
571
  });
 
572
  if (cnames.length) {
573
  params['config[cname][]'] = cnames;
574
  }
@@ -583,6 +592,7 @@ jQuery(function() {
583
  'config[container]': jQuery('#cdn_rscf_container').val(),
584
  'config[id]': jQuery('#cdn_rscf_id').val()
585
  });
 
586
  if (cnames.length) {
587
  params['config[cname][]'] = cnames;
588
  }
@@ -595,6 +605,7 @@ jQuery(function() {
595
  'config[key]': jQuery('#cdn_azure_key').val(),
596
  'config[container]': jQuery('#cdn_azure_container').val()
597
  });
 
598
  if (cnames.length) {
599
  params['config[cname][]'] = cnames;
600
  }
@@ -628,9 +639,12 @@ jQuery(function() {
628
  'config[key]': jQuery('#cdn_s3_key').val(),
629
  'config[secret]': jQuery('#cdn_s3_secret').val(),
630
  'config[bucket]': jQuery('#cdn_s3_bucket').val(),
631
- 'config[bucket_location]': jQuery('#cdn_s3_bucket_location').val(),
632
- 'config[cname][]': cnames
633
  });
 
 
 
 
634
  break;
635
 
636
  case me.hasClass('cdn_cf'):
@@ -641,9 +655,12 @@ jQuery(function() {
641
  'config[key]': jQuery('#cdn_cf_key').val(),
642
  'config[secret]': jQuery('#cdn_cf_secret').val(),
643
  'config[bucket]': jQuery('#cdn_cf_bucket').val(),
644
- 'config[bucket_location]': jQuery('#cdn_cf_bucket_location').val(),
645
- 'config[cname][]': cnames
646
  });
 
 
 
 
647
  break;
648
 
649
  case me.hasClass('cdn_cf2'):
@@ -654,9 +671,12 @@ jQuery(function() {
654
  'config[key]': jQuery('#cdn_cf2_key').val(),
655
  'config[secret]': jQuery('#cdn_cf2_secret').val(),
656
  'config[origin]': jQuery('#cdn_cf2_origin').val(),
657
- 'config[bucket_location]': jQuery('#cdn_cf2_bucket_location').val(),
658
- 'config[cname][]': cnames
659
  });
 
 
 
 
660
  break;
661
 
662
  case me.hasClass('cdn_rscf'):
@@ -666,9 +686,12 @@ jQuery(function() {
666
  engine: 'rscf',
667
  'config[user]': jQuery('#cdn_rscf_user').val(),
668
  'config[key]': jQuery('#cdn_rscf_key').val(),
669
- 'config[container]': jQuery('#cdn_rscf_container').val(),
670
- 'config[cname][]': cnames
671
  });
 
 
 
 
672
  break;
673
 
674
  case me.hasClass('cdn_azure'):
@@ -676,9 +699,12 @@ jQuery(function() {
676
  engine: 'azure',
677
  'config[user]': jQuery('#cdn_azure_user').val(),
678
  'config[key]': jQuery('#cdn_azure_key').val(),
679
- 'config[container]': jQuery('#cdn_azure_container').val(),
680
- 'config[cname][]': cnames
681
  });
 
 
 
 
682
  break;
683
  }
684
 
@@ -1017,8 +1043,8 @@ jQuery(function() {
1017
 
1018
  jQuery('#mobile_groups').append(li);
1019
  w3tc_mobile_groups_clear();
1020
-
1021
  window.location.hash = '#mobile_group_' + group;
 
1022
  }
1023
  } else {
1024
  alert('Empty group name!');
@@ -1119,8 +1145,8 @@ jQuery(function() {
1119
 
1120
  jQuery('#referrer_groups').append(li);
1121
  w3tc_referrer_groups_clear();
1122
-
1123
  window.location.hash = '#referrer_group_' + group;
 
1124
  }
1125
  } else {
1126
  alert('Empty group name!');
73
  }
74
  select.val(template);
75
  jQuery(append).find('.js_file_location').val(location);
76
+ jQuery('#js_files').append(append).find('li:last input:first').focus();
77
  w3tc_minify_js_file_clear();
78
  }
79
 
85
  select.append(jQuery('<option />').val(i).html(minify_templates[theme][i]));
86
  }
87
  select.val(template);
88
+ jQuery('#css_files').append(append).find('li:last input:first').focus();
89
  w3tc_minify_css_file_clear();
90
  }
91
 
389
 
390
  var qindex = v.indexOf('?');
391
  if (qindex != -1) {
392
+ if (!/^(https?:)?\/\//.test(v)) {
393
  query_js.push(g);
394
  }
395
  v = v.substr(0, qindex);
417
 
418
  var qindex = v.indexOf('?');
419
  if (qindex != -1) {
420
+ if (!/^(https?:)?\/\//.test(v)) {
421
  query_css.push(g);
422
  }
423
  v = v.substr(0, qindex);
499
  jQuery.extend(params, {
500
  engine: 'mirror'
501
  });
502
+
503
  if (cnames.length) {
504
  params['config[domain][]'] = cnames;
505
  }
507
 
508
  case me.hasClass('cdn_netdna'):
509
  jQuery.extend(params, {
510
+ engine: 'netdna',
511
+ 'config[apiid]': jQuery('#cdn_netdna_apiid').val(),
512
+ 'config[apikey]': jQuery('#cdn_netdna_apikey').val()
513
  });
514
+
515
  if (cnames.length) {
516
  params['config[domain][]'] = cnames;
517
  }
521
  jQuery.extend(params, {
522
  engine: 'cotendo'
523
  });
524
+
525
  if (cnames.length) {
526
  params['config[domain][]'] = cnames;
527
  }
536
  'config[pass]': jQuery('#cdn_ftp_pass').val(),
537
  'config[pasv]': jQuery('#cdn_ftp_pasv:checked').size()
538
  });
539
+
540
  if (cnames.length) {
541
  params['config[domain][]'] = cnames;
542
  }
549
  'config[secret]': jQuery('#cdn_s3_secret').val(),
550
  'config[bucket]': jQuery('#cdn_s3_bucket').val()
551
  });
552
+
553
  if (cnames.length) {
554
  params['config[cname][]'] = cnames;
555
  }
563
  'config[bucket]': jQuery('#cdn_cf_bucket').val(),
564
  'config[id]': jQuery('#cdn_cf_id').val()
565
  });
566
+
567
  if (cnames.length) {
568
  params['config[cname][]'] = cnames;
569
  }
577
  'config[origin]': jQuery('#cdn_cf2_origin').val(),
578
  'config[id]': jQuery('#cdn_cf2_id').val()
579
  });
580
+
581
  if (cnames.length) {
582
  params['config[cname][]'] = cnames;
583
  }
592
  'config[container]': jQuery('#cdn_rscf_container').val(),
593
  'config[id]': jQuery('#cdn_rscf_id').val()
594
  });
595
+
596
  if (cnames.length) {
597
  params['config[cname][]'] = cnames;
598
  }
605
  'config[key]': jQuery('#cdn_azure_key').val(),
606
  'config[container]': jQuery('#cdn_azure_container').val()
607
  });
608
+
609
  if (cnames.length) {
610
  params['config[cname][]'] = cnames;
611
  }
639
  'config[key]': jQuery('#cdn_s3_key').val(),
640
  'config[secret]': jQuery('#cdn_s3_secret').val(),
641
  'config[bucket]': jQuery('#cdn_s3_bucket').val(),
642
+ 'config[bucket_location]': jQuery('#cdn_s3_bucket_location').val()
 
643
  });
644
+
645
+ if (cnames.length) {
646
+ params['config[cname][]'] = cnames;
647
+ }
648
  break;
649
 
650
  case me.hasClass('cdn_cf'):
655
  'config[key]': jQuery('#cdn_cf_key').val(),
656
  'config[secret]': jQuery('#cdn_cf_secret').val(),
657
  'config[bucket]': jQuery('#cdn_cf_bucket').val(),
658
+ 'config[bucket_location]': jQuery('#cdn_cf_bucket_location').val()
 
659
  });
660
+
661
+ if (cnames.length) {
662
+ params['config[cname][]'] = cnames;
663
+ }
664
  break;
665
 
666
  case me.hasClass('cdn_cf2'):
671
  'config[key]': jQuery('#cdn_cf2_key').val(),
672
  'config[secret]': jQuery('#cdn_cf2_secret').val(),
673
  'config[origin]': jQuery('#cdn_cf2_origin').val(),
674
+ 'config[bucket_location]': jQuery('#cdn_cf2_bucket_location').val()
 
675
  });
676
+
677
+ if (cnames.length) {
678
+ params['config[cname][]'] = cnames;
679
+ }
680
  break;
681
 
682
  case me.hasClass('cdn_rscf'):
686
  engine: 'rscf',
687
  'config[user]': jQuery('#cdn_rscf_user').val(),
688
  'config[key]': jQuery('#cdn_rscf_key').val(),
689
+ 'config[container]': jQuery('#cdn_rscf_container').val()
 
690
  });
691
+
692
+ if (cnames.length) {
693
+ params['config[cname][]'] = cnames;
694
+ }
695
  break;
696
 
697
  case me.hasClass('cdn_azure'):
699
  engine: 'azure',
700
  'config[user]': jQuery('#cdn_azure_user').val(),
701
  'config[key]': jQuery('#cdn_azure_key').val(),
702
+ 'config[container]': jQuery('#cdn_azure_container').val()
 
703
  });
704
+
705
+ if (cnames.length) {
706
+ params['config[cname][]'] = cnames;
707
+ }
708
  break;
709
  }
710
 
1043
 
1044
  jQuery('#mobile_groups').append(li);
1045
  w3tc_mobile_groups_clear();
 
1046
  window.location.hash = '#mobile_group_' + group;
1047
+ li.find('textarea').focus();
1048
  }
1049
  } else {
1050
  alert('Empty group name!');
1145
 
1146
  jQuery('#referrer_groups').append(li);
1147
  w3tc_referrer_groups_clear();
 
1148
  window.location.hash = '#referrer_group_' + group;
1149
+ li.find('textarea').focus();
1150
  }
1151
  } else {
1152
  alert('Empty group name!');
inc/lightbox/minify_recommendations.phtml CHANGED
@@ -11,9 +11,8 @@
11
  </p>
12
 
13
  <div id="recom_container">
 
14
 
15
- <h4>JavaScript:</h4>
16
-
17
  <?php if (count($js_groups)) :?>
18
  <ul id="recom_js_files" class="minify-files">
19
  <?php $index = 0; foreach ($js_groups as $js_group => $js_files): ?>
@@ -60,8 +59,8 @@
60
  <td>
61
  <input class="js_file_verify button" type="button" value="Verify URI" />
62
  </td>
63
- </tr>
64
- </table>
65
  </li>
66
  <?php endforeach; ?>
67
  <?php endforeach; ?>
@@ -72,9 +71,9 @@
72
  <?php else:?>
73
  <p>No files found.</p>
74
  <?php endif;?>
75
-
76
  <h4>Cascading Style Sheets:</h4>
77
-
78
  <?php if (count($css_groups)) :?>
79
  <ul id="recom_css_files" class="minify-files">
80
  <?php $index = 0; foreach ($css_groups as $css_group => $css_files): ?>
@@ -106,7 +105,7 @@
106
  <input class="css_file_verify button" type="button" value="Verify URI" />
107
  </td>
108
  </tr>
109
- </table>
110
  </li>
111
  <?php endforeach; ?>
112
  <?php endforeach; ?>
@@ -119,15 +118,17 @@
119
  <?php endif;?>
120
  </div>
121
 
122
- <p>
123
- <input class="recom_apply button-primary" type="button" value="Apply &amp; close" />
124
- </p>
 
125
 
126
- <fieldset>
127
- <legend>Notes</legend>
128
 
129
- <ul>
130
- <li>Typically minification of advertiser code, analytics/statistics or any other types of tracking code is not recommended.</li>
131
- <li>Scripts that were not already detected above may require <a href="admin.php?page=w3tc_support&amp;request_type=plugin_config">professional consultation</a> to implement.</li>
132
- </ul>
133
- </fieldset>
 
11
  </p>
12
 
13
  <div id="recom_container">
14
+ <h4 style="margin-top: 0;">JavaScript:</h4>
15
 
 
 
16
  <?php if (count($js_groups)) :?>
17
  <ul id="recom_js_files" class="minify-files">
18
  <?php $index = 0; foreach ($js_groups as $js_group => $js_files): ?>
59
  <td>
60
  <input class="js_file_verify button" type="button" value="Verify URI" />
61
  </td>
62
+ </tr>
63
+ </table>
64
  </li>
65
  <?php endforeach; ?>
66
  <?php endforeach; ?>
71
  <?php else:?>
72
  <p>No files found.</p>
73
  <?php endif;?>
74
+
75
  <h4>Cascading Style Sheets:</h4>
76
+
77
  <?php if (count($css_groups)) :?>
78
  <ul id="recom_css_files" class="minify-files">
79
  <?php $index = 0; foreach ($css_groups as $css_group => $css_files): ?>
105
  <input class="css_file_verify button" type="button" value="Verify URI" />
106
  </td>
107
  </tr>
108
+ </table>
109
  </li>
110
  <?php endforeach; ?>
111
  <?php endforeach; ?>
118
  <?php endif;?>
119
  </div>
120
 
121
+ <div id="recom_container_bottom">
122
+ <p>
123
+ <input class="recom_apply button-primary" type="button" value="Apply &amp; close" />
124
+ </p>
125
 
126
+ <fieldset>
127
+ <legend>Notes</legend>
128
 
129
+ <ul>
130
+ <li>Typically minification of advertiser code, analytics/statistics or any other types of tracking code is not recommended.</li>
131
+ <li>Scripts that were not already detected above may require <a href="admin.php?page=w3tc_support&amp;request_type=plugin_config">professional consultation</a> to implement.</li>
132
+ </ul>
133
+ </fieldset>
134
+ </div>
inc/lightbox/self_test.phtml CHANGED
@@ -12,7 +12,7 @@
12
  </fieldset>
13
 
14
  <div id="w3tc-self-test">
15
- <h4>Server Modules &amp; Resources:</h4>
16
 
17
  <ul>
18
  <li>
@@ -213,24 +213,24 @@
213
  w3_get_browsercache_rules_no404wp_path()
214
  ));
215
  ?>
216
- <?php foreach ($paths as $path): ?>
217
- <li>
218
- <?php echo htmlspecialchars($path); ?>:
219
- <?php if (file_exists($path)): ?>
220
- <?php if (w3_is_writable($path)): ?>
221
- <code>OK</code>
222
- <?php else: ?>
223
- <code>Not write-able</code>
224
- <?php endif; ?>
225
  <?php else: ?>
226
- <?php if (w3_is_writable_dir(dirname($path))): ?>
227
- <code>Write-able</code>
228
- <?php else: ?>
229
- <code>Not write-able</code>
230
- <?php endif; ?>
231
  <?php endif; ?>
232
- </li>
233
- <?php endforeach; ?>
 
 
 
 
 
 
 
234
 
235
  <li>
236
  <?php echo w3_path(WP_CONTENT_DIR); ?>:
@@ -271,6 +271,15 @@
271
  <?php endif; ?>
272
  </li>
273
 
 
 
 
 
 
 
 
 
 
274
  <li>
275
  Network mode:
276
  <?php if (w3_is_network()): ?>
@@ -282,6 +291,6 @@
282
  </ul>
283
  </div>
284
 
285
- <p>
286
  <input class="button-primary" type="button" value="Close" />
287
- </p>
12
  </fieldset>
13
 
14
  <div id="w3tc-self-test">
15
+ <h4 style="margin-top: 0;">Server Modules &amp; Resources:</h4>
16
 
17
  <ul>
18
  <li>
213
  w3_get_browsercache_rules_no404wp_path()
214
  ));
215
  ?>
216
+ <?php foreach ($paths as $path): if ($path): ?>
217
+ <li>
218
+ <?php echo htmlspecialchars($path); ?>:
219
+ <?php if (file_exists($path)): ?>
220
+ <?php if (w3_is_writable($path)): ?>
221
+ <code>OK</code>
 
 
 
222
  <?php else: ?>
223
+ <code>Not write-able</code>
 
 
 
 
224
  <?php endif; ?>
225
+ <?php else: ?>
226
+ <?php if (w3_is_writable_dir(dirname($path))): ?>
227
+ <code>Write-able</code>
228
+ <?php else: ?>
229
+ <code>Not write-able</code>
230
+ <?php endif; ?>
231
+ <?php endif; ?>
232
+ </li>
233
+ <?php endif; endforeach; ?>
234
 
235
  <li>
236
  <?php echo w3_path(WP_CONTENT_DIR); ?>:
271
  <?php endif; ?>
272
  </li>
273
 
274
+ <li>
275
+ URL rewrite:
276
+ <?php if (w3_can_check_rules()): ?>
277
+ <code>Enabled</code>
278
+ <?php else: ?>
279
+ <code>Disabled</code>
280
+ <?php endif; ?>
281
+ </li>
282
+
283
  <li>
284
  Network mode:
285
  <?php if (w3_is_network()): ?>
291
  </ul>
292
  </div>
293
 
294
+ <div id="w3tc-self-test-bottom">
295
  <input class="button-primary" type="button" value="Close" />
296
+ </div>
inc/options/common/header.phtml CHANGED
@@ -41,4 +41,4 @@ jQuery(function($) {
41
  <a href="?page=w3tc_support"<?php if ($this->_page == 'w3tc_support'): ?> class="w3tc-options-menu-selected"<?php endif; ?> style="color: red;">Support</a> |
42
  <a href="?page=w3tc_install"<?php if ($this->_page == 'w3tc_install'): ?> class="w3tc-options-menu-selected"<?php endif; ?>>Install</a> |
43
  <a href="?page=w3tc_about"<?php if ($this->_page == 'w3tc_about'): ?> class="w3tc-options-menu-selected"<?php endif; ?>>About</a>
44
- </p>
41
  <a href="?page=w3tc_support"<?php if ($this->_page == 'w3tc_support'): ?> class="w3tc-options-menu-selected"<?php endif; ?> style="color: red;">Support</a> |
42
  <a href="?page=w3tc_install"<?php if ($this->_page == 'w3tc_install'): ?> class="w3tc-options-menu-selected"<?php endif; ?>>Install</a> |
43
  <a href="?page=w3tc_about"<?php if ($this->_page == 'w3tc_about'): ?> class="w3tc-options-menu-selected"<?php endif; ?>>About</a>
44
+ </p>
inc/options/general.phtml CHANGED
@@ -67,7 +67,7 @@
67
  <td>
68
  <select name="pgcache.engine">
69
  <optgroup label="Shared Server (disk enhanced is best):">
70
- <option value="file_pgcache"<?php selected($this->_config->get_string('pgcache.engine'), 'file_pgcache'); ?><?php if (! $check_rules): ?> disabled="disabled"<?php endif; ?>>Disk (enhanced)</option>
71
  <option value="file"<?php selected($this->_config->get_string('pgcache.engine'), 'file'); ?>>Disk (basic)</option>
72
  </optgroup>
73
  <optgroup label="Dedicated / Virtual Server:">
@@ -480,7 +480,7 @@
480
  <tr>
481
  <th colspan="2">
482
  <input type="hidden" name="widget.pagespeed.enabled" value="0" />
483
- <label><input type="checkbox" name="widget.pagespeed.enabled" value="1"<?php checked($this->_config->get_boolean('widget.latest.enabled'), true); ?> /> Enable Google Page Speed dashboard widget</label>
484
  <br /><span class="description">Display Google Page Speed results on the WordPress dashboard.</span>
485
  </th>
486
  </tr>
67
  <td>
68
  <select name="pgcache.engine">
69
  <optgroup label="Shared Server (disk enhanced is best):">
70
+ <option value="file_generic"<?php selected($this->_config->get_string('pgcache.engine'), 'file_generic'); ?><?php if (! $check_rules): ?> disabled="disabled"<?php endif; ?>>Disk (enhanced)</option>
71
  <option value="file"<?php selected($this->_config->get_string('pgcache.engine'), 'file'); ?>>Disk (basic)</option>
72
  </optgroup>
73
  <optgroup label="Dedicated / Virtual Server:">
480
  <tr>
481
  <th colspan="2">
482
  <input type="hidden" name="widget.pagespeed.enabled" value="0" />
483
+ <label><input type="checkbox" name="widget.pagespeed.enabled" value="1"<?php checked($this->_config->get_boolean('widget.pagespeed.enabled'), true); ?> /> Enable Google Page Speed dashboard widget</label>
484
  <br /><span class="description">Display Google Page Speed results on the WordPress dashboard.</span>
485
  </th>
486
  </tr>
inc/options/minify.phtml CHANGED
@@ -17,7 +17,7 @@ minify_templates['<?php echo addslashes($theme_key); ?>']['<?php echo addslashes
17
  is currently <span class="w3tc-<?php if ($minify_enabled): ?>enabled">enabled<?php else: ?>disabled">disabled<?php endif; ?></span>.
18
  </p>
19
  <p>
20
- To rebuild the minify cache use the
21
  <input type="hidden" name="page" value="<?php echo $this->_page; ?>" />
22
  <input type="submit" name="flush_minify" value="empty cache"<?php if (! $minify_enabled): ?> disabled="disabled"<?php endif; ?> class="button" />
23
  operation.
@@ -187,8 +187,8 @@ minify_templates['<?php echo addslashes($theme_key); ?>']['<?php echo addslashes
187
  <br /><span class="description">Files are minified by template. First select the theme to manage, then add scripts used in all templates to the "All Templates" group. Use the menu above to manage scripts unique to a specific template. If necessary drag &amp; drop to resolve dependency issues (due to incorrect order).</span>
188
  </p>
189
  <ul id="js_files" class="minify-files">
190
- <?php $index = 0; foreach ($js_groups as $js_theme => $js_templates): if (isset($templates[$js_theme])): ?>
191
- <?php foreach ($js_templates as $js_template => $js_locations): ?>
192
  <?php foreach ((array) $js_locations as $js_location => $js_config): ?>
193
  <?php if (! empty($js_config['files'])): foreach ((array) $js_config['files'] as $js_file): $index++; ?>
194
  <li>
@@ -229,7 +229,7 @@ minify_templates['<?php echo addslashes($theme_key); ?>']['<?php echo addslashes
229
  <input class="js_file_delete js_enabled button" type="button" value="Delete" />
230
  <input class="js_file_verify js_enabled button" type="button" value="Verify URI" />
231
  </td>
232
- </tr>
233
  </table>
234
  </li>
235
  <?php endforeach; endif; ?>
@@ -259,7 +259,7 @@ minify_templates['<?php echo addslashes($theme_key); ?>']['<?php echo addslashes
259
  <label><input id="css_enabled" type="checkbox" name="minify.css.enable" value="1"<?php checked($this->_config->get_boolean('minify.css.enable'), true); ?> /> Enable</label><br />
260
  <label><input class="css_enabled" type="checkbox" name="minify.css.combine" value="1"<?php checked($this->_config->get_boolean('minify.css.combine'), true); ?> /> Combine only</label><br />
261
  <?php
262
- $css_engine_file = '';
263
 
264
  switch ($css_engine) {
265
  case 'css':
@@ -316,8 +316,8 @@ minify_templates['<?php echo addslashes($theme_key); ?>']['<?php echo addslashes
316
  <br /><span class="description">Files are minified by template. First select the theme to manage, then add style sheets used in all templates to the "All Templates" group. Use the menu above to manage style sheets unique to a specific template. If necessary drag &amp; drop to resolve dependency issues (due to incorrect order).</span>
317
  </p>
318
  <ul id="css_files" class="minify-files">
319
- <?php $index = 0; foreach ($css_groups as $css_theme => $css_templates): if (isset($templates[$css_theme])): ?>
320
- <?php foreach ($css_templates as $css_template => $css_locations): ?>
321
  <?php foreach ((array) $css_locations as $css_location => $css_config): ?>
322
  <?php if (! empty($css_config['files'])): foreach ((array) $css_config['files'] as $css_file): $index++; ?>
323
  <li>
@@ -326,7 +326,7 @@ minify_templates['<?php echo addslashes($theme_key); ?>']['<?php echo addslashes
326
  <th>&nbsp;</th>
327
  <th>File URI:</th>
328
  <th colspan="2">Template:</th>
329
- </tr>
330
  <tr>
331
  <td><?php echo $index; ?>.</td>
332
  <td>
17
  is currently <span class="w3tc-<?php if ($minify_enabled): ?>enabled">enabled<?php else: ?>disabled">disabled<?php endif; ?></span>.
18
  </p>
19
  <p>
20
+ To rebuild the minify cache use the
21
  <input type="hidden" name="page" value="<?php echo $this->_page; ?>" />
22
  <input type="submit" name="flush_minify" value="empty cache"<?php if (! $minify_enabled): ?> disabled="disabled"<?php endif; ?> class="button" />
23
  operation.
187
  <br /><span class="description">Files are minified by template. First select the theme to manage, then add scripts used in all templates to the "All Templates" group. Use the menu above to manage scripts unique to a specific template. If necessary drag &amp; drop to resolve dependency issues (due to incorrect order).</span>
188
  </p>
189
  <ul id="js_files" class="minify-files">
190
+ <?php foreach ($js_groups as $js_theme => $js_templates): if (isset($templates[$js_theme])): ?>
191
+ <?php $index = 0; foreach ($js_templates as $js_template => $js_locations): ?>
192
  <?php foreach ((array) $js_locations as $js_location => $js_config): ?>
193
  <?php if (! empty($js_config['files'])): foreach ((array) $js_config['files'] as $js_file): $index++; ?>
194
  <li>
229
  <input class="js_file_delete js_enabled button" type="button" value="Delete" />
230
  <input class="js_file_verify js_enabled button" type="button" value="Verify URI" />
231
  </td>
232
+ </tr>
233
  </table>
234
  </li>
235
  <?php endforeach; endif; ?>
259
  <label><input id="css_enabled" type="checkbox" name="minify.css.enable" value="1"<?php checked($this->_config->get_boolean('minify.css.enable'), true); ?> /> Enable</label><br />
260
  <label><input class="css_enabled" type="checkbox" name="minify.css.combine" value="1"<?php checked($this->_config->get_boolean('minify.css.combine'), true); ?> /> Combine only</label><br />
261
  <?php
262
+ $css_engine_file = '';
263
 
264
  switch ($css_engine) {
265
  case 'css':
316
  <br /><span class="description">Files are minified by template. First select the theme to manage, then add style sheets used in all templates to the "All Templates" group. Use the menu above to manage style sheets unique to a specific template. If necessary drag &amp; drop to resolve dependency issues (due to incorrect order).</span>
317
  </p>
318
  <ul id="css_files" class="minify-files">
319
+ <?php foreach ($css_groups as $css_theme => $css_templates): if (isset($templates[$css_theme])): ?>
320
+ <?php $index = 0; foreach ($css_templates as $css_template => $css_locations): ?>
321
  <?php foreach ((array) $css_locations as $css_location => $css_config): ?>
322
  <?php if (! empty($css_config['files'])): foreach ((array) $css_config['files'] as $css_file): $index++; ?>
323
  <li>
326
  <th>&nbsp;</th>
327
  <th>File URI:</th>
328
  <th colspan="2">Template:</th>
329
+ </tr>
330
  <tr>
331
  <td><?php echo $index; ?>.</td>
332
  <td>
inc/options/pgcache.phtml CHANGED
@@ -7,7 +7,7 @@
7
  is currently <span class="w3tc-<?php if ($pgcache_enabled): ?>enabled">enabled<?php else: ?>disabled">disabled<?php endif; ?></span>.
8
  </p>
9
  <p>
10
- To rebuild the page cache use the
11
  <input type="submit" name="flush_pgcache" value="empty cache"<?php if (! $pgcache_enabled): ?> disabled="disabled"<?php endif; ?> class="button" />
12
  operation.
13
  <input type="hidden" name="page" value="<?php echo $this->_page; ?>" />
@@ -41,8 +41,8 @@
41
  </tr>
42
  <tr>
43
  <th>
44
- <input type="hidden" name="pgcache.cache.query" value="0"<?php if ($this->_config->get_string('pgcache.engine') == 'file_pgcache'): ?> disabled="disabled"<?php endif; ?> />
45
- <label><input type="checkbox" name="pgcache.cache.query" value="1"<?php checked($this->_config->get_boolean('pgcache.cache.query'), true); ?><?php if ($this->_config->get_string('pgcache.engine') == 'file_pgcache'): ?> disabled="disabled"<?php endif; ?> /> Cache <acronym title="Uniform Resource Identifier">URI</acronym>s with query string variables</label><br />
46
  <span class="description">Search result (and similar) pages will be cached if enabled.</span>
47
  </th>
48
  </tr>
@@ -76,7 +76,7 @@
76
  <tr>
77
  <th><label for="pgcache_file_gc">Garbage collection interval:</label></th>
78
  <td>
79
- <input id="pgcache_file_gc" type="text" name="pgcache.file.gc" value="<?php echo $this->_config->get_integer('pgcache.file.gc'); ?>" size="8"<?php if ($this->_config->get_string('pgcache.engine') != 'file' && $this->_config->get_string('pgcache.engine') != 'file_pgcache'): ?> disabled="disabled"<?php endif; ?> /> seconds
80
  <br /><span class="description">If caching to disk, specify how frequently expired cache data is removed. For busy sites, a lower value is best.</span>
81
  </td>
82
  </tr>
@@ -120,7 +120,7 @@
120
  <tr>
121
  <th><label for="pgcache_cache_headers">Specify page headers:</label></th>
122
  <td>
123
- <textarea id="pgcache_cache_headers" name="pgcache.cache.headers" cols="40" rows="5"<?php if (!W3TC_PHP5 || $this->_config->get_string('pgcache.engine') == 'file_pgcache'): ?> disabled="disabled"<?php endif; ?>><?php echo htmlspecialchars(implode("\r\n", $this->_config->get_array('pgcache.cache.headers'))); ?></textarea><br />
124
  <span class="description">Specify additional page headers to cache.</span>
125
  </td>
126
  </tr>
@@ -214,7 +214,7 @@
214
  <tr>
215
  <th colspan="2">
216
  <p>Specify the feed types to purge:</p>
217
- <input type="hidden" name="pgcache.purge.feed.types" value="" />
218
  <?php foreach($feeds as $feed): ?>
219
  <label><input type="checkbox" name="pgcache.purge.feed.types[]" value="<?php echo $feed; ?>"<?php checked(in_array($feed, $this->_config->get_array('pgcache.purge.feed.types')), true); ?> />
220
  <?php echo $feed; ?>
7
  is currently <span class="w3tc-<?php if ($pgcache_enabled): ?>enabled">enabled<?php else: ?>disabled">disabled<?php endif; ?></span>.
8
  </p>
9
  <p>
10
+ To rebuild the page cache use the
11
  <input type="submit" name="flush_pgcache" value="empty cache"<?php if (! $pgcache_enabled): ?> disabled="disabled"<?php endif; ?> class="button" />
12
  operation.
13
  <input type="hidden" name="page" value="<?php echo $this->_page; ?>" />
41
  </tr>
42
  <tr>
43
  <th>
44
+ <input type="hidden" name="pgcache.cache.query" value="0"<?php if ($this->_config->get_string('pgcache.engine') == 'file_generic'): ?> disabled="disabled"<?php endif; ?> />
45
+ <label><input type="checkbox" name="pgcache.cache.query" value="1"<?php checked($this->_config->get_boolean('pgcache.cache.query'), true); ?><?php if ($this->_config->get_string('pgcache.engine') == 'file_generic'): ?> disabled="disabled"<?php endif; ?> /> Cache <acronym title="Uniform Resource Identifier">URI</acronym>s with query string variables</label><br />
46
  <span class="description">Search result (and similar) pages will be cached if enabled.</span>
47
  </th>
48
  </tr>
76
  <tr>
77
  <th><label for="pgcache_file_gc">Garbage collection interval:</label></th>
78
  <td>
79
+ <input id="pgcache_file_gc" type="text" name="pgcache.file.gc" value="<?php echo $this->_config->get_integer('pgcache.file.gc'); ?>" size="8"<?php if ($this->_config->get_string('pgcache.engine') != 'file' && $this->_config->get_string('pgcache.engine') != 'file_generic'): ?> disabled="disabled"<?php endif; ?> /> seconds
80
  <br /><span class="description">If caching to disk, specify how frequently expired cache data is removed. For busy sites, a lower value is best.</span>
81
  </td>
82
  </tr>
120
  <tr>
121
  <th><label for="pgcache_cache_headers">Specify page headers:</label></th>
122
  <td>
123
+ <textarea id="pgcache_cache_headers" name="pgcache.cache.headers" cols="40" rows="5"<?php if (!W3TC_PHP5 || $this->_config->get_string('pgcache.engine') == 'file_generic'): ?> disabled="disabled"<?php endif; ?>><?php echo htmlspecialchars(implode("\r\n", $this->_config->get_array('pgcache.cache.headers'))); ?></textarea><br />
124
  <span class="description">Specify additional page headers to cache.</span>
125
  </td>
126
  </tr>
214
  <tr>
215
  <th colspan="2">
216
  <p>Specify the feed types to purge:</p>
217
+ <input type="hidden" name="pgcache.purge.feed.types" value="" />
218
  <?php foreach($feeds as $feed): ?>
219
  <label><input type="checkbox" name="pgcache.purge.feed.types[]" value="<?php echo $feed; ?>"<?php checked(in_array($feed, $this->_config->get_array('pgcache.purge.feed.types')), true); ?> />
220
  <?php echo $feed; ?>
lib/Minify/Minify.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Class Minify
4
  * @package Minify
5
  */
6
 
@@ -8,7 +8,7 @@
8
  * Minify_Source
9
  */
10
  require_once W3TC_LIB_MINIFY_DIR . '/Minify/Source.php';
11
-
12
  /**
13
  * Minify - Combines, minifies, and caches JavaScript and CSS files on demand.
14
  *
@@ -28,27 +28,27 @@ require_once W3TC_LIB_MINIFY_DIR . '/Minify/Source.php';
28
  * @link http://code.google.com/p/minify/
29
  */
30
  class Minify {
31
-
32
  const VERSION = '2.1.3';
33
  const TYPE_CSS = 'text/css';
34
  const TYPE_HTML = 'text/html';
35
  // there is some debate over the ideal JS Content-Type, but this is the
36
  // Apache default and what Yahoo! uses..
37
  const TYPE_JS = 'application/x-javascript';
38
-
39
  /**
40
  * How many hours behind are the file modification times of uploaded files?
41
- *
42
  * If you upload files from Windows to a non-Windows server, Windows may report
43
- * incorrect mtimes for the files. Immediately after modifying and uploading a
44
- * file, use the touch command to update the mtime on the server. If the mtime
45
- * jumps ahead by a number of hours, set this variable to that number. If the mtime
46
  * moves back, this should not be needed.
47
  *
48
  * @var int $uploaderHoursBehind
49
  */
50
  public static $uploaderHoursBehind = 0;
51
-
52
  /**
53
  * If this string is not empty AND the serve() option 'bubbleCssImports' is
54
  * NOT set, then serve() will check CSS files for @import declarations that
@@ -58,107 +58,99 @@ class Minify {
58
  * @var string $importWarning
59
  */
60
  public static $importWarning = "/* See http://code.google.com/p/minify/wiki/CommonProblems#@imports_can_appear_in_invalid_locations_in_combined_CSS_files */\n";
61
-
62
  /**
63
  * Cache ID
64
  * @var string
65
  */
66
  protected static $_cacheId = null;
67
-
68
  /**
69
  * Specify a cache object (with identical interface as Minify_Cache_File) or
70
  * a path to use with Minify_Cache_File.
71
- *
72
- * If not called, Minify will not use a cache and, for each 200 response, will
73
  * need to recombine files, minify and encode the output.
74
  *
75
  * @param mixed $cache object with identical interface as Minify_Cache_File or
76
  * a directory path, or null to disable caching. (default = '')
77
- *
78
- * @param bool $fileLocking (default = true) This only applies if the first
79
- * parameter is a string.
80
  *
81
  * @return null
82
  */
83
- public static function setCache($cache = '', $fileLocking = true)
84
  {
85
- if (is_string($cache)) {
86
- require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/File.php';
87
- self::$_cache = new Minify_Cache_File($cache, $fileLocking);
88
- } else {
89
- self::$_cache = $cache;
90
- }
91
  }
92
-
93
  /**
94
- * Serve a request for a minified file.
95
- *
96
  * Here are the available options and defaults in the base controller:
97
- *
98
- * 'isPublic' : send "public" instead of "private" in Cache-Control
99
  * headers, allowing shared caches to cache the output. (default true)
100
- *
101
  * 'quiet' : set to true to have serve() return an array rather than sending
102
  * any headers/output (default false)
103
- *
104
  * 'encodeOutput' : set to false to disable content encoding, and not send
105
  * the Vary header (default true)
106
- *
107
- * 'encodeMethod' : generally you should let this be determined by
108
  * HTTP_Encoder (leave null), but you can force a particular encoding
109
  * to be returned, by setting this to 'gzip' or '' (no encoding)
110
- *
111
  * 'encodeLevel' : level of encoding compression (0 to 9, default 9)
112
- *
113
  * 'contentTypeCharset' : appended to the Content-Type header sent. Set to a falsey
114
- * value to remove. (default 'utf-8')
115
- *
116
  * 'maxAge' : set this to the number of seconds the client should use its cache
117
  * before revalidating with the server. This sets Cache-Control: max-age and the
118
  * Expires header. Unlike the old 'setExpires' setting, this setting will NOT
119
  * prevent conditional GETs. Note this has nothing to do with server-side caching.
120
- *
121
  * 'rewriteCssUris' : If true, serve() will automatically set the 'currentDir'
122
  * minifier option to enable URI rewriting in CSS files (default true)
123
- *
124
  * 'bubbleCssImports' : If true, all @import declarations in combined CSS
125
  * files will be move to the top. Note this may alter effective CSS values
126
  * due to a change in order. (default false)
127
- *
128
  * 'debug' : set to true to minify all sources with the 'Lines' controller, which
129
  * eases the debugging of combined files. This also prevents 304 responses.
130
  * @see Minify_Lines::minify()
131
- *
132
- * 'minifiers' : to override Minify's default choice of minifier function for
133
- * a particular content-type, specify your callback under the key of the
134
  * content-type:
135
  * <code>
136
  * // call customCssMinifier($css) for all CSS minification
137
  * $options['minifiers'][Minify::TYPE_CSS] = 'customCssMinifier';
138
- *
139
  * // don't minify Javascript at all
140
  * $options['minifiers'][Minify::TYPE_JS] = '';
141
  * </code>
142
- *
143
  * 'minifierOptions' : to send options to the minifier function, specify your options
144
- * under the key of the content-type. E.g. To send the CSS minifier an option:
145
  * <code>
146
- * // give CSS minifier array('optionName' => 'optionValue') as 2nd argument
147
  * $options['minifierOptions'][Minify::TYPE_CSS]['optionName'] = 'optionValue';
148
  * </code>
149
- *
150
- * 'contentType' : (optional) this is only needed if your file extension is not
151
  * js/css/html. The given content-type will be sent regardless of source file
152
  * extension, so this should not be used in a Groups config with other
153
  * Javascript/CSS files.
154
- *
155
  * Any controller options are documented in that controller's setupSources() method.
156
- *
157
  * @param mixed instance of subclass of Minify_Controller_Base or string name of
158
  * controller. E.g. 'Files'
159
- *
160
  * @param array $options controller/serve options
161
- *
162
  * @return mixed null, or, if the 'quiet' option is set to true, an array
163
  * with keys "success" (bool), "statusCode" (int), "content" (string), and
164
  * "headers" (array).
@@ -169,18 +161,18 @@ class Minify {
169
  // make $controller into object
170
  $class = 'Minify_Controller_' . $controller;
171
  if (! class_exists($class, false)) {
172
- require_once W3TC_LIB_MINIFY_DIR . "/Minify/Controller/"
173
- . str_replace('_', '/', $controller) . ".php";
174
  }
175
  $controller = new $class();
176
  }
177
-
178
  // set up controller sources and mix remaining options with
179
  // controller defaults
180
  $options = $controller->setupSources($options);
181
  $options = $controller->analyzeSources($options);
182
  self::$_options = $controller->mixInDefaultOptions($options);
183
-
184
  // check request validity
185
  if (! $controller->sources) {
186
  // invalid request!
@@ -198,14 +190,14 @@ class Minify {
198
  );
199
  }
200
  }
201
-
202
  self::$_controller = $controller;
203
-
204
  if (self::$_options['debug']) {
205
  self::_setupDebug($controller->sources);
206
  self::$_options['maxAge'] = 0;
207
  }
208
-
209
  // determine encoding
210
  if (self::$_options['encodeOutput']) {
211
  if (self::$_options['encodeMethod'] !== null) {
@@ -214,7 +206,7 @@ class Minify {
214
  } else {
215
  // sniff request header
216
  require_once W3TC_LIB_MINIFY_DIR . '/HTTP/Encoder.php';
217
- // depending on what the client accepts, $contentEncoding may be
218
  // 'x-gzip' while our internal encodeMethod is 'gzip'. Calling
219
  // getAcceptedEncoding(false, false) leaves out compress and deflate as options.
220
  list(self::$_options['encodeMethod'], $contentEncoding) = HTTP_Encoder::getAcceptedEncoding(self::$_options['encodeOutput']);
@@ -222,7 +214,7 @@ class Minify {
222
  } else {
223
  self::$_options['encodeMethod'] = ''; // identity (no encoding)
224
  }
225
-
226
  // check client cache
227
  require_once W3TC_LIB_MINIFY_DIR . '/HTTP/ConditionalGet.php';
228
  $cgOptions = array(
@@ -253,7 +245,7 @@ class Minify {
253
  $headers = $cg->getHeaders();
254
  unset($cg);
255
  }
256
-
257
  if (self::$_options['contentType'] === self::TYPE_CSS) {
258
  reset($controller->sources);
259
  while (list($key, $source) = each($controller->sources)) {
@@ -268,11 +260,11 @@ class Minify {
268
  $source->minifyOptions['processCssImports'] = self::$_options['processCssImports'];
269
  }
270
  }
271
-
272
  // check server cache
273
  if (null !== self::$_cache) {
274
  // using cache
275
- // the goal is to use only the cache methods to sniff the length and
276
  // output the content, as they do not require ever loading the file into
277
  // memory.
278
  $cacheId = self::_getCacheId();
@@ -280,14 +272,14 @@ class Minify {
280
  ? $cacheId . '.' . self::$_options['encodeMethod']
281
  : $cacheId;
282
  // check cache for valid entry
283
- $cacheIsReady = self::$_cache->isValid($fullCacheId, self::$_options['lastModifiedTime']);
284
  if ($cacheIsReady) {
285
- $cacheContentLength = self::$_cache->getSize($fullCacheId);
286
  } else {
287
  // generate & cache content
288
  $content = self::_combineMinify();
289
  self::$_cache->store($cacheId, $content);
290
-
291
  if (self::$_options['encodeOutput'] && function_exists('gzencode')) {
292
  self::$_cache->store($cacheId . '.' . self::$_options['encodeMethod'], gzencode($content, self::$_options['encodeLevel']));
293
  }
@@ -302,14 +294,14 @@ class Minify {
302
  case 'gzip':
303
  $content = gzencode($content, self::$_options['encodeLevel']);
304
  break;
305
-
306
  case 'deflate':
307
  $content = gzdeflate($content, self::$_options['encodeLevel']);
308
  break;
309
  }
310
  // still need to encode
311
  }
312
-
313
  // add headers
314
  $headers['Content-Length'] = $cacheIsReady
315
  ? $cacheContentLength
@@ -345,17 +337,17 @@ class Minify {
345
  );
346
  }
347
  }
348
-
349
  /**
350
  * Return combined minified content for a set of sources
351
  *
352
  * No internal caching will be used and the content will not be HTTP encoded.
353
- *
354
  * @param array $sources array of filepaths and/or Minify_Source objects
355
- *
356
  * @param array $options (optional) array of options for serve. By default
357
  * these are already set: quiet = true, encodeMethod = '', lastModifiedTime = 0.
358
- *
359
  * @return string
360
  */
361
  public static function combine($sources, $options = array())
@@ -372,13 +364,13 @@ class Minify {
372
  self::$_cache = $cache;
373
  return $out['content'];
374
  }
375
-
376
  /**
377
  * On IIS, create $_SERVER['DOCUMENT_ROOT']
378
- *
379
  * @param bool $unsetPathInfo (default false) if true, $_SERVER['PATH_INFO']
380
  * will be unset (it is inconsistent with Apache's setting)
381
- *
382
  * @return null
383
  */
384
  public static function setDocRoot($unsetPathInfo = false)
@@ -386,8 +378,8 @@ class Minify {
386
  if (isset($_SERVER['SERVER_SOFTWARE'])
387
  && 0 === strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/')
388
  ) {
389
- $_SERVER['PATH_TRANSLATED']= preg_replace('~[/\\\]+~', '/', $_SERVER['PATH_TRANSLATED']);
390
-
391
  $_SERVER['DOCUMENT_ROOT'] = rtrim(substr(
392
  $_SERVER['PATH_TRANSLATED']
393
  ,0
@@ -400,22 +392,22 @@ class Minify {
400
  Minify_Logger::log("setDocRoot() set DOCUMENT_ROOT to \"{$_SERVER['DOCUMENT_ROOT']}\"");
401
  }
402
  }
403
-
404
  /**
405
  * @var mixed Minify_Cache_* object or null (i.e. no server cache is used)
406
  */
407
  private static $_cache = null;
408
-
409
  /**
410
  * @var Minify_Controller active controller for current request
411
  */
412
  protected static $_controller = null;
413
-
414
  /**
415
  * @var array options for current request
416
  */
417
  protected static $_options = null;
418
-
419
  /**
420
  * Set up sources to use Minify_Lines
421
  *
@@ -433,7 +425,7 @@ class Minify {
433
  );
434
  }
435
  }
436
-
437
  /**
438
  * Combines sources and minifies the result.
439
  *
@@ -442,7 +434,7 @@ class Minify {
442
  protected static function _combineMinify()
443
  {
444
  $type = self::$_options['contentType']; // ease readability
445
-
446
  // when combining scripts, make sure all statements separated and
447
  // trailing single line comment is terminated
448
  $implodeSeparator = ($type === self::TYPE_JS)
@@ -459,7 +451,7 @@ class Minify {
459
  $defaultMinifier = isset(self::$_options['minifiers'][$type])
460
  ? self::$_options['minifiers'][$type]
461
  : false;
462
-
463
  if (Minify_Source::haveNoMinifyPrefs(self::$_controller->sources)) {
464
  // all source have same options/minifier, better performance
465
  // to combine, then minify once
@@ -469,7 +461,7 @@ class Minify {
469
  $content = implode($implodeSeparator, $pieces);
470
  if ($defaultMinifier) {
471
  self::$_controller->loadMinifier($defaultMinifier);
472
- $content = call_user_func($defaultMinifier, $content, $defaultOptions);
473
  }
474
  } else {
475
  // minify each source with its own options and minifier, then combine
@@ -484,18 +476,18 @@ class Minify {
484
  if ($minifier) {
485
  self::$_controller->loadMinifier($minifier);
486
  // get source content and minify it
487
- $pieces[] = call_user_func($minifier, $source->getContent(), $options);
488
  } else {
489
- $pieces[] = $source->getContent();
490
  }
491
  }
492
  $content = implode($implodeSeparator, $pieces);
493
  }
494
-
495
  if ($type === self::TYPE_CSS && false !== strpos($content, '@import')) {
496
  $content = self::_handleCssImports($content);
497
  }
498
-
499
  // do any post-processing (esp. for editing build URIs)
500
  if (self::$_options['postprocessorRequire']) {
501
  require_once self::$_options['postprocessorRequire'];
@@ -505,7 +497,7 @@ class Minify {
505
  }
506
  return $content;
507
  }
508
-
509
  /**
510
  * Sets cache ID
511
  * @param string $cacheId
@@ -514,7 +506,7 @@ class Minify {
514
  {
515
  self::$_cacheId = $cacheId;
516
  }
517
-
518
  /**
519
  * Returns cache ID
520
  */
@@ -522,11 +514,11 @@ class Minify {
522
  {
523
  return self::$_cacheId;
524
  }
525
-
526
  /**
527
  * Make a unique cache id for for this request.
528
- *
529
- * Any settings that could affect output are taken into consideration
530
  *
531
  * @return string
532
  */
@@ -534,14 +526,14 @@ class Minify {
534
  {
535
  return (self::$_cacheId ? self::$_cacheId : md5(serialize(array(
536
  Minify_Source::getDigest(self::$_controller->sources)
537
- ,self::$_options['minifiers']
538
  ,self::$_options['minifierOptions']
539
  ,self::$_options['postprocessor']
540
  ,self::$_options['bubbleCssImports']
541
  ,self::$_options['processCssImports']
542
  ))));
543
  }
544
-
545
  /**
546
  * Bubble CSS @imports to the top or prepend a warning if an
547
  * @import is detected not at the top.
1
  <?php
2
  /**
3
+ * Class Minify
4
  * @package Minify
5
  */
6
 
8
  * Minify_Source
9
  */
10
  require_once W3TC_LIB_MINIFY_DIR . '/Minify/Source.php';
11
+
12
  /**
13
  * Minify - Combines, minifies, and caches JavaScript and CSS files on demand.
14
  *
28
  * @link http://code.google.com/p/minify/
29
  */
30
  class Minify {
31
+
32
  const VERSION = '2.1.3';
33
  const TYPE_CSS = 'text/css';
34
  const TYPE_HTML = 'text/html';
35
  // there is some debate over the ideal JS Content-Type, but this is the
36
  // Apache default and what Yahoo! uses..
37
  const TYPE_JS = 'application/x-javascript';
38
+
39
  /**
40
  * How many hours behind are the file modification times of uploaded files?
41
+ *
42
  * If you upload files from Windows to a non-Windows server, Windows may report
43
+ * incorrect mtimes for the files. Immediately after modifying and uploading a
44
+ * file, use the touch command to update the mtime on the server. If the mtime
45
+ * jumps ahead by a number of hours, set this variable to that number. If the mtime
46
  * moves back, this should not be needed.
47
  *
48
  * @var int $uploaderHoursBehind
49
  */
50
  public static $uploaderHoursBehind = 0;
51
+
52
  /**
53
  * If this string is not empty AND the serve() option 'bubbleCssImports' is
54
  * NOT set, then serve() will check CSS files for @import declarations that
58
  * @var string $importWarning
59
  */
60
  public static $importWarning = "/* See http://code.google.com/p/minify/wiki/CommonProblems#@imports_can_appear_in_invalid_locations_in_combined_CSS_files */\n";
61
+
62
  /**
63
  * Cache ID
64
  * @var string
65
  */
66
  protected static $_cacheId = null;
67
+
68
  /**
69
  * Specify a cache object (with identical interface as Minify_Cache_File) or
70
  * a path to use with Minify_Cache_File.
71
+ *
72
+ * If not called, Minify will not use a cache and, for each 200 response, will
73
  * need to recombine files, minify and encode the output.
74
  *
75
  * @param mixed $cache object with identical interface as Minify_Cache_File or
76
  * a directory path, or null to disable caching. (default = '')
 
 
 
77
  *
78
  * @return null
79
  */
80
+ public static function setCache($cache)
81
  {
82
+ self::$_cache = $cache;
 
 
 
 
 
83
  }
84
+
85
  /**
86
+ * Serve a request for a minified file.
87
+ *
88
  * Here are the available options and defaults in the base controller:
89
+ *
90
+ * 'isPublic' : send "public" instead of "private" in Cache-Control
91
  * headers, allowing shared caches to cache the output. (default true)
92
+ *
93
  * 'quiet' : set to true to have serve() return an array rather than sending
94
  * any headers/output (default false)
95
+ *
96
  * 'encodeOutput' : set to false to disable content encoding, and not send
97
  * the Vary header (default true)
98
+ *
99
+ * 'encodeMethod' : generally you should let this be determined by
100
  * HTTP_Encoder (leave null), but you can force a particular encoding
101
  * to be returned, by setting this to 'gzip' or '' (no encoding)
102
+ *
103
  * 'encodeLevel' : level of encoding compression (0 to 9, default 9)
104
+ *
105
  * 'contentTypeCharset' : appended to the Content-Type header sent. Set to a falsey
106
+ * value to remove. (default 'utf-8')
107
+ *
108
  * 'maxAge' : set this to the number of seconds the client should use its cache
109
  * before revalidating with the server. This sets Cache-Control: max-age and the
110
  * Expires header. Unlike the old 'setExpires' setting, this setting will NOT
111
  * prevent conditional GETs. Note this has nothing to do with server-side caching.
112
+ *
113
  * 'rewriteCssUris' : If true, serve() will automatically set the 'currentDir'
114
  * minifier option to enable URI rewriting in CSS files (default true)
115
+ *
116
  * 'bubbleCssImports' : If true, all @import declarations in combined CSS
117
  * files will be move to the top. Note this may alter effective CSS values
118
  * due to a change in order. (default false)
119
+ *
120
  * 'debug' : set to true to minify all sources with the 'Lines' controller, which
121
  * eases the debugging of combined files. This also prevents 304 responses.
122
  * @see Minify_Lines::minify()
123
+ *
124
+ * 'minifiers' : to override Minify's default choice of minifier function for
125
+ * a particular content-type, specify your callback under the key of the
126
  * content-type:
127
  * <code>
128
  * // call customCssMinifier($css) for all CSS minification
129
  * $options['minifiers'][Minify::TYPE_CSS] = 'customCssMinifier';
130
+ *
131
  * // don't minify Javascript at all
132
  * $options['minifiers'][Minify::TYPE_JS] = '';
133
  * </code>
134
+ *
135
  * 'minifierOptions' : to send options to the minifier function, specify your options
136
+ * under the key of the content-type. E.g. To send the CSS minifier an option:
137
  * <code>
138
+ * // give CSS minifier array('optionName' => 'optionValue') as 2nd argument
139
  * $options['minifierOptions'][Minify::TYPE_CSS]['optionName'] = 'optionValue';
140
  * </code>
141
+ *
142
+ * 'contentType' : (optional) this is only needed if your file extension is not
143
  * js/css/html. The given content-type will be sent regardless of source file
144
  * extension, so this should not be used in a Groups config with other
145
  * Javascript/CSS files.
146
+ *
147
  * Any controller options are documented in that controller's setupSources() method.
148
+ *
149
  * @param mixed instance of subclass of Minify_Controller_Base or string name of
150
  * controller. E.g. 'Files'
151
+ *
152
  * @param array $options controller/serve options
153
+ *
154
  * @return mixed null, or, if the 'quiet' option is set to true, an array
155
  * with keys "success" (bool), "statusCode" (int), "content" (string), and
156
  * "headers" (array).
161
  // make $controller into object
162
  $class = 'Minify_Controller_' . $controller;
163
  if (! class_exists($class, false)) {
164
+ require_once W3TC_LIB_MINIFY_DIR . "/Minify/Controller/"
165
+ . str_replace('_', '/', $controller) . ".php";
166
  }
167
  $controller = new $class();
168
  }
169
+
170
  // set up controller sources and mix remaining options with
171
  // controller defaults
172
  $options = $controller->setupSources($options);
173
  $options = $controller->analyzeSources($options);
174
  self::$_options = $controller->mixInDefaultOptions($options);
175
+
176
  // check request validity
177
  if (! $controller->sources) {
178
  // invalid request!
190
  );
191
  }
192
  }
193
+
194
  self::$_controller = $controller;
195
+
196
  if (self::$_options['debug']) {
197
  self::_setupDebug($controller->sources);
198
  self::$_options['maxAge'] = 0;
199
  }
200
+
201
  // determine encoding
202
  if (self::$_options['encodeOutput']) {
203
  if (self::$_options['encodeMethod'] !== null) {
206
  } else {
207
  // sniff request header
208
  require_once W3TC_LIB_MINIFY_DIR . '/HTTP/Encoder.php';
209
+ // depending on what the client accepts, $contentEncoding may be
210
  // 'x-gzip' while our internal encodeMethod is 'gzip'. Calling
211
  // getAcceptedEncoding(false, false) leaves out compress and deflate as options.
212
  list(self::$_options['encodeMethod'], $contentEncoding) = HTTP_Encoder::getAcceptedEncoding(self::$_options['encodeOutput']);
214
  } else {
215
  self::$_options['encodeMethod'] = ''; // identity (no encoding)
216
  }
217
+
218
  // check client cache
219
  require_once W3TC_LIB_MINIFY_DIR . '/HTTP/ConditionalGet.php';
220
  $cgOptions = array(
245
  $headers = $cg->getHeaders();
246
  unset($cg);
247
  }
248
+
249
  if (self::$_options['contentType'] === self::TYPE_CSS) {
250
  reset($controller->sources);
251
  while (list($key, $source) = each($controller->sources)) {
260
  $source->minifyOptions['processCssImports'] = self::$_options['processCssImports'];
261
  }
262
  }
263
+
264
  // check server cache
265
  if (null !== self::$_cache) {
266
  // using cache
267
+ // the goal is to use only the cache methods to sniff the length and
268
  // output the content, as they do not require ever loading the file into
269
  // memory.
270
  $cacheId = self::_getCacheId();
272
  ? $cacheId . '.' . self::$_options['encodeMethod']
273
  : $cacheId;
274
  // check cache for valid entry
275
+ $cacheIsReady = self::$_cache->isValid($fullCacheId, self::$_options['lastModifiedTime']);
276
  if ($cacheIsReady) {
277
+ $cacheContentLength = self::$_cache->getSize($fullCacheId);
278
  } else {
279
  // generate & cache content
280
  $content = self::_combineMinify();
281
  self::$_cache->store($cacheId, $content);
282
+
283
  if (self::$_options['encodeOutput'] && function_exists('gzencode')) {
284
  self::$_cache->store($cacheId . '.' . self::$_options['encodeMethod'], gzencode($content, self::$_options['encodeLevel']));
285
  }
294
  case 'gzip':
295
  $content = gzencode($content, self::$_options['encodeLevel']);
296
  break;
297
+
298
  case 'deflate':
299
  $content = gzdeflate($content, self::$_options['encodeLevel']);
300
  break;
301
  }
302
  // still need to encode
303
  }
304
+
305
  // add headers
306
  $headers['Content-Length'] = $cacheIsReady
307
  ? $cacheContentLength
337
  );
338
  }
339
  }
340
+
341
  /**
342
  * Return combined minified content for a set of sources
343
  *
344
  * No internal caching will be used and the content will not be HTTP encoded.
345
+ *
346
  * @param array $sources array of filepaths and/or Minify_Source objects
347
+ *
348
  * @param array $options (optional) array of options for serve. By default
349
  * these are already set: quiet = true, encodeMethod = '', lastModifiedTime = 0.
350
+ *
351
  * @return string
352
  */
353
  public static function combine($sources, $options = array())
364
  self::$_cache = $cache;
365
  return $out['content'];
366
  }
367
+
368
  /**
369
  * On IIS, create $_SERVER['DOCUMENT_ROOT']
370
+ *
371
  * @param bool $unsetPathInfo (default false) if true, $_SERVER['PATH_INFO']
372
  * will be unset (it is inconsistent with Apache's setting)
373
+ *
374
  * @return null
375
  */
376
  public static function setDocRoot($unsetPathInfo = false)
378
  if (isset($_SERVER['SERVER_SOFTWARE'])
379
  && 0 === strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/')
380
  ) {
381
+ $_SERVER['PATH_TRANSLATED']= preg_replace('~[/\\\]+~', '/', $_SERVER['PATH_TRANSLATED']);
382
+
383
  $_SERVER['DOCUMENT_ROOT'] = rtrim(substr(
384
  $_SERVER['PATH_TRANSLATED']
385
  ,0
392
  Minify_Logger::log("setDocRoot() set DOCUMENT_ROOT to \"{$_SERVER['DOCUMENT_ROOT']}\"");
393
  }
394
  }
395
+
396
  /**
397
  * @var mixed Minify_Cache_* object or null (i.e. no server cache is used)
398
  */
399
  private static $_cache = null;
400
+
401
  /**
402
  * @var Minify_Controller active controller for current request
403
  */
404
  protected static $_controller = null;
405
+
406
  /**
407
  * @var array options for current request
408
  */
409
  protected static $_options = null;
410
+
411
  /**
412
  * Set up sources to use Minify_Lines
413
  *
425
  );
426
  }
427
  }
428
+
429
  /**
430
  * Combines sources and minifies the result.
431
  *
434
  protected static function _combineMinify()
435
  {
436
  $type = self::$_options['contentType']; // ease readability
437
+
438
  // when combining scripts, make sure all statements separated and
439
  // trailing single line comment is terminated
440
  $implodeSeparator = ($type === self::TYPE_JS)
451
  $defaultMinifier = isset(self::$_options['minifiers'][$type])
452
  ? self::$_options['minifiers'][$type]
453
  : false;
454
+
455
  if (Minify_Source::haveNoMinifyPrefs(self::$_controller->sources)) {
456
  // all source have same options/minifier, better performance
457
  // to combine, then minify once
461
  $content = implode($implodeSeparator, $pieces);
462
  if ($defaultMinifier) {
463
  self::$_controller->loadMinifier($defaultMinifier);
464
+ $content = call_user_func($defaultMinifier, $content, $defaultOptions);
465
  }
466
  } else {
467
  // minify each source with its own options and minifier, then combine
476
  if ($minifier) {
477
  self::$_controller->loadMinifier($minifier);
478
  // get source content and minify it
479
+ $pieces[] = call_user_func($minifier, $source->getContent(), $options);
480
  } else {
481
+ $pieces[] = $source->getContent();
482
  }
483
  }
484
  $content = implode($implodeSeparator, $pieces);
485
  }
486
+
487
  if ($type === self::TYPE_CSS && false !== strpos($content, '@import')) {
488
  $content = self::_handleCssImports($content);
489
  }
490
+
491
  // do any post-processing (esp. for editing build URIs)
492
  if (self::$_options['postprocessorRequire']) {
493
  require_once self::$_options['postprocessorRequire'];
497
  }
498
  return $content;
499
  }
500
+
501
  /**
502
  * Sets cache ID
503
  * @param string $cacheId
506
  {
507
  self::$_cacheId = $cacheId;
508
  }
509
+
510
  /**
511
  * Returns cache ID
512
  */
514
  {
515
  return self::$_cacheId;
516
  }
517
+
518
  /**
519
  * Make a unique cache id for for this request.
520
+ *
521
+ * Any settings that could affect output are taken into consideration
522
  *
523
  * @return string
524
  */
526
  {
527
  return (self::$_cacheId ? self::$_cacheId : md5(serialize(array(
528
  Minify_Source::getDigest(self::$_controller->sources)
529
+ ,self::$_options['minifiers']
530
  ,self::$_options['minifierOptions']
531
  ,self::$_options['postprocessor']
532
  ,self::$_options['bubbleCssImports']
533
  ,self::$_options['processCssImports']
534
  ))));
535
  }
536
+
537
  /**
538
  * Bubble CSS @imports to the top or prepend a warning if an
539
  * @import is detected not at the top.
lib/Minify/Minify/CSS/UriRewriter.php CHANGED
@@ -211,7 +211,7 @@ class Minify_CSS_UriRewriter {
211
  $query = (isset($matches[2]) ? $matches[2] : '');
212
 
213
  if ($extension && in_array($extension, self::$_browserCacheExtensions)) {
214
- $uri = w3_remove_wp_query($uri);
215
  $uri .= ($query ? '&' : '?') . self::$_browserCacheId;
216
  }
217
  }
211
  $query = (isset($matches[2]) ? $matches[2] : '');
212
 
213
  if ($extension && in_array($extension, self::$_browserCacheExtensions)) {
214
+ $uri = w3_remove_query($uri);
215
  $uri .= ($query ? '&' : '?') . self::$_browserCacheId;
216
  }
217
  }
lib/Minify/Minify/Cache/File.php CHANGED
@@ -6,14 +6,16 @@
6
 
7
  class Minify_Cache_File {
8
 
9
- public function __construct($path = '', $fileLocking = false) {
10
  if (!$path) {
11
  require_once W3TC_LIB_MINIFY_DIR . '/Solar/Dir.php';
12
  $path = rtrim(Solar_Dir::tmp(), DIRECTORY_SEPARATOR);
13
  }
14
 
15
- $this->_locking = $fileLocking;
16
  $this->_path = $path;
 
 
 
17
  }
18
 
19
  /**
@@ -145,10 +147,9 @@ class Minify_Cache_File {
145
  * @return bool
146
  */
147
  public function flush() {
148
- return w3_emptydir(W3TC_CACHE_FILE_MINIFY_DIR, array(
149
- W3TC_CACHE_FILE_MINIFY_DIR . '/index.php',
150
- W3TC_CACHE_FILE_MINIFY_DIR . '/.htaccess'
151
- ));
152
  }
153
 
154
  /**
@@ -161,5 +162,7 @@ class Minify_Cache_File {
161
  }
162
 
163
  private $_path = null;
 
164
  private $_locking = null;
 
165
  }
6
 
7
  class Minify_Cache_File {
8
 
9
+ public function __construct($path = '', $exclude = array(), $locking = false, $flushTimeLimit = 0) {
10
  if (!$path) {
11
  require_once W3TC_LIB_MINIFY_DIR . '/Solar/Dir.php';
12
  $path = rtrim(Solar_Dir::tmp(), DIRECTORY_SEPARATOR);
13
  }
14
 
 
15
  $this->_path = $path;
16
+ $this->_exclude = $exclude;
17
+ $this->_locking = $locking;
18
+ $this->_flushTimeLimit = $flushTimeLimit;
19
  }
20
 
21
  /**
147
  * @return bool
148
  */
149
  public function flush() {
150
+ @set_time_limit($this->_flushTimeLimit);
151
+
152
+ return w3_emptydir($this->_path, $this->_exclude);
 
153
  }
154
 
155
  /**
162
  }
163
 
164
  private $_path = null;
165
+ private $_exclude = null;
166
  private $_locking = null;
167
+ private $_flushTimeLimit = null;
168
  }
lib/Minify/Minify/Controller/Files.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Class Minify_Controller_Files
4
  * @package Minify
5
  */
6
 
@@ -8,7 +8,7 @@ require_once W3TC_LIB_MINIFY_DIR . '/Minify/Controller/Base.php';
8
 
9
  /**
10
  * Controller class for minifying a set of files
11
- *
12
  * E.g. the following would serve the minified Javascript for a site
13
  * <code>
14
  * Minify::serve('Files', array(
@@ -19,7 +19,7 @@ require_once W3TC_LIB_MINIFY_DIR . '/Minify/Controller/Base.php';
19
  * )
20
  * ));
21
  * </code>
22
- *
23
  * As a shortcut, the controller will replace "//" at the beginning
24
  * of a filename with $_SERVER['DOCUMENT_ROOT'] . '/'.
25
  *
@@ -27,20 +27,20 @@ require_once W3TC_LIB_MINIFY_DIR . '/Minify/Controller/Base.php';
27
  * @author Stephen Clay <steve@mrclay.org>
28
  */
29
  class Minify_Controller_Files extends Minify_Controller_Base {
30
-
31
  /**
32
  * Set up file sources
33
- *
34
  * @param array $options controller and Minify options
35
  * @return array Minify options
36
- *
37
  * Controller options:
38
- *
39
  * 'files': (required) array of complete file paths, or a single path
40
  */
41
  public function setupSources($options) {
42
  // strip controller options
43
-
44
  $files = $options['files'];
45
  // if $files is a single object, casting will break it
46
  if (is_object($files)) {
@@ -49,7 +49,7 @@ class Minify_Controller_Files extends Minify_Controller_Base {
49
  $files = (array)$files;
50
  }
51
  unset($options['files']);
52
-
53
  $sources = array();
54
  foreach ($files as $file) {
55
  if ($file instanceof Minify_Source) {
@@ -63,9 +63,9 @@ class Minify_Controller_Files extends Minify_Controller_Base {
63
  if (is_file($realPath)) {
64
  $sources[] = new Minify_Source(array(
65
  'filepath' => $realPath
66
- ));
67
  } else {
68
- $this->log("The path \"{$file}\" could not be found (or was not a file)");
69
  return $options;
70
  }
71
  }
1
  <?php
2
  /**
3
+ * Class Minify_Controller_Files
4
  * @package Minify
5
  */
6
 
8
 
9
  /**
10
  * Controller class for minifying a set of files
11
+ *
12
  * E.g. the following would serve the minified Javascript for a site
13
  * <code>
14
  * Minify::serve('Files', array(
19
  * )
20
  * ));
21
  * </code>
22
+ *
23
  * As a shortcut, the controller will replace "//" at the beginning
24
  * of a filename with $_SERVER['DOCUMENT_ROOT'] . '/'.
25
  *
27
  * @author Stephen Clay <steve@mrclay.org>
28
  */
29
  class Minify_Controller_Files extends Minify_Controller_Base {
30
+
31
  /**
32
  * Set up file sources
33
+ *
34
  * @param array $options controller and Minify options
35
  * @return array Minify options
36
+ *
37
  * Controller options:
38
+ *
39
  * 'files': (required) array of complete file paths, or a single path
40
  */
41
  public function setupSources($options) {
42
  // strip controller options
43
+
44
  $files = $options['files'];
45
  // if $files is a single object, casting will break it
46
  if (is_object($files)) {
49
  $files = (array)$files;
50
  }
51
  unset($options['files']);
52
+
53
  $sources = array();
54
  foreach ($files as $file) {
55
  if ($file instanceof Minify_Source) {
63
  if (is_file($realPath)) {
64
  $sources[] = new Minify_Source(array(
65
  'filepath' => $realPath
66
+ ));
67
  } else {
68
+ $this->log("The path \"{$realPath}\" could not be found (or was not a file)");
69
  return $options;
70
  }
71
  }
lib/Minify/Minify/Controller/Groups.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Class Minify_Controller_Groups
4
  * @package Minify
5
  */
6
 
@@ -9,48 +9,48 @@ require_once W3TC_LIB_MINIFY_DIR . '/Minify/Controller/Base.php';
9
  /**
10
  * Controller class for serving predetermined groups of minimized sets, selected
11
  * by PATH_INFO
12
- *
13
  * <code>
14
- * Minify::serve('Groups', array(
15
  * 'groups' => array(
16
  * 'css' => array('//css/type.css', '//css/layout.css')
17
  * ,'js' => array('//js/jquery.js', '//js/site.js')
18
  * )
19
  * ));
20
  * </code>
21
- *
22
  * If the above code were placed in /serve.php, it would enable the URLs
23
  * /serve.php/js and /serve.php/css
24
- *
25
  * As a shortcut, the controller will replace "//" at the beginning
26
  * of a filename with $_SERVER['DOCUMENT_ROOT'] . '/'.
27
- *
28
  * @package Minify
29
  * @author Stephen Clay <steve@mrclay.org>
30
  */
31
  class Minify_Controller_Groups extends Minify_Controller_Base {
32
-
33
  /**
34
  * Set up groups of files as sources
35
- *
36
  * @param array $options controller and Minify options
37
  * @return array Minify options
38
- *
39
  * Controller options:
40
- *
41
  * 'groups': (required) array mapping PATH_INFO strings to arrays
42
- * of complete file paths. @see Minify_Controller_Groups
43
  */
44
  public function setupSources($options) {
45
  // strip controller options
46
  $groups = $options['groups'];
47
  unset($options['groups']);
48
-
49
  // mod_fcgid places PATH_INFO in ORIG_PATH_INFO
50
  $pi = isset($_SERVER['ORIG_PATH_INFO'])
51
- ? substr($_SERVER['ORIG_PATH_INFO'], 1)
52
  : (isset($_SERVER['PATH_INFO'])
53
- ? substr($_SERVER['PATH_INFO'], 1)
54
  : false
55
  );
56
  if (false === $pi || ! isset($groups[$pi])) {
@@ -59,7 +59,7 @@ class Minify_Controller_Groups extends Minify_Controller_Base {
59
  return $options;
60
  }
61
  $sources = array();
62
-
63
  $files = $groups[$pi];
64
  // if $files is a single object, casting will break it
65
  if (is_object($files)) {
@@ -79,9 +79,9 @@ class Minify_Controller_Groups extends Minify_Controller_Base {
79
  if (is_file($realPath)) {
80
  $sources[] = new Minify_Source(array(
81
  'filepath' => $realPath
82
- ));
83
  } else {
84
- $this->log("The path \"{$file}\" could not be found (or was not a file)");
85
  return $options;
86
  }
87
  }
1
  <?php
2
  /**
3
+ * Class Minify_Controller_Groups
4
  * @package Minify
5
  */
6
 
9
  /**
10
  * Controller class for serving predetermined groups of minimized sets, selected
11
  * by PATH_INFO
12
+ *
13
  * <code>
14
+ * Minify::serve('Groups', array(
15
  * 'groups' => array(
16
  * 'css' => array('//css/type.css', '//css/layout.css')
17
  * ,'js' => array('//js/jquery.js', '//js/site.js')
18
  * )
19
  * ));
20
  * </code>
21
+ *
22
  * If the above code were placed in /serve.php, it would enable the URLs
23
  * /serve.php/js and /serve.php/css
24
+ *
25
  * As a shortcut, the controller will replace "//" at the beginning
26
  * of a filename with $_SERVER['DOCUMENT_ROOT'] . '/'.
27
+ *
28
  * @package Minify
29
  * @author Stephen Clay <steve@mrclay.org>
30
  */
31
  class Minify_Controller_Groups extends Minify_Controller_Base {
32
+
33
  /**
34
  * Set up groups of files as sources
35
+ *
36
  * @param array $options controller and Minify options
37
  * @return array Minify options
38
+ *
39
  * Controller options:
40
+ *
41
  * 'groups': (required) array mapping PATH_INFO strings to arrays
42
+ * of complete file paths. @see Minify_Controller_Groups
43
  */
44
  public function setupSources($options) {
45
  // strip controller options
46
  $groups = $options['groups'];
47
  unset($options['groups']);
48
+
49
  // mod_fcgid places PATH_INFO in ORIG_PATH_INFO
50
  $pi = isset($_SERVER['ORIG_PATH_INFO'])
51
+ ? substr($_SERVER['ORIG_PATH_INFO'], 1)
52
  : (isset($_SERVER['PATH_INFO'])
53
+ ? substr($_SERVER['PATH_INFO'], 1)
54
  : false
55
  );
56
  if (false === $pi || ! isset($groups[$pi])) {
59
  return $options;
60
  }
61
  $sources = array();
62
+
63
  $files = $groups[$pi];
64
  // if $files is a single object, casting will break it
65
  if (is_object($files)) {
79
  if (is_file($realPath)) {
80
  $sources[] = new Minify_Source(array(
81
  'filepath' => $realPath
82
+ ));
83
  } else {
84
+ $this->log("The path \"{$realPath}\" could not be found (or was not a file)");
85
  return $options;
86
  }
87
  }
lib/Minify/Minify/Controller/MinApp.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * Class Minify_Controller_MinApp
4
  * @package Minify
5
  */
6
 
@@ -8,18 +8,18 @@ require_once W3TC_LIB_MINIFY_DIR . '/Minify/Controller/Base.php';
8
 
9
  /**
10
  * Controller class for requests to /min/index.php
11
- *
12
  * @package Minify
13
  * @author Stephen Clay <steve@mrclay.org>
14
  */
15
  class Minify_Controller_MinApp extends Minify_Controller_Base {
16
-
17
  /**
18
  * Set up groups of files as sources
19
- *
20
  * @param array $options controller and Minify options
21
  * @return array Minify options
22
- *
23
  */
24
  public function setupSources($options) {
25
  // filter controller options
@@ -28,7 +28,7 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
28
  'allowDirs' => '//'
29
  ,'groupsOnly' => false
30
  ,'groups' => array()
31
- ,'maxFiles' => 10
32
  )
33
  ,(isset($options['minApp']) ? $options['minApp'] : array())
34
  );
@@ -40,7 +40,7 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
40
  $this->log("A group configuration for \"{$_GET['g']}\" was not set");
41
  return $options;
42
  }
43
-
44
  $files = $cOptions['groups'][$_GET['g']];
45
  // if $files is a single object, casting will break it
46
  if (is_object($files)) {
@@ -60,9 +60,9 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
60
  if (is_file($realPath)) {
61
  $sources[] = new Minify_Source(array(
62
  'filepath' => $realPath
63
- ));
64
  } else {
65
- $this->log("The path \"{$file}\" could not be found (or was not a file)");
66
  continue;
67
  }
68
  }
@@ -70,7 +70,7 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
70
  // try user files
71
  // The following restrictions are to limit the URLs that minify will
72
  // respond to. Ideally there should be only one way to reference a file.
73
- if (// verify at least one file, files are single comma separated,
74
  // and are all same extension
75
  ! preg_match('/^[^,]+\\.(css|js)(?:,[^,]+\\.\\1)*$/', $_GET['f'])
76
  // no "//"
@@ -80,12 +80,12 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
80
  // no "./"
81
  || preg_match('/(?:^|[^\\.])\\.\\//', $_GET['f'])
82
  ) {
83
- $this->log("GET param 'f' invalid (see MinApp.php line 63)");
84
  return $options;
85
  }
86
  $files = explode(',', $_GET['f']);
87
  if (count($files) > $cOptions['maxFiles'] || $files != array_unique($files)) {
88
- $this->log("Too many or duplicate files specified");
89
  return $options;
90
  }
91
  if (!empty($_GET['b'])) {
@@ -94,9 +94,9 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
94
  && false === strpos($_GET['b'], '..')
95
  && $_GET['b'] !== '.') {
96
  // valid base
97
- $base = "/{$_GET['b']}/";
98
  } else {
99
- $this->log("GET param 'b' invalid (see MinApp.php line 84)");
100
  return $options;
101
  }
102
  } else {
1
  <?php
2
  /**
3
+ * Class Minify_Controller_MinApp
4
  * @package Minify
5
  */
6
 
8
 
9
  /**
10
  * Controller class for requests to /min/index.php
11
+ *
12
  * @package Minify
13
  * @author Stephen Clay <steve@mrclay.org>
14
  */
15
  class Minify_Controller_MinApp extends Minify_Controller_Base {
16
+
17
  /**
18
  * Set up groups of files as sources
19
+ *
20
  * @param array $options controller and Minify options
21
  * @return array Minify options
22
+ *
23
  */
24
  public function setupSources($options) {
25
  // filter controller options
28
  'allowDirs' => '//'
29
  ,'groupsOnly' => false
30
  ,'groups' => array()
31
+ ,'maxFiles' => 10
32
  )
33
  ,(isset($options['minApp']) ? $options['minApp'] : array())
34
  );
40
  $this->log("A group configuration for \"{$_GET['g']}\" was not set");
41
  return $options;
42
  }
43
+
44
  $files = $cOptions['groups'][$_GET['g']];
45
  // if $files is a single object, casting will break it
46
  if (is_object($files)) {
60
  if (is_file($realPath)) {
61
  $sources[] = new Minify_Source(array(
62
  'filepath' => $realPath
63
+ ));
64
  } else {
65
+ $this->log("The path \"{$realPath}\" could not be found (or was not a file)");
66
  continue;
67
  }
68
  }
70
  // try user files
71
  // The following restrictions are to limit the URLs that minify will
72
  // respond to. Ideally there should be only one way to reference a file.
73
+ if (// verify at least one file, files are single comma separated,
74
  // and are all same extension
75
  ! preg_match('/^[^,]+\\.(css|js)(?:,[^,]+\\.\\1)*$/', $_GET['f'])
76
  // no "//"
80
  // no "./"
81
  || preg_match('/(?:^|[^\\.])\\.\\//', $_GET['f'])
82
  ) {
83
+ $this->log("GET['f'] param invalid: \"{$_GET['f']}\"");
84
  return $options;
85
  }
86
  $files = explode(',', $_GET['f']);
87
  if (count($files) > $cOptions['maxFiles'] || $files != array_unique($files)) {
88
+ $this->log("Too many or duplicate files specified: \"" . implode(', ', $files) . "\"");
89
  return $options;
90
  }
91
  if (!empty($_GET['b'])) {
94
  && false === strpos($_GET['b'], '..')
95
  && $_GET['b'] !== '.') {
96
  // valid base
97
+ $base = "/{$_GET['b']}/";
98
  } else {
99
+ $this->log("GET['b'] param invalid: \"{$_GET['b']}\"");
100
  return $options;
101
  }
102
  } else {
lib/Minify/Minify/HTMLTidy.php CHANGED
@@ -6,6 +6,8 @@ class Minify_HTMLTidy {
6
  'clean' => false,
7
  'hide-comments' => true,
8
  'wrap' => 0,
 
 
9
  ), $options, array(
10
  'show-errors' => 0,
11
  'show-warnings' => false,
6
  'clean' => false,
7
  'hide-comments' => true,
8
  'wrap' => 0,
9
+ 'input-encoding' => 'utf8',
10
+ 'output-encoding' => 'utf8',
11
  ), $options, array(
12
  'show-errors' => 0,
13
  'show-warnings' => false,
lib/Minify/Minify/ImportProcessor.php CHANGED
@@ -134,9 +134,8 @@ class Minify_ImportProcessor {
134
  ? $m[1]
135
  : substr($m[1], 1, strlen($m[1]) - 2);
136
  if ('/' !== $url[0]) {
137
- if (strpos($url, '//') > 0) {
138
- // probably starts with protocol, do not alter
139
- } else {
140
  // prepend path with current dir separator (OS-independent)
141
  $path = $this->_currentDir
142
  . DIRECTORY_SEPARATOR . strtr($url, '/', DIRECTORY_SEPARATOR);
134
  ? $m[1]
135
  : substr($m[1], 1, strlen($m[1]) - 2);
136
  if ('/' !== $url[0]) {
137
+ if (false === strpos($url, '//') // protocol (non-data)
138
+ && 0 !== strpos($url, 'data:')) { // data protocol
 
139
  // prepend path with current dir separator (OS-independent)
140
  $path = $this->_currentDir
141
  . DIRECTORY_SEPARATOR . strtr($url, '/', DIRECTORY_SEPARATOR);
lib/Minify/Minify/Logger.php CHANGED
@@ -1,19 +1,19 @@
1
  <?php
2
  /**
3
- * Class Minify_Logger
4
  * @package Minify
5
  */
6
 
7
- /**
8
  * Message logging class
9
- *
10
  * @package Minify
11
  * @author Stephen Clay <steve@mrclay.org>
12
  */
13
  class Minify_Logger {
14
 
15
  /**
16
- * Set logger object.
17
  *
18
  * The object should have a method "log" that accepts a value as 1st argument and
19
  * an optional string label as the 2nd.
@@ -22,22 +22,21 @@ class Minify_Logger {
22
  * @return null
23
  */
24
  public static function setLogger($obj = null) {
25
- self::$_logger = $obj
26
- ? $obj
27
- : null;
28
  }
29
-
30
  /**
31
  * Pass a message to the logger (if set)
32
  *
33
  * @param string $msg message to log
34
  * @return null
35
  */
36
- public static function log($msg, $label = 'Minify') {
37
- if (! self::$_logger) return;
38
- self::$_logger->log($msg, $label);
 
39
  }
40
-
41
  /**
42
  * @var mixed logger object (like FirePHP) or null (i.e. no logger available)
43
  */
1
  <?php
2
  /**
3
+ * Class Minify_Logger
4
  * @package Minify
5
  */
6
 
7
+ /**
8
  * Message logging class
9
+ *
10
  * @package Minify
11
  * @author Stephen Clay <steve@mrclay.org>
12
  */
13
  class Minify_Logger {
14
 
15
  /**
16
+ * Set logger object.
17
  *
18
  * The object should have a method "log" that accepts a value as 1st argument and
19
  * an optional string label as the 2nd.
22
  * @return null
23
  */
24
  public static function setLogger($obj = null) {
25
+ self::$_logger = $obj;
 
 
26
  }
27
+
28
  /**
29
  * Pass a message to the logger (if set)
30
  *
31
  * @param string $msg message to log
32
  * @return null
33
  */
34
+ public static function log($msg) {
35
+ if (is_callable(self::$_logger)) {
36
+ call_user_func(self::$_logger, $msg);
37
+ }
38
  }
39
+
40
  /**
41
  * @var mixed logger object (like FirePHP) or null (i.e. no logger available)
42
  */
lib/S3.php CHANGED
@@ -95,7 +95,10 @@ class S3 {
95
  if ($rest->error === false && $rest->code !== 200)
96
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
97
  if ($rest->error !== false) {
98
- trigger_error(sprintf("S3::listBuckets(): [%s] %s", $rest->error['code'], $rest->error['message']), E_USER_WARNING);
 
 
 
99
  return false;
100
  }
101
  $results = array();
@@ -141,7 +144,10 @@ class S3 {
141
  if ($response->error === false && $response->code !== 200)
142
  $response->error = array('code' => $response->code, 'message' => 'Unexpected HTTP status');
143
  if ($response->error !== false) {
144
- trigger_error(sprintf("S3::getBucket(): [%s] %s", $response->error['code'], $response->error['message']), E_USER_WARNING);
 
 
 
145
  return false;
146
  }
147
 
@@ -230,8 +236,13 @@ class S3 {
230
  if ($rest->error === false && $rest->code !== 200)
231
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
232
  if ($rest->error !== false) {
233
- trigger_error(sprintf("S3::putBucket({$bucket}, {$acl}, {$location}): [%s] %s",
234
- $rest->error['code'], $rest->error['message']), E_USER_WARNING);
 
 
 
 
 
235
  return false;
236
  }
237
  return true;
@@ -250,8 +261,11 @@ class S3 {
250
  if ($rest->error === false && $rest->code !== 204)
251
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
252
  if ($rest->error !== false) {
253
- trigger_error(sprintf("S3::deleteBucket({$bucket}): [%s] %s",
254
- $rest->error['code'], $rest->error['message']), E_USER_WARNING);
 
 
 
255
  return false;
256
  }
257
  return true;
@@ -363,7 +377,10 @@ class S3 {
363
  if ($rest->response->error === false && $rest->response->code !== 200)
364
  $rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
365
  if ($rest->response->error !== false) {
366
- trigger_error(sprintf("S3::putObject(): [%s] %s", $rest->response->error['code'], $rest->response->error['message']), E_USER_WARNING);
 
 
 
367
  return false;
368
  }
369
  return true;
@@ -426,8 +443,13 @@ class S3 {
426
  if ($rest->response->error === false && $rest->response->code !== 200)
427
  $rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
428
  if ($rest->response->error !== false) {
429
- trigger_error(sprintf("S3::getObject({$bucket}, {$uri}): [%s] %s",
430
- $rest->response->error['code'], $rest->response->error['message']), E_USER_WARNING);
 
 
 
 
 
431
  return false;
432
  }
433
  return $rest->response;
@@ -448,8 +470,13 @@ class S3 {
448
  if ($rest->error === false && ($rest->code !== 200 && $rest->code !== 404))
449
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
450
  if ($rest->error !== false) {
451
- trigger_error(sprintf("S3::getObjectInfo({$bucket}, {$uri}): [%s] %s",
452
- $rest->error['code'], $rest->error['message']), E_USER_WARNING);
 
 
 
 
 
453
  return false;
454
  }
455
  return $rest->code == 200 ? $returnInfo ? $rest->headers : true : false;
@@ -481,8 +508,14 @@ class S3 {
481
  if ($rest->error === false && $rest->code !== 200)
482
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
483
  if ($rest->error !== false) {
484
- trigger_error(sprintf("S3::copyObject({$srcBucket}, {$srcUri}, {$bucket}, {$uri}): [%s] %s",
485
- $rest->error['code'], $rest->error['message']), E_USER_WARNING);
 
 
 
 
 
 
486
  return false;
487
  }
488
  return isset($rest->body->LastModified, $rest->body->ETag) ? array(
@@ -542,8 +575,13 @@ class S3 {
542
  if ($rest->error === false && $rest->code !== 200)
543
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
544
  if ($rest->error !== false) {
545
- trigger_error(sprintf("S3::setBucketLogging({$bucket}, {$uri}): [%s] %s",
546
- $rest->error['code'], $rest->error['message']), E_USER_WARNING);
 
 
 
 
 
547
  return false;
548
  }
549
  return true;
@@ -566,8 +604,11 @@ class S3 {
566
  if ($rest->error === false && $rest->code !== 200)
567
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
568
  if ($rest->error !== false) {
569
- trigger_error(sprintf("S3::getBucketLogging({$bucket}): [%s] %s",
570
- $rest->error['code'], $rest->error['message']), E_USER_WARNING);
 
 
 
571
  return false;
572
  }
573
  if (!isset($rest->body->LoggingEnabled)) return false; // No logging
@@ -602,8 +643,11 @@ class S3 {
602
  if ($rest->error === false && $rest->code !== 200)
603
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
604
  if ($rest->error !== false) {
605
- trigger_error(sprintf("S3::getBucketLocation({$bucket}): [%s] %s",
606
- $rest->error['code'], $rest->error['message']), E_USER_WARNING);
 
 
 
607
  return false;
608
  }
609
  return (isset($rest->body[0]) && (string)$rest->body[0] !== '') ? (string)$rest->body[0] : 'US';
@@ -661,8 +705,12 @@ class S3 {
661
  if ($rest->error === false && $rest->code !== 200)
662
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
663
  if ($rest->error !== false) {
664
- trigger_error(sprintf("S3::setAccessControlPolicy({$bucket}, {$uri}): [%s] %s",
665
- $rest->error['code'], $rest->error['message']), E_USER_WARNING);
 
 
 
 
666
  return false;
667
  }
668
  return true;
@@ -683,8 +731,12 @@ class S3 {
683
  if ($rest->error === false && $rest->code !== 200)
684
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
685
  if ($rest->error !== false) {
686
- trigger_error(sprintf("S3::getAccessControlPolicy({$bucket}, {$uri}): [%s] %s",
687
- $rest->error['code'], $rest->error['message']), E_USER_WARNING);
 
 
 
 
688
  return false;
689
  }
690
 
@@ -738,8 +790,12 @@ class S3 {
738
  if ($rest->error === false && $rest->code !== 204)
739
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
740
  if ($rest->error !== false) {
741
- trigger_error(sprintf("S3::deleteObject(): [%s] %s",
742
- $rest->error['code'], $rest->error['message']), E_USER_WARNING);
 
 
 
 
743
  return false;
744
  }
745
  return true;
@@ -840,8 +896,15 @@ class S3 {
840
  if ($rest->error === false && $rest->code !== 201)
841
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
842
  if ($rest->error !== false) {
843
- trigger_error(sprintf("S3::createDistribution($dnsName, $originType, ".(int)$enabled.", '$comment'): [%s] %s",
844
- $rest->error['code'], $rest->error['message']), E_USER_WARNING);
 
 
 
 
 
 
 
845
  return false;
846
  } elseif ($rest->body instanceof SimpleXMLElement)
847
  return self::__parseCloudFrontDistributionConfig($rest->body);
@@ -862,8 +925,11 @@ class S3 {
862
  if ($rest->error === false && $rest->code !== 200)
863
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
864
  if ($rest->error !== false) {
865
- trigger_error(sprintf("S3::getDistribution($distributionId): [%s] %s",
866
- $rest->error['code'], $rest->error['message']), E_USER_WARNING);
 
 
 
867
  return false;
868
  } elseif ($rest->body instanceof SimpleXMLElement) {
869
  $dist = self::__parseCloudFrontDistributionConfig($rest->body);
@@ -891,8 +957,11 @@ class S3 {
891
  if ($rest->error === false && $rest->code !== 200)
892
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
893
  if ($rest->error !== false) {
894
- trigger_error(sprintf("S3::updateDistribution({$dist['id']}, ".(int)$dist['enabled'].", '".$dist['comment']."'): [%s] %s",
895
- $rest->error['code'], $rest->error['message']), E_USER_WARNING);
 
 
 
896
  return false;
897
  } else {
898
  $dist = self::__parseCloudFrontDistributionConfig($rest->body);
@@ -918,8 +987,11 @@ class S3 {
918
  if ($rest->error === false && $rest->code !== 204)
919
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
920
  if ($rest->error !== false) {
921
- trigger_error(sprintf("S3::deleteDistribution({$dist['id']}): [%s] %s",
922
- $rest->error['code'], $rest->error['message']), E_USER_WARNING);
 
 
 
923
  return false;
924
  }
925
  return true;
@@ -940,7 +1012,9 @@ class S3 {
940
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
941
  if ($rest->error !== false) {
942
  trigger_error(sprintf("S3::listDistributions(): [%s] %s",
943
- $rest->error['code'], $rest->error['message']), E_USER_WARNING);
 
 
944
  return false;
945
  } elseif ($rest->body instanceof SimpleXMLElement && isset($rest->body->DistributionSummary)) {
946
  $list = array();
@@ -972,7 +1046,8 @@ class S3 {
972
  */
973
  private static function __getCloudFrontDistributionConfigXML($dnsName, $originType, $enabled, $comment, $callerReference = '0', $cnames = array()) {
974
  $dom = new DOMDocument('1.0', 'UTF-8');
975
- $dom->formatOutput = true;
 
976
  $distributionConfig = $dom->createElement('DistributionConfig');
977
  $distributionConfig->setAttribute('xmlns', 'http://cloudfront.amazonaws.com/doc/2010-11-01/');
978
 
@@ -987,11 +1062,18 @@ class S3 {
987
 
988
  $distributionConfig->appendChild($origin);
989
  $distributionConfig->appendChild($dom->createElement('CallerReference', $callerReference));
990
- foreach ($cnames as $cname)
 
991
  $distributionConfig->appendChild($dom->createElement('CNAME', $cname));
992
- if ($comment !== '') $distributionConfig->appendChild($dom->createElement('Comment', $comment));
 
 
 
 
 
993
  $distributionConfig->appendChild($dom->createElement('Enabled', $enabled ? 'true' : 'false'));
994
  $dom->appendChild($distributionConfig);
 
995
  return $dom->saveXML();
996
  }
997
 
@@ -1088,10 +1170,12 @@ class S3 {
1088
  }
1089
 
1090
  if ($rest->error !== false) {
1091
- trigger_error(sprintf("S3::createInvalidation($distributionId, %s): [%s] %s",
1092
- print_r($files, true),
1093
- $rest->error['code'], $rest->error['message']), E_USER_WARNING);
1094
-
 
 
1095
  return false;
1096
  } elseif ($rest->body instanceof SimpleXMLElement) {
1097
  return self::__parseCloudFrontInvalidation($rest->body);
@@ -1231,12 +1315,23 @@ class S3 {
1231
  }
1232
 
1233
  final class S3Request {
1234
- private $verb, $bucket, $uri, $resource = '', $parameters = array(),
1235
- $amzHeaders = array(), $headers = array(
1236
- 'Host' => '', 'Date' => '', 'Content-MD5' => '', 'Content-Type' => ''
 
 
 
 
 
 
 
 
 
 
 
 
 
1237
  );
1238
- public $fp = false, $size = 0, $data = false, $response;
1239
-
1240
 
1241
  /**
1242
  * Constructor
95
  if ($rest->error === false && $rest->code !== 200)
96
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
97
  if ($rest->error !== false) {
98
+ trigger_error(sprintf("S3::listBuckets(): [%s] %s",
99
+ $rest->error['code'],
100
+ $rest->error['message']
101
+ ), E_USER_WARNING);
102
  return false;
103
  }
104
  $results = array();
144
  if ($response->error === false && $response->code !== 200)
145
  $response->error = array('code' => $response->code, 'message' => 'Unexpected HTTP status');
146
  if ($response->error !== false) {
147
+ trigger_error(sprintf("S3::getBucket(): [%s] %s",
148
+ $response->error['code'],
149
+ $response->error['message']
150
+ ), E_USER_WARNING);
151
  return false;
152
  }
153
 
236
  if ($rest->error === false && $rest->code !== 200)
237
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
238
  if ($rest->error !== false) {
239
+ trigger_error(sprintf("S3::putBucket('%s', '%s', '%s'): [%s] %s",
240
+ $bucket,
241
+ $acl,
242
+ $location,
243
+ $rest->error['code'],
244
+ $rest->error['message']
245
+ ), E_USER_WARNING);
246
  return false;
247
  }
248
  return true;
261
  if ($rest->error === false && $rest->code !== 204)
262
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
263
  if ($rest->error !== false) {
264
+ trigger_error(sprintf("S3::deleteBucket('%s'): [%s] %s",
265
+ $bucket,
266
+ $rest->error['code'],
267
+ $rest->error['message']
268
+ ), E_USER_WARNING);
269
  return false;
270
  }
271
  return true;
377
  if ($rest->response->error === false && $rest->response->code !== 200)
378
  $rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
379
  if ($rest->response->error !== false) {
380
+ trigger_error(sprintf("S3::putObject(): [%s] %s",
381
+ $rest->response->error['code'],
382
+ $rest->response->error['message']
383
+ ), E_USER_WARNING);
384
  return false;
385
  }
386
  return true;
443
  if ($rest->response->error === false && $rest->response->code !== 200)
444
  $rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
445
  if ($rest->response->error !== false) {
446
+ trigger_error(sprintf("S3::getObject('%s', '%s', '%s'): [%s] %s",
447
+ $bucket,
448
+ $uri,
449
+ $saveTo,
450
+ $rest->response->error['code'],
451
+ $rest->response->error['message']
452
+ ), E_USER_WARNING);
453
  return false;
454
  }
455
  return $rest->response;
470
  if ($rest->error === false && ($rest->code !== 200 && $rest->code !== 404))
471
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
472
  if ($rest->error !== false) {
473
+ trigger_error(sprintf("S3::getObjectInfo('%s', '%s', %d): [%s] %s",
474
+ $bucket,
475
+ $uri,
476
+ $returnInfo,
477
+ $rest->error['code'],
478
+ $rest->error['message']
479
+ ), E_USER_WARNING);
480
  return false;
481
  }
482
  return $rest->code == 200 ? $returnInfo ? $rest->headers : true : false;
508
  if ($rest->error === false && $rest->code !== 200)
509
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
510
  if ($rest->error !== false) {
511
+ trigger_error(sprintf("S3::copyObject('%s', '%s', '%s', '%s'): [%s] %s",
512
+ $srcBucket,
513
+ $srcUri,
514
+ $bucket,
515
+ $uri,
516
+ $rest->error['code'],
517
+ $rest->error['message']
518
+ ), E_USER_WARNING);
519
  return false;
520
  }
521
  return isset($rest->body->LastModified, $rest->body->ETag) ? array(
575
  if ($rest->error === false && $rest->code !== 200)
576
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
577
  if ($rest->error !== false) {
578
+ trigger_error(sprintf("S3::setBucketLogging('%s', '%s', '%s'): [%s] %s",
579
+ $bucket,
580
+ $targetBucket,
581
+ $targetPrefix,
582
+ $rest->error['code'],
583
+ $rest->error['message']
584
+ ), E_USER_WARNING);
585
  return false;
586
  }
587
  return true;
604
  if ($rest->error === false && $rest->code !== 200)
605
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
606
  if ($rest->error !== false) {
607
+ trigger_error(sprintf("S3::getBucketLogging('%s'): [%s] %s",
608
+ $bucket,
609
+ $rest->error['code'],
610
+ $rest->error['message']
611
+ ), E_USER_WARNING);
612
  return false;
613
  }
614
  if (!isset($rest->body->LoggingEnabled)) return false; // No logging
643
  if ($rest->error === false && $rest->code !== 200)
644
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
645
  if ($rest->error !== false) {
646
+ trigger_error(sprintf("S3::getBucketLocation('%s'): [%s] %s",
647
+ $bucket,
648
+ $rest->error['code'],
649
+ $rest->error['message']
650
+ ), E_USER_WARNING);
651
  return false;
652
  }
653
  return (isset($rest->body[0]) && (string)$rest->body[0] !== '') ? (string)$rest->body[0] : 'US';
705
  if ($rest->error === false && $rest->code !== 200)
706
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
707
  if ($rest->error !== false) {
708
+ trigger_error(sprintf("S3::setAccessControlPolicy('%s', '%s'): [%s] %s",
709
+ $bucket,
710
+ $uri,
711
+ $rest->error['code'],
712
+ $rest->error['message']
713
+ ), E_USER_WARNING);
714
  return false;
715
  }
716
  return true;
731
  if ($rest->error === false && $rest->code !== 200)
732
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
733
  if ($rest->error !== false) {
734
+ trigger_error(sprintf("S3::getAccessControlPolicy('%s', '%s'): [%s] %s",
735
+ $bucket,
736
+ $uri,
737
+ $rest->error['code'],
738
+ $rest->error['message']
739
+ ), E_USER_WARNING);
740
  return false;
741
  }
742
 
790
  if ($rest->error === false && $rest->code !== 204)
791
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
792
  if ($rest->error !== false) {
793
+ trigger_error(sprintf("S3::deleteObject('%s', '%s'): [%s] %s",
794
+ $bucket,
795
+ $uri,
796
+ $rest->error['code'],
797
+ $rest->error['message']
798
+ ), E_USER_WARNING);
799
  return false;
800
  }
801
  return true;
896
  if ($rest->error === false && $rest->code !== 201)
897
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
898
  if ($rest->error !== false) {
899
+ trigger_error(sprintf("S3::createDistribution('%s', '%s', %d, '%s', '%s'): [%s] %s",
900
+ $dnsName,
901
+ $originType,
902
+ $enabled,
903
+ implode(', ', $cnames),
904
+ $comment,
905
+ $rest->error['code'],
906
+ $rest->error['message']
907
+ ), E_USER_WARNING);
908
  return false;
909
  } elseif ($rest->body instanceof SimpleXMLElement)
910
  return self::__parseCloudFrontDistributionConfig($rest->body);
925
  if ($rest->error === false && $rest->code !== 200)
926
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
927
  if ($rest->error !== false) {
928
+ trigger_error(sprintf("S3::getDistribution(%d): [%s] %s",
929
+ $distributionId,
930
+ $rest->error['code'],
931
+ $rest->error['message']
932
+ ), E_USER_WARNING);
933
  return false;
934
  } elseif ($rest->body instanceof SimpleXMLElement) {
935
  $dist = self::__parseCloudFrontDistributionConfig($rest->body);
957
  if ($rest->error === false && $rest->code !== 200)
958
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
959
  if ($rest->error !== false) {
960
+ trigger_error(sprintf("S3::updateDistribution('%s'): [%s] %s",
961
+ serialize($dist),
962
+ $rest->error['code'],
963
+ $rest->error['message']
964
+ ), E_USER_WARNING);
965
  return false;
966
  } else {
967
  $dist = self::__parseCloudFrontDistributionConfig($rest->body);
987
  if ($rest->error === false && $rest->code !== 204)
988
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
989
  if ($rest->error !== false) {
990
+ trigger_error(sprintf("S3::deleteDistribution('%s'): [%s] %s",
991
+ serialize($dist),
992
+ $rest->error['code'],
993
+ $rest->error['message']
994
+ ), E_USER_WARNING);
995
  return false;
996
  }
997
  return true;
1012
  $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
1013
  if ($rest->error !== false) {
1014
  trigger_error(sprintf("S3::listDistributions(): [%s] %s",
1015
+ $rest->error['code'],
1016
+ $rest->error['message']
1017
+ ), E_USER_WARNING);
1018
  return false;
1019
  } elseif ($rest->body instanceof SimpleXMLElement && isset($rest->body->DistributionSummary)) {
1020
  $list = array();
1046
  */
1047
  private static function __getCloudFrontDistributionConfigXML($dnsName, $originType, $enabled, $comment, $callerReference = '0', $cnames = array()) {
1048
  $dom = new DOMDocument('1.0', 'UTF-8');
1049
+
1050
+ $dom->formatOutput = true;
1051
  $distributionConfig = $dom->createElement('DistributionConfig');
1052
  $distributionConfig->setAttribute('xmlns', 'http://cloudfront.amazonaws.com/doc/2010-11-01/');
1053
 
1062
 
1063
  $distributionConfig->appendChild($origin);
1064
  $distributionConfig->appendChild($dom->createElement('CallerReference', $callerReference));
1065
+
1066
+ foreach ($cnames as $cname) {
1067
  $distributionConfig->appendChild($dom->createElement('CNAME', $cname));
1068
+ }
1069
+
1070
+ if ($comment !== '') {
1071
+ $distributionConfig->appendChild($dom->createElement('Comment', $comment));
1072
+ }
1073
+
1074
  $distributionConfig->appendChild($dom->createElement('Enabled', $enabled ? 'true' : 'false'));
1075
  $dom->appendChild($distributionConfig);
1076
+
1077
  return $dom->saveXML();
1078
  }
1079
 
1170
  }
1171
 
1172
  if ($rest->error !== false) {
1173
+ trigger_error(sprintf("S3::createInvalidation(%d, '%s'): [%s] %s",
1174
+ $distributionId,
1175
+ implode(', ', $paths),
1176
+ $rest->error['code'],
1177
+ $rest->error['message']
1178
+ ), E_USER_WARNING);
1179
  return false;
1180
  } elseif ($rest->body instanceof SimpleXMLElement) {
1181
  return self::__parseCloudFrontInvalidation($rest->body);
1315
  }
1316
 
1317
  final class S3Request {
1318
+ private $verb;
1319
+ private $bucket;
1320
+ private $uri;
1321
+ private $resource = '';
1322
+ private $parameters = array();
1323
+ private $amzHeaders = array();
1324
+
1325
+ public $fp = false;
1326
+ public $size = 0;
1327
+ public $data = false;
1328
+ public $response;
1329
+ public $headers = array(
1330
+ 'Host' => '',
1331
+ 'Date' => '',
1332
+ 'Content-MD5' => '',
1333
+ 'Content-Type' => ''
1334
  );
 
 
1335
 
1336
  /**
1337
  * Constructor
lib/W3/Cache.php CHANGED
@@ -31,8 +31,8 @@ if (!defined('W3TC_CACHE_FILE')) {
31
  define('W3TC_CACHE_FILE', 'file');
32
  }
33
 
34
- if (!defined('W3TC_CACHE_FILE_PGCACHE')) {
35
- define('W3TC_CACHE_FILE_PGCACHE', 'file_pgcache');
36
  }
37
 
38
  /**
@@ -49,7 +49,7 @@ class W3_Cache {
49
  function &instance($engine, $config = array()) {
50
  static $instances = array();
51
 
52
- $instance_key = sprintf('%s_%s', $engine, md5(serialize($config)));
53
 
54
  if (!isset($instances[$instance_key])) {
55
  switch ($engine) {
@@ -83,9 +83,9 @@ class W3_Cache {
83
  $instances[$instance_key] = & new W3_Cache_File($config);
84
  break;
85
 
86
- case W3TC_CACHE_FILE_PGCACHE:
87
- require_once W3TC_LIB_W3_DIR . '/Cache/File/PgCache.php';
88
- $instances[$instance_key] = & new W3_Cache_File_PgCache($config);
89
  break;
90
 
91
  default:
31
  define('W3TC_CACHE_FILE', 'file');
32
  }
33
 
34
+ if (!defined('W3TC_CACHE_FILE_GENERIC')) {
35
+ define('W3TC_CACHE_FILE_GENERIC', 'file_generic');
36
  }
37
 
38
  /**
49
  function &instance($engine, $config = array()) {
50
  static $instances = array();
51
 
52
+ $instance_key = sprintf('%s_%s', $engine, md5(implode('', $config)));
53
 
54
  if (!isset($instances[$instance_key])) {
55
  switch ($engine) {
83
  $instances[$instance_key] = & new W3_Cache_File($config);
84
  break;
85
 
86
+ case W3TC_CACHE_FILE_GENERIC:
87
+ require_once W3TC_LIB_W3_DIR . '/Cache/File/Generic.php';
88
+ $instances[$instance_key] = & new W3_Cache_File_Generic($config);
89
  break;
90
 
91
  default:
lib/W3/Cache/File.php CHANGED
@@ -21,35 +21,42 @@ class W3_Cache_File extends W3_Cache_Base {
21
  var $_cache_dir = '';
22
 
23
  /**
24
- * File locking
25
  *
26
- * @var boolean
27
  */
28
- var $_locking = false;
29
 
30
  /**
31
- * Flush timelimit
32
  *
33
  * @var int
34
  */
35
  var $_flush_timelimit = 0;
36
 
37
  /**
38
- * PHP5 constructor
 
 
 
 
 
 
 
39
  *
40
  * @param array $config
41
  */
42
  function __construct($config = array()) {
43
  $this->_cache_dir = isset($config['cache_dir']) ? trim($config['cache_dir']) : 'cache';
44
- $this->_locking = isset($config['locking']) ? (boolean) $config['locking'] : false;
45
  $this->_flush_timelimit = isset($config['flush_timelimit']) ? (int) $config['flush_timelimit'] : 180;
 
46
  }
47
 
48
  /**
49
- * PHP4 constructor
50
  *
51
- * @paran array $config
52
- * @return W3_Cache_File
53
  */
54
  function W3_Cache_File($config = array()) {
55
  $this->__construct($config);
@@ -81,7 +88,7 @@ class W3_Cache_File extends W3_Cache_Base {
81
  */
82
  function set($key, &$var, $expire = 0) {
83
  $sub_path = $this->_get_path($key);
84
- $path = $this->_cache_dir . '/' . $sub_path;
85
 
86
  $sub_dir = dirname($sub_path);
87
  $dir = dirname($path);
@@ -117,7 +124,7 @@ class W3_Cache_File extends W3_Cache_Base {
117
  */
118
  function get($key) {
119
  $var = false;
120
- $path = $this->_cache_dir . '/' . $this->_get_path($key);
121
 
122
  if (is_readable($path)) {
123
  $ftime = @filemtime($path);
@@ -182,7 +189,7 @@ class W3_Cache_File extends W3_Cache_Base {
182
  * @return boolean
183
  */
184
  function delete($key) {
185
- $path = $this->_cache_dir . '/' . $this->_get_path($key);
186
 
187
  if (file_exists($path)) {
188
  return @unlink($path);
@@ -199,9 +206,7 @@ class W3_Cache_File extends W3_Cache_Base {
199
  function flush() {
200
  @set_time_limit($this->_flush_timelimit);
201
 
202
- w3_emptydir($this->_cache_dir);
203
-
204
- return true;
205
  }
206
 
207
  /**
@@ -210,7 +215,7 @@ class W3_Cache_File extends W3_Cache_Base {
210
  * @param integer $key
211
  */
212
  function mtime($key) {
213
- $path = $this->_cache_dir . '/' . $this->_get_path($key);
214
 
215
  if (file_exists($path)) {
216
  return @filemtime($path);
21
  var $_cache_dir = '';
22
 
23
  /**
24
+ * Exclude files
25
  *
26
+ * @var array
27
  */
28
+ var $_exclude = array();
29
 
30
  /**
31
+ * Flush time limit
32
  *
33
  * @var int
34
  */
35
  var $_flush_timelimit = 0;
36
 
37
  /**
38
+ * File locking
39
+ *
40
+ * @var boolean
41
+ */
42
+ var $_locking = false;
43
+
44
+ /**
45
+ * PHP5-style constructor
46
  *
47
  * @param array $config
48
  */
49
  function __construct($config = array()) {
50
  $this->_cache_dir = isset($config['cache_dir']) ? trim($config['cache_dir']) : 'cache';
51
+ $this->_exclude = isset($config['exclude']) ? (array) $config['exclude'] : array();
52
  $this->_flush_timelimit = isset($config['flush_timelimit']) ? (int) $config['flush_timelimit'] : 180;
53
+ $this->_locking = isset($config['locking']) ? (boolean) $config['locking'] : false;
54
  }
55
 
56
  /**
57
+ * PHP4-style constructor
58
  *
59
+ * @param array $config
 
60
  */
61
  function W3_Cache_File($config = array()) {
62
  $this->__construct($config);
88
  */
89
  function set($key, &$var, $expire = 0) {
90
  $sub_path = $this->_get_path($key);
91
+ $path = $this->_cache_dir . DIRECTORY_SEPARATOR . $sub_path;
92
 
93
  $sub_dir = dirname($sub_path);
94
  $dir = dirname($path);
124
  */
125
  function get($key) {
126
  $var = false;
127
+ $path = $this->_cache_dir . DIRECTORY_SEPARATOR . $this->_get_path($key);
128
 
129
  if (is_readable($path)) {
130
  $ftime = @filemtime($path);
189
  * @return boolean
190
  */
191
  function delete($key) {
192
+ $path = $this->_cache_dir . DIRECTORY_SEPARATOR . $this->_get_path($key);
193
 
194
  if (file_exists($path)) {
195
  return @unlink($path);
206
  function flush() {
207
  @set_time_limit($this->_flush_timelimit);
208
 
209
+ return w3_emptydir($this->_cache_dir, $this->_exclude);
 
 
210
  }
211
 
212
  /**
215
  * @param integer $key
216
  */
217
  function mtime($key) {
218
+ $path = $this->_cache_dir . DIRECTORY_SEPARATOR . $this->_get_path($key);
219
 
220
  if (file_exists($path)) {
221
  return @filemtime($path);
lib/W3/Cache/File/Cleaner.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * File cache cleaner class
5
+ */
6
+ require_once W3TC_LIB_W3_DIR . '/Cache/File.php';
7
+
8
+ /**
9
+ * Class W3_Cache_File_Cleaner
10
+ */
11
+ class W3_Cache_File_Cleaner {
12
+ /**
13
+ * Cache directory
14
+ *
15
+ * @var string
16
+ */
17
+ var $_cache_dir = '';
18
+
19
+ /**
20
+ * Clean operation time limit
21
+ *
22
+ * @var int
23
+ */
24
+ var $_clean_timelimit = 0;
25
+
26
+ /**
27
+ * Exclude files
28
+ *
29
+ * @var array
30
+ */
31
+ var $_exclude = array();
32
+
33
+ /**
34
+ * PHP5-style constructor
35
+ *
36
+ * @param array $config
37
+ */
38
+ function __construct($config = array()) {
39
+ $this->_cache_dir = (isset($config['cache_dir']) ? trim($config['cache_dir']) : 'cache');
40
+ $this->_clean_timelimit = (isset($config['clean_timelimit']) ? (int) $config['clean_timelimit'] : 180);
41
+ $this->_exclude = (isset($config['exclude']) ? (array) $config['exclude'] : array());
42
+ }
43
+
44
+ /**
45
+ * PHP4-style constructor
46
+ *
47
+ * @param array $config
48
+ * @return void
49
+ */
50
+ function W3_Cache_File_Cleaner($config = array()) {
51
+ $this->__construct($config);
52
+ }
53
+
54
+ /**
55
+ * Run clean operation
56
+ *
57
+ * @return boolean
58
+ */
59
+ function clean() {
60
+ @set_time_limit($this->_clean_timelimit);
61
+
62
+ return $this->_clean($this->_cache_dir, false);
63
+ }
64
+
65
+ /**
66
+ * Clean
67
+ *
68
+ * @param string $path
69
+ * @param bool $remove
70
+ * @return void
71
+ */
72
+ function _clean($path, $remove = true) {
73
+ $dir = @opendir($path);
74
+
75
+ if ($dir) {
76
+ while (($entry = @readdir($dir)) !== false) {
77
+ if ($entry == '.' || $entry == '..') {
78
+ continue;
79
+ }
80
+
81
+ foreach ($this->_exclude as $mask) {
82
+ if (fnmatch($mask, basename($entry))) {
83
+ continue 2;
84
+ }
85
+ }
86
+
87
+ $full_path = $path . DIRECTORY_SEPARATOR . $entry;
88
+
89
+ if (@is_dir($full_path)) {
90
+ $this->_clean($full_path);
91
+ } elseif (!$this->is_valid($full_path)) {
92
+ @unlink($full_path);
93
+ }
94
+ }
95
+
96
+ @closedir($dir);
97
+
98
+ if ($remove) {
99
+ @rmdir($path);
100
+ }
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Check if file is valid
106
+ *
107
+ * @param string $file
108
+ * @return bool
109
+ */
110
+ function is_valid($file) {
111
+ $valid = false;
112
+
113
+ if (file_exists($file)) {
114
+ $ftime = @filemtime($file);
115
+
116
+ if ($ftime) {
117
+ $fp = @fopen($file, 'rb');
118
+
119
+ if ($fp) {
120
+ $expires = @fread($fp, 4);
121
+
122
+ if ($expires !== false) {
123
+ list(, $expire) = @unpack('L', $expires);
124
+
125
+ $expire = ($expire && $expire <= W3TC_CACHE_FILE_EXPIRE_MAX ? $expire : W3TC_CACHE_FILE_EXPIRE_MAX);
126
+
127
+ if ($ftime > (time() - $expire)) {
128
+ $valid = true;
129
+ }
130
+ }
131
+
132
+ @fclose($fp);
133
+ }
134
+ }
135
+ }
136
+
137
+ return $valid;
138
+ }
139
+ }
lib/W3/Cache/File/Cleaner/Generic.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Generic file cache cleaner class
5
+ */
6
+ require_once W3TC_LIB_W3_DIR . '/Cache/File/Cleaner.php';
7
+
8
+ /**
9
+ * Class W3_Cache_File_Cleaner_Generic
10
+ */
11
+ class W3_Cache_File_Cleaner_Generic extends W3_Cache_File_Cleaner {
12
+ /**
13
+ * Cache expire time
14
+ *
15
+ * @var int
16
+ */
17
+ var $_expire = 0;
18
+
19
+ /**
20
+ * PHP5-style constructor
21
+ *
22
+ * @param array $config
23
+ */
24
+ function __construct($config = array()) {
25
+ parent::__construct($config);
26
+
27
+ $this->_expire = (isset($config['expire']) ? (int) $config['expire'] : 0);
28
+
29
+ if (!$this->_expire || $this->_expire > W3TC_CACHE_FILE_EXPIRE_MAX) {
30
+ $this->_expire = W3TC_CACHE_FILE_EXPIRE_MAX;
31
+ }
32
+ }
33
+
34
+ /**
35
+ * PHP4-style constructor
36
+ *
37
+ * @param array $config
38
+ * @return void
39
+ */
40
+ function W3_Cache_File_Cleaner_Generic($config = array()) {
41
+ $this->__construct($config);
42
+ }
43
+
44
+ /**
45
+ * Checks if file is valid
46
+ *
47
+ * @param string $file
48
+ * @return bool
49
+ */
50
+ function is_valid($file) {
51
+ if (file_exists($file)) {
52
+ $ftime = @filemtime($file);
53
+
54
+ if ($ftime && $ftime > (time() - $this->_expire)) {
55
+ return true;
56
+ }
57
+ }
58
+
59
+ return false;
60
+ }
61
+ }
lib/W3/Cache/File/{PgCache.php → Generic.php} RENAMED
@@ -1,14 +1,14 @@
1
  <?php
2
 
3
  /**
4
- * File cache for Page cache
5
  */
6
  require_once W3TC_LIB_W3_DIR . '/Cache/File.php';
7
 
8
  /**
9
- * Class W3_Cache_File_PgCache
10
  */
11
- class W3_Cache_File_PgCache extends W3_Cache_File {
12
  /**
13
  * Expire
14
  *
@@ -17,10 +17,9 @@ class W3_Cache_File_PgCache extends W3_Cache_File {
17
  var $_expire = 0;
18
 
19
  /**
20
- * PHP5 style constructor
21
  *
22
  * @param array $config
23
- * @return void
24
  */
25
  function __construct($config = array()) {
26
  parent::__construct($config);
@@ -33,11 +32,11 @@ class W3_Cache_File_PgCache extends W3_Cache_File {
33
  }
34
 
35
  /**
36
- * PHP4 style constructor
 
37
  * @param array $config
38
- * @return void
39
  */
40
- function W3_Cache_File_PgCache($config = array()) {
41
  $this->__construct($config);
42
  }
43
 
@@ -116,21 +115,6 @@ class W3_Cache_File_PgCache extends W3_Cache_File {
116
  return $var;
117
  }
118
 
119
- /**
120
- * Flushes all data
121
- *
122
- * @return boolean
123
- */
124
- function flush() {
125
- @set_time_limit($this->_flush_timelimit);
126
-
127
- w3_emptydir($this->_cache_dir, array(
128
- $this->_cache_dir . '/.htaccess'
129
- ));
130
-
131
- return true;
132
- }
133
-
134
  /**
135
  * Returns cache file path by key
136
  *
@@ -140,4 +124,4 @@ class W3_Cache_File_PgCache extends W3_Cache_File {
140
  function _get_path($key) {
141
  return $key;
142
  }
143
- }
1
  <?php
2
 
3
  /**
4
+ * Generic file cache
5
  */
6
  require_once W3TC_LIB_W3_DIR . '/Cache/File.php';
7
 
8
  /**
9
+ * Class W3_Cache_File_Generic
10
  */
11
+ class W3_Cache_File_Generic extends W3_Cache_File {
12
  /**
13
  * Expire
14
  *
17
  var $_expire = 0;
18
 
19
  /**
20
+ * PHP5-style constructor
21
  *
22
  * @param array $config
 
23
  */
24
  function __construct($config = array()) {
25
  parent::__construct($config);
32
  }
33
 
34
  /**
35
+ * PHP4-style constructor
36
+ *
37
  * @param array $config
 
38
  */
39
+ function W3_Cache_File_Generic($config = array()) {
40
  $this->__construct($config);
41
  }
42
 
115
  return $var;
116
  }
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  /**
119
  * Returns cache file path by key
120
  *
124
  function _get_path($key) {
125
  return $key;
126
  }
127
+ }
lib/W3/Cache/File/Manager.php DELETED
@@ -1,75 +0,0 @@
1
- <?php
2
-
3
- require_once W3TC_LIB_W3_DIR . '/Cache/File.php';
4
-
5
- class W3_Cache_File_Manager {
6
- var $_cache_dir = '';
7
- var $_clean_timelimit = 0;
8
-
9
- function __construct($config = array()) {
10
- $this->_cache_dir = (isset($config['cache_dir']) ? trim($config['cache_dir']) : 'cache');
11
- $this->_clean_timelimit = (isset($config['clean_timelimit']) ? (int) $config['clean_timelimit'] : 180);
12
- }
13
-
14
- function W3_Cache_File_Manager($config = array()) {
15
- $this->__construct($config);
16
- }
17
-
18
- function clean() {
19
- @set_time_limit($this->_clean_timelimit);
20
-
21
- $this->_clean($this->_cache_dir, false);
22
- }
23
-
24
- function _clean($path, $remove = true) {
25
- $dir = @opendir($path);
26
-
27
- if ($dir) {
28
- while (($entry = @readdir($dir)) !== false) {
29
- if ($entry != '.' && $entry != '..') {
30
- $full_path = $path . '/' . $entry;
31
-
32
- if (@is_dir($full_path)) {
33
- $this->_clean($full_path);
34
- } elseif (!$this->is_valid($full_path)) {
35
- @unlink($full_path);
36
- }
37
- }
38
- }
39
-
40
- @closedir($dir);
41
-
42
- if ($remove) {
43
- @rmdir($path);
44
- }
45
- }
46
- }
47
-
48
- function is_valid($file) {
49
- $valid = false;
50
-
51
- if (file_exists($file)) {
52
- $ftime = @filemtime($file);
53
-
54
- if ($ftime) {
55
- $fp = @fopen($file, 'rb');
56
-
57
- if ($fp) {
58
- $expires = @fread($fp, 4);
59
-
60
- if ($expires !== false) {
61
- list(, $expire) = @unpack('L', $expires);
62
- $expire = ($expire && $expire <= W3TC_CACHE_FILE_EXPIRE_MAX ? $expire : W3TC_CACHE_FILE_EXPIRE_MAX);
63
- if ($ftime > (time() - $expire)) {
64
- $valid = true;
65
- }
66
- }
67
-
68
- @fclose($fp);
69
- }
70
- }
71
- }
72
-
73
- return $valid;
74
- }
75
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/W3/Cache/File/Minify/Manager.php DELETED
@@ -1,37 +0,0 @@
1
- <?php
2
-
3
- require_once W3TC_LIB_W3_DIR . '/Cache/File/Manager.php';
4
-
5
- class W3_Cache_File_Minify_Manager extends W3_Cache_File_Manager {
6
- var $_expire = 0;
7
-
8
- function __construct($config = array()) {
9
- parent::__construct($config);
10
-
11
- $this->_expire = (isset($config['expire']) ? (int) $config['expire'] : 0);
12
-
13
- if (!$this->_expire || $this->_expire > W3TC_CACHE_FILE_EXPIRE_MAX) {
14
- $this->_expire = W3TC_CACHE_FILE_EXPIRE_MAX;
15
- }
16
- }
17
-
18
- function W3_Cache_File_Minify_Manager($config = array()) {
19
- $this->__construct($config);
20
- }
21
-
22
- function is_valid($file) {
23
- if ($file == $this->_cache_dir . '/.htaccess' || $file == $this->_cache_dir . '/index.php') {
24
- return true;
25
- }
26
-
27
- if (file_exists($file)) {
28
- $ftime = @filemtime($file);
29
-
30
- if ($ftime && $ftime > (time() - $this->_expire)) {
31
- return true;
32
- }
33
- }
34
-
35
- return false;
36
- }
37
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/W3/Cache/File/PgCache/Manager.php DELETED
@@ -1,37 +0,0 @@
1
- <?php
2
-
3
- require_once W3TC_LIB_W3_DIR . '/Cache/File/Manager.php';
4
-
5
- class W3_Cache_File_PgCache_Manager extends W3_Cache_File_Manager {
6
- var $_expire = 0;
7
-
8
- function __construct($config = array()) {
9
- parent::__construct($config);
10
-
11
- $this->_expire = (isset($config['expire']) ? (int) $config['expire'] : 0);
12
-
13
- if (!$this->_expire || $this->_expire > W3TC_CACHE_FILE_EXPIRE_MAX) {
14
- $this->_expire = W3TC_CACHE_FILE_EXPIRE_MAX;
15
- }
16
- }
17
-
18
- function W3_Cache_File_PgCache_Manager($config = array()) {
19
- $this->__construct($config);
20
- }
21
-
22
- function is_valid($file) {
23
- if ($file == $this->_cache_dir . '/.htaccess') {
24
- return true;
25
- }
26
-
27
- if (file_exists($file)) {
28
- $ftime = @filemtime($file);
29
-
30
- if ($ftime && $ftime > (time() - $this->_expire)) {
31
- return true;
32
- }
33
- }
34
-
35
- return false;
36
- }
37
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/W3/Cache/Memcached.php CHANGED
@@ -18,6 +18,8 @@ class W3_Cache_Memcached extends W3_Cache_Base {
18
 
19
  /**
20
  * PHP5 constructor
 
 
21
  */
22
  function __construct($config) {
23
  $this->_memcache = & new Memcache();
@@ -42,6 +44,8 @@ class W3_Cache_Memcached extends W3_Cache_Base {
42
 
43
  /**
44
  * PHP4 constructor
 
 
45
  */
46
  function W3_Cache_Memcached($config) {
47
  $this->__construct($config);
18
 
19
  /**
20
  * PHP5 constructor
21
+ *
22
+ * @param array $config
23
  */
24
  function __construct($config) {
25
  $this->_memcache = & new Memcache();
44
 
45
  /**
46
  * PHP4 constructor
47
+ *
48
+ * @param array $config
49
  */
50
  function W3_Cache_Memcached($config) {
51
  $this->__construct($config);
lib/W3/Cdn.php CHANGED
@@ -54,7 +54,7 @@ class W3_Cdn {
54
  function &instance($engine, $config = array()) {
55
  static $instances = array();
56
 
57
- $instance_key = sprintf('%s_%s', $engine, md5(serialize($config)));
58
 
59
  if (!isset($instances[$instance_key])) {
60
  switch (true) {
54
  function &instance($engine, $config = array()) {
55
  static $instances = array();
56
 
57
+ $instance_key = sprintf('%s_%s', $engine, md5(implode('', $config)));
58
 
59
  if (!isset($instances[$instance_key])) {
60
  switch (true) {
lib/W3/Cdn/Azure.php CHANGED
@@ -87,7 +87,7 @@ class W3_Cdn_Azure extends W3_Cdn_Base {
87
  * @param array $files
88
  * @param array $results
89
  * @param boolean $force_rewrite
90
- * @return void
91
  */
92
  function upload($files, &$results, $force_rewrite = false) {
93
  $error = null;
@@ -95,7 +95,7 @@ class W3_Cdn_Azure extends W3_Cdn_Base {
95
  if (!$this->_init($error)) {
96
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
97
 
98
- return;
99
  }
100
 
101
  foreach ($files as $local_path => $remote_path) {
@@ -107,6 +107,8 @@ class W3_Cdn_Azure extends W3_Cdn_Base {
107
  $results[] = $this->_upload_gzip($local_path, $remote_path_gzip, $force_rewrite);
108
  }
109
  }
 
 
110
  }
111
 
112
  /**
@@ -210,14 +212,15 @@ class W3_Cdn_Azure extends W3_Cdn_Base {
210
  *
211
  * @param array $files
212
  * @param array $results
213
- * @return void
214
  */
215
  function delete($files, &$results) {
216
  $error = null;
217
 
218
  if (!$this->_init($error)) {
219
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
220
- return;
 
221
  }
222
 
223
  foreach ($files as $local_path => $remote_path) {
@@ -239,6 +242,8 @@ class W3_Cdn_Azure extends W3_Cdn_Base {
239
  }
240
  }
241
  }
 
 
242
  }
243
 
244
  /**
@@ -322,7 +327,7 @@ class W3_Cdn_Azure extends W3_Cdn_Base {
322
  /**
323
  * Returns CDN domain
324
  *
325
- * @return string
326
  */
327
  function get_domains() {
328
  if (!empty($this->_config['cname'])) {
87
  * @param array $files
88
  * @param array $results
89
  * @param boolean $force_rewrite
90
+ * @return boolean
91
  */
92
  function upload($files, &$results, $force_rewrite = false) {
93
  $error = null;
95
  if (!$this->_init($error)) {
96
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
97
 
98
+ return false;
99
  }
100
 
101
  foreach ($files as $local_path => $remote_path) {
107
  $results[] = $this->_upload_gzip($local_path, $remote_path_gzip, $force_rewrite);
108
  }
109
  }
110
+
111
+ return !$this->_is_error($results);
112
  }
113
 
114
  /**
212
  *
213
  * @param array $files
214
  * @param array $results
215
+ * @return boolean
216
  */
217
  function delete($files, &$results) {
218
  $error = null;
219
 
220
  if (!$this->_init($error)) {
221
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
222
+
223
+ return false;
224
  }
225
 
226
  foreach ($files as $local_path => $remote_path) {
242
  }
243
  }
244
  }
245
+
246
+ return !$this->_is_error($results);
247
  }
248
 
249
  /**
327
  /**
328
  * Returns CDN domain
329
  *
330
+ * @return array
331
  */
332
  function get_domains() {
333
  if (!empty($this->_config['cname'])) {
lib/W3/Cdn/Base.php CHANGED
@@ -75,10 +75,12 @@ class W3_Cdn_Base {
75
  * @param array $files
76
  * @param array $results
77
  * @param boolean $force_rewrite
78
- * @return void
79
  */
80
  function upload($files, &$results, $force_rewrite = false) {
81
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Not implemented.');
 
 
82
  }
83
 
84
  /**
@@ -86,10 +88,12 @@ class W3_Cdn_Base {
86
  *
87
  * @param array $files
88
  * @param array $results
89
- * @return void
90
  */
91
  function delete($files, &$results) {
92
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Not implemented.');
 
 
93
  }
94
 
95
  /**
@@ -97,10 +101,10 @@ class W3_Cdn_Base {
97
  *
98
  * @param array $files
99
  * @param array $results
100
- * @return void
101
  */
102
  function purge($files, &$results) {
103
- $this->upload($files, $results, true);
104
  }
105
 
106
  /**
75
  * @param array $files
76
  * @param array $results
77
  * @param boolean $force_rewrite
78
+ * @return boolean
79
  */
80
  function upload($files, &$results, $force_rewrite = false) {
81
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Not implemented.');
82
+
83
+ return false;
84
  }
85
 
86
  /**
88
  *
89
  * @param array $files
90
  * @param array $results
91
+ * @return boolean
92
  */
93
  function delete($files, &$results) {
94
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Not implemented.');
95
+
96
+ return false;
97
  }
98
 
99
  /**
101
  *
102
  * @param array $files
103
  * @param array $results
104
+ * @return boolean
105
  */
106
  function purge($files, &$results) {
107
+ return $this->upload($files, $results, true);
108
  }
109
 
110
  /**
lib/W3/Cdn/Ftp.php CHANGED
@@ -120,6 +120,7 @@ class W3_Cdn_Ftp extends W3_Cdn_Base {
120
  * Sends MDTM command
121
  *
122
  * @param string $remote_file
 
123
  * @return boolean
124
  */
125
  function _mdtm($remote_file, $mtime) {
@@ -134,7 +135,7 @@ class W3_Cdn_Ftp extends W3_Cdn_Base {
134
  * @param array $files
135
  * @param array $results
136
  * @param boolean $force_rewrite
137
- * @return void
138
  */
139
  function upload($files, &$results, $force_rewrite = false) {
140
  $error = null;
@@ -142,7 +143,7 @@ class W3_Cdn_Ftp extends W3_Cdn_Base {
142
  if (!$this->_connect($error)) {
143
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
144
 
145
- return;
146
  }
147
 
148
  $this->_set_error_handler();
@@ -155,7 +156,7 @@ class W3_Cdn_Ftp extends W3_Cdn_Base {
155
  $this->_restore_error_handler();
156
  $this->_disconnect();
157
 
158
- return;
159
  }
160
 
161
  foreach ($files as $local_path => $remote_path) {
@@ -214,6 +215,8 @@ class W3_Cdn_Ftp extends W3_Cdn_Base {
214
 
215
  $this->_restore_error_handler();
216
  $this->_disconnect();
 
 
217
  }
218
 
219
  /**
@@ -221,7 +224,7 @@ class W3_Cdn_Ftp extends W3_Cdn_Base {
221
  *
222
  * @param array $files
223
  * @param array $results
224
- * @return void
225
  */
226
  function delete($files, &$results) {
227
  $error = null;
@@ -229,7 +232,7 @@ class W3_Cdn_Ftp extends W3_Cdn_Base {
229
  if (!$this->_connect($error)) {
230
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
231
 
232
- return;
233
  }
234
 
235
  $this->_set_error_handler();
@@ -254,6 +257,8 @@ class W3_Cdn_Ftp extends W3_Cdn_Base {
254
 
255
  $this->_restore_error_handler();
256
  $this->_disconnect();
 
 
257
  }
258
 
259
  /**
@@ -354,7 +359,7 @@ class W3_Cdn_Ftp extends W3_Cdn_Base {
354
  /**
355
  * Returns array of CDN domains
356
  *
357
- * @return string
358
  */
359
  function get_domains() {
360
  if (!empty($this->_config['domain'])) {
120
  * Sends MDTM command
121
  *
122
  * @param string $remote_file
123
+ * @param integer $mtime
124
  * @return boolean
125
  */
126
  function _mdtm($remote_file, $mtime) {
135
  * @param array $files
136
  * @param array $results
137
  * @param boolean $force_rewrite
138
+ * @return boolean
139
  */
140
  function upload($files, &$results, $force_rewrite = false) {
141
  $error = null;
143
  if (!$this->_connect($error)) {
144
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
145
 
146
+ return false;
147
  }
148
 
149
  $this->_set_error_handler();
156
  $this->_restore_error_handler();
157
  $this->_disconnect();
158
 
159
+ return false;
160
  }
161
 
162
  foreach ($files as $local_path => $remote_path) {
215
 
216
  $this->_restore_error_handler();
217
  $this->_disconnect();
218
+
219
+ return !$this->_is_error($results);
220
  }
221
 
222
  /**
224
  *
225
  * @param array $files
226
  * @param array $results
227
+ * @return boolean
228
  */
229
  function delete($files, &$results) {
230
  $error = null;
232
  if (!$this->_connect($error)) {
233
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
234
 
235
+ return false;
236
  }
237
 
238
  $this->_set_error_handler();
257
 
258
  $this->_restore_error_handler();
259
  $this->_disconnect();
260
+
261
+ return !$this->_is_error($results);
262
  }
263
 
264
  /**
359
  /**
360
  * Returns array of CDN domains
361
  *
362
+ * @return array
363
  */
364
  function get_domains() {
365
  if (!empty($this->_config['domain'])) {
lib/W3/Cdn/Mirror.php CHANGED
@@ -37,10 +37,12 @@ class W3_Cdn_Mirror extends W3_Cdn_Base {
37
  * @param array $files
38
  * @param array $results
39
  * @param boolean $force_rewrite
40
- * @return void
41
  */
42
  function upload($files, &$results, $force_rewrite = false) {
43
  $results = $this->_get_results($files, W3TC_CDN_RESULT_OK, 'OK');
 
 
44
  }
45
 
46
  /**
@@ -48,10 +50,12 @@ class W3_Cdn_Mirror extends W3_Cdn_Base {
48
  *
49
  * @param array $files
50
  * @param array $results
51
- * @return void
52
  */
53
  function delete($files, &$results) {
54
  $results = $this->_get_results($files, W3TC_CDN_RESULT_OK, 'OK');
 
 
55
  }
56
 
57
  /**
37
  * @param array $files
38
  * @param array $results
39
  * @param boolean $force_rewrite
40
+ * @return boolean
41
  */
42
  function upload($files, &$results, $force_rewrite = false) {
43
  $results = $this->_get_results($files, W3TC_CDN_RESULT_OK, 'OK');
44
+
45
+ return true;
46
  }
47
 
48
  /**
50
  *
51
  * @param array $files
52
  * @param array $results
53
+ * @return boolean
54
  */
55
  function delete($files, &$results) {
56
  $results = $this->_get_results($files, W3TC_CDN_RESULT_OK, 'OK');
57
+
58
+ return true;
59
  }
60
 
61
  /**
lib/W3/Cdn/Mirror/Cotendo.php CHANGED
@@ -42,25 +42,25 @@ class W3_Cdn_Mirror_Cotendo extends W3_Cdn_Mirror {
42
  *
43
  * @param array $files
44
  * @param array $results
45
- * @return void
46
  */
47
  function purge($files, &$results) {
48
  if (empty($this->_config['username'])) {
49
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Empty username.');
50
 
51
- return;
52
  }
53
 
54
  if (empty($this->_config['password'])) {
55
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Empty password.');
56
 
57
- return;
58
  }
59
 
60
  if (empty($this->_config['zones'])) {
61
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Empty zones list.');
62
 
63
- return;
64
  }
65
 
66
  require_once W3TC_LIB_NUSOAP_DIR . '/nusoap.php';
@@ -75,7 +75,7 @@ class W3_Cdn_Mirror_Cotendo extends W3_Cdn_Mirror {
75
  if ($error) {
76
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, sprintf('Constructor error (%s).', $error));
77
 
78
- return;
79
  }
80
 
81
  $client->authtype = 'basic';
@@ -103,7 +103,7 @@ class W3_Cdn_Mirror_Cotendo extends W3_Cdn_Mirror {
103
  if ($client->fault) {
104
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Invalid response.');
105
 
106
- return;
107
  }
108
 
109
  $error = $client->getError();
@@ -111,10 +111,12 @@ class W3_Cdn_Mirror_Cotendo extends W3_Cdn_Mirror {
111
  if ($error) {
112
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, sprintf('Unable to purge (%s).', $error));
113
 
114
- return;
115
  }
116
  }
117
 
118
  $results = $this->_get_results($files, W3TC_CDN_RESULT_OK, 'OK');
 
 
119
  }
120
  }
42
  *
43
  * @param array $files
44
  * @param array $results
45
+ * @return boolean
46
  */
47
  function purge($files, &$results) {
48
  if (empty($this->_config['username'])) {
49
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Empty username.');
50
 
51
+ return false;
52
  }
53
 
54
  if (empty($this->_config['password'])) {
55
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Empty password.');
56
 
57
+ return false;
58
  }
59
 
60
  if (empty($this->_config['zones'])) {
61
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Empty zones list.');
62
 
63
+ return false;
64
  }
65
 
66
  require_once W3TC_LIB_NUSOAP_DIR . '/nusoap.php';
75
  if ($error) {
76
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, sprintf('Constructor error (%s).', $error));
77
 
78
+ return false;
79
  }
80
 
81
  $client->authtype = 'basic';
103
  if ($client->fault) {
104
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Invalid response.');
105
 
106
+ return false;
107
  }
108
 
109
  $error = $client->getError();
111
  if ($error) {
112
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, sprintf('Unable to purge (%s).', $error));
113
 
114
+ return false;
115
  }
116
  }
117
 
118
  $results = $this->_get_results($files, W3TC_CDN_RESULT_OK, 'OK');
119
+
120
+ return true;
121
  }
122
  }
lib/W3/Cdn/Mirror/Netdna.php CHANGED
@@ -40,25 +40,25 @@ class W3_Cdn_Mirror_Netdna extends W3_Cdn_Mirror {
40
  *
41
  * @param array $files
42
  * @param array $results
43
- * @return void
44
  */
45
  function purge($files, &$results) {
46
  if (empty($this->_config['apiid'])) {
47
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Empty API ID.');
48
 
49
- return;
50
  }
51
 
52
  if (empty($this->_config['apikey'])) {
53
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Empty API key.');
54
 
55
- return;
56
  }
57
 
58
  if ($this->_sha256('test') === false) {
59
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, "hash() or mhash() function doesn't exists.");
60
 
61
- return;
62
  }
63
 
64
  if (!class_exists('IXR_Client')) {
@@ -101,6 +101,31 @@ class W3_Cdn_Mirror_Netdna extends W3_Cdn_Mirror {
101
  if (function_exists('date_default_timezone_set')) {
102
  date_default_timezone_set($timezone);
103
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  }
105
 
106
  /**
40
  *
41
  * @param array $files
42
  * @param array $results
43
+ * @return boolean
44
  */
45
  function purge($files, &$results) {
46
  if (empty($this->_config['apiid'])) {
47
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Empty API ID.');
48
 
49
+ return false;
50
  }
51
 
52
  if (empty($this->_config['apikey'])) {
53
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'Empty API key.');
54
 
55
+ return false;
56
  }
57
 
58
  if ($this->_sha256('test') === false) {
59
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, "hash() or mhash() function doesn't exists.");
60
 
61
+ return false;
62
  }
63
 
64
  if (!class_exists('IXR_Client')) {
101
  if (function_exists('date_default_timezone_set')) {
102
  date_default_timezone_set($timezone);
103
  }
104
+
105
+ return !$this->_is_error($results);
106
+ }
107
+
108
+ /**
109
+ * Tests NetDNA
110
+ *
111
+ * @param string $error
112
+ * @return bool
113
+ */
114
+ function test(&$error) {
115
+ if (!parent::test($error)) {
116
+ return false;
117
+ }
118
+
119
+ $results = array();
120
+ $files = array('' => 'purge_test_' . time());
121
+
122
+ if (!$this->purge($files, $results) && isset($results[0]['error'])) {
123
+ $error = $results[0]['error'];
124
+
125
+ return false;
126
+ }
127
+
128
+ return true;
129
  }
130
 
131
  /**
lib/W3/Cdn/Rscf.php CHANGED
@@ -139,7 +139,7 @@ class W3_Cdn_Rscf extends W3_Cdn_Base {
139
  * @param array $files
140
  * @param array $results
141
  * @param boolean $force_rewrite
142
- * @return void
143
  */
144
  function upload($files, &$results, $force_rewrite = false) {
145
  $error = null;
@@ -147,7 +147,7 @@ class W3_Cdn_Rscf extends W3_Cdn_Base {
147
  if (!$this->_init($error) || !$this->_init_container($error)) {
148
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
149
 
150
- return;
151
  }
152
 
153
  foreach ($files as $local_path => $remote_path) {
@@ -192,6 +192,8 @@ class W3_Cdn_Rscf extends W3_Cdn_Base {
192
  $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, sprintf('Unable to write object (%s).', $exception->getMessage()));
193
  }
194
  }
 
 
195
  }
196
 
197
  /**
@@ -199,7 +201,7 @@ class W3_Cdn_Rscf extends W3_Cdn_Base {
199
  *
200
  * @param array $files
201
  * @param array $results
202
- * @return void
203
  */
204
  function delete($files, &$results) {
205
  $error = null;
@@ -207,7 +209,7 @@ class W3_Cdn_Rscf extends W3_Cdn_Base {
207
  if (!$this->_init($error) || !$this->_init_container($error)) {
208
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
209
 
210
- return;
211
  }
212
 
213
  foreach ($files as $local_path => $remote_path) {
@@ -218,6 +220,8 @@ class W3_Cdn_Rscf extends W3_Cdn_Base {
218
  $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, sprintf('Unable to delete object (%s).', $exception->getMessage()));
219
  }
220
  }
 
 
221
  }
222
 
223
  /**
@@ -286,7 +290,7 @@ class W3_Cdn_Rscf extends W3_Cdn_Base {
286
  /**
287
  * Returns CDN domain
288
  *
289
- * @return string
290
  */
291
  function get_domains() {
292
  if (!empty($this->_config['cname'])) {
139
  * @param array $files
140
  * @param array $results
141
  * @param boolean $force_rewrite
142
+ * @return boolean
143
  */
144
  function upload($files, &$results, $force_rewrite = false) {
145
  $error = null;
147
  if (!$this->_init($error) || !$this->_init_container($error)) {
148
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
149
 
150
+ return false;
151
  }
152
 
153
  foreach ($files as $local_path => $remote_path) {
192
  $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, sprintf('Unable to write object (%s).', $exception->getMessage()));
193
  }
194
  }
195
+
196
+ return !$this->_is_error($results);
197
  }
198
 
199
  /**
201
  *
202
  * @param array $files
203
  * @param array $results
204
+ * @return boolean
205
  */
206
  function delete($files, &$results) {
207
  $error = null;
209
  if (!$this->_init($error) || !$this->_init_container($error)) {
210
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
211
 
212
+ return false;
213
  }
214
 
215
  foreach ($files as $local_path => $remote_path) {
220
  $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, sprintf('Unable to delete object (%s).', $exception->getMessage()));
221
  }
222
  }
223
+
224
+ return !$this->_is_error($results);
225
  }
226
 
227
  /**
290
  /**
291
  * Returns CDN domain
292
  *
293
+ * @return array
294
  */
295
  function get_domains() {
296
  if (!empty($this->_config['cname'])) {
lib/W3/Cdn/S3.php CHANGED
@@ -81,7 +81,7 @@ class W3_Cdn_S3 extends W3_Cdn_Base {
81
  * @param array $files
82
  * @param array $results
83
  * @param boolean $force_rewrite
84
- * @return void
85
  */
86
  function upload($files, &$results, $force_rewrite = false) {
87
  $error = null;
@@ -89,7 +89,7 @@ class W3_Cdn_S3 extends W3_Cdn_Base {
89
  if (!$this->_init($error)) {
90
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
91
 
92
- return;
93
  }
94
 
95
  foreach ($files as $local_path => $remote_path) {
@@ -101,6 +101,8 @@ class W3_Cdn_S3 extends W3_Cdn_Base {
101
  $results[] = $this->_upload_gzip($local_path, $remote_path_gzip, $force_rewrite);
102
  }
103
  }
 
 
104
  }
105
 
106
  /**
@@ -206,7 +208,7 @@ class W3_Cdn_S3 extends W3_Cdn_Base {
206
  *
207
  * @param array $files
208
  * @param array $results
209
- * @return void
210
  */
211
  function delete($files, &$results) {
212
  $error = null;
@@ -214,7 +216,7 @@ class W3_Cdn_S3 extends W3_Cdn_Base {
214
  if (!$this->_init($error)) {
215
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
216
 
217
- return;
218
  }
219
 
220
  foreach ($files as $local_path => $remote_path) {
@@ -242,6 +244,8 @@ class W3_Cdn_S3 extends W3_Cdn_Base {
242
  }
243
  }
244
  }
 
 
245
  }
246
 
247
  /**
@@ -322,7 +326,7 @@ class W3_Cdn_S3 extends W3_Cdn_Base {
322
  /**
323
  * Returns CDN domain
324
  *
325
- * @return string
326
  */
327
  function get_domains() {
328
  if (!empty($this->_config['cname'])) {
81
  * @param array $files
82
  * @param array $results
83
  * @param boolean $force_rewrite
84
+ * @return boolean
85
  */
86
  function upload($files, &$results, $force_rewrite = false) {
87
  $error = null;
89
  if (!$this->_init($error)) {
90
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
91
 
92
+ return false;
93
  }
94
 
95
  foreach ($files as $local_path => $remote_path) {
101
  $results[] = $this->_upload_gzip($local_path, $remote_path_gzip, $force_rewrite);
102
  }
103
  }
104
+
105
+ return !$this->_is_error($results);
106
  }
107
 
108
  /**
208
  *
209
  * @param array $files
210
  * @param array $results
211
+ * @return boolean
212
  */
213
  function delete($files, &$results) {
214
  $error = null;
216
  if (!$this->_init($error)) {
217
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
218
 
219
+ return false;
220
  }
221
 
222
  foreach ($files as $local_path => $remote_path) {
244
  }
245
  }
246
  }
247
+
248
+ return !$this->_is_error($results);
249
  }
250
 
251
  /**
326
  /**
327
  * Returns CDN domain
328
  *
329
+ * @return array
330
  */
331
  function get_domains() {
332
  if (!empty($this->_config['cname'])) {
lib/W3/Cdn/S3/Cf.php CHANGED
@@ -101,13 +101,15 @@ class W3_Cdn_S3_Cf extends W3_Cdn_S3 {
101
  * @param array $files
102
  * @param array $results
103
  * @param boolean $force_rewrite
104
- * @return void
105
  */
106
  function upload($files, &$results, $force_rewrite = false) {
107
  if ($this->type == W3TC_CDN_CF_TYPE_S3) {
108
- parent::upload($files, $results, $force_rewrite);
109
  } else {
110
  $results = $this->_get_results($files, W3TC_CDN_RESULT_OK, 'OK');
 
 
111
  }
112
  }
113
 
@@ -116,13 +118,15 @@ class W3_Cdn_S3_Cf extends W3_Cdn_S3 {
116
  *
117
  * @param array $files
118
  * @param array $results
119
- * @return void
120
  */
121
  function delete($files, &$results) {
122
  if ($this->type == W3TC_CDN_CF_TYPE_S3) {
123
- parent::delete($files, $results);
124
  } else {
125
  $results = $this->_get_results($files, W3TC_CDN_RESULT_OK, 'OK');
 
 
126
  }
127
  }
128
 
@@ -131,14 +135,14 @@ class W3_Cdn_S3_Cf extends W3_Cdn_S3 {
131
  *
132
  * @param array $files
133
  * @param array $results
134
- * @return void
135
  */
136
  function purge($files, &$results) {
137
- parent::purge($files, $results);
138
-
139
- if (!$this->_is_error($results)) {
140
- $this->invalidate($files, $results);
141
  }
 
 
142
  }
143
 
144
  /**
@@ -146,13 +150,13 @@ class W3_Cdn_S3_Cf extends W3_Cdn_S3 {
146
  *
147
  * @param array $files
148
  * @param array $results
149
- * @return void
150
  */
151
  function invalidate($files, &$results) {
152
  if (!$this->_init($error)) {
153
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
154
 
155
- return;
156
  }
157
 
158
  $this->_set_error_handler();
@@ -162,13 +166,13 @@ class W3_Cdn_S3_Cf extends W3_Cdn_S3 {
162
  if ($dists === false) {
163
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, sprintf('Unable to list distributions (%s).', $this->_get_last_error()));
164
 
165
- return;
166
  }
167
 
168
  if (!count($dists)) {
169
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'No distributions found.');
170
 
171
- return;
172
  }
173
 
174
  $dist = false;
@@ -184,7 +188,7 @@ class W3_Cdn_S3_Cf extends W3_Cdn_S3 {
184
  if (!$dist) {
185
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, sprintf('Distribution for origin "%s" not found.', $origin));
186
 
187
- return;
188
  }
189
 
190
  $paths = array();
@@ -200,16 +204,18 @@ class W3_Cdn_S3_Cf extends W3_Cdn_S3 {
200
  if (!$invalidation) {
201
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, sprintf('Unable to create invalidation bath (%s).', $this->_get_last_error()));
202
 
203
- return;
204
  }
205
 
206
  $results = $this->_get_results($files, W3TC_CDN_RESULT_OK, 'OK');
 
 
207
  }
208
 
209
  /**
210
  * Returns array of CDN domains
211
  *
212
- * @return string
213
  */
214
  function get_domains() {
215
  if (!empty($this->_config['cname'])) {
@@ -381,7 +387,7 @@ class W3_Cdn_S3_Cf extends W3_Cdn_S3 {
381
  * Update distribution CNAMEs
382
  *
383
  * @param string $error
384
- * @return bool
385
  */
386
  function update_cnames(&$error) {
387
  if (!$this->_init($error)) {
101
  * @param array $files
102
  * @param array $results
103
  * @param boolean $force_rewrite
104
+ * @return boolean
105
  */
106
  function upload($files, &$results, $force_rewrite = false) {
107
  if ($this->type == W3TC_CDN_CF_TYPE_S3) {
108
+ return parent::upload($files, $results, $force_rewrite);
109
  } else {
110
  $results = $this->_get_results($files, W3TC_CDN_RESULT_OK, 'OK');
111
+
112
+ return true;
113
  }
114
  }
115
 
118
  *
119
  * @param array $files
120
  * @param array $results
121
+ * @return boolean
122
  */
123
  function delete($files, &$results) {
124
  if ($this->type == W3TC_CDN_CF_TYPE_S3) {
125
+ return parent::delete($files, $results);
126
  } else {
127
  $results = $this->_get_results($files, W3TC_CDN_RESULT_OK, 'OK');
128
+
129
+ return true;
130
  }
131
  }
132
 
135
  *
136
  * @param array $files
137
  * @param array $results
138
+ * @return boolean
139
  */
140
  function purge($files, &$results) {
141
+ if (parent::purge($files, $results)) {
142
+ return $this->invalidate($files, $results);
 
 
143
  }
144
+
145
+ return false;
146
  }
147
 
148
  /**
150
  *
151
  * @param array $files
152
  * @param array $results
153
+ * @return boolean
154
  */
155
  function invalidate($files, &$results) {
156
  if (!$this->_init($error)) {
157
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
158
 
159
+ return false;
160
  }
161
 
162
  $this->_set_error_handler();
166
  if ($dists === false) {
167
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, sprintf('Unable to list distributions (%s).', $this->_get_last_error()));
168
 
169
+ return false;
170
  }
171
 
172
  if (!count($dists)) {
173
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, 'No distributions found.');
174
 
175
+ return false;
176
  }
177
 
178
  $dist = false;
188
  if (!$dist) {
189
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, sprintf('Distribution for origin "%s" not found.', $origin));
190
 
191
+ return false;
192
  }
193
 
194
  $paths = array();
204
  if (!$invalidation) {
205
  $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, sprintf('Unable to create invalidation bath (%s).', $this->_get_last_error()));
206
 
207
+ return false;
208
  }
209
 
210
  $results = $this->_get_results($files, W3TC_CDN_RESULT_OK, 'OK');
211
+
212
+ return true;
213
  }
214
 
215
  /**
216
  * Returns array of CDN domains
217
  *
218
+ * @return array
219
  */
220
  function get_domains() {
221
  if (!empty($this->_config['cname'])) {
387
  * Update distribution CNAMEs
388
  *
389
  * @param string $error
390
+ * @return boolean
391
  */
392
  function update_cnames(&$error) {
393
  if (!$this->_init($error)) {
lib/W3/CloudFlare.php CHANGED
@@ -27,7 +27,8 @@ class W3_CloudFlare {
27
  '204.93.177.0/24',
28
  '204.93.173.0/24',
29
  '199.27.128.0/21',
30
- '173.245.48.0/20'
 
31
  );
32
 
33
  /**
27
  '204.93.177.0/24',
28
  '204.93.173.0/24',
29
  '199.27.128.0/21',
30
+ '173.245.48.0/20',
31
+ '103.22.200.0/2'
32
  );
33
 
34
  /**
lib/W3/Config.php CHANGED
@@ -240,7 +240,6 @@ class W3_Config {
240
  'varnish.servers' => 'array',
241
 
242
  'browsercache.enabled' => 'boolean',
243
- 'browsercache.id' => 'string',
244
  'browsercache.no404wp' => 'boolean',
245
  'browsercache.no404wp.exceptions' => 'array',
246
  'browsercache.cssjs.compression' => 'boolean',
@@ -295,10 +294,14 @@ class W3_Config {
295
  'notes.cdn_reupload' => 'boolean',
296
  'notes.need_empty_pgcache' => 'boolean',
297
  'notes.need_empty_minify' => 'boolean',
 
298
  'notes.pgcache_rules_core' => 'boolean',
299
  'notes.pgcache_rules_cache' => 'boolean',
 
 
300
  'notes.minify_rules_core' => 'boolean',
301
  'notes.minify_rules_cache' => 'boolean',
 
302
  'notes.support_us' => 'boolean',
303
  'notes.no_curl' => 'boolean',
304
  'notes.no_zlib' => 'boolean',
@@ -375,7 +378,7 @@ class W3_Config {
375
 
376
  'pgcache.enabled' => false,
377
  'pgcache.debug' => false,
378
- 'pgcache.engine' => 'file_pgcache',
379
  'pgcache.file.gc' => 3600,
380
  'pgcache.file.locking' => false,
381
  'pgcache.memcached.servers' => array(
@@ -499,7 +502,7 @@ class W3_Config {
499
  'minify.htmltidy.options.clean' => false,
500
  'minify.htmltidy.options.hide-comments' => true,
501
  'minify.htmltidy.options.wrap' => 0,
502
- 'minify.reject.logged' => true,
503
  'minify.reject.ua' => array(),
504
  'minify.reject.uri' => array(),
505
  'minify.error.notification' => '',
@@ -591,7 +594,6 @@ class W3_Config {
591
  'varnish.servers' => array(),
592
 
593
  'browsercache.enabled' => true,
594
- 'browsercache.id' => '',
595
  'browsercache.no404wp' => false,
596
  'browsercache.no404wp.exceptions' => array(
597
  'robots\.txt',
@@ -816,10 +818,14 @@ class W3_Config {
816
  'notes.cdn_reupload' => false,
817
  'notes.need_empty_pgcache' => false,
818
  'notes.need_empty_minify' => false,
 
819
  'notes.pgcache_rules_core' => true,
820
  'notes.pgcache_rules_cache' => true,
 
 
821
  'notes.minify_rules_core' => true,
822
  'notes.minify_rules_cache' => true,
 
823
  'notes.support_us' => true,
824
  'notes.no_curl' => true,
825
  'notes.no_zlib' => true,
@@ -891,8 +897,15 @@ class W3_Config {
891
  case 'dbcache.engine':
892
  case 'minify.engine':
893
  case 'objectcache.engine':
 
 
 
 
 
 
 
894
  switch (true) {
895
- case ($value == 'file_pgcache' && !w3_can_check_rules()):
896
  case ($value == 'apc' && !function_exists('apc_store')):
897
  case ($value == 'eaccelerator' && !function_exists('eaccelerator_put')):
898
  case ($value == 'xcache' && !function_exists('xcache_set')):
@@ -915,7 +928,7 @@ class W3_Config {
915
  * Disabled some page cache options when enhanced mode enabled
916
  */
917
  case 'pgcache.cache.query':
918
- if ($this->get_string('pgcache.engine') == 'file_pgcache') {
919
  return false;
920
  }
921
  break;
@@ -1332,7 +1345,6 @@ class W3_Config {
1332
  */
1333
  function set_defaults() {
1334
  $this->set('pgcache.enabled', true);
1335
- $this->set('minify.enabled', true);
1336
  $this->set('minify.auto', true);
1337
  $this->set('browsercache.enabled', true);
1338
  }
240
  'varnish.servers' => 'array',
241
 
242
  'browsercache.enabled' => 'boolean',
 
243
  'browsercache.no404wp' => 'boolean',
244
  'browsercache.no404wp.exceptions' => 'array',
245
  'browsercache.cssjs.compression' => 'boolean',
294
  'notes.cdn_reupload' => 'boolean',
295
  'notes.need_empty_pgcache' => 'boolean',
296
  'notes.need_empty_minify' => 'boolean',
297
+ 'notes.need_empty_objectcache' => 'boolean',
298
  'notes.pgcache_rules_core' => 'boolean',
299
  'notes.pgcache_rules_cache' => 'boolean',
300
+ 'notes.pgcache_rules_legacy' => 'boolean',
301
+ 'notes.pgcache_rules_wpsc' => 'boolean',
302
  'notes.minify_rules_core' => 'boolean',
303
  'notes.minify_rules_cache' => 'boolean',
304
+ 'notes.minify_rules_legacy' => 'boolean',
305
  'notes.support_us' => 'boolean',
306
  'notes.no_curl' => 'boolean',
307
  'notes.no_zlib' => 'boolean',
378
 
379
  'pgcache.enabled' => false,
380
  'pgcache.debug' => false,
381
+ 'pgcache.engine' => 'file_generic',
382
  'pgcache.file.gc' => 3600,
383
  'pgcache.file.locking' => false,
384
  'pgcache.memcached.servers' => array(
502
  'minify.htmltidy.options.clean' => false,
503
  'minify.htmltidy.options.hide-comments' => true,
504
  'minify.htmltidy.options.wrap' => 0,
505
+ 'minify.reject.logged' => false,
506
  'minify.reject.ua' => array(),
507
  'minify.reject.uri' => array(),
508
  'minify.error.notification' => '',
594
  'varnish.servers' => array(),
595
 
596
  'browsercache.enabled' => true,
 
597
  'browsercache.no404wp' => false,
598
  'browsercache.no404wp.exceptions' => array(
599
  'robots\.txt',
818
  'notes.cdn_reupload' => false,
819
  'notes.need_empty_pgcache' => false,
820
  'notes.need_empty_minify' => false,
821
+ 'notes.need_empty_objectcache' => false,
822
  'notes.pgcache_rules_core' => true,
823
  'notes.pgcache_rules_cache' => true,
824
+ 'notes.pgcache_rules_legacy' => true,
825
+ 'notes.pgcache_rules_wpsc' => true,
826
  'notes.minify_rules_core' => true,
827
  'notes.minify_rules_cache' => true,
828
+ 'notes.minify_rules_legacy' => true,
829
  'notes.support_us' => true,
830
  'notes.no_curl' => true,
831
  'notes.no_zlib' => true,
897
  case 'dbcache.engine':
898
  case 'minify.engine':
899
  case 'objectcache.engine':
900
+ /**
901
+ * Legacy support
902
+ */
903
+ if ($value == 'file_pgcache') {
904
+ $value = 'file_generic';
905
+ }
906
+
907
  switch (true) {
908
+ case ($value == 'file_generic' && !w3_can_check_rules()):
909
  case ($value == 'apc' && !function_exists('apc_store')):
910
  case ($value == 'eaccelerator' && !function_exists('eaccelerator_put')):
911
  case ($value == 'xcache' && !function_exists('xcache_set')):
928
  * Disabled some page cache options when enhanced mode enabled
929
  */
930
  case 'pgcache.cache.query':
931
+ if ($this->get_string('pgcache.engine') == 'file_generic') {
932
  return false;
933
  }
934
  break;
1345
  */
1346
  function set_defaults() {
1347
  $this->set('pgcache.enabled', true);
 
1348
  $this->set('minify.auto', true);
1349
  $this->set('browsercache.enabled', true);
1350
  }
lib/W3/Db.php CHANGED
@@ -3,14 +3,17 @@
3
  /**
4
  * W3 Database object
5
  */
6
- $wpdb = false;
 
7
 
8
- require_once ABSPATH . 'wp-includes/wp-db.php';
 
 
9
 
10
  /**
11
  * Class W3_Db
12
  */
13
- class W3_Db extends wpdb {
14
  /**
15
  * Array of queries
16
  *
@@ -76,9 +79,9 @@ class W3_Db extends wpdb {
76
 
77
  if ($this->_can_ob()) {
78
  ob_start(array(
79
- &$this,
80
- 'ob_callback'
81
- ));
82
  }
83
 
84
  parent::__construct($dbuser, $dbpassword, $dbname, $dbhost);
@@ -107,30 +110,15 @@ class W3_Db extends wpdb {
107
  return false;
108
  }
109
 
110
- ++$this->query_total;
111
-
112
- // Filter the query, if filters are available
113
- // NOTE: Some queries are made before the plugins have been loaded, and thus cannot be filtered with this method
114
- if (function_exists('apply_filters')) {
115
- $query = apply_filters('query', $query);
116
- }
117
-
118
- // Initialise return
119
- $return_val = 0;
120
- $this->flush();
121
-
122
- // Log how the function was called
123
- $this->func_call = "\$db->query(\"$query\")";
124
-
125
- // Keep track of the last query for debug..
126
- $this->last_query = $query;
127
-
128
  $reason = '';
129
- $caching = $this->_can_cache($query, $reason);
130
  $cached = false;
131
  $data = false;
132
  $time_total = 0;
133
 
 
 
 
 
134
  if ($caching) {
135
  $this->timer_start();
136
  $cache_key = $this->_get_cache_key($query);
@@ -139,88 +127,36 @@ class W3_Db extends wpdb {
139
  $time_total = $this->timer_stop();
140
  }
141
 
142
- /**
143
- * Check if query was cached
144
- */
145
  if (is_array($data)) {
146
- ++$this->query_hits;
147
  $cached = true;
 
148
 
149
- /**
150
- * Set result from the cache
151
- */
152
  $this->last_error = $data['last_error'];
153
  $this->last_query = $data['last_query'];
154
  $this->last_result = $data['last_result'];
155
  $this->col_info = $data['col_info'];
156
  $this->num_rows = $data['num_rows'];
 
 
157
  } else {
158
- ++$this->num_queries;
159
- ++$this->query_misses;
160
 
161
- // Perform the query via std mysql_query function..
162
  $this->timer_start();
163
- $this->result = @mysql_query($query, $this->dbh);
164
  $time_total = $this->timer_stop();
165
 
166
- if (defined('SAVEQUERIES') && SAVEQUERIES) {
167
- $this->queries[] = array(
168
- $query,
169
- $time_total,
170
- $this->get_caller()
 
 
 
171
  );
172
- }
173
-
174
- // If there is an error then take note of it..
175
- if (($this->last_error = mysql_error($this->dbh))) {
176
- $this->print_error();
177
- return false;
178
- }
179
-
180
- if (preg_match("/^\\s*(insert|delete|update|replace|alter)\\s+/si", $query)) {
181
- $this->rows_affected = mysql_affected_rows($this->dbh);
182
- // Take note of the insert_id
183
- if (preg_match("/^\\s*(insert|replace) /i", $query)) {
184
- $this->insert_id = mysql_insert_id($this->dbh);
185
- }
186
- // Return number of rows affected
187
- $return_val = $this->rows_affected;
188
- } elseif (is_resource($this->result)) {
189
- $i = 0;
190
- while ($i < @mysql_num_fields($this->result)) {
191
- $this->col_info[$i] = @mysql_fetch_field($this->result);
192
- $i++;
193
- }
194
-
195
- $num_rows = 0;
196
- while (($row = @mysql_fetch_object($this->result))) {
197
- $this->last_result[$num_rows] = $row;
198
- $num_rows++;
199
- }
200
-
201
- @mysql_free_result($this->result);
202
-
203
- // Log number of rows the query returned
204
- $this->num_rows = $num_rows;
205
-
206
- // Return number of rows selected
207
- $return_val = $this->num_rows;
208
 
209
- if ($caching) {
210
- /**
211
- * Store result to the cache
212
- */
213
- $data = array(
214
- 'last_error' => $this->last_error,
215
- 'last_query' => $this->last_query,
216
- 'last_result' => $this->last_result,
217
- 'col_info' => $this->col_info,
218
- 'num_rows' => $this->num_rows
219
- );
220
-
221
- $cache = & $this->_get_cache();
222
- $cache->set($cache_key, $data, $this->_lifetime);
223
- }
224
  }
225
  }
226
 
@@ -323,6 +259,7 @@ class W3_Db extends wpdb {
323
  * Check if can cache sql
324
  *
325
  * @param string $sql
 
326
  * @return boolean
327
  */
328
  function _can_cache($sql, &$cache_reject_reason) {
@@ -330,7 +267,7 @@ class W3_Db extends wpdb {
330
  * Skip if disabled
331
  */
332
  if (!$this->_config->get_boolean('dbcache.enabled')) {
333
- $cache_reject_reason = 'database caching is disabled';
334
 
335
  return false;
336
  }
@@ -348,7 +285,7 @@ class W3_Db extends wpdb {
348
  * Skip if doint AJAX
349
  */
350
  if (defined('DOING_AJAX')) {
351
- $cache_reject_reason = 'doing AJAX';
352
 
353
  return false;
354
  }
@@ -357,7 +294,7 @@ class W3_Db extends wpdb {
357
  * Skip if doing cron
358
  */
359
  if (defined('DOING_CRON')) {
360
- $cache_reject_reason = 'doing cron';
361
 
362
  return false;
363
  }
@@ -366,7 +303,7 @@ class W3_Db extends wpdb {
366
  * Skip if APP request
367
  */
368
  if (defined('APP_REQUEST')) {
369
- $cache_reject_reason = 'application request';
370
 
371
  return false;
372
  }
@@ -402,7 +339,7 @@ class W3_Db extends wpdb {
402
  * Skip if SQL is rejected
403
  */
404
  if (!$this->_check_sql($sql)) {
405
- $cache_reject_reason = 'query is rejected';
406
 
407
  return false;
408
  }
@@ -411,7 +348,7 @@ class W3_Db extends wpdb {
411
  * Skip if request URI is rejected
412
  */
413
  if (!$this->_check_request_uri()) {
414
- $cache_reject_reason = 'request URI is rejected';
415
 
416
  return false;
417
  }
@@ -420,7 +357,7 @@ class W3_Db extends wpdb {
420
  * Skip if cookie is rejected
421
  */
422
  if (!$this->_check_cookies()) {
423
- $cache_reject_reason = 'cookie is rejected';
424
 
425
  return false;
426
  }
@@ -429,7 +366,7 @@ class W3_Db extends wpdb {
429
  * Skip if user is logged in
430
  */
431
  if ($this->_config->get_boolean('dbcache.reject.logged') && !$this->_check_logged_in()) {
432
- $cache_reject_reason = 'user is logged in';
433
 
434
  return false;
435
  }
@@ -499,6 +436,13 @@ class W3_Db extends wpdb {
499
  return false;
500
  }
501
 
 
 
 
 
 
 
 
502
  return true;
503
  }
504
 
@@ -646,9 +590,22 @@ class W3_Db extends wpdb {
646
 
647
  if (count($this->query_stats)) {
648
  $debug_info .= "SQL info:\r\n";
649
- $debug_info .= sprintf("%s | %s | %s | % s | %s | %s\r\n", str_pad('#', 5, ' ', STR_PAD_LEFT), str_pad('Time (s)', 8, ' ', STR_PAD_LEFT), str_pad('Caching (Reject reason)', 30, ' ', STR_PAD_BOTH), str_pad('Status', 10, ' ', STR_PAD_BOTH), str_pad('Data size (b)', 13, ' ', STR_PAD_LEFT), 'Query');
 
 
 
 
 
 
650
  foreach ($this->query_stats as $index => $query) {
651
- $debug_info .= sprintf("%s | %s | %s | %s | %s | %s\r\n", str_pad($index + 1, 5, ' ', STR_PAD_LEFT), str_pad(round($query['time_total'], 4), 8, ' ', STR_PAD_LEFT), str_pad(($query['caching'] ? 'enabled' : sprintf('disabled (%s)', $query['reason'])), 30, ' ', STR_PAD_BOTH), str_pad(($query['cached'] ? 'cached' : 'not cached'), 10, ' ', STR_PAD_BOTH), str_pad($query['data_size'], 13, ' ', STR_PAD_LEFT), w3_escape_comment(trim($query['query'])));
 
 
 
 
 
 
 
652
  }
653
  }
654
 
3
  /**
4
  * W3 Database object
5
  */
6
+ if (!class_exists('W3_Db_Driver')) {
7
+ require_once ABSPATH . 'wp-includes/wp-db.php';
8
 
9
+ class W3_Db_Driver extends wpdb {
10
+ }
11
+ }
12
 
13
  /**
14
  * Class W3_Db
15
  */
16
+ class W3_Db extends W3_Db_Driver {
17
  /**
18
  * Array of queries
19
  *
79
 
80
  if ($this->_can_ob()) {
81
  ob_start(array(
82
+ &$this,
83
+ 'ob_callback'
84
+ ));
85
  }
86
 
87
  parent::__construct($dbuser, $dbpassword, $dbname, $dbhost);
110
  return false;
111
  }
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  $reason = '';
 
114
  $cached = false;
115
  $data = false;
116
  $time_total = 0;
117
 
118
+ $this->query_total++;
119
+
120
+ $caching = $this->_can_cache($query, $reason);
121
+
122
  if ($caching) {
123
  $this->timer_start();
124
  $cache_key = $this->_get_cache_key($query);
127
  $time_total = $this->timer_stop();
128
  }
129
 
 
 
 
130
  if (is_array($data)) {
 
131
  $cached = true;
132
+ $this->query_hits++;
133
 
 
 
 
134
  $this->last_error = $data['last_error'];
135
  $this->last_query = $data['last_query'];
136
  $this->last_result = $data['last_result'];
137
  $this->col_info = $data['col_info'];
138
  $this->num_rows = $data['num_rows'];
139
+
140
+ $return_val = $data['return_val'];
141
  } else {
142
+ $this->query_misses++;
 
143
 
 
144
  $this->timer_start();
145
+ $return_val = parent::query($query);
146
  $time_total = $this->timer_stop();
147
 
148
+ if ($caching) {
149
+ $data = array(
150
+ 'last_error' => $this->last_error,
151
+ 'last_query' => $this->last_query,
152
+ 'last_result' => $this->last_result,
153
+ 'col_info' => $this->col_info,
154
+ 'num_rows' => $this->num_rows,
155
+ 'return_val' => $return_val
156
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
+ $cache = & $this->_get_cache();
159
+ $cache->set($cache_key, $data, $this->_lifetime);
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  }
161
  }
162
 
259
  * Check if can cache sql
260
  *
261
  * @param string $sql
262
+ * @param string $cache_reject_reason
263
  * @return boolean
264
  */
265
  function _can_cache($sql, &$cache_reject_reason) {
267
  * Skip if disabled
268
  */
269
  if (!$this->_config->get_boolean('dbcache.enabled')) {
270
+ $cache_reject_reason = 'Database caching is disabled';
271
 
272
  return false;
273
  }
285
  * Skip if doint AJAX
286
  */
287
  if (defined('DOING_AJAX')) {
288
+ $cache_reject_reason = 'Doing AJAX';
289
 
290
  return false;
291
  }
294
  * Skip if doing cron
295
  */
296
  if (defined('DOING_CRON')) {
297
+ $cache_reject_reason = 'Doing cron';
298
 
299
  return false;
300
  }
303
  * Skip if APP request
304
  */
305
  if (defined('APP_REQUEST')) {
306
+ $cache_reject_reason = 'Application request';
307
 
308
  return false;
309
  }
339
  * Skip if SQL is rejected
340
  */
341
  if (!$this->_check_sql($sql)) {
342
+ $cache_reject_reason = 'Query is rejected';
343
 
344
  return false;
345
  }
348
  * Skip if request URI is rejected
349
  */
350
  if (!$this->_check_request_uri()) {
351
+ $cache_reject_reason = 'Request URI is rejected';
352
 
353
  return false;
354
  }
357
  * Skip if cookie is rejected
358
  */
359
  if (!$this->_check_cookies()) {
360
+ $cache_reject_reason = 'Cookie is rejected';
361
 
362
  return false;
363
  }
366
  * Skip if user is logged in
367
  */
368
  if ($this->_config->get_boolean('dbcache.reject.logged') && !$this->_check_logged_in()) {
369
+ $cache_reject_reason = 'User is logged in';
370
 
371
  return false;
372
  }
436
  return false;
437
  }
438
 
439
+ /**
440
+ * Check User Agent
441
+ */
442
+ if (isset($_SERVER['HTTP_USER_AGENT']) && stristr($_SERVER['HTTP_USER_AGENT'], W3TC_POWERED_BY) !== false) {
443
+ return false;
444
+ }
445
+
446
  return true;
447
  }
448
 
590
 
591
  if (count($this->query_stats)) {
592
  $debug_info .= "SQL info:\r\n";
593
+ $debug_info .= sprintf("%s | %s | %s | % s | %s | %s\r\n",
594
+ str_pad('#', 5, ' ', STR_PAD_LEFT), str_pad('Time (s)', 8, ' ', STR_PAD_LEFT),
595
+ str_pad('Caching (Reject reason)', 30, ' ', STR_PAD_BOTH),
596
+ str_pad('Status', 10, ' ', STR_PAD_BOTH),
597
+ str_pad('Data size (b)', 13, ' ', STR_PAD_LEFT),
598
+ 'Query');
599
+
600
  foreach ($this->query_stats as $index => $query) {
601
+ $debug_info .= sprintf("%s | %s | %s | %s | %s | %s\r\n",
602
+ str_pad($index + 1, 5, ' ', STR_PAD_LEFT),
603
+ str_pad(round($query['time_total'], 4), 8, ' ', STR_PAD_LEFT),
604
+ str_pad(($query['caching'] ? 'enabled'
605
+ : sprintf('disabled (%s)', $query['reason'])), 30, ' ', STR_PAD_BOTH),
606
+ str_pad(($query['cached'] ? 'cached' : 'not cached'), 10, ' ', STR_PAD_BOTH),
607
+ str_pad($query['data_size'], 13, ' ', STR_PAD_LEFT),
608
+ w3_escape_comment(trim($query['query'])));
609
  }
610
  }
611
 
lib/W3/Minifier.php CHANGED
@@ -285,37 +285,14 @@ class W3_Minifier {
285
  break;
286
  }
287
 
288
- if ($this->_config->get_boolean('browsercache.enabled')) {
289
- $types = array();
290
- $extensions = array();
291
-
292
  require_once W3TC_LIB_W3_DIR . '/Plugin/BrowserCache.php';
293
  $w3_plugin_browsercache =& W3_Plugin_Browsercache::instance();
294
 
295
- if ($this->_config->get_boolean('browsercache.cssjs.replace')) {
296
- $types = array_merge($types, array_keys($w3_plugin_browsercache->get_cssjs_types()));
297
- }
298
-
299
- if ($this->_config->get_boolean('browsercache.html.replace')) {
300
- $types = array_merge($types, array_keys($w3_plugin_browsercache->get_html_types()));
301
- }
302
-
303
- if ($this->_config->get_boolean('browsercache.other.replace')) {
304
- $types = array_merge($types, array_keys($w3_plugin_browsercache->get_other_types()));
305
- }
306
-
307
- if (count($types)) {
308
- foreach ($types as $type) {
309
- $extensions = array_merge($extensions, explode('|', $type));
310
- }
311
-
312
- $id = $this->_config->get_string('browsercache.id', date('Ymd'));
313
-
314
- $options = array_merge($options, array(
315
- 'browserCacheId' => $id,
316
- 'browserCacheExtensions' => $extensions
317
- ));
318
- }
319
  }
320
 
321
  return $options;
285
  break;
286
  }
287
 
288
+ if ($this->_config->get_boolean('browsercache.enabled') && ($this->_config->get_boolean('browsercache.cssjs.replace') || $this->_config->get_boolean('browsercache.html.replace') || $this->_config->get_boolean('browsercache.other.replace'))) {
 
 
 
289
  require_once W3TC_LIB_W3_DIR . '/Plugin/BrowserCache.php';
290
  $w3_plugin_browsercache =& W3_Plugin_Browsercache::instance();
291
 
292
+ $options = array_merge($options, array(
293
+ 'browserCacheId' => $w3_plugin_browsercache->get_replace_id(),
294
+ 'browserCacheExtensions' => $w3_plugin_browsercache->get_replace_extensions()
295
+ ));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  }
297
 
298
  return $options;
lib/W3/Minify.php CHANGED
@@ -51,35 +51,52 @@ class W3_Minify {
51
  $file = W3_Request::get_string('file');
52
 
53
  if (!$file) {
54
- $this->send_error('File param is missing.');
55
  }
56
 
57
  $hash = '';
58
  $matches = null;
59
 
60
- if (preg_match('~^([a-f0-9]+)\\.[0-9]+\\.(css|js)$~', $file, $matches)) {
61
  list(, $hash, $type) = $matches;
62
- } elseif (preg_match('~^([a-f0-9]+)\\/(.+)\\.(include(\\-(footer|body))?(-nb)?)\\.[0-9]+\\.(css|js)$~', $file, $matches)) {
63
  list(, $theme, $template, $location, , , , $type) = $matches;
64
  } else {
65
- $this->send_error('Bad file param format.');
66
  }
67
 
68
  require_once W3TC_LIB_MINIFY_DIR . '/Minify.php';
69
  require_once W3TC_LIB_MINIFY_DIR . '/HTTP/Encoder.php';
70
 
71
  /**
72
- * Fix DOCUMENT_ROOT for minify
73
  */
74
  $_SERVER['DOCUMENT_ROOT'] = w3_get_document_root();
75
 
 
 
 
76
  Minify::setCache($this->_get_cache());
77
 
78
- if ($this->_config->get_boolean('minify.debug')) {
79
- require_once W3TC_LIB_MINIFY_DIR . '/Minify/Logger.php';
80
- Minify_Logger::setLogger($this);
81
- }
 
 
82
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  $browsercache = $this->_config->get_boolean('browsercache.enabled');
84
 
85
  $serve_options = array_merge($this->_config->get_array('minify.options'), array(
@@ -96,6 +113,9 @@ class W3_Minify {
96
  )
97
  ));
98
 
 
 
 
99
  if ($hash) {
100
  $_GET['f'] = $this->get_files($hash, $type);
101
  } else {
@@ -103,6 +123,9 @@ class W3_Minify {
103
  $serve_options['minApp']['groups'] = $this->get_groups($theme, $template, $type);
104
  }
105
 
 
 
 
106
  require_once W3TC_LIB_W3_DIR . '/Minifier.php';
107
  $w3_minifier =& W3_Minifier::instance();
108
 
@@ -139,34 +162,35 @@ class W3_Minify {
139
  }
140
  }
141
 
 
 
 
142
  $w3_minifier->init($engine);
143
 
144
  $serve_options['minifiers'][$minifier_type] = $w3_minifier->get_minifier($engine);
145
  $serve_options['minifierOptions'][$minifier_type] = $w3_minifier->get_options($engine);
146
 
147
- if ($hash) {
148
- $id = $this->get_id_custom($hash, $type);
149
- $cache_id = $this->get_cache_id_custom($hash, $id, $type);
150
- } else {
151
- $id = $this->get_id_group($theme, $template, $location, $type);
152
- $cache_id = $this->get_cache_id_group($theme, $template, $location, $id, $type);
153
- }
154
-
155
- Minify::setCacheId($cache_id);
156
-
157
  if ($browsercache && $this->_config->get_boolean('browsercache.cssjs.w3tc')) {
158
  @header('X-Powered-By: ' . W3TC_POWERED_BY);
159
  }
160
 
 
 
 
161
  try {
162
  Minify::serve('MinApp', $serve_options);
163
  } catch (Exception $exception) {
164
- printf('<strong>W3 Total Cache Error:</strong> Minify error: %s', $exception->getMessage());
165
  }
166
  }
167
 
168
  /**
169
  * Flushes cache
 
 
170
  */
171
  function flush() {
172
  $cache = & $this->_get_cache();
@@ -194,11 +218,10 @@ class W3_Minify {
194
  * Log
195
  *
196
  * @param mixed $object
197
- * @param string $label
198
  * @return bool
199
  */
200
- function log($object, $label = null) {
201
- $data = sprintf("[%s] [%s] [%s] %s\n", date('r'), $_SERVER['REQUEST_URI'], $label, $object);
202
 
203
  return @file_put_contents(W3TC_MINIFY_LOG_FILE, $data, FILE_APPEND);
204
  }
@@ -262,16 +285,15 @@ class W3_Minify {
262
  if ($precached_file) {
263
  $result[$location][$file] = $precached_file;
264
  } else {
265
- $this->_handle_error($file);
266
  }
267
  } else {
268
- $file = urldecode($file);
269
  $path = w3_get_document_root() . '/' . $file;
270
 
271
  if (file_exists($path)) {
272
  $result[$location][$file] = '//' . $file;
273
  } else {
274
- $this->_handle_error($file);
275
  }
276
  }
277
  }
@@ -282,38 +304,16 @@ class W3_Minify {
282
  }
283
 
284
  /**
285
- * Returns cache id for group
286
- *
287
- * @param string $theme
288
- * @param string $template
289
- * @param string $location
290
- * @param integer $id
291
- * @param string $type
292
- * @return string
293
- */
294
- function get_cache_id_group($theme, $template, $location, $id, $type) {
295
- if ($this->_config->get_string('minify.engine') == 'file') {
296
- $cache_id = sprintf('%s/%s.%s.%d.%s', $theme, $template, $location, $id, $type);
297
- } else {
298
- $cache_id = sprintf('w3tc_%s_minify_%s', w3_get_host_id(), md5($theme . $template . $location . $id . $type));
299
- }
300
-
301
- return $cache_id;
302
- }
303
-
304
- /**
305
- * Returns cache id for custom files
306
  *
307
- * @param string $hash
308
- * @param integer $id
309
- * @param string $type
310
  * @return string
311
  */
312
- function get_cache_id_custom($hash, $id, $type) {
313
  if ($this->_config->get_string('minify.engine') == 'file') {
314
- $cache_id = sprintf('%s.%d.%s', $hash, $id, $type);
315
  } else {
316
- $cache_id = sprintf('w3tc_%s_minify_%s', w3_get_host_id(), md5($hash . $id . $type));
317
  }
318
 
319
  return $cache_id;
@@ -422,11 +422,11 @@ class W3_Minify {
422
 
423
  if ($id === false) {
424
  $sources = $this->get_sources_custom($hash, $type);
425
- $id = $this->_generate_id($sources);
426
  $this->_cache_set($key, $id);
427
  }
428
 
429
- return (int) $id;
430
  }
431
 
432
  /**
@@ -444,11 +444,11 @@ class W3_Minify {
444
 
445
  if ($id === false) {
446
  $sources = $this->get_sources_group($theme, $template, $location, $type);
447
- $id = $this->_generate_id($sources);
448
  $this->_cache_set($key, $id);
449
  }
450
 
451
- return (int) $id;
452
  }
453
 
454
  /**
@@ -458,7 +458,7 @@ class W3_Minify {
458
  * @return string
459
  */
460
  function get_custom_files_hash($files) {
461
- return md5(implode('', $files));
462
  }
463
 
464
  /**
@@ -501,8 +501,13 @@ class W3_Minify {
501
  */
502
  function get_custom_files($hash, $type) {
503
  $key = $this->get_custom_files_key($hash, $type);
504
- $files = (array) $this->_cache_get($key);
505
- $files = array_map('w3_normalize_file_minify2', $files);
 
 
 
 
 
506
 
507
  return $files;
508
  }
@@ -513,9 +518,26 @@ class W3_Minify {
513
  * @param string $error
514
  * @return void
515
  */
516
- function send_error($error) {
 
 
 
 
 
 
 
 
517
  header('HTTP/1.0 400 Bad Request');
518
- die($error);
 
 
 
 
 
 
 
 
 
519
  }
520
 
521
  /**
@@ -527,24 +549,13 @@ class W3_Minify {
527
  */
528
  function _precache_file($url, $type) {
529
  $lifetime = $this->_config->get_integer('minify.lifetime');
530
- $file_path = sprintf('%s/minify_%s.%s', W3TC_CACHE_FILE_MINIFY_DIR, md5($url), $type);
531
- $file_exists = file_exists($file_path);
532
 
533
- if ($file_exists && @filemtime($file_path) >= (time() - $lifetime)) {
534
- return $this->_get_minify_source($file_path, $url);
535
  }
536
 
537
- if (@is_dir(W3TC_CACHE_FILE_MINIFY_DIR)) {
538
- if (w3_download($url, $file_path) !== false) {
539
- return $this->_get_minify_source($file_path, $url);
540
- } else {
541
- $this->log(sprintf('Unable to download URL: %s', $url));
542
- }
543
- } else {
544
- $this->log(sprintf('The cache directory %s does not exist', W3TC_CACHE_FILE_MINIFY_DIR));
545
- }
546
-
547
- return ($file_exists ? $this->_get_minify_source($file_path, $url) : false);
548
  }
549
 
550
  /**
@@ -607,14 +618,14 @@ class W3_Minify {
607
 
608
  case 'file':
609
  default:
610
- if (!@is_dir(W3TC_CACHE_FILE_MINIFY_DIR)) {
611
- $this->log(sprintf('Cache directory %s does not exist', W3TC_CACHE_FILE_MINIFY_DIR));
612
- }
613
-
614
  require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/File.php';
615
 
616
  $cache[0] = & new Minify_Cache_File(
617
  W3TC_CACHE_FILE_MINIFY_DIR,
 
 
 
 
618
  $this->_config->get_boolean('minify.file.locking'),
619
  $this->_config->get_integer('timelimit.cache_flush')
620
  );
@@ -628,10 +639,9 @@ class W3_Minify {
628
  /**
629
  * Handle minify error
630
  *
631
- * @param string file
632
  * @return void
633
  */
634
- function _handle_error($file) {
635
  $notification = $this->_config->get_string('minify.error.notification');
636
 
637
  if ($notification) {
@@ -683,22 +693,107 @@ class W3_Minify {
683
  * Generates file ID
684
  *
685
  * @param array $sources
 
686
  * @return string
687
  */
688
- function _generate_id($sources) {
689
- $hash = '';
690
 
691
  foreach ($sources as $source) {
692
  if (file_exists($source)) {
693
  $data = @file_get_contents($source);
694
 
695
  if ($data !== false) {
696
- $hash .= $source . $data;
 
 
697
  }
698
  }
699
  }
700
 
701
- $id = abs(crc32($hash));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
702
 
703
  return $id;
704
  }
51
  $file = W3_Request::get_string('file');
52
 
53
  if (!$file) {
54
+ $this->error('File param is missing');
55
  }
56
 
57
  $hash = '';
58
  $matches = null;
59
 
60
+ if (preg_match('~^([a-f0-9]+)\\.[a-f0-9]+\\.(css|js)$~', $file, $matches)) {
61
  list(, $hash, $type) = $matches;
62
+ } elseif (preg_match('~^([a-f0-9]+)\\/(.+)\\.(include(\\-(footer|body))?(-nb)?)\\.[a-f0-9]+\\.(css|js)$~', $file, $matches)) {
63
  list(, $theme, $template, $location, , , , $type) = $matches;
64
  } else {
65
+ $this->error(sprintf('Bad file param format: "%s"', $file));
66
  }
67
 
68
  require_once W3TC_LIB_MINIFY_DIR . '/Minify.php';
69
  require_once W3TC_LIB_MINIFY_DIR . '/HTTP/Encoder.php';
70
 
71
  /**
72
+ * Fix DOCUMENT_ROOT
73
  */
74
  $_SERVER['DOCUMENT_ROOT'] = w3_get_document_root();
75
 
76
+ /**
77
+ * Set cache engine
78
+ */
79
  Minify::setCache($this->_get_cache());
80
 
81
+ /**
82
+ * Set cache ID
83
+ */
84
+ $cache_id = $this->get_cache_id($file);
85
+
86
+ Minify::setCacheId($cache_id);
87
 
88
+ /**
89
+ * Set logger
90
+ */
91
+ require_once W3TC_LIB_MINIFY_DIR . '/Minify/Logger.php';
92
+ Minify_Logger::setLogger(array(
93
+ &$this,
94
+ 'error')
95
+ );
96
+
97
+ /**
98
+ * Set options
99
+ */
100
  $browsercache = $this->_config->get_boolean('browsercache.enabled');
101
 
102
  $serve_options = array_merge($this->_config->get_array('minify.options'), array(
113
  )
114
  ));
115
 
116
+ /**
117
+ * Set sources
118
+ */
119
  if ($hash) {
120
  $_GET['f'] = $this->get_files($hash, $type);
121
  } else {
123
  $serve_options['minApp']['groups'] = $this->get_groups($theme, $template, $type);
124
  }
125
 
126
+ /**
127
+ * Set minifier
128
+ */
129
  require_once W3TC_LIB_W3_DIR . '/Minifier.php';
130
  $w3_minifier =& W3_Minifier::instance();
131
 
162
  }
163
  }
164
 
165
+ /**
166
+ * Initialize minifier
167
+ */
168
  $w3_minifier->init($engine);
169
 
170
  $serve_options['minifiers'][$minifier_type] = $w3_minifier->get_minifier($engine);
171
  $serve_options['minifierOptions'][$minifier_type] = $w3_minifier->get_options($engine);
172
 
173
+ /**
174
+ * Send X-Powered-By header
175
+ */
 
 
 
 
 
 
 
176
  if ($browsercache && $this->_config->get_boolean('browsercache.cssjs.w3tc')) {
177
  @header('X-Powered-By: ' . W3TC_POWERED_BY);
178
  }
179
 
180
+ /**
181
+ * Minify!
182
+ */
183
  try {
184
  Minify::serve('MinApp', $serve_options);
185
  } catch (Exception $exception) {
186
+ $this->error($exception->getMessage());
187
  }
188
  }
189
 
190
  /**
191
  * Flushes cache
192
+ *
193
+ * @return boolean
194
  */
195
  function flush() {
196
  $cache = & $this->_get_cache();
218
  * Log
219
  *
220
  * @param mixed $object
 
221
  * @return bool
222
  */
223
+ function log($msg) {
224
+ $data = sprintf("[%s] [%s] [%s] %s\n", date('r'), $_SERVER['REQUEST_URI'], (!empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '-'), $msg);
225
 
226
  return @file_put_contents(W3TC_MINIFY_LOG_FILE, $data, FILE_APPEND);
227
  }
285
  if ($precached_file) {
286
  $result[$location][$file] = $precached_file;
287
  } else {
288
+ $this->error(sprintf('Unable to cache remote file: "%s"', $file));
289
  }
290
  } else {
 
291
  $path = w3_get_document_root() . '/' . $file;
292
 
293
  if (file_exists($path)) {
294
  $result[$location][$file] = '//' . $file;
295
  } else {
296
+ $this->error(sprintf('File "%s" doesn\'t exist', $path));
297
  }
298
  }
299
  }
304
  }
305
 
306
  /**
307
+ * Returns minify cache ID
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
  *
309
+ * @param string $file
 
 
310
  * @return string
311
  */
312
+ function get_cache_id($file) {
313
  if ($this->_config->get_string('minify.engine') == 'file') {
314
+ $cache_id = $file;
315
  } else {
316
+ $cache_id = sprintf('w3tc_%s_minify_%s', w3_get_host_id(), md5($file));
317
  }
318
 
319
  return $cache_id;
422
 
423
  if ($id === false) {
424
  $sources = $this->get_sources_custom($hash, $type);
425
+ $id = $this->_generate_id($sources, $type);
426
  $this->_cache_set($key, $id);
427
  }
428
 
429
+ return $id;
430
  }
431
 
432
  /**
444
 
445
  if ($id === false) {
446
  $sources = $this->get_sources_group($theme, $template, $location, $type);
447
+ $id = $this->_generate_id($sources, $type);
448
  $this->_cache_set($key, $id);
449
  }
450
 
451
+ return $id;
452
  }
453
 
454
  /**
458
  * @return string
459
  */
460
  function get_custom_files_hash($files) {
461
+ return substr(md5(implode('', $files)), 0, 8);
462
  }
463
 
464
  /**
501
  */
502
  function get_custom_files($hash, $type) {
503
  $key = $this->get_custom_files_key($hash, $type);
504
+ $files = $this->_cache_get($key);
505
+
506
+ if ($files) {
507
+ $files = array_map('w3_normalize_file_minify2', (array) $files);
508
+ } else {
509
+ $files = array();
510
+ }
511
 
512
  return $files;
513
  }
518
  * @param string $error
519
  * @return void
520
  */
521
+ function error($error) {
522
+ $debug = $this->_config->get_boolean('minify.debug');
523
+
524
+ if ($debug) {
525
+ $this->log($error);
526
+ }
527
+
528
+ $this->_handle_error();
529
+
530
  header('HTTP/1.0 400 Bad Request');
531
+
532
+ echo '<h1>W3TC Minify Error</h1>';
533
+
534
+ if ($debug) {
535
+ echo sprintf('<p>%s.</p>', $error);
536
+ } else {
537
+ echo '<p>Enable debug mode to see error message.</p>';
538
+ }
539
+
540
+ die();
541
  }
542
 
543
  /**
549
  */
550
  function _precache_file($url, $type) {
551
  $lifetime = $this->_config->get_integer('minify.lifetime');
552
+ $cache_path = sprintf('%s/minify_%s.%s', W3TC_CACHE_FILE_MINIFY_DIR, md5($url), $type);
 
553
 
554
+ if (!file_exists($cache_path) || @filemtime($cache_path) < (time() - $lifetime)) {
555
+ w3_download($url, $cache_path);
556
  }
557
 
558
+ return (file_exists($cache_path) ? $this->_get_minify_source($cache_path, $url) : false);
 
 
 
 
 
 
 
 
 
 
559
  }
560
 
561
  /**
618
 
619
  case 'file':
620
  default:
 
 
 
 
621
  require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/File.php';
622
 
623
  $cache[0] = & new Minify_Cache_File(
624
  W3TC_CACHE_FILE_MINIFY_DIR,
625
+ array(
626
+ '.htaccess',
627
+ 'index.php'
628
+ ),
629
  $this->_config->get_boolean('minify.file.locking'),
630
  $this->_config->get_integer('timelimit.cache_flush')
631
  );
639
  /**
640
  * Handle minify error
641
  *
 
642
  * @return void
643
  */
644
+ function _handle_error() {
645
  $notification = $this->_config->get_string('minify.error.notification');
646
 
647
  if ($notification) {
693
  * Generates file ID
694
  *
695
  * @param array $sources
696
+ * @param string $type
697
  * @return string
698
  */
699
+ function _generate_id($sources, $type) {
700
+ $values = $sources;
701
 
702
  foreach ($sources as $source) {
703
  if (file_exists($source)) {
704
  $data = @file_get_contents($source);
705
 
706
  if ($data !== false) {
707
+ $values[] = md5($data);
708
+ } else {
709
+ $values[] = false;
710
  }
711
  }
712
  }
713
 
714
+ $keys = array(
715
+ 'minify.debug',
716
+ 'minify.engine',
717
+ 'minify.options',
718
+ 'minify.symlinks',
719
+ );
720
+
721
+ if ($type == 'js') {
722
+ $engine = $this->_config->get_string('minify.js.engine');
723
+
724
+ switch ($engine) {
725
+ case 'js':
726
+ $keys = array_merge($keys, array(
727
+ 'minify.js.combine.header',
728
+ 'minify.js.combine.body',
729
+ 'minify.js.combine.footer',
730
+ 'minify.js.strip.comments',
731
+ 'minify.js.strip.crlf',
732
+ ));
733
+ break;
734
+
735
+ case 'yuijs':
736
+ $keys = array_merge($keys, array(
737
+ 'minify.yuijs.options.line-break',
738
+ 'minify.yuijs.options.nomunge',
739
+ 'minify.yuijs.options.preserve-semi',
740
+ 'minify.yuijs.options.disable-optimizations',
741
+ ));
742
+ break;
743
+
744
+ case 'ccjs':
745
+ $keys = array_merge($keys, array(
746
+ 'minify.ccjs.options.compilation_level',
747
+ 'minify.ccjs.options.formatting',
748
+ ));
749
+ break;
750
+ }
751
+ } elseif ($type == 'css') {
752
+ $engine = $this->_config->get_string('minify.css.engine');
753
+
754
+ switch ($engine) {
755
+ case 'css':
756
+ $keys = array_merge($keys, array(
757
+ 'minify.css.combine',
758
+ 'minify.css.strip.comments',
759
+ 'minify.css.strip.crlf',
760
+ 'minify.css.imports',
761
+ ));
762
+ break;
763
+
764
+ case 'yuicss':
765
+ $keys = array_merge($keys, array(
766
+ 'minify.yuicss.options.line-break',
767
+ ));
768
+ break;
769
+
770
+ case 'csstidy':
771
+ $keys = array_merge($keys, array(
772
+ 'minify.csstidy.options.remove_bslash',
773
+ 'minify.csstidy.options.compress_colors',
774
+ 'minify.csstidy.options.compress_font-weight',
775
+ 'minify.csstidy.options.lowercase_s',
776
+ 'minify.csstidy.options.optimise_shorthands',
777
+ 'minify.csstidy.options.remove_last_;',
778
+ 'minify.csstidy.options.case_properties',
779
+ 'minify.csstidy.options.sort_properties',
780
+ 'minify.csstidy.options.sort_selectors',
781
+ 'minify.csstidy.options.merge_selectors',
782
+ 'minify.csstidy.options.discard_invalid_properties',
783
+ 'minify.csstidy.options.css_level',
784
+ 'minify.csstidy.options.preserve_css',
785
+ 'minify.csstidy.options.timestamp',
786
+ 'minify.csstidy.options.template',
787
+ ));
788
+ break;
789
+ }
790
+ }
791
+
792
+ foreach ($keys as $key) {
793
+ $values[] = $this->_config->get($key);
794
+ }
795
+
796
+ $id = substr(md5(implode('', $values)), 0, 6);
797
 
798
  return $id;
799
  }
lib/W3/ObjectCache.php CHANGED
@@ -466,7 +466,7 @@ class W3_ObjectCache {
466
  * Skip if disabled
467
  */
468
  if (!$this->_config->get_boolean('objectcache.enabled')) {
469
- $this->_cache_reject_reason = 'object caching is disabled';
470
 
471
  return false;
472
  }
@@ -493,7 +493,7 @@ class W3_ObjectCache {
493
  * Check request URI
494
  */
495
  if (!$this->_check_request_uri()) {
496
- $this->_cache_reject_reason = 'request URI is rejected';
497
 
498
  return false;
499
  }
@@ -506,6 +506,7 @@ class W3_ObjectCache {
506
  *
507
  * @param string $id
508
  * @param string $group
 
509
  * @return boolean
510
  */
511
  function _can_cache2($id, $group, &$cache_reject_reason) {
@@ -535,7 +536,7 @@ class W3_ObjectCache {
535
  }
536
 
537
  if (in_array($group, $this->nonpersistent_groups)) {
538
- $cache_reject_reason = 'non-persistent group';
539
 
540
  return false;
541
  }
@@ -635,6 +636,13 @@ class W3_ObjectCache {
635
  return false;
636
  }
637
 
 
 
 
 
 
 
 
638
  return true;
639
  }
640
 
466
  * Skip if disabled
467
  */
468
  if (!$this->_config->get_boolean('objectcache.enabled')) {
469
+ $this->_cache_reject_reason = 'Object caching is disabled';
470
 
471
  return false;
472
  }
493
  * Check request URI
494
  */
495
  if (!$this->_check_request_uri()) {
496
+ $this->_cache_reject_reason = 'Request URI is rejected';
497
 
498
  return false;
499
  }
506
  *
507
  * @param string $id
508
  * @param string $group
509
+ * @param string $cache_reject_reason
510
  * @return boolean
511
  */
512
  function _can_cache2($id, $group, &$cache_reject_reason) {
536
  }
537
 
538
  if (in_array($group, $this->nonpersistent_groups)) {
539
+ $cache_reject_reason = 'Non-persistent group';
540
 
541
  return false;
542
  }
636
  return false;
637
  }
638
 
639
+ /**
640
+ * Check User Agent
641
+ */
642
+ if (isset($_SERVER['HTTP_USER_AGENT']) && stristr($_SERVER['HTTP_USER_AGENT'], W3TC_POWERED_BY) !== false) {
643
+ return false;
644
+ }
645
+
646
  return true;
647
  }
648
 
lib/W3/PgCache.php CHANGED
@@ -102,7 +102,7 @@ class W3_PgCache {
102
  $this->_debug = $this->_config->get_boolean('pgcache.debug');
103
  $this->_request_uri = $_SERVER['REQUEST_URI'];
104
  $this->_lifetime = $this->_config->get_integer('browsercache.html.lifetime');
105
- $this->_enhanced_mode = ($this->_config->get_string('pgcache.engine') == 'file_pgcache');
106
 
107
  if ($this->_config->get_boolean('mobile.enabled')) {
108
  require_once W3TC_LIB_W3_DIR . '/Mobile.php';
@@ -922,11 +922,14 @@ class W3_PgCache {
922
  );
923
  break;
924
 
925
- case 'file_pgcache':
926
  $engineConfig = array(
 
 
 
 
927
  'cache_dir' => W3TC_CACHE_FILE_PGCACHE_DIR,
928
  'locking' => $this->_config->get_boolean('pgcache.file.locking'),
929
- 'expire' => $this->_lifetime,
930
  'flush_timelimit' => $this->_config->get_integer('timelimit.cache_flush')
931
  );
932
  break;
@@ -997,7 +1000,11 @@ class W3_PgCache {
997
  * @return boolean
998
  */
999
  function _check_ua() {
1000
- foreach ($this->_config->get_array('pgcache.reject.ua') as $ua) {
 
 
 
 
1001
  if (isset($_SERVER['HTTP_USER_AGENT']) && stristr($_SERVER['HTTP_USER_AGENT'], $ua) !== false) {
1002
  return false;
1003
  }
102
  $this->_debug = $this->_config->get_boolean('pgcache.debug');
103
  $this->_request_uri = $_SERVER['REQUEST_URI'];
104
  $this->_lifetime = $this->_config->get_integer('browsercache.html.lifetime');
105
+ $this->_enhanced_mode = ($this->_config->get_string('pgcache.engine') == 'file_generic');
106
 
107
  if ($this->_config->get_boolean('mobile.enabled')) {
108
  require_once W3TC_LIB_W3_DIR . '/Mobile.php';
922
  );
923
  break;
924
 
925
+ case 'file_generic':
926
  $engineConfig = array(
927
+ 'exclude' => array(
928
+ '.htaccess'
929
+ ),
930
+ 'expire' => $this->_lifetime,
931
  'cache_dir' => W3TC_CACHE_FILE_PGCACHE_DIR,
932
  'locking' => $this->_config->get_boolean('pgcache.file.locking'),
 
933
  'flush_timelimit' => $this->_config->get_integer('timelimit.cache_flush')
934
  );
935
  break;
1000
  * @return boolean
1001
  */
1002
  function _check_ua() {
1003
+ $uas = array_merge($this->_config->get_array('pgcache.reject.ua'), array(
1004
+ W3TC_POWERED_BY
1005
+ ));
1006
+
1007
+ foreach ($uas as $ua) {
1008
  if (isset($_SERVER['HTTP_USER_AGENT']) && stristr($_SERVER['HTTP_USER_AGENT'], $ua) !== false) {
1009
  return false;
1010
  }
lib/W3/Plugin/BrowserCache.php CHANGED
@@ -110,7 +110,7 @@ class W3_Plugin_BrowserCache extends W3_Plugin {
110
  }
111
 
112
  /**
113
- * Skip if doint AJAX
114
  */
115
  if (defined('DOING_AJAX')) {
116
  return false;
@@ -144,6 +144,13 @@ class W3_Plugin_BrowserCache extends W3_Plugin {
144
  return false;
145
  }
146
 
 
 
 
 
 
 
 
147
  return true;
148
  }
149
 
@@ -154,19 +161,16 @@ class W3_Plugin_BrowserCache extends W3_Plugin {
154
  * @return mixed
155
  */
156
  function ob_callback(&$buffer) {
157
- global $wpdb;
158
-
159
  if ($buffer != '' && w3_is_xml($buffer)) {
160
  $domain_url_regexp = w3_get_domain_url_regexp();
161
 
162
- $buffer = preg_replace_callback('~(href|src|action)=[\'"]((' . $domain_url_regexp . ')?(/.*?\.([a-z-_]+?)(\?.*?)?))[\'"]~', array(
163
  &$this,
164
  'link_replace_callback'
165
  ), $buffer);
166
  }
167
 
168
  return $buffer;
169
-
170
  }
171
 
172
  /**
@@ -179,9 +183,78 @@ class W3_Plugin_BrowserCache extends W3_Plugin {
179
  static $id = null, $extensions = null;
180
 
181
  if ($id === null) {
182
- $id = $this->_config->get_integer('browsercache.id', date('Ymd'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  }
184
 
 
 
 
 
 
 
 
 
 
 
 
185
  if ($extensions === null) {
186
  $types = array();
187
  $extensions = array();
@@ -203,16 +276,7 @@ class W3_Plugin_BrowserCache extends W3_Plugin {
203
  }
204
  }
205
 
206
- list ($match, $attr, $url, , , , $extension) = $matches;
207
-
208
- if (in_array($extension, $extensions)) {
209
- $url = w3_remove_wp_query($url);
210
- $url .= (strstr($url, '?') !== false ? '&' : '?') . $id;
211
-
212
- return sprintf('%s="%s"', $attr, $url);
213
- }
214
-
215
- return $match;
216
  }
217
 
218
  /**
@@ -827,7 +891,7 @@ class W3_Plugin_BrowserCache extends W3_Plugin {
827
  }
828
 
829
  /**
830
- * Erases rules
831
  *
832
  * @param string $data
833
  * @return string
@@ -839,7 +903,7 @@ class W3_Plugin_BrowserCache extends W3_Plugin {
839
  }
840
 
841
  /**
842
- * Erases rules
843
  *
844
  * @param string $data
845
  * @return string
@@ -851,7 +915,7 @@ class W3_Plugin_BrowserCache extends W3_Plugin {
851
  }
852
 
853
  /**
854
- * Removes rules
855
  *
856
  * @return boolean
857
  */
@@ -872,7 +936,7 @@ class W3_Plugin_BrowserCache extends W3_Plugin {
872
  }
873
 
874
  /**
875
- * Removes rules
876
  *
877
  * @return boolean
878
  */
@@ -905,7 +969,7 @@ class W3_Plugin_BrowserCache extends W3_Plugin {
905
  }
906
 
907
  /**
908
- * Check 404 rules
909
  *
910
  * @return boolean
911
  */
110
  }
111
 
112
  /**
113
+ * Skip if doing AJAX
114
  */
115
  if (defined('DOING_AJAX')) {
116
  return false;
144
  return false;
145
  }
146
 
147
+ /**
148
+ * Check User Agent
149
+ */
150
+ if (isset($_SERVER['HTTP_USER_AGENT']) && stristr($_SERVER['HTTP_USER_AGENT'], W3TC_POWERED_BY) !== false) {
151
+ return false;
152
+ }
153
+
154
  return true;
155
  }
156
 
161
  * @return mixed
162
  */
163
  function ob_callback(&$buffer) {
 
 
164
  if ($buffer != '' && w3_is_xml($buffer)) {
165
  $domain_url_regexp = w3_get_domain_url_regexp();
166
 
167
+ $buffer = preg_replace_callback('~(href|src|action)=[\'"]((' . $domain_url_regexp . ')?(/[^\'"]*\.([a-z-_]+)(\?[\'"]*)?))[\'"]~Ui', array(
168
  &$this,
169
  'link_replace_callback'
170
  ), $buffer);
171
  }
172
 
173
  return $buffer;
 
174
  }
175
 
176
  /**
183
  static $id = null, $extensions = null;
184
 
185
  if ($id === null) {
186
+ $id = $this->get_replace_id();
187
+ }
188
+
189
+ if ($extensions === null) {
190
+ $extensions = $this->get_replace_extensions();
191
+ }
192
+
193
+ list ($match, $attr, $url, , , , , $extension) = $matches;
194
+
195
+ if (in_array($extension, $extensions)) {
196
+ $url = w3_remove_query($url);
197
+ $url .= (strstr($url, '?') !== false ? '&amp;' : '?') . $id;
198
+
199
+ return sprintf('%s="%s"', $attr, $url);
200
+ }
201
+
202
+ return $match;
203
+ }
204
+
205
+ /**
206
+ * Returns replace ID
207
+ *
208
+ * @return string
209
+ */
210
+ function get_replace_id() {
211
+ static $cache_id = null;
212
+
213
+ if ($cache_id === null) {
214
+ $keys = array(
215
+ 'browsercache.cssjs.compression',
216
+ 'browsercache.cssjs.expires',
217
+ 'browsercache.cssjs.lifetime',
218
+ 'browsercache.cssjs.cache.control',
219
+ 'browsercache.cssjs.cache.policy',
220
+ 'browsercache.cssjs.etag',
221
+ 'browsercache.cssjs.w3tc',
222
+ 'browsercache.html.compression',
223
+ 'browsercache.html.expires',
224
+ 'browsercache.html.lifetime',
225
+ 'browsercache.html.cache.control',
226
+ 'browsercache.html.cache.policy',
227
+ 'browsercache.html.etag',
228
+ 'browsercache.html.w3tc',
229
+ 'browsercache.other.compression',
230
+ 'browsercache.other.expires',
231
+ 'browsercache.other.lifetime',
232
+ 'browsercache.other.cache.control',
233
+ 'browsercache.other.cache.policy',
234
+ 'browsercache.other.etag',
235
+ 'browsercache.other.w3tc'
236
+ );
237
+
238
+ $values = array();
239
+
240
+ foreach ($keys as $key) {
241
+ $values[] = $this->_config->get($key);
242
+ }
243
+
244
+ $cache_id = substr(md5(implode('', $values)), 0, 6);
245
  }
246
 
247
+ return $cache_id;
248
+ }
249
+
250
+ /**
251
+ * Returns replace extensions
252
+ *
253
+ * @return array
254
+ */
255
+ function get_replace_extensions() {
256
+ static $extensions = null;
257
+
258
  if ($extensions === null) {
259
  $types = array();
260
  $extensions = array();
276
  }
277
  }
278
 
279
+ return $extensions;
 
 
 
 
 
 
 
 
 
280
  }
281
 
282
  /**
891
  }
892
 
893
  /**
894
+ * Erases cache rules
895
  *
896
  * @param string $data
897
  * @return string
903
  }
904
 
905
  /**
906
+ * Erases no404wp rules
907
  *
908
  * @param string $data
909
  * @return string
915
  }
916
 
917
  /**
918
+ * Removes cache rules
919
  *
920
  * @return boolean
921
  */
936
  }
937
 
938
  /**
939
+ * Removes no404wp rules
940
  *
941
  * @return boolean
942
  */
969
  }
970
 
971
  /**
972
+ * Check no404wp rules
973
  *
974
  * @return boolean
975
  */
lib/W3/Plugin/Cdn.php CHANGED
@@ -305,8 +305,6 @@ class W3_Plugin_Cdn extends W3_Plugin {
305
  * @param integer $attachment_id
306
  */
307
  function delete_attachment($attachment_id) {
308
- $files = array();
309
-
310
  $files = $this->get_attachment_files($attachment_id);
311
  $files = apply_filters('w3tc_cdn_delete_attachment', $files);
312
 
@@ -359,20 +357,19 @@ class W3_Plugin_Cdn extends W3_Plugin {
359
  * Upload _wp_attached_file, _wp_attachment_metadata, _wp_attachment_backup_sizes
360
  *
361
  * @param integer $attachment_id
 
362
  * @return boolean
363
  */
364
- function purge_attachment($attachment_id) {
365
  $files = $this->get_attachment_files($attachment_id);
366
 
367
- $results = array();
368
-
369
  return $this->purge($files, false, $results);
370
  }
371
 
372
  /**
373
  * Cron schedules filter
374
  *
375
- * @paran array $schedules
376
  * @return array
377
  */
378
  function cron_schedules($schedules) {
@@ -436,7 +433,7 @@ class W3_Plugin_Cdn extends W3_Plugin {
436
  /**
437
  * Returns array of files from sizes array
438
  *
439
- * @param string $base_dir
440
  * @param array $sizes
441
  * @return array
442
  */
@@ -527,7 +524,6 @@ class W3_Plugin_Cdn extends W3_Plugin {
527
  $site_path = w3_get_site_path();
528
  $domain_url_regexp = w3_get_domain_url_regexp();
529
 
530
-
531
  if ($this->_config->get_boolean('cdn.uploads.enable')) {
532
  $upload_info = w3_upload_info();
533
 
@@ -559,9 +555,9 @@ class W3_Plugin_Cdn extends W3_Plugin {
559
 
560
  if ($this->_config->get_boolean('cdn.minify.enable')) {
561
  if ($this->_config->get_boolean('minify.auto')) {
562
- $regexps[] = '~(["\'])((' . $domain_url_regexp . ')?(' . w3_preg_quote($site_path . W3TC_CONTENT_MINIFY_DIR_NAME) . '/[a-f0-9]+\.[0-9]+\.(css|js)))~U';
563
  } else {
564
- $regexps[] = '~(["\'])((' . $domain_url_regexp . ')?(' . w3_preg_quote($site_path . W3TC_CONTENT_MINIFY_DIR_NAME) . '/[a-f0-9]+/.+\.include(-(footer|body))?(-nb)?\.[0-9]+\.(css|js)))~U';
565
  }
566
  }
567
 
@@ -748,7 +744,7 @@ class W3_Plugin_Cdn extends W3_Plugin {
748
  * @param array $files
749
  * @param boolean $queue_failed
750
  * @param array $results
751
- * @return void
752
  */
753
  function upload($files, $queue_failed, &$results) {
754
  $cdn = & $this->get_cdn();
@@ -756,15 +752,17 @@ class W3_Plugin_Cdn extends W3_Plugin {
756
 
757
  @set_time_limit($this->_config->get_integer('timelimit.cdn_upload'));
758
 
759
- $cdn->upload($files, $results, $force_rewrite);
760
 
761
- if ($queue_failed) {
762
  foreach ($results as $result) {
763
  if ($result['result'] != W3TC_CDN_RESULT_OK) {
764
  $this->queue_add($result['local_path'], $result['remote_path'], W3TC_CDN_COMMAND_UPLOAD, $result['error']);
765
  }
766
  }
767
  }
 
 
768
  }
769
 
770
  /**
@@ -773,22 +771,24 @@ class W3_Plugin_Cdn extends W3_Plugin {
773
  * @param array $files
774
  * @param boolean $queue_failed
775
  * @param array $results
776
- * @return void
777
  */
778
  function delete($files, $queue_failed, &$results) {
779
  $cdn = & $this->get_cdn();
780
 
781
  @set_time_limit($this->_config->get_integer('timelimit.cdn_delete'));
782
 
783
- $cdn->delete($files, $results);
784
 
785
- if ($queue_failed) {
786
  foreach ($results as $result) {
787
  if ($result['result'] != W3TC_CDN_RESULT_OK) {
788
  $this->queue_add($result['local_path'], $result['remote_path'], W3TC_CDN_COMMAND_DELETE, $result['error']);
789
  }
790
  }
791
  }
 
 
792
  }
793
 
794
  /**
@@ -820,15 +820,17 @@ class W3_Plugin_Cdn extends W3_Plugin {
820
 
821
  @set_time_limit($this->_config->get_integer('timelimit.cdn_purge'));
822
 
823
- $cdn->purge($files, $results);
824
 
825
- if ($queue_failed) {
826
  foreach ($results as $result) {
827
  if ($result['result'] != W3TC_CDN_RESULT_OK) {
828
  $this->queue_add($result['local_path'], $result['remote_path'], W3TC_CDN_COMMAND_PURGE, $result['error']);
829
  }
830
  }
831
  }
 
 
832
  }
833
 
834
  /**
@@ -1008,7 +1010,7 @@ class W3_Plugin_Cdn extends W3_Plugin {
1008
 
1009
  if (preg_match($regexp, $check_src)) {
1010
  /**
1011
- * Check for alredy uploaded attachment
1012
  */
1013
  if (isset($attachments[$src])) {
1014
  list($dst, $dst_url) = $attachments[$src];
@@ -1335,6 +1337,8 @@ class W3_Plugin_Cdn extends W3_Plugin {
1335
 
1336
  /**
1337
  * Exports includes to CDN
 
 
1338
  */
1339
  function get_files_includes() {
1340
  $includes_root = w3_path(ABSPATH . WPINC);
@@ -1348,6 +1352,8 @@ class W3_Plugin_Cdn extends W3_Plugin {
1348
 
1349
  /**
1350
  * Exports theme to CDN
 
 
1351
  */
1352
  function get_files_theme() {
1353
  /**
@@ -1371,6 +1377,8 @@ class W3_Plugin_Cdn extends W3_Plugin {
1371
 
1372
  /**
1373
  * Exports min files to CDN
 
 
1374
  */
1375
  function get_files_minify() {
1376
  $files = array();
@@ -1420,6 +1428,8 @@ class W3_Plugin_Cdn extends W3_Plugin {
1420
 
1421
  /**
1422
  * Exports custom files to CDN
 
 
1423
  */
1424
  function get_files_custom() {
1425
  $files = array();
@@ -1454,7 +1464,7 @@ class W3_Plugin_Cdn extends W3_Plugin {
1454
  global $wpdb;
1455
  static $queue = null, $reject_files = null;
1456
 
1457
- list($match, $quote, $url, $domain_url, $www, $path) = $matches;
1458
 
1459
  $path = ltrim($path, '/');
1460
 
@@ -1519,6 +1529,7 @@ class W3_Plugin_Cdn extends W3_Plugin {
1519
  * Search files
1520
  *
1521
  * @param string $search_dir
 
1522
  * @param string $mask
1523
  * @param boolean $recursive
1524
  * @return array
@@ -1821,8 +1832,8 @@ class W3_Plugin_Cdn extends W3_Plugin {
1821
  /**
1822
  * Returns true if we can do CDN logic
1823
  *
 
1824
  * @return string
1825
- * @return boolean
1826
  */
1827
  function can_cdn2(&$buffer) {
1828
  /**
@@ -1861,7 +1872,11 @@ class W3_Plugin_Cdn extends W3_Plugin {
1861
  * @return boolean
1862
  */
1863
  function check_ua() {
1864
- foreach ($this->_config->get_array('cdn.reject.ua') as $ua) {
 
 
 
 
1865
  if (isset($_SERVER['HTTP_USER_AGENT']) && stristr($_SERVER['HTTP_USER_AGENT'], $ua) !== false) {
1866
  return false;
1867
  }
305
  * @param integer $attachment_id
306
  */
307
  function delete_attachment($attachment_id) {
 
 
308
  $files = $this->get_attachment_files($attachment_id);
309
  $files = apply_filters('w3tc_cdn_delete_attachment', $files);
310
 
357
  * Upload _wp_attached_file, _wp_attachment_metadata, _wp_attachment_backup_sizes
358
  *
359
  * @param integer $attachment_id
360
+ * @param array $results
361
  * @return boolean
362
  */
363
+ function purge_attachment($attachment_id, &$results) {
364
  $files = $this->get_attachment_files($attachment_id);
365
 
 
 
366
  return $this->purge($files, false, $results);
367
  }
368
 
369
  /**
370
  * Cron schedules filter
371
  *
372
+ * @param array $schedules
373
  * @return array
374
  */
375
  function cron_schedules($schedules) {
433
  /**
434
  * Returns array of files from sizes array
435
  *
436
+ * @param string $attached_file
437
  * @param array $sizes
438
  * @return array
439
  */
524
  $site_path = w3_get_site_path();
525
  $domain_url_regexp = w3_get_domain_url_regexp();
526
 
 
527
  if ($this->_config->get_boolean('cdn.uploads.enable')) {
528
  $upload_info = w3_upload_info();
529
 
555
 
556
  if ($this->_config->get_boolean('cdn.minify.enable')) {
557
  if ($this->_config->get_boolean('minify.auto')) {
558
+ $regexps[] = '~(["\'])((' . $domain_url_regexp . ')?(' . w3_preg_quote($site_path . W3TC_CONTENT_MINIFY_DIR_NAME) . '/[a-f0-9]+\.[a-f0-9]+\.(css|js)))~U';
559
  } else {
560
+ $regexps[] = '~(["\'])((' . $domain_url_regexp . ')?(' . w3_preg_quote($site_path . W3TC_CONTENT_MINIFY_DIR_NAME) . '/[a-f0-9]+/.+\.include(-(footer|body))?(-nb)?\.[a-f0-9]+\.(css|js)))~U';
561
  }
562
  }
563
 
744
  * @param array $files
745
  * @param boolean $queue_failed
746
  * @param array $results
747
+ * @return boolean
748
  */
749
  function upload($files, $queue_failed, &$results) {
750
  $cdn = & $this->get_cdn();
752
 
753
  @set_time_limit($this->_config->get_integer('timelimit.cdn_upload'));
754
 
755
+ $return = $cdn->upload($files, $results, $force_rewrite);
756
 
757
+ if (!$return && $queue_failed) {
758
  foreach ($results as $result) {
759
  if ($result['result'] != W3TC_CDN_RESULT_OK) {
760
  $this->queue_add($result['local_path'], $result['remote_path'], W3TC_CDN_COMMAND_UPLOAD, $result['error']);
761
  }
762
  }
763
  }
764
+
765
+ return $return;
766
  }
767
 
768
  /**
771
  * @param array $files
772
  * @param boolean $queue_failed
773
  * @param array $results
774
+ * @return boolean
775
  */
776
  function delete($files, $queue_failed, &$results) {
777
  $cdn = & $this->get_cdn();
778
 
779
  @set_time_limit($this->_config->get_integer('timelimit.cdn_delete'));
780
 
781
+ $return = $cdn->delete($files, $results);
782
 
783
+ if (!$return && $queue_failed) {
784
  foreach ($results as $result) {
785
  if ($result['result'] != W3TC_CDN_RESULT_OK) {
786
  $this->queue_add($result['local_path'], $result['remote_path'], W3TC_CDN_COMMAND_DELETE, $result['error']);
787
  }
788
  }
789
  }
790
+
791
+ return $return;
792
  }
793
 
794
  /**
820
 
821
  @set_time_limit($this->_config->get_integer('timelimit.cdn_purge'));
822
 
823
+ $return = $cdn->purge($files, $results);
824
 
825
+ if (!$return && $queue_failed) {
826
  foreach ($results as $result) {
827
  if ($result['result'] != W3TC_CDN_RESULT_OK) {
828
  $this->queue_add($result['local_path'], $result['remote_path'], W3TC_CDN_COMMAND_PURGE, $result['error']);
829
  }
830
  }
831
  }
832
+
833
+ return $return;
834
  }
835
 
836
  /**
1010
 
1011
  if (preg_match($regexp, $check_src)) {
1012
  /**
1013
+ * Check for already uploaded attachment
1014
  */
1015
  if (isset($attachments[$src])) {
1016
  list($dst, $dst_url) = $attachments[$src];
1337
 
1338
  /**
1339
  * Exports includes to CDN
1340
+ *
1341
+ * @return array
1342
  */
1343
  function get_files_includes() {
1344
  $includes_root = w3_path(ABSPATH . WPINC);
1352
 
1353
  /**
1354
  * Exports theme to CDN
1355
+ *
1356
+ * @return array
1357
  */
1358
  function get_files_theme() {
1359
  /**
1377
 
1378
  /**
1379
  * Exports min files to CDN
1380
+ *
1381
+ * @return array
1382
  */
1383
  function get_files_minify() {
1384
  $files = array();
1428
 
1429
  /**
1430
  * Exports custom files to CDN
1431
+ *
1432
+ * @return array
1433
  */
1434
  function get_files_custom() {
1435
  $files = array();
1464
  global $wpdb;
1465
  static $queue = null, $reject_files = null;
1466
 
1467
+ list($match, $quote, $url, , , , $path) = $matches;
1468
 
1469
  $path = ltrim($path, '/');
1470
 
1529
  * Search files
1530
  *
1531
  * @param string $search_dir
1532
+ * @param string $base_dir
1533
  * @param string $mask
1534
  * @param boolean $recursive
1535
  * @return array
1832
  /**
1833
  * Returns true if we can do CDN logic
1834
  *
1835
+ * @param $buffer
1836
  * @return string
 
1837
  */
1838
  function can_cdn2(&$buffer) {
1839
  /**
1872
  * @return boolean
1873
  */
1874
  function check_ua() {
1875
+ $uas = array_merge($this->_config->get_array('cdn.reject.ua'), array(
1876
+ W3TC_POWERED_BY
1877
+ ));
1878
+
1879
+ foreach ($uas as $ua) {
1880
  if (isset($_SERVER['HTTP_USER_AGENT']) && stristr($_SERVER['HTTP_USER_AGENT'], $ua) !== false) {
1881
  return false;
1882
  }
lib/W3/Plugin/DbCache.php CHANGED
@@ -164,14 +164,14 @@ class W3_Plugin_DbCache extends W3_Plugin {
164
  * @return void
165
  */
166
  function cleanup() {
167
- require_once W3TC_LIB_W3_DIR . '/Cache/File/Manager.php';
168
 
169
- $w3_cache_file_manager = & new W3_Cache_File_Manager(array(
170
  'cache_dir' => W3TC_CACHE_FILE_DBCACHE_DIR,
171
  'clean_timelimit' => $this->_config->get_integer('timelimit.cache_gc')
172
  ));
173
 
174
- $w3_cache_file_manager->clean();
175
  }
176
 
177
  /**
164
  * @return void
165
  */
166
  function cleanup() {
167
+ require_once W3TC_LIB_W3_DIR . '/Cache/File/Cleaner.php';
168
 
169
+ $w3_cache_file_cleaner = & new W3_Cache_File_Cleaner(array(
170
  'cache_dir' => W3TC_CACHE_FILE_DBCACHE_DIR,
171
  'clean_timelimit' => $this->_config->get_integer('timelimit.cache_gc')
172
  ));
173
 
174
+ $w3_cache_file_cleaner->clean();
175
  }
176
 
177
  /**
lib/W3/Plugin/Minify.php CHANGED
@@ -178,21 +178,26 @@ class W3_Plugin_Minify extends W3_Plugin {
178
  * @return void
179
  */
180
  function cleanup() {
181
- require_once W3TC_LIB_W3_DIR . '/Cache/File/Minify/Manager.php';
182
-
183
- $w3_cache_file_minify_manager = & new W3_Cache_File_Minify_Manager(array(
 
 
 
 
 
184
  'cache_dir' => W3TC_CACHE_FILE_MINIFY_DIR,
185
  'expire' => $this->_config->get_integer('minify.file.gc'),
186
  'clean_timelimit' => $this->_config->get_integer('timelimit.cache_gc')
187
  ));
188
 
189
- $w3_cache_file_minify_manager->clean();
190
  }
191
 
192
  /**
193
  * Cron schedules filter
194
  *
195
- * @paran array $schedules
196
  * @return array
197
  */
198
  function cron_schedules($schedules) {
@@ -340,13 +345,39 @@ class W3_Plugin_Minify extends W3_Plugin {
340
  * @return array
341
  */
342
  function filter_files($files) {
343
- $files = array_map('w3_normalize_file_minify', $files);
344
- $files = array_filter($files, create_function('$el', 'return !w3_is_url($el);'));
345
  $files = array_values(array_unique($files));
346
 
347
  return $files;
348
  }
349
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
  /**
351
  * Removes style tags from the source
352
  *
@@ -540,7 +571,7 @@ class W3_Plugin_Minify extends W3_Plugin {
540
  /**
541
  * Returns current theme
542
  *
543
- * @retun string
544
  */
545
  function get_theme() {
546
  static $theme = null;
@@ -598,7 +629,7 @@ class W3_Plugin_Minify extends W3_Plugin {
598
  * Returns style tag
599
  *
600
  * @param string $url
601
- * @param string $import
602
  * @return string
603
  */
604
  function get_style($url, $import = false) {
@@ -613,7 +644,7 @@ class W3_Plugin_Minify extends W3_Plugin {
613
  * Prints script tag
614
  *
615
  * @param string $url
616
- * @param boolean $non_blocking
617
  * @return string
618
  */
619
  function get_script($url, $blocking = true) {
@@ -732,6 +763,7 @@ class W3_Plugin_Minify extends W3_Plugin {
732
  * @param string $template
733
  * @param string $location
734
  * @param string $type
 
735
  * @return string
736
  */
737
  function format_url_group($theme, $template, $location, $type, $rewrite = null) {
@@ -743,9 +775,9 @@ class W3_Plugin_Minify extends W3_Plugin {
743
  $site_url_ssl = w3_get_site_url_ssl();
744
 
745
  if ($this->_config->get_boolean('minify.rewrite')) {
746
- $url = sprintf('%s/%s/%s/%s.%s.%d.%s', $site_url_ssl, W3TC_CONTENT_MINIFY_DIR_NAME, $theme, $template, $location, $id, $type);
747
  } else {
748
- $url = sprintf('%s/%s/index.php?file=%s/%s.%s.%d.%s', $site_url_ssl, W3TC_CONTENT_MINIFY_DIR_NAME, $theme, $template, $location, $id, $type);
749
  }
750
 
751
  return $url;
@@ -769,9 +801,9 @@ class W3_Plugin_Minify extends W3_Plugin {
769
  $site_url_ssl = w3_get_site_url_ssl();
770
 
771
  if ($this->_config->get_boolean('minify.rewrite')) {
772
- $url = sprintf('%s/%s/%s.%d.%s', $site_url_ssl, W3TC_CONTENT_MINIFY_DIR_NAME, $hash, $id, $type);
773
  } else {
774
- $url = sprintf('%s/%s/index.php?file=%s.%d.%s', $site_url_ssl, W3TC_CONTENT_MINIFY_DIR_NAME, $hash, $id, $type);
775
  }
776
 
777
  return $url;
@@ -813,6 +845,8 @@ class W3_Plugin_Minify extends W3_Plugin {
813
 
814
  /**
815
  * Returns debug info
 
 
816
  */
817
  function get_debug_info() {
818
  $debug_info = "<!-- W3 Total Cache: Minify debug info:\r\n";
@@ -859,7 +893,7 @@ class W3_Plugin_Minify extends W3_Plugin {
859
  * Skip if doint AJAX
860
  */
861
  if (defined('DOING_AJAX')) {
862
- $this->minify_reject_reason = 'doing AJAX';
863
 
864
  return false;
865
  }
@@ -868,7 +902,7 @@ class W3_Plugin_Minify extends W3_Plugin {
868
  * Skip if doing cron
869
  */
870
  if (defined('DOING_CRON')) {
871
- $this->minify_reject_reason = 'doing cron';
872
 
873
  return false;
874
  }
@@ -877,7 +911,7 @@ class W3_Plugin_Minify extends W3_Plugin {
877
  * Skip if APP request
878
  */
879
  if (defined('APP_REQUEST')) {
880
- $this->minify_reject_reason = 'application request';
881
 
882
  return false;
883
  }
@@ -913,7 +947,7 @@ class W3_Plugin_Minify extends W3_Plugin {
913
  * Check User agent
914
  */
915
  if (!$this->check_ua()) {
916
- $this->minify_reject_reason = 'user agent is rejected';
917
 
918
  return false;
919
  }
@@ -922,7 +956,7 @@ class W3_Plugin_Minify extends W3_Plugin {
922
  * Check request URI
923
  */
924
  if (!$this->check_request_uri()) {
925
- $this->minify_reject_reason = 'request URI is rejected';
926
 
927
  return false;
928
  }
@@ -931,7 +965,7 @@ class W3_Plugin_Minify extends W3_Plugin {
931
  * Skip if user is logged in
932
  */
933
  if ($this->_config->get_boolean('minify.reject.logged') && !$this->check_logged_in()) {
934
- $this->minify_reject_reason = 'user is logged in';
935
 
936
  return false;
937
  }
@@ -940,7 +974,7 @@ class W3_Plugin_Minify extends W3_Plugin {
940
  * Check feed
941
  */
942
  if ($this->_config->get_boolean('minify.html.reject.feed') && function_exists('is_feed') && is_feed()) {
943
- $this->minify_reject_reason = 'feed is rejected';
944
 
945
  return false;
946
  }
@@ -951,8 +985,8 @@ class W3_Plugin_Minify extends W3_Plugin {
951
  /**
952
  * Returns true if we can minify
953
  *
 
954
  * @return string
955
- * @return boolean
956
  */
957
  function can_minify2(&$buffer) {
958
  /**
@@ -982,7 +1016,11 @@ class W3_Plugin_Minify extends W3_Plugin {
982
  * @return boolean
983
  */
984
  function check_ua() {
985
- foreach ($this->_config->get_array('minify.reject.ua') as $ua) {
 
 
 
 
986
  if (isset($_SERVER['HTTP_USER_AGENT']) && stristr($_SERVER['HTTP_USER_AGENT'], $ua) !== false) {
987
  return false;
988
  }
@@ -1370,7 +1408,9 @@ class W3_Plugin_Minify extends W3_Plugin {
1370
  if (file_exists($path)) {
1371
  $data = @file_get_contents($path);
1372
 
1373
- if ($data === false) {
 
 
1374
  return false;
1375
  }
1376
  } else {
@@ -1427,7 +1467,9 @@ class W3_Plugin_Minify extends W3_Plugin {
1427
  if (file_exists($path)) {
1428
  $data = @file_get_contents($path);
1429
 
1430
- if ($data === false) {
 
 
1431
  return false;
1432
  }
1433
  } else {
@@ -1474,7 +1516,7 @@ class W3_Plugin_Minify extends W3_Plugin {
1474
  }
1475
 
1476
  /**
1477
- * Erases W3TC rules from config
1478
  *
1479
  * @param string $data
1480
  * @return string
@@ -1486,7 +1528,7 @@ class W3_Plugin_Minify extends W3_Plugin {
1486
  }
1487
 
1488
  /**
1489
- * Erases W3TC rules from config
1490
  *
1491
  * @param string $data
1492
  * @return string
@@ -1498,7 +1540,19 @@ class W3_Plugin_Minify extends W3_Plugin {
1498
  }
1499
 
1500
  /**
1501
- * Removes W3TC rules from file cache dir
 
 
 
 
 
 
 
 
 
 
 
 
1502
  *
1503
  * @return boolean
1504
  */
@@ -1519,7 +1573,7 @@ class W3_Plugin_Minify extends W3_Plugin {
1519
  }
1520
 
1521
  /**
1522
- * Removes W3TC rules from file cache dir
1523
  *
1524
  * @return boolean
1525
  */
@@ -1540,7 +1594,28 @@ class W3_Plugin_Minify extends W3_Plugin {
1540
  }
1541
 
1542
  /**
1543
- * Checks rules
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1544
  *
1545
  * @return boolean
1546
  */
@@ -1552,7 +1627,7 @@ class W3_Plugin_Minify extends W3_Plugin {
1552
  }
1553
 
1554
  /**
1555
- * Checks rules
1556
  *
1557
  * @return boolean
1558
  */
@@ -1562,4 +1637,16 @@ class W3_Plugin_Minify extends W3_Plugin {
1562
 
1563
  return (($data = @file_get_contents($path)) && strstr(w3_clean_rules($data), w3_clean_rules($search)) !== false);
1564
  }
 
 
 
 
 
 
 
 
 
 
 
 
1565
  }
178
  * @return void
179
  */
180
  function cleanup() {
181
+ require_once W3TC_LIB_W3_DIR . '/Cache/File/Cleaner/Generic.php';
182
+
183
+ $w3_cache_file_cleaner_generic = & new W3_Cache_File_Cleaner_Generic(array(
184
+ 'exclude' => array(
185
+ '*.files',
186
+ '.htaccess',
187
+ 'index.php'
188
+ ),
189
  'cache_dir' => W3TC_CACHE_FILE_MINIFY_DIR,
190
  'expire' => $this->_config->get_integer('minify.file.gc'),
191
  'clean_timelimit' => $this->_config->get_integer('timelimit.cache_gc')
192
  ));
193
 
194
+ $w3_cache_file_cleaner_generic->clean();
195
  }
196
 
197
  /**
198
  * Cron schedules filter
199
  *
200
+ * @param array $schedules
201
  * @return array
202
  */
203
  function cron_schedules($schedules) {
345
  * @return array
346
  */
347
  function filter_files($files) {
348
+ $files = array_map('w3_normalize_file_minify2', $files);
349
+ $files = array_filter($files, array(&$this, '_filter_files'));
350
  $files = array_values(array_unique($files));
351
 
352
  return $files;
353
  }
354
 
355
+ /**
356
+ * URL file filter
357
+ *
358
+ * @param string $file
359
+ * @return bool
360
+ */
361
+ function _filter_files($file) {
362
+ if (w3_is_url($file)) {
363
+ return false;
364
+ }
365
+
366
+ $ext = strrchr($file, '.');
367
+
368
+ if ($ext != '.js' && $ext != '.css') {
369
+ return false;
370
+ }
371
+
372
+ $path = w3_get_document_root() . '/' . $file;
373
+
374
+ if (!file_exists($path)) {
375
+ return false;
376
+ }
377
+
378
+ return true;
379
+ }
380
+
381
  /**
382
  * Removes style tags from the source
383
  *
571
  /**
572
  * Returns current theme
573
  *
574
+ * @return string
575
  */
576
  function get_theme() {
577
  static $theme = null;
629
  * Returns style tag
630
  *
631
  * @param string $url
632
+ * @param boolean $import
633
  * @return string
634
  */
635
  function get_style($url, $import = false) {
644
  * Prints script tag
645
  *
646
  * @param string $url
647
+ * @param boolean $blocking
648
  * @return string
649
  */
650
  function get_script($url, $blocking = true) {
763
  * @param string $template
764
  * @param string $location
765
  * @param string $type
766
+ * @param boolean $rewrite
767
  * @return string
768
  */
769
  function format_url_group($theme, $template, $location, $type, $rewrite = null) {
775
  $site_url_ssl = w3_get_site_url_ssl();
776
 
777
  if ($this->_config->get_boolean('minify.rewrite')) {
778
+ $url = sprintf('%s/%s/%s/%s.%s.%s.%s', $site_url_ssl, W3TC_CONTENT_MINIFY_DIR_NAME, $theme, $template, $location, $id, $type);
779
  } else {
780
+ $url = sprintf('%s/%s/index.php?file=%s/%s.%s.%s.%s', $site_url_ssl, W3TC_CONTENT_MINIFY_DIR_NAME, $theme, $template, $location, $id, $type);
781
  }
782
 
783
  return $url;
801
  $site_url_ssl = w3_get_site_url_ssl();
802
 
803
  if ($this->_config->get_boolean('minify.rewrite')) {
804
+ $url = sprintf('%s/%s/%s.%s.%s', $site_url_ssl, W3TC_CONTENT_MINIFY_DIR_NAME, $hash, $id, $type);
805
  } else {
806
+ $url = sprintf('%s/%s/index.php?file=%s.%s.%s', $site_url_ssl, W3TC_CONTENT_MINIFY_DIR_NAME, $hash, $id, $type);
807
  }
808
 
809
  return $url;
845
 
846
  /**
847
  * Returns debug info
848
+ *
849
+ * @return string
850
  */
851
  function get_debug_info() {
852
  $debug_info = "<!-- W3 Total Cache: Minify debug info:\r\n";
893
  * Skip if doint AJAX
894
  */
895
  if (defined('DOING_AJAX')) {
896
+ $this->minify_reject_reason = 'Doing AJAX';
897
 
898
  return false;
899
  }
902
  * Skip if doing cron
903
  */
904
  if (defined('DOING_CRON')) {
905
+ $this->minify_reject_reason = 'Doing cron';
906
 
907
  return false;
908
  }
911
  * Skip if APP request
912
  */
913
  if (defined('APP_REQUEST')) {
914
+ $this->minify_reject_reason = 'Application request';
915
 
916
  return false;
917
  }
947
  * Check User agent
948
  */
949
  if (!$this->check_ua()) {
950
+ $this->minify_reject_reason = 'User agent is rejected';
951
 
952
  return false;
953
  }
956
  * Check request URI
957
  */
958
  if (!$this->check_request_uri()) {
959
+ $this->minify_reject_reason = 'Request URI is rejected';
960
 
961
  return false;
962
  }
965
  * Skip if user is logged in
966
  */
967
  if ($this->_config->get_boolean('minify.reject.logged') && !$this->check_logged_in()) {
968
+ $this->minify_reject_reason = 'User is logged in';
969
 
970
  return false;
971
  }
974
  * Check feed
975
  */
976
  if ($this->_config->get_boolean('minify.html.reject.feed') && function_exists('is_feed') && is_feed()) {
977
+ $this->minify_reject_reason = 'Feed is rejected';
978
 
979
  return false;
980
  }
985
  /**
986
  * Returns true if we can minify
987
  *
988
+ * @param string $buffer
989
  * @return string
 
990
  */
991
  function can_minify2(&$buffer) {
992
  /**
1016
  * @return boolean
1017
  */
1018
  function check_ua() {
1019
+ $uas = array_merge($this->_config->get_array('minify.reject.ua'), array(
1020
+ W3TC_POWERED_BY
1021
+ ));
1022
+
1023
+ foreach ($uas as $ua) {
1024
  if (isset($_SERVER['HTTP_USER_AGENT']) && stristr($_SERVER['HTTP_USER_AGENT'], $ua) !== false) {
1025
  return false;
1026
  }
1408
  if (file_exists($path)) {
1409
  $data = @file_get_contents($path);
1410
 
1411
+ if ($data !== false) {
1412
+ $data = $this->erase_rules_legacy($data);
1413
+ } else {
1414
  return false;
1415
  }
1416
  } else {
1467
  if (file_exists($path)) {
1468
  $data = @file_get_contents($path);
1469
 
1470
+ if ($data !== false) {
1471
+ $data = $this->erase_rules_legacy($data);
1472
+ } else {
1473
  return false;
1474
  }
1475
  } else {
1516
  }
1517
 
1518
  /**
1519
+ * Erases Minify core directives
1520
  *
1521
  * @param string $data
1522
  * @return string
1528
  }
1529
 
1530
  /**
1531
+ * Erases Minify cache directives
1532
  *
1533
  * @param string $data
1534
  * @return string
1540
  }
1541
 
1542
  /**
1543
+ * Erases Minify legacy directives
1544
+ *
1545
+ * @param string $data
1546
+ * @return string
1547
+ */
1548
+ function erase_rules_legacy($data) {
1549
+ $data = w3_erase_rules($data, W3TC_MARKER_BEGIN_MINIFY_LEGACY, W3TC_MARKER_END_MINIFY_LEGACY);
1550
+
1551
+ return $data;
1552
+ }
1553
+
1554
+ /**
1555
+ * Removes Minify core directives
1556
  *
1557
  * @return boolean
1558
  */
1573
  }
1574
 
1575
  /**
1576
+ * Removes Minify cache directives
1577
  *
1578
  * @return boolean
1579
  */
1594
  }
1595
 
1596
  /**
1597
+ * Removes Minify legacy directives
1598
+ *
1599
+ * @return boolean
1600
+ */
1601
+ function remove_rules_legacy() {
1602
+ $path = w3_get_minify_rules_cache_path();
1603
+
1604
+ if (file_exists($path)) {
1605
+ if (($data = @file_get_contents($path)) !== false) {
1606
+ $data = $this->erase_rules_legacy($data);
1607
+
1608
+ return @file_put_contents($path, $data);
1609
+ }
1610
+
1611
+ return false;
1612
+ }
1613
+
1614
+ return true;
1615
+ }
1616
+
1617
+ /**
1618
+ * Checks if core rules exists
1619
  *
1620
  * @return boolean
1621
  */
1627
  }
1628
 
1629
  /**
1630
+ * Checks if cache rules exists
1631
  *
1632
  * @return boolean
1633
  */
1637
 
1638
  return (($data = @file_get_contents($path)) && strstr(w3_clean_rules($data), w3_clean_rules($search)) !== false);
1639
  }
1640
+
1641
+
1642
+ /**
1643
+ * Check if legacy rules exists
1644
+ *
1645
+ * @return boolean
1646
+ */
1647
+ function check_rules_legacy() {
1648
+ $path = w3_get_minify_rules_core_path();
1649
+
1650
+ return (($data = @file_get_contents($path)) && w3_has_rules(w3_clean_rules($data), W3TC_MARKER_BEGIN_MINIFY_LEGACY, W3TC_MARKER_END_MINIFY_LEGACY));
1651
+ }
1652
  }
lib/W3/Plugin/ObjectCache.php CHANGED
@@ -164,14 +164,14 @@ class W3_Plugin_ObjectCache extends W3_Plugin {
164
  * @return void
165
  */
166
  function cleanup() {
167
- require_once W3TC_LIB_W3_DIR . '/Cache/File/Manager.php';
168
 
169
- $w3_cache_file_manager = & new W3_Cache_File_Manager(array(
170
  'cache_dir' => W3TC_CACHE_FILE_OBJECTCACHE_DIR,
171
  'clean_timelimit' => $this->_config->get_integer('timelimit.cache_gc')
172
  ));
173
 
174
- $w3_cache_file_manager->clean();
175
  }
176
 
177
  /**
164
  * @return void
165
  */
166
  function cleanup() {
167
+ require_once W3TC_LIB_W3_DIR . '/Cache/File/Cleaner.php';
168
 
169
+ $w3_cache_file_cleaner = & new W3_Cache_File_Cleaner(array(
170
  'cache_dir' => W3TC_CACHE_FILE_OBJECTCACHE_DIR,
171
  'clean_timelimit' => $this->_config->get_integer('timelimit.cache_gc')
172
  ));
173
 
174
+ $w3_cache_file_cleaner->clean();
175
  }
176
 
177
  /**
lib/W3/Plugin/PgCache.php CHANGED
@@ -29,7 +29,7 @@ class W3_Plugin_PgCache extends W3_Plugin {
29
  ));
30
 
31
  if ($this->_config->get_boolean('pgcache.enabled')) {
32
- if ($this->_config->get_string('pgcache.engine') == 'file' || $this->_config->get_string('pgcache.engine') == 'file_pgcache') {
33
  add_action('w3_pgcache_cleanup', array(
34
  &$this,
35
  'cleanup'
@@ -123,9 +123,9 @@ class W3_Plugin_PgCache extends W3_Plugin {
123
  * Activate plugin action
124
  */
125
  function activate() {
126
- if ($this->_config->get_boolean('pgcache.enabled') && $this->_config->get_string('pgcache.engine') == 'file_pgcache') {
127
  /**
128
- * Disable enchanged mode if permalink structure is disabled
129
  */
130
  $permalink_structure = get_option('permalink_structure');
131
 
@@ -186,7 +186,7 @@ class W3_Plugin_PgCache extends W3_Plugin {
186
  * Schedules events
187
  */
188
  function schedule() {
189
- if ($this->_config->get_boolean('pgcache.enabled') && ($this->_config->get_string('pgcache.engine') == 'file' || $this->_config->get_string('pgcache.engine') == 'file_pgcache')) {
190
  if (!wp_next_scheduled('w3_pgcache_cleanup')) {
191
  wp_schedule_event(time(), 'w3_pgcache_cleanup', 'w3_pgcache_cleanup');
192
  }
@@ -298,26 +298,29 @@ class W3_Plugin_PgCache extends W3_Plugin {
298
 
299
  switch ($engine) {
300
  case 'file':
301
- require_once W3TC_LIB_W3_DIR . '/Cache/File/Manager.php';
302
 
303
- $w3_cache_file_manager = & new W3_Cache_File_Manager(array(
304
  'cache_dir' => W3TC_CACHE_FILE_PGCACHE_DIR,
305
  'clean_timelimit' => $this->_config->get_integer('timelimit.cache_gc')
306
  ));
307
 
308
- $w3_cache_file_manager->clean();
309
  break;
310
 
311
- case 'file_pgcache':
312
- require_once W3TC_LIB_W3_DIR . '/Cache/File/PgCache/Manager.php';
313
 
314
- $w3_cache_file_pgcache_manager = & new W3_Cache_File_PgCache_Manager(array(
 
 
 
315
  'cache_dir' => W3TC_CACHE_FILE_PGCACHE_DIR,
316
  'expire' => $this->_config->get_integer('browsercache.html.lifetime'),
317
  'clean_timelimit' => $this->_config->get_integer('timelimit.cache_gc')
318
  ));
319
 
320
- $w3_cache_file_pgcache_manager->clean();
321
  break;
322
  }
323
  }
@@ -329,6 +332,8 @@ class W3_Plugin_PgCache extends W3_Plugin {
329
  * @return void
330
  */
331
  function prime($start = 0) {
 
 
332
  /**
333
  * Don't start cache prime if queues are still scheduled
334
  */
@@ -348,32 +353,73 @@ class W3_Plugin_PgCache extends W3_Plugin {
348
 
349
  $interval = $this->_config->get_integer('pgcache.prime.interval');
350
  $limit = $this->_config->get_integer('pgcache.prime.limit');
351
- $sitemap_url = $this->_config->get_string('pgcache.prime.sitemap');
352
- $sitemap_xml = w3_http_get($sitemap_url);
353
-
354
- $queue = array();
355
 
356
  /**
357
  * Parse XML sitemap
358
  */
359
- if ($sitemap_xml) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360
  $url_matches = null;
 
361
 
362
- if (preg_match_all('~<url>(.*)</url>~Uis', $sitemap_xml, $url_matches)) {
363
  $loc_matches = null;
364
- $priority_matches = null;
365
 
 
 
 
 
 
 
 
 
 
 
366
  $locs = array();
 
 
367
 
368
  foreach ($url_matches[1] as $url_match) {
369
  $loc = '';
370
  $priority = 0;
371
 
372
- if (preg_match('~<loc>(.*)</loc>~is', $url_match, $loc_matches)) {
373
  $loc = trim($loc_matches[1]);
374
  }
375
 
376
- if (preg_match('~<priority>(.*)</priority>~is', $url_match, $priority_matches)) {
377
  $priority = (double) trim($priority_matches[1]);
378
  }
379
 
@@ -384,33 +430,17 @@ class W3_Plugin_PgCache extends W3_Plugin {
384
 
385
  arsort($locs);
386
 
387
- $queue = array_keys($locs);
388
  }
389
  }
390
 
391
- /**
392
- * Queue URLs
393
- */
394
- $urls = array_slice($queue, $start, $limit);
395
-
396
- if (count($queue) > ($start + $limit)) {
397
- wp_schedule_single_event(time() + $interval, 'w3_pgcache_prime', array(
398
- $start + $limit
399
- ));
400
- }
401
-
402
- /**
403
- * Make HTTP requests and prime cache
404
- */
405
- foreach ($urls as $url) {
406
- w3_http_get($url);
407
- }
408
  }
409
 
410
  /**
411
  * Cron schedules filter
412
  *
413
- * @paran array $schedules
414
  * @return array
415
  */
416
  function cron_schedules($schedules) {
@@ -598,7 +628,7 @@ class W3_Plugin_PgCache extends W3_Plugin {
598
  $reject_cookies = array_merge($reject_cookies, $this->_config->get_array('pgcache.reject.cookie'));
599
  $reject_uris = array_merge($reject_uris, $this->_config->get_array('pgcache.reject.uri'));
600
  $reject_uris = array_map('w3_parse_path', $reject_uris);
601
- $reject_user_agents = $this->_config->get_array('pgcache.reject.ua');
602
  $accept_uris = $this->_config->get_array('pgcache.accept.uri');
603
  $accept_files = $this->_config->get_array('pgcache.accept.files');
604
 
@@ -858,7 +888,7 @@ class W3_Plugin_PgCache extends W3_Plugin {
858
  $reject_cookies = array_merge($reject_cookies, $this->_config->get_array('pgcache.reject.cookie'));
859
  $reject_uris = array_merge($reject_uris, $this->_config->get_array('pgcache.reject.uri'));
860
  $reject_uris = array_map('w3_parse_path', $reject_uris);
861
- $reject_user_agents = $this->_config->get_array('pgcache.reject.ua');
862
  $accept_uris = $this->_config->get_array('pgcache.accept.uri');
863
  $accept_files = $this->_config->get_array('pgcache.accept.files');
864
 
@@ -1288,6 +1318,7 @@ class W3_Plugin_PgCache extends W3_Plugin {
1288
  $data = @file_get_contents($path);
1289
 
1290
  if ($data !== false) {
 
1291
  $data = $this->erase_rules_wpsc($data);
1292
  } else {
1293
  return false;
@@ -1393,7 +1424,7 @@ class W3_Plugin_PgCache extends W3_Plugin {
1393
  }
1394
 
1395
  /**
1396
- * Erases W3TC directives from config
1397
  *
1398
  * @param string $data
1399
  * @return string
@@ -1405,7 +1436,7 @@ class W3_Plugin_PgCache extends W3_Plugin {
1405
  }
1406
 
1407
  /**
1408
- * Erases W3TC directives from config
1409
  *
1410
  * @param string $data
1411
  * @return string
@@ -1417,19 +1448,31 @@ class W3_Plugin_PgCache extends W3_Plugin {
1417
  }
1418
 
1419
  /**
1420
- * Erases WP Super Cache rules directives config
 
 
 
 
 
 
 
 
 
 
 
 
1421
  *
1422
  * @param string $data
1423
  * @return string
1424
  */
1425
  function erase_rules_wpsc($data) {
1426
- $data = w3_erase_rules($data, W3TC_MARKER_BEGIN_SUPERCACHE, W3TC_MARKER_END_SUPERCACHE);
1427
 
1428
  return $data;
1429
  }
1430
 
1431
  /**
1432
- * Removes W3TC directives from WP .htaccess
1433
  *
1434
  * @return boolean
1435
  */
@@ -1450,7 +1493,7 @@ class W3_Plugin_PgCache extends W3_Plugin {
1450
  }
1451
 
1452
  /**
1453
- * Removes W3TC directives from file cache dir
1454
  *
1455
  * @return boolean
1456
  */
@@ -1471,7 +1514,49 @@ class W3_Plugin_PgCache extends W3_Plugin {
1471
  }
1472
 
1473
  /**
1474
- * Checks core directives
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1475
  *
1476
  * @return boolean
1477
  */
@@ -1483,7 +1568,7 @@ class W3_Plugin_PgCache extends W3_Plugin {
1483
  }
1484
 
1485
  /**
1486
- * Checks cache directives
1487
  *
1488
  * @return boolean
1489
  */
@@ -1493,4 +1578,26 @@ class W3_Plugin_PgCache extends W3_Plugin {
1493
 
1494
  return (($data = @file_get_contents($path)) && strstr(w3_clean_rules($data), w3_clean_rules($search)) !== false);
1495
  }
1496
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  ));
30
 
31
  if ($this->_config->get_boolean('pgcache.enabled')) {
32
+ if ($this->_config->get_string('pgcache.engine') == 'file' || $this->_config->get_string('pgcache.engine') == 'file_generic') {
33
  add_action('w3_pgcache_cleanup', array(
34
  &$this,
35
  'cleanup'
123
  * Activate plugin action
124
  */
125
  function activate() {
126
+ if ($this->_config->get_boolean('pgcache.enabled') && $this->_config->get_string('pgcache.engine') == 'file_generic') {
127
  /**
128
+ * Disable enhanced mode if permalink structure is disabled
129
  */
130
  $permalink_structure = get_option('permalink_structure');
131
 
186
  * Schedules events
187
  */
188
  function schedule() {
189
+ if ($this->_config->get_boolean('pgcache.enabled') && ($this->_config->get_string('pgcache.engine') == 'file' || $this->_config->get_string('pgcache.engine') == 'file_generic')) {
190
  if (!wp_next_scheduled('w3_pgcache_cleanup')) {
191
  wp_schedule_event(time(), 'w3_pgcache_cleanup', 'w3_pgcache_cleanup');
192
  }
298
 
299
  switch ($engine) {
300
  case 'file':
301
+ require_once W3TC_LIB_W3_DIR . '/Cache/File/Cleaner.php';
302
 
303
+ $w3_cache_file_cleaner = & new W3_Cache_File_Cleaner(array(
304
  'cache_dir' => W3TC_CACHE_FILE_PGCACHE_DIR,
305
  'clean_timelimit' => $this->_config->get_integer('timelimit.cache_gc')
306
  ));
307
 
308
+ $w3_cache_file_cleaner->clean();
309
  break;
310
 
311
+ case 'file_generic':
312
+ require_once W3TC_LIB_W3_DIR . '/Cache/File/Cleaner/Generic.php';
313
 
314
+ $w3_cache_file_cleaner_generic = & new W3_Cache_File_Cleaner_Generic(array(
315
+ 'exclude' => array(
316
+ '.htaccess'
317
+ ),
318
  'cache_dir' => W3TC_CACHE_FILE_PGCACHE_DIR,
319
  'expire' => $this->_config->get_integer('browsercache.html.lifetime'),
320
  'clean_timelimit' => $this->_config->get_integer('timelimit.cache_gc')
321
  ));
322
 
323
+ $w3_cache_file_cleaner_generic->clean();
324
  break;
325
  }
326
  }
332
  * @return void
333
  */
334
  function prime($start = 0) {
335
+ $start = (int) $start;
336
+
337
  /**
338
  * Don't start cache prime if queues are still scheduled
339
  */
353
 
354
  $interval = $this->_config->get_integer('pgcache.prime.interval');
355
  $limit = $this->_config->get_integer('pgcache.prime.limit');
356
+ $sitemap = $this->_config->get_string('pgcache.prime.sitemap');
 
 
 
357
 
358
  /**
359
  * Parse XML sitemap
360
  */
361
+ $urls = $this->parse_sitemap($sitemap);
362
+
363
+ /**
364
+ * Queue URLs
365
+ */
366
+ $queue = array_slice($urls, $start, $limit);
367
+
368
+ if (count($urls) > ($start + $limit)) {
369
+ wp_schedule_single_event(time() + $interval, 'w3_pgcache_prime', array(
370
+ $start + $limit
371
+ ));
372
+ }
373
+
374
+ /**
375
+ * Make HTTP requests and prime cache
376
+ */
377
+ foreach ($queue as $url) {
378
+ w3_http_get($url);
379
+ }
380
+ }
381
+
382
+ /**
383
+ * Parses sitemap
384
+ *
385
+ * @param string $xml
386
+ * @return array
387
+ */
388
+ function parse_sitemap($url) {
389
+ $urls = array();
390
+
391
+ $xml = w3_http_get($url);
392
+
393
+ if ($xml) {
394
  $url_matches = null;
395
+ $sitemap_matches = null;
396
 
397
+ if (preg_match_all('~<sitemap>(.*?)</sitemap>~is', $xml, $sitemap_matches)) {
398
  $loc_matches = null;
 
399
 
400
+ foreach ($sitemap_matches[1] as $sitemap_match) {
401
+ if (preg_match('~<loc>(.*?)</loc>~is', $sitemap_match, $loc_matches)) {
402
+ $loc = trim($loc_matches[1]);
403
+
404
+ if ($loc) {
405
+ $urls = array_merge($urls, $this->parse_sitemap($loc));
406
+ }
407
+ }
408
+ }
409
+ } elseif (preg_match_all('~<url>(.*?)</url>~is', $xml, $url_matches)) {
410
  $locs = array();
411
+ $loc_matches = null;
412
+ $priority_matches = null;
413
 
414
  foreach ($url_matches[1] as $url_match) {
415
  $loc = '';
416
  $priority = 0;
417
 
418
+ if (preg_match('~<loc>(.*?)</loc>~is', $url_match, $loc_matches)) {
419
  $loc = trim($loc_matches[1]);
420
  }
421
 
422
+ if (preg_match('~<priority>(.*?)</priority>~is', $url_match, $priority_matches)) {
423
  $priority = (double) trim($priority_matches[1]);
424
  }
425
 
430
 
431
  arsort($locs);
432
 
433
+ $urls = array_keys($locs);
434
  }
435
  }
436
 
437
+ return $urls;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
438
  }
439
 
440
  /**
441
  * Cron schedules filter
442
  *
443
+ * @param array $schedules
444
  * @return array
445
  */
446
  function cron_schedules($schedules) {
628
  $reject_cookies = array_merge($reject_cookies, $this->_config->get_array('pgcache.reject.cookie'));
629
  $reject_uris = array_merge($reject_uris, $this->_config->get_array('pgcache.reject.uri'));
630
  $reject_uris = array_map('w3_parse_path', $reject_uris);
631
+ $reject_user_agents = array_merge(array(W3TC_POWERED_BY), $this->_config->get_array('pgcache.reject.ua'));
632
  $accept_uris = $this->_config->get_array('pgcache.accept.uri');
633
  $accept_files = $this->_config->get_array('pgcache.accept.files');
634
 
888
  $reject_cookies = array_merge($reject_cookies, $this->_config->get_array('pgcache.reject.cookie'));
889
  $reject_uris = array_merge($reject_uris, $this->_config->get_array('pgcache.reject.uri'));
890
  $reject_uris = array_map('w3_parse_path', $reject_uris);
891
+ $reject_user_agents = array_merge(array(W3TC_POWERED_BY), $this->_config->get_array('pgcache.reject.ua'));
892
  $accept_uris = $this->_config->get_array('pgcache.accept.uri');
893
  $accept_files = $this->_config->get_array('pgcache.accept.files');
894
 
1318
  $data = @file_get_contents($path);
1319
 
1320
  if ($data !== false) {
1321
+ $data = $this->erase_rules_legacy($data);
1322
  $data = $this->erase_rules_wpsc($data);
1323
  } else {
1324
  return false;
1424
  }
1425
 
1426
  /**
1427
+ * Erases Page Cache core directives
1428
  *
1429
  * @param string $data
1430
  * @return string
1436
  }
1437
 
1438
  /**
1439
+ * Erases Page Cache cache directives
1440
  *
1441
  * @param string $data
1442
  * @return string
1448
  }
1449
 
1450
  /**
1451
+ * Erases Page Cache legacy directives
1452
+ *
1453
+ * @param string $data
1454
+ * @return string
1455
+ */
1456
+ function erase_rules_legacy($data) {
1457
+ $data = w3_erase_rules($data, W3TC_MARKER_BEGIN_PGCACHE_LEGACY, W3TC_MARKER_END_PGCACHE_LEGACY);
1458
+
1459
+ return $data;
1460
+ }
1461
+
1462
+ /**
1463
+ * Erases WP Super Cache rules directives
1464
  *
1465
  * @param string $data
1466
  * @return string
1467
  */
1468
  function erase_rules_wpsc($data) {
1469
+ $data = w3_erase_rules($data, W3TC_MARKER_BEGIN_PGCACHE_WPSC, W3TC_MARKER_END_PGCACHE_WPSC);
1470
 
1471
  return $data;
1472
  }
1473
 
1474
  /**
1475
+ * Removes Page Cache core directives
1476
  *
1477
  * @return boolean
1478
  */
1493
  }
1494
 
1495
  /**
1496
+ * Removes Page Cache cache directives
1497
  *
1498
  * @return boolean
1499
  */
1514
  }
1515
 
1516
  /**
1517
+ * Removes Page Cache legacy directives
1518
+ *
1519
+ * @return boolean
1520
+ */
1521
+ function remove_rules_legacy() {
1522
+ $path = w3_get_pgcache_rules_core_path();
1523
+
1524
+ if (file_exists($path)) {
1525
+ if (($data = @file_get_contents($path)) !== false) {
1526
+ $data = $this->erase_rules_legacy($data);
1527
+
1528
+ return @file_put_contents($path, $data);
1529
+ }
1530
+
1531
+ return false;
1532
+ }
1533
+
1534
+ return true;
1535
+ }
1536
+
1537
+ /**
1538
+ * Removes WPSC directives
1539
+ *
1540
+ * @return boolean
1541
+ */
1542
+ function remove_rules_wpsc() {
1543
+ $path = w3_get_pgcache_rules_core_path();
1544
+
1545
+ if (file_exists($path)) {
1546
+ if (($data = @file_get_contents($path)) !== false) {
1547
+ $data = $this->erase_rules_wpsc($data);
1548
+
1549
+ return @file_put_contents($path, $data);
1550
+ }
1551
+
1552
+ return false;
1553
+ }
1554
+
1555
+ return true;
1556
+ }
1557
+
1558
+ /**
1559
+ * Checks if core rules exists
1560
  *
1561
  * @return boolean
1562
  */
1568
  }
1569
 
1570
  /**
1571
+ * Checks if cache rules exists
1572
  *
1573
  * @return boolean
1574
  */
1578
 
1579
  return (($data = @file_get_contents($path)) && strstr(w3_clean_rules($data), w3_clean_rules($search)) !== false);
1580
  }
1581
+
1582
+ /**
1583
+ * Check if legacy rules exists
1584
+ *
1585
+ * @return boolean
1586
+ */
1587
+ function check_rules_legacy() {
1588
+ $path = w3_get_pgcache_rules_core_path();
1589
+
1590
+ return (($data = @file_get_contents($path)) && w3_has_rules(w3_clean_rules($data), W3TC_MARKER_BEGIN_PGCACHE_LEGACY, W3TC_MARKER_END_PGCACHE_LEGACY));
1591
+ }
1592
+
1593
+ /**
1594
+ * Check if WPSC rules exists
1595
+ *
1596
+ * @return boolean
1597
+ */
1598
+ function check_rules_wpsc() {
1599
+ $path = w3_get_pgcache_rules_core_path();
1600
+
1601
+ return (($data = @file_get_contents($path)) && w3_has_rules(w3_clean_rules($data), W3TC_MARKER_BEGIN_PGCACHE_WPSC, W3TC_MARKER_END_PGCACHE_WPSC));
1602
+ }
1603
+ }
lib/W3/Plugin/TotalCache.php CHANGED
@@ -15,36 +15,42 @@ if (!defined('W3TC_PLUGIN_TOTALCACHE_REGEXP_COOKIEDOMAIN')) {
15
  class W3_Plugin_TotalCache extends W3_Plugin {
16
  /**
17
  * Current page
 
18
  * @var string
19
  */
20
  var $_page = 'w3tc_general';
21
 
22
  /**
23
  * Notes
 
24
  * @var array
25
  */
26
  var $_notes = array();
27
 
28
  /**
29
  * Errors
 
30
  * @var array
31
  */
32
  var $_errors = array();
33
 
34
  /**
35
  * Show support reminder flag
 
36
  * @var boolean
37
  */
38
  var $_support_reminder = false;
39
 
40
  /**
41
  * Used in PHPMailer init function
 
42
  * @var string
43
  */
44
  var $_phpmailer_sender = '';
45
 
46
  /**
47
  * Array of request types
 
48
  * @var array
49
  */
50
  var $_request_types = array(
@@ -59,6 +65,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
59
 
60
  /**
61
  * Array of request groups
 
62
  * @var array
63
  */
64
  var $_request_groups = array(
@@ -77,6 +84,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
77
 
78
  /**
79
  * Request price list
 
80
  * @var array
81
  */
82
  var $_request_prices = array(
@@ -89,6 +97,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
89
 
90
  /**
91
  * Runs plugin
 
 
92
  */
93
  function run() {
94
  register_activation_hook(W3TC_FILE, array(
@@ -159,19 +169,19 @@ class W3_Plugin_TotalCache extends W3_Plugin {
159
  add_filter('media_row_actions', array(
160
  &$this,
161
  'media_row_actions'
162
- ), null, 2);
163
  }
164
 
165
  if ($this->_config->get_boolean('pgcache.enabled')) {
166
  add_filter('post_row_actions', array(
167
  &$this,
168
  'post_row_actions'
169
- ), null, 2);
170
 
171
  add_filter('page_row_actions', array(
172
  &$this,
173
  'page_row_actions'
174
- ), null, 2);
175
  }
176
 
177
  if (isset($_REQUEST['w3tc_theme']) && isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT'] == W3TC_POWERED_BY) {
@@ -288,6 +298,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
288
 
289
  /**
290
  * Activate plugin action
 
 
291
  */
292
  function activate() {
293
  /**
@@ -388,6 +400,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
388
 
389
  /**
390
  * Deactivate plugin action
 
 
391
  */
392
  function deactivate() {
393
  $this->link_delete();
@@ -412,6 +426,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
412
 
413
  /**
414
  * Init action
 
 
415
  */
416
  function init() {
417
  /**
@@ -442,9 +458,6 @@ class W3_Plugin_TotalCache extends W3_Plugin {
442
  }
443
  }
444
 
445
- /**
446
- * Check rewrite test
447
- */
448
  /**
449
  * Check for rewrite test request
450
  */
@@ -460,6 +473,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
460
 
461
  /**
462
  * Load action
 
 
463
  */
464
  function load() {
465
  require_once W3TC_LIB_W3_DIR . '/Request.php';
@@ -567,6 +582,14 @@ class W3_Plugin_TotalCache extends W3_Plugin {
567
  if (isset($_REQUEST['flush_objectcache'])) {
568
  $this->flush_objectcache();
569
 
 
 
 
 
 
 
 
 
570
  $this->redirect(array(
571
  'w3tc_note' => 'flush_objectcache'
572
  ), true);
@@ -665,6 +688,36 @@ class W3_Plugin_TotalCache extends W3_Plugin {
665
  }
666
  }
667
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
668
  /**
669
  * Write browser cache rules
670
  */
@@ -731,6 +784,21 @@ class W3_Plugin_TotalCache extends W3_Plugin {
731
  ));
732
  }
733
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
734
  }
735
 
736
  /**
@@ -853,6 +921,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
853
 
854
  /**
855
  * Dashboard setup action
 
 
856
  */
857
  function wp_dashboard_setup() {
858
  wp_enqueue_style('w3tc-widget');
@@ -881,6 +951,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
881
 
882
  /**
883
  * Prints latest widget contents
 
 
884
  */
885
  function widget_latest() {
886
  global $wp_version;
@@ -917,6 +989,10 @@ class W3_Plugin_TotalCache extends W3_Plugin {
917
 
918
  /**
919
  * Latest widget control
 
 
 
 
920
  */
921
  function widget_latest_control($widget_id, $form_inputs = array()) {
922
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
@@ -952,6 +1028,10 @@ class W3_Plugin_TotalCache extends W3_Plugin {
952
 
953
  /**
954
  * Latest widget control
 
 
 
 
955
  */
956
  function widget_pagespeed_control($widget_id, $form_inputs = array()) {
957
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
@@ -966,6 +1046,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
966
 
967
  /**
968
  * Admin init
 
 
969
  */
970
  function admin_init() {
971
  wp_register_style('w3tc-options', plugins_url('inc/css/options.css', W3TC_FILE));
@@ -979,6 +1061,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
979
 
980
  /**
981
  * Admin menu
 
 
982
  */
983
  function admin_menu() {
984
  $pages = array(
@@ -1085,6 +1169,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1085
 
1086
  /**
1087
  * Admin bar menu
 
 
1088
  */
1089
  function admin_bar_menu() {
1090
  global $wp_admin_bar;
@@ -1093,7 +1179,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1093
  $menu_items = array(
1094
  array(
1095
  'id' => 'w3tc',
1096
- 'title' => 'Perfomance',
1097
  'href' => admin_url('admin.php?page=w3tc_general')
1098
  ),
1099
  array(
@@ -1203,6 +1289,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1203
  /**
1204
  * Plugin action links filter
1205
  *
 
1206
  * @return array
1207
  */
1208
  function plugin_action_links($links) {
@@ -1213,6 +1300,9 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1213
 
1214
  /**
1215
  * favorite_actions filter
 
 
 
1216
  */
1217
  function favorite_actions($actions) {
1218
  $actions['admin.php?page=w3tc_general&amp;flush_all'] = array(
@@ -1225,6 +1315,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1225
 
1226
  /**
1227
  * Admin notices action
 
 
1228
  */
1229
  function admin_notices() {
1230
  $config_path = (w3_is_preview_config() ? W3TC_CONFIG_PREVIEW_PATH : W3TC_CONFIG_PATH);
@@ -1243,11 +1335,14 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1243
  'fancy_permalinks_disabled_browsercache' => sprintf('Fancy permalinks are disabled. Please %s it first, then re-attempt to enabling the \'Do not process 404 errors for static objects with WordPress\'.', $this->button_link('enable', 'options-permalink.php')),
1244
  'pgcache_write_rules_core' => sprintf('The page cache rules could not be modified. Please %srun <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($pgcache_rules_core_path) ? '' : sprintf('create an empty file in <strong>%s</strong> and ', $pgcache_rules_core_path)), $pgcache_rules_core_path),
1245
  'pgcache_write_rules_cache' => sprintf('The page cache rules could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($pgcache_rules_cache_path) ? $pgcache_rules_cache_path : dirname($pgcache_rules_cache_path))),
 
 
1246
  'browsercache_write_rules_cache' => sprintf('The browser cache rules could not be modified. Please %srun <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($browsercache_rules_cache_path) ? '' : sprintf('create an empty file in <strong>%s</strong> and ', $browsercache_rules_cache_path)), $browsercache_rules_cache_path),
1247
  'browsercache_write_rules_no404wp' => sprintf('The browser cache rules could not be modified. Please %srun <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($browsercache_rules_no404wp_path) ? '' : sprintf('create an empty file in <strong>%s</strong> and ', $browsercache_rules_no404wp_path)), $browsercache_rules_no404wp_path),
1248
  'browsercache_write_rules_cdn' => sprintf('The browser cache rules for <acronym title="Content Delivery Network">CDN</acronym> could not be modified. Please check <acronym title="Content Delivery Network">CDN</acronym> settings.'),
1249
  'minify_write_rules_core' => sprintf('The minify rules could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($minify_rules_core_path) ? $minify_rules_core_path : dirname($minify_rules_core_path))),
1250
  'minify_write_rules_cache' => sprintf('The minify rules could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($minify_rules_cache_path) ? $minify_rules_cache_path : dirname($minify_rules_cache_path))),
 
1251
  'support_request_type' => 'Please select request type.',
1252
  'support_request_url' => 'Please enter the address of the site in the site <acronym title="Uniform Resource Locator">URL</acronym> field.',
1253
  'support_request_name' => 'Please enter your name in the Name field',
@@ -1288,9 +1383,13 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1288
  'flush_minify' => 'Minify cache successfully emptied.',
1289
  'pgcache_write_rules_core' => 'Page cache rewrite rules have been successfully written.',
1290
  'pgcache_write_rules_cache' => 'Page cache rewrite rules have been successfully written.',
 
 
1291
  'browsercache_write_rules_cache' => 'Browser cache directives have been successfully written.',
1292
  'browsercache_write_rules_no404wp' => 'Browser cache directives have been successfully written.',
1293
- 'minify_write_rules' => 'Minify rewrite rules have been successfully written.',
 
 
1294
  'support_request' => 'The support request has been successfully sent.',
1295
  'config_import' => 'Settings successfully imported.',
1296
  'config_reset' => 'Settings successfully restored.',
@@ -1411,6 +1510,13 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1411
  $notes[] = sprintf('The setting change(s) made either invalidate the cached data or modify the behavior of the site. %s now to provide a consistent user experience.', $this->button_link('Empty the page cache', sprintf('admin.php?page=%s&flush_pgcache', $this->_page)));
1412
  }
1413
 
 
 
 
 
 
 
 
1414
  /**
1415
  * Minify notifications
1416
  */
@@ -1444,6 +1550,9 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1444
 
1445
  /**
1446
  * Active plugins pre update option filter
 
 
 
1447
  */
1448
  function pre_update_option_active_plugins($new_value) {
1449
  $old_value = (array) get_option('active_plugins');
@@ -1458,6 +1567,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1458
 
1459
  /**
1460
  * Show plugin changes
 
 
1461
  */
1462
  function in_plugin_update_message() {
1463
  $data = w3_http_get(W3TC_README_URL);
@@ -1500,6 +1611,10 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1500
 
1501
  /**
1502
  * media_row_actions filter
 
 
 
 
1503
  */
1504
  function media_row_actions($actions, $post) {
1505
  $actions = array_merge($actions, array(
@@ -1511,6 +1626,10 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1511
 
1512
  /**
1513
  * post_row_actions filter
 
 
 
 
1514
  */
1515
  function post_row_actions($actions, $post) {
1516
  $actions = array_merge($actions, array(
@@ -1522,6 +1641,10 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1522
 
1523
  /**
1524
  * page_row_actions filter
 
 
 
 
1525
  */
1526
  function page_row_actions($actions, $post) {
1527
  $actions = array_merge($actions, array(
@@ -1627,6 +1750,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1627
 
1628
  /**
1629
  * Footer plugin action
 
 
1630
  */
1631
  function footer() {
1632
  echo '<div style="text-align: center;">Performance Optimization <a href="http://www.w3-edge.com/wordpress-plugins/" rel="external">WordPress Plugins</a> by W3 EDGE</div>';
@@ -1634,6 +1759,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1634
 
1635
  /**
1636
  * Options page
 
 
1637
  */
1638
  function options() {
1639
  /**
@@ -1646,7 +1773,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1646
  $this->_errors[] = sprintf('Page caching is not available. The current add-in %s is either an incorrect file or an old version. De-activate the plugin, remove the file, then activate the plugin again.', W3TC_ADDIN_FILE_ADVANCED_CACHE);
1647
  } elseif (!defined('WP_CACHE') || !WP_CACHE) {
1648
  $this->_errors[] = sprintf('Page caching is not available: please add: <strong>define(\'WP_CACHE\', true);</strong> to <strong>%swp-config.php</strong>. This error message will automatically disappear once the change is successfully made.', ABSPATH);
1649
- } elseif ($this->_config->get_string('pgcache.engine') == 'file_pgcache' && $this->_config->get_boolean('config.check') && w3_can_check_rules()) {
1650
  require_once W3TC_LIB_W3_DIR . '/Plugin/PgCache.php';
1651
  $w3_plugin_pgcache = & W3_Plugin_PgCache::instance();
1652
 
@@ -1658,6 +1785,14 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1658
  $this->_errors[] = sprintf('Disk enhanced page caching is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site above the WordPress directives %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. Or if permission allow this can be done automatically, by clicking here: %s. %s', w3_get_pgcache_rules_core_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_pgcache->generate_rules_core()), $this->button_link('auto-install', sprintf('admin.php?page=%s&pgcache_write_rules_core', $this->_page)), $this->button_hide_note('Hide this message', 'pgcache_rules_core'));
1659
  }
1660
 
 
 
 
 
 
 
 
 
1661
  if ($this->_config->get_boolean('notes.pgcache_rules_cache') && !$w3_plugin_pgcache->check_rules_cache()) {
1662
  $this->_errors[] = sprintf('Disk enhanced page caching is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. This can be done automatically, by clicking here: %s. %s', w3_get_pgcache_rules_cache_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_pgcache->generate_rules_cache()), $this->button_link('auto-install', sprintf('admin.php?page=%s&pgcache_write_rules_cache', $this->_page)), $this->button_hide_note('Hide this message', 'pgcache_rules_cache'));
1663
  }
@@ -1696,6 +1831,10 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1696
  $this->_errors[] = sprintf('Minify is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. This can be done automatically, by clicking here: %s. %s', w3_get_minify_rules_core_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_minify->generate_rules_core()), $this->button_link('auto-install', sprintf('admin.php?page=%s&minify_write_rules_core', $this->_page)), $this->button_hide_note('Hide this message', 'minify_rules_core'));
1697
  }
1698
 
 
 
 
 
1699
  if ($this->_config->get_string('minify.engine') == 'file' && $this->_config->get_boolean('notes.minify_rules_cache') && !$w3_plugin_minify->check_rules_cache()) {
1700
  $this->_errors[] = sprintf('Minify is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. This can be done automatically, by clicking here: %s. %s', w3_get_minify_rules_cache_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_minify->generate_rules_cache()), $this->button_link('auto-install', sprintf('admin.php?page=%s&minify_write_rules_cache', $this->_page)), $this->button_hide_note('Hide this message', 'minify_rules_cache'));
1701
  }
@@ -1866,7 +2005,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
1866
  /**
1867
  * Check permalinks
1868
  */
1869
- if ($this->_config->get_boolean('notes.no_permalink_rules') && (($this->_config->get_boolean('pgcache.enabled') && $this->_config->get_string('pgcache.engine') == 'file_pgcache') || ($this->_config->get_boolean('browsercache.enabled') && $this->_config->get_boolean('browsercache.no404wp'))) && !w3_is_permalink_rules()) {
1870
  $this->_errors[] = sprintf('The required directives for fancy permalinks could not be detected, please confirm they are available: <a href="http://codex.wordpress.org/Using_Permalinks#Creating_and_editing_.28.htaccess.29">Creating and editing</a> %s', $this->button_hide_note('Hide this message', 'no_permalink_rules'));
1871
  }
1872
 
@@ -2027,6 +2166,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2027
 
2028
  /**
2029
  * General tab
 
 
2030
  */
2031
  function options_general() {
2032
  global $current_user;
@@ -2069,7 +2210,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2069
 
2070
  $file_engines = array(
2071
  'file',
2072
- 'file_pgcache'
2073
  );
2074
 
2075
  $can_empty_memcache = ($pgcache_enabled && $pgcache_engine == 'memcached');
@@ -2132,6 +2273,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2132
 
2133
  /**
2134
  * Page cache tab
 
 
2135
  */
2136
  function options_pgcache() {
2137
  global $wp_rewrite;
@@ -2153,6 +2296,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2153
 
2154
  /**
2155
  * Minify tab
 
 
2156
  */
2157
  function options_minify() {
2158
  $minify_enabled = $this->_config->get_boolean('minify.enabled');
@@ -2198,6 +2343,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2198
 
2199
  /**
2200
  * Database cache tab
 
 
2201
  */
2202
  function options_dbcache() {
2203
  $dbcache_enabled = $this->_config->get_boolean('dbcache.enabled');
@@ -2207,6 +2354,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2207
 
2208
  /**
2209
  * Objects cache tab
 
 
2210
  */
2211
  function options_objectcache() {
2212
  $objectcache_enabled = $this->_config->get_boolean('objectcache.enabled');
@@ -2216,6 +2365,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2216
 
2217
  /**
2218
  * Objects cache tab
 
 
2219
  */
2220
  function options_browsercache() {
2221
  $browsercache_enabled = $this->_config->get_boolean('browsercache.enabled');
@@ -2231,6 +2382,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2231
 
2232
  /**
2233
  * Mobile tab
 
 
2234
  */
2235
  function options_mobile() {
2236
  $groups = $this->_config->get_array('mobile.rgroups');
@@ -2245,6 +2398,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2245
 
2246
  /**
2247
  * Referrer tab
 
 
2248
  */
2249
  function options_referrer() {
2250
  $groups = $this->_config->get_array('referrer.rgroups');
@@ -2259,6 +2414,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2259
 
2260
  /**
2261
  * CDN tab
 
 
2262
  */
2263
  function options_cdn() {
2264
  $cdn_enabled = $this->_config->get_boolean('cdn.enabled');
@@ -2275,6 +2432,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2275
 
2276
  /**
2277
  * FAQ tab
 
 
2278
  */
2279
  function options_faq() {
2280
  $faq = $this->parse_faq();
@@ -2284,6 +2443,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2284
 
2285
  /**
2286
  * Support tab
 
 
2287
  */
2288
  function options_support() {
2289
  require_once W3TC_LIB_W3_DIR . '/Request.php';
@@ -2342,6 +2503,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2342
 
2343
  /**
2344
  * Support select tab
 
 
2345
  */
2346
  function options_support_select() {
2347
  require_once W3TC_LIB_W3_DIR . '/Request.php';
@@ -2353,6 +2516,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2353
 
2354
  /**
2355
  * Support payment tab
 
 
2356
  */
2357
  function options_support_payment() {
2358
  require_once W3TC_LIB_W3_DIR . '/Request.php';
@@ -2373,6 +2538,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2373
 
2374
  /**
2375
  * Install tab
 
 
2376
  */
2377
  function options_install() {
2378
  $rewrite_rules = array();
@@ -2483,6 +2650,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2483
 
2484
  /**
2485
  * About tab
 
 
2486
  */
2487
  function options_about() {
2488
  include W3TC_DIR . '/inc/options/about.phtml';
@@ -2490,6 +2659,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2490
 
2491
  /**
2492
  * Options save action
 
 
2493
  */
2494
  function options_save() {
2495
  require_once W3TC_LIB_W3_DIR . '/Request.php';
@@ -2520,7 +2691,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2520
  /**
2521
  * Check permalinks for page cache
2522
  */
2523
- if ($config->get_boolean('pgcache.enabled') && $config->get_string('pgcache.engine') == 'file_pgcache' && !get_option('permalink_structure')) {
2524
  $this->redirect(array(
2525
  'w3tc_error' => 'fancy_permalinks_disabled_pgcache'
2526
  ));
@@ -2530,7 +2701,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2530
  /**
2531
  * Minify tab
2532
  */
2533
- if ($this->_page == 'w3tc_minify') {
2534
  $js_groups = array();
2535
  $css_groups = array();
2536
 
@@ -2915,11 +3086,57 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2915
  * @return void
2916
  */
2917
  function config_save(&$old_config, &$new_config, $preview = null) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2918
  /**
2919
  * Show need empty page cache notification
2920
  */
2921
  if ($new_config->get_boolean('pgcache.enabled')) {
2922
- $pgcache_dependencies = array(
2923
  'pgcache.debug',
2924
  'dbcache.enabled',
2925
  'objectcache.enabled',
@@ -2927,7 +3144,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
2927
  'cdn.enabled',
2928
  'mobile.enabled',
2929
  'referrer.enabled'
2930
- );
2931
 
2932
  if ($new_config->get_boolean('dbcache.enabled')) {
2933
  $pgcache_dependencies = array_merge($pgcache_dependencies, array(
@@ -3002,62 +3219,28 @@ class W3_Plugin_TotalCache extends W3_Plugin {
3002
  ));
3003
  }
3004
 
3005
- if ($new_config->get_boolean('browsercache.enabled')) {
3006
  $pgcache_dependencies = array_merge($pgcache_dependencies, array(
3007
- 'browsercache.cssjs.replace',
3008
- 'browsercache.html.replace',
3009
- 'browsercache.other.replace'
3010
  ));
 
3011
 
3012
- if ($new_config->get_boolean('browsercache.cssjs.replace') || $new_config->get_boolean('browsercache.html.replace') || $new_config->get_boolean('browsercache.other.replace')) {
3013
- $pgcache_dependencies = array_merge($pgcache_dependencies, array(
3014
- 'browsercache.cssjs.compression',
3015
- 'browsercache.cssjs.expires',
3016
- 'browsercache.cssjs.lifetime',
3017
- 'browsercache.cssjs.cache.control',
3018
- 'browsercache.cssjs.cache.policy',
3019
- 'browsercache.cssjs.etag',
3020
- 'browsercache.cssjs.w3tc',
3021
- 'browsercache.html.compression',
3022
- 'browsercache.html.expires',
3023
- 'browsercache.html.lifetime',
3024
- 'browsercache.html.cache.control',
3025
- 'browsercache.html.cache.policy',
3026
- 'browsercache.html.etag',
3027
- 'browsercache.html.w3tc',
3028
- 'browsercache.other.compression',
3029
- 'browsercache.other.expires',
3030
- 'browsercache.other.lifetime',
3031
- 'browsercache.other.cache.control',
3032
- 'browsercache.other.cache.policy',
3033
- 'browsercache.other.etag',
3034
- 'browsercache.other.w3tc'
3035
- ));
3036
- }
3037
-
3038
- if ($new_config->get_boolean('mobile.enabled')) {
3039
- $pgcache_dependencies = array_merge($pgcache_dependencies, array(
3040
- 'mobile.rgroups'
3041
- ));
3042
- }
3043
-
3044
- if ($new_config->get_boolean('referrer.enabled')) {
3045
- $pgcache_dependencies = array_merge($pgcache_dependencies, array(
3046
- 'referrer.rgroups'
3047
- ));
3048
- }
3049
 
3050
- $old_pgcache_dependencies_values = array();
3051
- $new_pgcache_dependencies_values = array();
3052
 
3053
- foreach ($pgcache_dependencies as $pgcache_dependency) {
3054
- $old_pgcache_dependencies_values[] = $old_config->get($pgcache_dependency);
3055
- $new_pgcache_dependencies_values[] = $new_config->get($pgcache_dependency);
3056
- }
3057
 
3058
- if (serialize($old_pgcache_dependencies_values) != serialize($new_pgcache_dependencies_values)) {
3059
- $new_config->set('notes.need_empty_pgcache', true);
3060
- }
3061
  }
3062
  }
3063
 
@@ -3065,14 +3248,14 @@ class W3_Plugin_TotalCache extends W3_Plugin {
3065
  * Show need empty minify notification
3066
  */
3067
  if ($new_config->get_boolean('minify.enabled') && (($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups')))) || ($new_config->get_boolean('minify.js.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.js.groups')))))) {
3068
- $minify_dependencies = array(
3069
  'minify.auto',
3070
  'minify.debug',
3071
  'minify.options',
3072
  'minify.symlinks',
3073
  'minify.css.enable',
3074
  'minify.js.enable'
3075
- );
3076
 
3077
  if ($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups')))) {
3078
  $minify_dependencies = array_merge($minify_dependencies, array(
@@ -3193,43 +3376,26 @@ class W3_Plugin_TotalCache extends W3_Plugin {
3193
  }
3194
 
3195
  /**
3196
- * Set new cache ID if browsercache settings changes
3197
  */
3198
- if ($new_config->get_boolean('browsercache.enabled') && ($new_config->get_boolean('browsercache.cssjs.replace') || $new_config->get_boolean('browsercache.html.replace') || $new_config->get_boolean('browsercache.other.replace'))) {
3199
- $browsercache_dependencies = array(
3200
- 'browsercache.cssjs.compression',
3201
- 'browsercache.cssjs.expires',
3202
- 'browsercache.cssjs.lifetime',
3203
- 'browsercache.cssjs.cache.control',
3204
- 'browsercache.cssjs.cache.policy',
3205
- 'browsercache.cssjs.etag',
3206
- 'browsercache.cssjs.w3tc',
3207
- 'browsercache.html.compression',
3208
- 'browsercache.html.expires',
3209
- 'browsercache.html.lifetime',
3210
- 'browsercache.html.cache.control',
3211
- 'browsercache.html.cache.policy',
3212
- 'browsercache.html.etag',
3213
- 'browsercache.html.w3tc',
3214
- 'browsercache.other.compression',
3215
- 'browsercache.other.expires',
3216
- 'browsercache.other.lifetime',
3217
- 'browsercache.other.cache.control',
3218
- 'browsercache.other.cache.policy',
3219
- 'browsercache.other.etag',
3220
- 'browsercache.other.w3tc'
3221
  );
3222
 
3223
- $old_browsercache_dependencies_values = array();
3224
- $new_browsercache_dependencies_values = array();
3225
 
3226
- foreach ($browsercache_dependencies as $browsercache_dependency) {
3227
- $old_browsercache_dependencies_values[] = $old_config->get($browsercache_dependency);
3228
- $new_browsercache_dependencies_values[] = $new_config->get($browsercache_dependency);
3229
  }
3230
 
3231
- if (serialize($old_browsercache_dependencies_values) != serialize($new_browsercache_dependencies_values)) {
3232
- $new_config->set('browsercache.id', rand(10000, 99999));
3233
  }
3234
  }
3235
 
@@ -3353,7 +3519,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
3353
  /**
3354
  * Write page cache rewrite rules
3355
  */
3356
- if ($new_config->get_boolean('pgcache.enabled') && $new_config->get_string('pgcache.engine') == 'file_pgcache') {
3357
  if (w3_can_modify_rules(w3_get_pgcache_rules_core_path())) {
3358
  $w3_plugin_pgcache->write_rules_core();
3359
  }
@@ -3544,6 +3710,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
3544
 
3545
  /**
3546
  * Save preview option
 
 
3547
  */
3548
  function preview_save() {
3549
  require_once W3TC_LIB_W3_DIR . '/Request.php';
@@ -3576,7 +3744,9 @@ class W3_Plugin_TotalCache extends W3_Plugin {
3576
  }
3577
 
3578
  /**
3579
- * Depoly preview settings action
 
 
3580
  */
3581
  function preview_deploy() {
3582
  if ($this->_config->save(false)) {
@@ -3594,6 +3764,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
3594
 
3595
  /**
3596
  * Select support type action
 
 
3597
  */
3598
  function support_select() {
3599
  require_once W3TC_LIB_W3_DIR . '/Request.php';
@@ -3620,6 +3792,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
3620
 
3621
  /**
3622
  * Send support request
 
 
3623
  */
3624
  function support_request() {
3625
  require_once W3TC_LIB_W3_DIR . '/Request.php';
@@ -4027,6 +4201,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4027
 
4028
  /**
4029
  * CDN queue action
 
 
4030
  */
4031
  function cdn_queue() {
4032
  require_once W3TC_LIB_W3_DIR . '/Request.php';
@@ -4074,6 +4250,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4074
 
4075
  /**
4076
  * CDN export library action
 
 
4077
  */
4078
  function cdn_export_library() {
4079
  require_once W3TC_LIB_W3_DIR . '/Plugin/Cdn.php';
@@ -4088,6 +4266,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4088
 
4089
  /**
4090
  * CDN export library process
 
 
4091
  */
4092
  function cdn_export_library_process() {
4093
  require_once W3TC_LIB_W3_DIR . '/Request.php';
@@ -4117,6 +4297,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4117
 
4118
  /**
4119
  * CDN import library action
 
 
4120
  */
4121
  function cdn_import_library() {
4122
  require_once W3TC_LIB_W3_DIR . '/Plugin/Cdn.php';
@@ -4134,6 +4316,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4134
 
4135
  /**
4136
  * CDN import library process
 
 
4137
  */
4138
  function cdn_import_library_process() {
4139
  require_once W3TC_LIB_W3_DIR . '/Request.php';
@@ -4163,6 +4347,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4163
 
4164
  /**
4165
  * CDN rename domain action
 
 
4166
  */
4167
  function cdn_rename_domain() {
4168
  require_once W3TC_LIB_W3_DIR . '/Plugin/Cdn.php';
@@ -4178,6 +4364,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4178
 
4179
  /**
4180
  * CDN rename domain process
 
 
4181
  */
4182
  function cdn_rename_domain_process() {
4183
  require_once W3TC_LIB_W3_DIR . '/Request.php';
@@ -4208,6 +4396,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4208
 
4209
  /**
4210
  * CDN export action
 
 
4211
  */
4212
  function cdn_export() {
4213
  require_once W3TC_LIB_W3_DIR . '/Request.php';
@@ -4245,6 +4435,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4245
 
4246
  /**
4247
  * CDN export process
 
 
4248
  */
4249
  function cdn_export_process() {
4250
  require_once W3TC_LIB_W3_DIR . '/Request.php';
@@ -4274,6 +4466,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4274
 
4275
  /**
4276
  * CDN purge action
 
 
4277
  */
4278
  function cdn_purge() {
4279
  $title = 'Content Delivery Network (CDN): Purge Tool';
@@ -4284,6 +4478,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4284
 
4285
  /**
4286
  * CDN purge post action
 
 
4287
  */
4288
  function cdn_purge_post() {
4289
  $title = 'Content Delivery Network (CDN): Purge Tool';
@@ -4337,7 +4533,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4337
  }
4338
 
4339
  /**
4340
- * Uploads browsercache .htaccess to FTP
4341
  *
4342
  * @return void
4343
  */
@@ -4364,7 +4560,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4364
  }
4365
 
4366
  /**
4367
- * Deletes browsercache .htaccess to FTP
4368
  *
4369
  * @return void
4370
  */
@@ -4444,6 +4640,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4444
 
4445
  /**
4446
  * Create container action
 
 
4447
  */
4448
  function cdn_create_container() {
4449
  require_once W3TC_LIB_W3_DIR . '/Request.php';
@@ -4495,16 +4693,19 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4495
 
4496
  /**
4497
  * CDN Purge Post
 
 
4498
  */
4499
  function cdn_purge_attachment() {
4500
  require_once W3TC_LIB_W3_DIR . '/Request.php';
4501
  require_once W3TC_LIB_W3_DIR . '/Plugin/Cdn.php';
4502
 
 
4503
  $attachment_id = W3_Request::get_integer('attachment_id');
4504
 
4505
  $w3_plugin_cdn = & W3_Plugin_Cdn::instance();
4506
 
4507
- if ($w3_plugin_cdn->purge_attachment($attachment_id)) {
4508
  $this->redirect(array(
4509
  'w3tc_note' => 'cdn_purge_attachment'
4510
  ), true);
@@ -4515,7 +4716,6 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4515
  }
4516
  }
4517
 
4518
-
4519
  /**
4520
  * S3 bucket location lightbox
4521
  *
@@ -4538,6 +4738,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4538
 
4539
  /**
4540
  * PgCache purge post
 
 
4541
  */
4542
  function pgcache_purge_post() {
4543
  require_once W3TC_LIB_W3_DIR . '/Request.php';
@@ -4560,6 +4762,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4560
 
4561
  /**
4562
  * PgCache purge page
 
 
4563
  */
4564
  function pgcache_purge_page() {
4565
  require_once W3TC_LIB_W3_DIR . '/Request.php';
@@ -4588,7 +4792,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4588
  */
4589
  function is_memcache_available($servers) {
4590
  static $results = array();
4591
- $key = md5(serialize($servers));
 
4592
 
4593
  if (!isset($results[$key])) {
4594
  require_once W3TC_LIB_W3_DIR . '/Cache/Memcached.php';
@@ -4609,6 +4814,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4609
 
4610
  /**
4611
  * Test memcached
 
 
4612
  */
4613
  function test_memcached() {
4614
  require_once W3TC_LIB_W3_DIR . '/Request.php';
@@ -4633,6 +4840,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4633
 
4634
  /**
4635
  * Test minifier action
 
 
4636
  */
4637
  function test_minifier() {
4638
  if (W3TC_PHP5) {
@@ -4729,7 +4938,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4729
  $data = w3_http_get($url);
4730
 
4731
  if ($data !== false) {
4732
- $result = ($data == 'OK');
4733
  } else {
4734
  $result = true;
4735
  }
@@ -4744,6 +4953,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4744
 
4745
  /**
4746
  * Update plugin link
 
 
4747
  */
4748
  function link_update() {
4749
  $this->link_delete();
@@ -4752,6 +4963,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4752
 
4753
  /**
4754
  * Insert plugin link into Blogroll
 
 
4755
  */
4756
  function link_insert() {
4757
  $support = $this->_config->get_string('common.support');
@@ -4771,6 +4984,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4771
 
4772
  /**
4773
  * Deletes plugin link from Blogroll
 
 
4774
  */
4775
  function link_delete() {
4776
  $bookmarks = get_bookmarks();
@@ -4838,6 +5053,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4838
 
4839
  /**
4840
  * Flush APC cache
 
4841
  * @return void
4842
  */
4843
  function flush_opcode() {
@@ -4854,7 +5070,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4854
  */
4855
  function flush_file() {
4856
  $this->flush('file');
4857
- $this->flush('file_pgcache');
4858
  }
4859
 
4860
  /**
@@ -4870,6 +5086,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4870
 
4871
  /**
4872
  * Flush page cache
 
 
4873
  */
4874
  function flush_pgcache() {
4875
  require_once W3TC_LIB_W3_DIR . '/PgCache.php';
@@ -4879,6 +5097,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4879
 
4880
  /**
4881
  * Flush page cache
 
 
4882
  */
4883
  function flush_dbcache() {
4884
  require_once W3TC_LIB_W3_DIR . '/Db.php';
@@ -4888,6 +5108,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4888
 
4889
  /**
4890
  * Flush page cache
 
 
4891
  */
4892
  function flush_objectcache() {
4893
  require_once W3TC_LIB_W3_DIR . '/ObjectCache.php';
@@ -4897,6 +5119,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
4897
 
4898
  /**
4899
  * Flush minify cache
 
 
4900
  */
4901
  function flush_minify() {
4902
  if (W3TC_PHP5) {
@@ -5080,7 +5304,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
5080
  }
5081
 
5082
  /**
5083
- * Skip if doint AJAX
5084
  */
5085
  if (defined('DOING_AJAX')) {
5086
  return false;
@@ -5114,11 +5338,20 @@ class W3_Plugin_TotalCache extends W3_Plugin {
5114
  return false;
5115
  }
5116
 
 
 
 
 
 
 
 
5117
  return true;
5118
  }
5119
 
5120
  /**
5121
  * Returns server info
 
 
5122
  */
5123
  function get_server_info() {
5124
  global $wp_version, $wp_db_version, $wpdb;
@@ -5177,6 +5410,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
5177
 
5178
  /**
5179
  * Support us lightbox
 
 
5180
  */
5181
  function support_us() {
5182
  $supports = $this->get_supports();
@@ -5186,6 +5421,8 @@ class W3_Plugin_TotalCache extends W3_Plugin {
5186
 
5187
  /**
5188
  * Minify recommendations lightbox
 
 
5189
  */
5190
  function minify_recommendations() {
5191
  $themes = $this->get_themes();
@@ -5294,15 +5531,17 @@ class W3_Plugin_TotalCache extends W3_Plugin {
5294
  /**
5295
  * Redirect function
5296
  *
5297
- * @param boolean $check_referer
 
 
5298
  */
5299
- function redirect($params = array(), $check_referer = false) {
5300
  require_once W3TC_LIB_W3_DIR . '/Request.php';
5301
 
5302
  $url = W3_Request::get_string('redirect');
5303
 
5304
  if ($url == '') {
5305
- if ($check_referer && !empty($_SERVER['HTTP_REFERER'])) {
5306
  $url = $_SERVER['HTTP_REFERER'];
5307
  } else {
5308
  $url = 'admin.php';
@@ -5383,6 +5622,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
5383
  /**
5384
  * Returns minify groups
5385
  *
 
5386
  * @return array
5387
  */
5388
  function get_theme_templates($theme_name) {
@@ -5404,7 +5644,7 @@ class W3_Plugin_TotalCache extends W3_Plugin {
5404
  /**
5405
  * Returns array of detected URLs for theme templates
5406
  *
5407
- * @param string $theme_name
5408
  * @return array
5409
  */
5410
  function get_theme_urls($theme_name) {
@@ -5820,32 +6060,6 @@ class W3_Plugin_TotalCache extends W3_Plugin {
5820
  * @return array
5821
  */
5822
  function _get_theme_recommendations($groups) {
5823
- /**
5824
- * Replace CDN hosts to local host
5825
- */
5826
- if ($this->_config->get_boolean('cdn.enabled')) {
5827
- require_once W3TC_LIB_W3_DIR . '/Plugin/Cdn.php';
5828
-
5829
- $w3_plugin_cdn = & W3_Plugin_Cdn::instance();
5830
- $cdn = & $w3_plugin_cdn->get_cdn();
5831
-
5832
- $search = array();
5833
- $domains = $cdn->get_domains();
5834
-
5835
- foreach ($domains as $domain) {
5836
- $_domains = array_map('trim', explode(',', $domain));
5837
- $search = array_merge($search, $_domains);
5838
- }
5839
-
5840
- $replace = w3_get_domain(w3_get_host());
5841
-
5842
- foreach ($groups as $template => $files) {
5843
- foreach ($files as $index => $file) {
5844
- $groups[$template][$index] = str_replace($search, $replace, $file);
5845
- }
5846
- }
5847
- }
5848
-
5849
  /**
5850
  * First calculate file usage count
5851
  */
@@ -5978,9 +6192,9 @@ class W3_Plugin_TotalCache extends W3_Plugin {
5978
  * @return string
5979
  */
5980
  function link_replace_callback($matches) {
5981
- list (, $attr, $quote, $domain_url, , $path) = $matches;
5982
 
5983
- $path .= (strstr($path, '?') !== false ? '&' : '?') . 'w3tc_preview=1';
5984
 
5985
  return sprintf('%s=%s%s%s', $attr, $quote, $domain_url, $path);
5986
  }
15
  class W3_Plugin_TotalCache extends W3_Plugin {
16
  /**
17
  * Current page
18
+ *
19
  * @var string
20
  */
21
  var $_page = 'w3tc_general';
22
 
23
  /**
24
  * Notes
25
+ *
26
  * @var array
27
  */
28
  var $_notes = array();
29
 
30
  /**
31
  * Errors
32
+ *
33
  * @var array
34
  */
35
  var $_errors = array();
36
 
37
  /**
38
  * Show support reminder flag
39
+ *
40
  * @var boolean
41
  */
42
  var $_support_reminder = false;
43
 
44
  /**
45
  * Used in PHPMailer init function
46
+ *
47
  * @var string
48
  */
49
  var $_phpmailer_sender = '';
50
 
51
  /**
52
  * Array of request types
53
+ *
54
  * @var array
55
  */
56
  var $_request_types = array(
65
 
66
  /**
67
  * Array of request groups
68
+ *
69
  * @var array
70
  */
71
  var $_request_groups = array(
84
 
85
  /**
86
  * Request price list
87
+ *
88
  * @var array
89
  */
90
  var $_request_prices = array(
97
 
98
  /**
99
  * Runs plugin
100
+ *
101
+ * @return void
102
  */
103
  function run() {
104
  register_activation_hook(W3TC_FILE, array(
169
  add_filter('media_row_actions', array(
170
  &$this,
171
  'media_row_actions'
172
+ ), 0, 2);
173
  }
174
 
175
  if ($this->_config->get_boolean('pgcache.enabled')) {
176
  add_filter('post_row_actions', array(
177
  &$this,
178
  'post_row_actions'
179
+ ), 0, 2);
180
 
181
  add_filter('page_row_actions', array(
182
  &$this,
183
  'page_row_actions'
184
+ ), 0, 2);
185
  }
186
 
187
  if (isset($_REQUEST['w3tc_theme']) && isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT'] == W3TC_POWERED_BY) {
298
 
299
  /**
300
  * Activate plugin action
301
+ *
302
+ * @return void
303
  */
304
  function activate() {
305
  /**
400
 
401
  /**
402
  * Deactivate plugin action
403
+ *
404
+ * @return void
405
  */
406
  function deactivate() {
407
  $this->link_delete();
426
 
427
  /**
428
  * Init action
429
+ *
430
+ * @return void
431
  */
432
  function init() {
433
  /**
458
  }
459
  }
460
 
 
 
 
461
  /**
462
  * Check for rewrite test request
463
  */
473
 
474
  /**
475
  * Load action
476
+ *
477
+ * @return void
478
  */
479
  function load() {
480
  require_once W3TC_LIB_W3_DIR . '/Request.php';
582
  if (isset($_REQUEST['flush_objectcache'])) {
583
  $this->flush_objectcache();
584
 
585
+ $this->_config->set('notes.need_empty_objectcache', false);
586
+
587
+ if (!$this->_config->save()) {
588
+ $this->redirect(array(
589
+ 'w3tc_error' => 'config_save'
590
+ ), true);
591
+ }
592
+
593
  $this->redirect(array(
594
  'w3tc_note' => 'flush_objectcache'
595
  ), true);
688
  }
689
  }
690
 
691
+ if (isset($_REQUEST['pgcache_remove_rules_legacy'])) {
692
+ require_once W3TC_LIB_W3_DIR . '/Plugin/PgCache.php';
693
+ $w3_plugin_pgcache = & W3_Plugin_PgCache::instance();
694
+
695
+ if ($w3_plugin_pgcache->remove_rules_legacy()) {
696
+ $this->redirect(array(
697
+ 'w3tc_note' => 'pgcache_remove_rules_legacy'
698
+ ));
699
+ } else {
700
+ $this->redirect(array(
701
+ 'w3tc_error' => 'pgcache_remove_rules_legacy'
702
+ ));
703
+ }
704
+ }
705
+
706
+ if (isset($_REQUEST['pgcache_remove_rules_wpsc'])) {
707
+ require_once W3TC_LIB_W3_DIR . '/Plugin/PgCache.php';
708
+ $w3_plugin_pgcache = & W3_Plugin_PgCache::instance();
709
+
710
+ if ($w3_plugin_pgcache->remove_rules_wpsc()) {
711
+ $this->redirect(array(
712
+ 'w3tc_note' => 'pgcache_remove_rules_wpsc'
713
+ ));
714
+ } else {
715
+ $this->redirect(array(
716
+ 'w3tc_error' => 'pgcache_remove_rules_wpsc'
717
+ ));
718
+ }
719
+ }
720
+
721
  /**
722
  * Write browser cache rules
723
  */
784
  ));
785
  }
786
  }
787
+
788
+ if (isset($_REQUEST['minify_remove_rules_legacy'])) {
789
+ require_once W3TC_LIB_W3_DIR . '/Plugin/Minify.php';
790
+ $w3_plugin_minify = & W3_Plugin_Minify::instance();
791
+
792
+ if ($w3_plugin_minify->remove_rules_legacy()) {
793
+ $this->redirect(array(
794
+ 'w3tc_note' => 'minify_remove_rules_legacy'
795
+ ));
796
+ } else {
797
+ $this->redirect(array(
798
+ 'w3tc_error' => 'minify_remove_rules_legacy'
799
+ ));
800
+ }
801
+ }
802
  }
803
 
804
  /**
921
 
922
  /**
923
  * Dashboard setup action
924
+ *
925
+ * @return void
926
  */
927
  function wp_dashboard_setup() {
928
  wp_enqueue_style('w3tc-widget');
951
 
952
  /**
953
  * Prints latest widget contents
954
+ *
955
+ * @return void
956
  */
957
  function widget_latest() {
958
  global $wp_version;
989
 
990
  /**
991
  * Latest widget control
992
+ *
993
+ * @param integer $widget_id
994
+ * @param array $form_inputs
995
+ * @return void
996
  */
997
  function widget_latest_control($widget_id, $form_inputs = array()) {
998
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
1028
 
1029
  /**
1030
  * Latest widget control
1031
+ *
1032
+ * @param integer $widget_id
1033
+ * @param array $form_inputs
1034
+ * @return void
1035
  */
1036
  function widget_pagespeed_control($widget_id, $form_inputs = array()) {
1037
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
1046
 
1047
  /**
1048
  * Admin init
1049
+ *
1050
+ * @return void
1051
  */
1052
  function admin_init() {
1053
  wp_register_style('w3tc-options', plugins_url('inc/css/options.css', W3TC_FILE));
1061
 
1062
  /**
1063
  * Admin menu
1064
+ *
1065
+ * @return void
1066
  */
1067
  function admin_menu() {
1068
  $pages = array(
1169
 
1170
  /**
1171
  * Admin bar menu
1172
+ *
1173
+ * @return void
1174
  */
1175
  function admin_bar_menu() {
1176
  global $wp_admin_bar;
1179
  $menu_items = array(
1180
  array(
1181
  'id' => 'w3tc',
1182
+ 'title' => 'Performance',
1183
  'href' => admin_url('admin.php?page=w3tc_general')
1184
  ),
1185
  array(
1289
  /**
1290
  * Plugin action links filter
1291
  *
1292
+ * @param array $links
1293
  * @return array
1294
  */
1295
  function plugin_action_links($links) {
1300
 
1301
  /**
1302
  * favorite_actions filter
1303
+ *
1304
+ * @param array $actions
1305
+ * @return void
1306
  */
1307
  function favorite_actions($actions) {
1308
  $actions['admin.php?page=w3tc_general&amp;flush_all'] = array(
1315
 
1316
  /**
1317
  * Admin notices action
1318
+ *
1319
+ * @return void
1320
  */
1321
  function admin_notices() {
1322
  $config_path = (w3_is_preview_config() ? W3TC_CONFIG_PREVIEW_PATH : W3TC_CONFIG_PATH);
1335
  'fancy_permalinks_disabled_browsercache' => sprintf('Fancy permalinks are disabled. Please %s it first, then re-attempt to enabling the \'Do not process 404 errors for static objects with WordPress\'.', $this->button_link('enable', 'options-permalink.php')),
1336
  'pgcache_write_rules_core' => sprintf('The page cache rules could not be modified. Please %srun <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($pgcache_rules_core_path) ? '' : sprintf('create an empty file in <strong>%s</strong> and ', $pgcache_rules_core_path)), $pgcache_rules_core_path),
1337
  'pgcache_write_rules_cache' => sprintf('The page cache rules could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($pgcache_rules_cache_path) ? $pgcache_rules_cache_path : dirname($pgcache_rules_cache_path))),
1338
+ 'pgcache_remove_rules_legacy' => sprintf('The legacy page cache rules could not be removed. Please run <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($pgcache_rules_cache_path) ? $pgcache_rules_cache_path : dirname($pgcache_rules_cache_path))),
1339
+ 'pgcache_remove_rules_wpsc' => sprintf('The WP Super Cache rules could not be removed. Please run <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($pgcache_rules_cache_path) ? $pgcache_rules_cache_path : dirname($pgcache_rules_cache_path))),
1340
  'browsercache_write_rules_cache' => sprintf('The browser cache rules could not be modified. Please %srun <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($browsercache_rules_cache_path) ? '' : sprintf('create an empty file in <strong>%s</strong> and ', $browsercache_rules_cache_path)), $browsercache_rules_cache_path),
1341
  'browsercache_write_rules_no404wp' => sprintf('The browser cache rules could not be modified. Please %srun <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($browsercache_rules_no404wp_path) ? '' : sprintf('create an empty file in <strong>%s</strong> and ', $browsercache_rules_no404wp_path)), $browsercache_rules_no404wp_path),
1342
  'browsercache_write_rules_cdn' => sprintf('The browser cache rules for <acronym title="Content Delivery Network">CDN</acronym> could not be modified. Please check <acronym title="Content Delivery Network">CDN</acronym> settings.'),
1343
  'minify_write_rules_core' => sprintf('The minify rules could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($minify_rules_core_path) ? $minify_rules_core_path : dirname($minify_rules_core_path))),
1344
  'minify_write_rules_cache' => sprintf('The minify rules could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($minify_rules_cache_path) ? $minify_rules_cache_path : dirname($minify_rules_cache_path))),
1345
+ 'minify_remove_rules_legacy' => sprintf('The legacy minify rules could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($minify_rules_cache_path) ? $minify_rules_cache_path : dirname($minify_rules_cache_path))),
1346
  'support_request_type' => 'Please select request type.',
1347
  'support_request_url' => 'Please enter the address of the site in the site <acronym title="Uniform Resource Locator">URL</acronym> field.',
1348
  'support_request_name' => 'Please enter your name in the Name field',
1383
  'flush_minify' => 'Minify cache successfully emptied.',
1384
  'pgcache_write_rules_core' => 'Page cache rewrite rules have been successfully written.',
1385
  'pgcache_write_rules_cache' => 'Page cache rewrite rules have been successfully written.',
1386
+ 'pgcache_remove_rules_legacy' => 'Legacy page cache configuration settings have been successfully removed.',
1387
+ 'pgcache_remove_rules_wpsc' => 'WP Super Cache configuration settings have been successfully removed.',
1388
  'browsercache_write_rules_cache' => 'Browser cache directives have been successfully written.',
1389
  'browsercache_write_rules_no404wp' => 'Browser cache directives have been successfully written.',
1390
+ 'minify_write_rules_core' => 'Minify rewrite rules have been successfully written.',
1391
+ 'minify_write_rules_cache' => 'Minify rewrite rules have been successfully written.',
1392
+ 'minify_remove_rules_legacy' => 'Legacy minify configuration settings have been successfuly removed.',
1393
  'support_request' => 'The support request has been successfully sent.',
1394
  'config_import' => 'Settings successfully imported.',
1395
  'config_reset' => 'Settings successfully restored.',
1510
  $notes[] = sprintf('The setting change(s) made either invalidate the cached data or modify the behavior of the site. %s now to provide a consistent user experience.', $this->button_link('Empty the page cache', sprintf('admin.php?page=%s&flush_pgcache', $this->_page)));
1511
  }
1512
 
1513
+ /**
1514
+ * Show notification when object cache needs to be emptied
1515
+ */
1516
+ if ($this->_config->get_boolean('objectcache.enabled') && $this->_config->get('notes.need_empty_objectcache') && !w3_is_preview_config()) {
1517
+ $notes[] = sprintf('The setting change(s) made either invalidate the cached data or modify the behavior of the site. %s now to provide a consistent user experience.', $this->button_link('Empty the object cache', sprintf('admin.php?page=%s&flush_objectcache', $this->_page)));
1518
+ }
1519
+
1520
  /**
1521
  * Minify notifications
1522
  */
1550
 
1551
  /**
1552
  * Active plugins pre update option filter
1553
+ *
1554
+ * @param string $new_value
1555
+ * @return string
1556
  */
1557
  function pre_update_option_active_plugins($new_value) {
1558
  $old_value = (array) get_option('active_plugins');
1567
 
1568
  /**
1569
  * Show plugin changes
1570
+ *
1571
+ * @return void
1572
  */
1573
  function in_plugin_update_message() {
1574
  $data = w3_http_get(W3TC_README_URL);
1611
 
1612
  /**
1613
  * media_row_actions filter
1614
+ *
1615
+ * @param array $actions
1616
+ * @param object $post
1617
+ * @return array
1618
  */
1619
  function media_row_actions($actions, $post) {
1620
  $actions = array_merge($actions, array(
1626
 
1627
  /**
1628
  * post_row_actions filter
1629
+ *
1630
+ * @param array $actions
1631
+ * @param object $post
1632
+ * @return array
1633
  */
1634
  function post_row_actions($actions, $post) {
1635
  $actions = array_merge($actions, array(
1641
 
1642
  /**
1643
  * page_row_actions filter
1644
+ *
1645
+ * @param array $actions
1646
+ * @param object $post
1647
+ * @return array
1648
  */
1649
  function page_row_actions($actions, $post) {
1650
  $actions = array_merge($actions, array(
1750
 
1751
  /**
1752
  * Footer plugin action
1753
+ *
1754
+ * @return void
1755
  */
1756
  function footer() {
1757
  echo '<div style="text-align: center;">Performance Optimization <a href="http://www.w3-edge.com/wordpress-plugins/" rel="external">WordPress Plugins</a> by W3 EDGE</div>';
1759
 
1760
  /**
1761
  * Options page
1762
+ *
1763
+ * @return void
1764
  */
1765
  function options() {
1766
  /**
1773
  $this->_errors[] = sprintf('Page caching is not available. The current add-in %s is either an incorrect file or an old version. De-activate the plugin, remove the file, then activate the plugin again.', W3TC_ADDIN_FILE_ADVANCED_CACHE);
1774
  } elseif (!defined('WP_CACHE') || !WP_CACHE) {
1775
  $this->_errors[] = sprintf('Page caching is not available: please add: <strong>define(\'WP_CACHE\', true);</strong> to <strong>%swp-config.php</strong>. This error message will automatically disappear once the change is successfully made.', ABSPATH);
1776
+ } elseif ($this->_config->get_string('pgcache.engine') == 'file_generic' && $this->_config->get_boolean('config.check') && w3_can_check_rules()) {
1777
  require_once W3TC_LIB_W3_DIR . '/Plugin/PgCache.php';
1778
  $w3_plugin_pgcache = & W3_Plugin_PgCache::instance();
1779
 
1785
  $this->_errors[] = sprintf('Disk enhanced page caching is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site above the WordPress directives %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. Or if permission allow this can be done automatically, by clicking here: %s. %s', w3_get_pgcache_rules_core_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_pgcache->generate_rules_core()), $this->button_link('auto-install', sprintf('admin.php?page=%s&pgcache_write_rules_core', $this->_page)), $this->button_hide_note('Hide this message', 'pgcache_rules_core'));
1786
  }
1787
 
1788
+ if ($this->_config->get_boolean('notes.pgcache_rules_legacy') && $w3_plugin_pgcache->check_rules_legacy()) {
1789
+ $this->_errors[] = sprintf('Legacy Page Cache rewrite rules have been found. To remove them manually, edit the configuration file (<strong>%s</strong>) and remove all lines between and including <strong>%s</strong> and <strong>%s</strong> markers inclusive. Or if permission allow this can be done automatically, by clicking here: %s. %s', w3_get_pgcache_rules_core_path(), W3TC_MARKER_BEGIN_PGCACHE_LEGACY, W3TC_MARKER_END_PGCACHE_LEGACY, $this->button_link('auto-remove', sprintf('admin.php?page=%s&pgcache_remove_rules_legacy', $this->_page)), $this->button_hide_note('Hide this message', 'pgcache_rules_legacy'));
1790
+ }
1791
+
1792
+ if ($this->_config->get_boolean('notes.pgcache_rules_wpsc') && $w3_plugin_pgcache->check_rules_wpsc()) {
1793
+ $this->_errors[] = sprintf('WP Super Cache rewrite rules have been found. To remove them manually, edit the configuration file (<strong>%s</strong>) and remove all lines between and including <strong>%s</strong> and <strong>%s</strong> markers inclusive. Or if permission allow this can be done automatically, by clicking here: %s. %s', w3_get_pgcache_rules_core_path(), W3TC_MARKER_BEGIN_PGCACHE_WPSC, W3TC_MARKER_END_PGCACHE_WPSC, $this->button_link('auto-remove', sprintf('admin.php?page=%s&pgcache_remove_rules_wpsc', $this->_page)), $this->button_hide_note('Hide this message', 'pgcache_rules_wpsc'));
1794
+ }
1795
+
1796
  if ($this->_config->get_boolean('notes.pgcache_rules_cache') && !$w3_plugin_pgcache->check_rules_cache()) {
1797
  $this->_errors[] = sprintf('Disk enhanced page caching is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. This can be done automatically, by clicking here: %s. %s', w3_get_pgcache_rules_cache_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_pgcache->generate_rules_cache()), $this->button_link('auto-install', sprintf('admin.php?page=%s&pgcache_write_rules_cache', $this->_page)), $this->button_hide_note('Hide this message', 'pgcache_rules_cache'));
1798
  }
1831
  $this->_errors[] = sprintf('Minify is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. This can be done automatically, by clicking here: %s. %s', w3_get_minify_rules_core_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_minify->generate_rules_core()), $this->button_link('auto-install', sprintf('admin.php?page=%s&minify_write_rules_core', $this->_page)), $this->button_hide_note('Hide this message', 'minify_rules_core'));
1832
  }
1833
 
1834
+ if ($this->_config->get_boolean('notes.minify_rules_legacy') && $w3_plugin_minify->check_rules_legacy()) {
1835
+ $this->_errors[] = sprintf('Legacy Minify rewrite rules have been found. To remove them manually, edit the configuration file (<strong>%s</strong>) and remove all lines between and including <strong>%s</strong> and <strong>%s</strong> markers inclusive. Or if permission allow this can be done automatically, by clicking here: %s. %s', w3_get_minify_rules_core_path(), W3TC_MARKER_BEGIN_MINIFY_LEGACY, W3TC_MARKER_END_MINIFY_LEGACY, $this->button_link('auto-remove', sprintf('admin.php?page=%s&minify_remove_rules_legacy', $this->_page)), $this->button_hide_note('Hide this message', 'minify_rules_legacy'));
1836
+ }
1837
+
1838
  if ($this->_config->get_string('minify.engine') == 'file' && $this->_config->get_boolean('notes.minify_rules_cache') && !$w3_plugin_minify->check_rules_cache()) {
1839
  $this->_errors[] = sprintf('Minify is not active. To enable it, add the following rules into the server configuration file (<strong>%s</strong>) of the site %s <textarea class="w3tc-rules" cols="120" rows="10" readonly="readonly">%s</textarea>. This can be done automatically, by clicking here: %s. %s', w3_get_minify_rules_cache_path(), $this->button('view code', '', 'w3tc-show-rules'), htmlspecialchars($w3_plugin_minify->generate_rules_cache()), $this->button_link('auto-install', sprintf('admin.php?page=%s&minify_write_rules_cache', $this->_page)), $this->button_hide_note('Hide this message', 'minify_rules_cache'));
1840
  }
2005
  /**
2006
  * Check permalinks
2007
  */
2008
+ if ($this->_config->get_boolean('notes.no_permalink_rules') && (($this->_config->get_boolean('pgcache.enabled') && $this->_config->get_string('pgcache.engine') == 'file_generic') || ($this->_config->get_boolean('browsercache.enabled') && $this->_config->get_boolean('browsercache.no404wp'))) && !w3_is_permalink_rules()) {
2009
  $this->_errors[] = sprintf('The required directives for fancy permalinks could not be detected, please confirm they are available: <a href="http://codex.wordpress.org/Using_Permalinks#Creating_and_editing_.28.htaccess.29">Creating and editing</a> %s', $this->button_hide_note('Hide this message', 'no_permalink_rules'));
2010
  }
2011
 
2166
 
2167
  /**
2168
  * General tab
2169
+ *
2170
+ * @return void
2171
  */
2172
  function options_general() {
2173
  global $current_user;
2210
 
2211
  $file_engines = array(
2212
  'file',
2213
+ 'file_generic'
2214
  );
2215
 
2216
  $can_empty_memcache = ($pgcache_enabled && $pgcache_engine == 'memcached');
2273
 
2274
  /**
2275
  * Page cache tab
2276
+ *
2277
+ * @return void
2278
  */
2279
  function options_pgcache() {
2280
  global $wp_rewrite;
2296
 
2297
  /**
2298
  * Minify tab
2299
+ *
2300
+ * @return void
2301
  */
2302
  function options_minify() {
2303
  $minify_enabled = $this->_config->get_boolean('minify.enabled');
2343
 
2344
  /**
2345
  * Database cache tab
2346
+ *
2347
+ * @return void
2348
  */
2349
  function options_dbcache() {
2350
  $dbcache_enabled = $this->_config->get_boolean('dbcache.enabled');
2354
 
2355
  /**
2356
  * Objects cache tab
2357
+ *
2358
+ * @return void
2359
  */
2360
  function options_objectcache() {
2361
  $objectcache_enabled = $this->_config->get_boolean('objectcache.enabled');
2365
 
2366
  /**
2367
  * Objects cache tab
2368
+ *
2369
+ * @return void
2370
  */
2371
  function options_browsercache() {
2372
  $browsercache_enabled = $this->_config->get_boolean('browsercache.enabled');
2382
 
2383
  /**
2384
  * Mobile tab
2385
+ *
2386
+ * @return void
2387
  */
2388
  function options_mobile() {
2389
  $groups = $this->_config->get_array('mobile.rgroups');
2398
 
2399
  /**
2400
  * Referrer tab
2401
+ *
2402
+ * @return void
2403
  */
2404
  function options_referrer() {
2405
  $groups = $this->_config->get_array('referrer.rgroups');
2414
 
2415
  /**
2416
  * CDN tab
2417
+ *
2418
+ * @return void
2419
  */
2420
  function options_cdn() {
2421
  $cdn_enabled = $this->_config->get_boolean('cdn.enabled');
2432
 
2433
  /**
2434
  * FAQ tab
2435
+ *
2436
+ * @return void
2437
  */
2438
  function options_faq() {
2439
  $faq = $this->parse_faq();
2443
 
2444
  /**
2445
  * Support tab
2446
+ *
2447
+ * @return void
2448
  */
2449
  function options_support() {
2450
  require_once W3TC_LIB_W3_DIR . '/Request.php';
2503
 
2504
  /**
2505
  * Support select tab
2506
+ *
2507
+ * @return void
2508
  */
2509
  function options_support_select() {
2510
  require_once W3TC_LIB_W3_DIR . '/Request.php';
2516
 
2517
  /**
2518
  * Support payment tab
2519
+ *
2520
+ * @return void
2521
  */
2522
  function options_support_payment() {
2523
  require_once W3TC_LIB_W3_DIR . '/Request.php';
2538
 
2539
  /**
2540
  * Install tab
2541
+ *
2542
+ * @return void
2543
  */
2544
  function options_install() {
2545
  $rewrite_rules = array();
2650
 
2651
  /**
2652
  * About tab
2653
+ *
2654
+ * @return void
2655
  */
2656
  function options_about() {
2657
  include W3TC_DIR . '/inc/options/about.phtml';
2659
 
2660
  /**
2661
  * Options save action
2662
+ *
2663
+ * @return void
2664
  */
2665
  function options_save() {
2666
  require_once W3TC_LIB_W3_DIR . '/Request.php';
2691
  /**
2692
  * Check permalinks for page cache
2693
  */
2694
+ if ($config->get_boolean('pgcache.enabled') && $config->get_string('pgcache.engine') == 'file_generic' && !get_option('permalink_structure')) {
2695
  $this->redirect(array(
2696
  'w3tc_error' => 'fancy_permalinks_disabled_pgcache'
2697
  ));
2701
  /**
2702
  * Minify tab
2703
  */
2704
+ if ($this->_page == 'w3tc_minify' && !$this->_config->get_boolean('minify.auto')) {
2705
  $js_groups = array();
2706
  $css_groups = array();
2707
 
3086
  * @return void
3087
  */
3088
  function config_save(&$old_config, &$new_config, $preview = null) {
3089
+ $browsercache_dependencies = array();
3090
+
3091
+ if ($new_config->get_boolean('browsercache.enabled')) {
3092
+ $browsercache_dependencies = array_merge($browsercache_dependencies, array(
3093
+ 'browsercache.cssjs.replace',
3094
+ 'browsercache.html.replace',
3095
+ 'browsercache.other.replace'
3096
+ ));
3097
+
3098
+ if ($new_config->get_boolean('browsercache.cssjs.replace')) {
3099
+ $browsercache_dependencies = array_merge($browsercache_dependencies, array(
3100
+ 'browsercache.cssjs.compression',
3101
+ 'browsercache.cssjs.expires',
3102
+ 'browsercache.cssjs.lifetime',
3103
+ 'browsercache.cssjs.cache.control',
3104
+ 'browsercache.cssjs.cache.policy',
3105
+ 'browsercache.cssjs.etag',
3106
+ 'browsercache.cssjs.w3tc'
3107
+ ));
3108
+ }
3109
+
3110
+ if ($new_config->get_boolean('browsercache.html.replace')) {
3111
+ $browsercache_dependencies = array_merge($browsercache_dependencies, array(
3112
+ 'browsercache.html.compression',
3113
+ 'browsercache.html.expires',
3114
+ 'browsercache.html.lifetime',
3115
+ 'browsercache.html.cache.control',
3116
+ 'browsercache.html.cache.policy',
3117
+ 'browsercache.html.etag',
3118
+ 'browsercache.html.w3tc'
3119
+ ));
3120
+ }
3121
+
3122
+ if ($new_config->get_boolean('browsercache.other.replace')) {
3123
+ $browsercache_dependencies = array_merge($browsercache_dependencies, array(
3124
+ 'browsercache.other.compression',
3125
+ 'browsercache.other.expires',
3126
+ 'browsercache.other.lifetime',
3127
+ 'browsercache.other.cache.control',
3128
+ 'browsercache.other.cache.policy',
3129
+ 'browsercache.other.etag',
3130
+ 'browsercache.other.w3tc'
3131
+ ));
3132
+ }
3133
+ }
3134
+
3135
  /**
3136
  * Show need empty page cache notification
3137
  */
3138
  if ($new_config->get_boolean('pgcache.enabled')) {
3139
+ $pgcache_dependencies = array_merge($browsercache_dependencies, array(
3140
  'pgcache.debug',
3141
  'dbcache.enabled',
3142
  'objectcache.enabled',
3144
  'cdn.enabled',
3145
  'mobile.enabled',
3146
  'referrer.enabled'
3147
+ ));
3148
 
3149
  if ($new_config->get_boolean('dbcache.enabled')) {
3150
  $pgcache_dependencies = array_merge($pgcache_dependencies, array(
3219
  ));
3220
  }
3221
 
3222
+ if ($new_config->get_boolean('mobile.enabled')) {
3223
  $pgcache_dependencies = array_merge($pgcache_dependencies, array(
3224
+ 'mobile.rgroups'
 
 
3225
  ));
3226
+ }
3227
 
3228
+ if ($new_config->get_boolean('referrer.enabled')) {
3229
+ $pgcache_dependencies = array_merge($pgcache_dependencies, array(
3230
+ 'referrer.rgroups'
3231
+ ));
3232
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3233
 
3234
+ $old_pgcache_dependencies_values = array();
3235
+ $new_pgcache_dependencies_values = array();
3236
 
3237
+ foreach ($pgcache_dependencies as $pgcache_dependency) {
3238
+ $old_pgcache_dependencies_values[] = $old_config->get($pgcache_dependency);
3239
+ $new_pgcache_dependencies_values[] = $new_config->get($pgcache_dependency);
3240
+ }
3241
 
3242
+ if (serialize($old_pgcache_dependencies_values) != serialize($new_pgcache_dependencies_values)) {
3243
+ $new_config->set('notes.need_empty_pgcache', true);
 
3244
  }
3245
  }
3246
 
3248
  * Show need empty minify notification
3249
  */
3250
  if ($new_config->get_boolean('minify.enabled') && (($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups')))) || ($new_config->get_boolean('minify.js.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.js.groups')))))) {
3251
+ $minify_dependencies = array_merge($browsercache_dependencies, array(
3252
  'minify.auto',
3253
  'minify.debug',
3254
  'minify.options',
3255
  'minify.symlinks',
3256
  'minify.css.enable',
3257
  'minify.js.enable'
3258
+ ));
3259
 
3260
  if ($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups')))) {
3261
  $minify_dependencies = array_merge($minify_dependencies, array(
3376
  }
3377
 
3378
  /**
3379
+ * Show need empty object cache notification
3380
  */
3381
+ if ($this->_config->get_boolean('objectcache.enabled')) {
3382
+ $objectcache_dependencies = array(
3383
+ 'objectcache.reject.admin',
3384
+ 'objectcache.reject.uri',
3385
+ 'objectcache.groups.global',
3386
+ 'objectcache.groups.nonpersistent'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3387
  );
3388
 
3389
+ $old_objectcache_dependencies_values = array();
3390
+ $new_objectcache_dependencies_values = array();
3391
 
3392
+ foreach ($objectcache_dependencies as $objectcache_dependency) {
3393
+ $old_objectcache_dependencies_values[] = $old_config->get($objectcache_dependency);
3394
+ $new_objectcache_dependencies_values[] = $new_config->get($objectcache_dependency);
3395
  }
3396
 
3397
+ if (serialize($old_objectcache_dependencies_values) != serialize($new_objectcache_dependencies_values)) {
3398
+ $new_config->set('notes.need_empty_objectcache', true);
3399
  }
3400
  }
3401
 
3519
  /**
3520
  * Write page cache rewrite rules
3521
  */
3522
+ if ($new_config->get_boolean('pgcache.enabled') && $new_config->get_string('pgcache.engine') == 'file_generic') {
3523
  if (w3_can_modify_rules(w3_get_pgcache_rules_core_path())) {
3524
  $w3_plugin_pgcache->write_rules_core();
3525
  }
3710
 
3711
  /**
3712
  * Save preview option
3713
+ *
3714
+ * @return void
3715
  */
3716
  function preview_save() {
3717
  require_once W3TC_LIB_W3_DIR . '/Request.php';
3744
  }
3745
 
3746
  /**
3747
+ * Deploy preview settings action
3748
+ *
3749
+ * @return void
3750
  */
3751
  function preview_deploy() {
3752
  if ($this->_config->save(false)) {
3764
 
3765
  /**
3766
  * Select support type action
3767
+ *
3768
+ * @return void
3769
  */
3770
  function support_select() {
3771
  require_once W3TC_LIB_W3_DIR . '/Request.php';
3792
 
3793
  /**
3794
  * Send support request
3795
+ *
3796
+ * @return void
3797
  */
3798
  function support_request() {
3799
  require_once W3TC_LIB_W3_DIR . '/Request.php';
4201
 
4202
  /**
4203
  * CDN queue action
4204
+ *
4205
+ * @return void
4206
  */
4207
  function cdn_queue() {
4208
  require_once W3TC_LIB_W3_DIR . '/Request.php';
4250
 
4251
  /**
4252
  * CDN export library action
4253
+ *
4254
+ * @return void
4255
  */
4256
  function cdn_export_library() {
4257
  require_once W3TC_LIB_W3_DIR . '/Plugin/Cdn.php';
4266
 
4267
  /**
4268
  * CDN export library process
4269
+ *
4270
+ * @return void
4271
  */
4272
  function cdn_export_library_process() {
4273
  require_once W3TC_LIB_W3_DIR . '/Request.php';
4297
 
4298
  /**
4299
  * CDN import library action
4300
+ *
4301
+ * @return void
4302
  */
4303
  function cdn_import_library() {
4304
  require_once W3TC_LIB_W3_DIR . '/Plugin/Cdn.php';
4316
 
4317
  /**
4318
  * CDN import library process
4319
+ *
4320
+ * @return void
4321
  */
4322
  function cdn_import_library_process() {
4323
  require_once W3TC_LIB_W3_DIR . '/Request.php';
4347
 
4348
  /**
4349
  * CDN rename domain action
4350
+ *
4351
+ * @return void
4352
  */
4353
  function cdn_rename_domain() {
4354
  require_once W3TC_LIB_W3_DIR . '/Plugin/Cdn.php';
4364
 
4365
  /**
4366
  * CDN rename domain process
4367
+ *
4368
+ * @return void
4369
  */
4370
  function cdn_rename_domain_process() {
4371
  require_once W3TC_LIB_W3_DIR . '/Request.php';
4396
 
4397
  /**
4398
  * CDN export action
4399
+ *
4400
+ * @return void
4401
  */
4402
  function cdn_export() {
4403
  require_once W3TC_LIB_W3_DIR . '/Request.php';
4435
 
4436
  /**
4437
  * CDN export process
4438
+ *
4439
+ * @return void
4440
  */
4441
  function cdn_export_process() {
4442
  require_once W3TC_LIB_W3_DIR . '/Request.php';
4466
 
4467
  /**
4468
  * CDN purge action
4469
+ *
4470
+ * @return void
4471
  */
4472
  function cdn_purge() {
4473
  $title = 'Content Delivery Network (CDN): Purge Tool';
4478
 
4479
  /**
4480
  * CDN purge post action
4481
+ *
4482
+ * @return void
4483
  */
4484
  function cdn_purge_post() {
4485
  $title = 'Content Delivery Network (CDN): Purge Tool';
4533
  }
4534
 
4535
  /**
4536
+ * Uploads Browser Cache .htaccess to FTP
4537
  *
4538
  * @return void
4539
  */
4560
  }
4561
 
4562
  /**
4563
+ * Deletes Browser Cache .htaccess from FTP
4564
  *
4565
  * @return void
4566
  */
4640
 
4641
  /**
4642
  * Create container action
4643
+ *
4644
+ * @return void
4645
  */
4646
  function cdn_create_container() {
4647
  require_once W3TC_LIB_W3_DIR . '/Request.php';
4693
 
4694
  /**
4695
  * CDN Purge Post
4696
+ *
4697
+ * @return void
4698
  */
4699
  function cdn_purge_attachment() {
4700
  require_once W3TC_LIB_W3_DIR . '/Request.php';
4701
  require_once W3TC_LIB_W3_DIR . '/Plugin/Cdn.php';
4702
 
4703
+ $results = array();
4704
  $attachment_id = W3_Request::get_integer('attachment_id');
4705
 
4706
  $w3_plugin_cdn = & W3_Plugin_Cdn::instance();
4707
 
4708
+ if ($w3_plugin_cdn->purge_attachment($attachment_id, $results)) {
4709
  $this->redirect(array(
4710
  'w3tc_note' => 'cdn_purge_attachment'
4711
  ), true);
4716
  }
4717
  }
4718
 
 
4719
  /**
4720
  * S3 bucket location lightbox
4721
  *
4738
 
4739
  /**
4740
  * PgCache purge post
4741
+ *
4742
+ * @return void
4743
  */
4744
  function pgcache_purge_post() {
4745
  require_once W3TC_LIB_W3_DIR . '/Request.php';
4762
 
4763
  /**
4764
  * PgCache purge page
4765
+ *
4766
+ * @return void
4767
  */
4768
  function pgcache_purge_page() {
4769
  require_once W3TC_LIB_W3_DIR . '/Request.php';
4792
  */
4793
  function is_memcache_available($servers) {
4794
  static $results = array();
4795
+
4796
+ $key = md5(implode('', $servers));
4797
 
4798
  if (!isset($results[$key])) {
4799
  require_once W3TC_LIB_W3_DIR . '/Cache/Memcached.php';
4814
 
4815
  /**
4816
  * Test memcached
4817
+ *
4818
+ * @return void
4819
  */
4820
  function test_memcached() {
4821
  require_once W3TC_LIB_W3_DIR . '/Request.php';
4840
 
4841
  /**
4842
  * Test minifier action
4843
+ *
4844
+ * @return void
4845
  */
4846
  function test_minifier() {
4847
  if (W3TC_PHP5) {
4938
  $data = w3_http_get($url);
4939
 
4940
  if ($data !== false) {
4941
+ $result = (trim($data) == 'OK');
4942
  } else {
4943
  $result = true;
4944
  }
4953
 
4954
  /**
4955
  * Update plugin link
4956
+ *
4957
+ * @return void
4958
  */
4959
  function link_update() {
4960
  $this->link_delete();
4963
 
4964
  /**
4965
  * Insert plugin link into Blogroll
4966
+ *
4967
+ * @return void
4968
  */
4969
  function link_insert() {
4970
  $support = $this->_config->get_string('common.support');
4984
 
4985
  /**
4986
  * Deletes plugin link from Blogroll
4987
+ *
4988
+ * @return void
4989
  */
4990
  function link_delete() {
4991
  $bookmarks = get_bookmarks();
5053
 
5054
  /**
5055
  * Flush APC cache
5056
+ *
5057
  * @return void
5058
  */
5059
  function flush_opcode() {
5070
  */
5071
  function flush_file() {
5072
  $this->flush('file');
5073
+ $this->flush('file_generic');
5074
  }
5075
 
5076
  /**
5086
 
5087
  /**
5088
  * Flush page cache
5089
+ *
5090
+ * @return void
5091
  */
5092
  function flush_pgcache() {
5093
  require_once W3TC_LIB_W3_DIR . '/PgCache.php';
5097
 
5098
  /**
5099
  * Flush page cache
5100
+ *
5101
+ * @return void
5102
  */
5103
  function flush_dbcache() {
5104
  require_once W3TC_LIB_W3_DIR . '/Db.php';
5108
 
5109
  /**
5110
  * Flush page cache
5111
+ *
5112
+ * @return void
5113
  */
5114
  function flush_objectcache() {
5115
  require_once W3TC_LIB_W3_DIR . '/ObjectCache.php';
5119
 
5120
  /**
5121
  * Flush minify cache
5122
+ *
5123
+ * @return void
5124
  */
5125
  function flush_minify() {
5126
  if (W3TC_PHP5) {
5304
  }
5305
 
5306
  /**
5307
+ * Skip if doing AJAX
5308
  */
5309
  if (defined('DOING_AJAX')) {
5310
  return false;
5338
  return false;
5339
  }
5340
 
5341
+ /**
5342
+ * Check User Agent
5343
+ */
5344
+ if (isset($_SERVER['HTTP_USER_AGENT']) && stristr($_SERVER['HTTP_USER_AGENT'], W3TC_POWERED_BY) !== false) {
5345
+ return false;
5346
+ }
5347
+
5348
  return true;
5349
  }
5350
 
5351
  /**
5352
  * Returns server info
5353
+ *
5354
+ * @return array
5355
  */
5356
  function get_server_info() {
5357
  global $wp_version, $wp_db_version, $wpdb;
5410
 
5411
  /**
5412
  * Support us lightbox
5413
+ *
5414
+ * @return void
5415
  */
5416
  function support_us() {
5417
  $supports = $this->get_supports();
5421
 
5422
  /**
5423
  * Minify recommendations lightbox
5424
+ *
5425
+ * @return void
5426
  */
5427
  function minify_recommendations() {
5428
  $themes = $this->get_themes();
5531
  /**
5532
  * Redirect function
5533
  *
5534
+ * @param array $params
5535
+ * @param boolean $check_referrer
5536
+ * @return void
5537
  */
5538
+ function redirect($params = array(), $check_referrer = false) {
5539
  require_once W3TC_LIB_W3_DIR . '/Request.php';
5540
 
5541
  $url = W3_Request::get_string('redirect');
5542
 
5543
  if ($url == '') {
5544
+ if ($check_referrer && !empty($_SERVER['HTTP_REFERER'])) {
5545
  $url = $_SERVER['HTTP_REFERER'];
5546
  } else {
5547
  $url = 'admin.php';
5622
  /**
5623
  * Returns minify groups
5624
  *
5625
+ * @param string $theme_name
5626
  * @return array
5627
  */
5628
  function get_theme_templates($theme_name) {
5644
  /**
5645
  * Returns array of detected URLs for theme templates
5646
  *
5647
+ * @param string $theme_name
5648
  * @return array
5649
  */
5650
  function get_theme_urls($theme_name) {
6060
  * @return array
6061
  */
6062
  function _get_theme_recommendations($groups) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6063
  /**
6064
  * First calculate file usage count
6065
  */
6192
  * @return string
6193
  */
6194
  function link_replace_callback($matches) {
6195
+ list (, $attr, $quote, $domain_url, , , $path) = $matches;
6196
 
6197
+ $path .= (strstr($path, '?') !== false ? '&amp;' : '?') . 'w3tc_preview=1';
6198
 
6199
  return sprintf('%s=%s%s%s', $attr, $quote, $domain_url, $path);
6200
  }
lib/W3/Request.php CHANGED
@@ -60,7 +60,7 @@ class W3_Request {
60
  * Returns double value
61
  *
62
  * @param string $key
63
- * @param double $default
64
  * @return double
65
  */
66
  function get_double($key, $default = 0.) {
60
  * Returns double value
61
  *
62
  * @param string $key
63
+ * @param double|float $default
64
  * @return double
65
  */
66
  function get_double($key, $default = 0.) {
lib/W3/Varnish.php CHANGED
@@ -68,7 +68,7 @@ class W3_Varnish {
68
  * Purge URI
69
  *
70
  * @param string $uri
71
- * @return bool
72
  */
73
  function purge($uri) {
74
  @set_time_limit($this->_timeout);
68
  * Purge URI
69
  *
70
  * @param string $uri
71
+ * @return boolean
72
  */
73
  function purge($uri) {
74
  @set_time_limit($this->_timeout);
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: fredericktownes
3
  Tags: user experience, cache, caching, page cache, css cache, js cache, db cache, disk cache, disk caching, database cache, http compression, gzip, deflate, minify, cdn, content delivery network, media library, performance, speed, multiple hosts, css, merge, combine, unobtrusive javascript, compress, optimize, optimizer, javascript, js, cascading style sheet, plugin, yslow, yui, google, google rank, google page speed, mod_pagespeed, s3, cloudfront, aws, amazon web services, cloud files, rackspace, cotendo, max cdn, limelight, cloudflare, microsoft, microsoft azure, iis, nginx, apache, varnish, xcache, apc, eacclerator, wincache, mysql, w3 total cache, batcache, wp cache, wp super cache, buddypress
4
  Requires at least: 2.8
5
  Tested up to: 3.2
6
- Stable tag: 0.9.2.2
7
 
8
  Improve site performance and user experience via caching: browser, page, object, database, minify and content delivery network support.
9
 
@@ -249,6 +249,11 @@ Install the plugin to read the full FAQ.
249
 
250
  == Press: Mentions, Tutorials &amp; Reviews ==
251
 
 
 
 
 
 
252
  **May 2011:**
253
 
254
  * [Optimizing WordPress with Nginx, Varnish, APC, W3 Total Cache, and Amazon S3 (With Benchmarks)](http://danielmiessler.com/blog/optimizing-wordpress-with-nginx-varnish-w3-total-cache-amazon-s3-and-memcached), Daniel Miessler
@@ -273,7 +278,7 @@ Install the plugin to read the full FAQ.
273
  **February 2011:**
274
 
275
  * [Optimizing WordPress with Nginx, Varnish, W3 Total Cache, Amazon S3, and Memcached (With Benchmarks)](http://danielmiessler.com/blog/optimizing-wordpress-with-nginx-varnish-w3-total-cache-amazon-s3-and-memcached), Daniel Miessler
276
- * [My WordPress site loads in 2 seconds does yours?](http://labsecrets.com/blog/2011/02/14/my-wordpress-site-loads-in-two-seconds-does-yours/)
277
 
278
  **January 2011:**
279
 
@@ -285,14 +290,14 @@ Install the plugin to read the full FAQ.
285
  **December 2010:**
286
 
287
  * [Best blog plugins](http://www.blog.web6.org/best-blog-plugins/)
288
- * [How To Make Your WordPress Blog Load Faster(http://www.johnchow.com/how-to-make-your-wordpress-blog-load-faster/), John Chow
289
  * [Unleash the Power of WordPress Using Plugin Combos](http://freelancefolder.com/unleash-the-power-of-wordpress-using-plugin-combos/), Paul de Wouters
290
  * [Rackspace Cloud Files for WordPress](http://sporkmarketing.com/blog/1095/rackspace-cloud-files-wordpress/), Jason Lancaster
291
 
292
  **November 2010:**
293
 
294
  * [Make your blog super fast with W3 Total Cache plugin](http://laspas.gr/2010/11/26/make-blog-super-fast-w3-total-cache-plugin/), Stratos Laspas
295
- * [10 WordPress Plugins Im Thankful For (And Cannot Live Without)](http://wpmu.org/10-wordpress-plugins-im-thankful-for-and-cannot-live-without/), Sarah Gooding
296
  * [Subjective Results of Installing W3 Total Cache Plugin](http://www.codyhatch.com/administriva/subjective-results-of-installing-w3-total-cache-plugin/), Cody Hatch
297
  * [13 Plugins Your WordPress Site Might Need](http://www.jonbishop.com/2010/11/13-plugins-your-wordpress-site-might-need/), Jon Bishop
298
  * [Best WordPress Plugins that Marketers Use](http://www.nicoleonthenet.com/6390/best-wordpress-plugins-marketers-use/), Nicole Dean
@@ -442,6 +447,16 @@ Please reach out to all of these people and support their projects if you're so
442
 
443
  == Changelog ==
444
 
 
 
 
 
 
 
 
 
 
 
445
  = 0.9.2.2 =
446
  * Fixed bug with minify directives, e.g.: "File param is missing," causing minify caching to fail
447
  * Fixed bug with document root detection for IIS server
3
  Tags: user experience, cache, caching, page cache, css cache, js cache, db cache, disk cache, disk caching, database cache, http compression, gzip, deflate, minify, cdn, content delivery network, media library, performance, speed, multiple hosts, css, merge, combine, unobtrusive javascript, compress, optimize, optimizer, javascript, js, cascading style sheet, plugin, yslow, yui, google, google rank, google page speed, mod_pagespeed, s3, cloudfront, aws, amazon web services, cloud files, rackspace, cotendo, max cdn, limelight, cloudflare, microsoft, microsoft azure, iis, nginx, apache, varnish, xcache, apc, eacclerator, wincache, mysql, w3 total cache, batcache, wp cache, wp super cache, buddypress
4
  Requires at least: 2.8
5
  Tested up to: 3.2
6
+ Stable tag: 0.9.2.3
7
 
8
  Improve site performance and user experience via caching: browser, page, object, database, minify and content delivery network support.
9
 
249
 
250
  == Press: Mentions, Tutorials &amp; Reviews ==
251
 
252
+ **June 2011:**
253
+
254
+ * [WordPress Optimization Results: Varnish/Nginx/APC + W3 Total Cache + Amazon S3 + CloudFlare](http://danielmiessler.com/blog/wordpress-optimization-results-varnishnginxapc-w3-total-cache-amazon-s3-cloudflare), Daniel Miessler
255
+ * [Case Study: WordPress, MaxCDN, CloudFlare and W3 Total Cache Integration](http://www.thewebhostinghero.com/articles/case-study-wp-maxcdn-cloudflare.html), Ritesh Sanap
256
+
257
  **May 2011:**
258
 
259
  * [Optimizing WordPress with Nginx, Varnish, APC, W3 Total Cache, and Amazon S3 (With Benchmarks)](http://danielmiessler.com/blog/optimizing-wordpress-with-nginx-varnish-w3-total-cache-amazon-s3-and-memcached), Daniel Miessler
278
  **February 2011:**
279
 
280
  * [Optimizing WordPress with Nginx, Varnish, W3 Total Cache, Amazon S3, and Memcached (With Benchmarks)](http://danielmiessler.com/blog/optimizing-wordpress-with-nginx-varnish-w3-total-cache-amazon-s3-and-memcached), Daniel Miessler
281
+ * [My WordPress site loads in 2 seconds... does yours?](http://labsecrets.com/blog/2011/02/14/my-wordpress-site-loads-in-two-seconds-does-yours/)
282
 
283
  **January 2011:**
284
 
290
  **December 2010:**
291
 
292
  * [Best blog plugins](http://www.blog.web6.org/best-blog-plugins/)
293
+ * [How To Make Your WordPress Blog Load Faster](http://www.johnchow.com/how-to-make-your-wordpress-blog-load-faster/), John Chow
294
  * [Unleash the Power of WordPress Using Plugin Combos](http://freelancefolder.com/unleash-the-power-of-wordpress-using-plugin-combos/), Paul de Wouters
295
  * [Rackspace Cloud Files for WordPress](http://sporkmarketing.com/blog/1095/rackspace-cloud-files-wordpress/), Jason Lancaster
296
 
297
  **November 2010:**
298
 
299
  * [Make your blog super fast with W3 Total Cache plugin](http://laspas.gr/2010/11/26/make-blog-super-fast-w3-total-cache-plugin/), Stratos Laspas
300
+ * [10 WordPress Plugins I'm Thankful For (And Cannot Live Without)](http://wpmu.org/10-wordpress-plugins-im-thankful-for-and-cannot-live-without/), Sarah Gooding
301
  * [Subjective Results of Installing W3 Total Cache Plugin](http://www.codyhatch.com/administriva/subjective-results-of-installing-w3-total-cache-plugin/), Cody Hatch
302
  * [13 Plugins Your WordPress Site Might Need](http://www.jonbishop.com/2010/11/13-plugins-your-wordpress-site-might-need/), Jon Bishop
303
  * [Best WordPress Plugins that Marketers Use](http://www.nicoleonthenet.com/6390/best-wordpress-plugins-marketers-use/), Nicole Dean
447
 
448
  == Changelog ==
449
 
450
+ = 0.9.2.3 =
451
+ * Added additional CloudFlare IP range
452
+ * Fixed bug in html tidy encoding
453
+ * Fixed bug with NetDNA / MaxCDN purging
454
+ * Improved handling of markers in .htaccess files - easier upgrades
455
+ * Improved cache busting logic
456
+ * Improved numerous notifications and user interface behaviors
457
+ * Improved AWS S3 and Cloudfront reliability
458
+ * Improved reliability of minify auto mode
459
+
460
  = 0.9.2.2 =
461
  * Fixed bug with minify directives, e.g.: "File param is missing," causing minify caching to fail
462
  * Fixed bug with document root detection for IIS server
w3-total-cache.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: W3 Total Cache
4
  Description: The highest rated and most complete WordPress performance plugin. Dramatically improve the speed and user experience of your site. Add browser, page, object and database caching as well as minify and content delivery network (CDN) to WordPress.
5
- Version: 0.9.2.2
6
  Plugin URI: http://www.w3-edge.com/wordpress-plugins/w3-total-cache/
7
  Author: Frederick Townes
8
  Author URI: http://www.linkedin.com/in/w3edge
2
  /*
3
  Plugin Name: W3 Total Cache
4
  Description: The highest rated and most complete WordPress performance plugin. Dramatically improve the speed and user experience of your site. Add browser, page, object and database caching as well as minify and content delivery network (CDN) to WordPress.
5
+ Version: 0.9.2.3
6
  Plugin URI: http://www.w3-edge.com/wordpress-plugins/w3-total-cache/
7
  Author: Frederick Townes
8
  Author URI: http://www.linkedin.com/in/w3edge
wp-content/db.php CHANGED
@@ -8,7 +8,6 @@ if (!defined('W3TC_DIR')) {
8
  }
9
 
10
  if (!@is_dir(W3TC_DIR) || !file_exists(W3TC_DIR . '/inc/define.php')) {
11
-
12
  if (!defined('WP_ADMIN')) { // lets don't show error on front end
13
  require_once (ABSPATH . WPINC . '/wp-db.php');
14
  } else {
@@ -16,10 +15,13 @@ if (!@is_dir(W3TC_DIR) || !file_exists(W3TC_DIR . '/inc/define.php')) {
16
  die(sprintf('<strong>W3 Total Cache Error:</strong> some files appear to be missing or out of place. Please re-install plugin or remove <strong>%s</strong>.', __FILE__));
17
  }
18
  } else {
19
-
20
  require_once W3TC_DIR . '/inc/define.php';
 
 
 
 
 
21
  require_once W3TC_LIB_W3_DIR . '/Db.php';
22
 
23
  $GLOBALS['wpdb'] = & W3_Db::instance();
24
  }
25
-
8
  }
9
 
10
  if (!@is_dir(W3TC_DIR) || !file_exists(W3TC_DIR . '/inc/define.php')) {
 
11
  if (!defined('WP_ADMIN')) { // lets don't show error on front end
12
  require_once (ABSPATH . WPINC . '/wp-db.php');
13
  } else {
15
  die(sprintf('<strong>W3 Total Cache Error:</strong> some files appear to be missing or out of place. Please re-install plugin or remove <strong>%s</strong>.', __FILE__));
16
  }
17
  } else {
 
18
  require_once W3TC_DIR . '/inc/define.php';
19
+
20
+ if (defined('DB_TYPE') && file_exists(W3TC_DB_DIR . DIRECTORY_SEPARATOR . DB_TYPE . '.php')) {
21
+ require_once W3TC_DB_DIR . DIRECTORY_SEPARATOR . DB_TYPE . '.php';
22
+ }
23
+
24
  require_once W3TC_LIB_W3_DIR . '/Db.php';
25
 
26
  $GLOBALS['wpdb'] = & W3_Db::instance();
27
  }