PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/w3-total-cache/inc/define.php

https://github.com/louieDA/bestilblomster
PHP | 1578 lines | 866 code | 228 blank | 484 comment | 165 complexity | 83141da87987b19d25a165350eae3ece MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, GPL-3.0, BSD-3-Clause, AGPL-1.0
  1. <?php
  2. if (!defined('ABSPATH')) {
  3. die();
  4. }
  5. define('W3TC', true);
  6. define('W3TC_VERSION', '0.9.3');
  7. define('W3TC_POWERED_BY', 'W3 Total Cache/' . W3TC_VERSION);
  8. define('W3TC_EMAIL', 'w3tc@w3-edge.com');
  9. define('W3TC_TEXT_DOMAIN', 'w3-total-cache');
  10. define('W3TC_PAYPAL_URL', 'https://www.paypal.com/cgi-bin/webscr');
  11. define('W3TC_PAYPAL_BUSINESS', 'w3tc-team@w3-edge.com');
  12. define('W3TC_LINK_URL', 'http://www.w3-edge.com/wordpress-plugins/');
  13. define('W3TC_LINK_NAME', 'WordPress Plugins');
  14. define('W3TC_FEED_URL', 'http://feeds.feedburner.com/W3TOTALCACHE');
  15. define('W3TC_NEWS_FEED_URL', 'http://feeds.feedburner.com/W3EDGE');
  16. define('W3TC_README_URL', 'http://plugins.svn.wordpress.org/w3-total-cache/trunk/readme.txt');
  17. define('W3TC_SUPPORT_US_TIMEOUT', 2592000);
  18. define('W3TC_SUPPORT_REQUEST_URL', 'http://www.w3-edge.com/?w3tc_support_request=1');
  19. define('NEWRELIC_SIGNUP_URL', 'http://newrelic.com/w3edge');
  20. define('MAXCDN_SIGNUP_URL', 'http://tracking.maxcdn.com/c/15753/3982/378?u=https%3A%2F%2Fsecure.maxcdn.com%2F%3Fpackage%3Dstarter%26coupon%3Dw3tc');
  21. // this is the URL our updater / license checker pings. This should be the URL of the site with EDD installed
  22. if (!defined('EDD_W3EDGE_STORE_URL')) define('EDD_W3EDGE_STORE_URL', 'http://www.w3-edge.com/' );
  23. if (!defined('EDD_W3EDGE_STORE_URL_PLUGIN')) define('EDD_W3EDGE_STORE_URL_PLUGIN', 'http://www.w3-edge.com/?w3tc_buy_pro_plugin' );
  24. // the name of your product. This should match the download name in EDD exactly
  25. define('EDD_W3EDGE_W3TC_NAME', 'W3 Total Cache Pro: Annual Subscription');
  26. define('W3TC_WIN', (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'));
  27. defined('W3TC_DIR') || define('W3TC_DIR', realpath(dirname(__FILE__) . '/..'));
  28. define('W3TC_FILE', 'w3-total-cache/w3-total-cache.php');
  29. define('W3TC_INC_DIR', W3TC_DIR . '/inc');
  30. define('W3TC_INC_WIDGET_DIR', W3TC_INC_DIR. '/widget');
  31. define('W3TC_INC_FUNCTIONS_DIR', W3TC_INC_DIR . '/functions');
  32. define('W3TC_INC_OPTIONS_DIR', W3TC_INC_DIR . '/options');
  33. define('W3TC_INC_LIGHTBOX_DIR', W3TC_INC_DIR . '/lightbox');
  34. define('W3TC_INC_POPUP_DIR', W3TC_INC_DIR . '/popup');
  35. define('W3TC_LIB_DIR', W3TC_DIR . '/lib');
  36. define('W3TC_LIB_W3_DIR', W3TC_LIB_DIR . '/W3');
  37. define('W3TC_LIB_MINIFY_DIR', W3TC_LIB_DIR . '/Minify');
  38. define('W3TC_LIB_CF_DIR', W3TC_LIB_DIR . '/CF');
  39. define('W3TC_LIB_CSSTIDY_DIR', W3TC_LIB_DIR . '/CSSTidy');
  40. define('W3TC_LIB_MICROSOFT_DIR', W3TC_LIB_DIR . '/Microsoft');
  41. define('W3TC_LIB_NUSOAP_DIR', W3TC_LIB_DIR . '/Nusoap');
  42. define('W3TC_LIB_NETDNA_DIR', W3TC_LIB_DIR . '/NetDNA');
  43. define('W3TC_LIB_OAUTH_DIR', W3TC_LIB_DIR . '/OAuth');
  44. define('W3TC_LIB_NEWRELIC_DIR', W3TC_LIB_DIR . '/NewRelic');
  45. define('W3TC_PLUGINS_DIR', W3TC_DIR . '/plugins');
  46. define('W3TC_INSTALL_DIR', W3TC_DIR . '/wp-content');
  47. define('W3TC_INSTALL_MINIFY_DIR', W3TC_INSTALL_DIR . '/w3tc/min');
  48. define('W3TC_LANGUAGES_DIR', W3TC_DIR . '/languages');
  49. define('W3TC_CACHE_DIR', WP_CONTENT_DIR . '/cache');
  50. define('W3TC_CONFIG_DIR', WP_CONTENT_DIR . '/w3tc-config');
  51. define('W3TC_CACHE_CONFIG_DIR', W3TC_CACHE_DIR . '/config');
  52. define('W3TC_CACHE_MINIFY_DIR', W3TC_CACHE_DIR . '/minify');
  53. define('W3TC_CACHE_PAGE_ENHANCED_DIR', W3TC_CACHE_DIR . '/page_enhanced');
  54. define('W3TC_CACHE_TMP_DIR', W3TC_CACHE_DIR . '/tmp');
  55. define('W3TC_CACHE_BLOGMAP_FILENAME', W3TC_CACHE_DIR . '/blogs.php');
  56. defined('WP_CONTENT_DIR') || define('WP_CONTENT_DIR', realpath(W3TC_DIR . '/../..'));
  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_INSTALL_FILE_ADVANCED_CACHE', W3TC_INSTALL_DIR . '/advanced-cache.php');
  62. define('W3TC_INSTALL_FILE_DB', W3TC_INSTALL_DIR . '/db.php');
  63. define('W3TC_INSTALL_FILE_OBJECT_CACHE', W3TC_INSTALL_DIR . '/object-cache.php');
  64. define('W3TC_ADDIN_FILE_ADVANCED_CACHE', WP_CONTENT_DIR . '/advanced-cache.php');
  65. define('W3TC_ADDIN_FILE_DB', WP_CONTENT_DIR . '/db.php');
  66. define('W3TC_FILE_DB_CLUSTER_CONFIG', WP_CONTENT_DIR . '/db-cluster-config.php');
  67. define('W3TC_ADDIN_FILE_OBJECT_CACHE', WP_CONTENT_DIR . '/object-cache.php');
  68. define('W3TC_WP_LOADER', (defined('WP_PLUGIN_DIR') ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins') . '/w3tc-wp-loader.php');
  69. if (!defined('W3TC_EXTENSION_DIR'))
  70. define('W3TC_EXTENSION_DIR', (defined('WP_PLUGIN_DIR') ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins'));
  71. w3_require_once(W3TC_INC_DIR . '/functions/compat.php');
  72. w3_require_once(W3TC_INC_DIR . '/functions/plugin.php');
  73. @ini_set('pcre.backtrack_limit', 4194304);
  74. @ini_set('pcre.recursion_limit', 4194304);
  75. global $w3_late_init;
  76. $w3_late_init = false;
  77. /**
  78. * Returns current microtime
  79. *
  80. * @return double
  81. */
  82. function w3_microtime() {
  83. list ($usec, $sec) = explode(' ', microtime());
  84. return ((double) $usec + (double) $sec);
  85. }
  86. /**
  87. * Check if content is HTML or XML
  88. *
  89. * @param string $content
  90. * @return boolean
  91. */
  92. function w3_is_xml($content) {
  93. if (strlen($content) > 1000) {
  94. $content = substr($content, 0, 1000);
  95. }
  96. if (strstr($content, '<!--') !== false) {
  97. $content = preg_replace('~<!--.*?-->~s', '', $content);
  98. }
  99. $content = ltrim($content, "\x00\x09\x0A\x0D\x20\xBB\xBF\xEF");
  100. return (stripos($content, '<?xml') === 0 || stripos($content, '<html') === 0 || stripos($content, '<!DOCTYPE') === 0);
  101. }
  102. /**
  103. * If content can handle HTML comments, can disable printout per request using filter 'w3tc_can_print_comment'
  104. * @param $buffer
  105. * @return bool
  106. */
  107. function w3_can_print_comment(&$buffer) {
  108. if (function_exists('apply_filters'))
  109. return apply_filters('w3tc_can_print_comment', w3_is_xml($buffer) && !defined('DOING_AJAX'));
  110. return w3_is_xml($buffer) && !defined('DOING_AJAX');
  111. }
  112. /*
  113. * Returns URI from filename/dirname
  114. *
  115. * @return string
  116. */
  117. function w3_filename_to_url($filename) {
  118. // using wp-content instead of document_root as known dir since dirbased
  119. // multisite wp adds blogname to the path inside site_url
  120. if (substr($filename, 0, strlen(WP_CONTENT_DIR)) != WP_CONTENT_DIR)
  121. return '';
  122. $uri_from_wp_content = substr($filename, strlen(WP_CONTENT_DIR));
  123. $site_url_ssl = w3_get_url_ssl(w3_get_home_url());
  124. $dir = '';
  125. if (substr(WP_CONTENT_DIR, 0, strlen(w3_get_site_root())) == w3_get_site_root()) {
  126. $dir = str_replace($site_url_ssl, '', w3_get_url_ssl(w3_get_site_url()));
  127. $dir = trim($dir, '/\\');
  128. if ($dir)
  129. $dir = '/' . $dir;
  130. $content_path = trim(substr(WP_CONTENT_DIR, strlen(w3_get_site_root())), '/\\');
  131. }
  132. else
  133. $content_path = trim(substr(WP_CONTENT_DIR, strlen(w3_get_document_root())), '/\\');
  134. $url = $site_url_ssl . $dir . '/' . $content_path . $uri_from_wp_content;
  135. return $url;
  136. }
  137. /**
  138. * Returns true if database cluster is used
  139. *
  140. * @return boolean
  141. */
  142. function w3_is_dbcluster() {
  143. return defined('W3TC_FILE_DB_CLUSTER_CONFIG') && @file_exists(W3TC_FILE_DB_CLUSTER_CONFIG)
  144. && defined('W3TC_ENTERPRISE') && W3TC_ENTERPRISE;
  145. }
  146. /**
  147. * Returns true if it's WPMU
  148. *
  149. * @return boolean
  150. */
  151. function w3_is_wpmu() {
  152. static $wpmu = null;
  153. if ($wpmu === null) {
  154. $wpmu = file_exists(ABSPATH . 'wpmu-settings.php');
  155. }
  156. return $wpmu;
  157. }
  158. /**
  159. * Returns true if WPMU uses vhosts
  160. *
  161. * @return boolean
  162. */
  163. function w3_is_subdomain_install() {
  164. return ((defined('SUBDOMAIN_INSTALL') && SUBDOMAIN_INSTALL) || (defined('VHOST') && VHOST == 'yes'));
  165. }
  166. /**
  167. * Returns true if it's WP with enabled Network mode
  168. *
  169. * @return boolean
  170. */
  171. function w3_is_multisite() {
  172. static $multisite = null;
  173. if ($multisite === null) {
  174. $multisite = ((defined('MULTISITE') && MULTISITE) || defined('SUNRISE') || w3_is_subdomain_install());
  175. }
  176. return $multisite;
  177. }
  178. /**
  179. * Returns if there is multisite mode
  180. *
  181. * @return boolean
  182. */
  183. function w3_is_network() {
  184. return (w3_is_wpmu() || w3_is_multisite());
  185. }
  186. /**
  187. * Check if URL is valid
  188. *
  189. * @param string $url
  190. * @return boolean
  191. */
  192. function w3_is_url($url) {
  193. return preg_match('~^(https?:)?//~', $url);
  194. }
  195. /**
  196. * Returns true if current connection is secure
  197. *
  198. * @return boolean
  199. */
  200. function w3_is_https() {
  201. switch (true) {
  202. case (isset($_SERVER['HTTPS']) && w3_to_boolean($_SERVER['HTTPS'])):
  203. case (isset($_SERVER['SERVER_PORT']) && (int) $_SERVER['SERVER_PORT'] == 443):
  204. return true;
  205. }
  206. return false;
  207. }
  208. /**
  209. * Check if there was database error
  210. *
  211. * @param string $content
  212. * @return boolean
  213. */
  214. function w3_is_database_error(&$content) {
  215. return (stristr($content, '<title>Database Error</title>') !== false);
  216. }
  217. /**
  218. * Retuns true if preview settings active
  219. *
  220. * @return boolean
  221. */
  222. function w3_is_preview_mode() {
  223. return (isset($_REQUEST['w3tc_preview']) ||
  224. (isset($_SERVER['HTTP_REFERER']) &&
  225. strstr($_SERVER['HTTP_REFERER'], 'w3tc_preview') !== false));
  226. }
  227. /**
  228. * Returns true if server is Apache
  229. *
  230. * @return boolean
  231. */
  232. function w3_is_apache() {
  233. return (isset($_SERVER['SERVER_SOFTWARE']) && stristr($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false);
  234. }
  235. /**
  236. * Check whether server is LiteSpeed
  237. *
  238. * @return bool
  239. */
  240. function w3_is_litespeed() {
  241. return (isset($_SERVER['SERVER_SOFTWARE']) && stristr($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') !== false);
  242. }
  243. /**
  244. * Returns true if server is nginx
  245. *
  246. * @return boolean
  247. */
  248. function w3_is_nginx() {
  249. return (isset($_SERVER['SERVER_SOFTWARE']) && stristr($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false);
  250. }
  251. /**
  252. * Check whether $engine is correct CDN engine
  253. *
  254. * @param string $engine
  255. * @return boolean
  256. */
  257. function w3_is_cdn_engine($engine) {
  258. return in_array($engine, array('ftp', 's3', 'cf', 'cf2', 'rscf', 'azure', 'mirror', 'netdna', 'maxcdn',
  259. 'cotendo', 'akamai', 'edgecast', 'att'));
  260. }
  261. /**
  262. * Returns true if CDN engine is mirror
  263. *
  264. * @param string $engine
  265. * @return bool
  266. */
  267. function w3_is_cdn_mirror($engine) {
  268. return in_array($engine, array('mirror', 'netdna', 'maxcdn', 'cotendo', 'cf2', 'akamai', 'edgecast', 'att'));
  269. }
  270. /**
  271. * Returns true if CDN has purge all support
  272. * @param $engine
  273. * @return bool
  274. */
  275. function w3_cdn_can_purge_all($engine) {
  276. return in_array($engine, array('cotendo', 'edgecast', 'att', 'netdna', 'maxcdn'));
  277. }
  278. /**
  279. * Returns domain from host
  280. *
  281. * @param string $host
  282. * @return string
  283. */
  284. function w3_get_domain($host) {
  285. $host = strtolower($host);
  286. if (($pos = strpos($host, ':')) !== false) {
  287. $host = substr($host, 0, $pos);
  288. }
  289. $host = rtrim($host, '.');
  290. return $host;
  291. }
  292. /**
  293. * Returns array of all available blognames
  294. *
  295. * @return array
  296. */
  297. function w3_get_blognames() {
  298. global $wpdb;
  299. $blognames = array();
  300. $sql = sprintf('SELECT domain, path FROM %s', $wpdb->blogs);
  301. $blogs = $wpdb->get_results($sql);
  302. if ($blogs) {
  303. $base_path = w3_get_base_path();
  304. foreach ($blogs as $blog) {
  305. $blogname = trim(str_replace($base_path, '', $blog->path), '/');
  306. if ($blogname) {
  307. $blognames[] = $blogname;
  308. }
  309. }
  310. }
  311. return $blognames;
  312. }
  313. /**
  314. * Returns current blog ID
  315. *
  316. * @return integer
  317. */
  318. function w3_get_blog_id() {
  319. global $w3_current_blog_id;
  320. if (!is_null($w3_current_blog_id))
  321. return $w3_current_blog_id;
  322. if (!w3_is_network() || is_network_admin()) {
  323. $w3_current_blog_id = 0;
  324. return $w3_current_blog_id;
  325. }
  326. $blog_data = w3_blogmap_get_blog_data();
  327. if (!is_null($blog_data))
  328. $w3_current_blog_id = substr($blog_data, 1);
  329. else
  330. $w3_current_blog_id = 0;
  331. return $w3_current_blog_id;
  332. }
  333. /**
  334. * Returns blogmap filename by home url
  335. *
  336. * @param string $blog_home_url
  337. * @return string
  338. */
  339. function w3_blogmap_filename($blog_home_url) {
  340. if (!defined('W3TC_BLOG_LEVELS'))
  341. return W3TC_CACHE_BLOGMAP_FILENAME;
  342. else {
  343. $filename = dirname(W3TC_CACHE_BLOGMAP_FILENAME) . '/' .
  344. basename(W3TC_CACHE_BLOGMAP_FILENAME, '.php') . '/';
  345. $s = md5($blog_home_url);
  346. for ($n = 0; $n < W3TC_BLOG_LEVELS; $n++)
  347. $filename .= substr($s, $n, 1) . '/';
  348. return $filename . basename(W3TC_CACHE_BLOGMAP_FILENAME);
  349. }
  350. }
  351. /**
  352. * Returns blog_id by home url
  353. * If database not initialized yet - returns 0
  354. *
  355. * @return integer
  356. */
  357. function w3_blogmap_get_blog_data() {
  358. $host = w3_get_host();
  359. // subdomain
  360. if (w3_is_subdomain_install()) {
  361. $blog_data = w3_blogmap_try_get_blog_data($host);
  362. if (is_null($blog_data))
  363. $GLOBALS['w3tc_blogmap_register_new_item'] = $host;
  364. return $blog_data;
  365. } else {
  366. // try subdir blog
  367. $url = $host . $_SERVER['REQUEST_URI'];
  368. $pos = strpos($url, '?');
  369. if ($pos !== false)
  370. $url = substr($url, 0, $pos);
  371. $url = rtrim($url, '/');
  372. $start_url = $url;
  373. for (;;) {
  374. $blog_data = w3_blogmap_try_get_blog_data($url);
  375. if (!is_null($blog_data))
  376. return $blog_data;
  377. $pos = strrpos($url, '/');
  378. if ($pos === false)
  379. break;
  380. $url = rtrim(substr($url, 0, $pos), '/');
  381. }
  382. $GLOBALS['w3tc_blogmap_register_new_item'] = $start_url;
  383. return null;
  384. }
  385. }
  386. function w3_blogmap_try_get_blog_data($url) {
  387. $filename = w3_blogmap_filename($url);
  388. if (file_exists($filename)) {
  389. $data = file_get_contents($filename);
  390. $blog_data = @eval($data);
  391. if (is_array($blog_data) && isset($blog_data[$url]))
  392. return $blog_data[$url];
  393. }
  394. return null;
  395. }
  396. /**
  397. * @return bool
  398. */
  399. function w3_force_master() {
  400. global $w3_force_master;
  401. if (!is_null($w3_force_master))
  402. return $w3_force_master;
  403. if (!w3_is_multisite())
  404. $w3_force_master = false;
  405. else {
  406. $blog_data = w3_blogmap_get_blog_data();
  407. if (is_null($blog_data) ||
  408. ($blog_data[0] != 'm' && $blog_data[0] != 'c'))
  409. $w3_force_master = true;
  410. else
  411. $w3_force_master = ($blog_data[0] == 'm');
  412. }
  413. return $w3_force_master;
  414. }
  415. /**
  416. * Returns path to section's cache dir
  417. *
  418. * @param string $section
  419. * @return string
  420. */
  421. function w3_cache_dir($section) {
  422. return W3TC_CACHE_DIR . '/' . $section;
  423. }
  424. /**
  425. * Returns path to blog's cache dir
  426. *
  427. * @param string $section
  428. * @param null|int $blog_id
  429. * @return string
  430. */
  431. function w3_cache_blog_dir($section, $blog_id = null) {
  432. if (is_null($blog_id))
  433. $blog_id = w3_get_blog_id();
  434. $postfix = sprintf('%06d', $blog_id);
  435. if (defined('W3TC_BLOG_LEVELS')) {
  436. for ($n = 0; $n < W3TC_BLOG_LEVELS; $n++)
  437. $postfix = substr($postfix, strlen($postfix) - 1 - $n, 1) . '/' .
  438. $postfix;
  439. }
  440. return w3_cache_dir($section) . '/' . $postfix;
  441. }
  442. /**
  443. * Return full path to log file for module
  444. * Path used in priority
  445. * 1) W3TC_DEBUG_DIR
  446. * 2) WP_DEBUG_LOG
  447. * 3) W3TC_CACHE_DIR
  448. *
  449. * @param $module
  450. * @param null $blog_id
  451. * @return string
  452. */
  453. function w3_debug_log($module, $blog_id = null) {
  454. if (is_null($blog_id))
  455. $blog_id = w3_get_blog_id();
  456. $postfix = sprintf('%06d', $blog_id);
  457. if (defined('W3TC_BLOG_LEVELS')) {
  458. for ($n = 0; $n < W3TC_BLOG_LEVELS; $n++)
  459. $postfix = substr($postfix, strlen($postfix) - 1 - $n, 1) . '/' .
  460. $postfix;
  461. }
  462. $from_dir = W3TC_CACHE_DIR;
  463. if (defined('W3TC_DEBUG_DIR') && W3TC_DEBUG_DIR) {
  464. $dir_path = W3TC_DEBUG_DIR;
  465. if (!is_dir(W3TC_DEBUG_DIR))
  466. $from_dir = dirname(W3TC_DEBUG_DIR);
  467. } else
  468. $dir_path = w3_cache_dir('log');
  469. $filename = $dir_path . '/' . $postfix . '/' . $module . '.log';
  470. if (!is_dir(dirname($filename))) {
  471. w3_require_once( W3TC_INC_DIR . '/functions/file.php');
  472. w3_mkdir_from(dirname($filename), $from_dir);
  473. }
  474. return $filename;
  475. }
  476. /**
  477. * Returns URL regexp from URL
  478. *
  479. * @param string $url
  480. * @return string
  481. */
  482. function w3_get_url_regexp($url) {
  483. $url = preg_replace('~(https?:)?//~i', '', $url);
  484. $url = preg_replace('~^www\.~i', '', $url);
  485. $regexp = '(https?:)?//(www\.)?' . w3_preg_quote($url);
  486. return $regexp;
  487. }
  488. /**
  489. * Returns SSL URL if current connection is https
  490. * @param string $url
  491. * @return string
  492. */
  493. function w3_get_url_ssl($url) {
  494. if (w3_is_https()) {
  495. $url = str_replace('http://', 'https://', $url);
  496. }
  497. return $url;
  498. }
  499. /**
  500. * Get domain URL
  501. *
  502. * @return string
  503. */
  504. function w3_get_domain_url() {
  505. $home_url = w3_get_home_url();
  506. $parse_url = @parse_url($home_url);
  507. if ($parse_url && isset($parse_url['scheme']) && isset($parse_url['host'])) {
  508. $scheme = $parse_url['scheme'];
  509. $host = $parse_url['host'];
  510. $port = (isset($parse_url['port']) && $parse_url['port'] != 80 ? ':' . (int) $parse_url['port'] : '');
  511. $domain_url = sprintf('%s://%s%s', $scheme, $host, $port);
  512. return $domain_url;
  513. }
  514. return false;
  515. }
  516. /**
  517. * Returns domain url regexp
  518. *
  519. * @return string
  520. */
  521. function w3_get_domain_url_regexp() {
  522. $domain_url = w3_get_domain_url();
  523. $regexp = w3_get_url_regexp($domain_url);
  524. return $regexp;
  525. }
  526. /**
  527. * Returns home URL
  528. *
  529. * No trailing slash!
  530. *
  531. * @return string
  532. */
  533. function w3_get_home_url() {
  534. static $home_url = null;
  535. if ($home_url === null) {
  536. $config = w3_instance('W3_Config');
  537. if (w3_is_multisite() && $config->get_boolean('common.force_master')) {
  538. $home_url = get_home_url();
  539. } else {
  540. // get_option is unusable here, it can cause problem when objCache isn't yet initialized
  541. // Which is why we save the 'home' option in our ConfigCache
  542. // We don't just use $config->get_string, because we want the cache to rebuild
  543. // when 'wordpress.home' is not (yet) present
  544. $home_url = $config->get_cache_option('wordpress.home');
  545. $home_url = rtrim($home_url, '/');
  546. }
  547. }
  548. return $home_url;
  549. }
  550. /**
  551. * Returns SSL home url
  552. *
  553. * @return string
  554. */
  555. function w3_get_home_url_ssl() {
  556. $home_url = w3_get_home_url();
  557. $ssl = w3_get_url_ssl($home_url);
  558. return $ssl;
  559. }
  560. /**
  561. * Returns home url regexp
  562. *
  563. * @return string
  564. */
  565. function w3_get_home_url_regexp() {
  566. $home_url = w3_get_home_url();
  567. $regexp = w3_get_url_regexp($home_url);
  568. return $regexp;
  569. }
  570. /**
  571. * Network installs returns wrong wp site path
  572. * @return string
  573. */
  574. function w3_get_wp_sitepath() {
  575. if (w3_is_network()) {
  576. global $current_site;
  577. return $current_site->path;
  578. } else {
  579. return w3_get_site_path();
  580. }
  581. }
  582. /**
  583. * Returns site URL
  584. *
  585. * No trailing slash!
  586. *
  587. * @return string
  588. */
  589. function w3_get_site_url() {
  590. static $site_url = null;
  591. if ($site_url === null) {
  592. $site_url = get_option('siteurl');
  593. $site_url = rtrim($site_url, '/');
  594. }
  595. return $site_url;
  596. }
  597. /**
  598. * Returns SSL site URL
  599. *
  600. * @return string
  601. */
  602. function w3_get_site_url_ssl() {
  603. $site_url = w3_get_site_url();
  604. $ssl = w3_get_url_ssl($site_url);
  605. return $ssl;
  606. }
  607. /**
  608. * Returns absolute path to document root
  609. *
  610. * No trailing slash!
  611. *
  612. * @return string
  613. */
  614. function w3_get_document_root() {
  615. static $document_root = null;
  616. $len = strlen($_SERVER['PHP_SELF']);
  617. $split = $len/2;
  618. if ($document_root === null) {
  619. if (!empty($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == $_SERVER['PHP_SELF']) {
  620. $document_root = w3_get_site_root();
  621. } elseif (!empty($_SERVER['SCRIPT_FILENAME'])) {
  622. $document_root = substr(w3_path($_SERVER['SCRIPT_FILENAME']), 0, -strlen(w3_path($_SERVER['PHP_SELF'])));
  623. } elseif (!empty($_SERVER['PATH_TRANSLATED'])) {
  624. $document_root = substr(w3_path($_SERVER['PATH_TRANSLATED']), 0, -strlen(w3_path($_SERVER['PHP_SELF'])));
  625. } elseif (!empty($_SERVER['DOCUMENT_ROOT'])) {
  626. $document_root = w3_path($_SERVER['DOCUMENT_ROOT']);
  627. } else {
  628. $document_root = w3_get_site_root();
  629. }
  630. $document_root = realpath($document_root);
  631. $document_root = w3_path($document_root);
  632. }
  633. return $document_root;
  634. }
  635. /**
  636. * Returns absolute path to home directory
  637. *
  638. * Example:
  639. *
  640. * DOCUMENT_ROOT=/var/www/vhosts/domain.com
  641. * Install dir=/var/www/vhosts/domain.com/site/blog
  642. * home=http://domain.com/site
  643. * siteurl=http://domain.com/site/blog
  644. * return /var/www/vhosts/domain.com/site
  645. *
  646. * No trailing slash!
  647. *
  648. * @return string
  649. */
  650. function w3_get_home_root() {
  651. if (w3_is_network()) {
  652. $path = w3_get_base_path();
  653. } else {
  654. $path = w3_get_home_path();
  655. }
  656. $home_root = w3_get_document_root() . $path;
  657. $home_root = realpath($home_root);
  658. $home_root = w3_path($home_root);
  659. return $home_root;
  660. }
  661. /**
  662. * Returns absolute path to blog install dir
  663. *
  664. * Example:
  665. *
  666. * DOCUMENT_ROOT=/var/www/vhosts/domain.com
  667. * install dir=/var/www/vhosts/domain.com/site/blog
  668. * return /var/www/vhosts/domain.com/site/blog
  669. *
  670. * No trailing slash!
  671. *
  672. * @return string
  673. */
  674. function w3_get_site_root() {
  675. $site_root = ABSPATH;
  676. $site_root = realpath($site_root);
  677. $site_root = w3_path($site_root);
  678. return $site_root;
  679. }
  680. /**
  681. * Returns blog path
  682. *
  683. * Example:
  684. *
  685. * siteurl=http://domain.com/site/blog
  686. * return /site/blog/
  687. *
  688. * With trailing slash!
  689. *
  690. * @return string
  691. */
  692. function w3_get_site_path() {
  693. $site_url = w3_get_site_url();
  694. $parse_url = @parse_url($site_url);
  695. if ($parse_url && isset($parse_url['path'])) {
  696. $site_path = '/' . ltrim($parse_url['path'], '/');
  697. } else {
  698. $site_path = '/';
  699. }
  700. if (substr($site_path, -1) != '/') {
  701. $site_path .= '/';
  702. }
  703. return $site_path;
  704. }
  705. /**
  706. * Returns home domain
  707. *
  708. * @return string
  709. */
  710. function w3_get_home_domain() {
  711. $home_url = w3_get_home_url();
  712. $parse_url = @parse_url($home_url);
  713. if ($parse_url && isset($parse_url['host'])) {
  714. return $parse_url['host'];
  715. }
  716. return w3_get_host();
  717. }
  718. /**
  719. * Returns home path
  720. *
  721. * Example:
  722. *
  723. * home=http://domain.com/site/
  724. * siteurl=http://domain.com/site/blog
  725. * return /site/
  726. *
  727. * With trailing slash!
  728. *
  729. * @return string
  730. */
  731. function w3_get_home_path() {
  732. $home_url = w3_get_home_url();
  733. $parse_url = @parse_url($home_url);
  734. if ($parse_url && isset($parse_url['path'])) {
  735. $home_path = '/' . ltrim($parse_url['path'], '/');
  736. } else {
  737. $home_path = '/';
  738. }
  739. if (substr($home_path, -1) != '/') {
  740. $home_path .= '/';
  741. }
  742. return $home_path;
  743. }
  744. /**
  745. * Returns path to WP directory relative to document root
  746. *
  747. * Example:
  748. *
  749. * DOCUMENT_ROOT=/var/www/vhosts/domain.com/
  750. * Install dir=/var/www/vhosts/domain.com/site/blog/
  751. * return /site/blog/
  752. *
  753. * With trailing slash!
  754. *
  755. * @return string
  756. */
  757. function w3_get_base_path() {
  758. $document_root = w3_get_document_root();
  759. $site_root = w3_get_site_root();
  760. $base_path = str_replace($document_root, '', $site_root);
  761. $base_path = '/' . ltrim($base_path, '/');
  762. if (substr($base_path, -1) != '/') {
  763. $base_path .= '/';
  764. }
  765. return $base_path;
  766. }
  767. /**
  768. * Returns server hostname
  769. *
  770. * @return string
  771. */
  772. function w3_get_host() {
  773. static $host = null;
  774. if ($host === null) {
  775. if (!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
  776. $host = $_SERVER['HTTP_X_FORWARDED_HOST'];
  777. } elseif (!empty($_SERVER['HTTP_HOST'])) {
  778. // HTTP_HOST sometimes is not set causing warning
  779. $host = $_SERVER['HTTP_HOST'];
  780. } else {
  781. $host = '';
  782. }
  783. }
  784. return $host;
  785. }
  786. /**
  787. * Returns host ID
  788. *
  789. * @return string
  790. */
  791. function w3_get_host_id() {
  792. static $host_id = null;
  793. if ($host_id === null) {
  794. $host = w3_get_host();
  795. $blog_id = w3_get_blog_id();
  796. $host_id = sprintf('%s_%d', $host, $blog_id);
  797. }
  798. return $host_id;
  799. }
  800. /**
  801. * Returns WP config file path
  802. *
  803. * @return string
  804. */
  805. function w3_get_wp_config_path() {
  806. $search = array(
  807. ABSPATH . 'wp-config.php',
  808. dirname(ABSPATH) . '/wp-config.php'
  809. );
  810. foreach ($search as $path) {
  811. if (file_exists($path)) {
  812. return $path;
  813. }
  814. }
  815. return false;
  816. }
  817. /**
  818. * Returns theme key
  819. *
  820. * @param string $theme_root
  821. * @param string $template
  822. * @param string $stylesheet
  823. * @return string
  824. */
  825. function w3_get_theme_key($theme_root, $template, $stylesheet) {
  826. $site_root = w3_get_site_root();
  827. $theme_path = ltrim(str_replace($site_root, '', w3_path($theme_root)), '/');
  828. return substr(md5($theme_path . $template . $stylesheet), 0, 5);
  829. }
  830. /**
  831. * Returns theme key (legacy support)
  832. *
  833. * @param string $theme_root
  834. * @param string $template
  835. * @param string $stylesheet
  836. * @return string
  837. */
  838. function w3_get_theme_key_legacy($theme_root, $template, $stylesheet) {
  839. return substr(md5($theme_root . $template . $stylesheet), 0, 6);
  840. }
  841. /**
  842. * Returns true if we can check rules
  843. *
  844. * @return bool
  845. */
  846. function w3_can_check_rules() {
  847. return (w3_is_apache() || w3_is_litespeed() || w3_is_nginx());
  848. }
  849. /**
  850. * Returns true if CDN engine is supporting purge
  851. *
  852. * @param string $engine
  853. * @return bool
  854. */
  855. function w3_can_cdn_purge($engine) {
  856. return in_array($engine, array('ftp', 's3', 'cf', 'cf2', 'rscf', 'azure', 'netdna', 'maxcdn', 'cotendo',
  857. 'edgecast', 'akamai', 'att'));
  858. }
  859. /**
  860. * Parses path
  861. *
  862. * @param string $path
  863. * @return mixed
  864. */
  865. function w3_parse_path($path) {
  866. $path = str_replace(array(
  867. '%BLOG_ID%',
  868. '%POST_ID%',
  869. '%BLOG_ID%',
  870. '%HOST%',
  871. '%DOMAIN%',
  872. '%BASE_PATH%'
  873. ), array(
  874. (isset($GLOBALS['blog_id']) ? (int) $GLOBALS['blog_id'] : 0),
  875. (isset($GLOBALS['post_id']) ? (int) $GLOBALS['post_id'] : 0),
  876. w3_get_blog_id(),
  877. w3_get_host(),
  878. w3_get_domain(w3_get_host()),
  879. trim(w3_get_base_path(), '/')
  880. ), $path);
  881. return $path;
  882. }
  883. /**
  884. * Normalizes file name
  885. *
  886. * Relative to site root!
  887. *
  888. * @param string $file
  889. * @return string
  890. */
  891. function w3_normalize_file($file) {
  892. if (w3_is_url($file)) {
  893. if (strstr($file, '?') === false) {
  894. $home_url_regexp = '~' . w3_get_home_url_regexp() . '~i';
  895. $file = preg_replace($home_url_regexp, '', $file);
  896. }
  897. }
  898. if (!w3_is_url($file)) {
  899. $file = w3_path($file);
  900. $file = str_replace(w3_get_site_root(), '', $file);
  901. $file = ltrim($file, '/');
  902. }
  903. return $file;
  904. }
  905. /**
  906. * Normalizes file name for minify
  907. *
  908. * Relative to document root!
  909. *
  910. * @param string $file
  911. * @return string
  912. */
  913. function w3_normalize_file_minify($file) {
  914. if (w3_is_url($file)) {
  915. if (strstr($file, '?') === false) {
  916. $domain_url_regexp = '~' . w3_get_domain_url_regexp() . '~i';
  917. $file = preg_replace($domain_url_regexp, '', $file);
  918. }
  919. }
  920. if (!w3_is_url($file)) {
  921. $file = w3_path($file);
  922. $file = str_replace(w3_get_document_root(), '', $file);
  923. $file = ltrim($file, '/');
  924. }
  925. return $file;
  926. }
  927. /**
  928. * Normalizes file name for minify
  929. *
  930. * Relative to document root!
  931. *
  932. * @param string $file
  933. * @return string
  934. */
  935. function w3_normalize_file_minify2($file) {
  936. $file = w3_remove_query($file);
  937. $file = w3_normalize_file_minify($file);
  938. $file = w3_translate_file($file);
  939. return $file;
  940. }
  941. /**
  942. * Translates remote file to local file
  943. *
  944. * @param string $file
  945. * @return string
  946. */
  947. function w3_translate_file($file) {
  948. if (!w3_is_url($file)) {
  949. $file = '/' . ltrim($file, '/');
  950. $regexp = '~^' . w3_preg_quote(w3_get_site_path()) . '~';
  951. $file = preg_replace($regexp, w3_get_base_path(), $file);
  952. $file = ltrim($file, '/');
  953. }
  954. return $file;
  955. }
  956. /**
  957. * Remove WP query string from URL
  958. *
  959. * @param string $url
  960. * @return string
  961. */
  962. function w3_remove_query($url) {
  963. $url = preg_replace('~[&\?]+(ver=([a-z0-9-_\.]+|[0-9-]+))~i', '', $url);
  964. return $url;
  965. }
  966. /**
  967. * Converts win path to unix
  968. *
  969. * @param string $path
  970. * @return string
  971. */
  972. function w3_path($path) {
  973. $path = preg_replace('~[/\\\]+~', '/', $path);
  974. $path = rtrim($path, '/');
  975. return $path;
  976. }
  977. /**
  978. * Returns real path of given path
  979. *
  980. * @param string $path
  981. * @return string
  982. */
  983. function w3_realpath($path) {
  984. $path = w3_path($path);
  985. $parts = explode('/', $path);
  986. $absolutes = array();
  987. foreach ($parts as $part) {
  988. if ('.' == $part) {
  989. continue;
  990. }
  991. if ('..' == $part) {
  992. array_pop($absolutes);
  993. } else {
  994. $absolutes[] = $part;
  995. }
  996. }
  997. return implode('/', $absolutes);
  998. }
  999. /**
  1000. * Returns GMT date
  1001. * @param integer $time
  1002. * @return string
  1003. */
  1004. function w3_http_date($time) {
  1005. return gmdate('D, d M Y H:i:s \G\M\T', $time);
  1006. }
  1007. /**
  1008. * Redirects to URL
  1009. *
  1010. * @param string $url
  1011. * @param array $params
  1012. * @return string
  1013. */
  1014. function w3_redirect($url = '', $params = array()) {
  1015. w3_require_once(W3TC_INC_DIR . '/functions/url.php');
  1016. $url = w3_url_format($url, $params);
  1017. if (function_exists('do_action'))
  1018. do_action('w3_redirect');
  1019. @header('Location: ' . $url);
  1020. exit();
  1021. }
  1022. /**
  1023. * Redirects to URL
  1024. *
  1025. * @param string $url
  1026. * @param array $params
  1027. *
  1028. * @return string
  1029. */
  1030. function w3_redirect_temp( $url = '', $params = array() ) {
  1031. w3_require_once( W3TC_INC_DIR . '/functions/url.php' );
  1032. $url = w3_url_format( $url, $params );
  1033. if (function_exists('do_action'))
  1034. do_action( 'w3_redirect' );
  1035. $status_code = 301;
  1036. $protocol = $_SERVER["SERVER_PROTOCOL"];
  1037. if ( 'HTTP/1.1' === $protocol ) {
  1038. $status_code = 307;
  1039. }
  1040. $text = get_status_header_desc( $status_code );
  1041. if ( !empty( $text ) ) {
  1042. $status_header = "$protocol $status_code $text";
  1043. @header( $status_header, true, $status_code );
  1044. }
  1045. @header( 'Location: ' . $url, true, $status_code );
  1046. exit();
  1047. }
  1048. /**
  1049. * Returns caching engine name
  1050. *
  1051. * @param $engine
  1052. * @param $module
  1053. *
  1054. * @return string
  1055. */
  1056. function w3_get_engine_name($engine, $module = '') {
  1057. switch ($engine) {
  1058. case 'memcached':
  1059. $engine_name = 'memcached';
  1060. break;
  1061. case 'apc':
  1062. $engine_name = 'apc';
  1063. break;
  1064. case 'eaccelerator':
  1065. $engine_name = 'eaccelerator';
  1066. break;
  1067. case 'xcache':
  1068. $engine_name = 'xcache';
  1069. break;
  1070. case 'wincache':
  1071. $engine_name = 'wincache';
  1072. break;
  1073. case 'file':
  1074. if ($module == 'pgcache')
  1075. $engine_name = 'disk: basic';
  1076. else
  1077. $engine_name = 'disk';
  1078. break;
  1079. case 'file_generic':
  1080. $engine_name = 'disk: enhanced';
  1081. break;
  1082. case 'ftp':
  1083. $engine_name = 'self-hosted / file transfer protocol upload';
  1084. break;
  1085. case 's3':
  1086. $engine_name = 'amazon simple storage service (s3)';
  1087. break;
  1088. case 'cf':
  1089. $engine_name = 'amazon cloudfront';
  1090. break;
  1091. case 'cf2':
  1092. $engine_name = 'amazon cloudfront';
  1093. break;
  1094. case 'rscf':
  1095. $engine_name = 'rackspace cloud files';
  1096. break;
  1097. case 'azure':
  1098. $engine_name = 'microsoft azure storage';
  1099. break;
  1100. case 'mirror':
  1101. $engine_name = 'mirror';
  1102. break;
  1103. case 'netdna':
  1104. $engine_name = 'netdna';
  1105. break;
  1106. case 'maxcdn':
  1107. $engine_name = 'maxcdn';
  1108. break;
  1109. case 'cotendo':
  1110. $engine_name = 'cotendo';
  1111. break;
  1112. case 'akamai':
  1113. $engine_name = 'akamai';
  1114. break;
  1115. case 'edgecast':
  1116. $engine_name = 'media template procdn / edgecast';
  1117. break;
  1118. case 'att':
  1119. $engine_name = 'at&amp;t';
  1120. break;
  1121. default:
  1122. $engine_name = 'n/a';
  1123. break;
  1124. }
  1125. return $engine_name;
  1126. }
  1127. /**
  1128. * Converts value to boolean
  1129. *
  1130. * @param mixed $value
  1131. * @return boolean
  1132. */
  1133. function w3_to_boolean($value) {
  1134. if (is_string($value)) {
  1135. switch (strtolower($value)) {
  1136. case '+':
  1137. case '1':
  1138. case 'y':
  1139. case 'on':
  1140. case 'yes':
  1141. case 'true':
  1142. case 'enabled':
  1143. return true;
  1144. case '-':
  1145. case '0':
  1146. case 'n':
  1147. case 'no':
  1148. case 'off':
  1149. case 'false':
  1150. case 'disabled':
  1151. return false;
  1152. }
  1153. }
  1154. return (boolean) $value;
  1155. }
  1156. /**
  1157. * Quotes regular expression string
  1158. *
  1159. * @param string $string
  1160. * @param string $delimiter
  1161. * @return string
  1162. */
  1163. function w3_preg_quote($string, $delimiter = null) {
  1164. $string = preg_quote($string, $delimiter);
  1165. $string = strtr($string, array(
  1166. ' ' => '\ '
  1167. ));
  1168. return $string;
  1169. }
  1170. /**
  1171. * Returns true if zlib output compression is enabled otherwise false
  1172. *
  1173. * @return boolean
  1174. */
  1175. function w3_zlib_output_compression() {
  1176. return w3_to_boolean(ini_get('zlib.output_compression'));
  1177. }
  1178. /**
  1179. * Recursive strips slahes from the var
  1180. *
  1181. * @param mixed $var
  1182. * @return mixed
  1183. */
  1184. function w3_stripslashes($var) {
  1185. if (is_string($var)) {
  1186. return stripslashes($var);
  1187. } elseif (is_array($var)) {
  1188. $var = array_map('w3_stripslashes', $var);
  1189. }
  1190. return $var;
  1191. }
  1192. /**
  1193. * Escapes HTML comment
  1194. *
  1195. * @param string $comment
  1196. * @return mixed
  1197. */
  1198. function w3_escape_comment($comment) {
  1199. while (strstr($comment, '--') !== false) {
  1200. $comment = str_replace('--', '- -', $comment);
  1201. }
  1202. return $comment;
  1203. }
  1204. /**
  1205. * Returns instance of singleton class
  1206. *
  1207. * @param string $class
  1208. * @return object
  1209. */
  1210. function w3_instance($class) {
  1211. static $instances = array();
  1212. if (!isset($instances[$class])) {
  1213. w3_require_once( W3TC_LIB_W3_DIR . '/' .
  1214. str_replace('_', '/', substr($class, 3)) . '.php');
  1215. $instances[$class] = new $class();
  1216. }
  1217. $v = $instances[$class]; // Don't return reference
  1218. return $v;
  1219. }
  1220. /**
  1221. * Requires and keeps track of which files has already been loaded.
  1222. *
  1223. * @param string $path Absolute path to the file
  1224. */
  1225. function w3_require_once($path) {
  1226. static $files = array();
  1227. if (!isset($files[$path])) {
  1228. $files[$path] = 1;
  1229. require_once $path;
  1230. }
  1231. }
  1232. /**
  1233. * Detects post ID
  1234. *
  1235. * @return integer
  1236. */
  1237. function w3_detect_post_id() {
  1238. global $posts, $comment_post_ID, $post_ID;
  1239. if ($post_ID) {
  1240. return $post_ID;
  1241. } elseif ($comment_post_ID) {
  1242. return $comment_post_ID;
  1243. } elseif (is_single() || is_page() && count($posts)) {
  1244. return $posts[0]->ID;
  1245. } elseif (isset($_REQUEST['p'])) {
  1246. return (integer) $_REQUEST['p'];
  1247. }
  1248. return 0;
  1249. }
  1250. function w3_get_instance_id() {
  1251. static $instance_id;
  1252. if(!isset($instance_id)) {
  1253. $config = w3_instance('W3_Config');
  1254. $instance_id = $config->get_integer('common.instance_id', 0);
  1255. }
  1256. return $instance_id;
  1257. }
  1258. /**
  1259. * Checks if post should be flushed or not. Returns true if it should not be flushed
  1260. * @param $post
  1261. * @param string $module which cache module to check against (pgcache, varnish, cdncache, dbcache or objectcache)
  1262. * @param W3_Config $config
  1263. * @return bool
  1264. */
  1265. function w3_is_flushable_post($post, $module, $config) {
  1266. if (is_numeric($post))
  1267. $post = get_post($post);
  1268. $post_status = array('publish');
  1269. // dont flush when we have post "attachment"
  1270. // its child of the post and is flushed always when post is published, while not changed in fact
  1271. $post_type = array('revision', 'attachment');
  1272. switch($module) {
  1273. case 'pgcache':
  1274. case 'varnish':
  1275. case 'cdncache':
  1276. if (!$config->get_boolean('pgcache.reject.logged'))
  1277. $post_status[] = 'private';
  1278. break;
  1279. case 'dbcache':
  1280. if (!$config->get_boolean('dbcache.reject.logged'))
  1281. $post_status[] = 'private';
  1282. break;
  1283. }
  1284. $flushable = !in_array($post->post_type, $post_type) && in_array($post->post_status, $post_status);
  1285. return apply_filters('w3tc_flushable_post', $flushable, $post, $module);
  1286. }
  1287. /**
  1288. * Takes seconds and converts to array('Nh ','Nm ', 'Ns ', 'Nms ') or "Nh Nm Ns Nms"
  1289. * @param $input
  1290. * @param bool $string
  1291. * @return array|string
  1292. */
  1293. function w3_convert_secs_to_time($input, $string = true) {
  1294. $input = (double)$input;
  1295. $time = array();
  1296. $msecs = floor($input*1000 % 1000);
  1297. $seconds = $input % 60;
  1298. $input = floor($input / 60);
  1299. $minutes = $input % 60;
  1300. $input = floor($input / 60);
  1301. $hours = $input % 60;
  1302. $input = floor($input / 60);
  1303. if ($hours)
  1304. $time[] = sprintf(__('%dh', 'w3-total-cache'), $hours);
  1305. if ($minutes)
  1306. $time[] = sprintf(__('%dm', 'w3-total-cache'), $minutes);
  1307. if ($seconds)
  1308. $time[] = sprintf(__('%ds', 'w3-total-cache'), $seconds);
  1309. if ($msecs)
  1310. $time[] = sprintf(__('%dms', 'w3-total-cache'), $msecs);
  1311. if(empty($time))
  1312. $time[] = sprintf(__('%dms', 'w3-total-cache'), 0);
  1313. if ($string)
  1314. return implode(' ', $time);
  1315. return $time;
  1316. }
  1317. /**
  1318. * @return string
  1319. */
  1320. function w3_w3tc_release_version($config = null) {
  1321. if (w3_is_enterprise($config))
  1322. return 'enterprise';
  1323. if (w3_is_pro($config))
  1324. return 'pro';
  1325. return 'community';
  1326. }
  1327. /**
  1328. * @param W3_Config $config
  1329. * @return bool
  1330. */
  1331. function w3_is_pro($config = null) {
  1332. $result = false;
  1333. if ($config)
  1334. $result = $config->get_string('plugin.type') == 'pro';
  1335. return $result || defined('W3TC_PRO') && W3TC_PRO;
  1336. }
  1337. /**
  1338. * @param W3_Config $config
  1339. * @return bool
  1340. */
  1341. function w3_is_enterprise($config = null) {
  1342. $result = false;
  1343. if ($config)
  1344. $result = $config->get_string('plugin.type') == 'enterprise';
  1345. return $result || defined('W3TC_ENTERPRISE') && W3TC_ENTERPRISE;
  1346. }