W3 Total Cache - Version 0.7

Version Description

  • WordPress MU support bug fixes
  • Minor CDN uploader fixes
  • Added minify support for URIs starting with /
  • Minor error message improvements
Download this release

Release Info

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

Code changes from version 0.6 to 0.7

inc/css/popup.css CHANGED
@@ -114,6 +114,9 @@ a:hover {
114
  .table th {
115
  background: #eee;
116
  }
 
 
 
117
  .updated,.error {
118
  -moz-border-radius-bottomleft: 3px;
119
  -moz-border-radius-bottomright: 3px;
114
  .table th {
115
  background: #eee;
116
  }
117
+ .queue td {
118
+ font-size: 10px;
119
+ }
120
  .updated,.error {
121
  -moz-border-radius-bottomleft: 3px;
122
  -moz-border-radius-bottomright: 3px;
inc/define.php CHANGED
@@ -1,7 +1,9 @@
1
  <?php
2
 
 
 
3
  if (! defined('W3_PLUGIN_VERSION')) {
4
- define('W3_PLUGIN_VERSION', '0.6');
5
  }
6
 
7
  if (! defined('W3_PLUGIN_POWERED_BY')) {
@@ -24,8 +26,12 @@ if (! defined('W3_PLUGIN_FILE')) {
24
  define('W3_PLUGIN_FILE', 'w3-total-cache/w3-total-cache.php');
25
  }
26
 
 
 
 
 
27
  if (! defined('W3_CONFIG_PATH')) {
28
- define('W3_CONFIG_PATH', WP_CONTENT_DIR . '/w3-total-cache-config.php');
29
  }
30
 
31
  if (! defined('W3_CONFIG_DEFAULT_PATH')) {
@@ -170,3 +176,113 @@ function w3_is_xml($content)
170
  {
171
  return (stristr($content, '<?xml') !== false || stristr($content, '<html') !== false);
172
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
 
3
+ $w3_blog_id = w3_get_blog_id();
4
+
5
  if (! defined('W3_PLUGIN_VERSION')) {
6
+ define('W3_PLUGIN_VERSION', '0.7');
7
  }
8
 
9
  if (! defined('W3_PLUGIN_POWERED_BY')) {
26
  define('W3_PLUGIN_FILE', 'w3-total-cache/w3-total-cache.php');
27
  }
28
 
29
+ if (! defined('W3_CONFIG_NAME')) {
30
+ define('W3_CONFIG_NAME', 'w3-total-cache-config');
31
+ }
32
+
33
  if (! defined('W3_CONFIG_PATH')) {
34
+ define('W3_CONFIG_PATH', WP_CONTENT_DIR . '/' . W3_CONFIG_NAME . ($w3_blog_id != '' ? '-' . $w3_blog_id : '') . '.php');
35
  }
36
 
37
  if (! defined('W3_CONFIG_DEFAULT_PATH')) {
176
  {
177
  return (stristr($content, '<?xml') !== false || stristr($content, '<html') !== false);
178
  }
179
+
180
+ /**
181
+ * Returns blog ID
182
+ *
183
+ * @return string
184
+ */
185
+ function w3_get_blog_id()
186
+ {
187
+ static $id = null;
188
+
189
+ if ($id === null) {
190
+ $wpmu = false;
191
+
192
+ if (defined('VHOST')) {
193
+ $wpmu = true;
194
+ } else {
195
+ $wpmu = file_exists(ABSPATH . 'wpmu-settings.php');
196
+ }
197
+
198
+ if ($wpmu) {
199
+ if (defined('VHOST') && VHOST === 'yes') {
200
+ $id = w3_get_domain($_SERVER['HTTP_HOST']);
201
+ } else {
202
+ if (defined('PATH_CURRENT_SITE')) {
203
+ $base = PATH_CURRENT_SITE;
204
+ } elseif (isset($GLOBALS['base'])) {
205
+ $base = $GLOBALS['base'];
206
+ } else {
207
+ $base = '/';
208
+ }
209
+
210
+ if (empty($base)) {
211
+ $base = '/';
212
+ }
213
+
214
+ $id = strtolower($_SERVER['REQUEST_URI']);
215
+
216
+ if (strpos($id, $base) === 0) {
217
+ $id = substr_replace($id, '', 0, strlen($base));
218
+ }
219
+
220
+ if (($pos = strpos($id, '/'))) {
221
+ $id = substr($id, 0, $pos);
222
+ }
223
+
224
+ if (($pos = strpos($id, '?'))) {
225
+ $id = substr($id, 0, $pos);
226
+ }
227
+
228
+ if ($id != '') {
229
+ $id = trim($id, '/');
230
+
231
+ if (in_array($id, array(
232
+ 'page',
233
+ 'comments',
234
+ 'blog',
235
+ 'wp-admin',
236
+ 'wp-includes',
237
+ 'wp-content',
238
+ 'files',
239
+ 'feed'
240
+ )) || is_file($id)) {
241
+ $id = '';
242
+ } else {
243
+ $id = $id . '.' . w3_get_domain($_SERVER['HTTP_HOST']);
244
+ }
245
+ }
246
+ }
247
+ }
248
+ }
249
+
250
+ return $id;
251
+ }
252
+
253
+ /**
254
+ * Returns domain from host
255
+ *
256
+ * @param string $host
257
+ * @return string
258
+ */
259
+ function w3_get_domain($host)
260
+ {
261
+ $host = strtolower($host);
262
+
263
+ if (strpos($host, 'www.') === 0) {
264
+ $host = str_replace('www.', '', $host);
265
+ }
266
+
267
+ if (($pos = strpos($host, ':'))) {
268
+ $host = substr($host, 0, $pos);
269
+ }
270
+
271
+ return $host;
272
+ }
273
+
274
+ /**
275
+ * Returns site url [fast]
276
+ *
277
+ * @return string
278
+ */
279
+ function w3_get_site_url()
280
+ {
281
+ static $site_url = null;
282
+
283
+ if (! $site_url) {
284
+ $site_url = get_option('siteurl');
285
+ }
286
+
287
+ return $site_url;
288
+ }
inc/options/install.phtml CHANGED
@@ -21,18 +21,18 @@
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 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: 3 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 />
@@ -40,8 +40,7 @@
40
  # gunzip -c libevent-1.4.12-stable.tar.gz | tar xf -<br />
41
  # cd libevent-1.4.12-stable</li>
42
  <li>Let's compile:<br />
43
- # ./configure<br />
44
- # make &amp;&amp; make install</li>
45
  <li>In the output you should see:<br />
46
  <br />
47
  Libraries have been installed in:<br />
@@ -57,14 +56,11 @@
57
  # gunzip -c memcached-1.4.0.tar.gz | tar xf -<br />
58
  # cd memcached-1.4.0</li>
59
  <li>Let's compile:<br />
60
- # ./configure<br />
61
- # make &amp;&amp; make install</li>
62
- <li>We can optionally create memcached.conf in /etc/:<br />
63
- # cp -p /var/www/vhosts/domain.com/httpdocs/wp-content/plugins/w3-total-cache/ini/memcached.conf /etc/</li>
64
  <li>Make sure memcached is starts automatically on server boot:<br />
65
  # touch /etc/init.d/memcached<br />
66
  # echo '#!/bin/sh -e' >> /etc/init.d/memcached<br />
67
- # echo '/usr/local/bin/memcached -d -m 128 -p 11211 -u nobody' >> /etc/init.d/memcached<br />
68
  # chmod u+x /etc/init.d/memcached</li>
69
  <li>And finally, let's start memcached:<br />
70
  # /etc/init.d/memcached</li>
@@ -85,22 +81,18 @@
85
  # wget <a href="http://pecl.php.net/get/memcache-2.2.5.tgz">http://pecl.php.net/get/memcache-2.2.5.tgz</a><br />
86
  # gunzip -c memcache-2.2.5.tgz | tar xf -<br />
87
  # cd memcache-2.2.5</li>
88
- <li>Now we start to compile:<br />
89
- # phpize<br />
90
- # ./configure<br />
91
- # make &amp;&amp; make install</li>
92
- <li>If the output is like this:<br />
93
- Installing shared extensions: /usr/lib/php/modules/<br />
94
- <br />
95
- Then:<br />
96
  # echo "extension=memcache.so" &gt; /etc/php.d/memcache.ini<br />
97
  <br />
98
  or you can also use the memcache.ini file we prepared for you:<br />
99
- # cp -p /var/www/vhosts/domain.com/httpdocs/wp-content/plugins/w3-total-cache/ini/apc.ini /etc/php.d/</li>
100
  <li>Finally restart apache:<br />
101
  # /etc/init.d/httpd restart</li>
102
- <li>You're done! Memcache should now be available. You can verify by creating a .<acronym title="Hypertext Preprocessor">php</acronym> script containing the following code and searching for "memcache" after opening the page in your browser:<br />
103
- &lt;?php phpinfo(); ?&gt;</li>
104
  </ol>
105
  <hr />
106
  <p id="APC"><strong><acronym title="Alternative PHP Cache">APC</acronym> Installation via Yum or <acronym title="PHP Extension Community Library">PECL</acronym>: </strong><br />
@@ -110,7 +102,7 @@
110
  # pecl install apc<br />
111
  <br />
112
  or using yum:<br />
113
- # yum install php-pecl-apc</li>
114
  <li>Make sure the module is loaded:<br />
115
  # echo "extension=apc.so" &gt; /etc/php.d/apc.ini<br />
116
  <br />
@@ -118,8 +110,8 @@
118
  # cp -p /var/www/vhosts/domain.com/httpdocs/wp-content/plugins/w3-total-cache/ini/apc.ini /etc/php.d/</li>
119
  <li>When ready, restart apache:<br />
120
  # /etc/init.d/httpd restart</li>
121
- <li>You're done! <acronym title="Alternative PHP Cache">APC</acronym> should now be available. You can verify by creating a .<acronym title="Hypertext Preprocessor">php</acronym> script containing the following code and opening the page in your browser:<br />
122
- &lt;?php phpinfo(); ?&gt;</li>
123
  </ol>
124
  <p>For windows users we recommend checking the following sites for more installation tips:</p>
125
  <ul>
@@ -139,17 +131,15 @@
139
  # whereis phpize<br />
140
  # whereis php-config</li>
141
  <li>Use the output from #2 to modify the --with-apxs and --with-php-config flags in the following compile command:<br />
142
- # phpize<br />
143
- # ./configure --enable-apc --enable-apc-mmap --with-apxs=/usr/bin/phpize --with-php-config=/usr/bin/php-config<br />
144
- # make &amp;&amp; make install<br />
145
  <br />The result should be similar to:<br />
146
  Installing shared extensions: /usr/lib/php/modules/</li>
147
  <li>Use our customed <acronym title="Alternative PHP Cache">APC</acronym> settings by overwriting apc.ini in /etc/php.d/:<br />
148
  # cp -p /var/www/vhosts/domain.com/httpdocs/wp-content/plugins/w3-total-cache/ini/apc.ini /etc/php.d/</li>
149
  <li>Restart apache when ready:<br />
150
  # /etc/init.d/httpd restart</li>
151
- <li>You're done! <acronym title="Alternative PHP Cache">APC</acronym> should now be available. You can verify by creating a .<acronym title="Hypertext Preprocessor">php</acronym> script containing the following code and searching for "<acronym title="Alternative PHP Cache">APC</acronym>" after opening the page in your browser:<br />
152
- &lt;?php phpinfo(); ?&gt;</li>
153
  </ol>
154
  <hr />
155
  <p><strong>Note(s):</strong></p>
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 />
40
  # gunzip -c libevent-1.4.12-stable.tar.gz | tar xf -<br />
41
  # cd libevent-1.4.12-stable</li>
42
  <li>Let's compile:<br />
43
+ # ./configure &amp;&amp; make &amp;&amp; make install</li>
 
44
  <li>In the output you should see:<br />
45
  <br />
46
  Libraries have been installed in:<br />
56
  # gunzip -c memcached-1.4.0.tar.gz | tar xf -<br />
57
  # cd memcached-1.4.0</li>
58
  <li>Let's compile:<br />
59
+ # ./configure &amp;&amp; make &amp;&amp; make install</li>
 
 
 
60
  <li>Make sure memcached is starts automatically on server boot:<br />
61
  # touch /etc/init.d/memcached<br />
62
  # echo '#!/bin/sh -e' >> /etc/init.d/memcached<br />
63
+ # echo '/usr/local/bin/memcached -d -m 128 -p 11211 -u nobody -l localhost' >> /etc/init.d/memcached<br />
64
  # chmod u+x /etc/init.d/memcached</li>
65
  <li>And finally, let's start memcached:<br />
66
  # /etc/init.d/memcached</li>
81
  # wget <a href="http://pecl.php.net/get/memcache-2.2.5.tgz">http://pecl.php.net/get/memcache-2.2.5.tgz</a><br />
82
  # gunzip -c memcache-2.2.5.tgz | tar xf -<br />
83
  # cd memcache-2.2.5</li>
84
+ <li>Now we start to compile (and copy the module to your <acronym title="PHP Extension Community Library">PECL</acronym> modules directory if necessary):<br />
85
+ # phpize &amp;&amp; ./configure &amp;&amp; make &amp;&amp; make install<br />
86
+ # cp -p /usr/local/src/memcache-2.2.5/modules/memcache.so /usr/lib/php/modules/</li>
87
+ <li>Make sure the module is loaded:<br />
 
 
 
 
88
  # echo "extension=memcache.so" &gt; /etc/php.d/memcache.ini<br />
89
  <br />
90
  or you can also use the memcache.ini file we prepared for you:<br />
91
+ # cp -p /var/www/vhosts/domain.com/httpdocs/wp-content/plugins/w3-total-cache/ini/memcache.ini /etc/php.d/</li>
92
  <li>Finally restart apache:<br />
93
  # /etc/init.d/httpd restart</li>
94
+ <li>You're done! Memcache should now be available. If the following command retuns anything, you're all set:<br />
95
+ # php -r 'phpinfo();' | grep 'memcache'</li>
96
  </ol>
97
  <hr />
98
  <p id="APC"><strong><acronym title="Alternative PHP Cache">APC</acronym> Installation via Yum or <acronym title="PHP Extension Community Library">PECL</acronym>: </strong><br />
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 />
110
  # cp -p /var/www/vhosts/domain.com/httpdocs/wp-content/plugins/w3-total-cache/ini/apc.ini /etc/php.d/</li>
111
  <li>When ready, restart apache:<br />
112
  # /etc/init.d/httpd restart</li>
113
+ <li>You're done! <acronym title="Alternative PHP Cache">APC</acronym> should now be available. If the following command retuns anything, you're all set:<br />
114
+ # php -r 'phpinfo();' | grep 'apc'</li>
115
  </ol>
116
  <p>For windows users we recommend checking the following sites for more installation tips:</p>
117
  <ul>
131
  # whereis phpize<br />
132
  # whereis php-config</li>
133
  <li>Use the output from #2 to modify the --with-apxs and --with-php-config flags in the following compile command:<br />
134
+ # phpize &amp;&amp; ./configure --enable-apc --enable-apc-mmap --with-apxs=/usr/bin/phpize --with-php-config=/usr/bin/php-config &amp;&amp; make &amp;&amp; make install<br />
 
 
135
  <br />The result should be similar to:<br />
136
  Installing shared extensions: /usr/lib/php/modules/</li>
137
  <li>Use our customed <acronym title="Alternative PHP Cache">APC</acronym> settings by overwriting apc.ini in /etc/php.d/:<br />
138
  # cp -p /var/www/vhosts/domain.com/httpdocs/wp-content/plugins/w3-total-cache/ini/apc.ini /etc/php.d/</li>
139
  <li>Restart apache when ready:<br />
140
  # /etc/init.d/httpd restart</li>
141
+ <li>You're done! <acronym title="Alternative PHP Cache">APC</acronym> should now be available. If the following command retuns anything, you're all set:<br />
142
+ # php -r 'phpinfo();' | grep 'apc'</li>
143
  </ol>
144
  <hr />
145
  <p><strong>Note(s):</strong></p>
inc/popup/cdn_queue.phtml CHANGED
@@ -5,16 +5,18 @@
5
 
6
  <div id="cdn_queue_upload" class="tab-content"<?php if ($cdn_queue_tab != 'upload'): ?> style="display: none;"<?php endif; ?>>
7
  <?php if (! empty($queue[W3_PLUGIN_CDN_COMMAND_UPLOAD])): ?>
8
- <table class="table">
9
  <tr>
10
- <th>File</th>
 
11
  <th>Last Error</th>
12
- <th width="25%">Date</th>
13
- <th width="10%">Delete</th>
14
  </tr>
15
  <?php foreach ((array) $queue[W3_PLUGIN_CDN_COMMAND_UPLOAD] as $result): ?>
16
  <tr>
17
- <td><?php echo htmlspecialchars($result->file); ?></td>
 
18
  <td><?php echo htmlspecialchars($result->last_error); ?></td>
19
  <td align="center"><?php echo htmlspecialchars($result->date); ?></td>
20
  <td align="center">
@@ -33,16 +35,18 @@
33
 
34
  <div id="cdn_queue_delete" class="tab-content"<?php if ($cdn_queue_tab != 'delete'): ?> style="display: none;"<?php endif; ?>>
35
  <?php if (! empty($queue[W3_PLUGIN_CDN_COMMAND_DELETE])): ?>
36
- <table class="table">
37
  <tr>
38
- <th>File</th>
 
39
  <th>Last Error</th>
40
  <th width="25%">Date</th>
41
  <th width="10%">Delete</th>
42
  </tr>
43
  <?php foreach ((array) $queue[W3_PLUGIN_CDN_COMMAND_DELETE] as $result): ?>
44
  <tr>
45
- <td><?php echo htmlspecialchars($result->file); ?></td>
 
46
  <td><?php echo htmlspecialchars($result->last_error); ?></td>
47
  <td align="center"><?php echo htmlspecialchars($result->date); ?></td>
48
  <td align="center">
5
 
6
  <div id="cdn_queue_upload" class="tab-content"<?php if ($cdn_queue_tab != 'upload'): ?> style="display: none;"<?php endif; ?>>
7
  <?php if (! empty($queue[W3_PLUGIN_CDN_COMMAND_UPLOAD])): ?>
8
+ <table class="table queue">
9
  <tr>
10
+ <th>Local Path</th>
11
+ <th>Remote Path</th>
12
  <th>Last Error</th>
13
+ <th>Date</th>
14
+ <th>Delete</th>
15
  </tr>
16
  <?php foreach ((array) $queue[W3_PLUGIN_CDN_COMMAND_UPLOAD] as $result): ?>
17
  <tr>
18
+ <td><?php echo htmlspecialchars($result->local_path); ?></td>
19
+ <td><?php echo htmlspecialchars($result->remote_path); ?></td>
20
  <td><?php echo htmlspecialchars($result->last_error); ?></td>
21
  <td align="center"><?php echo htmlspecialchars($result->date); ?></td>
22
  <td align="center">
35
 
36
  <div id="cdn_queue_delete" class="tab-content"<?php if ($cdn_queue_tab != 'delete'): ?> style="display: none;"<?php endif; ?>>
37
  <?php if (! empty($queue[W3_PLUGIN_CDN_COMMAND_DELETE])): ?>
38
+ <table class="table queue">
39
  <tr>
40
+ <th>Local Path</th>
41
+ <th>Remote Path</th>
42
  <th>Last Error</th>
43
  <th width="25%">Date</th>
44
  <th width="10%">Delete</th>
45
  </tr>
46
  <?php foreach ((array) $queue[W3_PLUGIN_CDN_COMMAND_DELETE] as $result): ?>
47
  <tr>
48
+ <td><?php echo htmlspecialchars($result->local_path); ?></td>
49
+ <td><?php echo htmlspecialchars($result->remote_path); ?></td>
50
  <td><?php echo htmlspecialchars($result->last_error); ?></td>
51
  <td align="center"><?php echo htmlspecialchars($result->date); ?></td>
52
  <td align="center">
lib/W3/Cdn/Ftp.php CHANGED
@@ -199,7 +199,7 @@ class W3_Cdn_Ftp extends W3_Cdn_Base
199
  $rand = md5(time());
200
  $tmp_dir = 'test_dir_' . $rand;
201
  $tmp_file = 'test_file_' . $rand;
202
- $tmp_path = WP_CONTENT_DIR . '/uploads/' . $tmp_file;
203
 
204
  if (! @ftp_mkdir($this->_ftp, $tmp_dir)) {
205
  $this->_disconnect();
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();
lib/W3/Db.php CHANGED
@@ -430,7 +430,13 @@ class W3_Db extends wpdb
430
  */
431
  function _get_cache_key($sql)
432
  {
433
- return sprintf('w3tc_%s_sql_%s', md5($_SERVER['HTTP_HOST']), md5($sql));
 
 
 
 
 
 
434
  }
435
 
436
  /**
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
  /**
lib/W3/PgCache.php CHANGED
@@ -655,7 +655,13 @@ class W3_PgCache
655
  */
656
  function _get_page_key($compression = false)
657
  {
658
- $key = sprintf('w3tc_%s_page_%s', md5($_SERVER['HTTP_HOST']), md5($_SERVER['REQUEST_URI']));
 
 
 
 
 
 
659
 
660
  if ($this->_config->get_boolean('pgcache.mobile.check') && ($mobile_type = $this->_get_mobile_type()) != '') {
661
  $key .= '_' . $mobile_type;
655
  */
656
  function _get_page_key($compression = false)
657
  {
658
+ $blog_id = w3_get_blog_id();
659
+
660
+ if (empty($blog_id)) {
661
+ $blog_id = $_SERVER['HTTP_HOST'];
662
+ }
663
+
664
+ $key = sprintf('w3tc_%s_page_%s', md5($blog_id), md5($_SERVER['REQUEST_URI']));
665
 
666
  if ($this->_config->get_boolean('pgcache.mobile.check') && ($mobile_type = $this->_get_mobile_type()) != '') {
667
  $key .= '_' . $mobile_type;
lib/W3/Plugin.php CHANGED
@@ -58,4 +58,30 @@ class W3_Plugin
58
 
59
  return $instance;
60
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  }
58
 
59
  return $instance;
60
  }
61
+
62
+ /**
63
+ * Check if plugin is locked
64
+ *
65
+ * @return boolean
66
+ */
67
+ function locked()
68
+ {
69
+ static $locked = null;
70
+
71
+ if ($locked === null) {
72
+ $dir = @dir(dirname(W3_CONFIG_PATH));
73
+ $config = basename(W3_CONFIG_PATH);
74
+
75
+ $locked = false;
76
+
77
+ while (($entry = @$dir->read())) {
78
+ if (strpos($entry, W3_CONFIG_NAME) === 0 && $entry !== $config) {
79
+ $locked = true;
80
+ break;
81
+ }
82
+ }
83
+ }
84
+
85
+ return $locked;
86
+ }
87
  }
lib/W3/Plugin/Cdn.php CHANGED
@@ -15,10 +15,6 @@ if (! defined('W3_PLUGIN_CDN_TABLE_QUEUE')) {
15
  define('W3_PLUGIN_CDN_TABLE_QUEUE', 'w3tc_cdn_queue');
16
  }
17
 
18
- if (! defined('W3_PLUGIN_CDN_UPLOADS_DIR')) {
19
- define('W3_PLUGIN_CDN_UPLOADS_DIR', 'wp-content/uploads/');
20
- }
21
-
22
  if (! defined('W3_PLUGIN_CDN_THEMES_DIR')) {
23
  define('W3_PLUGIN_CDN_THEMES_DIR', ABSPATH . 'wp-content/themes/');
24
  }
@@ -117,12 +113,13 @@ class W3_Plugin_Cdn extends W3_Plugin
117
 
118
  $sql = sprintf("CREATE TABLE IF NOT EXISTS `%s` (
119
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
120
- `file` varchar(255) NOT NULL DEFAULT '0',
121
- `command` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '1 - upload, 2 - delete',
 
122
  `last_error` varchar(255) NOT NULL DEFAULT '',
123
  `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
124
  PRIMARY KEY (`id`),
125
- UNIQUE KEY `file` (`file`),
126
  KEY `date` (`date`)
127
  )", $wpdb->prefix . W3_PLUGIN_CDN_TABLE_QUEUE);
128
  $wpdb->query($sql);
@@ -186,13 +183,11 @@ class W3_Plugin_Cdn extends W3_Plugin
186
  */
187
  function the_content($content)
188
  {
189
- static $siteurl = null;
190
-
191
- if (! $siteurl) {
192
- $siteurl = get_option('siteurl');
193
- }
194
 
195
- $content = preg_replace_callback('~' . preg_quote($siteurl) . '(/wp-content/uploads/([^"\'>]+))~', array(
196
  &$this,
197
  'link_replace_callback'
198
  ), $content);
@@ -234,7 +229,7 @@ class W3_Plugin_Cdn extends W3_Plugin
234
  } else {
235
  $file = get_post_meta($attachment_id, '_wp_attached_file', true);
236
  $files = array(
237
- W3_PLUGIN_CDN_UPLOADS_DIR . $file
238
  );
239
  }
240
 
@@ -253,13 +248,13 @@ class W3_Plugin_Cdn extends W3_Plugin
253
  return $buffer;
254
  }
255
 
256
- $siteurl = get_option('siteurl');
257
  $regexps = array();
258
 
259
  if ($this->_config->get_boolean('cdn.includes.enable', true)) {
260
  $mask = $this->_config->get_string('cdn.includes.files');
261
  if (! empty($mask)) {
262
- $regexps[] = '~' . preg_quote($siteurl) . '(/wp-includes/(' . $this->get_regexp_by_mask($mask) . '))~U';
263
  }
264
  }
265
 
@@ -267,12 +262,12 @@ class W3_Plugin_Cdn extends W3_Plugin
267
  $stylesheet = get_stylesheet();
268
  $mask = $this->_config->get_string('cdn.theme.files');
269
  if (! empty($mask)) {
270
- $regexps[] = '~' . preg_quote($siteurl) . '(/wp-content/themes/' . preg_quote($stylesheet) . '/(' . $this->get_regexp_by_mask($mask) . '))~U';
271
  }
272
  }
273
 
274
  if ($this->_config->get_boolean('cdn.minify.enable', true)) {
275
- $regexps[] = '~' . preg_quote($siteurl) . '(/' . preg_quote(W3_PLUGIN_MINIFY_MIN_DIRNAME) . '/include(-footer)?(-nb)?\.(css|js))~';
276
  }
277
 
278
  if ($this->_config->get_boolean('cdn.custom.enable', true)) {
@@ -282,7 +277,7 @@ class W3_Plugin_Cdn extends W3_Plugin
282
  foreach ($files as $file) {
283
  $files_quoted[] = preg_quote($file);
284
  }
285
- $regexps[] = '~' . preg_quote($siteurl) . '(/(' . implode('|', $files_quoted) . '))~';
286
  }
287
  }
288
 
@@ -310,13 +305,20 @@ class W3_Plugin_Cdn extends W3_Plugin
310
  {
311
  $files = array();
312
 
 
 
 
313
  if (isset($metadata['file'])) {
314
- $files[] = W3_PLUGIN_CDN_UPLOADS_DIR . $metadata['file'];
 
 
315
  if (isset($metadata['sizes'])) {
316
- $file_dir = W3_PLUGIN_CDN_UPLOADS_DIR . dirname($metadata['file']);
317
  foreach ((array) $metadata['sizes'] as $size) {
318
  if (isset($size['file'])) {
319
- $files[] = $file_dir . '/' . $size['file'];
 
 
320
  }
321
  }
322
  }
@@ -328,22 +330,23 @@ class W3_Plugin_Cdn extends W3_Plugin
328
  /**
329
  * Adds file to queue
330
  *
331
- * @param string $file
 
332
  * @param integer $command
333
  * @param string $last_error
334
  * @return ingteer
335
  */
336
- function queue_add($file, $command, $last_error)
337
  {
338
  global $wpdb;
339
 
340
  $table = $wpdb->prefix . W3_PLUGIN_CDN_TABLE_QUEUE;
341
- $sql = sprintf('SELECT id FROM %s WHERE file = "%s" AND command != %d', $table, $wpdb->escape($file), $command);
342
 
343
  if (($row = $wpdb->get_row($sql))) {
344
  $sql = sprintf('DELETE FROM %s WHERE id = %d', $table, $row->id);
345
  } else {
346
- $sql = sprintf('REPLACE INTO %s (file, command, last_error, date) VALUES ("%s", %d, "%s", NOW())', $table, $wpdb->escape($file), $command, $wpdb->escape($last_error));
347
  }
348
 
349
  return $wpdb->query($sql);
@@ -440,10 +443,8 @@ class W3_Plugin_Cdn extends W3_Plugin
440
  $map = array();
441
 
442
  foreach ($queue as $result) {
443
- $local_path = $this->format_local_path($result->file);
444
- $remote_path = $this->format_remote_path($result->file);
445
- $files[$local_path] = $remote_path;
446
- $map[$local_path] = $result->id;
447
  }
448
 
449
  switch ($command) {
@@ -478,13 +479,11 @@ class W3_Plugin_Cdn extends W3_Plugin
478
  function upload($files, $queue_failed = false, &$results = array())
479
  {
480
  $upload = array();
481
- $map = array();
482
 
483
- foreach ($files as $file) {
484
- $local_path = $this->format_local_path($file);
485
- $remote_path = $this->format_remote_path($file);
486
  $upload[$local_path] = $remote_path;
487
- $map[$local_path] = $file;
488
  }
489
 
490
  $cdn = $this->get_cdn();
@@ -492,7 +491,7 @@ class W3_Plugin_Cdn extends W3_Plugin
492
  if ($queue_failed) {
493
  foreach ($results as $result) {
494
  if ($result['result'] != W3_CDN_RESULT_OK) {
495
- $this->queue_add($map[$result['local_path']], W3_PLUGIN_CDN_COMMAND_UPLOAD, $result['error']);
496
  }
497
  }
498
  }
@@ -514,13 +513,11 @@ class W3_Plugin_Cdn extends W3_Plugin
514
  function delete($files, $queue_failed = false, &$results = array())
515
  {
516
  $delete = array();
517
- $map = array();
518
 
519
- foreach ($files as $file) {
520
- $local_path = $this->format_local_path($file);
521
- $remote_path = $this->format_remote_path($file);
522
  $delete[$local_path] = $remote_path;
523
- $map[$local_path] = $file;
524
  }
525
 
526
  $cdn = $this->get_cdn();
@@ -528,7 +525,7 @@ class W3_Plugin_Cdn extends W3_Plugin
528
  if ($queue_failed) {
529
  foreach ($results as $result) {
530
  if ($result['result'] != W3_CDN_RESULT_OK) {
531
- $this->queue_add($map[$result['local_path']], W3_PLUGIN_CDN_COMMAND_DELETE, $result['error']);
532
  }
533
  }
534
  }
@@ -567,7 +564,9 @@ class W3_Plugin_Cdn extends W3_Plugin
567
  LEFT JOIN
568
  %spostmeta AS pm2 ON p.ID = pm2.post_ID AND pm2.meta_key = "_wp_attachment_metadata"
569
  WHERE
570
- p.post_type = "attachment"', $wpdb->prefix, $wpdb->prefix, $wpdb->prefix);
 
 
571
 
572
  if ($limit) {
573
  $sql .= sprintf(' LIMIT %d', $limit);
@@ -582,6 +581,8 @@ class W3_Plugin_Cdn extends W3_Plugin
582
  if ($posts) {
583
  $count = count($posts);
584
  $total = $this->get_attachments_count();
 
 
585
  $files = array();
586
 
587
  foreach ($posts as $post) {
@@ -590,7 +591,9 @@ class W3_Plugin_Cdn extends W3_Plugin
590
  if (isset($metadata['file'])) {
591
  $files = array_merge($files, $this->get_metadata_files($metadata));
592
  } elseif (! empty($post->file)) {
593
- $files[] = $post->file;
 
 
594
  }
595
  }
596
  }
@@ -620,6 +623,7 @@ class W3_Plugin_Cdn extends W3_Plugin
620
  $results = array();
621
 
622
  $sql = sprintf('SELECT
 
623
  post_content
624
  FROM
625
  %sposts
@@ -644,9 +648,9 @@ class W3_Plugin_Cdn extends W3_Plugin
644
  $count = count($posts);
645
  $total = $this->get_import_posts_count();
646
 
647
- $siteurl = get_option('siteurl');
648
- $upload_info = wp_upload_dir();
649
- $upload_dir = ltrim(str_replace($siteurl, '', $upload_info['baseurl']), '/');
650
  $regexp = $this->get_regexp_by_mask($this->_config->get_string('cdn.import.files'));
651
  $import_external = $this->_config->get_boolean('cdn.import.external');
652
 
@@ -655,32 +659,37 @@ class W3_Plugin_Cdn extends W3_Plugin
655
 
656
  if (preg_match_all('~(href|src)=[\'"]?([^\'"<>\s]+)[\'"]?~', $post->post_content, $matches, PREG_SET_ORDER)) {
657
  foreach ($matches as $match) {
658
- $src = ltrim(str_replace($siteurl, '', $match[2]), '/');
659
- $file = sprintf('%s/%s', $upload_info['path'], basename($src));
660
- $dst = str_replace(ABSPATH, '', $file);
 
 
 
 
661
  $result = false;
662
  $error = '';
663
  $download_result = null;
664
 
665
  if (preg_match('~(' . $regexp . ')$~', $src)) {
666
- if (! file_exists($file)) {
667
- if (w3_is_url($src)) {
668
  if ($import_external) {
669
- $download_result = $this->download($src, $file);
670
  } else {
671
  $error = 'External file import is disabled';
672
  }
673
- } elseif (strstr($src, $upload_dir) === false) {
674
- $download_result = @copy(ABSPATH . $src, $file);
 
675
  } else {
676
  $error = 'Source file already exists';
677
  }
678
 
679
  if ($download_result !== null) {
680
  if ($download_result) {
681
- $title = basename($file);
682
- $guid = $upload_info['url'] . '/' . $title;
683
- $mime_type = $this->get_mime_type($file);
684
 
685
  $GLOBALS['wp_rewrite'] = & new WP_Rewrite();
686
 
@@ -689,11 +698,12 @@ class W3_Plugin_Cdn extends W3_Plugin
689
  'guid' => $guid,
690
  'post_title' => $title,
691
  'post_content' => ''
692
- ), $file);
693
 
694
  if (! is_wp_error($id)) {
695
  require_once ABSPATH . 'wp-admin/includes/image.php';
696
- wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file));
 
697
 
698
  $result = true;
699
  $error = 'OK';
@@ -906,11 +916,11 @@ class W3_Plugin_Cdn extends W3_Plugin
906
  static $queue = null, $domain = null, $debug = null;
907
 
908
  if ($queue === null) {
909
- $sql = sprintf('SELECT file FROM %s', $wpdb->prefix . W3_PLUGIN_CDN_TABLE_QUEUE);
910
  $queue = $wpdb->get_col($sql);
911
  }
912
 
913
- if (in_array($matches[2], $queue)) {
914
  return $matches[0];
915
  }
916
 
@@ -926,7 +936,7 @@ class W3_Plugin_Cdn extends W3_Plugin
926
  return $matches[0];
927
  }
928
 
929
- $url = sprintf('http://%s%s', $domain, $matches[1]);
930
 
931
  if ($debug) {
932
  $this->replaced_urls[] = $url;
@@ -1072,14 +1082,38 @@ class W3_Plugin_Cdn extends W3_Plugin
1072
  }
1073
 
1074
  /**
1075
- * Returns file from thumb file
1076
- *
1077
- * @param string $thumb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1078
  * @return string
1079
  */
1080
- function get_file_from_thumb($thumb)
1081
  {
1082
- return preg_replace('~\-\d{2,4}x\d{2,4}\.(jpg|png|gif)$~', '.\\1', $thumb);
 
 
 
 
 
 
 
 
1083
  }
1084
 
1085
  /**
15
  define('W3_PLUGIN_CDN_TABLE_QUEUE', 'w3tc_cdn_queue');
16
  }
17
 
 
 
 
 
18
  if (! defined('W3_PLUGIN_CDN_THEMES_DIR')) {
19
  define('W3_PLUGIN_CDN_THEMES_DIR', ABSPATH . 'wp-content/themes/');
20
  }
113
 
114
  $sql = sprintf("CREATE TABLE IF NOT EXISTS `%s` (
115
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
116
+ `local_path` varchar(255) NOT NULL DEFAULT '',
117
+ `remote_path` varchar(255) NOT NULL DEFAULT '',
118
+ `command` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '1 - Upload, 2 - Delete',
119
  `last_error` varchar(255) NOT NULL DEFAULT '',
120
  `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
121
  PRIMARY KEY (`id`),
122
+ UNIQUE KEY `path` (`local_path`, `remote_path`),
123
  KEY `date` (`date`)
124
  )", $wpdb->prefix . W3_PLUGIN_CDN_TABLE_QUEUE);
125
  $wpdb->query($sql);
183
  */
184
  function the_content($content)
185
  {
186
+ $siteurl = w3_get_site_url();
187
+ $upload_url = $this->get_upload_url();
188
+ $regexp = '~(' . preg_quote($siteurl) . ')?(/' . preg_quote($upload_url) . '[^"\'>]+)~';
 
 
189
 
190
+ $content = preg_replace_callback($regexp, array(
191
  &$this,
192
  'link_replace_callback'
193
  ), $content);
229
  } else {
230
  $file = get_post_meta($attachment_id, '_wp_attached_file', true);
231
  $files = array(
232
+ $file
233
  );
234
  }
235
 
248
  return $buffer;
249
  }
250
 
251
+ $siteurl = w3_get_site_url();
252
  $regexps = array();
253
 
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) . '))~U';
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) . '))~U';
266
  }
267
  }
268
 
269
  if ($this->_config->get_boolean('cdn.minify.enable', true)) {
270
+ $regexps[] = '~(' . preg_quote($siteurl) . ')?(/' . preg_quote(W3_PLUGIN_MINIFY_MIN_DIRNAME) . '/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
 
305
  {
306
  $files = array();
307
 
308
+ $upload_dir = $this->get_upload_dir();
309
+ $upload_url = $this->get_upload_url();
310
+
311
  if (isset($metadata['file'])) {
312
+ $local_file = $upload_dir . '/' . $metadata['file'];
313
+ $remote_file = $upload_url . '/' . $metadata['file'];
314
+ $files[$local_file] = $remote_file;
315
  if (isset($metadata['sizes'])) {
316
+ $file_dir = dirname($metadata['file']);
317
  foreach ((array) $metadata['sizes'] as $size) {
318
  if (isset($size['file'])) {
319
+ $local_file = $upload_dir . '/' . $file_dir . '/' . $size['file'];
320
+ $remote_file = $upload_url . '/' . $file_dir . '/' . $size['file'];
321
+ $files[$local_file] = $remote_file;
322
  }
323
  }
324
  }
330
  /**
331
  * Adds file to queue
332
  *
333
+ * @param string $local_path
334
+ * @param string $remote_path
335
  * @param integer $command
336
  * @param string $last_error
337
  * @return ingteer
338
  */
339
+ function queue_add($local_path, $remote_path, $command, $last_error)
340
  {
341
  global $wpdb;
342
 
343
  $table = $wpdb->prefix . W3_PLUGIN_CDN_TABLE_QUEUE;
344
+ $sql = sprintf('SELECT id FROM %s WHERE local_path = "%s" remote_path = "%s" AND command != %d', $table, $wpdb->escape($local_path), $wpdb->escape($remote_path), $command);
345
 
346
  if (($row = $wpdb->get_row($sql))) {
347
  $sql = sprintf('DELETE FROM %s WHERE id = %d', $table, $row->id);
348
  } else {
349
+ $sql = sprintf('REPLACE INTO %s (local_path, remote_path, command, last_error, date) VALUES ("%s", "%s", %d, "%s", NOW())', $table, $wpdb->escape($local_path), $wpdb->escape($remote_path), $command, $wpdb->escape($last_error));
350
  }
351
 
352
  return $wpdb->query($sql);
443
  $map = array();
444
 
445
  foreach ($queue as $result) {
446
+ $files[$result->local_path] = $result->remote_path;
447
+ $map[$result->local_path] = $result->id;
 
 
448
  }
449
 
450
  switch ($command) {
479
  function upload($files, $queue_failed = false, &$results = array())
480
  {
481
  $upload = array();
 
482
 
483
+ foreach ($files as $local_file => $remote_file) {
484
+ $local_path = $this->format_local_path($local_file);
485
+ $remote_path = $this->format_remote_path($remote_file);
486
  $upload[$local_path] = $remote_path;
 
487
  }
488
 
489
  $cdn = $this->get_cdn();
491
  if ($queue_failed) {
492
  foreach ($results as $result) {
493
  if ($result['result'] != W3_CDN_RESULT_OK) {
494
+ $this->queue_add($result['local_path'], $result['remote_path'], W3_PLUGIN_CDN_COMMAND_UPLOAD, $result['error']);
495
  }
496
  }
497
  }
513
  function delete($files, $queue_failed = false, &$results = array())
514
  {
515
  $delete = array();
 
516
 
517
+ foreach ($files as $local_file => $remote_file) {
518
+ $local_path = $this->format_local_path($local_file);
519
+ $remote_path = $this->format_remote_path($remote_file);
520
  $delete[$local_path] = $remote_path;
 
521
  }
522
 
523
  $cdn = $this->get_cdn();
525
  if ($queue_failed) {
526
  foreach ($results as $result) {
527
  if ($result['result'] != W3_CDN_RESULT_OK) {
528
+ $this->queue_add($result['local_path'], $result['remote_path'], W3_PLUGIN_CDN_COMMAND_DELETE, $result['error']);
529
  }
530
  }
531
  }
564
  LEFT JOIN
565
  %spostmeta AS pm2 ON p.ID = pm2.post_ID AND pm2.meta_key = "_wp_attachment_metadata"
566
  WHERE
567
+ p.post_type = "attachment"
568
+ GROUP BY
569
+ p.ID', $wpdb->prefix, $wpdb->prefix, $wpdb->prefix);
570
 
571
  if ($limit) {
572
  $sql .= sprintf(' LIMIT %d', $limit);
581
  if ($posts) {
582
  $count = count($posts);
583
  $total = $this->get_attachments_count();
584
+ $upload_dir = $this->get_upload_dir();
585
+ $upload_url = $this->get_upload_url();
586
  $files = array();
587
 
588
  foreach ($posts as $post) {
591
  if (isset($metadata['file'])) {
592
  $files = array_merge($files, $this->get_metadata_files($metadata));
593
  } elseif (! empty($post->file)) {
594
+ $local_file = $upload_dir . '/' . $post->file;
595
+ $remote_file = $upload_url . '/' . $post->file;
596
+ $files[$local_file] = $remote_file;
597
  }
598
  }
599
  }
623
  $results = array();
624
 
625
  $sql = sprintf('SELECT
626
+ ID,
627
  post_content
628
  FROM
629
  %sposts
648
  $count = count($posts);
649
  $total = $this->get_import_posts_count();
650
 
651
+ $siteurl = w3_get_site_url();
652
+ $upload_dir = $this->get_upload_dir();
653
+ $upload_url = $this->get_upload_url();
654
  $regexp = $this->get_regexp_by_mask($this->_config->get_string('cdn.import.files'));
655
  $import_external = $this->_config->get_boolean('cdn.import.external');
656
 
659
 
660
  if (preg_match_all('~(href|src)=[\'"]?([^\'"<>\s]+)[\'"]?~', $post->post_content, $matches, PREG_SET_ORDER)) {
661
  foreach ($matches as $match) {
662
+ $src = $match[2];
663
+ $file = ltrim(str_replace($siteurl, '', $src), '/');
664
+ $file_dir = date('Y/m');
665
+ $file_base = basename($file);
666
+ $dst = sprintf('%s/%s/%s', $upload_dir, $file_dir, $file_base);
667
+ $dst_path = ABSPATH . $dst;
668
+ $dst_url = sprintf('%s/%s/%s/%s', $siteurl, $upload_url, $file_dir, $file_base);
669
  $result = false;
670
  $error = '';
671
  $download_result = null;
672
 
673
  if (preg_match('~(' . $regexp . ')$~', $src)) {
674
+ if (! file_exists($dst_path)) {
675
+ if (w3_is_url($file)) {
676
  if ($import_external) {
677
+ $download_result = $this->download($file, $dst_path);
678
  } else {
679
  $error = 'External file import is disabled';
680
  }
681
+ } elseif (strstr($src, $upload_url) === false) {
682
+ $file_path = ABSPATH . $file;
683
+ $download_result = @copy(ABSPATH . $file_path, $dst_path);
684
  } else {
685
  $error = 'Source file already exists';
686
  }
687
 
688
  if ($download_result !== null) {
689
  if ($download_result) {
690
+ $title = $file_base;
691
+ $guid = $upload_url . '/' . $title;
692
+ $mime_type = $this->get_mime_type($file_base);
693
 
694
  $GLOBALS['wp_rewrite'] = & new WP_Rewrite();
695
 
698
  'guid' => $guid,
699
  'post_title' => $title,
700
  'post_content' => ''
701
+ ), $dst_path);
702
 
703
  if (! is_wp_error($id)) {
704
  require_once ABSPATH . 'wp-admin/includes/image.php';
705
+ wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $dst_path));
706
+ wp_update_post(array('ID' => $post->ID, 'post_content' => str_replace($src, $dst_url, $post->post_content)));
707
 
708
  $result = true;
709
  $error = 'OK';
916
  static $queue = null, $domain = null, $debug = null;
917
 
918
  if ($queue === null) {
919
+ $sql = sprintf('SELECT remote_path FROM %s', $wpdb->prefix . W3_PLUGIN_CDN_TABLE_QUEUE);
920
  $queue = $wpdb->get_col($sql);
921
  }
922
 
923
+ if (in_array(ltrim($matches[2], '/'), $queue)) {
924
  return $matches[0];
925
  }
926
 
936
  return $matches[0];
937
  }
938
 
939
+ $url = sprintf('http://%s%s', $domain, $matches[2]);
940
 
941
  if ($debug) {
942
  $this->replaced_urls[] = $url;
1082
  }
1083
 
1084
  /**
1085
+ * Returns upload dir
1086
+ *
1087
+ * @return string
1088
+ */
1089
+ function get_upload_dir()
1090
+ {
1091
+ static $upload_dir = null;
1092
+
1093
+ if (! $upload_dir) {
1094
+ $upload_info = wp_upload_dir();
1095
+ $upload_dir = trim(str_replace(ABSPATH, '', $upload_info['basedir']), '/');
1096
+ }
1097
+
1098
+ return $upload_dir;
1099
+ }
1100
+
1101
+ /**
1102
+ * Returns upload dir
1103
+ *
1104
  * @return string
1105
  */
1106
+ function get_upload_url()
1107
  {
1108
+ static $upload_dir = null;
1109
+
1110
+ if (! $upload_dir) {
1111
+ $upload_info = wp_upload_dir();
1112
+ $siteurl = w3_get_site_url();
1113
+ $upload_dir = trim(str_replace($siteurl, '', $upload_info['baseurl']), '/');
1114
+ }
1115
+
1116
+ return $upload_dir;
1117
  }
1118
 
1119
  /**
lib/W3/Plugin/DbCache.php CHANGED
@@ -48,12 +48,14 @@ class W3_Plugin_DbCache extends W3_Plugin
48
  */
49
  function activate()
50
  {
51
- $file_db = WP_CONTENT_DIR . '/db.php';
52
-
53
- if (@copy(W3_PLUGIN_CONTENT_DIR . '/db.php', $file_db)) {
54
- @chmod($file_db, 0666);
55
- } else {
56
- w3_writable_error($file_db);
 
 
57
  }
58
  }
59
 
@@ -62,6 +64,8 @@ class W3_Plugin_DbCache extends W3_Plugin
62
  */
63
  function deactivate()
64
  {
65
- @unlink(WP_CONTENT_DIR . '/db.php');
 
 
66
  }
67
  }
48
  */
49
  function activate()
50
  {
51
+ if (! $this->locked()) {
52
+ $file_db = WP_CONTENT_DIR . '/db.php';
53
+
54
+ if (@copy(W3_PLUGIN_CONTENT_DIR . '/db.php', $file_db)) {
55
+ @chmod($file_db, 0666);
56
+ } else {
57
+ w3_writable_error($file_db);
58
+ }
59
  }
60
  }
61
 
64
  */
65
  function deactivate()
66
  {
67
+ if (! $this->locked()) {
68
+ @unlink(WP_CONTENT_DIR . '/db.php');
69
+ }
70
  }
71
  }
lib/W3/Plugin/Minify.php CHANGED
@@ -72,28 +72,30 @@ class W3_Plugin_Minify extends W3_Plugin
72
  */
73
  function activate()
74
  {
75
- if (! is_dir(W3_PLUGIN_MINIFY_MIN_DIR)) {
76
- if (@mkdir(W3_PLUGIN_MINIFY_MIN_DIR, 0777)) {
77
- @chmod(W3_PLUGIN_MINIFY_MIN_DIR, 0777);
 
 
 
 
 
 
 
 
 
 
78
  } else {
79
- w3_writable_error(W3_PLUGIN_MINIFY_MIN_DIR);
 
 
 
 
 
 
 
 
80
  }
81
- }
82
-
83
- $file_htaccess = W3_PLUGIN_MINIFY_MIN_DIR . '/.htaccess';
84
-
85
- if (@copy(W3_PLUGIN_MINIFY_MIN_CONTENT_DIR . '/.htaccess', $file_htaccess)) {
86
- @chmod($file_htaccess, 0666);
87
- } else {
88
- w3_writable_error($file_htaccess);
89
- }
90
-
91
- $file_index = W3_PLUGIN_MINIFY_MIN_DIR . '/index.php';
92
-
93
- if (@copy(W3_PLUGIN_MINIFY_MIN_CONTENT_DIR . '/index.php', $file_index)) {
94
- @chmod($file_index, 0666);
95
- } else {
96
- w3_writable_error($file_index);
97
  }
98
  }
99
 
@@ -102,18 +104,20 @@ class W3_Plugin_Minify extends W3_Plugin
102
  */
103
  function deactivate()
104
  {
105
- @unlink(W3_PLUGIN_MINIFY_MIN_DIR . '/.htaccess');
106
- @unlink(W3_PLUGIN_MINIFY_MIN_DIR . '/index.php');
107
-
108
- @unlink(W3_PLUGIN_MINIFY_MIN_DIR . '/include.css');
109
-
110
- @unlink(W3_PLUGIN_MINIFY_MIN_DIR . '/include.js');
111
- @unlink(W3_PLUGIN_MINIFY_MIN_DIR . '/include-nb.js');
112
-
113
- @unlink(W3_PLUGIN_MINIFY_MIN_DIR . '/include-footer.js');
114
- @unlink(W3_PLUGIN_MINIFY_MIN_DIR . '/include-footer-nb.js');
115
-
116
- @rmdir(W3_PLUGIN_MINIFY_MIN_DIR);
 
 
117
  }
118
 
119
  /**
@@ -191,6 +195,7 @@ class W3_Plugin_Minify extends W3_Plugin
191
  $urls = array();
192
 
193
  $groups = $this->_config->get_array('minify.css.groups');
 
194
 
195
  foreach ($groups as $config) {
196
  if (isset($config['files'])) {
@@ -198,7 +203,7 @@ class W3_Plugin_Minify extends W3_Plugin
198
  if (w3_is_url($file)) {
199
  $urls[] = $file;
200
  } else {
201
- $urls[] = get_option('siteurl') . '/' . $file;
202
  }
203
  }
204
  }
@@ -223,6 +228,7 @@ class W3_Plugin_Minify extends W3_Plugin
223
  $urls = array();
224
 
225
  $groups = $this->_config->get_array('minify.js.groups');
 
226
 
227
  foreach ($groups as $config) {
228
  if (isset($config['files'])) {
@@ -230,7 +236,7 @@ class W3_Plugin_Minify extends W3_Plugin
230
  if (w3_is_url($file)) {
231
  $urls[] = $file;
232
  } else {
233
- $urls[] = get_option('siteurl') . '/' . $file;
234
  }
235
  }
236
  }
@@ -376,11 +382,13 @@ class W3_Plugin_Minify extends W3_Plugin
376
  */
377
  function format_group_url($type, $group)
378
  {
 
 
379
  if ($this->_config->get_boolean('minify.rewrite', false)) {
380
- return sprintf('%s/%s/%s.%s', get_option('siteurl'), W3_PLUGIN_MINIFY_MIN_DIRNAME, $group, $type);
381
  }
382
 
383
- return sprintf('%s/%s/?t=%s&g=%s', get_option('siteurl'), W3_PLUGIN_MINIFY_MIN_DIRNAME, $type, $group);
384
  }
385
 
386
  /**
@@ -409,7 +417,8 @@ class W3_Plugin_Minify extends W3_Plugin
409
  }
410
  }
411
 
412
- $url = sprintf('%s/%s/?f=%s', get_option('siteurl'), W3_PLUGIN_MINIFY_MIN_DIRNAME, implode(',', $files));
 
413
 
414
  if ($base) {
415
  $url .= sprintf('&b=%s', $base);
72
  */
73
  function activate()
74
  {
75
+ if (! $this->locked()) {
76
+ if (! is_dir(W3_PLUGIN_MINIFY_MIN_DIR)) {
77
+ if (@mkdir(W3_PLUGIN_MINIFY_MIN_DIR, 0777)) {
78
+ @chmod(W3_PLUGIN_MINIFY_MIN_DIR, 0777);
79
+ } else {
80
+ w3_writable_error(W3_PLUGIN_MINIFY_MIN_DIR);
81
+ }
82
+ }
83
+
84
+ $file_htaccess = W3_PLUGIN_MINIFY_MIN_DIR . '/.htaccess';
85
+
86
+ if (@copy(W3_PLUGIN_MINIFY_MIN_CONTENT_DIR . '/.htaccess', $file_htaccess)) {
87
+ @chmod($file_htaccess, 0666);
88
  } else {
89
+ w3_writable_error($file_htaccess);
90
+ }
91
+
92
+ $file_index = W3_PLUGIN_MINIFY_MIN_DIR . '/index.php';
93
+
94
+ if (@copy(W3_PLUGIN_MINIFY_MIN_CONTENT_DIR . '/index.php', $file_index)) {
95
+ @chmod($file_index, 0666);
96
+ } else {
97
+ w3_writable_error($file_index);
98
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  }
100
  }
101
 
104
  */
105
  function deactivate()
106
  {
107
+ if (! $this->locked()) {
108
+ @unlink(W3_PLUGIN_MINIFY_MIN_DIR . '/.htaccess');
109
+ @unlink(W3_PLUGIN_MINIFY_MIN_DIR . '/index.php');
110
+
111
+ @unlink(W3_PLUGIN_MINIFY_MIN_DIR . '/include.css');
112
+
113
+ @unlink(W3_PLUGIN_MINIFY_MIN_DIR . '/include.js');
114
+ @unlink(W3_PLUGIN_MINIFY_MIN_DIR . '/include-nb.js');
115
+
116
+ @unlink(W3_PLUGIN_MINIFY_MIN_DIR . '/include-footer.js');
117
+ @unlink(W3_PLUGIN_MINIFY_MIN_DIR . '/include-footer-nb.js');
118
+
119
+ @rmdir(W3_PLUGIN_MINIFY_MIN_DIR);
120
+ }
121
  }
122
 
123
  /**
195
  $urls = array();
196
 
197
  $groups = $this->_config->get_array('minify.css.groups');
198
+ $siteurl = w3_get_site_url();
199
 
200
  foreach ($groups as $config) {
201
  if (isset($config['files'])) {
203
  if (w3_is_url($file)) {
204
  $urls[] = $file;
205
  } else {
206
+ $urls[] = $siteurl . '/' . $file;
207
  }
208
  }
209
  }
228
  $urls = array();
229
 
230
  $groups = $this->_config->get_array('minify.js.groups');
231
+ $siteurl = w3_get_site_url();
232
 
233
  foreach ($groups as $config) {
234
  if (isset($config['files'])) {
236
  if (w3_is_url($file)) {
237
  $urls[] = $file;
238
  } else {
239
+ $urls[] = $siteurl . '/' . $file;
240
  }
241
  }
242
  }
382
  */
383
  function format_group_url($type, $group)
384
  {
385
+ $siteurl = w3_get_site_url();
386
+
387
  if ($this->_config->get_boolean('minify.rewrite', false)) {
388
+ return sprintf('%s/%s/%s.%s', $siteurl, W3_PLUGIN_MINIFY_MIN_DIRNAME, $group, $type);
389
  }
390
 
391
+ return sprintf('%s/%s/?t=%s&g=%s', $siteurl, W3_PLUGIN_MINIFY_MIN_DIRNAME, $type, $group);
392
  }
393
 
394
  /**
417
  }
418
  }
419
 
420
+ $siteurl = w3_get_site_url();
421
+ $url = sprintf('%s/%s/?f=%s', $siteurl, W3_PLUGIN_MINIFY_MIN_DIRNAME, implode(',', $files));
422
 
423
  if ($base) {
424
  $url .= sprintf('&b=%s', $base);
lib/W3/Plugin/PgCache.php CHANGED
@@ -114,10 +114,12 @@ class W3_Plugin_PgCache extends W3_Plugin
114
  die('<strong>' . ABSPATH . 'wp-config.php</strong> could not be written, please edit config and add:<br /><strong style="color:#f00;">define(\'WP_CACHE\', true);</strong> before <strong style="color:#f00;">require_once(ABSPATH . \'wp-settings.php\');</strong><br />then re-activate plugin.');
115
  }
116
 
117
- if (@copy(W3_PLUGIN_CONTENT_DIR . '/advanced-cache.php', WP_CONTENT_DIR . '/advanced-cache.php')) {
118
- @chmod(WP_CONTENT_DIR . '/advanced-cache.php', 0666);
119
- } else {
120
- w3_writable_error(WP_CONTENT_DIR . '/advanced-cache.php');
 
 
121
  }
122
  }
123
 
@@ -126,7 +128,9 @@ class W3_Plugin_PgCache extends W3_Plugin
126
  */
127
  function deactivate()
128
  {
129
- @unlink(WP_CONTENT_DIR . '/advanced-cache.php');
 
 
130
  }
131
 
132
  /**
114
  die('<strong>' . ABSPATH . 'wp-config.php</strong> could not be written, please edit config and add:<br /><strong style="color:#f00;">define(\'WP_CACHE\', true);</strong> before <strong style="color:#f00;">require_once(ABSPATH . \'wp-settings.php\');</strong><br />then re-activate plugin.');
115
  }
116
 
117
+ if (! $this->locked()) {
118
+ if (@copy(W3_PLUGIN_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
+ }
123
  }
124
  }
125
 
128
  */
129
  function deactivate()
130
  {
131
+ if (! $this->locked()) {
132
+ @unlink(WP_CONTENT_DIR . '/advanced-cache.php');
133
+ }
134
  }
135
 
136
  /**
lib/W3/Plugin/TotalCache.php CHANGED
@@ -142,21 +142,13 @@ class W3_Plugin_TotalCache extends W3_Plugin
142
  */
143
  function activate()
144
  {
145
- $uploadsDir = WP_CONTENT_DIR . '/uploads';
146
-
147
- if (! is_dir($uploadsDir)) {
148
- if (@mkdir($uploadsDir, 0777)) {
149
- @chmod($uploadsDir, 0777);
150
  } else {
151
- w3_writable_error($uploadsDir);
152
  }
153
  }
154
-
155
- if (@copy(W3_CONFIG_DEFAULT_PATH, W3_CONFIG_PATH)) {
156
- @chmod(W3_CONFIG_PATH, 0666);
157
- } else {
158
- w3_writable_error(W3_CONFIG_PATH);
159
- }
160
  }
161
 
162
  /**
@@ -194,7 +186,7 @@ class W3_Plugin_TotalCache extends W3_Plugin
194
  */
195
  function plugin_action_links($links)
196
  {
197
- $links[] = '<a class="edit" href="options-general.php?page=' . W3_PLUGIN_FILE . '"><strong>Settings</strong></a>';
198
 
199
  return $links;
200
  }
@@ -425,6 +417,10 @@ class W3_Plugin_TotalCache extends W3_Plugin
425
  $config->set('cdn.debug', $debug);
426
  }
427
 
 
 
 
 
428
  $config->set('common.defaults', false);
429
 
430
  if ($config->save()) {
@@ -584,7 +580,7 @@ class W3_Plugin_TotalCache extends W3_Plugin
584
  $total = null;
585
  $results = array();
586
 
587
- $w3_plugin_cdn->export_library($limit, $offset, $count, $total, $results);
588
 
589
  echo sprintf("{limit: %d, offset: %d, count: %d, total: %s, results: [\r\n", $limit, $offset, $count, $total);
590
 
@@ -638,7 +634,7 @@ class W3_Plugin_TotalCache extends W3_Plugin
638
  $total = null;
639
  $results = array();
640
 
641
- $w3_plugin_cdn->import_library($limit, $offset, $count, $total, $results);
642
 
643
  echo sprintf("{limit: %d, offset: %d, count: %d, total: %s, results: [\r\n", $limit, $offset, $count, $total);
644
 
@@ -707,9 +703,14 @@ class W3_Plugin_TotalCache extends W3_Plugin
707
  $w3_plugin_cdn = & W3_Plugin_Cdn::instance();
708
 
709
  $files = W3_Request::get_array('files');
 
710
  $results = array();
711
 
712
- $w3_plugin_cdn->upload($files, false, $results);
 
 
 
 
713
 
714
  echo "{results: [\r\n";
715
 
142
  */
143
  function activate()
144
  {
145
+ if (! file_exists(W3_CONFIG_PATH)) {
146
+ if (@copy(W3_CONFIG_DEFAULT_PATH, W3_CONFIG_PATH)) {
147
+ @chmod(W3_CONFIG_PATH, 0666);
 
 
148
  } else {
149
+ w3_writable_error(W3_CONFIG_PATH);
150
  }
151
  }
 
 
 
 
 
 
152
  }
153
 
154
  /**
186
  */
187
  function plugin_action_links($links)
188
  {
189
+ $links[] = '<a class="edit" href="options-general.php?page=' . W3_PLUGIN_FILE . '">Settings</a>';
190
 
191
  return $links;
192
  }
417
  $config->set('cdn.debug', $debug);
418
  }
419
 
420
+ if ($tab == 'cdn' && ! $config->get('common.defaults') && $config->get('cdn.domain') == '') {
421
+ $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>';
422
+ }
423
+
424
  $config->set('common.defaults', false);
425
 
426
  if ($config->save()) {
580
  $total = null;
581
  $results = array();
582
 
583
+ @$w3_plugin_cdn->export_library($limit, $offset, $count, $total, $results);
584
 
585
  echo sprintf("{limit: %d, offset: %d, count: %d, total: %s, results: [\r\n", $limit, $offset, $count, $total);
586
 
634
  $total = null;
635
  $results = array();
636
 
637
+ @$w3_plugin_cdn->import_library($limit, $offset, $count, $total, $results);
638
 
639
  echo sprintf("{limit: %d, offset: %d, count: %d, total: %s, results: [\r\n", $limit, $offset, $count, $total);
640
 
703
  $w3_plugin_cdn = & W3_Plugin_Cdn::instance();
704
 
705
  $files = W3_Request::get_array('files');
706
+ $upload = array();
707
  $results = array();
708
 
709
+ foreach ($files as $file) {
710
+ $upload[$file] = $file;
711
+ }
712
+
713
+ @$w3_plugin_cdn->upload($upload, false, $results);
714
 
715
  echo "{results: [\r\n";
716
 
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.6
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,12 @@ Install the plugin to read the full FAQ.
112
 
113
  == Changelog ==
114
 
 
 
 
 
 
 
115
  = 0.6 =
116
  * Improved error message notifications
117
  * FAQ and installation instructions corrections/adjustments
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
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 =
116
+ * WordPress MU support bug fixes
117
+ * Minor CDN uploader fixes
118
+ * Added minify support for URIs starting with /
119
+ * Minor error message improvements
120
+
121
  = 0.6 =
122
  * Improved error message notifications
123
  * FAQ and installation instructions corrections/adjustments
w3-total-cache.php CHANGED
@@ -1,8 +1,8 @@
1
  <?php
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 functionality and more to WordPress.
5
- Version: 0.6
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
1
  <?php
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
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
@@ -1,14 +1,20 @@
1
  <?php
2
 
3
  error_reporting(E_ALL ^ E_NOTICE);
 
4
 
5
  /**
6
  * W3 Total Cache Minify module
7
  */
 
 
 
 
8
  if (! defined('W3_PLUGIN_DIR')) {
9
  define('W3_PLUGIN_DIR', dirname(__FILE__) . '/../plugins/w3-total-cache');
10
  }
11
 
 
12
  require_once W3_PLUGIN_DIR . '/inc/define.php';
13
  require_once W3_PLUGIN_DIR . '/lib/W3/Minify.php';
14
 
1
  <?php
2
 
3
  error_reporting(E_ALL ^ E_NOTICE);
4
+ ini_set('display_errors', 'On');
5
 
6
  /**
7
  * W3 Total Cache Minify module
8
  */
9
+ if (! defined('ABSPATH')) {
10
+ define('ABSPATH', dirname(__FILE__) . '/../../');
11
+ }
12
+
13
  if (! defined('W3_PLUGIN_DIR')) {
14
  define('W3_PLUGIN_DIR', dirname(__FILE__) . '/../plugins/w3-total-cache');
15
  }
16
 
17
+ require_once ABSPATH . 'wp-config.php';
18
  require_once W3_PLUGIN_DIR . '/inc/define.php';
19
  require_once W3_PLUGIN_DIR . '/lib/W3/Minify.php';
20