diff --git a/quick-cache/includes/share.php b/quick-cache/includes/share.php index acef477..60fb2cf 100644 --- a/quick-cache/includes/share.php +++ b/quick-cache/includes/share.php @@ -1026,23 +1026,26 @@ public function apply_filters($hook, $value) public $htaccess_deny = "\n\tRequire all denied\n\n\n\tdeny from all\n"; } - /** - * Polyfill for {@link \__()}. - * - * @since 140422 First documented version. - * - * @param string $string String to translate. - * @param string $text_domain Plugin text domain. - * - * @return string Possibly translated string. - */ - function __($string, $text_domain) + if(!function_exists('\\'.__NAMESPACE__.'\\__')) { - static $exists; // Static cache. - if(($exists || function_exists('__')) && ($exists = TRUE)) - return \__($string, $text_domain); + /** + * Polyfill for {@link \__()}. + * + * @since 140422 First documented version. + * + * @param string $string String to translate. + * @param string $text_domain Plugin text domain. + * + * @return string Possibly translated string. + */ + function __($string, $text_domain) + { + static $exists; // Static cache. + if(($exists || function_exists('__')) && ($exists = TRUE)) + return \__($string, $text_domain); - return $string; // Not possible (yet). + return $string; // Not possible (yet). + } } } } \ No newline at end of file diff --git a/quick-cache/quick-cache.inc.php b/quick-cache/quick-cache.inc.php index 9d7f2ef..b742d9e 100644 --- a/quick-cache/quick-cache.inc.php +++ b/quick-cache/quick-cache.inc.php @@ -732,11 +732,8 @@ public function clear_cache($manually = FALSE) { $counter = 0; // Initialize. - $cache_dir = $this->cache_dir(); // Current cache directory. - if(!is_dir($cache_dir)) return $counter; // Nothing to do. - - // @TODO When set_time_limit() is disabled by PHP configuration, display a warning message to users upon plugin activation - @set_time_limit(1800); // In case of HUGE sites w/ a very large directory. Errors are ignored in case `set_time_limit()` is disabled. + if(!is_dir($cache_dir = $this->cache_dir())) + return $counter; // Nothing to do. $url = 'http://'.$_SERVER['HTTP_HOST'].$this->host_base_dir_tokens(); $cache_path_no_scheme_quv_ext = $this->url_to_cache_path($url, '', '', $this::CACHE_PATH_NO_SCHEME | $this::CACHE_PATH_NO_PATH_INDEX | $this::CACHE_PATH_NO_QUV | $this::CACHE_PATH_NO_EXT); @@ -744,6 +741,9 @@ public function clear_cache($manually = FALSE) '\/[^\/]+\/'.preg_quote($cache_path_no_scheme_quv_ext, '/'). '(?:\/index)?[.\/]/'; + // @TODO When set_time_limit() is disabled by PHP configuration, display a warning message to users upon plugin activation + @set_time_limit(1800); // In case of HUGE sites w/ a very large directory. Errors are ignored in case `set_time_limit()` is disabled. + /** @var $_dir_file \RecursiveDirectoryIterator For IDEs. */ foreach($this->dir_regex_iteration($cache_dir, $regex) as $_dir_file) { @@ -776,9 +776,10 @@ public function purge_cache() { $counter = 0; // Initialize. - $cache_dir = $this->cache_dir(); // Current cache directory. - $max_age = strtotime('-'.$this->options['cache_max_age']); - if(!is_dir($cache_dir)) return $counter; // Nothing to do. + if(!is_dir($cache_dir = $this->cache_dir())) + return $counter; // Nothing to do. + + $max_age = strtotime('-'.$this->options['cache_max_age']); // @TODO When set_time_limit() is disabled by PHP configuration, display a warning message to users upon plugin activation @set_time_limit(1800); // In case of HUGE sites w/ a very large directory. Errors are ignored in case `set_time_limit()` is disabled. @@ -912,9 +913,13 @@ public function auto_purge_post_cache($id, $force = FALSE) if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $counter; // Nothing to do. - $post_status = get_post_status($id); // Cache this. + if(!is_dir($cache_dir = $this->cache_dir())) + return $counter; // Nothing to do. + + if(!($permalink = get_permalink($id))) + return $counter; // Nothing we can do. - if(!$post_status) + if(!($post_status = get_post_status($id))) return $counter; // Nothing to do. if($post_status === 'auto-draft') @@ -932,16 +937,6 @@ public function auto_purge_post_cache($id, $force = FALSE) if($post_status === 'trash' && !$force) return $counter; // Nothing to do. - $cache_dir = $this->cache_dir(); // Current cache directory. - if(!is_dir($cache_dir)) return $counter; // Nothing to do. - - $counter += $this->auto_purge_xml_sitemaps_cache(); // If enabled and necessary. - $counter += $this->auto_purge_home_page_cache(); // If enabled and necessary. - $counter += $this->auto_purge_posts_page_cache(); // If enabled & applicable. - $counter += $this->auto_purge_post_terms_cache($id, $force); // If enabled and applicable. - - if(!($permalink = get_permalink($id))) return $counter; // Nothing we can do. - if(($type = get_post_type($id)) && ($type = get_post_type_object($type)) && !empty($type->labels->singular_name)) $type_singular_name = $type->labels->singular_name; // Singular name for the post type. else $type_singular_name = __('Post', $this->text_domain); // Default value. @@ -971,6 +966,11 @@ public function auto_purge_post_cache($id, $force = FALSE) } unset($_file); // Just a little housekeeping. + $counter += $this->auto_purge_xml_sitemaps_cache(); // If enabled and necessary. + $counter += $this->auto_purge_home_page_cache(); // If enabled and necessary. + $counter += $this->auto_purge_posts_page_cache(); // If enabled and necessary. + $counter += $this->auto_purge_post_terms_cache($id, $force); // If enabled and necessary. + return apply_filters(__METHOD__, $counter, get_defined_vars()); } @@ -1044,11 +1044,13 @@ public function auto_purge_xml_sitemaps_cache() if(!$this->options['enable']) return $counter; // Nothing to do. - $cache_dir = $this->cache_dir(); // Current cache directory. - if(!is_dir($cache_dir)) return $counter; // Nothing to do. + if(!is_dir($cache_dir = $this->cache_dir())) + return $counter; // Nothing to do. $patterns = '(?:'.implode('|', array_map(function ($pattern) { + $pattern = trim($pattern, '/'); + $pattern = str_replace('.', '-', $pattern); $pattern = preg_quote($pattern, '/'); // Escape. return preg_replace('/\\\\\*/', '.*?', $pattern); // Wildcards. @@ -1056,7 +1058,7 @@ public function auto_purge_xml_sitemaps_cache() $cache_path_no_scheme_quv_ext = $this->url_to_cache_path(home_url('/'), '', '', $this::CACHE_PATH_NO_SCHEME | $this::CACHE_PATH_NO_PATH_INDEX | $this::CACHE_PATH_NO_QUV | $this::CACHE_PATH_NO_EXT); $regex = '/^'.preg_quote($cache_dir, '/'). // Consider all schemes; all path paginations; and all possible variations. '\/[^\/]+\/'.preg_quote($cache_path_no_scheme_quv_ext, '/'). - '\/'.$patterns.'/'; + '\/'.$patterns.'\./'; /** @var $_file \RecursiveDirectoryIterator For IDEs. */ foreach($this->dir_regex_iteration($cache_dir, $regex) as $_file) if($_file->isFile() || $_file->isLink()) @@ -1073,7 +1075,7 @@ public function auto_purge_xml_sitemaps_cache() continue; // Stop here; we already issued a notice, or this notice is N/A. $this->enqueue_notice(''. - __('Quick Cache: detected changes. Found XML sitemap cache file(s) for the site (auto-purging).', $this->text_domain)); + __('Quick Cache: detected changes. Found XML sitemaps (auto-purging).', $this->text_domain)); $enqueued_notices++; // Notice counter. } unset($_file); // Just a little housekeeping. @@ -1110,8 +1112,8 @@ public function auto_purge_home_page_cache() if(!$this->options['cache_purge_home_page_enable']) return $counter; // Nothing to do. - $cache_dir = $this->cache_dir(); // Current cache directory. - if(!is_dir($cache_dir)) return $counter; // Nothing to do. + if(!is_dir($cache_dir = $this->cache_dir())) + return $counter; // Nothing to do. $cache_path_no_scheme_quv_ext = $this->url_to_cache_path(home_url('/'), '', '', $this::CACHE_PATH_NO_SCHEME | $this::CACHE_PATH_NO_PATH_INDEX | $this::CACHE_PATH_NO_QUV | $this::CACHE_PATH_NO_EXT); $regex = '/^'.preg_quote($cache_dir, '/'). // Consider all schemes; all path paginations; and all possible variations. @@ -1170,8 +1172,8 @@ public function auto_purge_posts_page_cache() if(!$this->options['cache_purge_posts_page_enable']) return $counter; // Nothing to do. - $cache_dir = $this->cache_dir(); // Current cache directory. - if(!is_dir($cache_dir)) return $counter; // Nothing to do. + if(!is_dir($cache_dir = $this->cache_dir())) + return $counter; // Nothing to do. $show_on_front = get_option('show_on_front'); $page_for_posts = get_option('page_for_posts'); @@ -1253,8 +1255,8 @@ public function auto_purge_author_page_cache($post_ID, \WP_Post $post_after, \WP if(!$this->options['cache_purge_author_page_enable']) return $counter; // Nothing to do. - $cache_dir = $this->cache_dir(); // Current cache directory. - if(!is_dir($cache_dir)) return $counter; // Nothing to do. + if(!is_dir($cache_dir = $this->cache_dir())) + return $counter; // Nothing to do. /* * If we're changing the post author AND @@ -1274,20 +1276,19 @@ public function auto_purge_author_page_cache($post_ID, \WP_Post $post_after, \WP $authors[] = (integer)$post_before->post_author; $authors[] = (integer)$post_after->post_author; } - elseif(($post_before->post_status === 'publish' || $post_before->post_status === 'private') || - ($post_after->post_status === 'publish' || $post_after->post_status === 'private') + else if(($post_before->post_status === 'publish' || $post_before->post_status === 'private') || + ($post_after->post_status === 'publish' || $post_after->post_status === 'private') ) $authors[] = (integer)$post_after->post_author; - else - return $counter; // Nothing to do. - // Get author posts URL and display name - foreach($authors as $_author_id) + else return $counter; // Nothing to do in this scenario. + + foreach($authors as $_author_id) // Get author posts URL and display name. { $authors_to_purge[$_author_id]['posts_url'] = get_author_posts_url($_author_id); $authors_to_purge[$_author_id]['display_name'] = get_the_author_meta('display_name', $_author_id); } - unset($_author_id); + unset($_author_id); // Housekeeping. foreach($authors_to_purge as $_author) { @@ -1363,6 +1364,9 @@ public function auto_purge_post_terms_cache($id, $force = FALSE) !$this->options['cache_purge_term_other_enable'] ) return $counter; // Nothing to do. + if(!is_dir($cache_dir = $this->cache_dir())) + return $counter; // Nothing to do. + $post_status = get_post_status($id); // Cache this. if($post_status === 'auto-draft') @@ -1377,9 +1381,6 @@ public function auto_purge_post_terms_cache($id, $force = FALSE) if($post_status === 'future' && !$force) return $counter; // Nothing to do. - $cache_dir = $this->cache_dir(); // Current cache directory. - if(!is_dir($cache_dir)) return $counter; // Nothing to do. - /* * Build an array of available taxonomies for this post (as taxonomy objects) */