W3 Total Cache - Version 0.9.2.10

Version Description

  • Added NetDNA / MaxCDN dashboard widget
  • Added zone dropdown for NetDNA and MaxCDN CDNs
  • Added create pull zone for NetDNA and MaxCDN CDNs
  • Added notification(s) if incompatible plugins are detected
  • Added "Disable CDN on the following pages" setting
  • Added "Disable CDN on SSL pages" setting
  • Added late init support for page cache's fragment caching
  • Added POT file
  • Added translations NL, PL
  • Fixed setenvif issue in htaccess rules
  • Fixed failed rewrite (404) and not caching feeds in nginx
  • Fixed NetDNA / MaxCDN CNAME purging issues and "Test CDN" functionality
  • Fixed Azure container handling
  • Fixed New Relic verification
  • Fixed theme preview
  • Fixed wrong path issue with w3tc-wp-loader.php
  • Fixed auto mode of Minify and filename lengths
  • Fixed purging monthly archives with Varnish
  • Fixed insert, delete, update quries purging with database cache
  • Fixed HTTP compression when dynamic page fragments are used
  • Fixed PHP_STRING and other warnings
  • Fixed case sensitive header detection
  • Fixed HEAD request handling
  • Fixed event scheduling propagation in Multi Site
  • Improved CDN custom file paths
  • Improved handling of legacy config files
  • Improved NetDNA / MaxCDN alias, key, secret string handling (backwards compatible)
  • Improved auto mode for minify file naming which was causing unncessary issues
  • Improved handling of hardcoded WordPress paths
  • Improved the file management functionality (FTP support, file permissions etc)
  • Improved disk cache directory usage
  • Improved garbage collection of expired cache files for disk enhanced method of page caching
  • Improved drop-in verification, only adds required drop-ins
  • Improved New Relic error notification handling
  • Improved New Relic "app name" settings with Multi Site
  • Improved cacheable mime type detection in Page Cache
  • Improved ob_callback performance and reduced number of output buffer calls
  • Improved minify handling with CDN and Multi Site
  • Improved Object Cache purge policy performance
  • Improved Database Cache purge policy performance
  • Improved handling of request methods other than GET, POST for page caching
  • Removed setting of New Relic app name in htaccess; set manually or use the dynamic setting on the "Monitoring" tab
Download this release

Release Info

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

Code changes from version 0.9.2.9 to 0.9.2.10

Files changed (144) hide show
  1. inc/define.php +133 -86
  2. inc/email/index.html +0 -0
  3. inc/email/minify_error_notification.html +0 -0
  4. inc/email/minify_error_notification.php +0 -0
  5. inc/email/support_request.php +0 -0
  6. inc/error.php +0 -0
  7. inc/functions/activation.php +442 -308
  8. inc/functions/compat.php +0 -0
  9. inc/functions/extract.php +0 -0
  10. inc/functions/file.php +53 -1
  11. inc/functions/http.php +0 -0
  12. inc/functions/ip_in_range.php +0 -0
  13. inc/functions/mime.php +0 -0
  14. inc/functions/multisite.php +9 -5
  15. inc/functions/other.php +61 -0
  16. inc/functions/plugin.php +51 -5
  17. inc/functions/rule.php +109 -0
  18. inc/functions/rule_cut.php +0 -0
  19. inc/functions/ui.php +31 -0
  20. inc/functions/update.php +0 -13
  21. inc/functions/url.php +0 -0
  22. inc/functions/widgets.php +0 -0
  23. inc/index.html +0 -0
  24. inc/lightbox/cdn_s3_bucket_location.php +2 -2
  25. inc/lightbox/create_netdna_maxcdn_pull_zone.php +35 -0
  26. inc/lightbox/index.html +0 -0
  27. inc/lightbox/minify_recommendations.php +22 -22
  28. inc/lightbox/self_test.php +81 -86
  29. inc/lightbox/support_us.php +10 -10
  30. inc/mime/all.php +0 -0
  31. inc/mime/cssjs.php +0 -0
  32. inc/mime/html.php +0 -0
  33. inc/mime/index.html +0 -0
  34. inc/mime/other.php +0 -0
  35. inc/options/about.php +23 -23
  36. inc/options/browsercache.php +108 -104
  37. inc/options/cdn.php +85 -67
  38. inc/options/cdn/akamai.php +14 -14
  39. inc/options/cdn/att.php +9 -9
  40. inc/options/cdn/azure.php +12 -12
  41. inc/options/cdn/cf.php +13 -13
  42. inc/options/cdn/cf2.php +13 -13
  43. inc/options/cdn/common/cnames.php +6 -6
  44. inc/options/cdn/common/index.html +0 -0
  45. inc/options/cdn/cotendo.php +11 -11
  46. inc/options/cdn/edgecast.php +10 -10
  47. inc/options/cdn/ftp.php +16 -16
  48. inc/options/cdn/index.html +0 -0
  49. inc/options/cdn/maxcdn.php +65 -0
  50. inc/options/cdn/mirror.php +8 -8
  51. inc/options/cdn/netdna.php +32 -21
  52. inc/options/cdn/rscf.php +13 -13
  53. inc/options/cdn/s3.php +14 -14
  54. inc/options/common/footer.php +0 -0
  55. inc/options/common/header.php +62 -63
  56. inc/options/common/help.php +1 -1
  57. inc/options/common/index.html +0 -0
  58. inc/options/dashboard.php +2 -3
  59. inc/options/dbcache.php +27 -27
  60. inc/options/enterprise/dbcluster-config.php +3 -6
  61. inc/options/enterprise/dbcluster_general_section.php +0 -0
  62. inc/options/faq.php +1 -1
  63. inc/options/general.php +242 -237
  64. inc/options/index.html +0 -0
  65. inc/options/install.php +72 -72
  66. inc/options/minify.php +131 -112
  67. inc/options/minify/ccjs.php +0 -0
  68. inc/options/minify/ccjs2.php +7 -7
  69. inc/options/minify/css.php +2 -2
  70. inc/options/minify/csstidy.php +10 -10
  71. inc/options/minify/csstidy2.php +17 -17
  72. inc/options/minify/html.php +1 -1
  73. inc/options/minify/htmltidy.php +2 -2
  74. inc/options/minify/htmltidy2.php +2 -2
  75. inc/options/minify/index.html +0 -0
  76. inc/options/minify/js.php +2 -2
  77. inc/options/minify/yuicss2.php +4 -4
  78. inc/options/minify/yuijs.php +3 -3
  79. inc/options/minify/yuijs2.php +5 -5
  80. inc/options/mobile.php +16 -16
  81. inc/options/new_relic.php +14 -1
  82. inc/options/objectcache.php +32 -19
  83. inc/options/pgcache.php +135 -97
  84. inc/options/pro/fragmentcache.php +21 -25
  85. inc/options/pro/fragmentcache_general_section.php +1 -1
  86. inc/options/referrer.php +15 -15
  87. inc/options/support.php +7 -2
  88. inc/options/support/form.php +6 -6
  89. inc/options/support/form/bug_report.php +21 -21
  90. inc/options/support/form/email_support.php +20 -20
  91. inc/options/support/form/index.html +0 -0
  92. inc/options/support/form/linux_config.php +18 -18
  93. inc/options/support/form/new_feature.php +12 -12
  94. inc/options/support/form/phone_support.php +20 -20
  95. inc/options/support/form/plugin_config.php +19 -19
  96. inc/options/support/form/theme_config.php +19 -19
  97. inc/options/support/index.html +0 -0
  98. inc/options/support/payment.php +5 -5
  99. inc/options/support/select.php +3 -3
  100. inc/popup/cdn_export_file.php +7 -7
  101. inc/popup/cdn_export_library.php +7 -7
  102. inc/popup/cdn_import_library.php +10 -10
  103. inc/popup/cdn_purge.php +10 -10
  104. inc/popup/cdn_queue.php +29 -29
  105. inc/popup/cdn_rename_domain.php +11 -11
  106. inc/popup/common/footer.php +0 -0
  107. inc/popup/common/header.php +0 -0
  108. inc/popup/common/index.html +0 -0
  109. inc/popup/index.html +0 -0
  110. inc/popup/pagespeed_results.php +7 -7
  111. inc/widget/index.html +0 -0
  112. inc/widget/latest.php +0 -0
  113. inc/widget/latest_ajax.php +0 -0
  114. inc/widget/latest_control.php +0 -0
  115. inc/widget/latest_news.php +0 -0
  116. inc/widget/latest_news_ajax.php +0 -0
  117. inc/widget/latest_news_control.php +0 -0
  118. inc/widget/maxcdn.php +58 -0
  119. inc/widget/maxcdn_signup.php +26 -0
  120. inc/widget/netdna.php +58 -0
  121. inc/widget/netdna_signup.php +25 -0
  122. inc/widget/new_relic.php +2 -13
  123. inc/widget/pagespeed.php +0 -0
  124. inc/widget/pagespeed_control.php +0 -0
  125. inc/widget/services.php +0 -0
  126. inc/widget/spreadtheword.php +0 -0
  127. index.html +0 -0
  128. ini/apc.ini +0 -0
  129. ini/dbcluster-config-sample.php +0 -0
  130. ini/eaccelerator.ini +0 -0
  131. ini/index.html +0 -0
  132. ini/memcache.ini +0 -0
  133. ini/nginx-network-sample-config.conf +0 -0
  134. ini/nginx-standalone-sample-config.conf +0 -0
  135. ini/php.append.ini +0 -0
  136. ini/s3-sample-policy.txt +0 -0
  137. ini/varnish-sample-config.vcl +0 -0
  138. ini/xcache.ini +0 -0
  139. languages/faq-en_US.xml +21 -12
  140. languages/faq-premium-en_US.xml +0 -0
  141. languages/w3-total-cache-nl_NL.mo +0 -0
  142. languages/w3-total-cache-nl_NL.po +6416 -0
  143. languages/w3-total-cache-pl_PL.po +3804 -0
  144. languages/w3-total-cache.pot +3614 -0
inc/define.php CHANGED
@@ -5,9 +5,10 @@ if (!defined('ABSPATH')) {
5
  }
6
 
7
  define('W3TC', true);
8
- define('W3TC_VERSION', '0.9.2.9');
9
  define('W3TC_POWERED_BY', 'W3 Total Cache/' . W3TC_VERSION);
10
  define('W3TC_EMAIL', 'w3tc@w3-edge.com');
 
11
  define('W3TC_PAYPAL_URL', 'https://www.paypal.com/cgi-bin/webscr');
12
  define('W3TC_PAYPAL_BUSINESS', 'w3tc-team@w3-edge.com');
13
  define('W3TC_LINK_URL', 'http://www.w3-edge.com/wordpress-plugins/');
@@ -17,9 +18,9 @@ define('W3TC_NEWS_FEED_URL', 'http://feeds.w3-edge.com/W3EDGE');
17
  define('W3TC_README_URL', 'http://plugins.svn.wordpress.org/w3-total-cache/trunk/readme.txt');
18
  define('W3TC_SUPPORT_US_TIMEOUT', 2592000);
19
  define('W3TC_SUPPORT_REQUEST_URL', 'http://www.w3-edge.com/?w3tc_support_request=1');
20
- define('NEWRELIC_SIGNUP_URL', 'https://rpm.newrelic.com/signup?product[level]=Standard&product[commitment]=Monthly&subscription[number_of_hosts]=1&partnership_id=295');
 
21
 
22
- define('W3TC_PHP5', PHP_VERSION >= 5);
23
  define('W3TC_WIN', (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'));
24
 
25
  defined('W3TC_DIR') || define('W3TC_DIR', realpath(dirname(__FILE__) . '/..'));
@@ -76,6 +77,8 @@ w3_require_once(W3TC_INC_DIR . '/functions/plugin.php');
76
  @ini_set('pcre.backtrack_limit', 4194304);
77
  @ini_set('pcre.recursion_limit', 4194304);
78
 
 
 
79
  /**
80
  * Returns current microtime
81
  *
@@ -275,7 +278,7 @@ function w3_is_nginx() {
275
  * @return boolean
276
  */
277
  function w3_is_cdn_engine($engine) {
278
- return in_array($engine, array('ftp', 's3', 'cf', 'cf2', 'rscf', 'azure', 'mirror', 'netdna',
279
  'cotendo', 'akamai', 'edgecast', 'att'));
280
  }
281
 
@@ -286,15 +289,16 @@ function w3_is_cdn_engine($engine) {
286
  * @return bool
287
  */
288
  function w3_is_cdn_mirror($engine) {
289
- return in_array($engine, array('mirror', 'netdna', 'cotendo', 'cf2', 'akamai', 'edgecast', 'att'));
290
  }
291
 
292
  /**
293
  * Returns true if CDN has purge all support
294
  * @param $engine
 
295
  */
296
  function w3_cdn_can_purge_all($engine) {
297
- return in_array($engine, array('cotendo', 'edgecast', 'att', 'netdna'));
298
  }
299
 
300
  /**
@@ -359,47 +363,16 @@ function w3_get_blog_id() {
359
  return $w3_current_blog_id;
360
  }
361
 
362
- $uri = w3_generate_request_uri();
363
-
364
- $w3_current_blog_id = w3_blogmap_get_blog_id($uri);
 
 
 
365
 
366
  return $w3_current_blog_id;
367
  }
368
 
369
- /**
370
- * @return string
371
- */
372
- function w3_generate_request_uri() {
373
- $host = w3_get_domain(w3_get_host());
374
- $site_home_uri = w3_get_base_path();
375
-
376
- // default path
377
- $uri = $host . $site_home_uri;
378
-
379
- if (!w3_is_subdomain_install()) {
380
- // try subdir blog
381
- $request_uri = rtrim($_SERVER['REQUEST_URI'], '/');
382
- $content_path = trim(substr(WP_CONTENT_DIR, strlen(w3_get_site_root())), '/');
383
- if (substr($request_uri, 1, strlen($content_path)) != $content_path && substr($request_uri, 0, strlen($site_home_uri)) == $site_home_uri) {
384
- $request_path_in_wp = '/' . substr($request_uri, strlen($site_home_uri));
385
-
386
- $n = strpos($request_path_in_wp, '/', 1);
387
- if ($n === false) {
388
- // case for homepage like /mywp/myblog
389
- // unfortunately catches also /index.php here and other pages
390
- // of "default" blog
391
- $blog_path_in_wp = substr($request_path_in_wp, 1);
392
- } else
393
- $blog_path_in_wp = substr($request_path_in_wp, 1, $n);
394
-
395
- $uri = $host . $site_home_uri . $blog_path_in_wp;
396
- return $uri;
397
- }
398
- return $uri;
399
- }
400
- return $uri;
401
- }
402
-
403
  /**
404
  * Returns blogmap filename by home url
405
  *
@@ -425,59 +398,81 @@ function w3_blogmap_filename($blog_home_url) {
425
  * Returns blog_id by home url
426
  * If database not initialized yet - returns 0
427
  *
428
- * @param string $blog_home_url
429
  * @return integer
430
  */
431
- function w3_blogmap_get_blog_id($blog_home_url) {
432
-
433
- $blog_data = w3_get_blogmap_data($blog_home_url);
434
- if ($blog_data && !is_int($blog_data))
435
- return substr($blog_data, 1);
436
 
437
- // we've faced new unknown yet url
 
 
 
 
438
 
439
- if (isset($GLOBALS['current_blog']))
440
- return $GLOBALS['current_blog']->blog_id;
441
-
442
- // use master config until data set and
443
- $GLOBALS['w3tc_blogmap_register_new_item'] = $blog_home_url;
444
-
445
- return 0;
446
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
447
 
448
- /**
449
- * @return bool
450
- */
451
- function w3_force_master() {
452
- if (!w3_is_multisite())
453
- return false;
454
- $blog_home_url = w3_generate_request_uri();
455
- $blog_data = w3_get_blogmap_data($blog_home_url);
456
- if (is_null($blog_data) || is_int($blog_data)) {
457
- // use master config until data set and
458
- $GLOBALS['w3tc_blogmap_register_new_item'] = $blog_home_url;
459
- return true;
460
  }
461
- return $blog_data[0] == 'm';
462
  }
463
 
464
- /**
465
- * @param $blog_home_url
466
- * @return null|string
467
- */
468
- function w3_get_blogmap_data($blog_home_url) {
469
- $filename = w3_blogmap_filename($blog_home_url);
470
 
471
  if (file_exists($filename)) {
472
  $data = file_get_contents($filename);
473
  $blog_data = @eval($data);
474
 
475
- if (is_array($blog_data) && isset($blog_data[$blog_home_url]))
476
- return $blog_data[$blog_home_url];
477
  }
478
  return null;
479
  }
480
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
481
  /**
482
  * Returns path to section's cache dir
483
  *
@@ -661,6 +656,19 @@ function w3_get_home_url_regexp() {
661
  return $regexp;
662
  }
663
 
 
 
 
 
 
 
 
 
 
 
 
 
 
664
  /**
665
  * Returns site URL
666
  *
@@ -979,7 +987,7 @@ function w3_can_check_rules() {
979
  * @return bool
980
  */
981
  function w3_can_cdn_purge($engine) {
982
- return in_array($engine, array('ftp', 's3', 'cf', 'cf2', 'rscf', 'azure', 'netdna', 'cotendo',
983
  'edgecast', 'akamai', 'att'));
984
  }
985
 
@@ -1162,19 +1170,51 @@ function w3_redirect($url = '', $params = array()) {
1162
  w3_require_once(W3TC_INC_DIR . '/functions/url.php');
1163
 
1164
  $url = w3_url_format($url, $params);
1165
- do_action('w3_redirect');
 
1166
 
1167
  @header('Location: ' . $url);
1168
  exit();
1169
  }
1170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1171
  /**
1172
  * Returns caching engine name
1173
  *
1174
  * @param $engine
1175
  * @return string
1176
  */
1177
- function w3_get_engine_name($engine) {
1178
  switch ($engine) {
1179
  case 'memcached':
1180
  $engine_name = 'memcached';
@@ -1197,7 +1237,10 @@ function w3_get_engine_name($engine) {
1197
  break;
1198
 
1199
  case 'file':
1200
- $engine_name = 'disk: basic';
 
 
 
1201
  break;
1202
 
1203
  case 'file_generic':
@@ -1233,7 +1276,11 @@ function w3_get_engine_name($engine) {
1233
  break;
1234
 
1235
  case 'netdna':
1236
- $engine_name = 'netdna / maxcdn';
 
 
 
 
1237
  break;
1238
 
1239
  case 'cotendo':
@@ -1415,7 +1462,7 @@ function w3_get_instance_id() {
1415
  /**
1416
  * Checks if post should be flushed or not. Returns true if it should not be flushed
1417
  * @param $post
1418
- * @param $module which cache module to check against (pgcache, varnish, cdncache, dbcache or objectcache)
1419
  * @param W3_Config $config
1420
  * @return bool
1421
  */
@@ -1491,4 +1538,4 @@ function w3_is_pro() {
1491
 
1492
  function w3_is_enterprise() {
1493
  return defined('W3TC_ENTERPRISE') && W3TC_ENTERPRISE;
1494
- }
5
  }
6
 
7
  define('W3TC', true);
8
+ define('W3TC_VERSION', '0.9.2.10');
9
  define('W3TC_POWERED_BY', 'W3 Total Cache/' . W3TC_VERSION);
10
  define('W3TC_EMAIL', 'w3tc@w3-edge.com');
11
+ define('W3TC_TEXT_DOMAIN', 'w3-total-cache');
12
  define('W3TC_PAYPAL_URL', 'https://www.paypal.com/cgi-bin/webscr');
13
  define('W3TC_PAYPAL_BUSINESS', 'w3tc-team@w3-edge.com');
14
  define('W3TC_LINK_URL', 'http://www.w3-edge.com/wordpress-plugins/');
18
  define('W3TC_README_URL', 'http://plugins.svn.wordpress.org/w3-total-cache/trunk/readme.txt');
19
  define('W3TC_SUPPORT_US_TIMEOUT', 2592000);
20
  define('W3TC_SUPPORT_REQUEST_URL', 'http://www.w3-edge.com/?w3tc_support_request=1');
21
+ define('NEWRELIC_SIGNUP_URL', 'https://rpm.newrelic.com/signup?product%5Blevel%5D=Standard&product%5Bcommitment%5D=Monthly&subscription%5Bnumber_of_hosts%5D=1&partnership_id=295');
22
+ define('MAXCDN_SIGNUP_URL', 'http://bit.ly/pXZ4t1');
23
 
 
24
  define('W3TC_WIN', (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'));
25
 
26
  defined('W3TC_DIR') || define('W3TC_DIR', realpath(dirname(__FILE__) . '/..'));
77
  @ini_set('pcre.backtrack_limit', 4194304);
78
  @ini_set('pcre.recursion_limit', 4194304);
79
 
80
+ global $w3_late_init;
81
+ $w3_late_init = false;
82
  /**
83
  * Returns current microtime
84
  *
278
  * @return boolean
279
  */
280
  function w3_is_cdn_engine($engine) {
281
+ return in_array($engine, array('ftp', 's3', 'cf', 'cf2', 'rscf', 'azure', 'mirror', 'netdna', 'maxcdn',
282
  'cotendo', 'akamai', 'edgecast', 'att'));
283
  }
284
 
289
  * @return bool
290
  */
291
  function w3_is_cdn_mirror($engine) {
292
+ return in_array($engine, array('mirror', 'netdna', 'maxcdn', 'cotendo', 'cf2', 'akamai', 'edgecast', 'att'));
293
  }
294
 
295
  /**
296
  * Returns true if CDN has purge all support
297
  * @param $engine
298
+ * @return bool
299
  */
300
  function w3_cdn_can_purge_all($engine) {
301
+ return in_array($engine, array('cotendo', 'edgecast', 'att', 'netdna', 'maxcdn'));
302
  }
303
 
304
  /**
363
  return $w3_current_blog_id;
364
  }
365
 
366
+
367
+ $blog_data = w3_blogmap_get_blog_data();
368
+ if (!is_null($blog_data))
369
+ $w3_current_blog_id = substr($blog_data, 1);
370
+ else
371
+ $w3_current_blog_id = 0;
372
 
373
  return $w3_current_blog_id;
374
  }
375
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
376
  /**
377
  * Returns blogmap filename by home url
378
  *
398
  * Returns blog_id by home url
399
  * If database not initialized yet - returns 0
400
  *
 
401
  * @return integer
402
  */
403
+ function w3_blogmap_get_blog_data() {
404
+ $host = w3_get_host();
 
 
 
405
 
406
+ // subdomain
407
+ if (w3_is_subdomain_install()) {
408
+ $blog_data = w3_blogmap_try_get_blog_data($host);
409
+ if (is_null($blog_data))
410
+ $GLOBALS['w3tc_blogmap_register_new_item'] = $host;
411
 
412
+ return $blog_data;
413
+ } else {
414
+ // try subdir blog
415
+ $url = $host . $_SERVER['REQUEST_URI'];
416
+ $pos = strpos($url, '?');
417
+ if ($pos !== false)
418
+ $url = substr($url, 0, $pos);
419
+
420
+ $url = rtrim($url, '/');
421
+ $start_url = $url;
422
+
423
+ for (;;) {
424
+ $blog_data = w3_blogmap_try_get_blog_data($url);
425
+ if (!is_null($blog_data))
426
+ return $blog_data;
427
+ $pos = strrpos($url, '/');
428
+ if ($pos === false)
429
+ break;
430
+
431
+ $url = rtrim(substr($url, 0, $pos), '/');
432
+ }
433
 
434
+ $GLOBALS['w3tc_blogmap_register_new_item'] = $start_url;
435
+ return null;
 
 
 
 
 
 
 
 
 
 
436
  }
 
437
  }
438
 
439
+
440
+
441
+ function w3_blogmap_try_get_blog_data($url) {
442
+ $filename = w3_blogmap_filename($url);
 
 
443
 
444
  if (file_exists($filename)) {
445
  $data = file_get_contents($filename);
446
  $blog_data = @eval($data);
447
 
448
+ if (is_array($blog_data) && isset($blog_data[$url]))
449
+ return $blog_data[$url];
450
  }
451
  return null;
452
  }
453
 
454
+ /**
455
+ * @return bool
456
+ */
457
+ function w3_force_master() {
458
+ global $w3_force_master;
459
+ if (!is_null($w3_force_master))
460
+ return $w3_force_master;
461
+
462
+ if (!w3_is_multisite())
463
+ $w3_force_master = false;
464
+ else {
465
+ $blog_data = w3_blogmap_get_blog_data();
466
+ if (is_null($blog_data) ||
467
+ ($blog_data[0] != 'm' && $blog_data[0] != 'c'))
468
+ $w3_force_master = true;
469
+ else
470
+ $w3_force_master = ($blog_data[0] == 'm');
471
+ }
472
+
473
+ return $w3_force_master;
474
+ }
475
+
476
  /**
477
  * Returns path to section's cache dir
478
  *
656
  return $regexp;
657
  }
658
 
659
+ /**
660
+ * Network installs returns wrong wp site path
661
+ * @return string
662
+ */
663
+ function w3_get_wp_sitepath() {
664
+ if (w3_is_network()) {
665
+ global $current_site;
666
+ return $current_site->path;
667
+ } else {
668
+ return w3_get_site_path();
669
+ }
670
+ }
671
+
672
  /**
673
  * Returns site URL
674
  *
987
  * @return bool
988
  */
989
  function w3_can_cdn_purge($engine) {
990
+ return in_array($engine, array('ftp', 's3', 'cf', 'cf2', 'rscf', 'azure', 'netdna', 'maxcdn', 'cotendo',
991
  'edgecast', 'akamai', 'att'));
992
  }
993
 
1170
  w3_require_once(W3TC_INC_DIR . '/functions/url.php');
1171
 
1172
  $url = w3_url_format($url, $params);
1173
+ if (function_exists('do_action'))
1174
+ do_action('w3_redirect');
1175
 
1176
  @header('Location: ' . $url);
1177
  exit();
1178
  }
1179
 
1180
+ /**
1181
+ * Redirects to URL
1182
+ *
1183
+ * @param string $url
1184
+ * @param array $params
1185
+ *
1186
+ * @return string
1187
+ */
1188
+ function w3_redirect_temp( $url = '', $params = array() ) {
1189
+ w3_require_once( W3TC_INC_DIR . '/functions/url.php' );
1190
+
1191
+ $url = w3_url_format( $url, $params );
1192
+ if (function_exists('do_action'))
1193
+ do_action( 'w3_redirect' );
1194
+
1195
+ $status_code = 301;
1196
+
1197
+ $protocol = $_SERVER["SERVER_PROTOCOL"];
1198
+ if ( 'HTTP/1.1' === $protocol ) {
1199
+ $status_code = 307;
1200
+ }
1201
+
1202
+ $text = get_status_header_desc( $status_code );
1203
+ if ( !empty( $text ) ) {
1204
+ $status_header = "$protocol $status_code $text";
1205
+ @header( $status_header, true, $status_code );
1206
+ }
1207
+ @header( 'Location: ' . $url, true, $status_code );
1208
+ exit();
1209
+ }
1210
+
1211
  /**
1212
  * Returns caching engine name
1213
  *
1214
  * @param $engine
1215
  * @return string
1216
  */
1217
+ function w3_get_engine_name($engine, $module = '') {
1218
  switch ($engine) {
1219
  case 'memcached':
1220
  $engine_name = 'memcached';
1237
  break;
1238
 
1239
  case 'file':
1240
+ if ($module == 'pgcache')
1241
+ $engine_name = 'disk: basic';
1242
+ else
1243
+ $engine_name = 'disk';
1244
  break;
1245
 
1246
  case 'file_generic':
1276
  break;
1277
 
1278
  case 'netdna':
1279
+ $engine_name = 'netdna';
1280
+ break;
1281
+
1282
+ case 'maxcdn':
1283
+ $engine_name = 'maxcdn';
1284
  break;
1285
 
1286
  case 'cotendo':
1462
  /**
1463
  * Checks if post should be flushed or not. Returns true if it should not be flushed
1464
  * @param $post
1465
+ * @param string $module which cache module to check against (pgcache, varnish, cdncache, dbcache or objectcache)
1466
  * @param W3_Config $config
1467
  * @return bool
1468
  */
1538
 
1539
  function w3_is_enterprise() {
1540
  return defined('W3TC_ENTERPRISE') && W3TC_ENTERPRISE;
1541
+ }
inc/email/index.html CHANGED
File without changes
inc/email/minify_error_notification.html CHANGED
File without changes
inc/email/minify_error_notification.php CHANGED
File without changes
inc/email/support_request.php CHANGED
File without changes
inc/error.php CHANGED
File without changes
inc/functions/activation.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
 
 
 
3
  /**
4
  * Deactivate plugin after activation error
5
  *
@@ -49,26 +51,9 @@ function w3_activate_error($error) {
49
  */
50
  function w3_activation_error_on_exception($e) {
51
  $reactivate_url = wp_nonce_url('plugins.php?action=activate&plugin=' . W3TC_FILE, 'activate-plugin_' . W3TC_FILE);
52
- $reactivate_button = sprintf('<input type="button" value="re-activate plugin" onclick="top.location.href = \'%s\'" />', addslashes($reactivate_url));
53
 
54
- w3_activate_error(sprintf('%s<br />then %s.', $e->getMessage(), $reactivate_button));
55
- }
56
-
57
- /**
58
- * W3 writable error
59
- *
60
- * @param string $path
61
- * @return string
62
- */
63
- function w3_writable_error($path) {
64
- $reactivate_url = wp_nonce_url('plugins.php?action=activate&plugin=' . W3TC_FILE, 'activate-plugin_' . W3TC_FILE);
65
- $reactivate_button = sprintf('<input type="button" value="re-activate plugin" onclick="top.location.href = \'%s\'" />', addslashes($reactivate_url));
66
-
67
- try {
68
- w3_throw_on_write_error($path);
69
- } catch (Exception $e) {
70
- w3_activation_error_on_exception($e);
71
- }
72
  }
73
 
74
  /**
@@ -81,13 +66,10 @@ function w3_throw_on_read_error($path) {
81
  w3_require_once(W3TC_INC_DIR . '/functions/file.php');
82
 
83
  if (w3_check_open_basedir($path)) {
84
- $error = sprintf('<strong>%s</strong> could not be read, please run following ' .
85
- 'command:<br /><strong style="color: #f00;">chmod 777 %s</strong>', $path,
86
  (file_exists($path) ? $path : dirname($path)));
87
  } else {
88
- $error = sprintf('<strong>%s</strong> could not be read, <strong>open_basedir' .
89
- '</strong> restriction in effect, please check your php.ini settings:<br />' .
90
- '<strong style="color: #f00;">open_basedir = "%s"</strong>', $path,
91
  ini_get('open_basedir'));
92
  }
93
 
@@ -107,20 +89,19 @@ function w3_throw_on_write_error($path, $chmod_dirs = array()) {
107
  if ($chmod_dirs) {
108
  $chmods = '<ul>';
109
  foreach($chmod_dirs as $dir) {
110
- $chmods .= sprintf('<li><strong style="color: #f00;">chmod 777 %s</strong></li>', $dir);
111
  }
112
  } else {
113
  $chmods = sprintf('<strong style="color: #f00;">chmod 777 %s</strong>',
114
  (file_exists($path) ? $path : dirname($path)));
115
  }
116
  if (w3_check_open_basedir($path)) {
117
- $error = sprintf('<strong>%s</strong> could not be created, please run following ' .
118
- 'command:<br />%s', $path,
119
  $chmods);
120
  } else {
121
- $error = sprintf('<strong>%s</strong> could not be created, <strong>open_basedir' .
122
- '</strong> restriction in effect, please check your php.ini settings:<br />' .
123
- '<strong style="color: #f00;">open_basedir = "%s"</strong>', $path,
124
  ini_get('open_basedir'));
125
  }
126
 
@@ -128,80 +109,59 @@ function w3_throw_on_write_error($path, $chmod_dirs = array()) {
128
  }
129
 
130
  /**
131
- * Creates cache folder and extension files.
132
- * Throws exception on failure.
133
  *
134
- * @throws Exception
 
 
 
 
 
 
135
  */
136
- function w3_activation_create_required_files() {
137
- /**
138
- * Check installation files
139
- */
140
- $files = array(
141
- W3TC_INSTALL_FILE_ADVANCED_CACHE,
142
- W3TC_INSTALL_FILE_DB,
143
- W3TC_INSTALL_FILE_OBJECT_CACHE);
144
-
145
- $nonexistent_files = array();
146
-
147
- foreach ($files as $file) {
148
- if (!file_exists($file)) {
149
- $nonexistent_files[] = $file;
150
- }
151
- }
152
 
153
- if (count($nonexistent_files)) {
154
- throw new Exception(sprintf('Unfortunately core file(s): (<strong>%s</strong>) ' .
155
- 'are missing, so activation will fail. Please re-start the installation ' .
156
- 'process from the beginning.', implode(', ', $nonexistent_files)));
 
157
  }
158
 
159
- $directories = array(
160
- W3TC_CACHE_DIR,
161
- W3TC_CONFIG_DIR,
162
- W3TC_CACHE_CONFIG_DIR,
163
- W3TC_CACHE_TMP_DIR);
164
-
165
- try{
166
- w3_wp_create_folders($directories, 'direct');
167
- } catch(Exception $ex) {}
168
  }
169
 
170
  /**
171
- * Copy file if destination does not exists or not equal
172
- *
173
- * @param string $source_filename
174
- * @param string $destination_filename
175
  * @param string $method Which method to use when creating
176
- * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
 
 
 
177
  * @throws FileOperationException
178
  */
179
- function w3_copy_if_not_equal($source_filename, $destination_filename, $method = 'direct') {
180
- if (@file_exists($destination_filename)) {
181
- $s = fopen($source_filename, 'rb');
182
- if ($s) {
183
- $v1 = fread($s, filesize($source_filename));
184
- fclose($s);
185
-
186
- $d = fopen($destination_filename, 'rb');
187
-
188
- if ($d) {
189
- if (filesize($destination_filename) <= 0)
190
- $v2 = '';
191
- else
192
- $v2 = fread($d, filesize($destination_filename));
193
-
194
- fclose($d);
195
-
196
- if ($v1 && $v2 && $v1 == $v2)
197
- return;
198
- }
199
- }
200
- }
201
 
202
- w3_wp_copy_file($source_filename, $destination_filename, $method);
203
- }
204
 
 
 
 
 
 
 
205
 
206
  /**
207
  * Copy file using WordPress filesystem functions.
@@ -210,10 +170,9 @@ function w3_copy_if_not_equal($source_filename, $destination_filename, $method =
210
  * @param string $method Which method to use when creating
211
  * @param string $url Where to redirect after creation
212
  * @param bool|string $context folder to copy files too
213
- * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
214
- * @throws FileOperationException
215
  */
216
- function w3_wp_copy_file($source_filename, $destination_filename, $method = '', $url = '', $context = false) {
217
  $contents = @file_get_contents($source_filename);
218
  if ($contents) {
219
  @file_put_contents($destination_filename, $contents);
@@ -223,13 +182,53 @@ function w3_wp_copy_file($source_filename, $destination_filename, $method = '',
223
  return;
224
  }
225
 
226
- w3_wp_request_filesystem_credentials($method, $url, $context);
 
 
 
 
 
 
227
 
228
  global $wp_filesystem;
229
- $contents = $wp_filesystem->get_contents($source_filename);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
 
231
- if (!$wp_filesystem->put_contents( $destination_filename, $contents, FS_CHMOD_FILE)) {
232
- throw new FileOperationException('Could not create file ' . $destination_filename, 'create', 'file', $destination_filename);
 
 
 
 
 
233
  }
234
  }
235
 
@@ -238,61 +237,82 @@ function w3_wp_copy_file($source_filename, $destination_filename, $method = '',
238
  * @param string $method Which method to use when creating
239
  * @param string $url Where to redirect after creation
240
  * @param bool|string $context folder to create folder in
241
- * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
242
  * @throws FileOperationException
243
  */
244
- function w3_wp_create_folder($folder, $method = '', $url = '', $context = false) {
245
- if (!@is_dir($folder) && !@w3_mkdir($folder)) {
246
- w3_wp_request_filesystem_credentials($method, $url, $context);
247
 
248
- global $wp_filesystem;
249
- if (!$wp_filesystem->mkdir($folder, FS_CHMOD_DIR)) {
250
- throw new FileOperationException('Could not create directory:' . $folder, 'create', 'folder', $folder);
251
- }
 
 
 
252
  }
253
  }
254
 
255
  /**
256
- * @param $folders
257
  * @param string $method Which method to use when creating
258
  * @param string $url Where to redirect after creation
259
  * @param bool|string $context path folder where delete folders resides
260
- * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
261
- * @throws FileOperationException
262
  */
263
- function w3_wp_delete_folders($folders, $method = '', $url = '', $context = false) {
264
- $delete_folders = array();
265
- foreach($folders as $folder) {
266
- if (is_dir($folder))
267
- $delete_folders[] = $folder;
268
- }
269
- if (empty($delete_folders))
270
  return;
271
 
272
- $removed = true;
273
- foreach ($delete_folders as $folder) {
274
- w3_rmdir($folder);
275
- if (@is_dir($folder))
276
- @rmdir($folder);
277
- if (@is_dir($folder)) {
278
- $removed = false;
279
- break;
280
- }
 
 
 
 
 
 
 
 
 
281
  }
 
282
 
283
- if ($removed)
 
 
 
 
 
 
 
284
  return;
285
- w3_wp_request_filesystem_credentials($method, $url, $context);
286
 
287
- global $wp_filesystem;
 
 
 
 
 
 
288
 
289
- foreach($delete_folders as $folder) {
290
- w3_rmdir($folder);
291
- if (file_exists($folder))
292
- if (!$wp_filesystem->rmdir($folder, FS_CHMOD_DIR)) {
293
- throw new FileOperationException('Could not delete directory: ' . $folder, 'delete', 'folder', $folder);
294
- }
 
295
  }
 
 
296
  }
297
 
298
  /**
@@ -300,18 +320,28 @@ function w3_wp_delete_folders($folders, $method = '', $url = '', $context = fals
300
  * @param string $method
301
  * @param string $url
302
  * @param bool|string $context folder where file to be deleted resides
303
- * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
304
- * @throws FileOperationException
305
  */
306
- function w3_wp_delete_file($file, $method = '', $url = '', $context = false) {
307
- if (!@unlink($file)) {
308
- w3_wp_request_filesystem_credentials($method, $url, false, $context = false);
 
 
309
 
310
- global $wp_filesystem;
 
 
 
 
 
311
 
312
- if (file_exists($file) && !$wp_filesystem->delete($file)) {
313
- throw new FileOperationException('Could not delete file: ' . $file, 'delete', 'file', $file);
314
- }
 
 
 
 
315
  }
316
  }
317
 
@@ -320,9 +350,14 @@ function w3_wp_delete_file($file, $method = '', $url = '', $context = false) {
320
  * @param string $method Which method to use when creating
321
  * @param string $url Where to redirect after creation
322
  * @param bool|string $context path to folder that should be have filesystem credentials. If false WP_CONTENT_DIR is assumed
323
- * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
324
  */
325
  function w3_wp_request_filesystem_credentials($method = '', $url = '', $context = false) {
 
 
 
 
 
326
  $success = true;
327
  ob_start();
328
  if (false === ($creds = request_filesystem_credentials($url, $method, false, $context, array()))) {
@@ -340,234 +375,333 @@ function w3_wp_request_filesystem_credentials($method = '', $url = '', $context
340
  }
341
  ob_end_clean();
342
 
 
 
 
 
 
 
343
  if (!$success) {
344
- throw new FilesystemCredentialException('Could not get write credentials', $method, $form);
345
  }
346
  }
347
 
348
  /**
349
- * Create files
350
- * @param $files array(from file => to file)
351
  * @param string $method
352
  * @param string $url
353
- * @param bool|string path to folder where files should be created
354
- * @throws FileOperationException
355
  */
356
- function w3_wp_create_files($files, $method = '', $url = '', $context = false) {
357
- if (empty($files))
358
- return;
 
 
 
 
359
 
360
- $created = true;
361
- foreach ($files as $source_filename => $destination_filename) {
362
- $contents = @file_get_contents($source_filename);
363
- if ($contents && !@file_put_contents($destination_filename, $contents)) {
364
- $created = false;
365
- break;
366
- }
367
  }
368
 
369
- if ($created)
370
- return;
371
 
372
- w3_wp_request_filesystem_credentials($method, $url, $context);
 
 
 
 
 
 
 
 
373
 
374
- global $wp_filesystem;
 
 
 
 
 
375
 
376
- foreach($files as $source_filename => $destination_filename) {
377
- $contents = $wp_filesystem->get_contents($source_filename);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
378
 
379
- if (file_exists($destination_filename) && ! $wp_filesystem->delete($destination_filename))
380
- throw new FileOperationException('Could not delete file: ' . $destination_filename, 'delete', 'file', $destination_filename);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
381
 
382
- if (!$wp_filesystem->put_contents($destination_filename, $contents, FS_CHMOD_FILE)) {
383
- throw new FileOperationException('Could not create file: ' . $destination_filename, 'create', 'file', $destination_filename);
 
 
 
384
  }
385
  }
 
 
 
 
 
 
 
 
 
 
 
386
  }
387
 
388
  /**
389
- * Create folders in wp content
390
- * @param $folders array(folderpath1, folderpath2, ...)
391
- * @param string $method
392
- * @param string $url
393
- * @param bool|string $context folder to create folders in
394
- * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
395
- * @throws FileOperationException
396
  */
397
- function w3_wp_create_folders($folders, $method = '', $url = '', $context = false) {
398
- if (empty($folders))
399
- return;
400
 
401
- $created = true;
402
- foreach ($folders as $folder) {
403
- if (!@is_dir($folder) && !@w3_mkdir_from($folder, WP_CONTENT_DIR)) {
404
- $created = false;
405
- break;
406
- }
407
  }
408
- if ($created)
409
- return;
410
-
411
- w3_wp_request_filesystem_credentials($method, $url, $context);
412
 
413
- global $wp_filesystem;
 
414
 
415
- foreach($folders as $folder) {
416
- if (!@is_dir($folder) && !$wp_filesystem->mkdir($folder, FS_CHMOD_DIR)) {
417
- throw new FileOperationException('Could not create directory:' . $folder, 'create', 'folder', $folder);
418
- }
419
  }
420
  }
421
 
422
- /**
423
- * Tries to write file content
424
- * @param string $filename path to file
425
- * @param string $content data to write
426
- * @param string $method Which method to use when creating
427
- * @param string $url Where to redirect after creation
428
- * @param bool|string $context folder in which to write file
429
- * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
430
- * @throws FileOperationException
431
- * @return bool;
432
- */
433
- function w3_wp_write_to_file($filename, $content, $method = '', $url = '', $context = false) {
434
- if (@file_put_contents($filename, $content))
435
- return true;
436
 
437
- w3_wp_request_filesystem_credentials($method, $url, $context);
438
- $permissions = array(0644, 0664, 0666);
439
- global $wp_filesystem;
440
- if (!$wp_filesystem->put_contents($filename, $content)) {
441
- foreach ($permissions as $permission) {
442
- try{
443
- w3_chmod_file($filename, $permission);
444
- if ($wp_filesystem->put_contents($filename, $content))
445
- return true;
446
- }catch (Exception $ex) {}
447
- }
448
- throw new FileOperationException('Could not write to file: ' . $filename, 'write', 'file', $filename);
 
 
449
  }
450
- return true;
451
  }
452
 
453
- /**
454
- * Tries to read file content
455
- * @param string $filename path to file
456
- * @param string $method Which method to use when creating
457
- * @param string $url Where to redirect after creation
458
- * @param bool|string $context folder to read from
459
- * @return mixed
460
- * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
461
- * @throws FileOperationException
462
- */
463
- function w3_wp_read_from_file($filename, $method = '', $url = '', $context = false) {
464
- $content = @file_get_contents($filename);
465
- if ($content)
466
- return $content;
467
 
468
- w3_wp_request_filesystem_credentials($method, $url, $context);
 
 
469
 
470
- global $wp_filesystem;
471
- if (!($content = $wp_filesystem->get_contents($filename))) {
472
- throw new FileOperationException('Could not read file: ' . $filename, 'write', 'file', $filename);
 
 
 
 
 
 
 
 
 
 
 
 
473
  }
474
- return $content;
475
  }
476
 
477
- /**
478
- * @param string $dir path to dir
479
- * @param int $permission
480
- * @param bool $recursive
481
- * @param string $method
482
- * @param string $url
483
- * @param bool|string $context folder where dir resides to chmod
484
- * @return bool
485
- * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
486
- * @throws FileOperationException
487
- */
488
- function w3_chmod_dir($dir, $permission, $recursive = false, $method = '', $url = '', $context = false) {
489
- if (!is_dir($dir) || !file_exists($dir))
490
- return false;
491
 
492
- if (@chmod($dir, $permission))
493
- return true;
 
494
 
495
- w3_wp_request_filesystem_credentials($method, $url, $context);
 
 
496
 
497
- global $wp_filesystem;
 
 
498
 
499
- if (!$wp_filesystem->chmod($dir, $permission, $recursive)) {
500
- throw new FileOperationException('Could not chmod dir: ' . $dir, 'chmod', 'dir', $dir);
501
  }
 
502
 
503
- return true;
 
 
 
 
 
 
 
 
 
 
 
504
  }
505
 
506
- /**
507
- * @param string $file path to file
508
- * @param $permission
509
- * @param string $method
510
- * @param string $url
511
- * @param bool|string $context
512
- * @return bool
513
- * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
514
- * @throws FileOperationException
515
- */
516
- function w3_chmod_file($file, $permission, $method = '', $url = '', $context = false) {
517
- if (!file_exists($file))
518
- return false;
519
- if (@chmod($file, $permission))
520
- return true;
521
 
522
- w3_wp_request_filesystem_credentials($method, $url, $context);
 
523
 
524
- global $wp_filesystem;
 
 
525
 
526
- if (!$wp_filesystem->chmod($file, $permission)) {
527
- throw new FileOperationException('Could not chmod file: ' . $file, 'chmod', 'file', $file);
528
  }
529
 
530
- return true;
 
 
531
  }
532
 
533
- /**
534
- * Creates maintenance mode file
535
- * @param $time
536
- */
537
- function w3_enable_maintenance_mode($time = null) {
538
- if (is_null($time))
539
- $time = 'time()';
540
- w3_wp_write_to_file(w3_get_site_root() . '/.maintenance', "<?php \$upgrading = $time; ?>");
 
 
 
 
541
  }
542
 
543
- /**
544
- * Deletes maintenance mode file
545
- */
546
- function w3_disable_maintenance_mode() {
547
- w3_wp_delete_file(w3_get_site_root() . '/.maintenance');
 
 
 
 
 
 
 
548
  }
549
 
550
- /**
551
- * Thrown when the plugin fails to get correct filesystem rights when it tries to modify manipulate filesystem.
552
- */
553
- class FilesystemCredentialException extends Exception
554
- {
555
- private $method_used;
556
- private $ftp_form;
557
 
558
- public function __construct($message, $method_used = 'direct', $ftp_form = '') {
559
  parent::__construct($message);
560
- $this->method_used = $method_used;
561
- $this->ftp_form = $ftp_form;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
562
  }
563
 
564
- public function method_used() {
565
- return $this->method_used;
 
 
 
 
 
 
 
 
 
566
  }
567
 
568
- public function ftp_form() {
569
- return $this->ftp_form;
 
570
 
 
 
571
  }
572
  }
573
 
1
  <?php
2
 
3
+ w3_require_once(W3TC_INC_DIR . '/functions/file.php');
4
+
5
  /**
6
  * Deactivate plugin after activation error
7
  *
51
  */
52
  function w3_activation_error_on_exception($e) {
53
  $reactivate_url = wp_nonce_url('plugins.php?action=activate&plugin=' . W3TC_FILE, 'activate-plugin_' . W3TC_FILE);
54
+ $reactivate_button = sprintf('%1$sre-activate plugin', '<input type="button" value="') . sprintf('" onclick="top.location.href = \'%s\'" />', addslashes($reactivate_url));
55
 
56
+ w3_activate_error(sprintf(__('%s<br />then %s.', 'w3-total-cache'), $e->getMessage(), $reactivate_button));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  }
58
 
59
  /**
66
  w3_require_once(W3TC_INC_DIR . '/functions/file.php');
67
 
68
  if (w3_check_open_basedir($path)) {
69
+ $error = sprintf(__('<strong>%s</strong> could not be read, please run following command:<br /><strong style="color: #f00;">chmod 777 %s</strong>', 'w3-total-cache'), $path,
 
70
  (file_exists($path) ? $path : dirname($path)));
71
  } else {
72
+ $error = sprintf(__('<strong>%s</strong> could not be read, <strong>open_basedir</strong> restriction in effect, please check your php.ini settings:<br /><strong style="color: #f00;">open_basedir = "%s"</strong>', 'w3-total-cache'), $path,
 
 
73
  ini_get('open_basedir'));
74
  }
75
 
89
  if ($chmod_dirs) {
90
  $chmods = '<ul>';
91
  foreach($chmod_dirs as $dir) {
92
+ $chmods .= sprintf(__('<li><strong style="color: #f00;">chmod 777 %s</strong></li>', 'w3-total-cache'), $dir);
93
  }
94
  } else {
95
  $chmods = sprintf('<strong style="color: #f00;">chmod 777 %s</strong>',
96
  (file_exists($path) ? $path : dirname($path)));
97
  }
98
  if (w3_check_open_basedir($path)) {
99
+ $error = sprintf(__('<strong>%s</strong> could not be created, please run following command:<br />%s', 'w3-total-cache'), $path,
 
100
  $chmods);
101
  } else {
102
+ $error = sprintf(__('<strong>%s</strong> could not be created, <strong>open_basedir
103
+ </strong> restriction in effect, please check your php.ini settings:<br />
104
+ <strong style="color: #f00;">open_basedir = "%s"</strong>', 'w3-total-cache'), $path,
105
  ini_get('open_basedir'));
106
  }
107
 
109
  }
110
 
111
  /**
112
+ * Tries to write file content
 
113
  *
114
+ * @param string $filename path to file
115
+ * @param string $content data to write
116
+ * @param string $method Which method to use when creating
117
+ * @param string $url Where to redirect after creation
118
+ * @param bool|string $context folder in which to write file
119
+ * @throws FilesystemWriteException
120
+ * @return void
121
  */
122
+ function w3_wp_write_to_file($filename, $content) {
123
+ if (@file_put_contents($filename, $content))
124
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
+ try {
127
+ w3_wp_request_filesystem_credentials();
128
+ } catch (FilesystemOperationException $ex) {
129
+ throw new FilesystemWriteException($ex->getMessage(),
130
+ $ex->credentials_form(), $filename, $content);
131
  }
132
 
133
+ global $wp_filesystem;
134
+ if (!$wp_filesystem->put_contents($filename, $content)) {
135
+ throw new FilesystemWriteException(
136
+ 'FTP credentials don\'t allow to write to file <strong>' .
137
+ $filename . '</strong>', w3_get_filesystem_credentials_form(),
138
+ $filename, $content);
139
+ }
 
 
140
  }
141
 
142
  /**
143
+ * Tries to read file content
144
+ * @param string $filename path to file
 
 
145
  * @param string $method Which method to use when creating
146
+ * @param string $url Where to redirect after creation
147
+ * @param bool|string $context folder to read from
148
+ * @return mixed
149
+ * @throws FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
150
  * @throws FileOperationException
151
  */
152
+ function w3_wp_read_from_file($filename) {
153
+ $content = @file_get_contents($filename);
154
+ if ($content)
155
+ return $content;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
 
157
+ w3_wp_request_filesystem_credentials();
 
158
 
159
+ global $wp_filesystem;
160
+ if (!($content = $wp_filesystem->get_contents($filename))) {
161
+ throw new FileOperationException('Could not read file: ' . $filename, 'write', 'file', $filename);
162
+ }
163
+ return $content;
164
+ }
165
 
166
  /**
167
  * Copy file using WordPress filesystem functions.
170
  * @param string $method Which method to use when creating
171
  * @param string $url Where to redirect after creation
172
  * @param bool|string $context folder to copy files too
173
+ * @throws FilesystemCopyException
 
174
  */
175
+ function w3_wp_copy_file($source_filename, $destination_filename) {
176
  $contents = @file_get_contents($source_filename);
177
  if ($contents) {
178
  @file_put_contents($destination_filename, $contents);
182
  return;
183
  }
184
 
185
+ try {
186
+ w3_wp_request_filesystem_credentials();
187
+ } catch (FilesystemOperationException $ex) {
188
+ throw new FilesystemCopyException($ex->getMessage(),
189
+ $ex->credentials_form(),
190
+ $source_filename, $destination_filename);
191
+ }
192
 
193
  global $wp_filesystem;
194
+ if (!$wp_filesystem->put_contents($destination_filename, $contents,
195
+ FS_CHMOD_FILE)) {
196
+ throw new FilesystemCopyException(
197
+ 'FTP credentials don\'t allow to copy to file <strong>' .
198
+ $destination_filename . '</strong>',
199
+ w3_get_filesystem_credentials_form(),
200
+ $source_filename, $destination_filename);
201
+ }
202
+ }
203
+
204
+ /**
205
+ * @param $folder
206
+ * @param string $method Which method to use when creating
207
+ * @param string $url Where to redirect after creation
208
+ * @param bool|string $context folder to create folder in
209
+ * @throws FilesystemMkdirException
210
+ */
211
+ function w3_wp_create_folder($folder, $from_folder) {
212
+ if (@is_dir($folder))
213
+ return;
214
+
215
+ if (w3_mkdir_from($folder, $from_folder))
216
+ return;
217
+
218
+ try {
219
+ w3_wp_request_filesystem_credentials();
220
+ } catch (FilesystemOperationException $ex) {
221
+ throw new FilesystemMkdirException($ex->getMessage(),
222
+ $ex->credentials_form(), $folder);
223
+ }
224
 
225
+ global $wp_filesystem;
226
+ if (!$wp_filesystem->mkdir($folder, FS_CHMOD_DIR)) {
227
+ throw new FilesystemMkdirException(
228
+ 'FTP credentials don\'t allow to create folder <strong>' .
229
+ $folder . '</strong>',
230
+ w3_get_filesystem_credentials_form(),
231
+ $folder);
232
  }
233
  }
234
 
237
  * @param string $method Which method to use when creating
238
  * @param string $url Where to redirect after creation
239
  * @param bool|string $context folder to create folder in
240
+ * @throws FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
241
  * @throws FileOperationException
242
  */
243
+ function w3_wp_create_writeable_folder($folder, $from_folder) {
244
+ w3_wp_create_folder($folder, $from_folder);
 
245
 
246
+ $permissions = array(0755, 0775, 0777);
247
+
248
+ for ($set_index = 0; $set_index < count($permissions); $set_index++) {
249
+ if (is_writable($folder))
250
+ break;
251
+
252
+ w3_wp_chmod($folder, $permissions[$set_index]);
253
  }
254
  }
255
 
256
  /**
257
+ * @param $folder
258
  * @param string $method Which method to use when creating
259
  * @param string $url Where to redirect after creation
260
  * @param bool|string $context path folder where delete folders resides
261
+ * @throws FilesystemRmdirException
 
262
  */
263
+ function w3_wp_delete_folder($folder) {
264
+ if (!@is_dir($folder))
 
 
 
 
 
265
  return;
266
 
267
+ w3_rmdir($folder);
268
+ if (!@is_dir($folder))
269
+ return;
270
+
271
+ try {
272
+ w3_wp_request_filesystem_credentials();
273
+ } catch (FilesystemOperationException $ex) {
274
+ throw new FilesystemRmdirException($ex->getMessage(),
275
+ $ex->credentials_form(), $folder);
276
+ }
277
+
278
+ global $wp_filesystem;
279
+ if (!$wp_filesystem->rmdir($folder)) {
280
+ throw new FilesystemRmdirException(
281
+ __('FTP credentials don\'t allow to delete folder ', 'w3-total-cache') .
282
+ '<strong>' . $folder . '</strong>',
283
+ w3_get_filesystem_credentials_form(),
284
+ $folder);
285
  }
286
+ }
287
 
288
+ /**
289
+ * @param string $filename
290
+ * @param int $permission
291
+ * @return void
292
+ * @throws FilesystemChmodException
293
+ */
294
+ function w3_wp_chmod($filename, $permission) {
295
+ if (@chmod($filename, $permission))
296
  return;
 
297
 
298
+
299
+ try {
300
+ w3_wp_request_filesystem_credentials();
301
+ } catch (FilesystemOperationException $ex) {
302
+ throw new FilesystemChmodException($ex->getMessage(),
303
+ $ex->credentials_form(), $filename, $permission);
304
+ }
305
 
306
+ global $wp_filesystem;
307
+ if (!$wp_filesystem->chmod($filename, $permission, true)) {
308
+ throw new FilesystemChmodException(
309
+ __('FTP credentials don\'t allow to chmod ', 'w3-total-cache') .
310
+ '<strong>' . $filename . '</strong>',
311
+ w3_get_filesystem_credentials_form(),
312
+ $filename, $permission);
313
  }
314
+
315
+ return true;
316
  }
317
 
318
  /**
320
  * @param string $method
321
  * @param string $url
322
  * @param bool|string $context folder where file to be deleted resides
323
+ * @throws FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
 
324
  */
325
+ function w3_wp_delete_file($filename) {
326
+ if (!@file_exists($filename))
327
+ return;
328
+ if (@unlink($filename))
329
+ return;
330
 
331
+ try {
332
+ w3_wp_request_filesystem_credentials();
333
+ } catch (FilesystemOperationException $ex) {
334
+ throw new FilesystemRmException($ex->getMessage(),
335
+ $ex->credentials_form(), $filename);
336
+ }
337
 
338
+ global $wp_filesystem;
339
+ if (!$wp_filesystem->delete($filename)) {
340
+ throw new FilesystemRmException(
341
+ __('FTP credentials don\'t allow to delete ', 'w3-total-cache') .
342
+ '<strong>' . $filename . '</strong>',
343
+ w3_get_filesystem_credentials_form(),
344
+ $filename);
345
  }
346
  }
347
 
350
  * @param string $method Which method to use when creating
351
  * @param string $url Where to redirect after creation
352
  * @param bool|string $context path to folder that should be have filesystem credentials. If false WP_CONTENT_DIR is assumed
353
+ * @throws FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials
354
  */
355
  function w3_wp_request_filesystem_credentials($method = '', $url = '', $context = false) {
356
+ if (strlen($url) <= 0)
357
+ $url = $_SERVER['REQUEST_URI'];
358
+ $url = preg_replace("/&w3tc_note=([^&]+)/", '', $url);
359
+
360
+
361
  $success = true;
362
  ob_start();
363
  if (false === ($creds = request_filesystem_credentials($url, $method, false, $context, array()))) {
375
  }
376
  ob_end_clean();
377
 
378
+ $error = '';
379
+ if (preg_match("/<div([^c]+)class=\"error\">(.+)<\/div>/", $form, $matches)) {
380
+ $error = $matches[2];
381
+ $form = str_replace($matches[0], '', $form);
382
+ }
383
+
384
  if (!$success) {
385
+ throw new FilesystemOperationException($error, $form);
386
  }
387
  }
388
 
389
  /**
 
 
390
  * @param string $method
391
  * @param string $url
392
+ * @param bool|string $context
393
+ * @return FilesystemOperationException with S/FTP form
394
  */
395
+ function w3_get_filesystem_credentials_form($method = '', $url = '',
396
+ $context = false) {
397
+ ob_start();
398
+ // If first check failed try again and show error message
399
+ request_filesystem_credentials($url, $method, true, false, array());
400
+ $success = false;
401
+ $form = ob_get_contents();
402
 
403
+ ob_end_clean();
404
+
405
+ $error = '';
406
+ if (preg_match("/<div([^c]+)class=\"error\">(.+)<\/div>/", $form, $matches)) {
407
+ $form = str_replace($matches[0], '', $form);
 
 
408
  }
409
 
410
+ return $form;
411
+ }
412
 
413
+ /**
414
+ * Creates maintenance mode file
415
+ * @param $time
416
+ */
417
+ function w3_enable_maintenance_mode($time = null) {
418
+ if (is_null($time))
419
+ $time = 'time()';
420
+ w3_wp_write_to_file(w3_get_site_root() . '/.maintenance', "<?php \$upgrading = $time; ?>");
421
+ }
422
 
423
+ /**
424
+ * Deletes maintenance mode file
425
+ */
426
+ function w3_disable_maintenance_mode() {
427
+ w3_wp_delete_file(w3_get_site_root() . '/.maintenance');
428
+ }
429
 
430
+ /**
431
+ * Used to display SelfTestExceptions in UI
432
+ * @param SelfTestExceptions
433
+ * @return array(before_errors = [], required_changes =>, later_errors => [])
434
+ **/
435
+ function w3_parse_selftest_exceptions($exs) {
436
+ $exceptions = $exs->exceptions();
437
+
438
+ $commands = '';
439
+ $required_changes = '';
440
+ $before_errors = array();
441
+ $later_errors = array();
442
+ $operation_error_already_shown = false;
443
+
444
+ foreach ($exceptions as $ex) {
445
+ if (!$operation_error_already_shown &&
446
+ $ex instanceof FilesystemOperationException) {
447
+ $m = $ex->getMessage();
448
+ if (strlen($m) > 0) {
449
+ $before_errors[] = $m;
450
+ // if multiple operations failed when
451
+ // they tried to fix environment - show only first
452
+ // otherwise can duplication information about
453
+ // absense of permissions
454
+ $operation_error_already_shown = true;
455
+ }
456
+ }
457
 
458
+ if ($ex instanceof FilesystemWriteException) {
459
+ $required_changes .=
460
+ sprintf(__('Create the <strong>%s</strong> file and paste the following text into it: <textarea>%s</textarea> <br />', 'w3-total-cache'), $ex->filename(), $ex->file_contents());
461
+ } else if ($ex instanceof FilesystemModifyException) {
462
+ $modification_content = $ex->file_contents();
463
+ if (strlen($modification_content) > 0)
464
+ $modification_content =
465
+ '<textarea style="height: 100px; width: 100%;">' .
466
+ $modification_content . '</textarea>';
467
+ $required_changes .=
468
+ $ex->modification_description() .
469
+ $modification_content .
470
+ '<br />';
471
+ } else if ($ex instanceof FilesystemCopyException) {
472
+ $commands .= 'cp ' . $ex->source_filename() . ' ' .
473
+ $ex->destination_filename() . '<br />';
474
+ } else if ($ex instanceof FilesystemMkdirException) {
475
+ $commands .= 'mkdir ' . $ex->folder() . '<br />';
476
+ $commands .= 'chmod 777 ' . $ex->folder() . '<br />';
477
+ } else if ($ex instanceof FilesystemRmException) {
478
+ $commands .= 'rm ' . $ex->filename() . '<br />';
479
+ } else if ($ex instanceof FilesystemRmdirException) {
480
+ $commands .= 'rm -rf ' . $ex->folder() . '<br />';
481
+ } else if ($ex instanceof FilesystemChmodException) {
482
+ $commands .= 'chmod 777 ' . $ex->filename() . '<br />';
483
+ } else if ($ex instanceof SelfTestFailedException) {
484
+ $t = $ex->technical_message();
485
+ if (strlen($t) > 0) {
486
+ $t = '<br />' .
487
+ '<a class="w3tc_read_technical_info" href="#">' .
488
+ __('Technical info', 'w3-total-cache').'</a>' .
489
+ '<div class="w3tc_technical_info" style="display: none">' .
490
+ $t . '</div>';
491
+ }
492
 
493
+ $later_errors[] =
494
+ $ex->getMessage() . $t;
495
+ } else {
496
+ // unknown command
497
+ $later_errors[] = $ex->getMessage();
498
  }
499
  }
500
+
501
+ if (strlen($commands) > 0) {
502
+ $required_changes .= __('Execute next commands in a shell:', 'w3-total-cache') .
503
+ '<br><strong>' . $commands . '</strong>';
504
+ }
505
+
506
+ return array(
507
+ 'before_errors' => $before_errors,
508
+ 'required_changes' => $required_changes,
509
+ 'later_errors' => $later_errors
510
+ );
511
  }
512
 
513
  /**
514
+ * Thrown when the plugin fails to get correct filesystem rights when it tries to modify manipulate filesystem.
 
 
 
 
 
 
515
  */
516
+ class FilesystemOperationException extends Exception {
517
+ private $credentials_form;
 
518
 
519
+ public function __construct($message, $credentials_form = null) {
520
+ parent::__construct($message);
521
+ $this->credentials_form = $credentials_form;
 
 
 
522
  }
 
 
 
 
523
 
524
+ public function credentials_form() {
525
+ return $this->credentials_form;
526
 
 
 
 
 
527
  }
528
  }
529
 
530
+ class FilesystemWriteException extends FilesystemOperationException {
531
+ private $filename;
532
+ private $file_contents;
 
 
 
 
 
 
 
 
 
 
 
533
 
534
+ public function __construct($message, $credentials_form, $filename,
535
+ $file_contents) {
536
+ parent::__construct($message, $credentials_form);
537
+
538
+ $this->filename = $filename;
539
+ $this->file_contents = $file_contents;
540
+ }
541
+
542
+ public function filename() {
543
+ return $this->filename;
544
+ }
545
+
546
+ public function file_contents() {
547
+ return $this->file_contents;
548
  }
 
549
  }
550
 
551
+ class FilesystemModifyException extends FilesystemOperationException {
552
+ private $modification_description;
553
+ private $filename;
554
+ private $file_contents;
 
 
 
 
 
 
 
 
 
 
555
 
556
+ public function __construct($message, $credentials_form,
557
+ $modification_description, $filename, $file_contents = '') {
558
+ parent::__construct($message, $credentials_form);
559
 
560
+ $this->modification_description = $modification_description;
561
+ $this->filename = $filename;
562
+ $this->file_contents = $file_contents;
563
+ }
564
+
565
+ function modification_description() {
566
+ return $this->modification_description;
567
+ }
568
+
569
+ public function filename() {
570
+ return $this->filename;
571
+ }
572
+
573
+ public function file_contents() {
574
+ return $this->file_contents;
575
  }
 
576
  }
577
 
578
+ class FilesystemCopyException extends FilesystemOperationException {
579
+ private $source_filename;
580
+ private $destination_filename;
 
 
 
 
 
 
 
 
 
 
 
581
 
582
+ public function __construct($message, $credentials_form,
583
+ $source_filename, $destination_filename) {
584
+ parent::__construct($message, $credentials_form);
585
 
586
+ $this->source_filename = $source_filename;
587
+ $this->destination_filename = $destination_filename;
588
+ }
589
 
590
+ public function source_filename() {
591
+ return $this->source_filename;
592
+ }
593
 
594
+ public function destination_filename() {
595
+ return $this->destination_filename;
596
  }
597
+ }
598
 
599
+ class FilesystemMkdirException extends FilesystemOperationException {
600
+ private $folder;
601
+
602
+ public function __construct($message, $credentials_form, $folder) {
603
+ parent::__construct($message, $credentials_form);
604
+
605
+ $this->folder = $folder;
606
+ }
607
+
608
+ public function folder() {
609
+ return $this->folder;
610
+ }
611
  }
612
 
613
+ class FilesystemChmodException extends FilesystemOperationException {
614
+ private $filename;
615
+ private $permission;
 
 
 
 
 
 
 
 
 
 
 
 
616
 
617
+ public function __construct($message, $credentials_form, $filename, $permission) {
618
+ parent::__construct($message, $credentials_form);
619
 
620
+ $this->filename = $filename;
621
+ $this->permission = $permission;
622
+ }
623
 
624
+ public function filename() {
625
+ return $this->filename;
626
  }
627
 
628
+ public function permission() {
629
+ return $this->permission;
630
+ }
631
  }
632
 
633
+ class FilesystemRmException extends FilesystemOperationException {
634
+ private $filename;
635
+
636
+ public function __construct($message, $credentials_form, $filename) {
637
+ parent::__construct($message, $credentials_form);
638
+
639
+ $this->filename = $filename;
640
+ }
641
+
642
+ public function filename() {
643
+ return $this->filename;
644
+ }
645
  }
646
 
647
+ class FilesystemRmdirException extends FilesystemOperationException {
648
+ private $folder;
649
+
650
+ public function __construct($message, $credentials_form, $folder) {
651
+ parent::__construct($message, $credentials_form);
652
+
653
+ $this->folder = $folder;
654
+ }
655
+
656
+ public function folder() {
657
+ return $this->folder;
658
+ }
659
  }
660
 
661
+ class SelfTestFailedException extends Exception {
662
+ private $technical_message;
 
 
 
 
 
663
 
664
+ public function __construct($message, $technical_message = '') {
665
  parent::__construct($message);
666
+ $this->technical_message = $technical_message;
667
+ }
668
+
669
+ public function technical_message() {
670
+ return $this->technical_message;
671
+ }
672
+ }
673
+
674
+
675
+
676
+ class SelfTestExceptions extends Exception {
677
+ private $exceptions;
678
+ private $credentials_form;
679
+
680
+ public function __construct() {
681
+ parent::__construct();
682
+
683
+ $this->exceptions = array();
684
  }
685
 
686
+ public function push($ex) {
687
+ if ($ex instanceof SelfTestExceptions) {
688
+ foreach ($ex->exceptions() as $ex2)
689
+ $this->push($ex2);
690
+ } else {
691
+ if ($this->credentials_form == null &&
692
+ $ex instanceof FilesystemOperationException &&
693
+ $ex->credentials_form() != null)
694
+ $this->credentials_form = $ex->credentials_form();
695
+ $this->exceptions[] = $ex;
696
+ }
697
  }
698
 
699
+ public function exceptions() {
700
+ return $this->exceptions;
701
+ }
702
 
703
+ public function credentials_form() {
704
+ return $this->credentials_form;
705
  }
706
  }
707
 
inc/functions/compat.php CHANGED
File without changes
inc/functions/extract.php CHANGED
File without changes
inc/functions/file.php CHANGED
@@ -278,4 +278,56 @@ function w3_get_file_owner($file = '') {
278
  }
279
  }
280
  return $fileowner . ':' . $filegroup;
281
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  }
279
  }
280
  return $fileowner . ':' . $filegroup;
281
+ }
282
+
283
+ /**
284
+ * Atomically writes file inside W3TC_CACHE_DIR dir
285
+ * @param $filename
286
+ * @param $content
287
+ * @throws Exception
288
+ * @return void
289
+ **/
290
+ function w3_file_put_contents_atomic($filename, $content) {
291
+ if (!is_dir(W3TC_CACHE_TMP_DIR) || !is_writable(W3TC_CACHE_TMP_DIR)) {
292
+ w3_mkdir_from(W3TC_CACHE_TMP_DIR, W3TC_CACHE_DIR);
293
+
294
+ if (!is_dir(W3TC_CACHE_TMP_DIR) || !is_writable(W3TC_CACHE_TMP_DIR)) {
295
+ throw new Exception('Can\'t create folder <strong>' .
296
+ W3TC_CACHE_TMP_DIR . '</strong>');
297
+ }
298
+ }
299
+
300
+ $temp = tempnam(W3TC_CACHE_TMP_DIR, 'temp');
301
+
302
+ try {
303
+ if (!($f = @fopen($temp, 'wb'))) {
304
+ if (file_exists($temp))
305
+ @unlink($temp);
306
+ throw new Exception('Can\'t write to temporary file <strong>' .
307
+ $temp . '</strong>');
308
+ }
309
+
310
+ fwrite($f, $content);
311
+ fclose($f);
312
+
313
+ if (!@rename($temp, $filename)) {
314
+ @unlink($filename);
315
+ if (!@rename($temp, $filename)) {
316
+ w3_mkdir_from(dirname($filename), W3TC_CACHE_DIR);
317
+ if (!@rename($temp, $filename)) {
318
+ throw new Exception('Can\'t write to file <strong>' .
319
+ $filename . '</strong>');
320
+ }
321
+ }
322
+ }
323
+
324
+ $chmod = 0644;
325
+ if (defined('FS_CHMOD_FILE'))
326
+ $chmod = FS_CHMOD_FILE;
327
+ @chmod($filename, $chmod);
328
+ } catch (Exception $ex) {
329
+ if (file_exists($temp))
330
+ @unlink($temp);
331
+ throw $ex;
332
+ }
333
+ }
inc/functions/http.php CHANGED
File without changes
inc/functions/ip_in_range.php CHANGED
File without changes
inc/functions/mime.php CHANGED
File without changes
inc/functions/multisite.php CHANGED
@@ -11,10 +11,10 @@ function w3_blogmap_register_new_item($blog_home_url, $config) {
11
 
12
  $filename = w3_blogmap_filename($blog_home_url);
13
 
14
- if (!file_exists($filename))
15
  $blog_ids = array();
16
  else {
17
- $data = file_get_contents($filename);
18
  $blog_ids = @eval($data);
19
  if (!is_array($blog_ids))
20
  $blog_ids = array();
@@ -30,8 +30,12 @@ function w3_blogmap_register_new_item($blog_home_url, $config) {
30
  $blog_ids_strings[] = "'" . $key . "' => '" . $value . "'";
31
 
32
  $data = sprintf('return array(%s);', implode(', ', $blog_ids_strings));
33
- if (!is_dir(dirname($filename)))
34
- w3_mkdir_from(dirname($filename), W3TC_CACHE_DIR);
35
 
36
- return @file_put_contents($filename, $data);
 
 
 
 
 
 
37
  }
11
 
12
  $filename = w3_blogmap_filename($blog_home_url);
13
 
14
+ if (!@file_exists($filename))
15
  $blog_ids = array();
16
  else {
17
+ $data = @file_get_contents($filename);
18
  $blog_ids = @eval($data);
19
  if (!is_array($blog_ids))
20
  $blog_ids = array();
30
  $blog_ids_strings[] = "'" . $key . "' => '" . $value . "'";
31
 
32
  $data = sprintf('return array(%s);', implode(', ', $blog_ids_strings));
 
 
33
 
34
+ try {
35
+ w3_file_put_contents_atomic($filename, $data);
36
+ } catch (Exception $ex) {
37
+ return false;
38
+ }
39
+
40
+ return true;
41
  }
inc/functions/other.php CHANGED
@@ -114,4 +114,65 @@ function w3_parse_faq() {
114
  }
115
 
116
  return $faq;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  }
114
  }
115
 
116
  return $faq;
117
+ }
118
+
119
+ /**
120
+ * Returns button link html
121
+ *
122
+ * @param string $text
123
+ * @param string $url
124
+ * @param boolean $new_window
125
+ * @return string
126
+ */
127
+ function w3tc_button_link($text, $url, $new_window = false) {
128
+ $url = str_replace('&amp;', '&', $url);
129
+
130
+ if ($new_window) {
131
+ $onclick = sprintf('window.open(\'%s\');', addslashes($url));
132
+ } else {
133
+ $onclick = sprintf('document.location.href=\'%s\';', addslashes($url));
134
+ }
135
+
136
+ return w3tc_button($text, $onclick);
137
+ }
138
+
139
+ /**
140
+ * Returns hide note button html
141
+ *
142
+ * @param string $text
143
+ * @param string $note
144
+ * @param string $redirect
145
+ * @param boolean $admin if to use config admin
146
+ * @return string
147
+ */
148
+ function w3tc_button_hide_note($text, $note, $redirect = '', $admin = false, $page ='') {
149
+ if (!$page) {
150
+ w3_require_once(W3TC_LIB_W3_DIR . '/Request.php');
151
+ $page = W3_Request::get_string('page');
152
+ }
153
+
154
+ $url = sprintf('admin.php?page=%s&w3tc_hide_note&note=%s', $page, $note);
155
+
156
+ if ($admin)
157
+ $url .= '&admin=1';
158
+
159
+ if ($redirect != '') {
160
+ $url .= '&redirect=' . urlencode($redirect);
161
+ }
162
+
163
+ $url = wp_nonce_url($url, 'w3tc');
164
+
165
+ return w3tc_button_link($text, $url);
166
+ }
167
+
168
+ /**
169
+ * Returns button html
170
+ *
171
+ * @param string $text
172
+ * @param string $onclick
173
+ * @param string $class
174
+ * @return string
175
+ */
176
+ function w3tc_button($text, $onclick = '', $class = '') {
177
+ return sprintf('<input type="button" class="button %s" value="%s" onclick="%s" />', htmlspecialchars($class), htmlspecialchars($text), htmlspecialchars($onclick));
178
  }
inc/functions/plugin.php CHANGED
@@ -11,8 +11,31 @@
11
  * @param mixed $callback
12
  * @return void
13
  */
14
- function w3tc_add_action($action, $callback) {
15
- $GLOBALS['_w3tc_actions'][$action][] = $callback;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  }
17
 
18
  /**
@@ -24,9 +47,32 @@ function w3tc_add_action($action, $callback) {
24
  */
25
  function w3tc_do_action($action, $value = null) {
26
  if (isset($GLOBALS['_w3tc_actions'][$action])) {
27
- foreach ((array) $GLOBALS['_w3tc_actions'][$action] as $callback) {
28
- if (is_callable($callback)) {
29
- $value = call_user_func($callback, $value);