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