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c#B$VE#Jƌ-n\ZHt8UI< c(6i > ؁];OI9ř4^LI* ','TѶ7EBA$6q} 6Hi4@- n˩|st/Z=3;Ϭl;N 63s~ *_lҰ$!Ym!gTɻ/,/gDn.uAiod>{bp׸r^Qy[\i@cfOEgC-V<[:C_\κX>!@mAw:)rbA+))bEP @P4332HA@`"X `0H?^f0"   x￷_t$-KF$9Jp0JHR-MRJRAUI(2(""%?)TJjJR(WETPD%@Pj҄iH4ɖDs,IQeJ!% lwtځ#,YD2֚5Fl#6¬df=TF"dBTbA+UA Tk Tֈ-UZȒAPrբthU "j%H& Z2H4nLMiHZUF2TŧH54bRfwUfº`tC1]4wL[u5kb+6Č* ]]w f.*]6dScч]ӓ5n|ѠU @ԻCWuwufKJ4uHnqdqeR'VZ]IԝɖU DAMAF֔d%v) vYjS費ZRfƩX*WZNۭ@jI֬B\ZH5"TVZ\R,* *P\,$FT# *TZs4@hZ*G4Z Jh"TC "Ԉ% )r 1jrrU9jj4f UHu W:v;IJ2.;jHR9i][AJUe\J)SJµɤhUXIeiwuUE5nXYV+Y*]YiSvMf cER(Ԁ\4 5Q %+-iiK4v.+QZQ0+ ("0^@"T[5Z SET %EUJRjGRH ;JR\ݨj-1&MZIXrգMHG1nR% %AjT'5(.Z:Jm݂ #MKQh֥Qk2+옵ZVC% i84"TR9TҪ-*)Ġҕ4d%(☝@LL]AwSdM+P0a]G*E*u*h% J+4 Pc Z-2ܤZw8-Hʹ%-W6BS.բBkTZ!@&j) { $base_path = w3_get_base_path(); foreach ($blogs as $blog) { $blogname = trim(str_replace($base_path, '', $blog->path), '/'); if ($blogname) { $blognames[] = $blogname; } } } return $blognames; } /** * Returns current blog ID * * @return integer */ function w3_get_blog_id() { global $w3_current_blog_id; if (!is_null($w3_current_blog_id)) return $w3_current_blog_id; if (!w3_is_network() || is_network_admin()) { $w3_current_blog_id = 0; return $w3_current_blog_id; } $blog_data = w3_blogmap_get_blog_data(); if (!is_null($blog_data)) $w3_current_blog_id = substr($blog_data, 1); else $w3_current_blog_id = 0; return $w3_current_blog_id; } /** * Returns blogmap filename by home url * * @param string $blog_home_url * @return string */ function w3_blogmap_filename($blog_home_url) { if (!defined('W3TC_BLOG_LEVELS')) return W3TC_CACHE_BLOGMAP_FILENAME; else { $filename = dirname(W3TC_CACHE_BLOGMAP_FILENAME) . '/' . basename(W3TC_CACHE_BLOGMAP_FILENAME, '.php') . '/'; $s = md5($blog_home_url); for ($n = 0; $n < W3TC_BLOG_LEVELS; $n++) $filename .= substr($s, $n, 1) . '/'; return $filename . basename(W3TC_CACHE_BLOGMAP_FILENAME); } } /** * Returns blog_id by home url * If database not initialized yet - returns 0 * * @return integer */ function w3_blogmap_get_blog_data() { $host = w3_get_host(); // subdomain if (w3_is_subdomain_install()) { $blog_data = w3_blogmap_try_get_blog_data($host); if (is_null($blog_data)) $GLOBALS['w3tc_blogmap_register_new_item'] = $host; return $blog_data; } else { // try subdir blog $url = $host . $_SERVER['REQUEST_URI']; $pos = strpos($url, '?'); if ($pos !== false) $url = substr($url, 0, $pos); $url = rtrim($url, '/'); $start_url = $url; for (;;) { $blog_data = w3_blogmap_try_get_blog_data($url); if (!is_null($blog_data)) return $blog_data; $pos = strrpos($url, '/'); if ($pos === false) break; $url = rtrim(substr($url, 0, $pos), '/'); } $GLOBALS['w3tc_blogmap_register_new_item'] = $start_url; return null; } } function w3_blogmap_try_get_blog_data($url) { $filename = w3_blogmap_filename($url); if (file_exists($filename)) { $data = file_get_contents($filename); $blog_data = @eval($data); if (is_array($blog_data) && isset($blog_data[$url])) return $blog_data[$url]; } return null; } /** * @return bool */ function w3_force_master() { global $w3_force_master; if (!is_null($w3_force_master)) return $w3_force_master; if (!w3_is_multisite()) $w3_force_master = false; else { $blog_data = w3_blogmap_get_blog_data(); if (is_null($blog_data) || ($blog_data[0] != 'm' && $blog_data[0] != 'c')) $w3_force_master = true; else $w3_force_master = ($blog_data[0] == 'm'); } return $w3_force_master; } /** * Returns path to section's cache dir * * @param string $section * @return string */ function w3_cache_dir($section) { return W3TC_CACHE_DIR . '/' . $section; } /** * Returns path to blog's cache dir * * @param string $section * @param null|int $blog_id * @return string */ function w3_cache_blog_dir($section, $blog_id = null) { if (is_null($blog_id)) $blog_id = w3_get_blog_id(); $postfix = sprintf('%06d', $blog_id); if (defined('W3TC_BLOG_LEVELS')) { for ($n = 0; $n < W3TC_BLOG_LEVELS; $n++) $postfix = substr($postfix, strlen($postfix) - 1 - $n, 1) . '/' . $postfix; } return w3_cache_dir($section) . '/' . $postfix; } /** * Return full path to log file for module * Path used in priority * 1) W3TC_DEBUG_DIR * 2) WP_DEBUG_LOG * 3) W3TC_CACHE_DIR * * @param $module * @param null $blog_id * @return string */ function w3_debug_log($module, $blog_id = null) { if (is_null($blog_id)) $blog_id = w3_get_blog_id(); $postfix = sprintf('%06d', $blog_id); if (defined('W3TC_BLOG_LEVELS')) { for ($n = 0; $n < W3TC_BLOG_LEVELS; $n++) $postfix = substr($postfix, strlen($postfix) - 1 - $n, 1) . '/' . $postfix; } $from_dir = W3TC_CACHE_DIR; if (defined('W3TC_DEBUG_DIR') && W3TC_DEBUG_DIR) { $dir_path = W3TC_DEBUG_DIR; if (!is_dir(W3TC_DEBUG_DIR)) $from_dir = dirname(W3TC_DEBUG_DIR); } else $dir_path = w3_cache_dir('log'); $filename = $dir_path . '/' . $postfix . '/' . $module . '.log'; if (!is_dir(dirname($filename))) { w3_require_once( W3TC_INC_DIR . '/functions/file.php'); w3_mkdir_from(dirname($filename), $from_dir); } return $filename; } /** * Returns URL regexp from URL * * @param string $url * @return string */ function w3_get_url_regexp($url) { $url = preg_replace('~(https?:)?//~i', '', $url); $url = preg_replace('~^www\.~i', '', $url); $regexp = '(https?:)?//(www\.)?' . w3_preg_quote($url); return $regexp; } /** * Returns SSL URL if current connection is https * @param string $url * @return string */ function w3_get_url_ssl($url) { if (w3_is_https()) { $url = str_replace('http://', 'https://', $url); } return $url; } /** * Get domain URL * * @return string */ function w3_get_domain_url() { $home_url = w3_get_home_url(); $parse_url = @parse_url($home_url); if ($parse_url && isset($parse_url['scheme']) && isset($parse_url['host'])) { $scheme = $parse_url['scheme']; $host = $parse_url['host']; $port = (isset($parse_url['port']) && $parse_url['port'] != 80 ? ':' . (int) $parse_url['port'] : ''); $domain_url = sprintf('%s://%s%s', $scheme, $host, $port); return $domain_url; } return false; } /** * Returns domain url regexp * * @return string */ function w3_get_domain_url_regexp() { $domain_url = w3_get_domain_url(); $regexp = w3_get_url_regexp($domain_url); return $regexp; } /** * Returns home URL * * No trailing slash! * * @return string */ function w3_get_home_url() { static $home_url = null; if ($home_url === null) { $config = w3_instance('W3_Config'); if (w3_is_multisite() && $config->get_boolean('common.force_master')) { $home_url = get_home_url(); } else { // get_option is unusable here, it can cause problem when objCache isn't yet initialized // Which is why we save the 'home' option in our ConfigCache // We don't just use $config->get_string, because we want the cache to rebuild // when 'wordpress.home' is not (yet) present $home_url = $config->get_cache_option('wordpress.home'); $home_url = rtrim($home_url, '/'); } } return $home_url; } /** * Returns SSL home url * * @return string */ function w3_get_home_url_ssl() { $home_url = w3_get_home_url(); $ssl = w3_get_url_ssl($home_url); return $ssl; } /** * Returns home url regexp * * @return string */ function w3_get_home_url_regexp() { $home_url = w3_get_home_url(); $regexp = w3_get_url_regexp($home_url); return $regexp; } /** * Network installs returns wrong wp site path * @return string */ function w3_get_wp_sitepath() { if (w3_is_network()) { global $current_site; return $current_site->path; } else { return w3_get_site_path(); } } /** * Returns site URL * * No trailing slash! * * @return string */ function w3_get_site_url() { static $site_url = null; if ($site_url === null) { $site_url = get_option('siteurl'); $site_url = rtrim($site_url, '/'); } return $site_url; } /** * Returns SSL site URL * * @return string */ function w3_get_site_url_ssl() { $site_url = w3_get_site_url(); $ssl = w3_get_url_ssl($site_url); return $ssl; } /** * Returns absolute path to document root * * No trailing slash! * * @return string */ function w3_get_document_root() { static $document_root = null; if ($document_root === null) { if (!empty($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == $_SERVER['PHP_SELF']) { $document_root = w3_get_site_root(); } elseif (!empty($_SERVER['SCRIPT_FILENAME'])) { $document_root = substr(w3_path($_SERVER['SCRIPT_FILENAME']), 0, -strlen(w3_path($_SERVER['PHP_SELF']))); } elseif (!empty($_SERVER['PATH_TRANSLATED'])) { $document_root = substr(w3_path($_SERVER['PATH_TRANSLATED']), 0, -strlen(w3_path($_SERVER['PHP_SELF']))); } elseif (!empty($_SERVER['DOCUMENT_ROOT'])) { $document_root = w3_path($_SERVER['DOCUMENT_ROOT']); } else { $document_root = w3_get_site_root(); } $document_root = realpath($document_root); $document_root = w3_path($document_root); } return $document_root; } /** * Returns absolute path to home directory * * Example: * * DOCUMENT_ROOT=/var/www/vhosts/domain.com * Install dir=/var/www/vhosts/domain.com/site/blog * home=http://domain.com/site * siteurl=http://domain.com/site/blog * return /var/www/vhosts/domain.com/site * * No trailing slash! * * @return string */ function w3_get_home_root() { if (w3_is_network()) { $path = w3_get_base_path(); } else { $path = w3_get_home_path(); } $home_root = w3_get_document_root() . $path; $home_root = realpath($home_root); $home_root = w3_path($home_root); return $home_root; } /** * Returns absolute path to blog install dir * * Example: * * DOCUMENT_ROOT=/var/www/vhosts/domain.com * install dir=/var/www/vhosts/domain.com/site/blog * return /var/www/vhosts/domain.com/site/blog * * No trailing slash! * * @return string */ function w3_get_site_root() { $site_root = ABSPATH; $site_root = realpath($site_root); $site_root = w3_path($site_root); return $site_root; } /** * Returns blog path * * Example: * * siteurl=http://domain.com/site/blog * return /site/blog/ * * With trailing slash! * * @return string */ function w3_get_site_path() { $site_url = w3_get_site_url(); $parse_url = @parse_url($site_url); if ($parse_url && isset($parse_url['path'])) { $site_path = '/' . ltrim($parse_url['path'], '/'); } else { $site_path = '/'; } if (substr($site_path, -1) != '/') { $site_path .= '/'; } return $site_path; } /** * Returns home domain * * @return string */ function w3_get_home_domain() { $home_url = w3_get_home_url(); $parse_url = @parse_url($home_url); if ($parse_url && isset($parse_url['host'])) { return $parse_url['host']; } return w3_get_host(); } /** * Returns home path * * Example: * * home=http://domain.com/site/ * siteurl=http://domain.com/site/blog * return /site/ * * With trailing slash! * * @return string */ function w3_get_home_path() { $home_url = w3_get_home_url(); $parse_url = @parse_url($home_url); if ($parse_url && isset($parse_url['path'])) { $home_path = '/' . ltrim($parse_url['path'], '/'); } else { $home_path = '/'; } if (substr($home_path, -1) != '/') { $home_path .= '/'; } return $home_path; } /** * Returns path to WP directory relative to document root * * Example: * * DOCUMENT_ROOT=/var/www/vhosts/domain.com/ * Install dir=/var/www/vhosts/domain.com/site/blog/ * return /site/blog/ * * With trailing slash! * * @return string */ function w3_get_base_path() { $document_root = w3_get_document_root(); $site_root = w3_get_site_root(); $base_path = str_replace($document_root, '', $site_root); $base_path = '/' . ltrim($base_path, '/'); if (substr($base_path, -1) != '/') { $base_path .= '/'; } return $base_path; } /** * Returns server hostname * * @return string */ function w3_get_host() { static $host = null; if ($host === null) { if (!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) { $host = $_SERVER['HTTP_X_FORWARDED_HOST']; } elseif (!empty($_SERVER['HTTP_HOST'])) { // HTTP_HOST sometimes is not set causing warning $host = $_SERVER['HTTP_HOST']; } else { $host = ''; } } return $host; } /** * Returns host ID * * @return string */ function w3_get_host_id() { static $host_id = null; if ($host_id === null) { $host = w3_get_host(); $blog_id = w3_get_blog_id(); $host_id = sprintf('%s_%d', $host, $blog_id); } return $host_id; } /** * Returns WP config file path * * @return string */ function w3_get_wp_config_path() { $search = array( ABSPATH . 'wp-config.php', dirname(ABSPATH) . '/wp-config.php' ); foreach ($search as $path) { if (file_exists($path)) { return $path; } } return false; } /** * Returns theme key * * @param string $theme_root * @param string $template * @param string $stylesheet * @return string */ function w3_get_theme_key($theme_root, $template, $stylesheet) { $site_root = w3_get_site_root(); $theme_path = ltrim(str_replace($site_root, '', w3_path($theme_root)), '/'); return substr(md5($theme_path . $template . $stylesheet), 0, 5); } /** * Returns theme key (legacy support) * * @param string $theme_root * @param string $template * @param string $stylesheet * @return string */ function w3_get_theme_key_legacy($theme_root, $template, $stylesheet) { return substr(md5($theme_root . $template . $stylesheet), 0, 6); } /** * Returns true if we can check rules * * @return bool */ function w3_can_check_rules() { return (w3_is_apache() || w3_is_litespeed() || w3_is_nginx()); } /** * Returns true if CDN engine is supporting purge * * @param string $engine * @return bool */ function w3_can_cdn_purge($engine) { return in_array($engine, array('ftp', 's3', 'cf', 'cf2', 'rscf', 'azure', 'netdna', 'maxcdn', 'cotendo', 'edgecast', 'akamai', 'att')); } /** * Returns true if CDN supports realtime purge. That is purging on post changes, comments etc. * @param $engine * @return bool */ function w3tc_cdn_supports_realtime_purge($engine) { return !in_array($engine, array('cf2')); } /** * Parses path * * @param string $path * @return mixed */ function w3_parse_path($path) { $path = str_replace(array( '%BLOG_ID%', '%POST_ID%', '%BLOG_ID%', '%HOST%', '%DOMAIN%', '%BASE_PATH%' ), array( (isset($GLOBALS['blog_id']) ? (int) $GLOBALS['blog_id'] : 0), (isset($GLOBALS['post_id']) ? (int) $GLOBALS['post_id'] : 0), w3_get_blog_id(), w3_get_host(), w3_get_domain(w3_get_host()), trim(w3_get_base_path(), '/') ), $path); return $path; } /** * Normalizes file name * * Relative to site root! * * @param string $file * @return string */ function w3_normalize_file($file) { if (w3_is_url($file)) { if (strstr($file, '?') === false) { $home_url_regexp = '~' . w3_get_home_url_regexp() . '~i'; $file = preg_replace($home_url_regexp, '', $file); } } if (!w3_is_url($file)) { $file = w3_path($file); $file = str_replace(w3_get_site_root(), '', $file); $file = ltrim($file, '/'); } return $file; } /** * Normalizes file name for minify * * Relative to document root! * * @param string $file * @return string */ function w3_normalize_file_minify($file) { if (w3_is_url($file)) { if (strstr($file, '?') === false) { $domain_url_regexp = '~' . w3_get_domain_url_regexp() . '~i'; $file = preg_replace($domain_url_regexp, '', $file); } } if (!w3_is_url($file)) { $file = w3_path($file); $file = str_replace(w3_get_document_root(), '', $file); $file = ltrim($file, '/'); } return $file; } /** * Normalizes file name for minify * * Relative to document root! * * @param string $file * @return string */ function w3_normalize_file_minify2($file) { $file = w3_remove_query($file); $file = w3_normalize_file_minify($file); $file = w3_translate_file($file); return $file; } /** * Translates remote file to local file * * @param string $file * @return string */ function w3_translate_file($file) { if (!w3_is_url($file)) { $file = '/' . ltrim($file, '/'); $regexp = '~^' . w3_preg_quote(w3_get_site_path()) . '~'; $file = preg_replace($regexp, w3_get_base_path(), $file); $file = ltrim($file, '/'); } return $file; } /** * Remove WP query string from URL * * @param string $url * @return string */ function w3_remove_query($url) { $url = preg_replace('~[&\?]+(ver=([a-z0-9-_\.]+|[0-9-]+))~i', '', $url); return $url; } /** * Converts win path to unix * * @param string $path * @return string */ function w3_path($path) { $path = preg_replace('~[/\\\]+~', '/', $path); $path = rtrim($path, '/'); return $path; } /** * Returns real path of given path * * @param string $path * @return string */ function w3_realpath($path) { $path = w3_path($path); $parts = explode('/', $path); $absolutes = array(); foreach ($parts as $part) { if ('.' == $part) { continue; } if ('..' == $part) { array_pop($absolutes); } else { $absolutes[] = $part; } } return implode('/', $absolutes); } /** * Returns GMT date * @param integer $time * @return string */ function w3_http_date($time) { return gmdate('D, d M Y H:i:s \G\M\T', $time); } /** * Redirects to URL * * @param string $url * @param array $params * @return string */ function w3_redirect($url = '', $params = array()) { w3_require_once(W3TC_INC_DIR . '/functions/url.php'); $url = w3_url_format($url, $params); if (function_exists('do_action')) do_action('w3_redirect'); @header('Location: ' . $url); exit(); } /** * Redirects to URL * * @param string $url * @param array $params * * @return string */ function w3_redirect_temp( $url = '', $params = array() ) { w3_require_once( W3TC_INC_DIR . '/functions/url.php' ); $url = w3_url_format( $url, $params ); if (function_exists('do_action')) do_action( 'w3_redirect' ); $status_code = 301; $protocol = $_SERVER["SERVER_PROTOCOL"]; if ( 'HTTP/1.1' === $protocol ) { $status_code = 307; } $text = get_status_header_desc( $status_code ); if ( !empty( $text ) ) { $status_header = "$protocol $status_code $text"; @header( $status_header, true, $status_code ); } @header( 'Location: ' . $url, true, $status_code ); exit(); } /** * Returns caching engine name * * @param $engine * @param $module * * @return string */ function w3_get_engine_name($engine, $module = '') { switch ($engine) { case 'memcached': $engine_name = 'memcached'; break; case 'apc': $engine_name = 'apc'; break; case 'eaccelerator': $engine_name = 'eaccelerator'; break; case 'xcache': $engine_name = 'xcache'; break; case 'wincache': $engine_name = 'wincache'; break; case 'file': if ($module == 'pgcache') $engine_name = 'disk: basic'; else $engine_name = 'disk'; break; case 'file_generic': $engine_name = 'disk: enhanced'; break; case 'ftp': $engine_name = 'self-hosted / file transfer protocol upload'; break; case 's3': $engine_name = 'amazon simple storage service (s3)'; break; case 'cf': $engine_name = 'amazon cloudfront'; break; case 'cf2': $engine_name = 'amazon cloudfront'; break; case 'rscf': $engine_name = 'rackspace cloud files'; break; case 'azure': $engine_name = 'microsoft azure storage'; break; case 'mirror': $engine_name = 'mirror'; break; case 'netdna': $engine_name = 'netdna'; break; case 'maxcdn': $engine_name = 'maxcdn'; break; case 'cotendo': $engine_name = 'cotendo'; break; case 'akamai': $engine_name = 'akamai'; break; case 'edgecast': $engine_name = 'media template procdn / edgecast'; break; case 'att': $engine_name = 'at&t'; break; default: $engine_name = 'n/a'; break; } return $engine_name; } /** * Converts value to boolean * * @param mixed $value * @return boolean */ function w3_to_boolean($value) { if (is_string($value)) { switch (strtolower($value)) { case '+': case '1': case 'y': case 'on': case 'yes': case 'true': case 'enabled': return true; case '-': case '0': case 'n': case 'no': case 'off': case 'false': case 'disabled': return false; } } return (boolean) $value; } /** * Quotes regular expression string * * @param string $string * @param string $delimiter * @return string */ function w3_preg_quote($string, $delimiter = null) { $string = preg_quote($string, $delimiter); $string = strtr($string, array( ' ' => '\ ' )); return $string; } /** * Returns true if zlib output compression is enabled otherwise false * * @return boolean */ function w3_zlib_output_compression() { return w3_to_boolean(ini_get('zlib.output_compression')); } /** * Recursive strips slahes from the var * * @param mixed $var * @return mixed */ function w3_stripslashes($var) { if (is_string($var)) { return stripslashes($var); } elseif (is_array($var)) { $var = array_map('w3_stripslashes', $var); } return $var; } /** * Escapes HTML comment * * @param string $comment * @return mixed */ function w3_escape_comment($comment) { while (strstr($comment, '--') !== false) { $comment = str_replace('--', '- -', $comment); } return $comment; } /** * Returns instance of singleton class * * @param string $class * @return object */ function w3_instance($class) { static $instances = array(); if (!isset($instances[$class])) { w3_require_once( W3TC_LIB_W3_DIR . '/' . str_replace('_', '/', substr($class, 3)) . '.php'); $instances[$class] = new $class(); } $v = $instances[$class]; // Don't return reference return $v; } /** * Requires and keeps track of which files has already been loaded. * * @param string $path Absolute path to the file */ function w3_require_once($path) { static $files = array(); if (!isset($files[$path])) { $files[$path] = 1; require_once $path; } } /** * Detects post ID * * @return integer */ function w3_detect_post_id() { global $posts, $comment_post_ID, $post_ID; if ($post_ID) { return $post_ID; } elseif ($comment_post_ID) { return $comment_post_ID; } elseif (is_single() || is_page() && count($posts)) { return $posts[0]->ID; } elseif (isset($_REQUEST['p'])) { return (integer) $_REQUEST['p']; } return 0; } function w3_get_instance_id() { static $instance_id; if(!isset($instance_id)) { $config = w3_instance('W3_Config'); $instance_id = $config->get_integer('common.instance_id', 0); } return $instance_id; } /** * Checks if post should be flushed or not. Returns true if it should not be flushed * @param $post * @param string $module which cache module to check against (pgcache, varnish, cdncache, dbcache or objectcache) * @param W3_Config $config * @return bool */ function w3_is_flushable_post($post, $module, $config) { if (is_numeric($post)) $post = get_post($post); $post_status = array('publish'); // dont flush when we have post "attachment" // its child of the post and is flushed always when post is published, while not changed in fact $post_type = array('revision', 'attachment'); switch($module) { case 'pgcache': case 'varnish': case 'cdncache': if (!$config->get_boolean('pgcache.reject.logged')) $post_status[] = 'private'; break; case 'dbcache': if (!$config->get_boolean('dbcache.reject.logged')) $post_status[] = 'private'; break; } $flushable = !in_array($post->post_type, $post_type) && in_array($post->post_status, $post_status); return apply_filters('w3tc_flushable_post', $flushable, $post, $module); } /** * Takes seconds and converts to array('Nh ','Nm ', 'Ns ', 'Nms ') or "Nh Nm Ns Nms" * @param $input * @param bool $string * @return array|string */ function w3_convert_secs_to_time($input, $string = true) { $input = (double)$input; $time = array(); $msecs = floor($input*1000 % 1000); $seconds = $input % 60; $input = floor($input / 60); $minutes = $input % 60; $input = floor($input / 60); $hours = $input % 60; if ($hours) $time[] = sprintf(__('%dh', 'w3-total-cache'), $hours); if ($minutes) $time[] = sprintf(__('%dm', 'w3-total-cache'), $minutes); if ($seconds) $time[] = sprintf(__('%ds', 'w3-total-cache'), $seconds); if ($msecs) $time[] = sprintf(__('%dms', 'w3-total-cache'), $msecs); if(empty($time)) $time[] = sprintf(__('%dms', 'w3-total-cache'), 0); if ($string) return implode(' ', $time); return $time; } /** * @var W3_Config $config * @return string */ function w3_w3tc_release_version($config = null) { if (w3_is_enterprise($config)) return 'enterprise'; if (w3_is_pro($config) && w3tc_is_pro_dev_mode()) return 'pro development'; if (w3_is_pro($config)) return 'pro'; return 'community'; } /** * @param W3_Config $config * @return bool */ function w3_is_pro($config = null) { $result = false; if ($config) $result = $config->get_string('plugin.type') == 'pro' || ($config->get_string('plugin.type') == 'pro_dev' ); return $result || (defined('W3TC_PRO') && W3TC_PRO); } /** * Enable Pro Dev mode support * @return bool */ function w3tc_is_pro_dev_mode() { return defined('W3TC_PRO_DEV_MODE') && W3TC_PRO_DEV_MODE; } /** * @param W3_Config $config * @return bool */ function w3_is_enterprise($config = null) { $result = false; if ($config) $result = $config->get_string('plugin.type') == 'enterprise'; return $result || (defined('W3TC_ENTERPRISE') && W3TC_ENTERPRISE); } /** * Checks if site is using edge mode. * @return bool */ function w3tc_edge_mode() { return defined('W3TC_EDGE_MODE') && W3TC_EDGE_MODE; }