W3 Total Cache - Version 0.7.5.1

Version Description

  • Resolved a bug in the minify library preventing proper permission notification messages
  • Improved notification handling
  • Fixed bug with database cache that caused comment counts to become out of date
  • Added memcached test button for convenience
  • Fixed minor issue with URI with CDN functionality enabled
  • Removed unnecessary minify options
  • Improved reliability of Media Library Export
  • Minification error now dialogs disabled when JS or CSS minify settings disabled
  • Normalized line endings with /n as per minify author's direction
  • Added option to concatenate any script to header or footer with non-blocking options for scripts that cannot be minified (e.g. obfuscated scripts)
  • Improved compatibility with suPHP
  • Added options to concatenate JS files only in header or footer (for use with obfuscated scripts)
Download this release

Release Info

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

Code changes from version 0.7.5 to 0.7.5.1

inc/css/options.css CHANGED
@@ -25,7 +25,7 @@
25
  .w3tc-error {
26
  background:#f99
27
  }
28
- .w3tc-cdn-status {
29
  padding:5px
30
  }
31
  #w3tc acronym {
25
  .w3tc-error {
26
  background:#f99
27
  }
28
+ .w3tc-status {
29
  padding:5px
30
  }
31
  #w3tc acronym {
inc/define.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- define('W3TC_VERSION', '0.7.5');
4
  define('W3TC_POWERED_BY', 'W3 Total Cache/' . W3TC_VERSION);
5
  define('W3TC_LINK_URL', 'http://www.w3-edge.com/wordpress-plugins/');
6
  define('W3TC_LINK_NAME', 'WordPress Plugins');
@@ -72,45 +72,43 @@ function w3_is_url($url)
72
  return preg_match('~^https?://~', $url);
73
  }
74
 
75
- if (! function_exists('gzdecode')) {
76
- /**
77
- * Decodes gzip-encoded string
78
- *
79
- * @param string $data
80
- * @return string
81
- */
82
- function gzdecode($data)
83
- {
84
- $flags = ord(substr($data, 3, 1));
85
- $headerlen = 10;
86
- $extralen = 0;
87
-
88
- if ($flags & 4) {
89
- $extralen = unpack('v', substr($data, 10, 2));
90
- $extralen = $extralen[1];
91
- $headerlen += 2 + $extralen;
92
- }
93
-
94
- if ($flags & 8) {
95
- $headerlen = strpos($data, chr(0), $headerlen) + 1;
96
- }
97
-
98
- if ($flags & 16) {
99
- $headerlen = strpos($data, chr(0), $headerlen) + 1;
100
- }
101
-
102
- if ($flags & 2) {
103
- $headerlen += 2;
104
- }
105
-
106
- $unpacked = gzinflate(substr($data, $headerlen));
107
-
108
- if ($unpacked === FALSE) {
109
- $unpacked = $data;
110
- }
111
-
112
- return $unpacked;
113
  }
 
 
 
 
 
 
 
 
 
 
 
 
114
  }
115
 
116
  /**
@@ -120,7 +118,7 @@ if (! function_exists('gzdecode')) {
120
  * @param integer $mask
121
  * @return boolean
122
  */
123
- function w3_mkdir($path, $mask = 0777)
124
  {
125
  $dirs = preg_split('~[\\/]+~', $path);
126
  $curr_path = '';
@@ -265,3 +263,45 @@ function w3_get_site_url()
265
 
266
  return $site_url;
267
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
 
3
+ define('W3TC_VERSION', '0.7.5.1');
4
  define('W3TC_POWERED_BY', 'W3 Total Cache/' . W3TC_VERSION);
5
  define('W3TC_LINK_URL', 'http://www.w3-edge.com/wordpress-plugins/');
6
  define('W3TC_LINK_NAME', 'WordPress Plugins');
72
  return preg_match('~^https?://~', $url);
73
  }
74
 
75
+ /**
76
+ * Decodes gzip-encoded string
77
+ *
78
+ * @param string $data
79
+ * @return string
80
+ */
81
+ function w3_gzdecode($data)
82
+ {
83
+ $flags = ord(substr($data, 3, 1));
84
+ $headerlen = 10;
85
+ $extralen = 0;
86
+
87
+ if ($flags & 4) {
88
+ $extralen = unpack('v', substr($data, 10, 2));
89
+ $extralen = $extralen[1];
90
+ $headerlen += 2 + $extralen;
91
+ }
92
+
93
+ if ($flags & 8) {
94
+ $headerlen = strpos($data, chr(0), $headerlen) + 1;
95
+ }
96
+
97
+ if ($flags & 16) {
98
+ $headerlen = strpos($data, chr(0), $headerlen) + 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  }
100
+
101
+ if ($flags & 2) {
102
+ $headerlen += 2;
103
+ }
104
+
105
+ $unpacked = gzinflate(substr($data, $headerlen));
106
+
107
+ if ($unpacked === FALSE) {
108
+ $unpacked = $data;
109
+ }
110
+
111
+ return $unpacked;
112
  }
113
 
114
  /**
118
  * @param integer $mask
119
  * @return boolean
120
  */
121
+ function w3_mkdir($path, $mask = 0755)
122
  {
123
  $dirs = preg_split('~[\\/]+~', $path);
124
  $curr_path = '';
263
 
264
  return $site_url;
265
  }
266
+
267
+ /**
268
+ * Returns upload info
269
+ *
270
+ * @return array
271
+ */
272
+ function w3_upload_info()
273
+ {
274
+ static $upload_info = null;
275
+
276
+ if ($upload_info === null) {
277
+ $upload_info = @wp_upload_dir();
278
+
279
+ if (! empty($upload_info['error'])) {
280
+ $upload_info = false;
281
+ }
282
+ }
283
+
284
+ return $upload_info;
285
+ }
286
+
287
+ /**
288
+ * Redirects to URL
289
+ *
290
+ * @param string $url
291
+ * @param string $params
292
+ */
293
+ function w3_redirect($url = '', $params = '')
294
+ {
295
+ $url = (! empty($url) ? $url : $_SERVER['HTTP_REFERER']);
296
+ if (empty($url)) {
297
+ $url = $_SERVER['REQUEST_URI'];
298
+ }
299
+
300
+ if (! empty($params)) {
301
+ $params = (strpos($url, '?') === false ? '?' : '&') . $params;
302
+ $url .= $params;
303
+ }
304
+
305
+ header('Location: ' . $url);
306
+ exit();
307
+ }
inc/js/options.js CHANGED
@@ -159,25 +159,49 @@ jQuery(function($) {
159
  });
160
 
161
  $('#minify_form').submit(function() {
162
- var invalid_js = [], invalid_css = [];
 
163
  $('#js_files :text').each(function() {
164
  var v = $(this).val();
165
- if (v != '' && ! /\.js$/.test(v)) {
166
- invalid_js.push(v);
 
 
 
 
 
 
 
 
 
167
  }
168
  });
169
  $('#css_files :text').each(function() {
170
  var v = $(this).val();
171
- if (v != '' && ! /\.css$/.test(v)) {
172
- invalid_css.push(v);
 
 
 
 
 
 
 
 
 
173
  }
174
  });
175
 
176
- if (invalid_js.length && ! confirm('These files have invalid JS file extension:\r\n\r\n' + invalid_js.join('\r\n') + '\r\n\r\nAre you confident this files contain valid JS code?')) {
177
  return false;
178
  }
179
 
180
- if (invalid_css.length && ! confirm('These files have invalid CSS file extension:\r\n\r\n' + invalid_css.join('\r\n') + '\r\n\r\nAre you confident this files contain valid CSS code?')) {
 
 
 
 
 
181
  return false;
182
  }
183
 
@@ -223,4 +247,19 @@ jQuery(function($) {
223
  status.html(data.error);
224
  }, 'json');
225
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  });
159
  });
160
 
161
  $('#minify_form').submit(function() {
162
+ var js = [], css = [], invalid_js = [], invalid_css = [], duplicate = false;
163
+
164
  $('#js_files :text').each(function() {
165
  var v = $(this).val();
166
+ if (v != '') {
167
+ for (var i = 0; i < js.length; i++) {
168
+ if (js[i] == v) {
169
+ duplicate = true;
170
+ break;
171
+ }
172
+ }
173
+ js[js.length] = v;
174
+ if (! /\.js$/.test(v)) {
175
+ invalid_js.push(v);
176
+ }
177
  }
178
  });
179
  $('#css_files :text').each(function() {
180
  var v = $(this).val();
181
+ if (v != '') {
182
+ for (var i = 0; i < css.length; i++) {
183
+ if (css[i] == v) {
184
+ duplicate = true;
185
+ break;
186
+ }
187
+ }
188
+ css[css.length] = v;
189
+ if (! /\.css$/.test(v)) {
190
+ invalid_css.push(v);
191
+ }
192
  }
193
  });
194
 
195
+ if ($('#js_enabled:checked').size() && invalid_js.length && ! confirm('These files have invalid JS file extension:\r\n\r\n' + invalid_js.join('\r\n') + '\r\n\r\nAre you confident this files contain valid JS code?')) {
196
  return false;
197
  }
198
 
199
+ if ($('#css_enabled:checked').size() && invalid_css.length && ! confirm('These files have invalid CSS file extension:\r\n\r\n' + invalid_css.join('\r\n') + '\r\n\r\nAre you confident this files contain valid CSS code?')) {
200
+ return false;
201
+ }
202
+
203
+ if (duplicate) {
204
+ alert('Duplicate files have been found in your minify settings, please check your settings again.');
205
  return false;
206
  }
207
 
247
  status.html(data.error);
248
  }, 'json');
249
  });
250
+
251
+ $('#test_memcached').click(function() {
252
+ var status = $('#test_memcached_status');
253
+ status.removeClass('w3tc-error');
254
+ status.addClass('w3tc-process');
255
+ status.html('Testing...');
256
+ $.post('options-general.php', {
257
+ page: 'w3-total-cache/w3-total-cache.php',
258
+ w3tc_action: 'test_memcached',
259
+ servers: $('#memcached_servers').val()
260
+ }, function(data) {
261
+ status.addClass(data.result ? 'w3tc-success' : 'w3tc-error');
262
+ status.html(data.error);
263
+ }, 'json');
264
+ });
265
  });
inc/options/cdn.phtml CHANGED
@@ -51,7 +51,7 @@
51
  </tr>
52
  </table>
53
  <p>
54
- <input id="test_ftp" class="button" type="button" value="Test FTP server" /> <span id="test_ftp_status" class="w3tc-cdn-status w3tc-process"></span>
55
  </p>
56
  </div>
57
  <div id="cdn_cf" class="w3tc-tab-content" style="display: none;">
@@ -138,7 +138,7 @@
138
  <tr>
139
  <th colspan="2">
140
  <input type="hidden" name="cdn.import.external" value="0" />
141
- <label><input type="checkbox" name="cdn.import.external" value="1"<?php checked($config->get_boolean('cdn.import.external'), true); ?> /> Import external files</label>
142
  </th>
143
  </tr>
144
  <tr>
51
  </tr>
52
  </table>
53
  <p>
54
+ <input id="test_ftp" class="button" type="button" value="Test FTP server" /> <span id="test_ftp_status" class="w3tc-status w3tc-process"></span>
55
  </p>
56
  </div>
57
  <div id="cdn_cf" class="w3tc-tab-content" style="display: none;">
138
  <tr>
139
  <th colspan="2">
140
  <input type="hidden" name="cdn.import.external" value="0" />
141
+ <label><input type="checkbox" name="cdn.import.external" value="1"<?php checked($config->get_boolean('cdn.import.external'), true); ?> /> Import external media library attachments</label>
142
  </th>
143
  </tr>
144
  <tr>
inc/options/common/header.phtml CHANGED
@@ -3,22 +3,22 @@
3
 
4
  <h2>W3 Total Cache</h2>
5
 
 
 
 
 
 
 
 
 
6
  <?php if (count($errors)): ?>
7
- <div id="message" class="error">
8
  <?php foreach ($errors as $error): ?>
9
- <p><?php echo $error; ?></p>
 
 
10
  <?php endforeach; ?>
11
- </div>
12
  <?php endif; ?>
13
 
14
- <?php if (count($notes)): ?>
15
- <div id="message" class="updated fade">
16
- <?php foreach ($notes as $note): ?>
17
- <p><?php echo $note; ?></p>
18
- <?php endforeach; ?>
19
- </div>
20
- <?php endif; ?>
21
-
22
  <p id="w3tc-options-menu">
23
  <a href="?page=<?php echo W3TC_FILE; ?>&amp;tab=general"<?php if ($tab == 'general'): ?> class="w3tc-options-menu-selected"<?php endif; ?>>General Settings</a> |
24
  <a href="?page=<?php echo W3TC_FILE; ?>&amp;tab=pgcache"<?php if ($tab == 'pgcache'): ?> class="w3tc-options-menu-selected"<?php endif; ?>>Page Cache Settings</a> |
3
 
4
  <h2>W3 Total Cache</h2>
5
 
6
+ <?php if (count($notes)): ?>
7
+ <?php foreach ($notes as $note): ?>
8
+ <div id="message" class="updated fade">
9
+ <p><?php echo $note; ?></p>
10
+ </div>
11
+ <?php endforeach; ?>
12
+ <?php endif; ?>
13
+
14
  <?php if (count($errors)): ?>
 
15
  <?php foreach ($errors as $error): ?>
16
+ <div id="message" class="error">
17
+ <p><?php echo $error; ?></p>
18
+ </div>
19
  <?php endforeach; ?>
 
20
  <?php endif; ?>
21
 
 
 
 
 
 
 
 
 
22
  <p id="w3tc-options-menu">
23
  <a href="?page=<?php echo W3TC_FILE; ?>&amp;tab=general"<?php if ($tab == 'general'): ?> class="w3tc-options-menu-selected"<?php endif; ?>>General Settings</a> |
24
  <a href="?page=<?php echo W3TC_FILE; ?>&amp;tab=pgcache"<?php if ($tab == 'pgcache'): ?> class="w3tc-options-menu-selected"<?php endif; ?>>Page Cache Settings</a> |
inc/options/dbcache.phtml CHANGED
@@ -5,15 +5,15 @@
5
  <form action="options-general.php?page=<?php echo urldecode(W3TC_FILE); ?>&amp;tab=<?php echo $tab; ?>" method="post">
6
  <table class="form-table">
7
  <tr>
8
- <th style="width: 250px;"><label for="dbcache_memcached_servers">Memcached Hostname:Port / IP:Port:</label></th>
9
  <td>
10
- <input id="dbcache_memcached_servers" type="text" name="dbcache.memcached.servers" value="<?php echo htmlspecialchars(implode(',', $config->get_array('dbcache.memcached.servers'))); ?>" size="100"<?php if ($config->get_string('dbcache.engine', 'memcached') != 'memcached'): ?> disabled="disabled"<?php endif; ?> /><br />
11
  <span class="description">Multiple servers may be used and seperated by a comma; e.g. 192.168.1.100:11211, domain.com:22122</span>
12
  </td>
13
  </tr>
14
  <tr>
15
- <th><label for="dbcache_lifetime_default">Maximum lifetime of cache objects:</label></th>
16
- <td><input id="dbcache_lifetime_default" type="text" name="dbcache.lifetime.default" value="<?php echo $config->get_integer('dbcache.lifetime.default'); ?>" size="8" /> seconds</td>
17
  </tr>
18
  </table>
19
 
5
  <form action="options-general.php?page=<?php echo urldecode(W3TC_FILE); ?>&amp;tab=<?php echo $tab; ?>" method="post">
6
  <table class="form-table">
7
  <tr>
8
+ <th style="width: 250px;"><label for="memcached_servers">Memcached Hostname:Port / IP:Port:</label></th>
9
  <td>
10
+ <input id="memcached_servers" type="text" name="dbcache.memcached.servers" value="<?php echo htmlspecialchars(implode(',', $config->get_array('dbcache.memcached.servers'))); ?>" size="100"<?php if ($config->get_string('dbcache.engine', 'memcached') != 'memcached'): ?> disabled="disabled"<?php endif; ?> /> <input id="test_memcached" class="button" type="button" value="Test Memcached"<?php if ($config->get_string('dbcache.engine', 'memcached') != 'memcached'): ?> disabled="disabled"<?php endif; ?> /> <span id="test_memcached_status" class="w3tc-status w3tc-process"></span><br />
11
  <span class="description">Multiple servers may be used and seperated by a comma; e.g. 192.168.1.100:11211, domain.com:22122</span>
12
  </td>
13
  </tr>
14
  <tr>
15
+ <th><label for="dbcache_lifetime">Maximum lifetime of cache objects:</label></th>
16
+ <td><input id="dbcache_lifetime" type="text" name="dbcache.lifetime" value="<?php echo $config->get_integer('dbcache.lifetime'); ?>" size="8" /> seconds</td>
17
  </tr>
18
  </table>
19
 
inc/options/faq.phtml CHANGED
@@ -124,7 +124,7 @@
124
  <ul>
125
  <li>Reduced <a href="http://en.wikipedia.org/wiki/Customer_attrition" target="_blank">attrition</a></li>
126
  <li>Higher conversion rates for e-commerce / affiliate etc sites</li>
127
- <li>Increased time on site /more page views per visitor</li>
128
  </ul>
129
  <p><em>In fact, if wordpress.com (for example) applied some of the techniques used in this plugin, we imagine they'd realize ~10% performance improvement on the <acronym title="Cascading Style Sheet">CSS</acronym>, <acronym title="JavaScript">JS</acronym> and <acronym title="Hypertext Markup Language">HTML</acronym> (respectively) on the millions of blogs they host.</em></p>
130
  <p>As a practical matter, Akamai and JupiterResearch did a study on <a href="http://www.akamai.com/html/about/press/releases/2006/press_110606.html" target="_blank">acceptable wait time for retail web sites</a> to load back in late 2006 concluding that users may leave after 4 seconds of waiting. That was several years ago now, even before 3G was available for mobile devices, what do you think web users expect today? <a href="http://blogs.zdnet.com/BTL/?p=3925" target="_blank">According to Marissa Mayer</a> of Google, as she stated the same year as Akamai, improving the speed of sites/applications reduces the learning curve for applications and contributes to higher use. It's time to bring the performance major corporations enjoy to the blogosphere.</p>
124
  <ul>
125
  <li>Reduced <a href="http://en.wikipedia.org/wiki/Customer_attrition" target="_blank">attrition</a></li>
126
  <li>Higher conversion rates for e-commerce / affiliate etc sites</li>
127
+ <li>Increased time on site / more page views per visitor</li>
128
  </ul>
129
  <p><em>In fact, if wordpress.com (for example) applied some of the techniques used in this plugin, we imagine they'd realize ~10% performance improvement on the <acronym title="Cascading Style Sheet">CSS</acronym>, <acronym title="JavaScript">JS</acronym> and <acronym title="Hypertext Markup Language">HTML</acronym> (respectively) on the millions of blogs they host.</em></p>
130
  <p>As a practical matter, Akamai and JupiterResearch did a study on <a href="http://www.akamai.com/html/about/press/releases/2006/press_110606.html" target="_blank">acceptable wait time for retail web sites</a> to load back in late 2006 concluding that users may leave after 4 seconds of waiting. That was several years ago now, even before 3G was available for mobile devices, what do you think web users expect today? <a href="http://blogs.zdnet.com/BTL/?p=3925" target="_blank">According to Marissa Mayer</a> of Google, as she stated the same year as Akamai, improving the speed of sites/applications reduces the learning curve for applications and contributes to higher use. It's time to bring the performance major corporations enjoy to the blogosphere.</p>
inc/options/general.phtml CHANGED
@@ -2,11 +2,20 @@
2
 
3
  $enabled = ($config->get_boolean('dbcache.enabled') || $config->get_boolean('pgcache.enabled') || $config->get_boolean('minify.enabled') || $config->get_boolean('cdn.enabled'));
4
  $debug = ($config->get_boolean('dbcache.debug') || $config->get_boolean('pgcache.debug') || $config->get_boolean('minify.debug') || $config->get_boolean('cdn.debug'));
5
- $supportType = $config->get_string('common.support.type', 'footer');
6
 
7
- $canEmptyMemcache = ($config->get_string('dbcache.engine') == 'memcached' || $config->get_string('pgcache.engine') == 'memcached' || $config->get_string('minify.engine') == 'memcached');
8
- $canEmptyApc = ($config->get_string('dbcache.engine') == 'apc' || $config->get_string('pgcache.engine') == 'apc' || $config->get_string('minify.engine') == 'apc');
9
- $canEmptyDisk = ($config->get_string('minify.engine') == 'file');
 
 
 
 
 
 
 
 
 
10
 
11
  ?>
12
  <h3>General Settings</h3>
@@ -19,9 +28,9 @@ $canEmptyDisk = ($config->get_string('minify.engine') == 'file');
19
  <p>You can
20
  <input type="hidden" name="page" value="<?php echo W3TC_FILE; ?>" />
21
  <input class="button" type="submit" name="flush_all" value="empty all caches" /> at once or
22
- <input class="button" type="submit" name="flush_memcached" value="empty only the memcached cache"<?php if (! $canEmptyMemcache): ?> disabled="disabled"<?php endif; ?> /> or
23
- <input class="button" type="submit" name="flush_apc" value="empty only the APC cache"<?php if (! $canEmptyApc): ?> disabled="disabled"<?php endif; ?> /> or
24
- <input class="button" type="submit" name="flush_file" value="empty only the minify disk cache"<?php if (! $canEmptyDisk): ?> disabled="disabled"<?php endif; ?> />.
25
  </p>
26
  </form>
27
 
@@ -40,7 +49,7 @@ $canEmptyDisk = ($config->get_string('minify.engine') == 'file');
40
  <tr>
41
  <th valign="top">Page Caching Method:</th>
42
  <td>
43
- <label><input type="radio" name="pgcache.engine" value="memcached"<?php checked($config->get_string('pgcache.engine'), 'memcached'); ?> /> Memcached</label><br />
44
  <label><input type="radio" name="pgcache.engine" value="apc"<?php checked($config->get_string('pgcache.engine'), 'apc'); ?><?php if (! $check_apc): ?> disabled="disabled"<?php endif; ?> /> <acronym title="Alternative PHP Cache">APC</acronym></label><br />
45
  </td>
46
  </tr>
@@ -61,7 +70,7 @@ $canEmptyDisk = ($config->get_string('minify.engine') == 'file');
61
  <th valign="top">Minify Caching Method:</th>
62
  <td>
63
  <label><input type="radio" name="minify.engine" value="file"<?php checked($config->get_string('minify.engine'), 'file'); ?> /> Disk</label><br />
64
- <label><input type="radio" name="minify.engine" value="memcached"<?php checked($config->get_string('minify.engine'), 'memcached'); ?> /> Memcached</label><br />
65
  <label><input type="radio" name="minify.engine" value="apc"<?php checked($config->get_string('minify.engine'), 'apc'); ?><?php if (! $check_apc): ?> disabled="disabled"<?php endif; ?> /> <acronym title="Alternative PHP Cache">APC</acronym></label><br />
66
  </td>
67
  </tr>
@@ -81,7 +90,7 @@ $canEmptyDisk = ($config->get_string('minify.engine') == 'file');
81
  <tr>
82
  <th valign="top">Database Caching Method:</th>
83
  <td>
84
- <label><input type="radio" name="dbcache.engine" value="memcached"<?php checked($config->get_string('dbcache.engine'), 'memcached'); ?> /> Memcached</label><br />
85
  <label><input type="radio" name="dbcache.engine" value="apc"<?php checked($config->get_string('dbcache.engine'), 'apc'); ?><?php if (! $check_apc): ?> disabled="disabled"<?php endif; ?> /> <acronym title="Alternative PHP Cache">APC</acronym></label><br />
86
  </td>
87
  </tr>
@@ -123,7 +132,13 @@ $canEmptyDisk = ($config->get_string('minify.engine') == 'file');
123
  <h3>Support Us</h3>
124
 
125
  <p>If this plugin has saved you money, made your server more stable and/or improved user experience for the readers of your blog, support us with a link!</p>
126
- <p><input type="hidden" name="common.support" value="0" /><label><input type="checkbox" name="common.support"<?php checked($config->get_boolean('common.support'), true); ?> /> Yes, I'd love to support you guys, please add the link to my site's</label> <select name="common.support.type"><option value="blogroll"<?php selected($supportType, 'blogroll'); ?>>blogroll</option><option value="footer"<?php selected($supportType, 'footer'); ?>>footer</option></select>.</p>
 
 
 
 
 
 
127
  <p>If you want to place the link manually here is the code:</p>
128
  <p><textarea cols="100" rows="3">Performance Optimization &lt;a href=&quot;http://www.w3-edge.com/wordpress-plugins/&quot; rel=&quot;external&quot;&gt;WordPress Plugins&lt;/a&gt; by W3 EDGE</textarea></p>
129
 
2
 
3
  $enabled = ($config->get_boolean('dbcache.enabled') || $config->get_boolean('pgcache.enabled') || $config->get_boolean('minify.enabled') || $config->get_boolean('cdn.enabled'));
4
  $debug = ($config->get_boolean('dbcache.debug') || $config->get_boolean('pgcache.debug') || $config->get_boolean('minify.debug') || $config->get_boolean('cdn.debug'));
5
+ $support_type = $config->get_string('common.support.type', 'footer');
6
 
7
+ $can_empty_memcache = ($config->get_string('dbcache.engine') == 'memcached' || $config->get_string('pgcache.engine') == 'memcached' || $config->get_string('minify.engine') == 'memcached');
8
+ $can_empty_apc = ($config->get_string('dbcache.engine') == 'apc' || $config->get_string('pgcache.engine') == 'apc' || $config->get_string('minify.engine') == 'apc');
9
+ $can_empty_disk = ($config->get_string('minify.engine') == 'file');
10
+
11
+ $memcache_engine = class_exists('Memcache') ? '(Memcache)' : '';
12
+
13
+ $support_types = array('footer' => 'Page footer');
14
+ $link_categories = get_terms('link_category', array('hide_empty' => 0));
15
+
16
+ foreach ($link_categories as $link_category) {
17
+ $support_types['link_category_' . $link_category->term_id] = $link_category->name;
18
+ }
19
 
20
  ?>
21
  <h3>General Settings</h3>
28
  <p>You can
29
  <input type="hidden" name="page" value="<?php echo W3TC_FILE; ?>" />
30
  <input class="button" type="submit" name="flush_all" value="empty all caches" /> at once or
31
+ <input class="button" type="submit" name="flush_memcached" value="empty only the memcached cache"<?php if (! $can_empty_memcache): ?> disabled="disabled"<?php endif; ?> /> or
32
+ <input class="button" type="submit" name="flush_apc" value="empty only the APC cache"<?php if (! $can_empty_apc): ?> disabled="disabled"<?php endif; ?> /> or
33
+ <input class="button" type="submit" name="flush_file" value="empty only the minify disk cache"<?php if (! $can_empty_disk): ?> disabled="disabled"<?php endif; ?> />.
34
  </p>
35
  </form>
36
 
49
  <tr>
50
  <th valign="top">Page Caching Method:</th>
51
  <td>
52
+ <label><input type="radio" name="pgcache.engine" value="memcached"<?php checked($config->get_string('pgcache.engine'), 'memcached'); ?> /> Memcached <?php echo $memcache_engine; ?></label><br />
53
  <label><input type="radio" name="pgcache.engine" value="apc"<?php checked($config->get_string('pgcache.engine'), 'apc'); ?><?php if (! $check_apc): ?> disabled="disabled"<?php endif; ?> /> <acronym title="Alternative PHP Cache">APC</acronym></label><br />
54
  </td>
55
  </tr>
70
  <th valign="top">Minify Caching Method:</th>
71
  <td>
72
  <label><input type="radio" name="minify.engine" value="file"<?php checked($config->get_string('minify.engine'), 'file'); ?> /> Disk</label><br />
73
+ <label><input type="radio" name="minify.engine" value="memcached"<?php checked($config->get_string('minify.engine'), 'memcached'); ?> /> Memcached <?php echo $memcache_engine; ?></label><br />
74
  <label><input type="radio" name="minify.engine" value="apc"<?php checked($config->get_string('minify.engine'), 'apc'); ?><?php if (! $check_apc): ?> disabled="disabled"<?php endif; ?> /> <acronym title="Alternative PHP Cache">APC</acronym></label><br />
75
  </td>
76
  </tr>
90
  <tr>
91
  <th valign="top">Database Caching Method:</th>
92
  <td>
93
+ <label><input type="radio" name="dbcache.engine" value="memcached"<?php checked($config->get_string('dbcache.engine'), 'memcached'); ?> /> Memcached <?php echo $memcache_engine; ?></label><br />
94
  <label><input type="radio" name="dbcache.engine" value="apc"<?php checked($config->get_string('dbcache.engine'), 'apc'); ?><?php if (! $check_apc): ?> disabled="disabled"<?php endif; ?> /> <acronym title="Alternative PHP Cache">APC</acronym></label><br />
95
  </td>
96
  </tr>
132
  <h3>Support Us</h3>
133
 
134
  <p>If this plugin has saved you money, made your server more stable and/or improved user experience for the readers of your blog, support us with a link!</p>
135
+ <p><input type="hidden" name="common.support.enabled" value="0" /><label><input type="checkbox" name="common.support.enabled"<?php checked($config->get_boolean('common.support.enabled'), true); ?> /> Yes, I'd love to support you guys, please add the link to my site's</label>
136
+ <select name="common.support.type">
137
+ <?php foreach ($support_types as $support_type_id => $support_type_name): ?>
138
+ <option value="<?php echo $support_type_id; ?>"<?php selected($support_type, $support_type_id); ?>><?php echo htmlspecialchars($support_type_name); ?></option>
139
+ <?php endforeach; ?>
140
+ </select>.
141
+ </p>
142
  <p>If you want to place the link manually here is the code:</p>
143
  <p><textarea cols="100" rows="3">Performance Optimization &lt;a href=&quot;http://www.w3-edge.com/wordpress-plugins/&quot; rel=&quot;external&quot;&gt;WordPress Plugins&lt;/a&gt; by W3 EDGE</textarea></p>
144
 
inc/options/install.phtml CHANGED
@@ -19,20 +19,20 @@
19
  <em>Time required: ~1 minute</em></p>
20
  <ol>
21
  <li><a href="http://www.google.com/search?q=installing%20yum&amp;output=search&amp;tbs=qdr:y&amp;tbo=1" target="_blank">Install yum</a> for your operating system if you don't already have it. If you like, you can update all of your installed software, but do so only if you have the experience and time to double check configurations afterwards:<br />
22
- # yum -y update</li>
23
  <li>Install <acronym title="PHP Extension Community Library">PECL</acronym>:<br />
24
- # yum -y install php-pear</li>
25
  <li>Install the <acronym title="Hypertext Preprocessor">PHP</acronym> Development package:<br />
26
- # yum -y install php-devel</li>
27
  <li>Install apxs with the following command:<br />
28
- # yum -y install httpd-devel</li>
29
  </ol>
30
  <hr />
31
  <p id="memcached"><strong>Memcached (Daemon) Installation:</strong><br />
32
- <em>Time required: 3 minutes</em></p>
33
  <ol>
34
  <li>Try to install with yum:<br />
35
- # yum -y install libevent<br />
36
  <br />
37
  If this succeeds skip to #5. If this fails, then let's compile. Download and extract the <a href="http://www.monkey.org/~provos/libevent/" target="_blank">latest stable version</a>:<br />
38
  # cd /usr/local/src<br />
@@ -102,7 +102,7 @@
102
  # pecl install apc<br />
103
  <br />
104
  or using yum:<br />
105
- # yum -y install php-pecl-apc</li>
106
  <li>Make sure the module is loaded:<br />
107
  # echo "extension=apc.so" &gt; /etc/php.d/apc.ini<br />
108
  <br />
@@ -144,10 +144,10 @@
144
  <hr />
145
  <p><strong>Note(s):</strong></p>
146
  <ul>
147
- <li>These server instructions are for CentOS, however we can provide others based on <a href="mailto:wordpressexperts@w3-edge.com">your requests</a>.</li>
148
- <li>In the case where the "Rewrite <acronym>URL</acronym> Structure" (in <a href="/wp-admin/options-general.php?page=w3-total-cache/w3-total-cache.php&amp;tab=minify">Minify Settings</a> tab) is desired, and apache is not used, the file located in wp-content/plugins/w3-total-cache/wp-content/w3tc-cache/.htaccess contains directives that must be created for the directory: wp-content/uploads/w3tc-cache/.</li>
149
  <li>Restarting the web server will empty your <acronym title="Alternative PHP Cache">APC</acronym> cache, which means it will have to be rebuilt over time and your site's performance will suffer during this period. Still, <acronym title="Alternative PHP Cache">APC</acronym> should be installed in any case to maximize WordPress performance.</li>
150
  <li>Consider using memcached for objects that must persist across web server restarts or that you wish to share amongst your pool of servers (or cluster), e.g.: database objects or page cache.</li>
151
- <li>Some yum or <acronym title="PHP Extension Community Library">PECL</acronym> mirrors may not have your the necessary packages, in such cases you may have to do a manual installation.</li>
152
  </ul>
153
  </div>
19
  <em>Time required: ~1 minute</em></p>
20
  <ol>
21
  <li><a href="http://www.google.com/search?q=installing%20yum&amp;output=search&amp;tbs=qdr:y&amp;tbo=1" target="_blank">Install yum</a> for your operating system if you don't already have it. If you like, you can update all of your installed software, but do so only if you have the experience and time to double check configurations afterwards:<br />
22
+ # yum update</li>
23
  <li>Install <acronym title="PHP Extension Community Library">PECL</acronym>:<br />
24
+ # yum install php-pear</li>
25
  <li>Install the <acronym title="Hypertext Preprocessor">PHP</acronym> Development package:<br />
26
+ # yum install php-devel</li>
27
  <li>Install apxs with the following command:<br />
28
+ # yum install httpd-devel</li>
29
  </ol>
30
  <hr />
31
  <p id="memcached"><strong>Memcached (Daemon) Installation:</strong><br />
32
+ <em>Time required: 2 minutes</em></p>
33
  <ol>
34
  <li>Try to install with yum:<br />
35
+ # yum install libevent<br />
36
  <br />
37
  If this succeeds skip to #5. If this fails, then let's compile. Download and extract the <a href="http://www.monkey.org/~provos/libevent/" target="_blank">latest stable version</a>:<br />
38
  # cd /usr/local/src<br />
102
  # pecl install apc<br />
103
  <br />
104
  or using yum:<br />
105
+ # yum install php-pecl-apc</li>
106
  <li>Make sure the module is loaded:<br />
107
  # echo "extension=apc.so" &gt; /etc/php.d/apc.ini<br />
108
  <br />
144
  <hr />
145
  <p><strong>Note(s):</strong></p>
146
  <ul>
147
+ <li>The provided instructions are for CentOS, however we can provide others based on <a href="mailto:wordpressexperts@w3-edge.com">your requests</a>.</li>
148
+ <li>In the case where the "Rewrite <acronym>URL</acronym> Structure" (in <a href="/wp-admin/options-general.php?page=w3-total-cache/w3-total-cache.php&amp;tab=minify">Minify Settings</a> tab) is desired, and apache is not used, the file located in wp-content/plugins/w3-total-cache/wp-content/w3tc-cache/.htaccess contains directives that must be created for the directory: wp-content/w3tc-cache/.</li>
149
  <li>Restarting the web server will empty your <acronym title="Alternative PHP Cache">APC</acronym> cache, which means it will have to be rebuilt over time and your site's performance will suffer during this period. Still, <acronym title="Alternative PHP Cache">APC</acronym> should be installed in any case to maximize WordPress performance.</li>
150
  <li>Consider using memcached for objects that must persist across web server restarts or that you wish to share amongst your pool of servers (or cluster), e.g.: database objects or page cache.</li>
151
+ <li>Some yum or mirrors may not have the necessary packages, in such cases you may have to do a manual installation.</li>
152
  </ul>
153
  </div>
inc/options/minify.phtml CHANGED
@@ -32,16 +32,16 @@ foreach ($js_check_groups as $js_check_group) {
32
  <form id="minify_form" action="options-general.php?page=<?php echo urldecode(W3TC_FILE); ?>&amp;tab=<?php echo $tab; ?>" method="post">
33
  <table class="form-table">
34
  <tr>
35
- <th style="width: 250px;"><label for="minify_memcached_servers">Memcached Hostname:Port / IP:Port:</label></th>
36
  <td>
37
- <input id="minify_memcached_servers" type="text" name="minify.memcached.servers" value="<?php echo htmlspecialchars(implode(',', $config->get_array('minify.memcached.servers'))); ?>" size="100"<?php if ($config->get_string('minify.engine', 'memcached') != 'memcached'): ?> disabled="disabled"<?php endif; ?> /><br />
38
- <span class="description">Multiple servers may be used and seperated by a comma; e.g. 192.168.1.100:11211, domain.com:22122</span>
39
  </td>
40
  </tr>
41
  <tr>
42
  <th colspan="2">
43
  <input type="hidden" name="minify.compress" value="0" />
44
- <label><input type="checkbox" name="minify.compress" value="1"<?php checked($config->get_boolean('minify.compress'), true); ?> /> <acronym title="Hypertext Transfer Protocol">HTTP</acronym> compression (<acronym title="GNU zip">gzip</acronym> / deflate)</label><br />
45
  <span class="description">Reduce file size by utomatically detecting the user agent's supported compression method of any.</span>
46
  </th>
47
  </tr>
@@ -79,11 +79,13 @@ foreach ($js_check_groups as $js_check_group) {
79
  <th valign="top"><acronym title="JavaScript">JS</acronym> Minify Settings:</th>
80
  <td>
81
  <input type="hidden" name="minify.js.enable" value="0" />
82
- <input type="hidden" name="minify.js.clean" value="0" />
 
83
  <input type="hidden" name="minify.js.strip.comments" value="0" />
84
  <input type="hidden" name="minify.js.strip.crlf" value="0" />
85
  <label><input id="js_enabled" type="checkbox" name="minify.js.enable" value="1"<?php checked($config->get_boolean('minify.js.enable'), true); ?> /> Minify</label><br />
86
- <label><input class="js_enabled" type="checkbox" name="minify.js.clean" value="1"<?php checked($config->get_boolean('minify.js.clean'), true); ?> /> Clean <acronym title="JavaScript">JS</acronym></label><br />
 
87
  <label><input class="js_enabled" type="checkbox" name="minify.js.strip.comments" value="1"<?php checked($config->get_boolean('minify.js.strip.comments'), true); ?> /> Comment removal</label><br />
88
  <label><input class="js_enabled" type="checkbox" name="minify.js.strip.crlf" value="1"<?php checked($config->get_boolean('minify.js.strip.crlf'), true); ?> /> Line break removal</label><br />
89
  </td>
@@ -92,11 +94,9 @@ foreach ($js_check_groups as $js_check_group) {
92
  <th valign="top"><acronym title="Cascading Style Sheets">CSS</acronym> Minify Settings:</th>
93
  <td>
94
  <input type="hidden" name="minify.css.enable" value="0" />
95
- <input type="hidden" name="minify.css.clean" value="0" />
96
  <input type="hidden" name="minify.css.strip.comments" value="0" />
97
  <input type="hidden" name="minify.css.strip.crlf" value="0" />
98
  <label><input id="css_enabled" type="checkbox" name="minify.css.enable" value="1"<?php checked($config->get_boolean('minify.css.enable'), true); ?> /> Minify</label><br />
99
- <label><input class="css_enabled" type="checkbox" name="minify.css.clean" value="1"<?php checked($config->get_boolean('minify.css.clean'), true); ?> /> Clean <acronym title="Cascading Style Sheets">CSS</acronym></label><br />
100
  <label><input class="css_enabled" type="checkbox" name="minify.css.strip.comments" value="1"<?php checked($config->get_boolean('minify.css.strip.comments'), true); ?> /> Comment removal</label><br />
101
  <label><input class="css_enabled" type="checkbox" name="minify.css.strip.crlf" value="1"<?php checked($config->get_boolean('minify.css.strip.crlf'), true); ?> /> Line break removal</label><br />
102
  </td>
32
  <form id="minify_form" action="options-general.php?page=<?php echo urldecode(W3TC_FILE); ?>&amp;tab=<?php echo $tab; ?>" method="post">
33
  <table class="form-table">
34
  <tr>
35
+ <th style="width: 250px;"><label for="memcached_servers">Memcached Hostname:Port / IP:Port:</label></th>
36
  <td>
37
+ <input id="memcached_servers" type="text" name="minify.memcached.servers" value="<?php echo htmlspecialchars(implode(',', $config->get_array('minify.memcached.servers'))); ?>" size="100"<?php if ($config->get_string('minify.engine', 'memcached') != 'memcached'): ?> disabled="disabled"<?php endif; ?> /> <input id="test_memcached" class="button" type="button" value="Test Memcached"<?php if ($config->get_string('minify.engine', 'memcached') != 'memcached'): ?> disabled="disabled"<?php endif; ?> /> <span id="test_memcached_status" class="w3tc-status w3tc-process"></span><br />
38
+ <span class="description">Multiple servers may be used and seperated by a comma; e.g. 192.168.1.100:11211, domain.com:22122</span>
39
  </td>
40
  </tr>
41
  <tr>
42
  <th colspan="2">
43
  <input type="hidden" name="minify.compress" value="0" />
44
+ <label><input type="checkbox" name="minify.compress" value="1"<?php checked($config->get_boolean('minify.compress'), true); ?> /> <acronym title="Hypertext Transfer Protocol">HTTP</acronym> compression (<acronym title="GNU zip">gzip</acronym> / deflate)</label><br />
45
  <span class="description">Reduce file size by utomatically detecting the user agent's supported compression method of any.</span>
46
  </th>
47
  </tr>
79
  <th valign="top"><acronym title="JavaScript">JS</acronym> Minify Settings:</th>
80
  <td>
81
  <input type="hidden" name="minify.js.enable" value="0" />
82
+ <input type="hidden" name="minify.js.combine.header" value="0" />
83
+ <input type="hidden" name="minify.js.combine.footer" value="0" />
84
  <input type="hidden" name="minify.js.strip.comments" value="0" />
85
  <input type="hidden" name="minify.js.strip.crlf" value="0" />
86
  <label><input id="js_enabled" type="checkbox" name="minify.js.enable" value="1"<?php checked($config->get_boolean('minify.js.enable'), true); ?> /> Minify</label><br />
87
+ <label><input class="js_enabled" type="checkbox" name="minify.js.combine.header" value="1"<?php checked($config->get_boolean('minify.js.combine.header'), true); ?> /> Only combine (Head)</label><br />
88
+ <label><input class="js_enabled" type="checkbox" name="minify.js.combine.footer" value="1"<?php checked($config->get_boolean('minify.js.combine.footer'), true); ?> /> Only combine (Footer)</label><br />
89
  <label><input class="js_enabled" type="checkbox" name="minify.js.strip.comments" value="1"<?php checked($config->get_boolean('minify.js.strip.comments'), true); ?> /> Comment removal</label><br />
90
  <label><input class="js_enabled" type="checkbox" name="minify.js.strip.crlf" value="1"<?php checked($config->get_boolean('minify.js.strip.crlf'), true); ?> /> Line break removal</label><br />
91
  </td>
94
  <th valign="top"><acronym title="Cascading Style Sheets">CSS</acronym> Minify Settings:</th>
95
  <td>
96
  <input type="hidden" name="minify.css.enable" value="0" />
 
97
  <input type="hidden" name="minify.css.strip.comments" value="0" />
98
  <input type="hidden" name="minify.css.strip.crlf" value="0" />
99
  <label><input id="css_enabled" type="checkbox" name="minify.css.enable" value="1"<?php checked($config->get_boolean('minify.css.enable'), true); ?> /> Minify</label><br />
 
100
  <label><input class="css_enabled" type="checkbox" name="minify.css.strip.comments" value="1"<?php checked($config->get_boolean('minify.css.strip.comments'), true); ?> /> Comment removal</label><br />
101
  <label><input class="css_enabled" type="checkbox" name="minify.css.strip.crlf" value="1"<?php checked($config->get_boolean('minify.css.strip.crlf'), true); ?> /> Line break removal</label><br />
102
  </td>
inc/options/pgcache.phtml CHANGED
@@ -5,10 +5,10 @@
5
  <form action="options-general.php?page=<?php echo urldecode(W3TC_FILE); ?>&amp;tab=<?php echo $tab; ?>" method="post">
6
  <table class="form-table">
7
  <tr>
8
- <th style="width: 250px;"><label for="pgcache_memcached_servers">Memcached Hostname:Port / IP:Port:</label></th>
9
  <td>
10
- <input id="pgcache_memcached_servers" type="text" name="pgcache.memcached.servers" value="<?php echo htmlspecialchars(implode(',', $config->get_array('pgcache.memcached.servers'))); ?>" size="100"<?php if ($config->get_string('pgcache.engine', 'memcached') != 'memcached'): ?> disabled="disabled"<?php endif; ?> />
11
- <br /><span class="description">Multiple servers may be used and seperated by a comma; e.g. 192.168.1.100:11211, domain.com:22122</span>
12
  </td>
13
  </tr>
14
  <tr>
5
  <form action="options-general.php?page=<?php echo urldecode(W3TC_FILE); ?>&amp;tab=<?php echo $tab; ?>" method="post">
6
  <table class="form-table">
7
  <tr>
8
+ <th style="width: 250px;"><label for="memcached_servers">Memcached Hostname:Port / IP:Port:</label></th>
9
  <td>
10
+ <input id="memcached_servers" type="text" name="pgcache.memcached.servers" value="<?php echo htmlspecialchars(implode(',', $config->get_array('pgcache.memcached.servers'))); ?>" size="100"<?php if ($config->get_string('pgcache.engine', 'memcached') != 'memcached'): ?> disabled="disabled"<?php endif; ?> /> <input id="test_memcached" class="button" type="button" value="Test Memcached"<?php if ($config->get_string('pgcache.engine', 'memcached') != 'memcached'): ?> disabled="disabled"<?php endif; ?> /> <span id="test_memcached_status" class="w3tc-status w3tc-process"></span><br />
11
+ <span class="description">Multiple servers may be used and seperated by a comma; e.g. 192.168.1.100:11211, domain.com:22122</span>
12
  </td>
13
  </tr>
14
  <tr>
lib/Minify/JSMin.php CHANGED
@@ -146,7 +146,7 @@ class JSMin {
146
  }
147
  if (ord($this->a) <= self::ORD_LF) {
148
  throw new JSMin_UnterminatedStringException(
149
- 'Unterminated String: ' . var_export($str, true));
150
  }
151
  $str .= $this->a;
152
  if ($this->a === '\\') {
@@ -173,7 +173,7 @@ class JSMin {
173
  $pattern .= $this->a;
174
  } elseif (ord($this->a) <= self::ORD_LF) {
175
  throw new JSMin_UnterminatedRegExpException(
176
- 'Unterminated RegExp: '. var_export($pattern, true));
177
  }
178
  $this->output .= $this->a;
179
  }
@@ -285,7 +285,7 @@ class JSMin {
285
  return ' ';
286
  }
287
  } elseif ($get === null) {
288
- throw new JSMin_UnterminatedCommentException('Unterminated Comment: ' . var_export('/*' . $comment, true));
289
  }
290
  $comment .= $get;
291
  }
146
  }
147
  if (ord($this->a) <= self::ORD_LF) {
148
  throw new JSMin_UnterminatedStringException(
149
+ 'Unterminated String: ' . $str);
150
  }
151
  $str .= $this->a;
152
  if ($this->a === '\\') {
173
  $pattern .= $this->a;
174
  } elseif (ord($this->a) <= self::ORD_LF) {
175
  throw new JSMin_UnterminatedRegExpException(
176
+ 'Unterminated RegExp: '. $pattern);
177
  }
178
  $this->output .= $this->a;
179
  }
285
  return ' ';
286
  }
287
  } elseif ($get === null) {
288
+ throw new JSMin_UnterminatedCommentException('Unterminated Comment: /*' . $comment);
289
  }
290
  $comment .= $get;
291
  }
lib/Minify/Minify/CSS/UriRewriter.php CHANGED
@@ -67,7 +67,7 @@ class Minify_CSS_UriRewriter {
67
  self::$debugText .= "docRoot : " . self::$_docRoot . "\n"
68
  . "currentDir : " . self::$_currentDir . "\n";
69
  if (self::$_symlinks) {
70
- self::$debugText .= "symlinks : " . var_export(self::$_symlinks, 1) . "\n";
71
  }
72
  self::$debugText .= "\n";
73
 
67
  self::$debugText .= "docRoot : " . self::$_docRoot . "\n"
68
  . "currentDir : " . self::$_currentDir . "\n";
69
  if (self::$_symlinks) {
70
+ self::$debugText .= "symlinks : " . implode(', ', self::$_symlinks) . "\n";
71
  }
72
  self::$debugText .= "\n";
73
 
lib/W3/Cache/Memcached/Client.php CHANGED
@@ -30,8 +30,8 @@ class W3_Cache_Memcached_Client extends W3_Cache_Memcached_Base
30
  }
31
 
32
  $this->_memcached = & new memcached_client(array(
33
- 'servers' => $this->config['servers'],
34
- 'persistant' => true,
35
  'debug' => false,
36
  'compress_threshold' => (! empty($this->config['compress_threshold']) ? (integer) $this->config['compress_threshold'] : 0)
37
  ));
30
  }
31
 
32
  $this->_memcached = & new memcached_client(array(
33
+ 'servers' => $this->config['servers'],
34
+ 'persistant' => isset($this->config['persistant']) ? (boolean) $this->config['persistant'] : false,
35
  'debug' => false,
36
  'compress_threshold' => (! empty($this->config['compress_threshold']) ? (integer) $this->config['compress_threshold'] : 0)
37
  ));
lib/W3/Cache/Memcached/Native.php CHANGED
@@ -45,9 +45,11 @@ class W3_Cache_Memcached_Native extends W3_Cache_Memcached_Base
45
  function connect()
46
  {
47
  if (! empty($this->config['servers'])) {
 
 
48
  foreach ((array) $this->config['servers'] as $server) {
49
  list ($ip, $port) = explode(':', $server);
50
- $this->_memcache->addServer($ip, $port, true);
51
  }
52
  } else {
53
  return false;
45
  function connect()
46
  {
47
  if (! empty($this->config['servers'])) {
48
+ $persistant = isset($this->config['persistant']) ? (boolean) $this->config['persistant'] : false;
49
+
50
  foreach ((array) $this->config['servers'] as $server) {
51
  list ($ip, $port) = explode(':', $server);
52
+ $this->_memcache->addServer($ip, $port, $persistant);
53
  }
54
  } else {
55
  return false;
lib/W3/Cdn/Ftp.php CHANGED
@@ -115,7 +115,7 @@ class W3_Cdn_Ftp extends W3_Cdn_Base
115
  continue;
116
  }
117
 
118
- @ftp_chmod($this->_ftp, 0777, $dir);
119
 
120
  if (! @ftp_chdir($this->_ftp, $dir)) {
121
  @ftp_close($this->_ftp);
@@ -137,7 +137,7 @@ class W3_Cdn_Ftp extends W3_Cdn_Base
137
 
138
  if ($result) {
139
  $count ++;
140
- @ftp_chmod($this->_ftp, 0777, $remote_file);
141
  }
142
  }
143
 
@@ -192,19 +192,30 @@ class W3_Cdn_Ftp extends W3_Cdn_Base
192
  */
193
  function test(&$error = null)
194
  {
195
- if (! $this->_connect($error)) {
196
- return false;
197
- }
198
-
199
  $rand = md5(time());
 
200
  $tmp_dir = 'test_dir_' . $rand;
201
  $tmp_file = 'test_file_' . $rand;
202
- $tmp_path = WP_CONTENT_DIR . '/' . $tmp_file;
 
 
 
 
 
 
 
 
 
 
 
 
203
 
204
  if (! @ftp_mkdir($this->_ftp, $tmp_dir)) {
205
  $this->_disconnect();
206
  $error = sprintf('Unable to make directory: %s', $tmp_dir);
207
  return false;
 
 
208
  }
209
 
210
  if (! @ftp_chdir($this->_ftp, $tmp_dir)) {
@@ -213,13 +224,6 @@ class W3_Cdn_Ftp extends W3_Cdn_Base
213
  return false;
214
  }
215
 
216
- @ftp_chmod($this->_ftp, 0777);
217
-
218
- if (($fp = @fopen($tmp_path, 'w'))) {
219
- @fputs($fp, $rand);
220
- @fclose($fp);
221
- }
222
-
223
  if (! @ftp_put($this->_ftp, $tmp_file, $tmp_path, FTP_BINARY)) {
224
  @ftp_cdup($this->_ftp);
225
  @ftp_rmdir($this->_ftp, $tmp_dir);
@@ -233,7 +237,6 @@ class W3_Cdn_Ftp extends W3_Cdn_Base
233
  @ftp_cdup($this->_ftp);
234
  @ftp_rmdir($this->_ftp, $tmp_dir);
235
  @unlink($tmp_path);
236
-
237
  $this->_disconnect();
238
 
239
  return true;
115
  continue;
116
  }
117
 
118
+ @ftp_chmod($this->_ftp, 0755, $dir);
119
 
120
  if (! @ftp_chdir($this->_ftp, $dir)) {
121
  @ftp_close($this->_ftp);
137
 
138
  if ($result) {
139
  $count ++;
140
+ @ftp_chmod($this->_ftp, 0644, $remote_file);
141
  }
142
  }
143
 
192
  */
193
  function test(&$error = null)
194
  {
 
 
 
 
195
  $rand = md5(time());
196
+ $upload_info = w3_upload_info();
197
  $tmp_dir = 'test_dir_' . $rand;
198
  $tmp_file = 'test_file_' . $rand;
199
+ $tmp_path = $upload_info['path'] . '/' . $tmp_file;
200
+
201
+ if (($fp = @fopen($tmp_path, 'w'))) {
202
+ @fputs($fp, $rand);
203
+ @fclose($fp);
204
+ } else {
205
+ $error = sprintf('Unable to create file: %s', $tmp_path);
206
+ return false;
207
+ }
208
+
209
+ if (! $this->_connect($error)) {
210
+ return false;
211
+ }
212
 
213
  if (! @ftp_mkdir($this->_ftp, $tmp_dir)) {
214
  $this->_disconnect();
215
  $error = sprintf('Unable to make directory: %s', $tmp_dir);
216
  return false;
217
+ } else {
218
+ @ftp_chmod($this->_ftp, 0755, $tmp_dir);
219
  }
220
 
221
  if (! @ftp_chdir($this->_ftp, $tmp_dir)) {
224
  return false;
225
  }
226
 
 
 
 
 
 
 
 
227
  if (! @ftp_put($this->_ftp, $tmp_file, $tmp_path, FTP_BINARY)) {
228
  @ftp_cdup($this->_ftp);
229
  @ftp_rmdir($this->_ftp, $tmp_dir);
237
  @ftp_cdup($this->_ftp);
238
  @ftp_rmdir($this->_ftp, $tmp_dir);
239
  @unlink($tmp_path);
 
240
  $this->_disconnect();
241
 
242
  return true;
lib/W3/Config.php CHANGED
@@ -23,6 +23,102 @@ class W3_Config
23
  */
24
  var $_config = array();
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  /**
27
  * Returns config value
28
  *
@@ -32,7 +128,7 @@ class W3_Config
32
  */
33
  function get($key, $default = null)
34
  {
35
- if (array_key_exists($key, $this->_config)) {
36
  return $this->_config[$key];
37
  }
38
 
@@ -98,7 +194,13 @@ class W3_Config
98
  */
99
  function set($key, $value)
100
  {
101
- $this->_config[$key] = $value;
 
 
 
 
 
 
102
  }
103
 
104
  /**
@@ -136,13 +238,12 @@ class W3_Config
136
 
137
  /**
138
  * Reads config from request
139
- * @param array $keys
140
  */
141
- function read_request($keys)
142
  {
143
  require_once W3TC_LIB_W3_DIR . '/Request.php';
144
 
145
- foreach ($keys as $key => $type) {
146
  $request_key = str_replace('.', '_', $key);
147
 
148
  if (! isset($_REQUEST[$request_key])) {
23
  */
24
  var $_config = array();
25
 
26
+ /**
27
+ * Config keys
28
+ */
29
+ var $_keys = array(
30
+ 'dbcache.enabled' => 'boolean',
31
+ 'dbcache.debug' => 'boolean',
32
+ 'dbcache.engine' => 'string',
33
+ 'dbcache.memcached.engine' => 'string',
34
+ 'dbcache.memcached.servers' => 'array',
35
+ 'dbcache.reject.admin' => 'boolean',
36
+ 'dbcache.reject.uri' => 'array',
37
+ 'dbcache.reject.cookie' => 'array',
38
+ 'dbcache.reject.sql' => 'array',
39
+ 'dbcache.lifetime' => 'integer',
40
+
41
+ 'pgcache.enabled' => 'boolean',
42
+ 'pgcache.debug' => 'boolean',
43
+ 'pgcache.engine' => 'string',
44
+ 'pgcache.memcached.engine' => 'string',
45
+ 'pgcache.memcached.servers' => 'array',
46
+ 'pgcache.lifetime' => 'integer',
47
+ 'pgcache.compress' => 'boolean',
48
+ 'pgcache.cache.logged' => 'boolean',
49
+ 'pgcache.cache.query' => 'boolean',
50
+ 'pgcache.cache.home' => 'boolean',
51
+ 'pgcache.cache.feed' => 'boolean',
52
+ 'pgcache.cache.404' => 'boolean',
53
+ 'pgcache.cache.flush' => 'boolean',
54
+ 'pgcache.cache.headers' => 'array',
55
+ 'pgcache.accept.files' => 'array',
56
+ 'pgcache.reject.uri' => 'array',
57
+ 'pgcache.reject.ua' => 'array',
58
+ 'pgcache.reject.cookie' => 'array',
59
+ 'pgcache.mobile.check' => 'boolean',
60
+ 'pgcache.mobile.whitelist' => 'array',
61
+ 'pgcache.mobile.browsers' => 'array',
62
+
63
+ 'minify.enabled' => 'boolean',
64
+ 'minify.debug' => 'boolean',
65
+ 'minify.engine' => 'string',
66
+ 'minify.memcached.engine' => 'string',
67
+ 'minify.memcached.servers' => 'array',
68
+ 'minify.rewrite' => 'boolean',
69
+ 'minify.logger' => 'boolean',
70
+ 'minify.cache.path' => 'string',
71
+ 'minify.cache.locking' => 'string',
72
+ 'minify.docroot' => 'string',
73
+ 'minify.fixtime' => 'integer',
74
+ 'minify.compress' => 'boolean',
75
+ 'minify.compress.ie6' => 'boolean',
76
+ 'minify.options' => 'array',
77
+ 'minify.symlinks' => 'array',
78
+ 'minify.lifetime' => 'integer',
79
+ 'minify.html.enable' => 'boolean',
80
+ 'minify.html.strip.crlf' => 'boolean',
81
+ 'minify.html.reject.admin' => 'boolean',
82
+ 'minify.css.enable' => 'boolean',
83
+ 'minify.css.strip.comments' => 'boolean',
84
+ 'minify.css.strip.crlf' => 'boolean',
85
+ 'minify.css.groups' => 'array',
86
+ 'minify.js.enable' => 'boolean',
87
+ 'minify.js.combine.header' => 'boolean',
88
+ 'minify.js.combine.footer' => 'boolean',
89
+ 'minify.js.strip.comments' => 'boolean',
90
+ 'minify.js.strip.crlf' => 'boolean',
91
+ 'minify.js.groups' => 'array',
92
+
93
+ 'cdn.enabled' => 'boolean',
94
+ 'cdn.debug' => 'boolean',
95
+ 'cdn.engine' => 'string',
96
+ 'cdn.domain' => 'string',
97
+ 'cdn.includes.enable' => 'boolean',
98
+ 'cdn.includes.files' => 'string',
99
+ 'cdn.theme.enable' => 'boolean',
100
+ 'cdn.theme.files' => 'string',
101
+ 'cdn.minify.enable' => 'boolean',
102
+ 'cdn.custom.enable' => 'boolean',
103
+ 'cdn.custom.files' => 'array',
104
+ 'cdn.import.external' => 'boolean',
105
+ 'cdn.import.files' => 'string',
106
+ 'cdn.limit.queue' => 'integer',
107
+ 'cdn.ftp.host' => 'string',
108
+ 'cdn.ftp.user' => 'string',
109
+ 'cdn.ftp.pass' => 'string',
110
+ 'cdn.ftp.path' => 'string',
111
+ 'cdn.ftp.pasv' => 'boolean',
112
+
113
+ 'common.support.enabled' => 'boolean',
114
+ 'common.support.type' => 'string',
115
+
116
+ 'notes.defaults' => 'boolean',
117
+ 'notes.wp_content_perms' => 'boolean',
118
+ 'notes.cdn_first_time' => 'boolean',
119
+ 'notes.no_memcached_nor_apc' => 'boolean',
120
+ );
121
+
122
  /**
123
  * Returns config value
124
  *
128
  */
129
  function get($key, $default = null)
130
  {
131
+ if (isset($this->_keys[$key]) && array_key_exists($key, $this->_config)) {
132
  return $this->_config[$key];
133
  }
134
 
194
  */
195
  function set($key, $value)
196
  {
197
+ if (isset($this->_keys[$key])) {
198
+ $type = $this->_keys[$key];
199
+ settype($value, $type);
200
+ $this->_config[$key] = $value;
201
+ }
202
+
203
+ return false;
204
  }
205
 
206
  /**
238
 
239
  /**
240
  * Reads config from request
 
241
  */
242
+ function read_request()
243
  {
244
  require_once W3TC_LIB_W3_DIR . '/Request.php';
245
 
246
+ foreach ($this->_keys as $key => $type) {
247
  $request_key = str_replace('.', '_', $key);
248
 
249
  if (! isset($_REQUEST[$request_key])) {
lib/W3/Db.php CHANGED
@@ -61,6 +61,13 @@ class W3_Db extends wpdb
61
  */
62
  var $_config = null;
63
 
 
 
 
 
 
 
 
64
  /**
65
  * PHP5 constructor
66
  *
@@ -73,6 +80,7 @@ class W3_Db extends wpdb
73
  {
74
  require_once W3TC_LIB_W3_DIR . '/Config.php';
75
  $this->_config = W3_Config::instance();
 
76
 
77
  parent::__construct($dbuser, $dbpassword, $dbname, $dbhost);
78
  }
@@ -102,7 +110,7 @@ class W3_Db extends wpdb
102
  return false;
103
  }
104
 
105
- ++ $this->query_total;
106
 
107
  // filter the query, if filters are available
108
  // NOTE: some queries are made before the plugins have been loaded, and thus cannot be filtered with this method
@@ -120,7 +128,8 @@ class W3_Db extends wpdb
120
  // Keep track of the last query for debug..
121
  $this->last_query = $query;
122
 
123
- $caching = $this->can_cache($query);
 
124
  $cached = false;
125
  $data = false;
126
  $time_total = 0;
@@ -138,7 +147,7 @@ class W3_Db extends wpdb
138
  * Check if query was cached
139
  */
140
  if (is_array($data)) {
141
- ++ $this->query_hits;
142
  $cached = true;
143
 
144
  /**
@@ -150,8 +159,8 @@ class W3_Db extends wpdb
150
  $this->col_info = $data['col_info'];
151
  $this->num_rows = $data['num_rows'];
152
  } else {
153
- ++ $this->num_queries;
154
- ++ $this->query_misses;
155
 
156
  // Perform the query via std mysql_query function..
157
  $this->timer_start();
@@ -184,13 +193,13 @@ class W3_Db extends wpdb
184
  $i = 0;
185
  while ($i < @mysql_num_fields($this->result)) {
186
  $this->col_info[$i] = @mysql_fetch_field($this->result);
187
- $i ++;
188
  }
189
 
190
  $num_rows = 0;
191
  while (($row = @mysql_fetch_object($this->result))) {
192
  $this->last_result[$num_rows] = $row;
193
- $num_rows ++;
194
  }
195
 
196
  @mysql_free_result($this->result);
@@ -214,7 +223,7 @@ class W3_Db extends wpdb
214
  );
215
 
216
  $cache = $this->_get_cache();
217
- $cache->set($cache_key, $data, $this->_get_lifetime($query));
218
  }
219
  }
220
  }
@@ -223,6 +232,7 @@ class W3_Db extends wpdb
223
  $this->query_stats[] = array(
224
  'query' => $query,
225
  'caching' => $caching,
 
226
  'cached' => $cached,
227
  'time_total' => $time_total
228
  );
@@ -239,12 +249,21 @@ class W3_Db extends wpdb
239
  * @param string $sql
240
  * @return boolean
241
  */
242
- function can_cache($sql)
243
  {
244
  /**
245
  * Skip if disabled
246
  */
247
  if (! $this->_config->get_boolean('dbcache.enabled')) {
 
 
 
 
 
 
 
 
 
248
  return false;
249
  }
250
 
@@ -252,13 +271,31 @@ class W3_Db extends wpdb
252
  * Skip if doing cron
253
  */
254
  if (defined('DOING_CRON')) {
 
255
  return false;
256
  }
257
 
258
  /**
259
- * Skip if request URI is rejected
260
  */
261
- if (! $this->_check_request_uri()) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  return false;
263
  }
264
 
@@ -266,6 +303,31 @@ class W3_Db extends wpdb
266
  * Skip if SQL is rejected
267
  */
268
  if (! $this->_check_sql($sql)) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  return false;
270
  }
271
 
@@ -316,9 +378,9 @@ class W3_Db extends wpdb
316
 
317
  if (count($this->query_stats)) {
318
  $debug_info .= "SQL info:\r\n";
319
- $debug_info .= sprintf("%s | %s | %s | % s | %s\r\n", str_pad('#', 5, ' ', STR_PAD_LEFT), str_pad('Time (s)', 8, ' ', STR_PAD_LEFT), str_pad('Caching', 10, ' ', STR_PAD_BOTH), str_pad('Status', 10, ' ', STR_PAD_BOTH), 'Query');
320
  foreach ($this->query_stats as $index => $query) {
321
- $debug_info .= sprintf("%s | %s | %s | %s | %s\r\n", str_pad($index + 1, 5, ' ', STR_PAD_LEFT), str_pad(round($query['time_total'], 3), 8, ' ', STR_PAD_LEFT), str_pad(($query['caching'] ? 'enabled' : 'disabled'), 10, ' ', STR_PAD_BOTH), str_pad(($query['cached'] ? 'Cached' : 'Not cached'), 10, ' ', STR_PAD_BOTH), str_replace('-->', '-- >', trim($query['query'])));
322
  }
323
  }
324
 
@@ -341,7 +403,8 @@ class W3_Db extends wpdb
341
  if ($engine == 'memcached') {
342
  $engineConfig = array(
343
  'engine' => $this->_config->get_string('dbcache.memcached.engine', 'auto'),
344
- 'servers' => $this->_config->get_array('dbcache.memcached.servers')
 
345
  );
346
  } else {
347
  $engineConfig = array();
@@ -371,7 +434,8 @@ class W3_Db extends wpdb
371
  'set names',
372
  'found_rows',
373
  $this->prefix . 'posts',
374
- $this->prefix . 'postsmeta'
 
375
  );
376
 
377
  if (preg_match('@(' . implode('|', $auto_reject_strings) . ')@i', $sql)) {
@@ -398,7 +462,6 @@ class W3_Db extends wpdb
398
  function _check_request_uri()
399
  {
400
  $auto_reject_uri = array(
401
- 'wp-admin',
402
  'wp-login',
403
  'wp-register',
404
  'wp-signup'
@@ -423,48 +486,65 @@ class W3_Db extends wpdb
423
  }
424
 
425
  /**
426
- * Returns cache key
427
  *
428
- * @param string $sql
429
- * @return string
430
  */
431
- function _get_cache_key($sql)
432
  {
433
- $blog_id = w3_get_blog_id();
 
 
 
 
 
 
 
434
 
435
- if (empty($blog_id)) {
436
- $blog_id = $_SERVER['HTTP_HOST'];
 
 
 
 
437
  }
438
 
439
- return sprintf('w3tc_%s_sql_%s', md5($blog_id), md5($sql));
440
  }
441
 
442
  /**
443
- * Returns lifetime for SQL
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
  *
445
  * @param string $sql
446
- * @return integer
447
  */
448
- function _get_lifetime($sql)
449
  {
450
- $config = array(
451
- '__default' => $this->_config->get_integer('dbcache.lifetime.default', 180),
452
- '_options' => $this->_config->get_integer('dbcache.lifetime.options', 180),
453
- '_links' => $this->_config->get_integer('dbcache.lifetime.links', 10800),
454
- '_terms' => $this->_config->get_integer('dbcache.lifetime.terms', 10800),
455
- '_user' => $this->_config->get_integer('dbcache.lifetime.user', 1800),
456
- '_post' => $this->_config->get_integer('dbcache.lifetime.post', 3600)
457
- );
458
-
459
- $lifetime = $config['__default'];
460
 
461
- foreach ($config as $string => $ttl) {
462
- if (strstr($sql, $string) !== false) {
463
- $lifetime = $ttl;
464
- break;
465
- }
466
  }
467
 
468
- return $lifetime;
469
  }
470
  }
61
  */
62
  var $_config = null;
63
 
64
+ /**
65
+ * Lifetime
66
+ *
67
+ * @var integer
68
+ */
69
+ var $_lifetime = null;
70
+
71
  /**
72
  * PHP5 constructor
73
  *
80
  {
81
  require_once W3TC_LIB_W3_DIR . '/Config.php';
82
  $this->_config = W3_Config::instance();
83
+ $this->_lifetime = $this->_config->get_integer('dbcache.lifetime', 180);
84
 
85
  parent::__construct($dbuser, $dbpassword, $dbname, $dbhost);
86
  }
110
  return false;
111
  }
112
 
113
+ ++$this->query_total;
114
 
115
  // filter the query, if filters are available
116
  // NOTE: some queries are made before the plugins have been loaded, and thus cannot be filtered with this method
128
  // Keep track of the last query for debug..
129
  $this->last_query = $query;
130
 
131
+ $reason = '';
132
+ $caching = $this->can_cache($query, $reason);
133
  $cached = false;
134
  $data = false;
135
  $time_total = 0;
147
  * Check if query was cached
148
  */
149
  if (is_array($data)) {
150
+ ++$this->query_hits;
151
  $cached = true;
152
 
153
  /**
159
  $this->col_info = $data['col_info'];
160
  $this->num_rows = $data['num_rows'];
161
  } else {
162
+ ++$this->num_queries;
163
+ ++$this->query_misses;
164
 
165
  // Perform the query via std mysql_query function..
166
  $this->timer_start();
193
  $i = 0;
194
  while ($i < @mysql_num_fields($this->result)) {
195
  $this->col_info[$i] = @mysql_fetch_field($this->result);
196
+ $i++;
197
  }
198
 
199
  $num_rows = 0;
200
  while (($row = @mysql_fetch_object($this->result))) {
201
  $this->last_result[$num_rows] = $row;
202
+ $num_rows++;
203
  }
204
 
205
  @mysql_free_result($this->result);
223
  );
224
 
225
  $cache = $this->_get_cache();
226
+ $cache->set($cache_key, $data, $this->_lifetime);
227
  }
228
  }
229
  }
232
  $this->query_stats[] = array(
233
  'query' => $query,
234
  'caching' => $caching,
235
+ 'reason' => $reason,
236
  'cached' => $cached,
237
  'time_total' => $time_total
238
  );
249
  * @param string $sql
250
  * @return boolean
251
  */
252
+ function can_cache($sql, &$cache_reject_reason)
253
  {
254
  /**
255
  * Skip if disabled
256
  */
257
  if (! $this->_config->get_boolean('dbcache.enabled')) {
258
+ $cache_reject_reason = 'Caching is disabled';
259
+ return false;
260
+ }
261
+
262
+ /**
263
+ * Skip if doint AJAX
264
+ */
265
+ if (defined('DOING_AJAX')) {
266
+ $cache_reject_reason = 'Doing AJAX';
267
  return false;
268
  }
269
 
271
  * Skip if doing cron
272
  */
273
  if (defined('DOING_CRON')) {
274
+ $cache_reject_reason = 'Doing cron';
275
  return false;
276
  }
277
 
278
  /**
279
+ * Skip if APP request
280
  */
281
+ if (defined('APP_REQUEST')) {
282
+ $cache_reject_reason = 'APP request';
283
+ return false;
284
+ }
285
+
286
+ /**
287
+ * Skip if XMLRPC request
288
+ */
289
+ if (defined('XMLRPC_REQUEST')) {
290
+ $cache_reject_reason = 'XMLRPC request';
291
+ return false;
292
+ }
293
+
294
+ /**
295
+ * Skip if admin
296
+ */
297
+ if (defined('WP_ADMIN')) {
298
+ $cache_reject_reason = 'Admin';
299
  return false;
300
  }
301
 
303
  * Skip if SQL is rejected
304
  */
305
  if (! $this->_check_sql($sql)) {
306
+ $cache_reject_reason = 'SQL rejected';
307
+ return false;
308
+ }
309
+
310
+ /**
311
+ * Skip if request URI is rejected
312
+ */
313
+ if (! $this->_check_request_uri()) {
314
+ $cache_reject_reason = 'URI rejected';
315
+ return false;
316
+ }
317
+
318
+ /**
319
+ * Skip if cookie is rejected
320
+ */
321
+ if (! $this->_check_cookies()) {
322
+ $cache_reject_reason = 'Cookie rejected';
323
+ return false;
324
+ }
325
+
326
+ /**
327
+ * Skip if user is logged in
328
+ */
329
+ if (! $this->_check_logged_in()) {
330
+ $cache_reject_reason = 'User is logged in';
331
  return false;
332
  }
333
 
378
 
379
  if (count($this->query_stats)) {
380
  $debug_info .= "SQL info:\r\n";
381
+ $debug_info .= sprintf("%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), 'Query');
382
  foreach ($this->query_stats as $index => $query) {
383
+ $debug_info .= sprintf("%s | %s | %s | %s | %s\r\n", str_pad($index + 1, 5, ' ', STR_PAD_LEFT), str_pad(round($query['time_total'], 3), 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_replace('-->', '-- >', trim($query['query'])));
384
  }
385
  }
386
 
403
  if ($engine == 'memcached') {
404
  $engineConfig = array(
405
  'engine' => $this->_config->get_string('dbcache.memcached.engine', 'auto'),
406
+ 'servers' => $this->_config->get_array('dbcache.memcached.servers'),
407
+ 'persistant' => true
408
  );
409
  } else {
410
  $engineConfig = array();
434
  'set names',
435
  'found_rows',
436
  $this->prefix . 'posts',
437
+ $this->prefix . 'postmeta',
438
+ $this->prefix . 'comments'
439
  );
440
 
441
  if (preg_match('@(' . implode('|', $auto_reject_strings) . ')@i', $sql)) {
462
  function _check_request_uri()
463
  {
464
  $auto_reject_uri = array(
 
465
  'wp-login',
466
  'wp-register',
467
  'wp-signup'
486
  }
487
 
488
  /**
489
+ * Checks WordPress cookies
490
  *
491
+ * @return boolean
 
492
  */
493
+ function _check_cookies()
494
  {
495
+ foreach (array_keys($_COOKIE) as $cookie_name) {
496
+ if ($cookie_name == 'wordpress_test_cookie') {
497
+ continue;
498
+ }
499
+ if (preg_match('/^wp-postpass|^comment_author/', $cookie_name)) {
500
+ return false;
501
+ }
502
+ }
503
 
504
+ foreach ($this->_config->get_array('dbcache.reject.cookie') as $reject_cookie) {
505
+ foreach (array_keys($_COOKIE) as $cookie_name) {
506
+ if (strstr($cookie_name, $reject_cookie) !== false) {
507
+ return false;
508
+ }
509
+ }
510
  }
511
 
512
+ return true;
513
  }
514
 
515
  /**
516
+ * Check if user is logged in
517
+ *
518
+ * @return boolean
519
+ */
520
+ function _check_logged_in()
521
+ {
522
+ foreach (array_keys($_COOKIE) as $cookie_name) {
523
+ if ($cookie_name == 'wordpress_test_cookie') {
524
+ continue;
525
+ }
526
+ if (strpos($cookie_name, 'wordpress') === 0) {
527
+ return false;
528
+ }
529
+ }
530
+
531
+ return true;
532
+ }
533
+
534
+ /**
535
+ * Returns cache key
536
  *
537
  * @param string $sql
538
+ * @return string
539
  */
540
+ function _get_cache_key($sql)
541
  {
542
+ $blog_id = w3_get_blog_id();
 
 
 
 
 
 
 
 
 
543
 
544
+ if (empty($blog_id)) {
545
+ $blog_id = $_SERVER['HTTP_HOST'];
 
 
 
546
  }
547
 
548
+ return sprintf('w3tc_%s_sql_%s', md5($blog_id), md5($sql));
549
  }
550
  }
lib/W3/Minify.php CHANGED
@@ -87,12 +87,25 @@ class W3_Minify
87
  $serve_options['maxAge'] = 31536000;
88
  }
89
 
90
- if (isset($_GET['g']) && isset($_GET['t'])) {
91
- // will need groups config
92
- $serve_options['minApp']['groups'] = $this->_get_groups($_GET['t']);
93
- }
94
-
95
- if (isset($_GET['f']) || isset($_GET['g'])) {
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  // serve!
97
  @header('X-Powered-By: ' . W3TC_POWERED_BY);
98
  Minify::serve('MinApp', $serve_options);
@@ -112,23 +125,27 @@ class W3_Minify
112
  {
113
  switch ($type) {
114
  case 'text/css':
115
- if ($this->_config->get_boolean('minify.css.strip.comments', true)) {
116
  $content = preg_replace('~/\*.*\*/~Us', '', $content);
117
  }
118
 
119
- if ($this->_config->get_boolean('minify.css.strip.crlf', true)) {
120
  $content = preg_replace("~[\r\n]+~", ' ', $content);
 
 
121
  }
122
  break;
123
 
124
  case 'application/x-javascript':
125
- if ($this->_config->get_boolean('minify.js.strip.comments', true)) {
126
  $content = preg_replace('~^//.*$~m', '', $content);
127
  $content = preg_replace('~/\*.*\*/~Us', '', $content);
128
  }
129
 
130
- if ($this->_config->get_boolean('minify.js.strip.crlf', true)) {
131
  $content = preg_replace("~[\r\n]+~", '', $content);
 
 
132
  }
133
  break;
134
  }
@@ -207,7 +224,7 @@ class W3_Minify
207
  if (w3_is_url($css_file)) {
208
  $css_file_info = sprintf('%s (%s)', $css_file, $css_file_path);
209
  } else {
210
- $css_file_path = $css_file_info = ABSPATH . ltrim($css_file, '/');
211
  }
212
 
213
  $debug_info .= sprintf("%s | %s | % s | %s\r\n", str_pad($css_group, 15, ' ', STR_PAD_BOTH), str_pad(date('Y-m-d H:i:s', filemtime($css_file_path)), 19, ' ', STR_PAD_BOTH), str_pad(filesize($css_file_path), 12, ' ', STR_PAD_LEFT), $css_file_info);
@@ -226,7 +243,7 @@ class W3_Minify
226
  if (w3_is_url($js_file)) {
227
  $js_file_info = sprintf('%s (%s)', $js_file, $js_file_path);
228
  } else {
229
- $js_file_path = $js_file_info = ABSPATH . ltrim($js_file, '/');
230
  }
231
 
232
  $debug_info .= sprintf("%s | %s | % s | %s\r\n", str_pad($js_group, 15, ' ', STR_PAD_BOTH), str_pad(date('Y-m-d H:i:s', filemtime($js_file_path)), 19, ' ', STR_PAD_BOTH), str_pad(filesize($js_file_path), 12, ' ', STR_PAD_LEFT), $js_file_info);
@@ -239,6 +256,16 @@ class W3_Minify
239
  return $debug_info;
240
  }
241
 
 
 
 
 
 
 
 
 
 
 
242
  /**
243
  * Returns minify groups
244
  *
@@ -331,7 +358,8 @@ class W3_Minify
331
  require_once W3TC_LIB_W3_DIR . '/Cache/Memcached.php';
332
  require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/Memcache.php';
333
  $memcached = & W3_Cache_Memcached::instance($this->_config->get_string('minify.memcached.engine', 'auto'), array(
334
- 'servers' => $this->_config->get_array('minify.memcached.servers')
 
335
  ));
336
  $cache = & new Minify_Cache_Memcache($memcached);
337
  break;
87
  $serve_options['maxAge'] = 31536000;
88
  }
89
 
90
+ if (isset($_GET['f']) || (isset($_GET['g']) && isset($_GET['t']))) {
91
+ if (isset($_GET['g']) && isset($_GET['t'])) {
92
+ // will need groups config
93
+ $serve_options['minApp']['groups'] = $this->_get_groups($_GET['t']);
94
+
95
+ if ($_GET['t'] == 'js' && ((in_array($_GET['g'], array(
96
+ 'include',
97
+ 'include-nb'
98
+ )) && $this->_config->get_boolean('minify.js.combine.header')) || (in_array($_GET['g'], array(
99
+ 'include-footer',
100
+ 'include-footer-nb'
101
+ )) && $this->_config->get_boolean('minify.js.combine.footer')))) {
102
+ $serve_options['minifiers']['application/x-javascript'] = array(
103
+ $this,
104
+ 'minify_stub'
105
+ );
106
+ }
107
+ }
108
+
109
  // serve!
110
  @header('X-Powered-By: ' . W3TC_POWERED_BY);
111
  Minify::serve('MinApp', $serve_options);
125
  {
126
  switch ($type) {
127
  case 'text/css':
128
+ if ($this->_config->get_boolean('minify.css.strip.comments')) {
129
  $content = preg_replace('~/\*.*\*/~Us', '', $content);
130
  }
131
 
132
+ if ($this->_config->get_boolean('minify.css.strip.crlf')) {
133
  $content = preg_replace("~[\r\n]+~", ' ', $content);
134
+ } else {
135
+ $content = preg_replace("~[\r\n]+~", "\n", $content);
136
  }
137
  break;
138
 
139
  case 'application/x-javascript':
140
+ if ($this->_config->get_boolean('minify.js.strip.comments')) {
141
  $content = preg_replace('~^//.*$~m', '', $content);
142
  $content = preg_replace('~/\*.*\*/~Us', '', $content);
143
  }
144
 
145
+ if ($this->_config->get_boolean('minify.js.strip.crlf')) {
146
  $content = preg_replace("~[\r\n]+~", '', $content);
147
+ } else {
148
+ $content = preg_replace("~[\r\n]+~", "\n", $content);
149
  }
150
  break;
151
  }
224
  if (w3_is_url($css_file)) {
225
  $css_file_info = sprintf('%s (%s)', $css_file, $css_file_path);
226
  } else {
227
+ $css_file_path = $css_file_info = ABSPATH . ltrim($css_file, '\\/');
228
  }
229
 
230
  $debug_info .= sprintf("%s | %s | % s | %s\r\n", str_pad($css_group, 15, ' ', STR_PAD_BOTH), str_pad(date('Y-m-d H:i:s', filemtime($css_file_path)), 19, ' ', STR_PAD_BOTH), str_pad(filesize($css_file_path), 12, ' ', STR_PAD_LEFT), $css_file_info);
243
  if (w3_is_url($js_file)) {
244
  $js_file_info = sprintf('%s (%s)', $js_file, $js_file_path);
245
  } else {
246
+ $js_file_path = $js_file_info = ABSPATH . ltrim($js_file, '\\/');
247
  }
248
 
249
  $debug_info .= sprintf("%s | %s | % s | %s\r\n", str_pad($js_group, 15, ' ', STR_PAD_BOTH), str_pad(date('Y-m-d H:i:s', filemtime($js_file_path)), 19, ' ', STR_PAD_BOTH), str_pad(filesize($js_file_path), 12, ' ', STR_PAD_LEFT), $js_file_info);
256
  return $debug_info;
257
  }
258
 
259
+ /**
260
+ * Minify stub function
261
+ *
262
+ * @param string $source
263
+ */
264
+ function minify_stub($source)
265
+ {
266
+ return $source;
267
+ }
268
+
269
  /**
270
  * Returns minify groups
271
  *
358
  require_once W3TC_LIB_W3_DIR . '/Cache/Memcached.php';
359
  require_once W3TC_LIB_MINIFY_DIR . '/Minify/Cache/Memcache.php';
360
  $memcached = & W3_Cache_Memcached::instance($this->_config->get_string('minify.memcached.engine', 'auto'), array(
361
+ 'servers' => $this->_config->get_array('minify.memcached.servers'),
362
+ 'persistant' => true
363
  ));
364
  $cache = & new Minify_Cache_Memcache($memcached);
365
  break;
lib/W3/PgCache.php CHANGED
@@ -44,6 +44,13 @@ class W3_PgCache
44
  */
45
  var $_time_start = 0;
46
 
 
 
 
 
 
 
 
47
  /**
48
  * PHP5 Constructor
49
  */
@@ -100,7 +107,7 @@ class W3_PgCache
100
  */
101
  if ($this->_config->get_boolean('pgcache.debug')) {
102
  $time_total = w3_microtime() - $this->_time_start;
103
- $debug_info = $this->_get_debug_info(true, true, $time_total, $data['headers']);
104
  $this->_append_content($data, "\r\n\r\n" . $debug_info);
105
  }
106
 
@@ -136,10 +143,16 @@ class W3_PgCache
136
  */
137
  function ob_callback($buffer)
138
  {
139
- if (empty($buffer) || ! $this->_can_cache2()) {
140
- if (w3_is_xml($buffer)) {
141
  $this->_send_compression_headers($this->_compression);
142
 
 
 
 
 
 
 
143
  switch ($this->_compression) {
144
  case 'gzip':
145
  return gzencode($buffer);
@@ -164,7 +177,7 @@ class W3_PgCache
164
  $page_keys = array();
165
 
166
  $cache = $this->_get_cache();
167
- $lifetime = $this->_config->get_integer('dbcache.lifetime', 3600);
168
  $time = time();
169
  $is_404 = is_404();
170
 
@@ -184,7 +197,7 @@ class W3_PgCache
184
  * Set headers to cache
185
  */
186
  $data['headers'] = $this->_get_data_headers($compression);
187
-
188
  /**
189
  * Set content to cache
190
  */
@@ -235,7 +248,7 @@ class W3_PgCache
235
  */
236
  if ($this->_config->get_boolean('pgcache.debug')) {
237
  $time_total = w3_microtime() - $this->_time_start;
238
- $debug_info = $this->_get_debug_info(true, false, $time_total, $data_array[$this->_compression]['headers']);
239
  $this->_append_content($data_array[$this->_compression], "\r\n\r\n" . $debug_info);
240
  }
241
 
@@ -356,6 +369,47 @@ class W3_PgCache
356
  * Skip if disabled
357
  */
358
  if (! $this->_config->get_boolean('pgcache.enabled', true)) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
359
  return false;
360
  }
361
 
@@ -363,6 +417,7 @@ class W3_PgCache
363
  * Skip if posting
364
  */
365
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
 
366
  return false;
367
  }
368
 
@@ -370,6 +425,7 @@ class W3_PgCache
370
  * Skip if session defined
371
  */
372
  if (defined('SID') && SID != '') {
 
373
  return false;
374
  }
375
 
@@ -377,6 +433,7 @@ class W3_PgCache
377
  * Skip if there is query in the request uri
378
  */
379
  if (! $this->_config->get_boolean('pgcache.cache.query', true) && strstr($_SERVER['REQUEST_URI'], '?') !== false) {
 
380
  return false;
381
  }
382
 
@@ -384,6 +441,7 @@ class W3_PgCache
384
  * Check request URI
385
  */
386
  if (! in_array($_SERVER['PHP_SELF'], $this->_config->get_array('pgcache.accept.files')) && ! $this->_check_request_uri()) {
 
387
  return false;
388
  }
389
 
@@ -391,6 +449,7 @@ class W3_PgCache
391
  * Check User Agent
392
  */
393
  if (! $this->_check_ua()) {
 
394
  return false;
395
  }
396
 
@@ -398,6 +457,16 @@ class W3_PgCache
398
  * Check WordPress cookies
399
  */
400
  if (! $this->_check_cookies()) {
 
 
 
 
 
 
 
 
 
 
401
  return false;
402
  }
403
 
@@ -407,9 +476,10 @@ class W3_PgCache
407
  /**
408
  * Checks if can we do cache logic
409
  *
 
410
  * @return boolean
411
  */
412
- function _can_cache2()
413
  {
414
  /**
415
  * Skip if caching is disabled
@@ -418,10 +488,18 @@ class W3_PgCache
418
  return false;
419
  }
420
 
 
 
 
 
 
 
421
  /**
422
  * Don't cache 404 pages
423
  */
424
  if (! $this->_config->get_boolean('pgcache.cache.404', true) && is_404()) {
 
 
425
  return false;
426
  }
427
 
@@ -429,6 +507,8 @@ class W3_PgCache
429
  * Don't cache homepage
430
  */
431
  if (! $this->_config->get_boolean('pgcache.cache.home', true) && is_home()) {
 
 
432
  return false;
433
  }
434
 
@@ -436,13 +516,8 @@ class W3_PgCache
436
  * Don't cache feed
437
  */
438
  if (! $this->_config->get_boolean('pgcache.cache.feed', true) && is_feed()) {
439
- return false;
440
- }
441
-
442
- /**
443
- * Skip if user is logged in
444
- */
445
- if (! $this->_config->get_boolean('pgcache.cache.logged', true) && is_user_logged_in()) {
446
  return false;
447
  }
448
 
@@ -463,7 +538,8 @@ class W3_PgCache
463
  if ($engine == 'memcached') {
464
  $engineConfig = array(
465
  'engine' => $this->_config->get_string('pgcache.memcached.engine', 'auto'),
466
- 'servers' => $this->_config->get_array('pgcache.memcached.servers')
 
467
  );
468
  } else {
469
  $engineConfig = array();
@@ -484,11 +560,8 @@ class W3_PgCache
484
  function _check_request_uri()
485
  {
486
  $auto_reject_uri = array(
487
- 'wp-admin',
488
  'wp-includes',
489
  'wp-content',
490
- 'xmlrpc.php',
491
- 'wp-app.php',
492
  'robots.txt'
493
  );
494
 
@@ -535,7 +608,7 @@ class W3_PgCache
535
  if ($cookie_name == 'wordpress_test_cookie') {
536
  continue;
537
  }
538
- if (preg_match('/^wp-postpass|^wordpress|^comment_author/', $cookie_name)) {
539
  return false;
540
  }
541
  }
@@ -551,6 +624,25 @@ class W3_PgCache
551
  return true;
552
  }
553
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
554
  /**
555
  * Checks gzip availability
556
  *
@@ -723,19 +815,23 @@ class W3_PgCache
723
  * Returns debug info
724
  *
725
  * @param boolean $cache
 
726
  * @param boolean $status
727
  * @param double $time
728
  * @param array $headers
729
  * @return string
730
  */
731
- function _get_debug_info($cache, $status, $time, $headers)
732
  {
733
  $debug_info = "<!-- W3 Total Cache: Page cache debug info:\r\n";
734
  $debug_info .= sprintf("%s%s\r\n", str_pad('Engine: ', 20), $this->_config->get_string('pgcache.engine'));
735
  $debug_info .= sprintf("%s%s\r\n", str_pad('Key: ', 20), $this->_page_key);
736
  $debug_info .= sprintf("%s%s\r\n", str_pad('Caching: ', 20), ($cache ? 'enabled' : 'disabled'));
 
 
 
737
  $debug_info .= sprintf("%s%s\r\n", str_pad('Status: ', 20), ($status ? 'cached' : 'not cached'));
738
- $debug_info .= sprintf("%s%.3fs\r\n", str_pad('Time: ', 20), $time);
739
 
740
  if (count($headers)) {
741
  $debug_info .= "Headers info:\r\n";
@@ -764,7 +860,7 @@ class W3_PgCache
764
  break;
765
 
766
  case 'gzip':
767
- $data['content'] = gzdecode($data['content']);
768
  $data['content'] .= $content;
769
  $data['content'] = gzencode($data['content']);
770
  break;
44
  */
45
  var $_time_start = 0;
46
 
47
+ /**
48
+ * Cache reject reason
49
+ *
50
+ * @var string
51
+ */
52
+ var $_cache_reject_reason = '';
53
+
54
  /**
55
  * PHP5 Constructor
56
  */
107
  */
108
  if ($this->_config->get_boolean('pgcache.debug')) {
109
  $time_total = w3_microtime() - $this->_time_start;
110
+ $debug_info = $this->_get_debug_info(true, '', true, $time_total, $data['headers']);
111
  $this->_append_content($data, "\r\n\r\n" . $debug_info);
112
  }
113
 
143
  */
144
  function ob_callback($buffer)
145
  {
146
+ if (! $this->_can_cache2($buffer)) {
147
+ if (w3_is_xml($buffer) && ! is_admin()) {
148
  $this->_send_compression_headers($this->_compression);
149
 
150
+ if ($this->_config->get_boolean('pgcache.debug')) {
151
+ $time_total = w3_microtime() - $this->_time_start;
152
+ $debug_info = $this->_get_debug_info(false, $this->_cache_reject_reason, false, $time_total, $this->_get_data_headers($this->_compression));
153
+ $buffer .= "\r\n\r\n" . $debug_info;
154
+ }
155
+
156
  switch ($this->_compression) {
157
  case 'gzip':
158
  return gzencode($buffer);
177
  $page_keys = array();
178
 
179
  $cache = $this->_get_cache();
180
+ $lifetime = $this->_config->get_integer('pgcache.lifetime', 3600);
181
  $time = time();
182
  $is_404 = is_404();
183
 
197
  * Set headers to cache
198
  */
199
  $data['headers'] = $this->_get_data_headers($compression);
200
+
201
  /**
202
  * Set content to cache
203
  */
248
  */
249
  if ($this->_config->get_boolean('pgcache.debug')) {
250
  $time_total = w3_microtime() - $this->_time_start;
251
+ $debug_info = $this->_get_debug_info(true, '', false, $time_total, $data_array[$this->_compression]['headers']);
252
  $this->_append_content($data_array[$this->_compression], "\r\n\r\n" . $debug_info);
253
  }
254
 
369
  * Skip if disabled
370
  */
371
  if (! $this->_config->get_boolean('pgcache.enabled', true)) {
372
+ $this->_cache_reject_reason = 'Caching is disabled';
373
+ return false;
374
+ }
375
+
376
+ /**
377
+ * Skip if doing AJAX
378
+ */
379
+ if (defined('DOING_AJAX')) {
380
+ $this->_cache_reject_reason = 'Doing AJAX';
381
+ return false;
382
+ }
383
+
384
+ /**
385
+ * Skip if doing cron
386
+ */
387
+ if (defined('DOING_CRON')) {
388
+ $this->_cache_reject_reason = 'Doing cron';
389
+ return false;
390
+ }
391
+
392
+ /**
393
+ * Skip if APP request
394
+ */
395
+ if (defined('APP_REQUEST')) {
396
+ $this->_cache_reject_reason = 'APP request';
397
+ return false;
398
+ }
399
+
400
+ /**
401
+ * Skip if XMLRPC request
402
+ */
403
+ if (defined('XMLRPC_REQUEST')) {
404
+ $this->_cache_reject_reason = 'XMLRPC request';
405
+ return false;
406
+ }
407
+
408
+ /**
409
+ * Skip if admin
410
+ */
411
+ if (defined('WP_ADMIN')) {
412
+ $this->_cache_reject_reason = 'Admin';
413
  return false;
414
  }
415
 
417
  * Skip if posting
418
  */
419
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
420
+ $this->_cache_reject_reason = 'Request method is POST';
421
  return false;
422
  }
423
 
425
  * Skip if session defined
426
  */
427
  if (defined('SID') && SID != '') {
428
+ $this->_cache_reject_reason = 'Session is started';
429
  return false;
430
  }
431
 
433
  * Skip if there is query in the request uri
434
  */
435
  if (! $this->_config->get_boolean('pgcache.cache.query', true) && strstr($_SERVER['REQUEST_URI'], '?') !== false) {
436
+ $this->_cache_reject_reason = 'Request URI contains query';
437
  return false;
438
  }
439
 
441
  * Check request URI
442
  */
443
  if (! in_array($_SERVER['PHP_SELF'], $this->_config->get_array('pgcache.accept.files')) && ! $this->_check_request_uri()) {
444
+ $this->_cache_reject_reason = 'Request URI rejected';
445
  return false;
446
  }
447
 
449
  * Check User Agent
450
  */
451
  if (! $this->_check_ua()) {
452
+ $this->_cache_reject_reason = 'User Agent rejected';
453
  return false;
454
  }
455
 
457
  * Check WordPress cookies
458
  */
459
  if (! $this->_check_cookies()) {
460
+ $this->_cache_reject_reason = 'Cookie rejected';
461
+ return false;
462
+ }
463
+
464
+ /**
465
+ * Skip if user is logged in
466
+ */
467
+ if (! $this->_config->get_boolean('pgcache.cache.logged', true) && ! $this->_check_logged_in()) {
468
+ $this->_cache_reject_reason = 'User is logged in';
469
+
470
  return false;
471
  }
472
 
476
  /**
477
  * Checks if can we do cache logic
478
  *
479
+ * @param string $buffer
480
  * @return boolean
481
  */
482
+ function _can_cache2($buffer)
483
  {
484
  /**
485
  * Skip if caching is disabled
488
  return false;
489
  }
490
 
491
+ if (empty($buffer)) {
492
+ $this->_cache_reject_reason = 'Page is empty';
493
+
494
+ return false;
495
+ }
496
+
497
  /**
498
  * Don't cache 404 pages
499
  */
500
  if (! $this->_config->get_boolean('pgcache.cache.404', true) && is_404()) {
501
+ $this->_cache_reject_reason = 'Page is 404';
502
+
503
  return false;
504
  }
505
 
507
  * Don't cache homepage
508
  */
509
  if (! $this->_config->get_boolean('pgcache.cache.home', true) && is_home()) {
510
+ $this->_cache_reject_reason = 'Page is home';
511
+
512
  return false;
513
  }
514
 
516
  * Don't cache feed
517
  */
518
  if (! $this->_config->get_boolean('pgcache.cache.feed', true) && is_feed()) {
519
+ $this->_cache_reject_reason = 'Page is feed';
520
+
 
 
 
 
 
521
  return false;
522
  }
523
 
538
  if ($engine == 'memcached') {
539
  $engineConfig = array(
540
  'engine' => $this->_config->get_string('pgcache.memcached.engine', 'auto'),
541
+ 'servers' => $this->_config->get_array('pgcache.memcached.servers'),
542
+ 'persistant' => true
543
  );
544
  } else {
545
  $engineConfig = array();
560
  function _check_request_uri()
561
  {
562
  $auto_reject_uri = array(
 
563
  'wp-includes',
564
  'wp-content',
 
 
565
  'robots.txt'
566
  );
567
 
608
  if ($cookie_name == 'wordpress_test_cookie') {
609
  continue;
610
  }
611
+ if (preg_match('/^wp-postpass|^comment_author/', $cookie_name)) {
612
  return false;
613
  }
614
  }
624
  return true;
625
  }
626
 
627
+ /**
628
+ * Check if user is logged in
629
+ *
630
+ * @return boolean
631
+ */
632
+ function _check_logged_in()
633
+ {
634
+ foreach (array_keys($_COOKIE) as $cookie_name) {
635
+ if ($cookie_name == 'wordpress_test_cookie') {
636
+ continue;
637
+ }
638
+ if (strpos($cookie_name, 'wordpress') === 0) {
639
+ return false;
640
+ }
641
+ }
642
+
643
+ return true;
644
+ }
645
+
646
  /**
647
  * Checks gzip availability
648
  *
815
  * Returns debug info
816
  *
817
  * @param boolean $cache
818
+ * @param string $reason
819
  * @param boolean $status
820
  * @param double $time
821
  * @param array $headers
822
  * @return string
823
  */
824
+ function _get_debug_info($cache, $reason, $status, $time, $headers)
825
  {
826
  $debug_info = "<!-- W3 Total Cache: Page cache debug info:\r\n";
827
  $debug_info .= sprintf("%s%s\r\n", str_pad('Engine: ', 20), $this->_config->get_string('pgcache.engine'));
828
  $debug_info .= sprintf("%s%s\r\n", str_pad('Key: ', 20), $this->_page_key);
829
  $debug_info .= sprintf("%s%s\r\n", str_pad('Caching: ', 20), ($cache ? 'enabled' : 'disabled'));
830
+ if (! $cache) {
831
+ $debug_info .= sprintf("%s%s\r\n", str_pad('Reject reason: ', 20), $reason);
832
+ }
833
  $debug_info .= sprintf("%s%s\r\n", str_pad('Status: ', 20), ($status ? 'cached' : 'not cached'));
834
+ $debug_info .= sprintf("%s%.3fs\r\n", str_pad('Creation Time: ', 20), $time);
835
 
836
  if (count($headers)) {
837
  $debug_info .= "Headers info:\r\n";
860
  break;
861
 
862
  case 'gzip':
863
+ $data['content'] = (function_exists('gzdecode') ? gzdecode($data['content']) : w3_gzdecode($data['content']));
864
  $data['content'] .= $content;
865
  $data['content'] = gzencode($data['content']);
866
  break;
lib/W3/Plugin/Cdn.php CHANGED
@@ -91,11 +91,16 @@ class W3_Plugin_Cdn extends W3_Plugin
91
  {
92
  global $wpdb;
93
 
94
- $upload_info = wp_upload_dir();
95
 
96
- if (! empty($upload_info['error'])) {
97
- echo sprintf('<strong>Upload directory error:</strong> %s', $upload_info['error']);
98
- die();
 
 
 
 
 
99
  }
100
 
101
  $sql = sprintf('DROP TABLE IF EXISTS `%s%s`', $wpdb->prefix, W3TC_CDN_TABLE_QUEUE);
@@ -183,7 +188,7 @@ class W3_Plugin_Cdn extends W3_Plugin
183
  $upload_url = $this->get_upload_url();
184
 
185
  if ($upload_url) {
186
- $regexp = '~(["\'])((' . preg_quote($siteurl) . ')?/(' . preg_quote($upload_url) . '[^"\'>]+))~';
187
 
188
  $content = preg_replace_callback($regexp, array(
189
  &$this,
@@ -205,7 +210,7 @@ class W3_Plugin_Cdn extends W3_Plugin
205
  'every_15_min' => array(
206
  'interval' => 900,
207
  'display' => 'Every 15 minutes'
208
- ),
209
  );
210
  }
211
 
@@ -224,7 +229,7 @@ class W3_Plugin_Cdn extends W3_Plugin
224
  } else {
225
  $file = get_post_meta($attachment_id, '_wp_attached_file', true);
226
  $files = array(
227
- $file
228
  );
229
  }
230
 
@@ -249,7 +254,7 @@ class W3_Plugin_Cdn extends W3_Plugin
249
  if ($this->_config->get_boolean('cdn.includes.enable', true)) {
250
  $mask = $this->_config->get_string('cdn.includes.files');
251
  if (! empty($mask)) {
252
- $regexps[] = '~(["\'])((' . preg_quote($siteurl) . ')?/(wp-includes/(' . $this->get_regexp_by_mask($mask) . ')))~';
253
  }
254
  }
255
 
@@ -257,12 +262,12 @@ class W3_Plugin_Cdn extends W3_Plugin
257
  $stylesheet = get_stylesheet();
258
  $mask = $this->_config->get_string('cdn.theme.files');
259
  if (! empty($mask)) {
260
- $regexps[] = '~(["\'])((' . preg_quote($siteurl) . ')?/(wp-content/themes/' . preg_quote($stylesheet) . '/(' . $this->get_regexp_by_mask($mask) . ')))~';
261
  }
262
  }
263
 
264
  if ($this->_config->get_boolean('cdn.minify.enable', true)) {
265
- $regexps[] = '~(["\'])((' . preg_quote($siteurl) . ')?/(' . preg_quote(W3TC_MINIFY_DIR_NAME) . '/include(-footer)?(-nb)?\.(css|js)))~';
266
  }
267
 
268
  if ($this->_config->get_boolean('cdn.custom.enable', true)) {
@@ -272,7 +277,7 @@ class W3_Plugin_Cdn extends W3_Plugin
272
  foreach ($files as $file) {
273
  $files_quoted[] = preg_quote($file);
274
  }
275
- $regexps[] = '~(["\'])((' . preg_quote($siteurl) . ')?/(' . implode('|', $files_quoted) . '))~';
276
  }
277
  }
278
 
@@ -305,11 +310,12 @@ class W3_Plugin_Cdn extends W3_Plugin
305
 
306
  if ($upload_dir && $upload_url) {
307
  if (isset($metadata['file'])) {
308
- $local_file = $upload_dir . '/' . $metadata['file'];
309
- $remote_file = $upload_url . '/' . $metadata['file'];
 
310
  $files[$local_file] = $remote_file;
311
  if (isset($metadata['sizes'])) {
312
- $file_dir = dirname($metadata['file']);
313
  foreach ((array) $metadata['sizes'] as $size) {
314
  if (isset($size['file'])) {
315
  $local_file = $upload_dir . '/' . $file_dir . '/' . $size['file'];
@@ -587,13 +593,16 @@ class W3_Plugin_Cdn extends W3_Plugin
587
  foreach ($posts as $post) {
588
  if (! empty($post->metadata)) {
589
  $metadata = @unserialize($post->metadata);
590
- if (isset($metadata['file'])) {
591
- $files = array_merge($files, $this->get_metadata_files($metadata));
592
- } elseif (! empty($post->file)) {
593
- $local_file = $upload_dir . '/' . $post->file;
594
- $remote_file = $upload_url . '/' . $post->file;
595
- $files[$local_file] = $remote_file;
596
- }
 
 
 
597
  }
598
  }
599
 
@@ -657,21 +666,23 @@ class W3_Plugin_Cdn extends W3_Plugin
657
 
658
  foreach ($posts as $post) {
659
  $matches = null;
 
660
 
661
- if (preg_match_all('~(href|src)=[\'"]?([^\'"<>\s]+)[\'"]?~', $post->post_content, $matches, PREG_SET_ORDER)) {
662
  foreach ($matches as $match) {
663
  $src = $match[2];
664
- $file = ltrim(str_replace($siteurl, '', $src), '/');
665
- $file_dir = date('Y/m');
666
- $file_base = basename($file);
667
- $dst = sprintf('%s/%s/%s', $upload_dir, $file_dir, $file_base);
668
- $dst_path = ABSPATH . $dst;
669
- $dst_url = sprintf('%s/%s/%s/%s', $siteurl, $upload_url, $file_dir, $file_base);
670
- $result = false;
671
- $error = '';
672
- $download_result = null;
673
 
674
  if (preg_match('~(' . $regexp . ')$~', $src)) {
 
 
 
 
 
 
 
 
 
 
675
  if (! file_exists($dst_path)) {
676
  if (w3_is_url($file)) {
677
  if ($import_external) {
@@ -704,17 +715,13 @@ class W3_Plugin_Cdn extends W3_Plugin
704
  if (! is_wp_error($id)) {
705
  require_once ABSPATH . 'wp-admin/includes/image.php';
706
  wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $dst_path));
707
- wp_update_post(array(
708
- 'ID' => $post->ID,
709
- 'post_content' => str_replace($src, $dst_url, $post->post_content)
710
- ));
711
 
 
712
  $result = true;
713
  $error = 'OK';
714
  } else {
715
  $error = 'Unable to insert attachment';
716
  }
717
-
718
  } else {
719
  $error = 'Unable to download file';
720
  }
@@ -722,18 +729,23 @@ class W3_Plugin_Cdn extends W3_Plugin
722
  } else {
723
  $error = 'Destination file already exists';
724
  }
725
- } else {
726
- $error = 'File type is not supported';
 
 
 
 
 
727
  }
728
-
729
- $results[] = array(
730
- 'src' => $src,
731
- 'dst' => $dst,
732
- 'result' => $result,
733
- 'error' => $error
734
- );
735
  }
736
  }
 
 
 
 
 
 
 
737
  }
738
  }
739
  }
@@ -919,7 +931,7 @@ class W3_Plugin_Cdn extends W3_Plugin
919
  {
920
  global $wpdb;
921
  static $queue = null, $domain = null;
922
-
923
  if (in_array($matches[2], $this->replaced_urls)) {
924
  return $matches[0];
925
  }
@@ -1094,9 +1106,9 @@ class W3_Plugin_Cdn extends W3_Plugin
1094
  static $upload_dir = null;
1095
 
1096
  if ($upload_dir === null) {
1097
- $upload_info = wp_upload_dir();
1098
- if (empty($upload_info['error'])) {
1099
- $upload_dir = trim(str_replace(ABSPATH, '', $upload_info['basedir']), '/');
1100
  } else {
1101
  $upload_dir = false;
1102
  }
@@ -1115,10 +1127,10 @@ class W3_Plugin_Cdn extends W3_Plugin
1115
  static $upload_dir = null;
1116
 
1117
  if ($upload_dir === null) {
1118
- $upload_info = wp_upload_dir();
1119
- if (empty($upload_info['error'])) {
1120
  $siteurl = w3_get_site_url();
1121
- $upload_dir = trim(str_replace($siteurl, '', $upload_info['baseurl']), '/');
1122
  } else {
1123
  $upload_dir = false;
1124
  }
@@ -1127,6 +1139,22 @@ class W3_Plugin_Cdn extends W3_Plugin
1127
  return $upload_dir;
1128
  }
1129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1130
  /**
1131
  * Returns CDN object
1132
  *
91
  {
92
  global $wpdb;
93
 
94
+ $upload_info = w3_upload_info();
95
 
96
+ if (! $upload_info) {
97
+ $upload_path = get_option('upload_path');
98
+ $upload_path = trim($upload_path);
99
+ if (empty($upload_path)) {
100
+ $upload_path = WP_CONTENT_DIR . '/uploads';
101
+ }
102
+
103
+ w3_writable_error($upload_path);
104
  }
105
 
106
  $sql = sprintf('DROP TABLE IF EXISTS `%s%s`', $wpdb->prefix, W3TC_CDN_TABLE_QUEUE);
188
  $upload_url = $this->get_upload_url();
189
 
190
  if ($upload_url) {
191
+ $regexp = '~(["\'])((' . preg_quote($siteurl) . ')?/?(' . preg_quote($upload_url) . '[^"\'>]+))~';
192
 
193
  $content = preg_replace_callback($regexp, array(
194
  &$this,
210
  'every_15_min' => array(
211
  'interval' => 900,
212
  'display' => 'Every 15 minutes'
213
+ )
214
  );
215
  }
216
 
229
  } else {
230
  $file = get_post_meta($attachment_id, '_wp_attached_file', true);
231
  $files = array(
232
+ $this->normalize_attachment_file($file)
233
  );
234
  }
235
 
254
  if ($this->_config->get_boolean('cdn.includes.enable', true)) {
255
  $mask = $this->_config->get_string('cdn.includes.files');
256
  if (! empty($mask)) {
257
+ $regexps[] = '~(["\'])((' . preg_quote($siteurl) . ')?/?(wp-includes/(' . $this->get_regexp_by_mask($mask) . ')))~';
258
  }
259
  }
260
 
262
  $stylesheet = get_stylesheet();
263
  $mask = $this->_config->get_string('cdn.theme.files');
264
  if (! empty($mask)) {
265
+ $regexps[] = '~(["\'])((' . preg_quote($siteurl) . ')?/?(wp-content/themes/' . preg_quote($stylesheet) . '/(' . $this->get_regexp_by_mask($mask) . ')))~';
266
  }
267
  }
268
 
269
  if ($this->_config->get_boolean('cdn.minify.enable', true)) {
270
+ $regexps[] = '~(["\'])((' . preg_quote($siteurl) . ')?/?(' . preg_quote(W3TC_MINIFY_DIR_NAME) . '/include(-footer)?(-nb)?\.(css|js)))~';
271
  }
272
 
273
  if ($this->_config->get_boolean('cdn.custom.enable', true)) {
277
  foreach ($files as $file) {
278
  $files_quoted[] = preg_quote($file);
279
  }
280
+ $regexps[] = '~(["\'])((' . preg_quote($siteurl) . ')?/?(' . implode('|', $files_quoted) . '))~';
281
  }
282
  }
283
 
310
 
311
  if ($upload_dir && $upload_url) {
312
  if (isset($metadata['file'])) {
313
+ $file = $this->normalize_attachment_file($metadata['file']);
314
+ $local_file = $upload_dir . '/' . $file;
315
+ $remote_file = $upload_url . '/' . $file;
316
  $files[$local_file] = $remote_file;
317
  if (isset($metadata['sizes'])) {
318
+ $file_dir = dirname($file);
319
  foreach ((array) $metadata['sizes'] as $size) {
320
  if (isset($size['file'])) {
321
  $local_file = $upload_dir . '/' . $file_dir . '/' . $size['file'];
593
  foreach ($posts as $post) {
594
  if (! empty($post->metadata)) {
595
  $metadata = @unserialize($post->metadata);
596
+ } else {
597
+ $metadata = array();
598
+ }
599
+ if (isset($metadata['file'])) {
600
+ $files = array_merge($files, $this->get_metadata_files($metadata));
601
+ } elseif (! empty($post->file)) {
602
+ $file = $this->normalize_attachment_file($post->file);
603
+ $local_file = $upload_dir . '/' . $file;
604
+ $remote_file = $upload_url . '/' . $file;
605
+ $files[$local_file] = $remote_file;
606
  }
607
  }
608
 
666
 
667
  foreach ($posts as $post) {
668
  $matches = null;
669
+ $post_content = $post->post_content;
670
 
671
+ if (preg_match_all('~(href|src)=[\'"]?([^\'"<>\s]+)[\'"]?~', $post_content, $matches, PREG_SET_ORDER)) {
672
  foreach ($matches as $match) {
673
  $src = $match[2];
 
 
 
 
 
 
 
 
 
674
 
675
  if (preg_match('~(' . $regexp . ')$~', $src)) {
676
+ $file = ltrim(str_replace($siteurl, '', $src), '\\/');
677
+ $file_dir = date('Y/m');
678
+ $file_base = basename($file);
679
+ $dst = sprintf('%s/%s/%s', $upload_dir, $file_dir, $file_base);
680
+ $dst_path = ABSPATH . $dst;
681
+ $dst_url = sprintf('%s/%s/%s/%s', $siteurl, $upload_url, $file_dir, $file_base);
682
+ $result = false;
683
+ $error = '';
684
+ $download_result = null;
685
+
686
  if (! file_exists($dst_path)) {
687
  if (w3_is_url($file)) {
688
  if ($import_external) {
715
  if (! is_wp_error($id)) {
716
  require_once ABSPATH . 'wp-admin/includes/image.php';
717
  wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $dst_path));
 
 
 
 
718
 
719
+ $post_content = str_replace($src, $dst_url, $post_content);
720
  $result = true;
721
  $error = 'OK';
722
  } else {
723
  $error = 'Unable to insert attachment';
724
  }
 
725
  } else {
726
  $error = 'Unable to download file';
727
  }
729
  } else {
730
  $error = 'Destination file already exists';
731
  }
732
+
733
+ $results[] = array(
734
+ 'src' => $src,
735
+ 'dst' => $dst,
736
+ 'result' => $result,
737
+ 'error' => $error
738
+ );
739
  }
 
 
 
 
 
 
 
740
  }
741
  }
742
+
743
+ if ($post_content != $post->post_content) {
744
+ wp_update_post(array(
745
+ 'ID' => $post->ID,
746
+ 'post_content' => $post_content
747
+ ));
748
+ }
749
  }
750
  }
751
  }
931
  {
932
  global $wpdb;
933
  static $queue = null, $domain = null;
934
+
935
  if (in_array($matches[2], $this->replaced_urls)) {
936
  return $matches[0];
937
  }
1106
  static $upload_dir = null;
1107
 
1108
  if ($upload_dir === null) {
1109
+ $upload_info = w3_upload_info();
1110
+ if ($upload_info) {
1111
+ $upload_dir = ltrim(str_replace(ABSPATH, '', $upload_info['basedir']), '\\/');
1112
  } else {
1113
  $upload_dir = false;
1114
  }
1127
  static $upload_dir = null;
1128
 
1129
  if ($upload_dir === null) {
1130
+ $upload_info = w3_upload_info();
1131
+ if ($upload_info) {
1132
  $siteurl = w3_get_site_url();
1133
+ $upload_dir = ltrim(str_replace($siteurl, '', $upload_info['baseurl']), '\\/');
1134
  } else {
1135
  $upload_dir = false;
1136
  }
1139
  return $upload_dir;
1140
  }
1141
 
1142
+ /**
1143
+ * Normalizes attachment file
1144
+ *
1145
+ * @param string $file
1146
+ * @return string
1147
+ */
1148
+ function normalize_attachment_file($file)
1149
+ {
1150
+ $upload_info = w3_upload_info();
1151
+ if ($upload_info) {
1152
+ $file = ltrim(str_replace($upload_info['basedir'], '', $file), '\\/');
1153
+ }
1154
+
1155
+ return $file;
1156
+ }
1157
+
1158
  /**
1159
  * Returns CDN object
1160
  *
lib/W3/Plugin/DbCache.php CHANGED
@@ -52,7 +52,7 @@ class W3_Plugin_DbCache extends W3_Plugin
52
  $file_db = WP_CONTENT_DIR . '/db.php';
53
 
54
  if (@copy(W3TC_CONTENT_DIR . '/db.php', $file_db)) {
55
- @chmod($file_db, 0666);
56
  } else {
57
  w3_writable_error($file_db);
58
  }
52
  $file_db = WP_CONTENT_DIR . '/db.php';
53
 
54
  if (@copy(W3TC_CONTENT_DIR . '/db.php', $file_db)) {
55
+ @chmod($file_db, 0644);
56
  } else {
57
  w3_writable_error($file_db);
58
  }
lib/W3/Plugin/Minify.php CHANGED
@@ -62,8 +62,8 @@ class W3_Plugin_Minify extends W3_Plugin
62
  {
63
  if (! $this->locked()) {
64
  if (! is_dir(W3TC_MINIFY_DIR)) {
65
- if (@mkdir(W3TC_MINIFY_DIR, 0777)) {
66
- @chmod(W3TC_MINIFY_DIR, 0777);
67
  } else {
68
  w3_writable_error(W3TC_MINIFY_DIR);
69
  }
@@ -72,7 +72,7 @@ class W3_Plugin_Minify extends W3_Plugin
72
  $file_htaccess = W3TC_MINIFY_DIR . '/.htaccess';
73
 
74
  if (@copy(W3TC_MINIFY_CONTENT_DIR . '/_htaccess', $file_htaccess)) {
75
- @chmod($file_htaccess, 0666);
76
  } else {
77
  w3_writable_error($file_htaccess);
78
  }
@@ -80,7 +80,7 @@ class W3_Plugin_Minify extends W3_Plugin
80
  $file_index = W3TC_MINIFY_DIR . '/index.php';
81
 
82
  if (@copy(W3TC_MINIFY_CONTENT_DIR . '/index.php', $file_index)) {
83
- @chmod($file_index, 0666);
84
  } else {
85
  w3_writable_error($file_index);
86
  }
@@ -131,7 +131,7 @@ class W3_Plugin_Minify extends W3_Plugin
131
  }
132
 
133
  if (! empty($head_prepend)) {
134
- $buffer = preg_replace('~<head[^>]+>~Ui', '\\0' . $head_prepend, $buffer);
135
  }
136
 
137
  $buffer = $this->clean($buffer);
@@ -157,11 +157,11 @@ class W3_Plugin_Minify extends W3_Plugin
157
  */
158
  function clean($content)
159
  {
160
- if ($this->_config->get_boolean('minify.css.enable', true) && $this->_config->get_boolean('minify.css.clean', true)) {
161
  $content = $this->clean_styles($content);
162
  }
163
 
164
- if ($this->_config->get_boolean('minify.js.enable', true) && $this->_config->get_boolean('minify.js.clean', true)) {
165
  $content = $this->clean_scripts($content);
166
  }
167
 
@@ -169,6 +169,8 @@ class W3_Plugin_Minify extends W3_Plugin
169
  $content = $this->minify_html($content);
170
  }
171
 
 
 
172
  return $content;
173
  }
174
 
@@ -180,7 +182,7 @@ class W3_Plugin_Minify extends W3_Plugin
180
  */
181
  function clean_styles($content)
182
  {
183
- $urls = array();
184
 
185
  $groups = $this->_config->get_array('minify.css.groups');
186
  $siteurl = w3_get_site_url();
@@ -189,17 +191,17 @@ class W3_Plugin_Minify extends W3_Plugin
189
  if (isset($config['files'])) {
190
  foreach ((array) $config['files'] as $file) {
191
  if (w3_is_url($file)) {
192
- $urls[] = $file;
193
  } else {
194
- $urls[] = $siteurl . '/' . $file;
195
  }
196
  }
197
  }
198
  }
199
 
200
- foreach ($urls as $url) {
201
- $content = preg_replace('~<link[^<>]*href=["\']?' . preg_quote($url) . '["\']?[^<>]*/?>~is', '', $content);
202
- $content = preg_replace('~@import\s+(url\s*)?[\(]?["\']?\s*' . preg_quote($url) . '\s*["\']?[\)]?\s*;?~is', '', $content);
203
  }
204
 
205
  return $content;
@@ -213,7 +215,7 @@ class W3_Plugin_Minify extends W3_Plugin
213
  */
214
  function clean_scripts($content)
215
  {
216
- $urls = array();
217
 
218
  $groups = $this->_config->get_array('minify.js.groups');
219
  $siteurl = w3_get_site_url();
@@ -222,16 +224,16 @@ class W3_Plugin_Minify extends W3_Plugin
222
  if (isset($config['files'])) {
223
  foreach ((array) $config['files'] as $file) {
224
  if (w3_is_url($file)) {
225
- $urls[] = $file;
226
  } else {
227
- $urls[] = $siteurl . '/' . $file;
228
  }
229
  }
230
  }
231
  }
232
 
233
- foreach ($urls as $url) {
234
- $content = preg_replace('~<script[^<>]*src=["\']?' . preg_quote($url) . '["\']?[^<>]*></script>~is', '', $content);
235
  }
236
 
237
  return $content;
@@ -252,21 +254,33 @@ class W3_Plugin_Minify extends W3_Plugin
252
  require_once 'JSMin.php';
253
 
254
  $options = array(
255
- 'xhtml' => true,
256
- 'cssMinifier' => array(
 
 
 
257
  'Minify_CSS',
258
  'minify'
259
- ),
260
- 'jsMinifier' => array(
 
 
 
261
  'JSMin',
262
  'minify'
263
- )
264
- );
265
 
266
- $content = Minify_HTML::minify($content, $options);
 
 
 
 
267
 
268
- if ($this->_config->get_boolean('minify.html.strip.crlf', false)) {
269
  $content = preg_replace("~[\r\n]+~", ' ', $content);
 
 
270
  }
271
 
272
  return $content;
62
  {
63
  if (! $this->locked()) {
64
  if (! is_dir(W3TC_MINIFY_DIR)) {
65
+ if (@mkdir(W3TC_MINIFY_DIR, 0755)) {
66
+ @chmod(W3TC_MINIFY_DIR, 0755);
67
  } else {
68
  w3_writable_error(W3TC_MINIFY_DIR);
69
  }
72
  $file_htaccess = W3TC_MINIFY_DIR . '/.htaccess';
73
 
74
  if (@copy(W3TC_MINIFY_CONTENT_DIR . '/_htaccess', $file_htaccess)) {
75
+ @chmod($file_htaccess, 0644);
76
  } else {
77
  w3_writable_error($file_htaccess);
78
  }
80
  $file_index = W3TC_MINIFY_DIR . '/index.php';
81
 
82
  if (@copy(W3TC_MINIFY_CONTENT_DIR . '/index.php', $file_index)) {
83
+ @chmod($file_index, 0644);
84
  } else {
85
  w3_writable_error($file_index);
86
  }
131
  }
132
 
133
  if (! empty($head_prepend)) {
134
+ $buffer = preg_replace('~<head[^>]*>~Ui', '\\0' . $head_prepend, $buffer);
135
  }
136
 
137
  $buffer = $this->clean($buffer);
157
  */
158
  function clean($content)
159
  {
160
+ if ($this->_config->get_boolean('minify.css.enable', true)) {
161
  $content = $this->clean_styles($content);
162
  }
163
 
164
+ if ($this->_config->get_boolean('minify.js.enable', true)) {
165
  $content = $this->clean_scripts($content);
166
  }
167
 
169
  $content = $this->minify_html($content);
170
  }
171
 
172
+ $content = preg_replace('~<style[^<>]*>\s*</style>~', '', $content);
173
+
174
  return $content;
175
  }
176
 
182
  */
183
  function clean_styles($content)
184
  {
185
+ $regexps = array();
186
 
187
  $groups = $this->_config->get_array('minify.css.groups');
188
  $siteurl = w3_get_site_url();
191
  if (isset($config['files'])) {
192
  foreach ((array) $config['files'] as $file) {
193
  if (w3_is_url($file)) {
194
+ $regexps[] = preg_quote($file);
195
  } else {
196
+ $regexps[] = '(' . preg_quote($siteurl) . ')?/?' . preg_quote($file);
197
  }
198
  }
199
  }
200
  }
201
 
202
+ foreach ($regexps as $regexp) {
203
+ $content = preg_replace('~<link\s+[^<>]*href=["\']?' . $regexp . '["\']?[^<>]*/?>~is', '', $content);
204
+ $content = preg_replace('~@import\s+(url\s*)?\(?["\']?\s*' . $regexp . '\s*["\']?\)?[^;]*;?~is', '', $content);
205
  }
206
 
207
  return $content;
215
  */
216
  function clean_scripts($content)
217
  {
218
+ $regexps = array();
219
 
220
  $groups = $this->_config->get_array('minify.js.groups');
221
  $siteurl = w3_get_site_url();
224
  if (isset($config['files'])) {
225
  foreach ((array) $config['files'] as $file) {
226
  if (w3_is_url($file)) {
227
+ $regexps[] = preg_quote($file);
228
  } else {
229
+ $regexps[] = '(' . preg_quote($siteurl) . ')?/?' . preg_quote($file);
230
  }
231
  }
232
  }
233
  }
234
 
235
+ foreach ($regexps as $regexp) {
236
+ $content = preg_replace('~<script\s+[^<>]*src=["\']?' . $regexp . '["\']?[^<>]*></script>~is', '', $content);
237
  }
238
 
239
  return $content;
254
  require_once 'JSMin.php';
255
 
256
  $options = array(
257
+ 'xhtml' => true
258
+ );
259
+
260
+ if ($this->_config->get_boolean('minify.css.enable', true)) {
261
+ $options['cssMinifier'] = array(
262
  'Minify_CSS',
263
  'minify'
264
+ );
265
+ }
266
+
267
+ if ($this->_config->get_boolean('minify.js.enable', true)) {
268
+ $options['jsMinifier'] = array(
269
  'JSMin',
270
  'minify'
271
+ );
272
+ }
273
 
274
+ try {
275
+ $content = Minify_HTML::minify($content, $options);
276
+ } catch (Exception $exception) {
277
+ return sprintf('<strong>W3 Total Cache Error:</strong> Minify error: %s', $exception->getMessage());
278
+ }
279
 
280
+ if ($this->_config->get_boolean('minify.html.strip.crlf')) {
281
  $content = preg_replace("~[\r\n]+~", ' ', $content);
282
+ } else {
283
+ $content = preg_replace("~[\r\n]+~", "\n", $content);
284
  }
285
 
286
  return $content;
lib/W3/Plugin/PgCache.php CHANGED
@@ -28,12 +28,12 @@ class W3_Plugin_PgCache extends W3_Plugin
28
  if ($this->_config->get_boolean('pgcache.enabled')) {
29
  add_action('publish_phone', array(
30
  &$this,
31
- 'on_post_change'
32
  ));
33
 
34
  add_action('publish_post', array(
35
  &$this,
36
- 'on_post_change'
37
  ));
38
 
39
  add_action('edit_post', array(
@@ -43,7 +43,7 @@ class W3_Plugin_PgCache extends W3_Plugin
43
 
44
  add_action('delete_post', array(
45
  &$this,
46
- 'on_post_change'
47
  ));
48
 
49
  add_action('comment_post', array(
@@ -116,7 +116,7 @@ class W3_Plugin_PgCache extends W3_Plugin
116
 
117
  if (! $this->locked()) {
118
  if (@copy(W3TC_CONTENT_DIR . '/advanced-cache.php', WP_CONTENT_DIR . '/advanced-cache.php')) {
119
- @chmod(WP_CONTENT_DIR . '/advanced-cache.php', 0666);
120
  } else {
121
  w3_writable_error(WP_CONTENT_DIR . '/advanced-cache.php');
122
  }
@@ -171,7 +171,7 @@ class W3_Plugin_PgCache extends W3_Plugin
171
  */
172
  function on_post_edit($post_id)
173
  {
174
- if ($this->_config->get_boolean('pgcache.cache.flush', false)) {
175
  $this->on_change();
176
  } else {
177
  $this->on_post_change($post_id);
28
  if ($this->_config->get_boolean('pgcache.enabled')) {
29
  add_action('publish_phone', array(
30
  &$this,
31
+ 'on_post_edit'
32
  ));
33
 
34
  add_action('publish_post', array(
35
  &$this,
36
+ 'on_post_edit'
37
  ));
38
 
39
  add_action('edit_post', array(
43
 
44
  add_action('delete_post', array(
45
  &$this,
46
+ 'on_post_edit'
47
  ));
48
 
49
  add_action('comment_post', array(
116
 
117
  if (! $this->locked()) {
118
  if (@copy(W3TC_CONTENT_DIR . '/advanced-cache.php', WP_CONTENT_DIR . '/advanced-cache.php')) {
119
+ @chmod(WP_CONTENT_DIR . '/advanced-cache.php', 0644);
120
  } else {
121
  w3_writable_error(WP_CONTENT_DIR . '/advanced-cache.php');
122
  }
171
  */
172
  function on_post_edit($post_id)
173
  {
174
+ if ($this->_config->get_boolean('pgcache.cache.flush')) {
175
  $this->on_change();
176
  } else {
177
  $this->on_post_change($post_id);
lib/W3/Plugin/TotalCache.php CHANGED
@@ -47,7 +47,12 @@ class W3_Plugin_TotalCache extends W3_Plugin
47
  'favorite_actions'
48
  ));
49
 
50
- if ($this->_config->get_boolean('common.support', true) && $this->_config->get_string('common.support.type', 'footer') == 'footer') {
 
 
 
 
 
51
  add_action('wp_footer', array(
52
  &$this,
53
  'footer'
@@ -121,7 +126,7 @@ class W3_Plugin_TotalCache extends W3_Plugin
121
  {
122
  if (! file_exists(W3TC_CONFIG_PATH)) {
123
  if (@copy(W3TC_CONFIG_DEFAULT_PATH, W3TC_CONFIG_PATH)) {
124
- @chmod(W3TC_CONFIG_PATH, 0666);
125
  } else {
126
  w3_writable_error(W3TC_CONFIG_PATH);
127
  }
@@ -178,7 +183,7 @@ class W3_Plugin_TotalCache extends W3_Plugin
178
  */
179
  function plugin_action_links($links)
180
  {
181
- $links[] = '<a class="edit" href="options-general.php?page=' . W3TC_FILE . '">Settings</a>';
182
 
183
  return $links;
184
  }
@@ -196,6 +201,36 @@ class W3_Plugin_TotalCache extends W3_Plugin
196
  return $actions;
197
  }
198
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  /**
200
  * Footer plugin action
201
  */
@@ -236,98 +271,7 @@ class W3_Plugin_TotalCache extends W3_Plugin
236
  * Save config
237
  */
238
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
239
- $keys = array(
240
- 'dbcache.enabled' => 'boolean',
241
- 'dbcache.debug' => 'boolean',
242
- 'dbcache.engine' => 'string',
243
- 'dbcache.memcached.engine' => 'string',
244
- 'dbcache.memcached.servers' => 'array',
245
- 'dbcache.reject.admin' => 'boolean',
246
- 'dbcache.reject.uri' => 'array',
247
- 'dbcache.reject.sql' => 'array',
248
- 'dbcache.lifetime.default' => 'integer',
249
- 'dbcache.lifetime.options' => 'integer',
250
- 'dbcache.lifetime.links' => 'integer',
251
- 'dbcache.lifetime.terms' => 'integer',
252
- 'dbcache.lifetime.user' => 'integer',
253
- 'dbcache.lifetime.post' => 'integer',
254
-
255
- 'pgcache.enabled' => 'boolean',
256
- 'pgcache.debug' => 'boolean',
257
- 'pgcache.engine' => 'string',
258
- 'pgcache.memcached.engine' => 'string',
259
- 'pgcache.memcached.servers' => 'array',
260
- 'pgcache.lifetime' => 'integer',
261
- 'pgcache.compress' => 'boolean',
262
- 'pgcache.cache.logged' => 'boolean',
263
- 'pgcache.cache.query' => 'boolean',
264
- 'pgcache.cache.home' => 'boolean',
265
- 'pgcache.cache.feed' => 'boolean',
266
- 'pgcache.cache.404' => 'boolean',
267
- 'pgcache.cache.flush' => 'boolean',
268
- 'pgcache.cache.headers' => 'array',
269
- 'pgcache.accept.files' => 'array',
270
- 'pgcache.reject.uri' => 'array',
271
- 'pgcache.reject.ua' => 'array',
272
- 'pgcache.reject.cookie' => 'array',
273
- 'pgcache.mobile.check' => 'boolean',
274
- 'pgcache.mobile.whitelist' => 'array',
275
- 'pgcache.mobile.browsers' => 'array',
276
-
277
- 'minify.enabled' => 'boolean',
278
- 'minify.debug' => 'boolean',
279
- 'minify.engine' => 'string',
280
- 'minify.memcached.engine' => 'string',
281
- 'minify.memcached.servers' => 'array',
282
- 'minify.rewrite' => 'boolean',
283
- 'minify.logger' => 'boolean',
284
- 'minify.cache.path' => 'string',
285
- 'minify.cache.locking' => 'string',
286
- 'minify.docroot' => 'string',
287
- 'minify.fixtime' => 'integer',
288
- 'minify.compress' => 'boolean',
289
- 'minify.compress.ie6' => 'boolean',
290
- 'minify.options' => 'array',
291
- 'minify.symlinks' => 'array',
292
- 'minify.lifetime' => 'integer',
293
- 'minify.html.enable' => 'boolean',
294
- 'minify.html.strip.crlf' => 'boolean',
295
- 'minify.html.reject.admin' => 'boolean',
296
- 'minify.css.enable' => 'boolean',
297
- 'minify.css.strip.comments' => 'boolean',
298
- 'minify.css.strip.crlf' => 'boolean',
299
- 'minify.css.clean' => 'boolean',
300
- 'minify.css.groups' => 'array',
301
- 'minify.js.enable' => 'boolean',
302
- 'minify.js.strip.comments' => 'boolean',
303
- 'minify.js.strip.crlf' => 'boolean',
304
- 'minify.js.clean' => 'boolean',
305
- 'minify.js.groups' => 'array',
306
-
307
- 'cdn.enabled' => 'boolean',
308
- 'cdn.engine' => 'string',
309
- 'cdn.domain' => 'string',
310
- 'cdn.includes.enable' => 'boolean',
311
- 'cdn.includes.files' => 'string',
312
- 'cdn.theme.enable' => 'boolean',
313
- 'cdn.theme.files' => 'string',
314
- 'cdn.minify.enable' => 'boolean',
315
- 'cdn.custom.enable' => 'boolean',
316
- 'cdn.custom.files' => 'array',
317
- 'cdn.import.external' => 'boolean',
318
- 'cdn.import.files' => 'string',
319
- 'cdn.limit.queue' => 'integer',
320
- 'cdn.ftp.host' => 'string',
321
- 'cdn.ftp.user' => 'string',
322
- 'cdn.ftp.pass' => 'string',
323
- 'cdn.ftp.path' => 'string',
324
- 'cdn.ftp.pasv' => 'boolean',
325
-
326
- 'common.support' => 'boolean',
327
- 'common.support.type' => 'string'
328
- );
329
-
330
- $config->read_request($keys);
331
 
332
  if ($tab == 'minify') {
333
  $css_files_header = W3_Request::get_array('css_files_include');
@@ -407,72 +351,118 @@ class W3_Plugin_TotalCache extends W3_Plugin
407
  $config->set('cdn.debug', $debug);
408
  }
409
 
410
- $config->set('common.defaults', false);
411
-
412
  if ($config->save()) {
413
- $notes[] = 'Plugin configuration updated successfully.';
414
- } else {
415
- $errors[] = 'Unable to save plugin configuration: config file is not writeable.';
416
- }
417
-
418
- if ($config->get_boolean('common.support', true) && $config->get_string('common.support.type', 'footer') == 'blogroll') {
419
- $this->link_insert();
420
- } else {
421
  $this->link_delete();
 
 
 
 
 
 
 
 
422
  }
423
  }
424
 
 
 
 
425
  if (isset($_REQUEST['flush_all'])) {
426
  $this->flush_all();
427
- $notes[] = 'All caches emptied successfully.';
428
  }
429
 
 
 
 
430
  if (isset($_REQUEST['flush_memcached'])) {
431
  $this->flush_memcached();
432
- $notes[] = 'Memcached cache emptied successfully.';
433
  }
434
 
 
 
 
435
  if (isset($_REQUEST['flush_apc'])) {
436
  $this->flush_apc();
437
- $notes[] = 'APC cache emptied successfully.';
438
  }
439
 
 
 
 
440
  if (isset($_REQUEST['flush_file'])) {
441
  $this->flush_file();
442
- $notes[] = 'Disk cache emptied successfully.';
 
 
 
 
 
 
 
 
 
 
443
  }
444
 
445
  /**
446
  * Do some checks
447
  */
 
 
 
448
 
449
- $check_memcache = $this->check_memcache();
450
- $check_apc = $this->check_apc();
 
 
 
 
 
 
 
 
451
 
452
- if (! $check_memcache && ! $check_apc) {
453
- $errors[] = '<strong>Memcached</strong> nor <strong>APC</strong> appear to be installed correctly.';
 
 
 
 
 
 
 
 
 
454
  }
455
 
456
- if ($config->get_boolean('dbcache.enabled') && ! $this->check_db()) {
457
- $errors[] = '<strong>Database caching</strong> is not available. <strong>db.php</strong> is not installed. Either the wp-content directory is not write-able or you have another caching plugin installed.';
 
 
 
 
 
 
458
  }
459
 
 
 
 
460
  if ($config->get_boolean('pgcache.enabled')) {
461
  if (! $this->check_advanced_cache()) {
462
- $errors[] = '<strong>Page caching</strong> is not available. <strong>advanced-cache.php</strong> is not installed. Either the <strong>wp-content</strong> directory is not write-able or you have another caching plugin installed.';
463
  } elseif (! defined('WP_CACHE')) {
464
  $errors[] = '<strong>Page caching</strong> is not available. <strong>WP_CACHE</strong> constant is not defined in wp-config.php.';
465
  }
466
  }
467
 
468
- if ($config->get_boolean('common.defaults', true)) {
469
- $notes[] = 'The plugin is in quick setup mode, our recommended defaults are set. Simply satisfy all warnings and enable the plugin to get started or customize all of the settings you wish.';
470
-
471
- if ($tab == 'cdn') {
472
- $notes[] = '<strong>It appears this is the first time you are using this feature. Unless you wish to first import attachments in your posts that are not already in the media library, please start a "manual export to <acronym title="Content Delivery Network">CDN</acronym>" and only enable this module after pending attachments have been successfully uploaded.</strong>';
473
- }
474
- } elseif ($tab == 'cdn' && $config->get('cdn.enabled') && $config->get('cdn.domain') == '') {
475
- $errors[] = 'The "Replace domain in URL with" field must be populated. Enter the hostname of your <acronym title="Content Delivery Network">CDN</acronym> provider. <em>This is the hostname you would enter into your address bar in order to view objects in your browser.</em>';
476
  }
477
 
478
  /**
@@ -750,26 +740,66 @@ class W3_Plugin_TotalCache extends W3_Plugin
750
  }
751
 
752
  /**
753
- * Insert plugin link into Blogroll
754
  */
755
- function link_insert()
756
  {
757
- $bookmarks = get_bookmarks();
758
- $exists = false;
759
- foreach ($bookmarks as $bookmark) {
760
- if ($bookmark->link_url == W3TC_LINK_URL) {
761
- $exists = true;
762
- break;
763
- }
 
 
 
 
 
 
 
 
 
 
 
 
764
  }
765
 
766
- if (! $exists) {
767
- require_once ABSPATH . 'wp-admin/includes/bookmark.php';
768
- wp_insert_link(array(
769
- 'link_url' => W3TC_LINK_URL,
770
- 'link_name' => W3TC_LINK_NAME
771
- ));
 
 
 
 
 
 
 
 
 
772
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
773
  }
774
 
775
  /**
@@ -908,10 +938,9 @@ class W3_Plugin_TotalCache extends W3_Plugin
908
 
909
  $host = gethostbyaddr($_SERVER['SERVER_ADDR']);
910
  $date = date('Y-m-d H:i:s');
911
- $time = timer_stop();
912
 
913
- if ($this->_config->get_boolean('common.support')) {
914
- $buffer .= sprintf("\r\n<!-- Served from: %s @ %s in %.3f seconds by W3 Total Cache -->", $host, $date, $time);
915
  } else {
916
  $buffer .= <<<DATA
917
  <!--
@@ -942,7 +971,7 @@ DATA;
942
  $buffer .= sprintf("Content Delivery Network via %s\r\n", $this->_config->get_string('cdn.domain', 'N/A'));
943
  }
944
 
945
- $buffer .= sprintf("\r\nServed from: %s @ %s in %.3f seconds -->", $host, $date, $time);
946
  }
947
 
948
  if ($this->_config->get_boolean('dbcache.enabled', true) && $this->_config->get_boolean('dbcache.debug') && is_a($wpdb, 'W3_Db')) {
47
  'favorite_actions'
48
  ));
49
 
50
+ add_action('admin_notices', array(
51
+ &$this,
52
+ 'admin_notices'
53
+ ));
54
+
55
+ if ($this->_config->get_boolean('common.support.enabled', true) && $this->_config->get_string('common.support.type', 'footer') == 'footer') {
56
  add_action('wp_footer', array(
57
  &$this,
58
  'footer'
126
  {
127
  if (! file_exists(W3TC_CONFIG_PATH)) {
128
  if (@copy(W3TC_CONFIG_DEFAULT_PATH, W3TC_CONFIG_PATH)) {
129
+ @chmod(W3TC_CONFIG_PATH, 0644);
130
  } else {
131
  w3_writable_error(W3TC_CONFIG_PATH);
132
  }
183
  */
184
  function plugin_action_links($links)
185
  {
186
+ array_unshift($links, '<a class="edit" href="options-general.php?page=' . W3TC_FILE . '">Settings</a>');
187
 
188
  return $links;
189
  }
201
  return $actions;
202
  }
203
 
204
+ /**
205
+ * Admin notices action
206
+ */
207
+ function admin_notices()
208
+ {
209
+ $notices = array(
210
+ 1 => 'All caches emptied successfully.',
211
+ 2 => 'Memcached cache emptied successfully.',
212
+ 3 => 'APC cache emptied successfully.',
213
+ 4 => 'Disk cache emptied successfully.',
214
+ 5 => 'Plugin configuration updated successfully.'
215
+ );
216
+
217
+ $errors = array(
218
+ 1 => 'Unable to save plugin configuration: config file is not writeable.'
219
+ );
220
+
221
+ require_once W3TC_LIB_W3_DIR . '/Request.php';
222
+ $notice_id = W3_Request::get_integer('w3tc_notice_id');
223
+ $error_id = W3_Request::get_integer('w3tc_error_id');
224
+
225
+ if (! empty($notice_id) && isset($notices[$notice_id])) {
226
+ echo sprintf('<div id="message" class="updated fade"><p>%s</p></div>', $notices[$notice_id]);
227
+ }
228
+
229
+ if (! empty($error_id) && isset($errors[$error_id])) {
230
+ echo sprintf('<div id="message" class="error"><p>%s</p></div>', $errors[$error_id]);
231
+ }
232
+ }
233
+
234
  /**
235
  * Footer plugin action
236
  */
271
  * Save config
272
  */
273
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
274
+ $config->read_request();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
 
276
  if ($tab == 'minify') {
277
  $css_files_header = W3_Request::get_array('css_files_include');
351
  $config->set('cdn.debug', $debug);
352
  }
353
 
 
 
354
  if ($config->save()) {
 
 
 
 
 
 
 
 
355
  $this->link_delete();
356
+
357
+ if ($config->get_boolean('common.support.enabled', true) && ($link_category_id = $this->link_get_category_id($config->get_string('common.support.type', 'footer')))) {
358
+ $this->link_insert($link_category_id);
359
+ }
360
+
361
+ w3_redirect('', 'w3tc_notice_id=5');
362
+ } else {
363
+ w3_redirect('', 'w3tc_error_id=1');
364
  }
365
  }
366
 
367
+ /**
368
+ * Flush all caches
369
+ */
370
  if (isset($_REQUEST['flush_all'])) {
371
  $this->flush_all();
372
+ w3_redirect('', 'w3tc_notice_id=1');
373
  }
374
 
375
+ /**
376
+ * Flush memcached cache
377
+ */
378
  if (isset($_REQUEST['flush_memcached'])) {
379
  $this->flush_memcached();
380
+ w3_redirect('', 'w3tc_notice_id=2');
381
  }
382
 
383
+ /**
384
+ * Flush APC cache
385
+ */
386
  if (isset($_REQUEST['flush_apc'])) {
387
  $this->flush_apc();
388
+ w3_redirect('', 'w3tc_notice_id=3');
389
  }
390
 
391
+ /**
392
+ * Flish disk cache
393
+ */
394
  if (isset($_REQUEST['flush_file'])) {
395
  $this->flush_file();
396
+ w3_redirect('', 'w3tc_notice_id=4');
397
+ }
398
+
399
+ /**
400
+ * Hide notes
401
+ */
402
+ if (isset($_REQUEST['hide_note'])) {
403
+ $setting = sprintf('notes.%s', W3_Request::get_string('hide_note'));
404
+ $config->set($setting, false);
405
+ $config->save();
406
+ w3_redirect();
407
  }
408
 
409
  /**
410
  * Do some checks
411
  */
412
+ if ($config->get_boolean('notes.defaults', true)) {
413
+ $notes[] = 'The plugin is in quick setup mode, our recommended defaults are set. Simply satisfy all warnings and enable the plugin to get started or customize all of the settings you wish. <a href="options-general.php?page=' . W3TC_FILE . '&hide_note=defaults">Hide this message</a>';
414
+ }
415
 
416
+ /**
417
+ * Check wp-content permissions
418
+ */
419
+ if ($config->get_boolean('notes.wp_content_perms', true)) {
420
+ $wp_content_stat = stat(WP_CONTENT_DIR);
421
+ $wp_content_mode = ($wp_content_stat['mode'] & 0777);
422
+ if ($wp_content_mode != 0755) {
423
+ $notes[] = '<strong>' . WP_CONTENT_DIR . '</strong> is <strong>writeable</strong>! You should change the permissions and make it more restrictive. Use your ftp client, or the following command to fix things: <strong>chmod 755 ' . WP_CONTENT_DIR . '</strong>. <a href="options-general.php?page=' . W3TC_FILE . '&hide_note=wp_content_perms">Hide this message</a>';
424
+ }
425
+ }
426
 
427
+ /**
428
+ * CDN checks
429
+ */
430
+ if ($tab == 'cdn') {
431
+ if ($config->get('notes.cdn_first_time', true)) {
432
+ $notes[] = 'It appears this is the first time you are using CDN feature. Unless you wish to first import attachments in your posts that are not already in the media library, please start a <strong>"manual export to <acronym title="Content Delivery Network">CDN</acronym>"</strong> and only enable this module after pending attachments have been successfully uploaded. <a href="options-general.php?page=' . W3TC_FILE . '&hide_note=cdn_first_time">Hide this message</a>';
433
+ }
434
+
435
+ if ($config->get('cdn.enabled') && $config->get('cdn.domain') == '') {
436
+ $errors[] = 'The <strong>"Replace domain in URL with"</strong> field must be populated. Enter the hostname of your <acronym title="Content Delivery Network">CDN</acronym> provider. <em>This is the hostname you would enter into your address bar in order to view objects in your browser.</em>';
437
+ }
438
  }
439
 
440
+ /**
441
+ * Check for memcached & APC
442
+ */
443
+ $check_memcache = $this->check_memcache();
444
+ $check_apc = $this->check_apc();
445
+
446
+ if (! $check_memcache && ! $check_apc && $config->get_boolean('notes.no_memcached_nor_apc', true)) {
447
+ $notes[] = '<strong>Memcached</strong> nor <strong>APC</strong> appear to be installed correctly. <a href="options-general.php?page=' . W3TC_FILE . '&hide_note=no_memcached_nor_apc">Hide this message</a>';
448
  }
449
 
450
+ /**
451
+ * Check for PgCache availability
452
+ */
453
  if ($config->get_boolean('pgcache.enabled')) {
454
  if (! $this->check_advanced_cache()) {
455
+ $errors[] = '<strong>Page caching</strong> is not available. <strong>advanced-cache.php</strong> is not installed. Either the <strong>' . WP_CONTENT_DIR . '</strong> directory is not write-able or you have another caching plugin installed.';
456
  } elseif (! defined('WP_CACHE')) {
457
  $errors[] = '<strong>Page caching</strong> is not available. <strong>WP_CACHE</strong> constant is not defined in wp-config.php.';
458
  }
459
  }
460
 
461
+ /**
462
+ * Check for DbCache availability
463
+ */
464
+ if ($config->get_boolean('dbcache.enabled') && ! $this->check_db()) {
465
+ $errors[] = '<strong>Database caching</strong> is not available. <strong>db.php</strong> is not installed. Either the <strong>' . WP_CONTENT_DIR . '</strong> directory is not write-able or you have another caching plugin installed.';
 
 
 
466
  }
467
 
468
  /**
740
  }
741
 
742
  /**
743
+ * Test memcached
744
  */
745
+ function test_memcached()
746
  {
747
+ require_once W3TC_LIB_W3_DIR . '/Request.php';
748
+ require_once W3TC_LIB_W3_DIR . '/Cache/Memcached.php';
749
+
750
+ $servers = W3_Request::get_string('servers');
751
+ $test_string = sprintf('test_' . md5(time()));
752
+
753
+ $memcached = W3_Cache_Memcached::instance(W3_CACHE_MEMCACHED_AUTO, array(
754
+ 'servers' => $servers,
755
+ 'persistant' => false
756
+ ));
757
+
758
+ $memcached->set($test_string, $test_string);
759
+
760
+ if ($memcached->get($test_string) == $test_string) {
761
+ $result = true;
762
+ $error = 'Test passed';
763
+ } else {
764
+ $result = false;
765
+ $error = 'Test failed';
766
  }
767
 
768
+ echo sprintf('{result: %d, error: "%s"}', $result, addslashes($error));
769
+ }
770
+
771
+ /**
772
+ * Returns link category ID
773
+ *
774
+ * @param string $support_type
775
+ * @return integer
776
+ */
777
+ function link_get_category_id($support_type)
778
+ {
779
+ $matches = null;
780
+
781
+ if (preg_match('~^link_category_(\d+)$~', $support_type, $matches)) {
782
+ return $matches[1];
783
  }
784
+
785
+ return false;
786
+ }
787
+
788
+ /**
789
+ * Insert plugin link into Blogroll
790
+ *
791
+ * @param integer $link_category_id
792
+ */
793
+ function link_insert($link_category_id)
794
+ {
795
+ require_once ABSPATH . 'wp-admin/includes/bookmark.php';
796
+ wp_insert_link(array(
797
+ 'link_url' => W3TC_LINK_URL,
798
+ 'link_name' => W3TC_LINK_NAME,
799
+ 'link_category' => array(
800
+ $link_category_id
801
+ )
802
+ ));
803
  }
804
 
805
  /**
938
 
939
  $host = gethostbyaddr($_SERVER['SERVER_ADDR']);
940
  $date = date('Y-m-d H:i:s');
 
941
 
942
+ if ($this->_config->get_boolean('common.support.enabled')) {
943
+ $buffer .= sprintf("\r\n<!-- Served from: %s @ %s by W3 Total Cache -->", $host, $date);
944
  } else {
945
  $buffer .= <<<DATA
946
  <!--
971
  $buffer .= sprintf("Content Delivery Network via %s\r\n", $this->_config->get_string('cdn.domain', 'N/A'));
972
  }
973
 
974
+ $buffer .= sprintf("\r\nServed from: %s @ %s -->", $host, $date);
975
  }
976
 
977
  if ($this->_config->get_boolean('dbcache.enabled', true) && $this->_config->get_boolean('dbcache.debug') && is_a($wpdb, 'W3_Db')) {
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: fredericktownes
3
  Tags: user experience, cache, caching, page cache, css cache, js cache, db cache, database cache, http compression, gzip, deflate, minify, CDN, content delivery network, media library, wp cache, wp super cache, w3 total cache, performance, speed
4
  Requires at least: 2.5
5
  Tested up to: 2.8.4
6
- Stable tag: 0.7.5
7
 
8
  Dramatically improve the user experience of your blog. Add page caching, database caching, minify and content delivery network functionality and more to WordPress.
9
 
@@ -112,6 +112,20 @@ Install the plugin to read the full FAQ.
112
 
113
  == Changelog ==
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  = 0.7.5 =
116
  * Fixed issue with auto-download/upgrade and additional error checking
117
  * Improved handling of inline comments and JavaScript in HTML documents
@@ -140,4 +154,4 @@ Install the plugin to read the full FAQ.
140
  * Improved cache stability for large objects
141
 
142
  = 0.5 =
143
- * Initial release.
3
  Tags: user experience, cache, caching, page cache, css cache, js cache, db cache, database cache, http compression, gzip, deflate, minify, CDN, content delivery network, media library, wp cache, wp super cache, w3 total cache, performance, speed
4
  Requires at least: 2.5
5
  Tested up to: 2.8.4
6
+ Stable tag: 0.7.5.1
7
 
8
  Dramatically improve the user experience of your blog. Add page caching, database caching, minify and content delivery network functionality and more to WordPress.
9
 
112
 
113
  == Changelog ==
114
 
115
+ = 0.7.5.1 =
116
+ * Resolved a bug in the minify library preventing proper permission notification messages
117
+ * Improved notification handling
118
+ * Fixed bug with database cache that caused comment counts to become out of date
119
+ * Added memcached test button for convenience
120
+ * Fixed minor issue with URI with CDN functionality enabled
121
+ * Removed unnecessary minify options
122
+ * Improved reliability of Media Library Export
123
+ * Minification error now dialogs disabled when JS or CSS minify settings disabled
124
+ * Normalized line endings with /n as per minify author's direction
125
+ * Added option to concatenate any script to header or footer with non-blocking options for scripts that cannot be minified (e.g. obfuscated scripts)
126
+ * Improved compatibility with suPHP
127
+ * Added options to concatenate JS files only in header or footer (for use with obfuscated scripts)
128
+
129
  = 0.7.5 =
130
  * Fixed issue with auto-download/upgrade and additional error checking
131
  * Improved handling of inline comments and JavaScript in HTML documents
154
  * Improved cache stability for large objects
155
 
156
  = 0.5 =
157
+ * Initial release
w3-total-cache-config-default.php CHANGED
@@ -16,13 +16,9 @@ return array(
16
  ),
17
  'dbcache.reject.admin' => false,
18
  'dbcache.reject.uri' => array(),
 
19
  'dbcache.reject.sql' => array(),
20
- 'dbcache.lifetime.default' => 180,
21
- 'dbcache.lifetime.options' => 180,
22
- 'dbcache.lifetime.links' => 10800,
23
- 'dbcache.lifetime.terms' => 10800,
24
- 'dbcache.lifetime.user' => 1800,
25
- 'dbcache.lifetime.post' => 3600,
26
 
27
  /**
28
  * PgCache configuration
@@ -41,7 +37,7 @@ return array(
41
  'pgcache.cache.home' => true,
42
  'pgcache.cache.feed' => true,
43
  'pgcache.cache.404' => true,
44
- 'pgcache.cache.flush' => true,
45
  'pgcache.cache.headers' => array(
46
  'Last-Modified',
47
  'Expires',
@@ -104,7 +100,6 @@ return array(
104
  'minify.html.reject.admin' => true,
105
  'minify.html.strip.crlf' => false,
106
  'minify.css.enable' => true,
107
- 'minify.css.clean' => true,
108
  'minify.css.strip.comments' => false,
109
  'minify.css.strip.crlf' => false,
110
  'minify.css.groups' => array(
@@ -115,7 +110,8 @@ return array(
115
  )
116
  ),
117
  'minify.js.enable' => true,
118
- 'minify.js.clean' => true,
 
119
  'minify.js.strip.comments' => false,
120
  'minify.js.strip.crlf' => false,
121
  'minify.js.groups' => array(),
@@ -123,7 +119,7 @@ return array(
123
  /**
124
  * CDN configuration
125
  */
126
- 'cdn.enabled' => false,
127
  'cdn.debug' => false,
128
  'cdn.engine' => 'ftp',
129
  'cdn.domain' => '',
@@ -148,7 +144,14 @@ return array(
148
  /**
149
  * Common configuration
150
  */
151
- 'common.defaults' => true,
152
- 'common.support' => true,
153
- 'common.support.type' => 'footer'
 
 
 
 
 
 
 
154
  );
16
  ),
17
  'dbcache.reject.admin' => false,
18
  'dbcache.reject.uri' => array(),
19
+ 'dbcache.reject.cookie' => array(),
20
  'dbcache.reject.sql' => array(),
21
+ 'dbcache.lifetime' => 180,
 
 
 
 
 
22
 
23
  /**
24
  * PgCache configuration
37
  'pgcache.cache.home' => true,
38
  'pgcache.cache.feed' => true,
39
  'pgcache.cache.404' => true,
40
+ 'pgcache.cache.flush' => false,
41
  'pgcache.cache.headers' => array(
42
  'Last-Modified',
43
  'Expires',
100
  'minify.html.reject.admin' => true,
101
  'minify.html.strip.crlf' => false,
102
  'minify.css.enable' => true,
 
103
  'minify.css.strip.comments' => false,
104
  'minify.css.strip.crlf' => false,
105
  'minify.css.groups' => array(
110
  )
111
  ),
112
  'minify.js.enable' => true,
113
+ 'minify.js.combine.header' => false,
114
+ 'minify.js.combine.footer' => false,
115
  'minify.js.strip.comments' => false,
116
  'minify.js.strip.crlf' => false,
117
  'minify.js.groups' => array(),
119
  /**
120
  * CDN configuration
121
  */
122
+ 'cdn.enabled' => false,
123
  'cdn.debug' => false,
124
  'cdn.engine' => 'ftp',
125
  'cdn.domain' => '',
144
  /**
145
  * Common configuration
146
  */
147
+ 'common.support.enabled' => true,
148
+ 'common.support.type' => 'footer',
149
+
150
+ /**
151
+ * Notes configuration
152
+ */
153
+ 'notes.defaults' => true,
154
+ 'notes.wp_content_perms' => true,
155
+ 'notes.cdn_first_time' => true,
156
+ 'notes.no_memcached_nor_apc' => true,
157
  );
w3-total-cache.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: W3 Total Cache
4
  Description: Dramatically improve the user experience of your blog. Add transparent page caching, database caching, minify and content delivery network (CDN) functionality and more to WordPress.
5
- Version: 0.7.5
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: Dramatically improve the user experience of your blog. Add transparent page caching, database caching, minify and content delivery network (CDN) functionality and more to WordPress.
5
+ Version: 0.7.5.1
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/w3tc-cache/index.php CHANGED
@@ -7,18 +7,17 @@ ini_set('display_errors', 'On');
7
  * W3 Total Cache Minify module
8
  */
9
  if (! defined('ABSPATH')) {
10
- define('ABSPATH', dirname(__FILE__) . '/../../');
11
  }
12
 
13
  if (! defined('W3TC_DIR')) {
14
- define('W3TC_DIR', dirname(__FILE__) . '/../plugins/w3-total-cache');
15
  }
16
 
17
  if (! is_dir(W3TC_DIR) || ! file_exists(W3TC_DIR . '/inc/define.php')) {
18
  die(sprintf('<strong>W3 Total Cache Error:</strong> plugin seems to be broken. Please re-install plugin or remove <strong>%s</strong>.', dirname(__FILE__)));
19
  }
20
 
21
- require_once ABSPATH . 'wp-config.php';
22
  require_once W3TC_DIR . '/inc/define.php';
23
  require_once W3TC_DIR . '/lib/W3/Minify.php';
24
 
7
  * W3 Total Cache Minify module
8
  */
9
  if (! defined('ABSPATH')) {
10
+ require_once dirname(__FILE__) . '/../../wp-load.php';
11
  }
12
 
13
  if (! defined('W3TC_DIR')) {
14
+ define('W3TC_DIR', realpath(dirname(__FILE__) . '/../plugins/w3-total-cache'));
15
  }
16
 
17
  if (! is_dir(W3TC_DIR) || ! file_exists(W3TC_DIR . '/inc/define.php')) {
18
  die(sprintf('<strong>W3 Total Cache Error:</strong> plugin seems to be broken. Please re-install plugin or remove <strong>%s</strong>.', dirname(__FILE__)));
19
  }
20
 
 
21
  require_once W3TC_DIR . '/inc/define.php';
22
  require_once W3TC_DIR . '/lib/W3/Minify.php';
23