W3 Total Cache - Version 0.9.2.6

Version Description

  • Added support for grouping cache entries for easier flushing
  • Added more options for placing minified files on pages. Custom placements using HTML comments.
  • Added CSS inclusion for auto / manual minify. If present its used: <!-- W3TC-include-css -->
  • Added JS inclusion for minify auto mode. If present its used: <!-- W3TC-include-js-head -->,
  • Added JS inclusion for minify manual mode. If present they are used when selecting correspong location in placement dropdown: <!-- W3TC-include-js-head -->, <!-- W3TC-include-js-body-start -->, <!-- W3TC-include-js-body-end -->
  • Added new minification inclusion options, async, defer, extsrc and asyncsrc
  • Added flushing sitemaps
  • Added flushing custom pages
  • Added flush the current blog when flushing in MultiSite
  • Added flushing home page and/or post page if static
  • Added flushing older pages (page/2, page/3) on purge requests
  • Added flushing a limited amount of pagenumbers
  • Added purging caches for deleted blogs in WordPress MultiSite
  • Added uninstall process to the plugin for easier cleanup
  • Added upgrade support that cleans up and removes old cache folders
  • Added message when disk enhanced page caching is not working properly
  • Added custom wp-content name and locations
  • Added CDN feature "Dont use CDN for specific roles"
  • Added "Purge from cache" link on edit post/page pages
  • Added permalink suffixes (.html, .htm etc)
  • Added uploading blogs.dir files when using MultiSite and CDN
  • Added notification about IAM when using Amazon services (SNS, CloudFront, S3 etc)
  • Added 'Don't minify JS files' 'Don't minify CSS files' options for minify
  • Added Access-Control-Allow-Origin support for CDNs
  • Added hooks clean_post_cache and menu changes
  • Added caching JSON mime-type. Other mime-types can be added using array filter 'w3tc_is_cacheable_content_type'
  • Added automatic reloading of config files when APC apc.stat is disabled
  • Added request reload of APC file over HTTP
  • Added priming of post on publish
  • Added single config file (by default) when using WordPress MultiSite
  • Added switch_to_blog() support
  • Added wp_cache_decr, wp_cache_incr support
  • Added wp_cache_switch_to_blog support
  • Added fragment caching functionality that extends the transient caching methods in WordPress core
  • Added network activation and network policy management
  • Added control for comment cookie lifetime
  • Added Go Daddy SUBDOMAIN_DOCUMENT_ROOT directive support
  • Added JSON to mod_deflate configuration
  • Added JavaScript mime-type variations to mod_deflate configuration
  • Added WP-CLI support for purging cache, purging pull CDNs, reloading APC files, clearing APC, deleting pgcache files, and updating browser query string
  • Added .htc mime type
  • Added Rackspace CloudFiles container location selection
  • Added rejected terms in database cache, to allow for deeper database caching capability
  • Added Akamai CDN origin pull support
  • Added system cache purge when apc.stat is disabled
  • Added origin rel canonical support for CDNs
  • Added AT&T origin pull CDN
  • Added full-page mirroring and purging for origin pull CDNs
  • Added compatibility mode improve disk enhanced page caching performance ~20% for users that don't care about interoperability
  • Added nginx example files
  • Added varnish example files
  • Added basic application monitoring support using New Relic
  • Added application monitoring widget using New Relic
  • Added plugin dashboard page to display widgets etc
  • Added purge from cache link to admin bar dropdown while browser posts/pages on front-end
  • Added purge CDN completely link to admin bar dropdown
  • Added CDN SSL checkbox "Disable CDN on SSL page"
  • Added pull CDN support to MultiSite
  • Fixed caching of the "Front Page" and added an option for the same
  • Fixed w3_url_format function was not included error
  • Fixed security vulnerability with file cache: disk basic page caching, database or object caching to disk. CVEs: CVE-2012-6077, CVE-2012-6078, CVE-2012-6079
  • Fixed issue with concurrent writes to single config file
  • Fixed Preview mode and deploy button
  • Fixed varnish purging (See varnish config example file in ini folder)
  • Fixed false positive notification on Page Cache: Disc Enhanced
  • Fixed broken images for feedburner in dashboard on HTTPS sites
  • Fixed minify ID generation causing notices
  • Fixed false positive on minification related to group configuration among other
  • Fixed default wp-content path and CDN uploads when WordPress is installed in directory
  • Fixed pages not flushing when making changes in WordPress Admin
  • Fixed mod_filter being used on unsupported Apache versions
  • Fixed WordPress upgrade issue caused by W3TC remaining active
  • Fixed minify path when using WordPress MultiSite and blogs in sub-directories
  • Fixed user interface for "Dont cache specific roles"
  • Fixed CDN and minify to file for storage
  • Fixed feed_link filters interferring with feed purging
  • Fixed false positive with minify rewrite test and WordPress MultiSite sub-directory mode
  • Fixed WordPress Multisite in sub-directory mode and minify paths
  • Fixed caching posts page when using static home page
  • Fixed object cache not being initialised before getting options
  • Fixed locating document root for minify in certain environments
  • Fixed saving settings if permalinks are turned off
  • Fixed "Install" page displaying rules that is not required
  • Fixed minify cache being empty while page is cached so no minified files are generated, minified files auto generation no longer depend on pages not being cached
  • Fixed unnecessary flushing with SSL, user agents and referrer not being activated
  • Fixed "Purge from Page Cache" not purging varnish or CDN when enabled
  • Fixed CSS minification and relative paths in external files
  • Fixed login / logout and compability with BuddyPress
  • Fixed flushing same posts many times if status is trashed or restored
  • Fixed handling of .html fancy permalinks with nginx
  • Fixed handling of missing xcache opcode cache
  • Fixed Amazon S3 allowing LIST permissions to everyone
  • Fixed handling of .xml mime type
  • Fixed numerous object cache compatibility issues
  • Fixed memcached port support issue
  • Fixed HTTP_HOST not defined warning issue
  • Fixed xdebug not configured halt issue
  • Fixed minified files not being mirrored by push CDNs
  • Fixed uploading to CDNs multiple times even if force overwrite is disabled
  • Improved CloudFlare support: purging, dev mode, minification options, automatic IP range updates, rocket loader feature, security levels
  • Improved support for the Bad Behavior plugin
  • Improved object cache and MultiSite compability
  • Improved flushing behavior with better post and pages detection. To change behavior hook into filter 'w3tc_flushable_post'
  • Improved XML user interface when using Page Cache Disc: Enhanced
  • Improved minify filename path generation
  • Improved minify custom placement usage
  • Improved PHP 5 compability by removing deprecated functionality
  • Improved WP 3.4 and 3.5 compability by removing deprecated functions usage
  • Improved plugin by removing unnecessary ob_starts
  • Improved minify usage by returning old minify files while generating new
  • Improved update procedure by removing need to manually deactivate and reactivate plugin
  • Improved CDN paths and URL generation using both single and multisite installs
  • Improved Admin Bar menu with more flushing actions
  • Improved minify auto by adding support for downloading and combining external files
  • Improved descriptions for various "Do not cache ..." textareas
  • Improved header settings so plugin header settings override WordPress default header where appropriate
  • Improved debug logging by adding a debug folder constant: W3TC_DEBUG_DIR
  • Improved support for WPTouch plugin
  • Improved custom post type support and flushing
  • Improved cache key format and handling
  • Improved minify support on Windows
  • Improved purging functionality for CDN providers
  • Improved compatibility wp-fb-autoconnect plugin
  • Improved support of WordPress installed when in a sub-directory
  • Improved support of non-default WordPress folder setups
  • Improved use of HTTP API and FileSystem API in WordPress. HTTP API usage improves minify and CDN functionality. FileSystem API integration improves activation, deactivation and configuration changes
  • Improved execution time across all caching engines
  • Improved cache miss performance for page caching
  • Improved notification handling
  • Improved cache priming algorithm
  • Improved minify error reporting
  • Improved varnish purging capability
  • Improved memory caching logic and purging speed
  • Improved support for auto minify in more hosting environments
  • Improved support for use of sockets in memcached
  • Improved handling of old settings upon update
  • Improved detection of document root on additional hosting providers
  • Improved handling of eTags
  • Improved browser cache policy options
  • Improved bug submission form implementation
  • Improved NetDNA / MaxCDN support by using their new API
  • Disabled minify if CloudFlare is active
  • Removed PHP 4 support
  • Removed cookie used for user agent groups unless the feature is used
  • Removed cookie used for referrer unless the feature is used
  • Removed duplicate inclusion of JSON library
Download this release

Release Info

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

Code changes from version 0.9.2.5 to 0.9.2.6

Files changed (138) hide show
  1. inc/.htaccess +0 -3
  2. inc/define.php +426 -158
  3. inc/email/index.html +0 -0
  4. inc/email/minify_error_notification.html +1 -1
  5. inc/email/minify_error_notification.php +1 -1
  6. inc/email/support_request.php +0 -0
  7. inc/error.php +0 -0
  8. inc/functions/activation.php +621 -78
  9. inc/functions/compat.php +58 -40
  10. inc/functions/extract.php +44 -0
  11. inc/functions/file.php +104 -0
  12. inc/functions/http.php +21 -0
  13. inc/functions/ip_in_range.php +212 -0
  14. inc/functions/mime.php +0 -0
  15. inc/functions/multisite.php +37 -0
  16. inc/functions/other.php +117 -0
  17. inc/functions/plugin.php +285 -13
  18. inc/functions/rule.php +63 -23
  19. inc/functions/rule_cut.php +31 -0
  20. inc/functions/update.php +63 -0
  21. inc/functions/url.php +1 -1
  22. inc/functions/widgets.php +100 -0
  23. inc/index.html +0 -0
  24. inc/lightbox/cdn_s3_bucket_location.php +1 -1
  25. inc/lightbox/index.html +0 -0
  26. inc/lightbox/minify_recommendations.php +4 -12
  27. inc/lightbox/self_test.php +21 -9
  28. inc/lightbox/support_us.php +8 -8
  29. inc/mime/all.php +0 -0
  30. inc/mime/cssjs.php +7 -2
  31. inc/mime/html.php +0 -0
  32. inc/mime/index.html +0 -0
  33. inc/mime/other.php +1 -0
  34. inc/options/about.php +0 -0
  35. inc/options/browsercache.php +142 -72
  36. inc/options/cdn.php +234 -184
  37. inc/options/cdn/akamai.php +65 -0
  38. inc/options/cdn/att.php +38 -0
  39. inc/options/cdn/azure.php +8 -5
  40. inc/options/cdn/cf.php +16 -6
  41. inc/options/cdn/cf2.php +14 -5
  42. inc/options/cdn/common/cnames.php +10 -7
  43. inc/options/cdn/common/index.html +0 -0
  44. inc/options/cdn/cotendo.php +7 -4
  45. inc/options/cdn/edgecast.php +5 -3
  46. inc/options/cdn/ftp.php +10 -7
  47. inc/options/cdn/index.html +0 -0
  48. inc/options/cdn/mirror.php +1 -1
  49. inc/options/cdn/netdna.php +24 -6
  50. inc/options/cdn/rscf.php +10 -6
  51. inc/options/cdn/s3.php +12 -4
  52. inc/options/common/footer.php +0 -0
  53. inc/options/common/header.php +173 -27
  54. inc/options/common/help.php +0 -0
  55. inc/options/common/index.html +0 -0
  56. inc/options/dashboard.php +62 -0
  57. inc/options/dbcache.php +100 -85
  58. inc/options/enterprise/dbcluster-config.php +32 -0
  59. inc/options/enterprise/dbcluster_general_section.php +8 -0
  60. inc/options/faq.php +0 -0
  61. inc/options/general.php +797 -556
  62. inc/options/index.html +0 -0
  63. inc/options/install.php +24 -12
  64. inc/options/minify.php +305 -236
  65. inc/options/minify/ccjs.php +7 -1
  66. inc/options/minify/ccjs2.php +11 -4
  67. inc/options/minify/css.php +2 -4
  68. inc/options/minify/csstidy.php +12 -21
  69. inc/options/minify/csstidy2.php +9 -5
  70. inc/options/minify/html.php +1 -2
  71. inc/options/minify/htmltidy.php +2 -4
  72. inc/options/minify/htmltidy2.php +4 -1
  73. inc/options/minify/index.html +0 -0
  74. inc/options/minify/js.php +2 -4
  75. inc/options/minify/yuicss2.php +10 -4
  76. inc/options/minify/yuijs.php +3 -6
  77. inc/options/minify/yuijs2.php +14 -4
  78. inc/options/mobile.php +74 -61
  79. inc/options/new_relic.php +171 -0
  80. inc/options/objectcache.php +49 -44
  81. inc/options/pgcache.php +371 -265
  82. inc/options/pro/fragmentcache.php +97 -0
  83. inc/options/pro/fragmentcache_general_section.php +46 -0
  84. inc/options/referrer.php +65 -65
  85. inc/options/support.php +1 -1
  86. inc/options/support/form.php +1 -1
  87. inc/options/support/form/bug_report.php +12 -2
  88. inc/options/support/form/email_support.php +12 -2
  89. inc/options/support/form/index.html +0 -0
  90. inc/options/support/form/linux_config.php +12 -2
  91. inc/options/support/form/new_feature.php +12 -2
  92. inc/options/support/form/phone_support.php +12 -2
  93. inc/options/support/form/plugin_config.php +12 -2
  94. inc/options/support/form/theme_config.php +12 -2
  95. inc/options/support/index.html +0 -0
  96. inc/options/support/payment.php +1 -1
  97. inc/options/support/select.php +1 -1
  98. inc/popup/cdn_export_file.php +2 -3
  99. inc/popup/cdn_export_library.php +2 -3
  100. inc/popup/cdn_import_library.php +2 -3
  101. inc/popup/cdn_purge.php +0 -0
  102. inc/popup/cdn_queue.php +3 -0
  103. inc/popup/cdn_rename_domain.php +2 -3
  104. inc/popup/common/footer.php +0 -0
  105. inc/popup/common/header.php +0 -0
  106. inc/popup/common/index.html +0 -0
  107. inc/popup/index.html +0 -0
  108. inc/popup/pagespeed_results.php +0 -0
  109. inc/widget/index.html +0 -0
  110. inc/widget/latest.php +0 -0
  111. inc/widget/latest_ajax.php +0 -3
  112. inc/widget/latest_control.php +1 -1
  113. inc/widget/latest_news.php +7 -0
  114. inc/widget/latest_news_ajax.php +10 -0
  115. inc/widget/latest_news_control.php +7 -0
  116. inc/widget/new_relic.php +104 -0
  117. inc/widget/pagespeed.php +0 -0
  118. inc/widget/pagespeed_control.php +4 -4
  119. inc/widget/services.php +12 -0
  120. inc/widget/spreadtheword.php +16 -0
  121. index.html +0 -0
  122. ini/.htaccess +0 -3
  123. ini/apc.ini +4 -4
  124. ini/dbcluster-config-sample.php +181 -0
  125. ini/eaccelerator.ini +0 -0
  126. ini/index.html +0 -0
  127. ini/memcache.ini +0 -0
  128. ini/nginx-network-sample-config.conf +31 -0
  129. ini/nginx-standalone-sample-config.conf +22 -0
  130. ini/php.append.ini +0 -0
  131. ini/s3-sample-policy.txt +23 -0
  132. ini/varnish-sample-config.vcl +89 -0
  133. ini/xcache.ini +0 -0
  134. inc/options/faq.xml → languages/faq-en_US.xml +193 -88
  135. languages/faq-premium-en_US.xml +110 -0
  136. lib/.htaccess +0 -3
  137. lib/CF/cacert.pem +3113 -3113
  138. lib/CF/cloudfiles.php +0 -1013
inc/.htaccess DELETED
@@ -1,3 +0,0 @@
1
- Options -Indexes
2
- Order deny,allow
3
- Deny from all
 
 
 
inc/define.php CHANGED
@@ -5,7 +5,7 @@ if (!defined('ABSPATH')) {
5
  }
6
 
7
  define('W3TC', true);
8
- define('W3TC_VERSION', '0.9.2.5');
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');
@@ -13,8 +13,11 @@ define('W3TC_PAYPAL_BUSINESS', 'w3tc-team@w3-edge.com');
13
  define('W3TC_LINK_URL', 'http://www.w3-edge.com/wordpress-plugins/');
14
  define('W3TC_LINK_NAME', 'WordPress Plugins');
15
  define('W3TC_FEED_URL', 'http://feeds.feedburner.com/W3TOTALCACHE');
16
- define('W3TC_README_URL', 'http://plugins.trac.wordpress.org/browser/w3-total-cache/trunk/readme.txt?format=txt');
 
17
  define('W3TC_SUPPORT_US_TIMEOUT', 2592000);
 
 
18
 
19
  define('W3TC_PHP5', PHP_VERSION >= 5);
20
  define('W3TC_WIN', (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'));
@@ -22,6 +25,9 @@ define('W3TC_WIN', (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'));
22
  defined('W3TC_DIR') || define('W3TC_DIR', realpath(dirname(__FILE__) . '/..'));
23
  define('W3TC_FILE', 'w3-total-cache/w3-total-cache.php');
24
  define('W3TC_INC_DIR', W3TC_DIR . '/inc');
 
 
 
25
  define('W3TC_LIB_DIR', W3TC_DIR . '/lib');
26
  define('W3TC_LIB_W3_DIR', W3TC_LIB_DIR . '/W3');
27
  define('W3TC_LIB_MINIFY_DIR', W3TC_LIB_DIR . '/Minify');
@@ -29,59 +35,28 @@ define('W3TC_LIB_CF_DIR', W3TC_LIB_DIR . '/CF');
29
  define('W3TC_LIB_CSSTIDY_DIR', W3TC_LIB_DIR . '/CSSTidy');
30
  define('W3TC_LIB_MICROSOFT_DIR', W3TC_LIB_DIR . '/Microsoft');
31
  define('W3TC_LIB_NUSOAP_DIR', W3TC_LIB_DIR . '/Nusoap');
 
 
 
32
  define('W3TC_PLUGINS_DIR', W3TC_DIR . '/plugins');
33
  define('W3TC_INSTALL_DIR', W3TC_DIR . '/wp-content');
34
  define('W3TC_INSTALL_MINIFY_DIR', W3TC_INSTALL_DIR . '/w3tc/min');
 
35
 
36
- define('W3TC_BLOGNAMES_PATH', WP_CONTENT_DIR . '/w3-total-cache-blognames.php');
37
- define('W3TC_BLOGNAME', w3_get_blogname());
38
- define('W3TC_SUFFIX', (W3TC_BLOGNAME != '' ? '-' . W3TC_BLOGNAME : ''));
 
 
 
 
39
 
40
  defined('WP_CONTENT_DIR') || define('WP_CONTENT_DIR', realpath(W3TC_DIR . '/../..'));
41
- define('WP_CONTENT_DIR_PATH', dirname(WP_CONTENT_DIR));
42
- define('WP_CONTENT_DIR_NAME', basename(WP_CONTENT_DIR));
43
- define('W3TC_CONTENT_DIR_NAME', WP_CONTENT_DIR_NAME . '/w3tc' . W3TC_SUFFIX);
44
- define('W3TC_CONTENT_DIR', WP_CONTENT_DIR_PATH . '/' . W3TC_CONTENT_DIR_NAME);
45
- define('W3TC_CONTENT_MINIFY_DIR_NAME', W3TC_CONTENT_DIR_NAME . '/min');
46
- define('W3TC_CONTENT_MINIFY_DIR', WP_CONTENT_DIR_PATH . '/' . W3TC_CONTENT_DIR_NAME . '/min');
47
- define('W3TC_CACHE_FILE_DBCACHE_DIR', W3TC_CONTENT_DIR . '/dbcache');
48
- define('W3TC_CACHE_FILE_OBJECTCACHE_DIR', W3TC_CONTENT_DIR . '/objectcache');
49
- define('W3TC_CACHE_FILE_PGCACHE_DIR', W3TC_CONTENT_DIR . '/pgcache');
50
- define('W3TC_CACHE_FILE_MINIFY_DIR', W3TC_CONTENT_DIR . '/min');
51
- define('W3TC_LOG_DIR', W3TC_CONTENT_DIR . '/log');
52
- define('W3TC_TMP_DIR', W3TC_CONTENT_DIR . '/tmp');
53
- define('W3TC_CONFIG_PATH', WP_CONTENT_DIR . '/w3-total-cache-config' . W3TC_SUFFIX . '.php');
54
- define('W3TC_CONFIG_PREVIEW_PATH', WP_CONTENT_DIR . '/w3-total-cache-config' . W3TC_SUFFIX . '-preview.php');
55
- define('W3TC_CONFIG_MASTER_PATH', WP_CONTENT_DIR . '/w3-total-cache-config.php');
56
- define('W3TC_MINIFY_LOG_FILE', W3TC_LOG_DIR . '/minify.log');
57
  define('W3TC_CDN_COMMAND_UPLOAD', 1);
58
  define('W3TC_CDN_COMMAND_DELETE', 2);
59
  define('W3TC_CDN_COMMAND_PURGE', 3);
60
  define('W3TC_CDN_TABLE_QUEUE', 'w3tc_cdn_queue');
61
- define('W3TC_CDN_LOG_FILE', W3TC_LOG_DIR . '/cdn.log');
62
- define('W3TC_VARNISH_LOG_FILE', W3TC_LOG_DIR . '/varnish.log');
63
-
64
- define('W3TC_MARKER_BEGIN_WORDPRESS', '# BEGIN WordPress');
65
- define('W3TC_MARKER_BEGIN_PGCACHE_CORE', '# BEGIN W3TC Page Cache core');
66
- define('W3TC_MARKER_BEGIN_PGCACHE_CACHE', '# BEGIN W3TC Page Cache cache');
67
- define('W3TC_MARKER_BEGIN_PGCACHE_LEGACY', '# BEGIN W3TC Page Cache');
68
- define('W3TC_MARKER_BEGIN_PGCACHE_WPSC', '# BEGIN WPSuperCache');
69
- define('W3TC_MARKER_BEGIN_BROWSERCACHE_CACHE', '# BEGIN W3TC Browser Cache');
70
- define('W3TC_MARKER_BEGIN_BROWSERCACHE_NO404WP', '# BEGIN W3TC Skip 404 error handling by WordPress for static files');
71
- define('W3TC_MARKER_BEGIN_MINIFY_CORE', '# BEGIN W3TC Minify core');
72
- define('W3TC_MARKER_BEGIN_MINIFY_CACHE', '# BEGIN W3TC Minify cache');
73
- define('W3TC_MARKER_BEGIN_MINIFY_LEGACY', '# BEGIN W3TC Minify');
74
-
75
- define('W3TC_MARKER_END_WORDPRESS', '# END WordPress');
76
- define('W3TC_MARKER_END_PGCACHE_CORE', '# END W3TC Page Cache core');
77
- define('W3TC_MARKER_END_PGCACHE_CACHE', '# END W3TC Page Cache cache');
78
- define('W3TC_MARKER_END_PGCACHE_LEGACY', '# END W3TC Page Cache');
79
- define('W3TC_MARKER_END_PGCACHE_WPSC', '# END WPSuperCache');
80
- define('W3TC_MARKER_END_BROWSERCACHE_CACHE', '# END W3TC Browser Cache');
81
- define('W3TC_MARKER_END_BROWSERCACHE_NO404WP', '# END W3TC Skip 404 error handling by WordPress for static files');
82
- define('W3TC_MARKER_END_MINIFY_CORE', '# END W3TC Minify core');
83
- define('W3TC_MARKER_END_MINIFY_CACHE', '# END W3TC Minify cache');
84
- define('W3TC_MARKER_END_MINIFY_LEGACY', '# END W3TC Minify');
85
 
86
  define('W3TC_INSTALL_FILE_ADVANCED_CACHE', W3TC_INSTALL_DIR . '/advanced-cache.php');
87
  define('W3TC_INSTALL_FILE_DB', W3TC_INSTALL_DIR . '/db.php');
@@ -89,10 +64,14 @@ define('W3TC_INSTALL_FILE_OBJECT_CACHE', W3TC_INSTALL_DIR . '/object-cache.php')
89
 
90
  define('W3TC_ADDIN_FILE_ADVANCED_CACHE', WP_CONTENT_DIR . '/advanced-cache.php');
91
  define('W3TC_ADDIN_FILE_DB', WP_CONTENT_DIR . '/db.php');
 
92
  define('W3TC_ADDIN_FILE_OBJECT_CACHE', WP_CONTENT_DIR . '/object-cache.php');
93
 
94
- require_once W3TC_INC_DIR . '/functions/compat.php';
95
- require_once W3TC_INC_DIR . '/functions/plugin.php';
 
 
 
96
 
97
  @ini_set('pcre.backtrack_limit', 4194304);
98
  @ini_set('pcre.recursion_limit', 4194304);
@@ -128,6 +107,37 @@ function w3_is_xml($content) {
128
  return (stripos($content, '<?xml') === 0 || stripos($content, '<html') === 0 || stripos($content, '<!DOCTYPE') === 0);
129
  }
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  /**
132
  * Returns true if it's WPMU
133
  *
@@ -211,22 +221,15 @@ function w3_is_database_error(&$content) {
211
  return (stristr($content, '<title>Database Error</title>') !== false);
212
  }
213
 
214
- /**
215
- * Returns true if preview config exists
216
- *
217
- * @return boolean
218
- */
219
- function w3_is_preview_config() {
220
- return file_exists(W3TC_CONFIG_PREVIEW_PATH);
221
- }
222
-
223
  /**
224
  * Retuns true if preview settings active
225
  *
226
  * @return boolean
227
  */
228
  function w3_is_preview_mode() {
229
- return (w3_is_preview_config() && (defined('WP_ADMIN') || isset($_REQUEST['w3tc_preview']) || (isset($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'], 'w3tc_preview') !== false)));
 
 
230
  }
231
 
232
  /**
@@ -263,7 +266,8 @@ function w3_is_nginx() {
263
  * @return boolean
264
  */
265
  function w3_is_cdn_engine($engine) {
266
- return in_array($engine, array('ftp', 's3', 'cf', 'cf2', 'rscf', 'azure', 'mirror', 'netdna', 'cotendo', 'edgecast'));
 
267
  }
268
 
269
  /**
@@ -273,7 +277,15 @@ function w3_is_cdn_engine($engine) {
273
  * @return bool
274
  */
275
  function w3_is_cdn_mirror($engine) {
276
- return in_array($engine, array('mirror', 'netdna', 'cotendo', 'cf2', 'edgecast'));
 
 
 
 
 
 
 
 
277
  }
278
 
279
  /**
@@ -285,10 +297,6 @@ function w3_is_cdn_mirror($engine) {
285
  function w3_get_domain($host) {
286
  $host = strtolower($host);
287
 
288
- if (strpos($host, 'www.') === 0) {
289
- $host = substr($host, 4);
290
- }
291
-
292
  if (($pos = strpos($host, ':')) !== false) {
293
  $host = substr($host, 0, $pos);
294
  }
@@ -327,114 +335,208 @@ function w3_get_blognames() {
327
  }
328
 
329
  /**
330
- * Load blognames from file
331
  *
332
- * @return array
333
  */
334
- function w3_load_blognames() {
335
- $blognames = include W3TC_BLOGNAMES_PATH;
 
 
 
 
 
 
 
 
336
 
337
- return $blognames;
 
 
 
 
338
  }
339
 
340
  /**
341
- * Save blognames into file
342
- *
343
- * @param string $blognames
344
- * @return boolean
345
  */
346
- function w3_save_blognames($blognames = null) {
347
- if (!$blognames) {
348
- $blognames = w3_get_blognames();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
  }
 
 
350
 
351
- $strings = array();
352
-
353
- foreach ($blognames as $blogname) {
354
- $strings[] = sprintf("'%s'", addslashes($blogname));
355
- }
 
 
 
 
 
 
 
356
 
357
- $data = sprintf('<?php return array(%s);', implode(', ', $strings));
 
 
358
 
359
- return @file_put_contents(W3TC_BLOGNAMES_PATH, $data);
 
360
  }
361
 
362
  /**
363
- * Detect WPMU blogname
 
364
  *
365
- * @return string
 
366
  */
367
- function w3_get_blogname() {
368
- static $blogname = null;
369
 
370
- if ($blogname === null) {
371
- if (w3_is_network()) {
372
- $host = w3_get_host();
373
- $domain = w3_get_domain($host);
374
 
375
- if (w3_is_subdomain_install()) {
376
- $blogname = $domain;
377
- } else {
378
- $uri = $_SERVER['REQUEST_URI'];
379
- $base_path = w3_get_base_path();
380
 
381
- if ($base_path != '' && strpos($uri, $base_path) === 0) {
382
- $uri = substr_replace($uri, '/', 0, strlen($base_path));
383
- }
384
 
385
- $blogname = w3_get_blogname_from_uri($uri);
 
 
 
 
386
 
387
- if ($blogname != '') {
388
- $blogname = $blogname . '.' . $domain;
389
- } else {
390
- $blogname = $domain;
391
- }
392
- }
393
- } else {
394
- $blogname = '';
395
- }
 
 
 
396
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
397
 
398
- return $blogname;
 
 
 
399
  }
400
 
401
  /**
402
- * Returns blogname from URI
403
  *
404
- * @param string $uri
405
  * @return string
406
  */
407
- function w3_get_blogname_from_uri($uri) {
408
- $blogname = '';
409
- $matches = null;
410
- $uri = strtolower($uri);
411
-
412
- if (preg_match('~^/([a-z0-9-]+)/~', $uri, $matches)) {
413
- if (file_exists(W3TC_BLOGNAMES_PATH)) {
414
- // Get blognames from cache
415
- $blognames = w3_load_blognames();
416
- } elseif (isset($GLOBALS['wpdb'])) {
417
- // Get blognames from DB
418
- $blognames = w3_get_blognames();
419
- } else {
420
- $blognames = array();
421
- }
422
 
423
- if (is_array($blognames) && in_array($matches[1], $blognames)) {
424
- $blogname = $matches[1];
425
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
426
  }
427
 
428
- return $blogname;
429
  }
430
 
431
  /**
432
- * Returns current blog ID
 
 
 
 
433
  *
434
- * @return integer
 
 
435
  */
436
- function w3_get_blog_id() {
437
- return (isset($GLOBALS['blog_id']) ? (int) $GLOBALS['blog_id'] : 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
438
  }
439
 
440
  /**
@@ -508,10 +610,19 @@ function w3_get_domain_url_regexp() {
508
  */
509
  function w3_get_home_url() {
510
  static $home_url = null;
511
-
512
  if ($home_url === null) {
513
- $home_url = get_option('home');
514
- $home_url = rtrim($home_url, '/');
 
 
 
 
 
 
 
 
 
515
  }
516
 
517
  return $home_url;
@@ -581,9 +692,13 @@ function w3_get_site_url_ssl() {
581
  */
582
  function w3_get_document_root() {
583
  static $document_root = null;
 
 
584
 
585
  if ($document_root === null) {
586
- if (!empty($_SERVER['SCRIPT_FILENAME'])) {
 
 
587
  $document_root = substr(w3_path($_SERVER['SCRIPT_FILENAME']), 0, -strlen(w3_path($_SERVER['PHP_SELF'])));
588
  } elseif (!empty($_SERVER['PATH_TRANSLATED'])) {
589
  $document_root = substr(w3_path($_SERVER['PATH_TRANSLATED']), 0, -strlen(w3_path($_SERVER['PHP_SELF'])));
@@ -761,7 +876,14 @@ function w3_get_host() {
761
  static $host = null;
762
 
763
  if ($host === null) {
764
- $host = (!empty($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST']);
 
 
 
 
 
 
 
765
  }
766
 
767
  return $host;
@@ -848,7 +970,8 @@ function w3_can_check_rules() {
848
  * @return bool
849
  */
850
  function w3_can_cdn_purge($engine) {
851
- return in_array($engine, array('ftp', 's3', 'cf', 'cf2', 'rscf', 'azure', 'netdna', 'cotendo', 'edgecast'));
 
852
  }
853
 
854
  /**
@@ -861,14 +984,14 @@ function w3_parse_path($path) {
861
  $path = str_replace(array(
862
  '%BLOG_ID%',
863
  '%POST_ID%',
864
- '%BLOGNAME%',
865
  '%HOST%',
866
  '%DOMAIN%',
867
  '%BASE_PATH%'
868
  ), array(
869
  (isset($GLOBALS['blog_id']) ? (int) $GLOBALS['blog_id'] : 0),
870
  (isset($GLOBALS['post_id']) ? (int) $GLOBALS['post_id'] : 0),
871
- w3_get_blogname(),
872
  w3_get_host(),
873
  w3_get_domain(w3_get_host()),
874
  trim(w3_get_base_path(), '/')
@@ -967,7 +1090,7 @@ function w3_translate_file($file) {
967
  * @return string
968
  */
969
  function w3_remove_query($url) {
970
- $url = preg_replace('~[&\?]+(ver=[a-z0-9-_\.]+|[0-9-]+)~i', '', $url);
971
 
972
  return $url;
973
  }
@@ -1027,9 +1150,10 @@ function w3_http_date($time) {
1027
  * @return string
1028
  */
1029
  function w3_redirect($url = '', $params = array()) {
1030
- require_once W3TC_INC_DIR . '/functions/url.php';
1031
 
1032
  $url = w3_url_format($url, $params);
 
1033
 
1034
  @header('Location: ' . $url);
1035
  exit();
@@ -1107,10 +1231,18 @@ function w3_get_engine_name($engine) {
1107
  $engine_name = 'cotendo';
1108
  break;
1109
 
 
 
 
 
1110
  case 'edgecast':
1111
  $engine_name = 'media template procdn / edgecast';
1112
  break;
1113
 
 
 
 
 
1114
  default:
1115
  $engine_name = 'n/a';
1116
  break;
@@ -1212,13 +1344,13 @@ function w3_escape_comment($comment) {
1212
  * @param string $class
1213
  * @return object
1214
  */
1215
- function &w3_instance($class) {
1216
  static $instances = array();
1217
 
1218
  if (!isset($instances[$class])) {
1219
- require_once W3TC_LIB_W3_DIR . '/' .
1220
- str_replace('_', '/', substr($class, 3)) . '.php';
1221
- @$instances[$class] = & new $class();
1222
  }
1223
 
1224
  $v = $instances[$class]; // Don't return reference
@@ -1226,19 +1358,155 @@ function &w3_instance($class) {
1226
  }
1227
 
1228
  /**
1229
- * Loads plugins
1230
  *
1231
- * @return void
1232
  */
1233
- function w3_load_plugins() {
1234
- $dir = @opendir(W3TC_PLUGINS_DIR);
1235
 
1236
- if ($dir) {
1237
- while (($entry = @readdir($dir)) !== false) {
1238
- if (strrchr($entry, '.') === '.php') {
1239
- require_once W3TC_PLUGINS_DIR . '/' . $entry;
1240
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1241
  }
1242
- @closedir($dir);
1243
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1244
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  }
6
 
7
  define('W3TC', true);
8
+ define('W3TC_VERSION', '0.9.2.6');
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');
13
  define('W3TC_LINK_URL', 'http://www.w3-edge.com/wordpress-plugins/');
14
  define('W3TC_LINK_NAME', 'WordPress Plugins');
15
  define('W3TC_FEED_URL', 'http://feeds.feedburner.com/W3TOTALCACHE');
16
+ 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'));
25
  defined('W3TC_DIR') || define('W3TC_DIR', realpath(dirname(__FILE__) . '/..'));
26
  define('W3TC_FILE', 'w3-total-cache/w3-total-cache.php');
27
  define('W3TC_INC_DIR', W3TC_DIR . '/inc');
28
+ define('W3TC_INC_WIDGET_DIR', W3TC_INC_DIR. '/widget');
29
+ define('W3TC_INC_FUNCTIONS_DIR', W3TC_INC_DIR . '/functions');
30
+ define('W3TC_INC_OPTIONS_DIR', W3TC_INC_DIR . '/options');
31
  define('W3TC_LIB_DIR', W3TC_DIR . '/lib');
32
  define('W3TC_LIB_W3_DIR', W3TC_LIB_DIR . '/W3');
33
  define('W3TC_LIB_MINIFY_DIR', W3TC_LIB_DIR . '/Minify');
35
  define('W3TC_LIB_CSSTIDY_DIR', W3TC_LIB_DIR . '/CSSTidy');
36
  define('W3TC_LIB_MICROSOFT_DIR', W3TC_LIB_DIR . '/Microsoft');
37
  define('W3TC_LIB_NUSOAP_DIR', W3TC_LIB_DIR . '/Nusoap');
38
+ define('W3TC_LIB_NETDNA_DIR', W3TC_LIB_DIR . '/NetDNA');
39
+ define('W3TC_LIB_OAUTH_DIR', W3TC_LIB_DIR . '/OAuth');
40
+ define('W3TC_LIB_NEWRELIC_DIR', W3TC_LIB_DIR . '/NewRelic');
41
  define('W3TC_PLUGINS_DIR', W3TC_DIR . '/plugins');
42
  define('W3TC_INSTALL_DIR', W3TC_DIR . '/wp-content');
43
  define('W3TC_INSTALL_MINIFY_DIR', W3TC_INSTALL_DIR . '/w3tc/min');
44
+ define('W3TC_LANGUAGES_DIR', W3TC_DIR . '/languages');
45
 
46
+ define('W3TC_CACHE_DIR', WP_CONTENT_DIR . '/cache');
47
+ define('W3TC_CONFIG_DIR', WP_CONTENT_DIR . '/w3tc-config');
48
+ define('W3TC_CACHE_CONFIG_DIR', W3TC_CACHE_DIR . '/config');
49
+ define('W3TC_CACHE_MINIFY_DIR', W3TC_CACHE_DIR . '/minify');
50
+ define('W3TC_CACHE_PAGE_ENHANCED_DIR', W3TC_CACHE_DIR . '/page_enhanced');
51
+ define('W3TC_CACHE_TMP_DIR', W3TC_CACHE_DIR . '/tmp');
52
+ define('W3TC_CACHE_BLOGMAP_FILENAME', W3TC_CACHE_DIR . '/blogs.php');
53
 
54
  defined('WP_CONTENT_DIR') || define('WP_CONTENT_DIR', realpath(W3TC_DIR . '/../..'));
55
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  define('W3TC_CDN_COMMAND_UPLOAD', 1);
57
  define('W3TC_CDN_COMMAND_DELETE', 2);
58
  define('W3TC_CDN_COMMAND_PURGE', 3);
59
  define('W3TC_CDN_TABLE_QUEUE', 'w3tc_cdn_queue');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  define('W3TC_INSTALL_FILE_ADVANCED_CACHE', W3TC_INSTALL_DIR . '/advanced-cache.php');
62
  define('W3TC_INSTALL_FILE_DB', W3TC_INSTALL_DIR . '/db.php');
64
 
65
  define('W3TC_ADDIN_FILE_ADVANCED_CACHE', WP_CONTENT_DIR . '/advanced-cache.php');
66
  define('W3TC_ADDIN_FILE_DB', WP_CONTENT_DIR . '/db.php');
67
+ define('W3TC_FILE_DB_CLUSTER_CONFIG', WP_CONTENT_DIR . '/db-cluster-config.php');
68
  define('W3TC_ADDIN_FILE_OBJECT_CACHE', WP_CONTENT_DIR . '/object-cache.php');
69
 
70
+
71
+ define('W3TC_WP_LOADER', (defined('WP_PLUGIN_DIR') ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins') . '/w3tc-wp-loader.php');
72
+
73
+ w3_require_once(W3TC_INC_DIR . '/functions/compat.php');
74
+ w3_require_once(W3TC_INC_DIR . '/functions/plugin.php');
75
 
76
  @ini_set('pcre.backtrack_limit', 4194304);
77
  @ini_set('pcre.recursion_limit', 4194304);
107
  return (stripos($content, '<?xml') === 0 || stripos($content, '<html') === 0 || stripos($content, '<!DOCTYPE') === 0);
108
  }
109
 
110
+ /*
111
+ * Returns URI from filename/dirname
112
+ *
113
+ * @return string
114
+ */
115
+ function w3_filename_to_url($filename) {
116
+ // using wp-content instead of document_root as known dir since dirbased
117
+ // multisite wp adds blogname to the path inside site_url
118
+ if (substr($filename, 0, strlen(WP_CONTENT_DIR)) != WP_CONTENT_DIR)
119
+ return '';
120
+ $uri_from_wp_content = substr($filename, strlen(WP_CONTENT_DIR));
121
+
122
+ $site_url_ssl = w3_get_url_ssl(w3_get_home_url());
123
+
124
+ $content_path = trim(substr(WP_CONTENT_DIR, strlen(w3_get_document_root())), '/');
125
+
126
+ $url = $site_url_ssl . '/' . $content_path . $uri_from_wp_content;
127
+
128
+ return $url;
129
+ }
130
+
131
+ /**
132
+ * Returns true if database cluster is used
133
+ *
134
+ * @return boolean
135
+ */
136
+ function w3_is_dbcluster() {
137
+ return defined('W3TC_FILE_DB_CLUSTER_CONFIG') && @file_exists(W3TC_FILE_DB_CLUSTER_CONFIG)
138
+ && defined('W3TC_ENTERPRISE') && W3TC_ENTERPRISE;
139
+ }
140
+
141
  /**
142
  * Returns true if it's WPMU
143
  *
221
  return (stristr($content, '<title>Database Error</title>') !== false);
222
  }
223
 
 
 
 
 
 
 
 
 
 
224
  /**
225
  * Retuns true if preview settings active
226
  *
227
  * @return boolean
228
  */
229
  function w3_is_preview_mode() {
230
+ return (isset($_REQUEST['w3tc_preview']) ||
231
+ (isset($_SERVER['HTTP_REFERER']) &&
232
+ strstr($_SERVER['HTTP_REFERER'], 'w3tc_preview') !== false));
233
  }
234
 
235
  /**
266
  * @return boolean
267
  */
268
  function w3_is_cdn_engine($engine) {
269
+ return in_array($engine, array('ftp', 's3', 'cf', 'cf2', 'rscf', 'azure', 'mirror', 'netdna',
270
+ 'cotendo', 'akamai', 'edgecast', 'att'));
271
  }
272
 
273
  /**
277
  * @return bool
278
  */
279
  function w3_is_cdn_mirror($engine) {
280
+ return in_array($engine, array('mirror', 'netdna', 'cotendo', 'cf2', 'akamai', 'edgecast', 'att'));
281
+ }
282
+
283
+ /**
284
+ * Returns true if CDN has purge all support
285
+ * @param $engine
286
+ */
287
+ function w3_cdn_can_purge_all($engine) {
288
+ return in_array($engine, array('cotendo', 'edgecast', 'att', 'netdna'));
289
  }
290
 
291
  /**
297
  function w3_get_domain($host) {
298
  $host = strtolower($host);
299
 
 
 
 
 
300
  if (($pos = strpos($host, ':')) !== false) {
301
  $host = substr($host, 0, $pos);
302
  }
335
  }
336
 
337
  /**
338
+ * Returns current blog ID
339
  *
340
+ * @return integer
341
  */
342
+ function w3_get_blog_id() {
343
+ global $w3_current_blog_id;
344
+
345
+ if (!is_null($w3_current_blog_id))
346
+ return $w3_current_blog_id;
347
+
348
+ if (!w3_is_network() || is_network_admin()) {
349
+ $w3_current_blog_id = 0;
350
+ return $w3_current_blog_id;
351
+ }
352
 
353
+ $uri = w3_generate_request_uri();
354
+
355
+ $w3_current_blog_id = w3_blogmap_get_blog_id($uri);
356
+
357
+ return $w3_current_blog_id;
358
  }
359
 
360
  /**
361
+ * @return string
 
 
 
362
  */
363
+ function w3_generate_request_uri() {
364
+ $host = w3_get_domain(w3_get_host());
365
+ $site_home_uri = w3_get_base_path();
366
+
367
+ // default path
368
+ $uri = $host . $site_home_uri;
369
+
370
+ if (!w3_is_subdomain_install()) {
371
+ // try subdir blog
372
+ $request_uri = rtrim($_SERVER['REQUEST_URI'], '/');
373
+ $content_path = trim(substr(WP_CONTENT_DIR, strlen(w3_get_site_root())), '/');
374
+ if (substr($request_uri, 1, strlen($content_path)) != $content_path && substr($request_uri, 0, strlen($site_home_uri)) == $site_home_uri) {
375
+ $request_path_in_wp = '/' . substr($request_uri, strlen($site_home_uri));
376
+
377
+ $n = strpos($request_path_in_wp, '/', 1);
378
+ if ($n === false) {
379
+ // case for homepage like /mywp/myblog
380
+ // unfortunately catches also /index.php here and other pages
381
+ // of "default" blog
382
+ $blog_path_in_wp = substr($request_path_in_wp, 1);
383
+ } else
384
+ $blog_path_in_wp = substr($request_path_in_wp, 1, $n);
385
+
386
+ $uri = $host . $site_home_uri . $blog_path_in_wp;
387
+ return $uri;
388
+ }
389
+ return $uri;
390
  }
391
+ return $uri;
392
+ }
393
 
394
+ /**
395
+ * Returns blogmap filename by home url
396
+ *
397
+ * @param string $blog_home_url
398
+ * @return string
399
+ */
400
+ function w3_blogmap_filename($blog_home_url) {
401
+ if (!defined('W3TC_BLOG_LEVELS'))
402
+ return W3TC_CACHE_BLOGMAP_FILENAME;
403
+ else {
404
+ $filename = dirname(W3TC_CACHE_BLOGMAP_FILENAME) . '/' .
405
+ basename(W3TC_CACHE_BLOGMAP_FILENAME, '.php') . '/';
406
 
407
+ $s = md5($blog_home_url);
408
+ for ($n = 0; $n < W3TC_BLOG_LEVELS; $n++)
409
+ $filename .= substr($s, $n, 1) . '/';
410
 
411
+ return $filename . basename(W3TC_CACHE_BLOGMAP_FILENAME);
412
+ }
413
  }
414
 
415
  /**
416
+ * Returns blog_id by home url
417
+ * If database not initialized yet - returns 0
418
  *
419
+ * @param string $blog_home_url
420
+ * @return integer
421
  */
422
+ function w3_blogmap_get_blog_id($blog_home_url) {
 
423
 
424
+ $blog_data = w3_get_blogmap_data($blog_home_url);
425
+ if ($blog_data && !is_int($blog_data))
426
+ return substr($blog_data, 1);
 
427
 
428
+ // we've faced new unknown yet url
 
 
 
 
429
 
430
+ if (isset($GLOBALS['current_blog']))
431
+ return $GLOBALS['current_blog']->blog_id;
 
432
 
433
+ // use master config until data set and
434
+ $GLOBALS['w3tc_blogmap_register_new_item'] = $blog_home_url;
435
+
436
+ return 0;
437
+ }
438
 
439
+ /**
440
+ * @return bool
441
+ */
442
+ function w3_force_master() {
443
+ if (!w3_is_multisite())
444
+ return false;
445
+ $blog_home_url = w3_generate_request_uri();
446
+ $blog_data = w3_get_blogmap_data($blog_home_url);
447
+ if (is_null($blog_data) || is_int($blog_data)) {
448
+ // use master config until data set and
449
+ $GLOBALS['w3tc_blogmap_register_new_item'] = $blog_home_url;
450
+ return true;
451
  }
452
+ return $blog_data[0] == 'm';
453
+ }
454
+
455
+ /**
456
+ * @param $blog_home_url
457
+ * @return null|string
458
+ */
459
+ function w3_get_blogmap_data($blog_home_url) {
460
+ $filename = w3_blogmap_filename($blog_home_url);
461
+
462
+ if (file_exists($filename)) {
463
+ $data = file_get_contents($filename);
464
+ $blog_data = @eval($data);
465
 
466
+ if (is_array($blog_data) && isset($blog_data[$blog_home_url]))
467
+ return $blog_data[$blog_home_url];
468
+ }
469
+ return null;
470
  }
471
 
472
  /**
473
+ * Returns path to section's cache dir
474
  *
475
+ * @param string $section
476
  * @return string
477
  */
478
+ function w3_cache_dir($section) {
479
+ return W3TC_CACHE_DIR . '/' . $section;
480
+ }
 
 
 
 
 
 
 
 
 
 
 
 
481
 
482
+ /**
483
+ * Returns path to blog's cache dir
484
+ *
485
+ * @param string $section
486
+ * @param null|int $blog_id
487
+ * @return string
488
+ */
489
+ function w3_cache_blog_dir($section, $blog_id = null) {
490
+ if (is_null($blog_id))
491
+ $blog_id = w3_get_blog_id();
492
+
493
+ $postfix = sprintf('%06d', $blog_id);
494
+
495
+ if (defined('W3TC_BLOG_LEVELS')) {
496
+ for ($n = 0; $n < W3TC_BLOG_LEVELS; $n++)
497
+ $postfix = substr($postfix, strlen($postfix) - 1 - $n, 1) . '/' .
498
+ $postfix;
499
  }
500
 
501
+ return w3_cache_dir($section) . '/' . $postfix;
502
  }
503
 
504
  /**
505
+ * Return full path to log file for module
506
+ * Path used in priority
507
+ * 1) W3TC_DEBUG_DIR
508
+ * 2) WP_DEBUG_LOG
509
+ * 3) W3TC_CACHE_DIR
510
  *
511
+ * @param $module
512
+ * @param null $blog_id
513
+ * @return string
514
  */
515
+ function w3_debug_log($module, $blog_id = null) {
516
+ if (is_null($blog_id))
517
+ $blog_id = w3_get_blog_id();
518
+
519
+ $postfix = sprintf('%06d', $blog_id);
520
+
521
+ if (defined('W3TC_BLOG_LEVELS')) {
522
+ for ($n = 0; $n < W3TC_BLOG_LEVELS; $n++)
523
+ $postfix = substr($postfix, strlen($postfix) - 1 - $n, 1) . '/' .
524
+ $postfix;
525
+ }
526
+ $from_dir = W3TC_CACHE_DIR;
527
+ if (defined('W3TC_DEBUG_DIR') && W3TC_DEBUG_DIR) {
528
+ $dir_path = W3TC_DEBUG_DIR;
529
+ if (!is_dir(W3TC_DEBUG_DIR))
530
+ $from_dir = dirname(W3TC_DEBUG_DIR);
531
+ } else
532
+ $dir_path = w3_cache_dir('log');
533
+ $filename = $dir_path . '/' . $postfix . '/' . $module . '.log';
534
+ if (!is_dir(dirname($filename))) {
535
+ w3_require_once( W3TC_INC_DIR . '/functions/file.php');
536
+ w3_mkdir_from(dirname($filename), $from_dir);
537
+ }
538
+
539
+ return $filename;
540
  }
541
 
542
  /**
610
  */
611
  function w3_get_home_url() {
612
  static $home_url = null;
613
+
614
  if ($home_url === null) {
615
+ $config = w3_instance('W3_Config');
616
+ if ($config->get_boolean('common.force_master')) {
617
+ $home_url = get_home_url();
618
+ } else {
619
+ // get_option is unusable here, it can cause problem when objCache isn't yet initialized
620
+ // Which is why we save the 'home' option in our ConfigCache
621
+ // We don't just use $config->get_string, because we want the cache to rebuild
622
+ // when 'wordpress.home' is not (yet) present
623
+ $home_url = $config->get_cache_option('wordpress.home');
624
+ $home_url = rtrim($home_url, '/');
625
+ }
626
  }
627
 
628
  return $home_url;
692
  */
693
  function w3_get_document_root() {
694
  static $document_root = null;
695
+ $len = strlen($_SERVER['PHP_SELF']);
696
+ $split = $len/2;
697
 
698
  if ($document_root === null) {
699
+ if (!empty($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == $_SERVER['PHP_SELF']) {
700
+ $document_root = w3_get_site_root();
701
+ } elseif (!empty($_SERVER['SCRIPT_FILENAME'])) {
702
  $document_root = substr(w3_path($_SERVER['SCRIPT_FILENAME']), 0, -strlen(w3_path($_SERVER['PHP_SELF'])));
703
  } elseif (!empty($_SERVER['PATH_TRANSLATED'])) {
704
  $document_root = substr(w3_path($_SERVER['PATH_TRANSLATED']), 0, -strlen(w3_path($_SERVER['PHP_SELF'])));
876
  static $host = null;
877
 
878
  if ($host === null) {
879
+ if (!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
880
+ $host = $_SERVER['HTTP_X_FORWARDED_HOST'];
881
+ } elseif (!empty($_SERVER['HTTP_HOST'])) {
882
+ // HTTP_HOST sometimes is not set causing warning
883
+ $host = $_SERVER['HTTP_HOST'];
884
+ } else {
885
+ $host = '';
886
+ }
887
  }
888
 
889
  return $host;
970
  * @return bool
971
  */
972
  function w3_can_cdn_purge($engine) {
973
+ return in_array($engine, array('ftp', 's3', 'cf', 'cf2', 'rscf', 'azure', 'netdna', 'cotendo',
974
+ 'edgecast', 'akamai', 'att'));
975
  }
976
 
977
  /**
984
  $path = str_replace(array(
985
  '%BLOG_ID%',
986
  '%POST_ID%',
987
+ '%BLOG_ID%',
988
  '%HOST%',
989
  '%DOMAIN%',
990
  '%BASE_PATH%'
991
  ), array(
992
  (isset($GLOBALS['blog_id']) ? (int) $GLOBALS['blog_id'] : 0),
993
  (isset($GLOBALS['post_id']) ? (int) $GLOBALS['post_id'] : 0),
994
+ w3_get_blog_id(),
995
  w3_get_host(),
996
  w3_get_domain(w3_get_host()),
997
  trim(w3_get_base_path(), '/')
1090
  * @return string
1091
  */
1092
  function w3_remove_query($url) {
1093
+ $url = preg_replace('~[&\?]+(ver=([a-z0-9-_\.]+|[0-9-]+))~i', '', $url);
1094
 
1095
  return $url;
1096
  }
1150
  * @return string
1151
  */
1152
  function w3_redirect($url = '', $params = array()) {
1153
+ w3_require_once(W3TC_INC_DIR . '/functions/url.php');
1154
 
1155
  $url = w3_url_format($url, $params);
1156
+ do_action('w3_redirect');
1157
 
1158
  @header('Location: ' . $url);
1159
  exit();
1231
  $engine_name = 'cotendo';
1232
  break;
1233
 
1234
+ case 'akamai':
1235
+ $engine_name = 'akamai';
1236
+ break;
1237
+
1238
  case 'edgecast':
1239
  $engine_name = 'media template procdn / edgecast';
1240
  break;
1241
 
1242
+ case 'att':
1243
+ $engine_name = 'at&amp;t';
1244
+ break;
1245
+
1246
  default:
1247
  $engine_name = 'n/a';
1248
  break;
1344
  * @param string $class
1345
  * @return object
1346
  */
1347
+ function w3_instance($class) {
1348
  static $instances = array();
1349
 
1350
  if (!isset($instances[$class])) {
1351
+ w3_require_once( W3TC_LIB_W3_DIR . '/' .
1352
+ str_replace('_', '/', substr($class, 3)) . '.php');
1353
+ $instances[$class] = new $class();
1354
  }
1355
 
1356
  $v = $instances[$class]; // Don't return reference
1358
  }
1359
 
1360
  /**
1361
+ * Requires and keeps track of which files has already been loaded.
1362
  *
1363
+ * @param string $path Absolute path to the file
1364
  */
1365
+ function w3_require_once($path) {
1366
+ static $files = array();
1367
 
1368
+ if (!isset($files[$path])) {
1369
+ $files[$path] = 1;
1370
+ require $path;
1371
+ }
1372
+ }
1373
+
1374
+ /**
1375
+ * Detects post ID
1376
+ *
1377
+ * @return integer
1378
+ */
1379
+ function w3_detect_post_id() {
1380
+ global $posts, $comment_post_ID, $post_ID;
1381
+
1382
+ if ($post_ID) {
1383
+ return $post_ID;
1384
+ } elseif ($comment_post_ID) {
1385
+ return $comment_post_ID;
1386
+ } elseif (is_single() || is_page() && count($posts)) {
1387
+ return $posts[0]->ID;
1388
+ } elseif (isset($_REQUEST['p'])) {
1389
+ return (integer) $_REQUEST['p'];
1390
+ }
1391
+
1392
+ return 0;
1393
+ }
1394
+
1395
+ function w3_get_instance_id() {
1396
+ static $instance_id;
1397
+
1398
+ if(!isset($instance_id)) {
1399
+ $config = w3_instance('W3_Config');
1400
+ $instance_id = $config->get_integer('common.instance_id', 0);
1401
+ }
1402
+ return $instance_id;
1403
+ }
1404
+
1405
+
1406
+ /**
1407
+ * Checks if post should be flushed or not. Returns true if it should not be flushed
1408
+ * @param $post
1409
+ * @param $module which cache module to check against (pgcache, varnish, cdncache, dbcache or objectcache)
1410
+ * @param W3_Config $config
1411
+ * @return bool
1412
+ */
1413
+ function w3_is_flushable_post($post, $module, $config) {
1414
+ if (is_numeric($post))
1415
+ $post = get_post($post);
1416
+ $post_status = array('publish');
1417
+ // dont flush when we have post "attachment"
1418
+ // its child of the post and is flushed always when post is published, while not changed in fact
1419
+ $post_type = array('revision', 'attachment');
1420
+ switch($module) {
1421
+ case 'pgcache':
1422
+ case 'varnish':
1423
+ case 'cdncache':
1424
+ if (!$config->get_boolean('pgcache.reject.logged'))
1425
+ $post_status[] = 'private';
1426
+ break;
1427
+ case 'dbcache':
1428
+ if (!$config->get_boolean('dbcache.reject.logged'))
1429
+ $post_status[] = 'private';
1430
+ break;
1431
+ }
1432
+ $flushable = !in_array($post->post_type, $post_type) && in_array($post->post_status, $post_status);
1433
+ return apply_filters('w3tc_flushable_post', $flushable, $post, $module);
1434
+ }
1435
+
1436
+ /**
1437
+ * @param $filename
1438
+ * @param $content
1439
+ * @return bool
1440
+ */
1441
+ function file_put_contents_atomic($filename, $content) {
1442
+
1443
+ $temp = tempnam(W3TC_CACHE_TMP_DIR, 'temp');
1444
+ if (!($f = @fopen($temp, 'wb'))) {
1445
+ $temp = W3TC_CACHE_TMP_DIR . DIRECTORY_SEPARATOR . uniqid('temp');
1446
+ if (!($f = @fopen($temp, 'wb'))) {
1447
+ trigger_error("file_put_contents_atomic() : error writing temporary file '$temp'", E_USER_WARNING);
1448
+ return false;
1449
  }
 
1450
  }
1451
+
1452
+ fwrite($f, $content);
1453
+ fclose($f);
1454
+
1455
+ if (!@rename($temp, $filename)) {
1456
+ @unlink($filename);
1457
+ @rename($temp, $filename);
1458
+ }
1459
+
1460
+ return true;
1461
+
1462
+ }
1463
+ /**
1464
+ * Takes seconds and converts to array('Nh ','Nm ', 'Ns ', 'Nms ') or "Nh Nm Ns Nms"
1465
+ * @param $input
1466
+ * @param bool $string
1467
+ * @return array|string
1468
+ */
1469
+ function w3_convert_secs_to_time($input, $string = true) {
1470
+ $input = (double)$input;
1471
+ $time = array();
1472
+ $msecs = floor($input*1000 % 1000);
1473
+ $seconds = $input % 60;
1474
+ $input = floor($input / 60);
1475
+ $minutes = $input % 60;
1476
+ $input = floor($input / 60);
1477
+ $hours = $input % 60;
1478
+ $input = floor($input / 60);
1479
+ if ($hours)
1480
+ $time[] = sprintf(__('%dh', 'w3-total-cache'), $hours);
1481
+ if ($minutes)
1482
+ $time[] = sprintf(__('%dm', 'w3-total-cache'), $minutes);
1483
+ if ($seconds)
1484
+ $time[] = sprintf(__('%ds', 'w3-total-cache'), $seconds);
1485
+ if ($msecs)
1486
+ $time[] = sprintf(__('%dms', 'w3-total-cache'), $msecs);
1487
+
1488
+ if(empty($time))
1489
+ $time[] = sprintf(__('%dms', 'w3-total-cache'), 0);
1490
+ if ($string)
1491
+ return implode(' ', $time);
1492
+ return $time;
1493
  }
1494
+
1495
+ /**
1496
+ * @return string
1497
+ */
1498
+ function w3_w3tc_release_version() {
1499
+ if (defined('W3TC_ENTERPRISE') && W3TC_ENTERPRISE)
1500
+ return 'enterprise';
1501
+ if (defined('W3TC_PRO') && W3TC_PRO)
1502
+ return 'pro';
1503
+ return 'community';
1504
+ }
1505
+
1506
+ function w3_is_pro() {
1507
+ return defined('W3TC_PRO') && W3TC_PRO;
1508
+ }
1509
+
1510
+ function w3_is_enterprise() {
1511
+ return defined('W3TC_ENTERPRISE') && W3TC_ENTERPRISE;
1512
+ }
inc/email/index.html CHANGED
File without changes
inc/email/minify_error_notification.html CHANGED
@@ -1,7 +1,7 @@
1
  <html>
2
  <head></head>
3
  <body>
4
- <p>Unfortunately an error occurred while creating the minify cache. Please check your settings to ensure your site is working as intended.</p>
5
  <p>Thanks for using W3 Total Cache.</p>
6
  </body>
7
  </html>
1
  <html>
2
  <head></head>
3
  <body>
4
+ <p>Unfortunately, an error occurred while creating the minify cache. Please check your settings to ensure your site is working as intended.</p>
5
  <p>Thanks for using W3 Total Cache.</p>
6
  </body>
7
  </html>
inc/email/minify_error_notification.php CHANGED
@@ -1,7 +1,7 @@
1
  <html>
2
  <head></head>
3
  <body>
4
- <p>Unfortunately an error occurred while creating the minify cache. Please check your settings to ensure your site is working as intended.</p>
5
  <p>Thanks for using W3 Total Cache.</p>
6
  </body>
7
  </html>
1
  <html>
2
  <head></head>
3
  <body>
4
+ <p>Unfortunately, an error occurred while creating the minify cache. Please check your settings to ensure your site is working as intended.</p>
5
  <p>Thanks for using W3 Total Cache.</p>
6
  </body>
7
  </html>
inc/email/support_request.php CHANGED
File without changes
inc/error.php CHANGED
File without changes
inc/functions/activation.php CHANGED
@@ -1,78 +1,621 @@
1
- <?php
2
-
3
- /**
4
- * Deactivate plugin after activation error
5
- *
6
- * @return void
7
- */
8
- function w3_activation_cleanup() {
9
- $active_plugins = (array) get_option('active_plugins');
10
- $active_plugins_network = (array) get_site_option('active_sitewide_plugins');
11
-
12
- // workaround for WPMU deactivation bug
13
- remove_action('deactivate_' . W3TC_FILE, 'deactivate_sitewide_plugin');
14
-
15
- do_action('deactivate_plugin', W3TC_FILE);
16
-
17
- $key = array_search(W3TC_FILE, $active_plugins);
18
-
19
- if ($key !== false) {
20
- array_splice($active_plugins, $key, 1);
21
- }
22
-
23
- unset($active_plugins_network[W3TC_FILE]);
24
-
25
- do_action('deactivate_' . W3TC_FILE);
26
- do_action('deactivated_plugin', W3TC_FILE);
27
-
28
- update_option('active_plugins', $active_plugins);
29
- update_site_option('active_sitewide_plugins', $active_plugins_network);
30
- }
31
-
32
- /**
33
- * W3 activate error
34
- *
35
- * @param string $error
36
- * @return void
37
- */
38
- function w3_activate_error($error) {
39
- w3_activation_cleanup();
40
-
41
- include W3TC_INC_DIR . '/error.php';
42
- exit();
43
- }
44
-
45
- /**
46
- * W3 writable error
47
- *
48
- * @param string $path
49
- * @return string
50
- */
51
- function w3_writable_error($path) {
52
- $reactivate_url = wp_nonce_url('plugins.php?action=activate&plugin=' . W3TC_FILE, 'activate-plugin_' . W3TC_FILE);
53
- $reactivate_button = sprintf('<input type="button" value="re-activate plugin" onclick="top.location.href = \'%s\'" />', addslashes($reactivate_url));
54
-
55
- require_once W3TC_INC_DIR . '/functions/file.php';
56
-
57
- if (w3_check_open_basedir($path)) {
58
- $error = sprintf('<strong>%s</strong> could not be created, please run following command:<br /><strong style="color: #f00;">chmod 777 %s</strong><br />then %s.', $path, (file_exists($path) ? $path : dirname($path)), $reactivate_button);
59
- } else {
60
- $error = sprintf('<strong>%s</strong> could not be created, <strong>open_basedir</strong> restriction in effect, please check your php.ini settings:<br /><strong style="color: #f00;">open_basedir = "%s"</strong><br />then %s.', $path, ini_get('open_basedir'), $reactivate_button);
61
- }
62
-
63
- w3_activate_error($error);
64
- }
65
-
66
- /**
67
- * W3 Network activation error
68
- *
69
- * @return void
70
- */
71
- function w3_network_activate_error() {
72
- w3_activation_cleanup();
73
- wp_redirect(plugins_url('pub/network_activation.php', W3TC_FILE));
74
-
75
- echo '<p><strong>W3 Total Cache Error:</strong> plugin cannot be activated network-wide.</p>';
76
- echo '<p><a href="javascript:history.back(-1);">Back</a>';
77
- exit();
78
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Deactivate plugin after activation error
5
+ *
6
+ * @return void
7
+ */
8
+ function w3_activation_cleanup() {
9
+ $active_plugins = (array) get_option('active_plugins');
10
+ $active_plugins_network = (array) get_site_option('active_sitewide_plugins');
11
+
12
+ // workaround for WPMU deactivation bug
13
+ remove_action('deactivate_' . W3TC_FILE, 'deactivate_sitewide_plugin');
14
+
15
+ do_action('deactivate_plugin', W3TC_FILE);
16
+
17
+ $key = array_search(W3TC_FILE, $active_plugins);
18
+
19
+ if ($key !== false) {
20
+ array_splice($active_plugins, $key, 1);
21
+ }
22
+
23
+ unset($active_plugins_network[W3TC_FILE]);
24
+
25
+ do_action('deactivate_' . W3TC_FILE);
26
+ do_action('deactivated_plugin', W3TC_FILE);
27
+
28
+ update_option('active_plugins', $active_plugins);
29
+ update_site_option('active_sitewide_plugins', $active_plugins_network);
30
+ }
31
+
32
+ /**
33
+ * W3 activate error
34
+ *
35
+ * @param string $error
36
+ * @return void
37
+ */
38
+ function w3_activate_error($error) {
39
+ w3_activation_cleanup();
40
+
41
+ include W3TC_INC_DIR . '/error.php';
42
+ exit();
43
+ }
44
+
45
+ /**
46
+ * Print activation error with repeat button based on exception
47
+ *
48
+ * @param $e
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
+ /**
75
+ * W3 error on read
76
+ *
77
+ * @param string $path
78
+ * @throws FileOperationException
79
+ */
80
+ 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
+
94
+ throw new FileOperationException($error, 'read', 'file', $path);
95
+ }
96
+
97
+ /**
98
+ * W3 writable error
99
+ *
100
+ * @param string $path
101
+ * @throws FileOperationException
102
+ */
103
+ function w3_throw_on_write_error($path) {
104
+ w3_require_once(W3TC_INC_DIR . '/functions/file.php');
105
+
106
+ if (w3_check_open_basedir($path)) {
107
+ $error = sprintf('<strong>%s</strong> could not be created, please run following ' .
108
+ 'command:<br /><strong style="color: #f00;">chmod 777 %s</strong>', $path,
109
+ (file_exists($path) ? $path : dirname($path)));
110
+ } else {
111
+ $error = sprintf('<strong>%s</strong> could not be created, <strong>open_basedir' .
112
+ '</strong> restriction in effect, please check your php.ini settings:<br />' .
113
+ '<strong style="color: #f00;">open_basedir = "%s"</strong>', $path,
114
+ ini_get('open_basedir'));
115
+ }
116
+
117
+ throw new FileOperationException($error, 'create', 'file', $path);
118
+ }
119
+
120
+ /**
121
+ * Creates cache folder and extension files.
122
+ * Throws exception on failure.
123
+ *
124
+ * @throws Exception
125
+ */
126
+ function w3_activation_create_required_files() {
127
+ /**
128
+ * Check installation files
129
+ */
130
+ $files = array(
131
+ W3TC_INSTALL_FILE_ADVANCED_CACHE,
132
+ W3TC_INSTALL_FILE_DB,
133
+ W3TC_INSTALL_FILE_OBJECT_CACHE);
134
+
135
+ $nonexistent_files = array();
136
+
137
+ foreach ($files as $file) {
138
+ if (!file_exists($file)) {
139
+ $nonexistent_files[] = $file;
140
+ }
141
+ }
142
+
143
+ if (count($nonexistent_files)) {
144
+ throw new Exception(sprintf('Unfortunately core file(s): (<strong>%s</strong>) ' .
145
+ 'are missing, so activation will fail. Please re-start the installation ' .
146
+ 'process from the beginning.', implode(', ', $nonexistent_files)));
147
+ }
148
+
149
+ $directories = array(
150
+ W3TC_CACHE_DIR,
151
+ W3TC_CONFIG_DIR,
152
+ W3TC_CACHE_CONFIG_DIR,
153
+ W3TC_CACHE_TMP_DIR);
154
+
155
+ foreach ($directories as $d) {
156
+ if (!@is_dir($d)) {
157
+ try{
158
+ w3_wp_create_folder($d, 'direct');
159
+ } catch(Exception $ex) {}
160
+ }
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Copy file if destination does not exists or not equal
166
+ *
167
+ * @param string $source_filename
168
+ * @param string $destination_filename
169
+ * @param string $method Which method to use when creating
170
+ * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
171
+ * @throws FileOperationException
172
+ */
173
+ function w3_copy_if_not_equal($source_filename, $destination_filename, $method = 'direct') {
174
+ if (@file_exists($destination_filename)) {
175
+ $s = fopen($source_filename, 'rb');
176
+ if ($s) {
177
+ $v1 = fread($s, filesize($source_filename));
178
+ fclose($s);
179
+
180
+ $d = fopen($destination_filename, 'rb');
181
+
182
+ if ($d) {
183
+ if (filesize($destination_filename) <= 0)
184
+ $v2 = '';
185
+ else
186
+ $v2 = fread($d, filesize($destination_filename));
187
+
188
+ fclose($d);
189
+
190
+ if ($v1 && $v2 && $v1 == $v2)
191
+ return;
192
+ }
193
+ }
194
+ }
195
+
196
+ w3_wp_copy_file($source_filename, $destination_filename, $method);
197
+ }
198
+
199
+
200
+ /**
201
+ * Copy file using WordPress filesystem functions.
202
+ * @param $source_filename
203
+ * @param $destination_filename
204
+ * @param string $method Which method to use when creating
205
+ * @param string $url Where to redirect after creation
206
+ * @param bool|string $context folder to copy files too
207
+ * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
208
+ * @throws FileOperationException
209
+ */
210
+ function w3_wp_copy_file($source_filename, $destination_filename, $method = '', $url = '', $context = false) {
211
+ w3_wp_request_filesystem_credentials($method, $url, $context);
212
+
213
+ global $wp_filesystem;
214
+ $contents = $wp_filesystem->get_contents($source_filename);
215
+
216
+ if (!$wp_filesystem->put_contents( $destination_filename, $contents, FS_CHMOD_FILE)) {
217
+ throw new FileOperationException('Could not create file ' . $destination_filename, 'create', 'file', $destination_filename);
218
+ }
219
+ }
220
+
221
+ /**
222
+ * @param $folder
223
+ * @param string $method Which method to use when creating
224
+ * @param string $url Where to redirect after creation
225
+ * @param bool|string $context folder to create folder in
226
+ * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
227
+ * @throws FileOperationException
228
+ */
229
+ function w3_wp_create_folder($folder, $method = '', $url = '', $context = false) {
230
+ w3_wp_request_filesystem_credentials($method, $url, $context);
231
+
232
+ global $wp_filesystem;
233
+ if (!$wp_filesystem->mkdir($folder, FS_CHMOD_DIR)) {
234
+ throw new FileOperationException('Could not create folder:' . $folder, 'create', 'folder', $folder);
235
+ }
236
+ }
237
+
238
+
239
+ /**
240
+ * @param $folders
241
+ * @param string $method Which method to use when creating
242
+ * @param string $url Where to redirect after creation
243
+ * @param bool|string $context folder to create folders in
244
+ * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
245
+ * @throws FileOperationException
246
+ */
247
+ function w3_wp_create_folders($folders, $method = '', $url = '', $context = false) {
248
+ w3_wp_request_filesystem_credentials($method, $url, $context);
249
+
250
+ global $wp_filesystem;
251
+
252
+ foreach($folders as $folder) {
253
+ if (!$wp_filesystem->mkdir($folder, FS_CHMOD_DIR)) {
254
+ throw new FileOperationException('Could not create folder: ' . $folder, 'create', 'folder', $folder);
255
+ }
256
+ }
257
+ }
258
+
259
+ /**
260
+ * @param $folders
261
+ * @param string $method Which method to use when creating
262
+ * @param string $url Where to redirect after creation
263
+ * @param bool|string $context path folder where delete folders resides
264
+ * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
265
+ * @throws FileOperationException
266
+ */
267
+ function w3_wp_delete_folders($folders, $method = '', $url = '', $context = false) {
268
+ $delete_folders = array();
269
+ foreach($folders as $folder) {
270
+ if (is_dir($folder) && file_exists($folder))
271
+ $delete_folders[] = $folder;
272
+ }
273
+ if (empty($delete_folders))
274
+ return;
275
+ w3_wp_request_filesystem_credentials($method, $url, $context);
276
+
277
+ global $wp_filesystem;
278
+
279
+ foreach($delete_folders as $folder) {
280
+ w3_rmdir($folder);
281
+ if (file_exists($folder))
282
+ if (!$wp_filesystem->rmdir($folder, FS_CHMOD_DIR)) {
283
+ throw new FileOperationException('Could not delete folder: ' . $folder, 'delete', 'folder', $folder);
284
+ }
285
+ }
286
+ }
287
+
288
+ /**
289
+ * @param $file
290
+ * @param string $method
291
+ * @param string $url
292
+ * @param bool|string $context folder where file to be deleted resides
293
+ * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
294
+ * @throws FileOperationException
295
+ */
296
+ function w3_wp_delete_file($file, $method = '', $url = '', $context = false) {
297
+ if (@unlink($file)) {
298
+ w3_wp_request_filesystem_credentials($method, $url, false, $context = false);
299
+
300
+ global $wp_filesystem;
301
+
302
+ if (file_exists($file) && !$wp_filesystem->delete($file)) {
303
+ throw new FileOperationException('Could not delete file: ' . $file, 'delete', 'file', $file);
304
+ }
305
+ }
306
+ }
307
+
308
+ /**
309
+ * Copy files using WordPress filesystem functions.
310
+ * @param $files
311
+ * @param string $method Which method to use when creating
312
+ * @param string $url Where to redirect after creation
313
+ * @param bool|string $context folder to copy too
314
+ * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
315
+ * @throws FileOperationException
316
+ */
317
+ function w3_wp_copy_files($files, $method = '', $url = '', $context = false) {
318
+ w3_wp_request_filesystem_credentials($method, $url, false, $context);
319
+
320
+ global $wp_filesystem;
321
+ foreach($files as $source_filename => $destination_filename) {
322
+ $contents = $wp_filesystem->get_contents($source_filename);
323
+
324
+ if (!$wp_filesystem->put_contents($destination_filename, $contents, FS_CHMOD_FILE)) {
325
+ throw new FileOperationException('Could not create file: ' . $destination_filename, 'create', 'file', $destination_filename);
326
+ }
327
+ }
328
+ }
329
+
330
+ /**
331
+ * Get WordPress filesystems credentials. Required for WP filesystem usage.
332
+ * @param string $method Which method to use when creating
333
+ * @param string $url Where to redirect after creation
334
+ * @param bool|string $context path to folder that should be have filesystem credentials. If false WP_CONTENT_DIR is assumed
335
+ * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
336
+ */
337
+ function w3_wp_request_filesystem_credentials($method = '', $url = '', $context = false) {
338
+ $success = true;
339
+ ob_start();
340
+ if (false === ($creds = request_filesystem_credentials($url, $method, false, $context, array()))) {
341
+ $success = false;
342
+ }
343
+ $form = ob_get_contents();
344
+ ob_end_clean();
345
+
346
+ ob_start();
347
+ // If first check failed try again and show error message
348
+ if (!WP_Filesystem($creds) && $success) {
349
+ request_filesystem_credentials($url, $method, true, false, array());
350
+ $success = false;
351
+ $form = ob_get_contents();
352
+ }
353
+ ob_end_clean();
354
+
355
+ if (!$success) {
356
+ throw new FilesystemCredentialException('Could not get write credentials', $method, $form);
357
+ }
358
+ }
359
+
360
+ /**
361
+ * @param $add_in_files array with key as source and value as destination
362
+ * @param $cache_folders value is the folder path
363
+ * @param string $method Which method to use when creating
364
+ * @param string $url Where to redirect after creation
365
+ * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials
366
+ * @throws FileOperationException
367
+ */
368
+ function w3_create_missing_files_and_folders($add_in_files, $cache_folders, $method = '', $url = '') {
369
+ if (empty($add_in_files) && empty($cache_folders))
370
+ return;
371
+
372
+ w3_wp_request_filesystem_credentials($method, $url);
373
+
374
+ global $wp_filesystem;
375
+
376
+ foreach($cache_folders as $folder) {
377
+ if (!$wp_filesystem->mkdir($folder, FS_CHMOD_DIR)) {
378
+ throw new FileOperationException('Could not create folder:' . $folder, 'create', 'folder', $folder);
379
+ }
380
+ }
381
+ foreach($add_in_files as $source_filename => $destination_filename) {
382
+ $contents = $wp_filesystem->get_contents($source_filename);
383
+
384
+ if (file_exists($destination_filename) && ! $wp_filesystem->delete($destination_filename))
385
+ throw new FileOperationException('Could not delete file: ' . $destination_filename, 'delete', 'file', $destination_filename);
386
+
387
+ if (!$wp_filesystem->put_contents($destination_filename, $contents, FS_CHMOD_FILE)) {
388
+ throw new FileOperationException('Could not create file: ' . $destination_filename, 'create', 'file', $destination_filename);
389
+ }
390
+ }
391
+ }
392
+
393
+ /**
394
+ * Create files
395
+ * @param $files array(from file => to file)
396
+ * @param string $method
397
+ * @param string $url
398
+ * @param bool|string path to folder where files should be created
399
+ * @throws FileOperationException
400
+ */
401
+ function w3_create_files($files, $method = '', $url = '', $context = false) {
402
+ if (empty($files))
403
+ return;
404
+
405
+ w3_wp_request_filesystem_credentials($method, $url, $context);
406
+
407
+ global $wp_filesystem;
408
+
409
+ foreach($files as $source_filename => $destination_filename) {
410
+ $contents = $wp_filesystem->get_contents($source_filename);
411
+
412