W3 Total Cache - Version 0.9.0

Version Description

  • Added preview feature so all cache settings can be reviewed prior to deployment
  • Added minify configuration wizard (help button on minify tab)
  • Added "never cache the following pages" to database and object cache
  • Added minify option to JavaScript embed after <body>
  • Added minify error notifications
  • Added drag and drop dependency resolution for minify CSS / JavaScript groups
  • Added object caching
  • Added option to automatically page cache prime (preload) with or without XML sitemap
  • Added support for multiple CNAMEs to CDN
  • Added support for minifcation of any respective theme installed a single site
  • Added support for page caching of multiple themes for various user agent groups
  • Added support for theme switching / redirection based on groups of user agents
  • Added compatibility with WP Super Cache fragment caching method (disk basic mode only)
  • Added HTTP compression and headers for AWS S3
  • Added ignored comment stems field, with Google AdSense default value to HTML minify
  • Added support for varnish purging
  • Added Rackspace CloudFiles support
  • Added native NetDNA / MaxCDN integration
  • Added option to cache 404 pages
  • Added changed files auto-upload to CDN
  • Added option to handle 404 errors for static objects directly with the web server
  • Added support for gravity forms to database cache default settings
  • Added changed file auto-upload to CDN
  • Database connection errors now return internal server (500) error response and are thus not cached
  • Incomplete plugin installation / removal no longer generates public errors
  • Unterminated string errors no longer display publicly
  • Support tab improvements
  • Install tab improvements
  • Resolved conflicts with disk enhanced .htaccess directives insertion
  • Improved compatibility with all mobile plugins
  • Improved AWS reliability
  • Improved browser caching support and management
  • Improved directory management for disk caching methods for increased performance
  • Improved handling of missing minify files
  • Improved Media Library import
  • Improved Multi Site support
  • Improved SSL interoperability
Download this release

Release Info

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

Code changes from version 0.8.5.2 to 0.9.0

Files changed (90) hide show
  1. inc/css/lightbox.css +5 -7
  2. inc/css/options.css +193 -6
  3. inc/define.php +1145 -537
  4. inc/email/minify_error_notification.html +7 -0
  5. inc/{options/support_email.phtml → email/support_request.phtml} +13 -3
  6. inc/images/logo.png +0 -0
  7. inc/images/logo_small.png +0 -0
  8. inc/js/lightbox.js +184 -30
  9. inc/js/options.js +681 -342
  10. inc/js/popup.js +26 -22
  11. inc/lightbox/minify_recommendations.phtml +130 -0
  12. inc/lightbox/self_test.phtml +343 -0
  13. inc/lightbox/support_us.phtml +1 -1
  14. inc/lightbox/tweet.phtml +3 -3
  15. inc/mime/all.php +624 -0
  16. inc/mime/cssjs.php +9 -0
  17. inc/mime/html.php +14 -0
  18. inc/{mime.php → mime/other.php} +31 -36
  19. inc/options/about.phtml +6 -7
  20. inc/options/browsercache.phtml +270 -0
  21. inc/options/cdn.phtml +59 -26
  22. inc/options/cdn/cf.phtml +33 -30
  23. inc/options/cdn/common/cnames.phtml +43 -0
  24. inc/options/cdn/ftp.phtml +45 -43
  25. inc/options/cdn/mirror.phtml +12 -7
  26. inc/options/cdn/netdna.phtml +24 -0
  27. inc/options/cdn/rscf.phtml +32 -0
  28. inc/options/cdn/s3.phtml +37 -33
  29. inc/options/common/header.phtml +28 -21
  30. inc/options/common/help.phtml +15 -0
  31. inc/options/dbcache.phtml +30 -20
  32. inc/options/faq.phtml +16 -569
  33. inc/options/faq.xml +701 -0
  34. inc/options/general.phtml +197 -69
  35. inc/options/install.phtml +275 -134
  36. inc/options/minify.phtml +184 -83
  37. inc/options/mobile.phtml +86 -0
  38. inc/options/objectcache.phtml +94 -0
  39. inc/options/pgcache.phtml +102 -44
  40. inc/options/support.phtml +26 -95
  41. inc/options/support/bug_report.phtml +80 -0
  42. inc/options/support/email_support.phtml +80 -0
  43. inc/options/support/linux_config.phtml +68 -0
  44. inc/options/support/new_feature.phtml +45 -0
  45. inc/options/support/phone_support.phtml +80 -0
  46. inc/options/support/plugin_config.phtml +76 -0
  47. inc/options/support/theme_config.phtml +76 -0
  48. inc/options/support_payment.phtml +33 -0
  49. inc/options/support_select.phtml +34 -0
  50. inc/popup/cdn_export_file.phtml +1 -1
  51. inc/popup/cdn_export_library.phtml +1 -1
  52. inc/popup/cdn_import_library.phtml +3 -3
  53. inc/popup/cdn_queue.phtml +4 -4
  54. inc/popup/cdn_rename_domain.phtml +1 -1
  55. inc/popup/common/header.phtml +3 -3
  56. ini/_htaccess +0 -126
  57. ini/apc.ini +2 -2
  58. ini/eaccelerator.ini +2 -1
  59. ini/xcache.ini +1 -1
  60. lib/CF/cacert.pem +3113 -0
  61. lib/CF/cloudfiles.php +2137 -0
  62. lib/CF/cloudfiles_exceptions.php +41 -0
  63. lib/CF/cloudfiles_http.php +1338 -0
  64. lib/Minify/HTTP/ConditionalGet.php +235 -185
  65. lib/Minify/HTTP/Encoder.php +2 -6
  66. lib/Minify/Minify.php +6 -7
  67. lib/Minify/Minify/CSS/Compressor.php +26 -2
  68. lib/Minify/Minify/CSS/UriRewriter.php +2 -2
  69. lib/Minify/Minify/Cache/File.php +10 -3
  70. lib/Minify/Minify/CombineOnly.php +1 -1
  71. lib/Minify/Minify/Controller/MinApp.php +1 -1
  72. lib/Minify/Minify/HTML.php +83 -55
  73. lib/S3.php +2 -5
  74. lib/W3/Cache/Apc.php +3 -3
  75. lib/W3/Cache/Base.php +3 -3
  76. lib/W3/Cache/Eaccelerator.php +3 -3
  77. lib/W3/Cache/File.php +44 -9
  78. lib/W3/Cache/File/Manager.php +6 -4
  79. lib/W3/Cache/File/PgCache.php +43 -6
  80. lib/W3/Cache/Memcached.php +3 -3
  81. lib/W3/Cache/Xcache.php +3 -3
  82. lib/W3/Cdn.php +30 -12
  83. lib/W3/Cdn/Base.php +315 -16
  84. lib/W3/Cdn/Cf.php +57 -21
  85. lib/W3/Cdn/Ftp.php +44 -34
  86. lib/W3/Cdn/Mirror.php +11 -21
  87. lib/W3/Cdn/Netdna.php +138 -0
  88. lib/W3/Cdn/Rscf.php +304 -0
  89. lib/W3/Cdn/S3.php +169 -54
  90. lib/W3/Config.php +362 -154
inc/css/lightbox.css CHANGED
@@ -3,7 +3,8 @@
3
  }
4
 
5
  .lightbox {
6
- background: #f9f9f9;
 
7
  padding: 10px 20px;
8
  border: 1px solid #bbb;
9
  border-radius: 11px;
@@ -12,10 +13,11 @@
12
  }
13
 
14
  .lightbox-close {
15
- cursor: hand;
16
  cursor: pointer;
 
17
  text-decoration: underline;
18
- float: right;
 
19
  }
20
 
21
  .lightbox-loader {
@@ -23,7 +25,3 @@
23
  background-position: center center;
24
  background-repeat: no-repeat;
25
  }
26
-
27
- .lightbox th {
28
- width: 80px;
29
- }
3
  }
4
 
5
  .lightbox {
6
+ position: absolute;
7
+ background: #fdfdfd;
8
  padding: 10px 20px;
9
  border: 1px solid #bbb;
10
  border-radius: 11px;
13
  }
14
 
15
  .lightbox-close {
 
16
  cursor: pointer;
17
+ position: absolute;
18
  text-decoration: underline;
19
+ top: 25px;
20
+ right: 20px;
21
  }
22
 
23
  .lightbox-loader {
25
  background-position: center center;
26
  background-repeat: no-repeat;
27
  }
 
 
 
 
inc/css/options.css CHANGED
@@ -5,10 +5,6 @@
5
  width: 36px
6
  }
7
 
8
- .w3tc-options-menu-selected {
9
- font-weight: 700
10
- }
11
-
12
  .w3tc-enabled {
13
  color: #090;
14
  font-weight: 700
@@ -36,6 +32,59 @@
36
  padding: 5px
37
  }
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  #w3tc acronym {
40
  border-bottom: 1px dotted #666
41
  }
@@ -53,6 +102,20 @@
53
  font-style: 400
54
  }
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  #w3tc h5 {
57
  margin: 0
58
  }
@@ -110,6 +173,7 @@
110
 
111
  #w3tc fieldset {
112
  margin: 1em 0;
 
113
  padding: 0 1em 1em 1em;
114
  border: 1px solid #bbb;
115
  border-radius: 11px;
@@ -122,12 +186,135 @@
122
  padding: 0;
123
  }
124
 
125
- #w3tc legend {
126
  color: #999;
127
  padding: 0 5px;
128
  font-weight: bold;
129
  }
130
 
131
- #cdn-general th {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  width: 400px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  }
5
  width: 36px
6
  }
7
 
 
 
 
 
8
  .w3tc-enabled {
9
  color: #090;
10
  font-weight: 700
32
  padding: 5px
33
  }
34
 
35
+ .w3tc-test-ok,.w3tc-test-warn,.w3tc-test-error {
36
+ font-weight: bold;
37
+ }
38
+
39
+ .w3tc-test-ok {
40
+ color: #090;
41
+ }
42
+
43
+ .w3tc-test-warn {
44
+ color: #f90;
45
+ }
46
+
47
+ .w3tc-test-error {
48
+ color: #f00;
49
+ }
50
+
51
+ #w3tc-help ul {
52
+ float: left;
53
+ width: 29%;
54
+ list-style-type: disc;
55
+ margin: 1em 2% 1em 2%;
56
+ }
57
+
58
+ #w3tc-help li {
59
+ margin: 0;
60
+ }
61
+
62
+ #w3tc-help a {
63
+ text-decoration: none;
64
+ }
65
+
66
+ #w3tc-help a:hover {
67
+ text-decoration: underline;
68
+ }
69
+
70
+ #w3tc-nav select {
71
+ background: #f9f9f9 !important;
72
+ border: 0;
73
+ color: #333;
74
+ font-size: 1em;
75
+ font-weight: bold;
76
+ }
77
+
78
+ #w3tc-nav optgroup {
79
+ background: #fff;
80
+ font-style: normal;
81
+ padding: 3px;
82
+ }
83
+
84
+ #w3tc-nav option {
85
+ background: #fff;
86
+ }
87
+
88
  #w3tc acronym {
89
  border-bottom: 1px dotted #666
90
  }
102
  font-style: 400
103
  }
104
 
105
+ #w3tc optgroup {
106
+ font-style: normal;
107
+ }
108
+
109
+ #w3tc optgroup option {
110
+ text-indent: 20px;
111
+ }
112
+
113
+ #w3tc h2 span {
114
+ font-size: 0.6em;
115
+ font-style: normal;
116
+ text-shadow: none;
117
+ }
118
+
119
  #w3tc h5 {
120
  margin: 0
121
  }
173
 
174
  #w3tc fieldset {
175
  margin: 1em 0;
176
+ background: #fdfdfd;
177
  padding: 0 1em 1em 1em;
178
  border: 1px solid #bbb;
179
  border-radius: 11px;
186
  padding: 0;
187
  }
188
 
189
+ #w3tc fieldset legend {
190
  color: #999;
191
  padding: 0 5px;
192
  font-weight: bold;
193
  }
194
 
195
+ #w3tc fieldset legend a:hover {
196
+ text-decoration: none;
197
+ }
198
+
199
+ #w3tc pre.code {
200
+ color: #000;
201
+ margin: 1em 0;
202
+ overflow: auto;
203
+ background: #eee;
204
+ padding: 12px 15px;
205
+ border: 1px solid #ccc;
206
+ }
207
+
208
+ #w3tc pre.console {
209
+ color: #ccc;
210
+ margin: 1em 0;
211
+ overflow: auto;
212
+ background: #000;
213
+ padding: 12px 15px;
214
+ border: 1px solid #ccc;
215
+ }
216
+
217
+ #w3tc-cdn-general th {
218
  width: 400px;
219
+ }
220
+
221
+ #cdn_cnames li {
222
+ padding: 5px;
223
+ cursor: ns-resize;
224
+ }
225
+
226
+ #cdn_cnames li:hover {
227
+ background: #f9f9f9;
228
+ }
229
+
230
+ #cdn_cnames li span {
231
+ color: #999;
232
+ }
233
+
234
+ #mobile_groups li {
235
+ cursor: ns-resize;
236
+ list-style: none;
237
+ background: #f9f9f9;
238
+ margin-bottom: 1em;
239
+ border-radius: 8px;
240
+ -webkit-border-radius: 8px;
241
+ -moz-border-radius: 8px;
242
+ }
243
+
244
+ #mobile_groups li:hover {
245
+ background: #f3f3f3;
246
+ }
247
+
248
+ #mobile_groups li table {
249
+ margin: 0;
250
+ }
251
+
252
+ .mobile_group {
253
+ font-weight: bold;
254
+ }
255
+
256
+ #recom_container,#self_test_container {
257
+ overflow: auto;
258
+ }
259
+
260
+ #self_test_container fieldset {
261
+ width: 70%;
262
+ }
263
+
264
+ .monospace {
265
+ font-family: monospace;
266
+ }
267
+
268
+ .w3tc-rules {
269
+ display: none;
270
+ margin: 1em 0;
271
+ padding: 0;
272
+ background: none;
273
+ }
274
+
275
+ .minify-files li {
276
+ padding: 2px;
277
+ cursor: ns-resize;
278
+ list-style: none;
279
+ }
280
+
281
+ .minify-files li:hover {
282
+ background: #f9f9f9;
283
+ }
284
+
285
+ .minify-files th,.minify-files td {
286
+ line-height: normal;
287
+ border: 0;
288
+ padding: 0;
289
+ margin: 0;
290
+ }
291
+
292
+ .minify-files th {
293
+ width: auto;
294
+ color: #aaa !important;
295
+ font-size: 10px;
296
+ font-weight: normal;
297
+ text-align: left;
298
+ }
299
+
300
+ .minify-files td {
301
+ font-size: 13px;
302
+ }
303
+
304
+ th.minify-files-add,td.minify-files-add {
305
+ width: 40px;
306
+ text-align: center;
307
+ }
308
+
309
+ .minify-files-exists input,.minify-files-exists select {
310
+ color: red;
311
+ }
312
+
313
+ #support_loading {
314
+ height: 32px;
315
+ background: url(../images/loader.gif) left center no-repeat;
316
+ padding-left: 38px;
317
+ line-height: 32px;
318
+ margin: 1em 0;
319
+ font-weight: bold;
320
  }
inc/define.php CHANGED
@@ -1,13 +1,15 @@
1
  <?php
2
 
3
- define('W3TC_VERSION', '0.8.5.2');
4
  define('W3TC_POWERED_BY', 'W3 Total Cache/' . W3TC_VERSION);
5
  define('W3TC_EMAIL', 'w3tc@w3-edge.com');
 
 
6
  define('W3TC_LINK_URL', 'http://www.w3-edge.com/wordpress-plugins/');
7
  define('W3TC_LINK_NAME', 'WordPress Plugins');
8
  define('W3TC_FEED_URL', 'http://feeds.feedburner.com/W3TOTALCACHE');
9
  define('W3TC_README_URL', 'http://plugins.trac.wordpress.org/browser/w3-total-cache/trunk/readme.txt?format=txt');
10
- define('W3TC_TWITTER_STATUS', 'I just optimized my #wordpress blog\'s #performance using the W3 Total Cache #plugin by @w3edge. Check it out! http://j.mp/A69xX');
11
  define('W3TC_SUPPORT_US_TIMEOUT', 2592000);
12
 
13
  define('W3TC_PHP5', PHP_VERSION >= 5);
@@ -18,56 +20,54 @@ define('W3TC_FILE', 'w3-total-cache/w3-total-cache.php');
18
  define('W3TC_LIB_DIR', W3TC_DIR . '/lib');
19
  define('W3TC_LIB_W3_DIR', W3TC_LIB_DIR . '/W3');
20
  define('W3TC_LIB_MINIFY_DIR', W3TC_LIB_DIR . '/Minify');
 
21
  define('W3TC_PLUGINS_DIR', W3TC_DIR . '/plugins');
22
  define('W3TC_INSTALL_DIR', W3TC_DIR . '/wp-content');
23
  define('W3TC_INSTALL_MINIFY_DIR', W3TC_INSTALL_DIR . '/w3tc/min');
24
 
25
- $GLOBALS['w3_reserved_blognames'] = array(
26
- 'page',
27
- 'comments',
28
- 'blog',
29
- 'wp-admin',
30
- 'wp-includes',
31
- 'wp-content',
32
- 'files',
33
- 'feed'
34
- );
35
-
36
  define('W3TC_BLOGNAME', w3_get_blogname());
37
- define('W3TC_PREFIX', (W3TC_BLOGNAME != '' ? '-' . W3TC_BLOGNAME : ''));
38
 
39
  defined('WP_CONTENT_DIR') || define('WP_CONTENT_DIR', realpath(W3TC_DIR . '/../..'));
 
40
  define('WP_CONTENT_DIR_NAME', basename(WP_CONTENT_DIR));
41
- define('W3TC_CONTENT_DIR_NAME', WP_CONTENT_DIR_NAME . '/w3tc' . W3TC_PREFIX);
42
- define('W3TC_CONTENT_DIR', ABSPATH . W3TC_CONTENT_DIR_NAME);
43
  define('W3TC_CONTENT_MINIFY_DIR_NAME', W3TC_CONTENT_DIR_NAME . '/min');
44
- define('W3TC_CONTENT_MINIFY_DIR', ABSPATH . W3TC_CONTENT_DIR_NAME . '/min');
45
  define('W3TC_CACHE_FILE_DBCACHE_DIR', W3TC_CONTENT_DIR . '/dbcache');
 
46
  define('W3TC_CACHE_FILE_PGCACHE_DIR', W3TC_CONTENT_DIR . '/pgcache');
47
  define('W3TC_CACHE_FILE_MINIFY_DIR', W3TC_CONTENT_DIR . '/min');
48
  define('W3TC_LOG_DIR', W3TC_CONTENT_DIR . '/log');
49
  define('W3TC_TMP_DIR', W3TC_CONTENT_DIR . '/tmp');
50
- define('W3TC_CONFIG_PATH', WP_CONTENT_DIR . '/w3-total-cache-config' . W3TC_PREFIX . '.php');
 
51
  define('W3TC_CONFIG_MASTER_PATH', WP_CONTENT_DIR . '/w3-total-cache-config.php');
52
  define('W3TC_MINIFY_LOG_FILE', W3TC_LOG_DIR . '/minify.log');
53
  define('W3TC_CDN_COMMAND_UPLOAD', 1);
54
  define('W3TC_CDN_COMMAND_DELETE', 2);
55
  define('W3TC_CDN_TABLE_QUEUE', 'w3tc_cdn_queue');
56
 
57
- ini_set('pcre.backtrack_limit', 4194304);
58
- ini_set('pcre.recursion_limit', 4194304);
 
 
59
 
60
  /**
61
  * W3 activate error
62
- *
63
  * @param string $error
64
  * @return void
65
  */
66
-
67
  function w3_activate_error($error)
68
  {
69
  $active_plugins = (array) get_option('active_plugins');
70
 
 
 
 
71
  $key = array_search(W3TC_FILE, $active_plugins);
72
 
73
  if ($key !== false) {
@@ -79,6 +79,7 @@ function w3_activate_error($error)
79
  do_action('deactivated_plugin', W3TC_FILE);
80
 
81
  update_option('active_plugins', $active_plugins);
 
82
  } else {
83
  do_action('deactivate_' . W3TC_FILE);
84
  }
@@ -112,64 +113,26 @@ function w3_writable_error($path)
112
  }
113
 
114
  /**
115
- * Returns current microtime
116
- *
117
- * @return float
118
- */
119
- function w3_microtime()
120
- {
121
- list ($usec, $sec) = explode(" ", microtime());
122
- return ((float) $usec + (float) $sec);
123
- }
124
-
125
- /**
126
- * Check if URL is valid
127
- *
128
- * @param string $url
129
- * @return boolean
130
  */
131
- function w3_is_url($url)
132
  {
133
- return preg_match('~^https?://~', $url);
 
 
134
  }
135
 
136
  /**
137
- * Decodes gzip-encoded string
138
  *
139
- * @param string $data
140
- * @return string
141
  */
142
- function w3_gzdecode($data)
143
  {
144
- $flags = ord(substr($data, 3, 1));
145
- $headerlen = 10;
146
- $extralen = 0;
147
-
148
- if ($flags & 4) {
149
- $extralen = unpack('v', substr($data, 10, 2));
150
- $extralen = $extralen[1];
151
- $headerlen += 2 + $extralen;
152
- }
153
-
154
- if ($flags & 8) {
155
- $headerlen = strpos($data, chr(0), $headerlen) + 1;
156
- }
157
-
158
- if ($flags & 16) {
159
- $headerlen = strpos($data, chr(0), $headerlen) + 1;
160
- }
161
-
162
- if ($flags & 2) {
163
- $headerlen += 2;
164
- }
165
-
166
- $unpacked = gzinflate(substr($data, $headerlen));
167
-
168
- if ($unpacked === FALSE) {
169
- $unpacked = $data;
170
- }
171
-
172
- return $unpacked;
173
  }
174
 
175
  /**
@@ -187,13 +150,13 @@ function w3_mkdir($path, $mask = 0755, $curr_path = '')
187
  $dirs = explode('/', $path);
188
 
189
  foreach ($dirs as $dir) {
190
- if (empty($dir)) {
191
  return false;
192
  }
193
 
194
  $curr_path .= ($curr_path == '' ? '' : '/') . $dir;
195
 
196
- if (! is_dir($curr_path)) {
197
  if (@mkdir($curr_path, $mask)) {
198
  @chmod($curr_path, $mask);
199
  } else {
@@ -207,7 +170,7 @@ function w3_mkdir($path, $mask = 0755, $curr_path = '')
207
 
208
  /**
209
  * Recursive remove dir
210
- *
211
  * @param string $path
212
  * @param array $exclude
213
  * @return void
@@ -217,11 +180,11 @@ function w3_rmdir($path, $exclude = array(), $remove = true)
217
  $dir = @opendir($path);
218
 
219
  if ($dir) {
220
- while (($entry = @readdir($dir))) {
221
  $full_path = $path . '/' . $entry;
222
 
223
- if ($entry != '.' && $entry != '..' && ! in_array($full_path, $exclude)) {
224
- if (is_dir($full_path)) {
225
  w3_rmdir($full_path, $exclude);
226
  } else {
227
  @unlink($full_path);
@@ -239,7 +202,7 @@ function w3_rmdir($path, $exclude = array(), $remove = true)
239
 
240
  /**
241
  * Recursive empty dir
242
- *
243
  * @param string $path
244
  * @param array $exclude
245
  * @return void
@@ -255,13 +218,14 @@ function w3_emptydir($path, $exclude = array())
255
  * @param string $content
256
  * @return boolean
257
  */
258
- function w3_is_xml($content)
259
  {
260
  return (stristr($content, '<?xml') !== false || stristr($content, '<html') !== false);
261
  }
262
 
263
  /**
264
  * Returns true if it's WPMU
 
265
  * @return boolean
266
  */
267
  function w3_is_wpmu()
@@ -275,191 +239,148 @@ function w3_is_wpmu()
275
  return $wpmu;
276
  }
277
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  /**
279
  * Returns true if WPMU uses vhosts
 
280
  * @return boolean
281
  */
282
  function w3_is_vhost()
283
  {
284
- return (defined('VHOST') && VHOST == 'yes');
285
  }
286
 
287
  /**
288
- * Detect WPMU blogname
289
  *
290
- * @return string
 
291
  */
292
- function w3_get_blogname()
293
  {
294
- static $blogname = null;
295
-
296
- if ($blogname === null) {
297
- if (w3_is_wpmu()) {
298
- $domain = w3_get_domain($_SERVER['HTTP_HOST']);
299
-
300
- if (w3_is_vhost()) {
301
- $blogname = $domain;
302
- } else {
303
- $uri = $_SERVER['REQUEST_URI'];
304
- $site_path = w3_get_site_path();
305
-
306
- if ($site_path != '' && strpos($uri, $site_path) === 0) {
307
- $uri = substr_replace($uri, '/', 0, strlen($site_path));
308
- }
309
-
310
- $blogname = w3_get_blogname_from_uri($uri);
311
-
312
- if ($blogname != '') {
313
- $blogname = $blogname . '.' . $domain;
314
- } else {
315
- $blogname = $domain;
316
- }
317
- }
318
- } else {
319
- $blogname = '';
320
- }
321
- }
322
-
323
- return $blogname;
324
  }
325
 
326
  /**
327
- * Returns blogname from URI
328
- *
329
- * @param string $uri
330
- * @param string
331
  */
332
- function w3_get_blogname_from_uri($uri)
333
  {
334
- global $w3_reserved_blognames;
335
-
336
- $blogname = '';
337
- $matches = null;
338
- $uri = strtolower($uri);
339
-
340
- if (preg_match('~^/([a-z0-9-]+)/~', $uri, $matches)) {
341
- $blogname = $matches[1];
342
-
343
- if (in_array($blogname, $w3_reserved_blognames) || file_exists($blogname)) {
344
- $blogname = '';
345
- }
346
  }
347
 
348
- return $blogname;
349
  }
350
 
351
  /**
352
- * Returns site url
353
- *
354
- * @return string
355
  */
356
- function w3_get_site_url()
357
  {
358
- static $site_url = null;
359
-
360
- if ($site_url === null) {
361
- if (function_exists('get_option')) {
362
- $site_url = get_option('siteurl');
363
- } else {
364
- $site_url = sprintf('http://%s%s', $_SERVER['HTTP_HOST'], w3_get_site_path());
365
- }
366
-
367
- $site_url = rtrim($site_url, '/');
368
- }
369
 
370
- return $site_url;
371
  }
372
 
373
  /**
374
- * Returns SSL site url
375
- *
376
- * @return string
 
377
  */
378
- function w3_get_site_url_ssl()
379
  {
380
- $site_url = w3_get_site_url();
381
-
382
- if (w3_is_https()) {
383
- $site_url = str_replace('http:', 'https:', $site_url);
384
- }
385
-
386
- return $site_url;
387
  }
388
 
389
  /**
390
- * Returns site url regexp
391
- *
392
- * @return string
393
  */
394
- function w3_get_site_url_regexp()
395
  {
396
- $site_url = w3_get_site_url();
397
- $domain = preg_replace('~https?://~i', '', $site_url);
398
- $regexp = 'https?://' . w3_preg_quote($domain);
399
- return $regexp;
400
  }
401
 
402
  /**
403
- * Returns blog path
404
- *
405
- * @return string
406
  */
407
- function w3_get_site_path()
408
  {
409
- $document_root = w3_get_document_root();
410
- $path = str_replace($document_root, '', w3_path(ABSPATH));
411
- $path = '/' . ltrim($path, '/');
412
-
413
- if (substr($path, - 1) != '/') {
414
- $path .= '/';
415
- }
416
-
417
- return $path;
418
  }
419
 
420
  /**
421
- * Returns blog path
422
  *
423
- * @return string
 
424
  */
425
- function w3_get_blog_path()
426
  {
427
- $domain_url = w3_get_domain_url();
428
- $site_url = w3_get_site_url();
429
 
430
- $path = str_replace($domain_url, '', $site_url);
431
- $path = '/' . ltrim($path, '/');
432
 
433
- if (substr($path, - 1) != '/') {
434
- $path .= '/';
 
 
 
 
 
 
435
  }
436
 
437
- return $path;
438
  }
439
 
440
  /**
441
- * Returns document root
442
- * @return string
 
 
443
  */
444
- function w3_get_document_root()
445
  {
446
- static $document_root = null;
447
-
448
- if ($document_root === null) {
449
- if (isset($_SERVER['DOCUMENT_ROOT'])) {
450
- $document_root = $_SERVER['DOCUMENT_ROOT'];
451
- } elseif (isset($_SERVER['SCRIPT_FILENAME'])) {
452
- $document_root = substr($_SERVER['SCRIPT_FILENAME'], 0, - strlen($_SERVER['PHP_SELF']));
453
- } elseif (isset($_SERVER['PATH_TRANSLATED'])) {
454
- $document_root = substr($_SERVER['PATH_TRANSLATED'], 0, - strlen($_SERVER['PHP_SELF']));
455
- } else {
456
- $document_root = ABSPATH;
457
- }
458
-
459
- $document_root = w3_path($document_root);
460
- }
461
 
462
- return $document_root;
463
  }
464
 
465
  /**
@@ -486,205 +407,651 @@ function w3_get_domain($host)
486
  }
487
 
488
  /**
489
- * Get domain URL
490
- *
491
- * @return string
492
  */
493
- function w3_get_domain_url()
494
  {
495
- $site_url = w3_get_site_url();
496
- $parse_url = @parse_url($site_url);
497
 
498
- if ($parse_url && isset($parse_url['scheme']) && isset($parse_url['host'])) {
499
- $scheme = $parse_url['scheme'];
500
- $host = $parse_url['host'];
501
- $port = (isset($parse_url['port']) && $parse_url['port'] != 80 ? ':' . (int) $parse_url['port'] : '');
502
- $domain_url = sprintf('%s://%s%s', $scheme, $host, $port);
 
 
503
 
504
- return $domain_url;
 
 
 
 
 
 
505
  }
506
 
507
- return false;
508
  }
509
 
510
  /**
511
- * Returns domain url regexp
512
- *
513
- * @return string
514
  */
515
- function w3_get_domain_url_regexp()
516
  {
517
- $domain_url = w3_get_domain_url();
518
- $domain = preg_replace('~https?://~i', '', $domain_url);
519
- $regexp = 'https?://' . w3_preg_quote($domain);
520
- return $regexp;
521
  }
522
 
523
  /**
524
- * Returns upload info
525
- *
526
- * @return array
 
527
  */
528
- function w3_upload_info()
529
  {
530
- static $upload_info = null;
 
 
531
 
532
- if ($upload_info === null) {
533
- $upload_info = @wp_upload_dir();
534
-
535
- if (empty($upload_info['error'])) {
536
- $site_url = w3_get_site_url();
537
- $upload_info['upload_url'] = trim(str_replace($site_url, '', $upload_info['baseurl']), '/');
538
- $upload_info['upload_dir'] = trim(str_replace(ABSPATH, '', $upload_info['basedir']), '/');
539
- } else {
540
- $upload_info = false;
541
- }
542
  }
543
 
544
- return $upload_info;
 
 
545
  }
546
 
547
  /**
548
- * Redirects to URL
549
- *
550
- * @param string $url
551
- * @param string $params
552
  * @return string
553
  */
554
- function w3_redirect($url = '', $params = array())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
555
  {
556
- $fragment = '';
 
557
 
558
- if ($url != '' && ($parse_url = @parse_url($url))) {
559
- $url = '';
560
-
561
- if (! empty($parse_url['scheme'])) {
562
- $url .= $parse_url['scheme'] . '://';
563
- }
564
-
565
- if (! empty($parse_url['user'])) {
566
- $url .= $parse_url['user'];
567
-
568
- if (! empty($parse_url['pass'])) {
569
- $url .= ':' . $parse_url['pass'];
570
- }
571
- }
572
-
573
- if (! empty($parse_url['host'])) {
574
- $url .= $parse_url['host'];
575
- }
576
-
577
- if (! empty($parse_url['port']) && $parse_url['port'] != 80) {
578
- $url .= ':' . (int) $parse_url['port'];
579
- }
580
-
581
- $url .= (! empty($parse_url['path']) ? $parse_url['path'] : '/');
582
-
583
- if (! empty($parse_url['query'])) {
584
- $old_params = array();
585
- parse_str($parse_url['query'], $old_params);
586
-
587
- $params = array_merge($old_params, $params);
588
  }
589
-
590
- if (! empty($parse_url['fragment'])) {
591
- $fragment = '#' . $parse_url['fragment'];
 
592
  }
593
- } else {
594
- $parse_url = array();
595
  }
596
 
597
- if (($count = count($params))) {
598
- $query = '';
599
-
600
- foreach ($params as $param => $value) {
601
- $count--;
602
- $query .= urlencode($param) . (! empty($value) ? '=' . urlencode($value) : '') . ($count ? '&' : '');
603
- }
604
-
605
- $url .= (strpos($url, '?') === false ? '?' : '&') . $query;
606
- }
 
 
607
 
608
- if ($fragment != '') {
609
- $url .= $fragment;
610
  }
611
 
612
- @header('Location: ' . $url);
613
- exit();
614
  }
615
 
616
  /**
617
- * Returns caching engine name
618
  *
619
- * @param $engine
620
- * @return string
621
  */
622
- function w3_get_engine_name($engine)
623
  {
624
- switch ($engine) {
625
- case 'memcached':
626
- $engine_name = 'memcached';
627
- break;
628
-
629
- case 'apc':
630
- $engine_name = 'apc';
631
- break;
632
-
633
- case 'eaccelerator':
634
- $engine_name = 'eaccelerator';
635
- break;
636
-
637
- case 'xcache':
638
- $engine_name = 'xcache';
639
- break;
640
-
641
- case 'file':
642
- $engine_name = 'disk';
643
- break;
644
-
645
- case 'file_pgcache':
646
- $engine_name = 'disk (enhanced)';
647
- break;
648
-
649
- default:
650
- $engine_name = 'N/A';
651
- break;
652
  }
653
 
654
- return $engine_name;
655
  }
656
 
657
  /**
658
- * Converts value to boolean
659
  *
660
- * @param mixed $value
661
  * @return boolean
662
  */
663
- function w3_to_boolean($value)
664
  {
665
- if (is_string($value)) {
666
- switch (strtolower($value)) {
667
- case '+':
668
- case '1':
669
- case 'y':
670
- case 'on':
671
- case 'yes':
672
- case 'true':
673
- case 'enabled':
674
- return true;
675
-
676
- case '-':
677
- case '0':
678
- case 'n':
679
- case 'no':
680
- case 'off':
681
- case 'false':
682
- case 'disabled':
683
- return false;
684
  }
685
  }
686
 
687
- return (boolean) $value;
688
  }
689
 
690
  /**
@@ -694,28 +1061,38 @@ function w3_to_boolean($value)
694
  * @param string $url
695
  * @param string $data
696
  * @param string $auth
 
697
  * @return string
698
  */
699
- function w3_url_request($method, $url, $data = '', $auth = '')
700
  {
701
  $status = 0;
702
  $method = strtoupper($method);
703
 
704
- if (! function_exists('curl_init')) {
705
  $ch = curl_init();
706
 
707
  curl_setopt($ch, CURLOPT_URL, $url);
708
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
709
  curl_setopt($ch, CURLOPT_USERAGENT, W3TC_POWERED_BY);
710
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
 
711
  curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
 
 
712
 
713
- if ($method == 'POST') {
714
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
715
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
 
 
 
 
 
 
716
  }
717
 
718
- if (! empty($auth)) {
719
  curl_setopt($ch, CURLOPT_USERPWD, $auth);
720
  }
721
 
@@ -730,7 +1107,7 @@ function w3_url_request($method, $url, $data = '', $auth = '')
730
  if ($parse_url && isset($parse_url['host'])) {
731
  $host = $parse_url['host'];
732
  $port = (isset($parse_url['port']) ? (int) $parse_url['port'] : 80);
733
- $path = (! empty($parse_url['path']) ? $parse_url['path'] : '/');
734
  $query = (isset($parse_url['query']) ? $parse_url['query'] : '');
735
  $request_uri = $path . ($query != '' ? '?' . $query : '');
736
 
@@ -741,33 +1118,35 @@ function w3_url_request($method, $url, $data = '', $auth = '')
741
  'Connection: close'
742
  );
743
 
744
- if (! empty($data)) {
745
  $request_headers_array[] = sprintf('Content-Length: %d', strlen($data));
746
  }
747
 
748
- if (! empty($auth)) {
749
  $request_headers_array[] = sprintf('Authorization: Basic %s', base64_encode($auth));
750
  }
751
 
752
  $request_headers = implode("\r\n", $request_headers_array);
753
  $request = $request_headers . "\r\n\r\n" . $data;
 
 
754
 
755
- $fp = @fsockopen($host, $port);
756
 
757
- if (! $fp) {
758
  return false;
759
  }
760
 
761
  $response = '';
762
  @fputs($fp, $request);
763
 
764
- while (! @feof($fp)) {
765
  $response .= @fgets($fp, 4096);
766
  }
767
 
768
  @fclose($fp);
769
 
770
- list ($response_headers, $contents) = explode("\r\n\r\n", $response, 2);
771
 
772
  $matches = null;
773
 
@@ -777,7 +1156,7 @@ function w3_url_request($method, $url, $data = '', $auth = '')
777
  }
778
  }
779
 
780
- if ($status == 200) {
781
  return $contents;
782
  }
783
 
@@ -787,12 +1166,14 @@ function w3_url_request($method, $url, $data = '', $auth = '')
787
  /**
788
  * Download url via GET
789
  *
790
- * @param $url
 
 
791
  * @return string
792
  */
793
- function w3_url_get($url)
794
  {
795
- return w3_url_request('GET', $url);
796
  }
797
 
798
  /**
@@ -801,23 +1182,46 @@ function w3_url_get($url)
801
  * @param string $url
802
  * @param string $data
803
  * @param string $auth
 
 
 
 
 
 
 
 
 
 
 
 
 
804
  * @return string
805
  */
806
- function w3_url_post($url, $data = '', $auth = '')
807
  {
808
- return w3_url_request('POST', $url, $data, $auth);
 
 
 
 
 
 
 
 
 
 
809
  }
810
 
811
  /**
812
  * Downloads data to a file
813
- *
814
  * @param string $url
815
  * @param string $file
816
  * @return boolean
817
  */
818
  function w3_download($url, $file)
819
  {
820
- $data = w3_url_get($url);
821
 
822
  if ($data !== false) {
823
  return @file_put_contents($file, $data);
@@ -827,121 +1231,221 @@ function w3_download($url, $file)
827
  }
828
 
829
  /**
830
- * Loads plugins
831
  *
832
- * @return void
833
  */
834
- function w3_load_plugins()
835
  {
836
- $dir = @opendir(W3TC_PLUGINS_DIR);
837
 
838
- if ($dir) {
839
- while (($entry = @readdir($dir))) {
840
- if (strrchr($entry, '.') === '.php') {
841
- require_once W3TC_PLUGINS_DIR . '/' . $entry;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
842
  }
843
  }
844
- @closedir($dir);
845
- }
846
- }
847
-
848
- /**
849
- * Returns true if current connection is secure
850
- *
851
- * @return boolean
852
- */
853
- function w3_is_https()
854
- {
855
- switch (true) {
856
- case (isset($_SERVER['HTTPS']) && w3_to_boolean($_SERVER['HTTPS'])):
857
- case (isset($_SERVER['SERVER_PORT']) && (int) $_SERVER['SERVER_PORT'] == 443):
858
- return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
859
  }
860
 
861
- return false;
862
- }
863
-
864
- /**
865
- * Converts win path to unix
866
- * @param string $path
867
- * @return string
868
- */
869
- function w3_path($path)
870
- {
871
- $path = preg_replace('~[/\\\]+~', '/', $path);
872
- $path = rtrim($path, '/');
873
 
874
- return $path;
 
875
  }
876
 
877
  /**
878
- * Returns realpath of given path
879
  *
880
- * @param string $path
 
881
  */
882
- function w3_realpath($path)
883
  {
884
- $path = w3_path($path);
885
- $parts = explode('/', $path);
886
- $absolutes = array();
887
-
888
- foreach ($parts as $part) {
889
- if ('.' == $part) {
890
- continue;
891
- }
892
- if ('..' == $part) {
893
- array_pop($absolutes);
894
- } else {
895
- $absolutes[] = $part;
896
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
897
  }
898
 
899
- return implode('/', $absolutes);
900
  }
901
 
902
  /**
903
- * Returns open basedirs
904
  *
905
- * @return array
 
906
  */
907
- function w3_get_open_basedirs()
908
  {
909
- $open_basedir_ini = ini_get('open_basedir');
910
- $open_basedirs = (W3TC_WIN ? preg_split('~[;,]~', $open_basedir_ini) : explode(':', $open_basedir_ini));
911
- $result = array();
912
-
913
- foreach ($open_basedirs as $open_basedir) {
914
- $open_basedir = trim($open_basedir);
915
- if ($open_basedir != '') {
916
- $result[] = w3_realpath($open_basedir);
 
 
 
 
 
 
 
 
 
 
 
917
  }
918
  }
919
 
920
- return $result;
921
  }
922
 
923
  /**
924
- * Checks if path is restricted by open_basedir
925
  *
926
- * @param string $path
927
- * @return boolean
928
  */
929
- function w3_check_open_basedir($path)
930
  {
931
- $path = w3_realpath($path);
932
- $open_basedirs = w3_get_open_basedirs();
933
-
934
- if (! count($open_basedirs)) {
935
- return true;
936
- }
937
 
938
- foreach ($open_basedirs as $open_basedir) {
939
- if (strstr($path, $open_basedir) !== false) {
940
- return true;
 
 
941
  }
 
942
  }
943
-
944
- return false;
945
  }
946
 
947
  /**
@@ -952,23 +1456,70 @@ function w3_check_open_basedir($path)
952
  */
953
  function w3_get_mime_type($file)
954
  {
955
- $mime_types = include W3TC_DIR . '/inc/mime.php';
956
 
957
- $file_ext = strrchr($file, '.');
958
-
959
- if ($file_ext) {
960
- $file_ext = ltrim($file_ext, '.');
961
- foreach ($mime_types as $extension => $mime_type) {
962
- $exts = explode('|', $extension);
963
- foreach ($exts as $ext) {
964
- if ($file_ext == $ext) {
965
- return $mime_type;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
966
  }
 
 
967
  }
968
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
969
  }
970
 
971
- return false;
972
  }
973
 
974
  /**
@@ -985,7 +1536,7 @@ function w3_twitter_status_update($username, $password, $status, &$error)
985
  $data = sprintf('status=%s', urlencode($status));
986
  $auth = sprintf('%s:%s', $username, $password);
987
 
988
- $xml = w3_url_post('http://twitter.com/statuses/update.xml', $data, $auth);
989
 
990
  if ($xml) {
991
  $matches = null;
@@ -1006,7 +1557,7 @@ function w3_twitter_status_update($username, $password, $status, &$error)
1006
 
1007
  /**
1008
  * Quotes regular expression string
1009
- *
1010
  * @param string $regexp
1011
  * @return string
1012
  */
@@ -1020,56 +1571,9 @@ function w3_preg_quote($string, $delimiter = null)
1020
  return $string;
1021
  }
1022
 
1023
- /**
1024
- * Converts file path to relative
1025
- *
1026
- * @param string $file
1027
- * @return string
1028
- */
1029
- function w3_normalize_file($file)
1030
- {
1031
- if (w3_is_url($file)) {
1032
- if (strstr($file, '?') === false) {
1033
- $domain_url_regexp = '~' . w3_get_domain_url_regexp() . '~i';
1034
- $file = preg_replace($domain_url_regexp, '', $file);
1035
- }
1036
- } else {
1037
- $abspath = w3_path(ABSPATH);
1038
- $file = w3_path($file);
1039
- $file = str_replace($abspath, '', $file);
1040
- }
1041
-
1042
- $file = ltrim($file, '/');
1043
-
1044
- return $file;
1045
- }
1046
-
1047
- /**
1048
- * Translates URL to local path
1049
- * @param string $url
1050
- * @return string
1051
- */
1052
- function w3_translate_file($url)
1053
- {
1054
- if (! w3_is_url($url)) {
1055
- $url = w3_get_domain_url() . '/' . ltrim($url, '/\\');
1056
- }
1057
-
1058
- $site_url_regexp = '~' . w3_get_site_url_regexp() . '~i';
1059
-
1060
- if (preg_match($site_url_regexp, $url) && strstr($url, '?') === false) {
1061
- $url = preg_replace($site_url_regexp, '', $url);
1062
- $url = w3_get_site_path() . ltrim($url, '/\\');
1063
- }
1064
-
1065
- $url = ltrim($url, '/');
1066
-
1067
- return $url;
1068
- }
1069
-
1070
  /**
1071
  * Returns true if zlib output compression is enabled otherwise false
1072
- *
1073
  * @return boolean
1074
  */
1075
  function w3_zlib_output_compression()
@@ -1079,7 +1583,7 @@ function w3_zlib_output_compression()
1079
 
1080
  /**
1081
  * Recursive strips slahes from the var
1082
- *
1083
  * @param mixed $var
1084
  * @return mixed
1085
  */
@@ -1094,14 +1598,14 @@ function w3_stripslashes($var)
1094
  return $var;
1095
  }
1096
 
1097
- if (! function_exists('file_put_contents')) {
1098
- if (! defined('FILE_APPEND')) {
1099
  define('FILE_APPEND', 8);
1100
  }
1101
 
1102
  /**
1103
  * Puts contents to the file
1104
- *
1105
  * @param string $filename
1106
  * @param string $data
1107
  * @param integer $flags
@@ -1124,6 +1628,7 @@ if (! function_exists('file_put_contents')) {
1124
 
1125
  /**
1126
  * Cleanup .htaccess rules
 
1127
  * @param string $rules
1128
  * @return string
1129
  */
@@ -1137,24 +1642,127 @@ function w3_clean_rules($rules)
1137
  }
1138
 
1139
  /**
1140
- * Send powered by header
 
 
 
 
 
1141
  */
1142
- function w3_send_x_powered_by()
1143
  {
1144
- switch (true) {
1145
- case defined('DOING_AJAX'):
1146
- case defined('DOING_CRON'):
1147
- case defined('APP_REQUEST'):
1148
- case defined('XMLRPC_REQUEST'):
1149
- case defined('WP_ADMIN'):
1150
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1151
  }
1152
 
1153
- @header('X-Powered-By: ' . W3TC_POWERED_BY);
1154
  }
1155
 
1156
- if (w3_is_wpmu()) {
1157
- unset($_GET['sitewide']);
 
 
 
 
 
 
 
 
 
 
1158
  }
1159
 
1160
- w3_send_x_powered_by();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
 
3
+ define('W3TC_VERSION', '0.9b');
4
  define('W3TC_POWERED_BY', 'W3 Total Cache/' . W3TC_VERSION);
5
  define('W3TC_EMAIL', 'w3tc@w3-edge.com');
6
+ define('W3TC_PAYPAL_URL', 'https://www.paypal.com/cgi-bin/webscr');
7
+ define('W3TC_PAYPAL_BUSINESS', 'w3tc@w3-edge.com');
8
  define('W3TC_LINK_URL', 'http://www.w3-edge.com/wordpress-plugins/');
9
  define('W3TC_LINK_NAME', 'WordPress Plugins');
10
  define('W3TC_FEED_URL', 'http://feeds.feedburner.com/W3TOTALCACHE');
11
  define('W3TC_README_URL', 'http://plugins.trac.wordpress.org/browser/w3-total-cache/trunk/readme.txt?format=txt');
12
+ define('W3TC_TWITTER_STATUS', 'YES! I optimized my #wordpress site\'s #performance using the W3 Total Cache #plugin by @w3edge. Check it out! http://j.mp/A69xX');
13
  define('W3TC_SUPPORT_US_TIMEOUT', 2592000);
14
 
15
  define('W3TC_PHP5', PHP_VERSION >= 5);
20
  define('W3TC_LIB_DIR', W3TC_DIR . '/lib');
21
  define('W3TC_LIB_W3_DIR', W3TC_LIB_DIR . '/W3');
22
  define('W3TC_LIB_MINIFY_DIR', W3TC_LIB_DIR . '/Minify');
23
+ define('W3TC_LIB_CF_DIR', W3TC_LIB_DIR . '/CF');
24
  define('W3TC_PLUGINS_DIR', W3TC_DIR . '/plugins');
25
  define('W3TC_INSTALL_DIR', W3TC_DIR . '/wp-content');
26
  define('W3TC_INSTALL_MINIFY_DIR', W3TC_INSTALL_DIR . '/w3tc/min');
27
 
28
+ define('W3TC_BLOGNAMES_PATH', WP_CONTENT_DIR . '/w3-total-cache-blognames.php');
 
 
 
 
 
 
 
 
 
 
29
  define('W3TC_BLOGNAME', w3_get_blogname());
30
+ define('W3TC_SUFFIX', (W3TC_BLOGNAME != '' ? '-' . W3TC_BLOGNAME : ''));
31
 
32
  defined('WP_CONTENT_DIR') || define('WP_CONTENT_DIR', realpath(W3TC_DIR . '/../..'));
33
+ define('WP_CONTENT_DIR_PATH', dirname(WP_CONTENT_DIR));
34
  define('WP_CONTENT_DIR_NAME', basename(WP_CONTENT_DIR));
35
+ define('W3TC_CONTENT_DIR_NAME', WP_CONTENT_DIR_NAME . '/w3tc' . W3TC_SUFFIX);
36
+ define('W3TC_CONTENT_DIR', WP_CONTENT_DIR_PATH . '/' . W3TC_CONTENT_DIR_NAME);
37
  define('W3TC_CONTENT_MINIFY_DIR_NAME', W3TC_CONTENT_DIR_NAME . '/min');
38
+ define('W3TC_CONTENT_MINIFY_DIR', WP_CONTENT_DIR_PATH . '/' . W3TC_CONTENT_DIR_NAME . '/min');
39
  define('W3TC_CACHE_FILE_DBCACHE_DIR', W3TC_CONTENT_DIR . '/dbcache');
40
+ define('W3TC_CACHE_FILE_OBJECTCACHE_DIR', W3TC_CONTENT_DIR . '/objectcache');
41
  define('W3TC_CACHE_FILE_PGCACHE_DIR', W3TC_CONTENT_DIR . '/pgcache');
42
  define('W3TC_CACHE_FILE_MINIFY_DIR', W3TC_CONTENT_DIR . '/min');
43
  define('W3TC_LOG_DIR', W3TC_CONTENT_DIR . '/log');
44
  define('W3TC_TMP_DIR', W3TC_CONTENT_DIR . '/tmp');
45
+ define('W3TC_CONFIG_PATH', WP_CONTENT_DIR . '/w3-total-cache-config' . W3TC_SUFFIX . '.php');
46
+ define('W3TC_CONFIG_PREVIEW_PATH', WP_CONTENT_DIR . '/w3-total-cache-config' . W3TC_SUFFIX . '-preview.php');
47
  define('W3TC_CONFIG_MASTER_PATH', WP_CONTENT_DIR . '/w3-total-cache-config.php');
48
  define('W3TC_MINIFY_LOG_FILE', W3TC_LOG_DIR . '/minify.log');
49
  define('W3TC_CDN_COMMAND_UPLOAD', 1);
50
  define('W3TC_CDN_COMMAND_DELETE', 2);
51
  define('W3TC_CDN_TABLE_QUEUE', 'w3tc_cdn_queue');
52
 
53
+ @ini_set('pcre.backtrack_limit', 4194304);
54
+ @ini_set('pcre.recursion_limit', 4194304);
55
+
56
+ $_w3tc_actions = array();
57
 
58
  /**
59
  * W3 activate error
60
+ *
61
  * @param string $error
62
  * @return void
63
  */
 
64
  function w3_activate_error($error)
65
  {
66
  $active_plugins = (array) get_option('active_plugins');
67
 
68
+ // workaround for WPMU deactivation bug
69
+ remove_action('deactivate_' . W3TC_FILE, 'deactivate_sitewide_plugin');
70
+
71
  $key = array_search(W3TC_FILE, $active_plugins);
72
 
73
  if ($key !== false) {
79
  do_action('deactivated_plugin', W3TC_FILE);
80
 
81
  update_option('active_plugins', $active_plugins);
82
+
83
  } else {
84
  do_action('deactivate_' . W3TC_FILE);
85
  }
113
  }
114
 
115
  /**
116
+ * W3 Network activation error
117
+ *
118
+ * @return void
 
 
 
 
 
 
 
 
 
 
 
 
119
  */
120
+ function w3_network_activate_error()
121
  {
122
+ echo '<p><strong>W3 Total Cache Error:</strong> plugin cannot be activated network-wide.</p>';
123
+ echo '<p><a href="javascript:history.back(-1);">Back</a>';
124
+ exit();
125
  }
126
 
127
  /**
128
+ * Returns current microtime
129
  *
130
+ * @return float
 
131
  */
132
+ function w3_microtime()
133
  {
134
+ list($usec, $sec) = explode(" ", microtime());
135
+ return ((float) $usec + (float) $sec);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  }
137
 
138
  /**
150
  $dirs = explode('/', $path);
151
 
152
  foreach ($dirs as $dir) {
153
+ if ($dir == '') {
154
  return false;
155
  }
156
 
157
  $curr_path .= ($curr_path == '' ? '' : '/') . $dir;
158
 
159
+ if (!@is_dir($curr_path)) {
160
  if (@mkdir($curr_path, $mask)) {
161
  @chmod($curr_path, $mask);
162
  } else {
170
 
171
  /**
172
  * Recursive remove dir
173
+ *
174
  * @param string $path
175
  * @param array $exclude
176
  * @return void
180
  $dir = @opendir($path);
181
 
182
  if ($dir) {
183
+ while (($entry = @readdir($dir)) !== false) {
184
  $full_path = $path . '/' . $entry;
185
 
186
+ if ($entry != '.' && $entry != '..' && !in_array($full_path, $exclude)) {
187
+ if (@is_dir($full_path)) {
188
  w3_rmdir($full_path, $exclude);
189
  } else {
190
  @unlink($full_path);
202
 
203
  /**
204
  * Recursive empty dir
205
+ *
206
  * @param string $path
207
  * @param array $exclude
208
  * @return void
218
  * @param string $content
219
  * @return boolean
220
  */
221
+ function w3_is_xml(&$content)
222
  {
223
  return (stristr($content, '<?xml') !== false || stristr($content, '<html') !== false);
224
  }
225
 
226
  /**
227
  * Returns true if it's WPMU
228
+ *
229
  * @return boolean
230
  */
231
  function w3_is_wpmu()
239
  return $wpmu;
240
  }
241
 
242
+ /**
243
+ * Returns true if it's WP with enabled Network mode
244
+ *
245
+ * @return boolean
246
+ */
247
+ function w3_is_network_mode()
248
+ {
249
+ static $network_mode = null;
250
+
251
+ if ($network_mode === null) {
252
+ $network_mode = (defined('MULTISITE') && MULTISITE);
253
+ }
254
+
255
+ return $network_mode;
256
+ }
257
+
258
+ /**
259
+ * Returns if there is multisite mode
260
+ *
261
+ * @return boolean
262
+ */
263
+ function w3_is_multisite()
264
+ {
265
+ return (w3_is_wpmu() || w3_is_network_mode());
266
+ }
267
+
268
  /**
269
  * Returns true if WPMU uses vhosts
270
+ *
271
  * @return boolean
272
  */
273
  function w3_is_vhost()
274
  {
275
+ return ((defined('SUBDOMAIN_INSTALL') && SUBDOMAIN_INSTALL) || (defined('VHOST') && VHOST == 'yes'));
276
  }
277
 
278
  /**
279
+ * Check if URL is valid
280
  *
281
+ * @param string $url
282
+ * @return boolean
283
  */
284
+ function w3_is_url($url)
285
  {
286
+ return preg_match('~^https?://~', $url);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287
  }
288
 
289
  /**
290
+