/** * 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 unknown $module * @param null $blog_id * @return string */ public static function log_filename($module, $blog_id = null) { if (is_null($blog_id)) { $blog_id = Util_Environment::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 = Util_Environment::cache_dir('log'); } $filename = $dir_path . '/' . $postfix . '/' . $module . '.log'; if (!is_dir(dirname($filename))) { Util_File::mkdir_from(dirname($filename), $from_dir); } return $filename; }
/** * Constructor * * @param array $config */ function __construct($config = array()) { parent::__construct($config); if (isset($config['cache_dir'])) { $this->_cache_dir = trim($config['cache_dir']); } else { $this->_cache_dir = Util_Environment::cache_blog_dir($config['section'], $config['blog_id']); } $this->_exclude = isset($config['exclude']) ? (array) $config['exclude'] : array(); $this->_flush_timelimit = isset($config['flush_timelimit']) ? (int) $config['flush_timelimit'] : 180; $this->_locking = isset($config['locking']) ? (bool) $config['locking'] : false; if (isset($config['flush_dir'])) { $this->_flush_dir = $config['flush_dir']; } else { if ($config['blog_id'] <= 0 && !isset($config['cache_dir'])) { // clear whole section if we operate on master cache // and in a mode when cache_dir not strictly specified $this->_flush_dir = Util_Environment::cache_dir($config['section']); } else { $this->_flush_dir = $this->_cache_dir; } } if (isset($config['use_wp_hash']) && $config['use_wp_hash']) { $this->_use_wp_hash = true; } }
/** * Returns path to blog's cache dir * * @param string $section * @param null|int $blog_id * @return string */ public static function cache_blog_dir($section, $blog_id = null) { if (!Util_Environment::is_wpmu()) { $postfix = ''; } else { if (is_null($blog_id)) { $blog_id = Util_Environment::blog_id(); } $postfix = DIRECTORY_SEPARATOR . sprintf('%d', $blog_id); if (defined('W3TC_BLOG_LEVELS')) { for ($n = 0; $n < W3TC_BLOG_LEVELS; $n++) { $postfix = DIRECTORY_SEPARATOR . substr($postfix, strlen($postfix) - 1 - $n, 1) . $postfix; } } } return Util_Environment::cache_dir($section) . $postfix; }
/** * Usage statistics uses one of other module's cache * to store its temporary data */ public static function get_usage_statistics_cache() { static $cache = null; if (is_null($cache)) { $c = Dispatcher::config(); if ($c->get_boolean('objectcache.enabled')) { $provider = Dispatcher::component('ObjectCache_WpObjectCache_Regular'); } else { if ($c->get_boolean('dbcache.enabled')) { $provider = Dispatcher::component('DbCache_Core'); } else { if ($c->get_boolean('pgcache.enabled')) { $provider = Dispatcher::component('PgCache_ContentGrabber'); } else { if ($c->get_boolean('minify.enabled')) { $provider = Dispatcher::component('Minify_Core'); } else { return null; } } } } $engineConfig = $provider->get_usage_statistics_cache_config(); $engineConfig['module'] = 'stats'; $engineConfig['blog_id'] = 0; // count wpmu-wide stats if ($engineConfig['engine'] == 'file') { $engineConfig['cache_dir'] = Util_Environment::cache_dir('stats'); } $cache = Cache::instance($engineConfig['engine'], $engineConfig); } return $cache; }