From ad5348214ecf88b05ba037ecc73cb9316a58eea1 Mon Sep 17 00:00:00 2001
From: JasWSInc
Date: Fri, 13 Jun 2014 01:33:48 -0800
Subject: [PATCH] Finalizing websharks/quick-cache#151 Additional work toward
achieving websharks/quick-cache#130 Also resolves websharks/quick-cache#206
Also resolves websharks/quick-cache#95 Also resolves
websharks/quick-cache#193
---
quick-cache-pro/includes/actions.php | 137 +--
.../includes/advanced-cache.tpl.php | 931 +--------------
quick-cache-pro/includes/auto-cache.php | 9 +-
quick-cache-pro/includes/menu-pages.php | 525 ++++-----
quick-cache-pro/includes/share.php | 1012 ++++++++++++++++-
.../includes/version-specific-upgrade.php | 136 +++
quick-cache-pro/quick-cache-pro.inc.php | 768 +++----------
7 files changed, 1651 insertions(+), 1867 deletions(-)
create mode 100644 quick-cache-pro/includes/version-specific-upgrade.php
diff --git a/quick-cache-pro/includes/actions.php b/quick-cache-pro/includes/actions.php
index a063afec..be8757fa 100644
--- a/quick-cache-pro/includes/actions.php
+++ b/quick-cache-pro/includes/actions.php
@@ -6,8 +6,12 @@
class actions // Action handlers.
{
+ protected $plugin; // Set by constructor.
+
public function __construct()
{
+ $this->plugin = plugin();
+
if(empty($_REQUEST[__NAMESPACE__])) return;
foreach((array)$_REQUEST[__NAMESPACE__] as $action => $args)
if(method_exists($this, $action)) $this->{$action}($args);
@@ -15,21 +19,21 @@ public function __construct()
public function wipe_cache($args)
{
- if(!current_user_can(plugin()->network_cap))
+ if(!current_user_can($this->plugin->network_cap))
return; // Nothing to do.
if(empty($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce']))
return; // Unauthenticated POST data.
- $counter = plugin()->wipe_cache(TRUE); // Counter.
+ $counter = $this->plugin->wipe_cache(TRUE); // Counter.
- if(plugin()->options['cache_clear_s2clean_enable'])
+ if($this->plugin->options['cache_clear_s2clean_enable'])
if(function_exists('s2clean')) $s2clean_counter = s2clean()->md_cache_clear();
- if(plugin()->options['cache_clear_eval_code']) // Custom code?
+ if($this->plugin->options['cache_clear_eval_code']) // Custom code?
{
ob_start(); // Buffer output from PHP code.
- eval('?>'.plugin()->options['cache_clear_eval_code'].''.$this->plugin->options['cache_clear_eval_code'].'network_cap))
+ if(!current_user_can($this->plugin->network_cap))
return; // Nothing to do.
if(empty($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce']))
return; // Unauthenticated POST data.
- $counter = plugin()->wipe_cache(TRUE); // Counter.
+ $counter = $this->plugin->wipe_cache(TRUE); // Counter.
- if(plugin()->options['cache_clear_s2clean_enable'])
+ if($this->plugin->options['cache_clear_s2clean_enable'])
if(function_exists('s2clean')) $s2clean_counter = s2clean()->md_cache_clear();
- if(plugin()->options['cache_clear_eval_code']) // Custom code?
+ if($this->plugin->options['cache_clear_eval_code']) // Custom code?
{
ob_start(); // Buffer output from PHP code.
- eval('?>'.plugin()->options['cache_clear_eval_code'].''.$this->plugin->options['cache_clear_eval_code'].'Wiped a total of %1$s
cache files.
', plugin()->text_domain), $counter);
- $response .= __('Cache wiped for all sites; recreation will occur automatically over time.
', plugin()->text_domain);
- if(isset($s2clean_counter)) $response .= sprintf(__('Also wiped %1$s
s2Clean cache files.
', plugin()->text_domain), $s2clean_counter);
+ $response = sprintf(__('Wiped a total of %1$s
cache files.
', $this->plugin->text_domain), $counter);
+ $response .= __('Cache wiped for all sites; recreation will occur automatically over time.
', $this->plugin->text_domain);
+ if(isset($s2clean_counter)) $response .= sprintf(__('Also wiped %1$s
s2Clean cache files.
', $this->plugin->text_domain), $s2clean_counter);
if(!empty($eval_output)) $response .= $eval_output; // Custom output (perhaps even multiple messages).
exit($response); // JavaScript will take it from here.
@@ -68,21 +72,21 @@ public function ajax_wipe_cache($args)
public function clear_cache($args)
{
- if(!current_user_can(plugin()->cap))
+ if(!current_user_can($this->plugin->cap))
return; // Nothing to do.
if(empty($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce']))
return; // Unauthenticated POST data.
- $counter = plugin()->clear_cache(TRUE); // Counter.
+ $counter = $this->plugin->clear_cache(TRUE); // Counter.
- if(plugin()->options['cache_clear_s2clean_enable'])
+ if($this->plugin->options['cache_clear_s2clean_enable'])
if(function_exists('s2clean')) $s2clean_counter = s2clean()->md_cache_clear();
- if(plugin()->options['cache_clear_eval_code']) // Custom code?
+ if($this->plugin->options['cache_clear_eval_code']) // Custom code?
{
ob_start(); // Buffer output from PHP code.
- eval('?>'.plugin()->options['cache_clear_eval_code'].''.$this->plugin->options['cache_clear_eval_code'].'cap))
+ if(!current_user_can($this->plugin->cap))
return; // Nothing to do.
if(empty($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce']))
return; // Unauthenticated POST data.
- $counter = plugin()->clear_cache(TRUE); // Counter.
+ $counter = $this->plugin->clear_cache(TRUE); // Counter.
- if(plugin()->options['cache_clear_s2clean_enable'])
+ if($this->plugin->options['cache_clear_s2clean_enable'])
if(function_exists('s2clean')) $s2clean_counter = s2clean()->md_cache_clear();
- if(plugin()->options['cache_clear_eval_code']) // Custom code?
+ if($this->plugin->options['cache_clear_eval_code']) // Custom code?
{
ob_start(); // Buffer output from PHP code.
- eval('?>'.plugin()->options['cache_clear_eval_code'].''.$this->plugin->options['cache_clear_eval_code'].'Cleared a total of %1$s
cache files.', plugin()->text_domain), $counter);
- $response .= __('Cache cleared for this site; recreation will occur automatically over time.
', plugin()->text_domain);
- if(isset($s2clean_counter)) $response .= sprintf(__('Also cleared %1$s
s2Clean cache files.
', plugin()->text_domain), $s2clean_counter);
+ $response = sprintf(__('Cleared a total of %1$s
cache files.
', $this->plugin->text_domain), $counter);
+ $response .= __('Cache cleared for this site; recreation will occur automatically over time.
', $this->plugin->text_domain);
+ if(isset($s2clean_counter)) $response .= sprintf(__('Also cleared %1$s
s2Clean cache files.
', $this->plugin->text_domain), $s2clean_counter);
if(!empty($eval_output)) $response .= $eval_output; // Custom output (perhaps even multiple messages).
exit($response); // JavaScript will take it from here.
@@ -121,7 +125,7 @@ public function ajax_clear_cache($args)
public function save_options($args)
{
- if(!current_user_can(plugin()->cap))
+ if(!current_user_can($this->plugin->cap))
return; // Nothing to do.
if(empty($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce']))
@@ -141,38 +145,38 @@ public function save_options($args)
if(isset($args['base_dir'])) // No leading/trailing slashes please.
$args['base_dir'] = trim($args['base_dir'], '\\/'." \t\n\r\0\x0B");
- plugin()->options = array_merge(plugin()->default_options, $args);
+ $this->plugin->options = array_merge($this->plugin->default_options, $args);
- if(!trim(plugin()->options['base_dir'], '\\/'." \t\n\r\0\x0B") // Empty?
- || strpos(basename(plugin()->options['base_dir']), 'wp-') === 0 // Reserved?
- ) plugin()->options['base_dir'] = plugin()->default_options['base_dir'];
+ if(!trim($this->plugin->options['base_dir'], '\\/'." \t\n\r\0\x0B") // Empty?
+ || strpos(basename($this->plugin->options['base_dir']), 'wp-') === 0 // Reserved?
+ ) $this->plugin->options['base_dir'] = $this->plugin->default_options['base_dir'];
- update_option(__NAMESPACE__.'_options', plugin()->options); // Blog-specific.
- if(is_multisite()) update_site_option(__NAMESPACE__.'_options', plugin()->options);
+ update_option(__NAMESPACE__.'_options', $this->plugin->options); // Blog-specific.
+ if(is_multisite()) update_site_option(__NAMESPACE__.'_options', $this->plugin->options);
$redirect_to = self_admin_url('/admin.php'); // Redirect preparations.
$query_args = array('page' => __NAMESPACE__, __NAMESPACE__.'__updated' => '1');
- plugin()->auto_wipe_cache(); // May produce a notice.
+ $this->plugin->auto_wipe_cache(); // May produce a notice.
- if(plugin()->options['enable']) // Enable.
+ if($this->plugin->options['enable']) // Enable.
{
- if(!($add_wp_cache_to_wp_config = plugin()->add_wp_cache_to_wp_config()))
+ if(!($add_wp_cache_to_wp_config = $this->plugin->add_wp_cache_to_wp_config()))
$query_args[__NAMESPACE__.'__wp_config_wp_cache_add_failure'] = '1';
- if(!($add_advanced_cache = plugin()->add_advanced_cache()))
+ if(!($add_advanced_cache = $this->plugin->add_advanced_cache()))
$query_args[__NAMESPACE__.'__advanced_cache_add_failure']
= ($add_advanced_cache === NULL)
? 'qc-advanced-cache' : '1';
- plugin()->update_blog_paths();
+ $this->plugin->update_blog_paths();
}
else // We need to disable Quick Cache in this case.
{
- if(!($remove_wp_cache_from_wp_config = plugin()->remove_wp_cache_from_wp_config()))
+ if(!($remove_wp_cache_from_wp_config = $this->plugin->remove_wp_cache_from_wp_config()))
$query_args[__NAMESPACE__.'__wp_config_wp_cache_remove_failure'] = '1';
- if(!($remove_advanced_cache = plugin()->remove_advanced_cache()))
+ if(!($remove_advanced_cache = $this->plugin->remove_advanced_cache()))
$query_args[__NAMESPACE__.'__advanced_cache_remove_failure'] = '1';
}
$redirect_to = add_query_arg(urlencode_deep($query_args), $redirect_to);
@@ -182,40 +186,39 @@ public function save_options($args)
public function restore_default_options($args)
{
- if(!current_user_can(plugin()->cap))
+ if(!current_user_can($this->plugin->cap))
return; // Nothing to do.
if(empty($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce']))
return; // Unauthenticated POST data.
delete_option(__NAMESPACE__.'_options'); // Blog-specific.
- delete_option('ws_plugin__qcache_options'); // Blog-specific.
if(is_multisite()) delete_site_option(__NAMESPACE__.'_options');
- plugin()->options = plugin()->default_options;
+ $this->plugin->options = $this->plugin->default_options;
$redirect_to = self_admin_url('/admin.php'); // Redirect preparations.
$query_args = array('page' => __NAMESPACE__, __NAMESPACE__.'__restored' => '1');
- plugin()->auto_wipe_cache(); // May produce a notice.
+ $this->plugin->auto_wipe_cache(); // May produce a notice.
- if(plugin()->options['enable']) // Enable.
+ if($this->plugin->options['enable']) // Enable.
{
- if(!($add_wp_cache_to_wp_config = plugin()->add_wp_cache_to_wp_config()))
+ if(!($add_wp_cache_to_wp_config = $this->plugin->add_wp_cache_to_wp_config()))
$query_args[__NAMESPACE__.'__wp_config_wp_cache_add_failure'] = '1';
- if(!($add_advanced_cache = plugin()->add_advanced_cache()))
+ if(!($add_advanced_cache = $this->plugin->add_advanced_cache()))
$query_args[__NAMESPACE__.'__advanced_cache_add_failure']
= ($add_advanced_cache === NULL)
? 'qc-advanced-cache' : '1';
- plugin()->update_blog_paths();
+ $this->plugin->update_blog_paths();
}
else // We need to disable Quick Cache in this case.
{
- if(!($remove_wp_cache_from_wp_config = plugin()->remove_wp_cache_from_wp_config()))
+ if(!($remove_wp_cache_from_wp_config = $this->plugin->remove_wp_cache_from_wp_config()))
$query_args[__NAMESPACE__.'__wp_config_wp_cache_remove_failure'] = '1';
- if(!($remove_advanced_cache = plugin()->remove_advanced_cache()))
+ if(!($remove_advanced_cache = $this->plugin->remove_advanced_cache()))
$query_args[__NAMESPACE__.'__advanced_cache_remove_failure'] = '1';
}
$redirect_to = add_query_arg(urlencode_deep($query_args), $redirect_to);
@@ -225,7 +228,7 @@ public function restore_default_options($args)
public function export_options($args)
{
- if(!current_user_can(plugin()->cap))
+ if(!current_user_can($this->plugin->cap))
return; // Nothing to do.
if(empty($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce']))
@@ -237,7 +240,7 @@ public function export_options($args)
while(@ob_end_clean()) ; // Cleans output buffers.
- $export = json_encode(plugin()->options);
+ $export = json_encode($this->plugin->options);
$file_name = __NAMESPACE__.'-options.json';
nocache_headers();
@@ -251,7 +254,7 @@ public function export_options($args)
public function update_sync($args)
{
- if(!current_user_can(plugin()->update_cap))
+ if(!current_user_can($this->plugin->update_cap))
return; // Nothing to do.
if(empty($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce']))
@@ -259,9 +262,9 @@ public function update_sync($args)
$args = array_map('trim', stripslashes_deep((array)$args));
- if(empty($args['username'])) $args['username'] = plugin()->options['update_sync_username'];
- if(empty($args['password'])) $args['password'] = plugin()->options['update_sync_password'];
- if(!isset($args['version_check'])) $args['version_check'] = plugin()->options['update_sync_version_check'];
+ if(empty($args['username'])) $args['username'] = $this->plugin->options['update_sync_username'];
+ if(empty($args['password'])) $args['password'] = $this->plugin->options['update_sync_password'];
+ if(!isset($args['version_check'])) $args['version_check'] = $this->plugin->options['update_sync_version_check'];
$update_sync_url = 'https://www.websharks-inc.com/products/update-sync.php';
$update_sync_post_vars = array('data' => array('slug' => str_replace('_', '-', __NAMESPACE__).'-pro', 'version' => 'latest-stable',
@@ -275,7 +278,7 @@ public function update_sync($args)
) // Report errors in all of these cases. Redirect errors to `update-sync` page.
{
if(!empty($update_sync_response['error'])) $error = $update_sync_response['error'];
- else $error = __('Unknown error. Please wait 15 minutes and try again.', plugin()->text_domain);
+ else $error = __('Unknown error. Please wait 15 minutes and try again.', $this->plugin->text_domain);
$redirect_to = self_admin_url('/admin.php'); // Redirect preparations.
$query_args = array('page' => __NAMESPACE__.'-update-sync', __NAMESPACE__.'__error' => $error);
@@ -283,20 +286,20 @@ public function update_sync($args)
wp_redirect($redirect_to).exit(); // Done; with errors.
}
- plugin()->options['update_sync_username'] = $args['username']; // Update username.
- plugin()->options['update_sync_password'] = $args['password']; // Update password.
- plugin()->options['update_sync_version_check'] = $args['version_check']; // Check version?
- plugin()->options['last_update_sync_version_check'] = time(); // Update this; we just checked :-)
- update_option(__NAMESPACE__.'_options', plugin()->options); // Save each of these options.
- if(is_multisite()) update_site_option(__NAMESPACE__.'_options', plugin()->options);
+ $this->plugin->options['update_sync_username'] = $args['username']; // Update username.
+ $this->plugin->options['update_sync_password'] = $args['password']; // Update password.
+ $this->plugin->options['update_sync_version_check'] = $args['version_check']; // Check version?
+ $this->plugin->options['last_update_sync_version_check'] = time(); // Update this; we just checked :-)
+ update_option(__NAMESPACE__.'_options', $this->plugin->options); // Save each of these options.
+ if(is_multisite()) update_site_option(__NAMESPACE__.'_options', $this->plugin->options);
$notices = (is_array($notices = get_option(__NAMESPACE__.'_notices'))) ? $notices : array();
unset($notices['persistent-update-sync-version']); // Dismiss this notice.
update_option(__NAMESPACE__.'_notices', $notices); // Update notices.
$redirect_to = self_admin_url('/update.php'); // Runs update routines in WordPress.
- $query_args = array('action' => 'upgrade-plugin', 'plugin' => plugin_basename(plugin()->file),
- '_wpnonce' => wp_create_nonce('upgrade-plugin_'.plugin_basename(plugin()->file)),
+ $query_args = array('action' => 'upgrade-plugin', 'plugin' => plugin_basename($this->plugin->file),
+ '_wpnonce' => wp_create_nonce('upgrade-plugin_'.plugin_basename($this->plugin->file)),
__NAMESPACE__.'__update_version' => $update_sync_response['version'],
__NAMESPACE__.'__update_zip' => base64_encode($update_sync_response['zip']));
$redirect_to = add_query_arg(urlencode_deep($query_args), $redirect_to);
@@ -306,7 +309,7 @@ public function update_sync($args)
public function dismiss_notice($args)
{
- if(!current_user_can(plugin()->cap))
+ if(!current_user_can($this->plugin->cap))
return; // Nothing to do.
if(empty($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce']))
@@ -324,7 +327,7 @@ public function dismiss_notice($args)
public function dismiss_error($args)
{
- if(!current_user_can(plugin()->cap))
+ if(!current_user_can($this->plugin->cap))
return; // Nothing to do.
if(empty($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce']))
diff --git a/quick-cache-pro/includes/advanced-cache.tpl.php b/quick-cache-pro/includes/advanced-cache.tpl.php
index 5b1d97d0..5ace7796 100644
--- a/quick-cache-pro/includes/advanced-cache.tpl.php
+++ b/quick-cache-pro/includes/advanced-cache.tpl.php
@@ -100,13 +100,13 @@
if(!defined('QUICK_CACHE_DIR'))
/**
- * Directory used to store cache files; relative to `ABSPATH`.
+ * Directory used to store cache files; relative to `WP_CONTENT_DIR`.
*
* @since 140422 First documented version.
*
* @var string Absolute server directory path.
*/
- define('QUICK_CACHE_DIR', ABSPATH.'%%QUICK_CACHE_DIR%%');
+ define('QUICK_CACHE_DIR', WP_CONTENT_DIR.'/'.'%%QUICK_CACHE_DIR%%');
if(!defined('QUICK_CACHE_MAX_AGE'))
/**
@@ -218,7 +218,7 @@
*
* @var string Absolute server directory path.
*/
- define('QUICK_CACHE_HTMLC_CACHE_DIR_PUBLIC', ABSPATH.'%%QUICK_CACHE_HTMLC_CACHE_DIR_PUBLIC%%');
+ define('QUICK_CACHE_HTMLC_CACHE_DIR_PUBLIC', WP_CONTENT_DIR.'/'.'%%QUICK_CACHE_HTMLC_CACHE_DIR_PUBLIC%%');
if(!defined('QUICK_CACHE_HTMLC_CACHE_DIR_PRIVATE'))
/**
@@ -228,7 +228,7 @@
*
* @var string Absolute server directory path.
*/
- define('QUICK_CACHE_HTMLC_CACHE_DIR_PRIVATE', ABSPATH.'%%QUICK_CACHE_HTMLC_CACHE_DIR_PRIVATE%%');
+ define('QUICK_CACHE_HTMLC_CACHE_DIR_PRIVATE', WP_CONTENT_DIR.'/'.'%%QUICK_CACHE_HTMLC_CACHE_DIR_PRIVATE%%');
if(!defined('QUICK_CACHE_HTMLC_COMPRESS_COMBINE_HEAD_BODY_CSS'))
/**
@@ -331,16 +331,16 @@
* @package quick_cache\advanced_cache
* @since 140422 First documented version.
*/
- class advanced_cache # `/wp-content/advanced-cache.php`
+ class advanced_cache extends share # `/wp-content/advanced-cache.php`
{
/**
- * Identifies the pro version of Quick Cache.
+ * Microtime; defined by class constructor for debugging purposes.
*
* @since 140422 First documented version.
*
- * @var boolean `TRUE` for Quick Cache Pro; else `FALSE`.
+ * @var float Result of a call to {@link \microtime()}.
*/
- public $is_pro = TRUE;
+ public $timer = 0;
/**
* Flagged as `TRUE` if QC advanced cache is active & running.
@@ -351,15 +351,6 @@ class advanced_cache # `/wp-content/advanced-cache.php`
*/
public $is_running = FALSE;
- /**
- * Microtime; defined by class constructor for debugging purposes.
- *
- * @since 140422 First documented version.
- *
- * @var float Result of a call to {@link \microtime()}.
- */
- public $timer = 0;
-
/**
* Calculated protocol; one of `http://` or `https://`.
*
@@ -441,17 +432,6 @@ class advanced_cache # `/wp-content/advanced-cache.php`
'set_debug_info' => QUICK_CACHE_DEBUGGING_ENABLE,
);
- /**
- * Last HTTP status code passed through {@link \status_header}.
- *
- * @since 140422 First documented version.
- *
- * @var null|integer Last HTTP status code (if applicable).
- *
- * @see maybe_filter_status_header_postload()
- */
- public $http_status;
-
/**
* An array of debug info.
*
@@ -484,37 +464,37 @@ class advanced_cache # `/wp-content/advanced-cache.php`
public $is_404 = FALSE;
/**
- * Is the current request a WordPress content type?
+ * Last HTTP status code passed through {@link \status_header}.
*
- * @since 140605 Improving debug notes display.
+ * @since 140422 First documented version.
*
- * @var boolean `TRUE` if is a WP content type.
+ * @var integer Last HTTP status code (if applicable).
*
- * @see wp_main_query_postload()
+ * @see maybe_filter_status_header_postload()
*/
- public $is_a_wp_content_type = FALSE;
+ public $http_status = 0;
/**
- * Current WordPress {@link \site_url()}.
+ * Is the current request a WordPress content type?
*
- * @since 140422 First documented version.
+ * @since 140605 Improving debug notes display.
*
- * @var string Current WordPress {@link \site_url()}.
+ * @var boolean `TRUE` if is a WP content type.
*
* @see wp_main_query_postload()
*/
- public $site_url = '';
+ public $is_a_wp_content_type = FALSE;
/**
- * Current WordPress {@link \home_url()}.
+ * Current WordPress {@link \content_url()}.
*
- * @since 140422 First documented version.
+ * @since 14xxxx Reorganizing class members.
*
- * @var string Current WordPress {@link \home_url()}.
+ * @var string Current WordPress {@link \content_url()}.
*
* @see wp_main_query_postload()
*/
- public $home_url = '';
+ public $content_url = '';
/**
* Flag for {@link \is_user_loged_in()}.
@@ -549,43 +529,6 @@ class advanced_cache # `/wp-content/advanced-cache.php`
*/
public $plugin_file = QUICK_CACHE_PLUGIN_FILE;
- /**
- * Flag indicating the current user login cookie is expired or invalid.
- *
- * @since 140429 Improving user cache handlers.
- *
- * @var boolean `TRUE` if current user login cookie is expired or invalid.
- * See also {@link user_token()} and {@link maybe_start_ob_when_logged_in_postload()}.
- */
- public $user_login_cookie_expired_or_invalid = FALSE;
-
- /**
- * Text domain for translations; based on `__NAMESPACE__`.
- *
- * @since 140422 First documented version.
- *
- * @var string Defined by class constructor; for translations.
- */
- public $text_domain = '';
-
- /**
- * Array of hooks added by plugins.
- *
- * @since 140422 First documented version.
- *
- * @var array An array of any hooks added by plugins.
- */
- public $hooks = array();
-
- /**
- * Easy reference to the {@link share} class instance.
- *
- * @since 14xxxx Reorganizing class members.
- *
- * @var share References {@link share} class.
- */
- public $share; // Set by constructor.
-
/**
* No-cache because of the current {@link \PHP_SAPI}.
*
@@ -854,16 +797,16 @@ class advanced_cache # `/wp-content/advanced-cache.php`
*/
public function __construct()
{
+ parent::__construct(); // Shared constructor.
+
if(!WP_CACHE || !QUICK_CACHE_ENABLE)
return; // Not enabled.
if(defined('WP_INSTALLING') || defined('RELOCATE'))
return; // N/A; installing|relocating.
- $this->is_running = TRUE;
- $this->timer = microtime(TRUE);
- $this->text_domain = str_replace('_', '-', __NAMESPACE__);
- $this->share = $GLOBALS[__NAMESPACE__.'__share'];
+ $this->is_running = TRUE;
+ $this->timer = microtime(TRUE);
$this->load_ac_plugins();
$this->register_shutdown_flag();
@@ -1237,19 +1180,14 @@ public function wp_main_query_postload()
if($this->is_wp_loaded_query || is_admin())
return; // Nothing to do.
- if(!is_main_query())
- return; // Not the main query.
+ if(!is_main_query()) return; // Not main query.
$this->is_wp_loaded_query = TRUE;
$this->is_404 = is_404();
- $this->site_url = site_url();
- $this->home_url = home_url();
$this->is_user_logged_in = is_user_logged_in();
+ $this->content_url = rtrim(content_url(), '/');
$this->is_maintenance = function_exists('is_maintenance') && is_maintenance();
$this->is_a_wp_content_type = $this->is_404 || $this->is_maintenance || is_front_page() || is_home() || is_singular() || is_archive() || is_post_type_archive() || is_tax() || is_search() || is_feed();
-
- if(function_exists('\\'.__NAMESPACE__.'\\plugin'))
- $this->plugin_file = plugin()->file;
}
/**
@@ -1349,7 +1287,7 @@ public function output_buffer_callback_handler($buffer, $phase)
if(QUICK_CACHE_DEBUGGING_ENABLE && $this->is_html_xml_doc($cache)) // Only if HTML comments are possible.
{
$total_time = number_format(microtime(TRUE) - $this->timer, 5, '.', '');
- $cache .= "\n".'';
+ $cache .= "\n".'';
$cache .= "\n".'';
$cache .= "\n".'';
@@ -1385,8 +1323,10 @@ public function output_buffer_callback_handler($buffer, $phase)
*/
public function maybe_compress_html($cache)
{
- if(!$this->site_url) return $cache; // Not possible.
- if(!QUICK_CACHE_HTMLC_ENABLE || !$this->plugin_file)
+ if(!$this->content_url)
+ return $cache; // Not possible.
+
+ if(!QUICK_CACHE_HTMLC_ENABLE)
return $cache; // Nothing to do here.
require_once dirname($this->plugin_file).'/includes/html-compressor/stub.php';
@@ -1408,7 +1348,7 @@ public function maybe_compress_html($cache)
'cache_expiration_time' => QUICK_CACHE_HTMLC_CACHE_EXPIRATION_TIME,
'cache_dir_public' => QUICK_CACHE_HTMLC_CACHE_DIR_PUBLIC.$host_dir_token,
- 'cache_dir_url_public' => $this->site_url.'/'.str_replace(ABSPATH, '', QUICK_CACHE_HTMLC_CACHE_DIR_PUBLIC.$host_dir_token),
+ 'cache_dir_url_public' => $this->content_url.str_replace(WP_CONTENT_DIR, '', QUICK_CACHE_HTMLC_CACHE_DIR_PUBLIC.$host_dir_token),
'cache_dir_private' => QUICK_CACHE_HTMLC_CACHE_DIR_PRIVATE.$host_dir_token,
'compress_combine_head_body_css' => QUICK_CACHE_HTMLC_COMPRESS_COMBINE_HEAD_BODY_CSS,
@@ -1587,811 +1527,6 @@ public function maybe_get_nc_debug_info($reason_code = '', $reason = '')
}
return "\n".'';
}
-
- /*
- * See also: `quick-cache-pro.inc.php` duplicates.
- * @TODO Find a way to centralize this section so it can be shared between both classes easily.
- */
-
- /**
- * Exclude scheme from cache path.
- *
- * @since 140422 First documented version.
- *
- * @var integer Part of a bitmask.
- */
- const CACHE_PATH_NO_SCHEME = 1;
-
- /**
- * Exclude host (i.e. domain name) from cache path.
- *
- * @since 140422 First documented version.
- *
- * @var integer Part of a bitmask.
- */
- const CACHE_PATH_NO_HOST = 2;
-
- /**
- * Exclude path from cache path.
- *
- * @since 140422 First documented version.
- *
- * @var integer Part of a bitmask.
- */
- const CACHE_PATH_NO_PATH = 4;
-
- /**
- * Exclude path index (i.e. no default `index`) from cache path.
- *
- * @since 140422 First documented version.
- *
- * @var integer Part of a bitmask.
- */
- const CACHE_PATH_NO_PATH_INDEX = 8;
-
- /**
- * Exclude query, user & version salt from cache path.
- *
- * @since 140422 First documented version.
- *
- * @var integer Part of a bitmask.
- */
- const CACHE_PATH_NO_QUV = 16;
-
- /**
- * Exclude query string from cache path.
- *
- * @since 140422 First documented version.
- *
- * @var integer Part of a bitmask.
- */
- const CACHE_PATH_NO_QUERY = 32;
-
- /**
- * Exclude user token from cache path.
- *
- * @since 140422 First documented version.
- *
- * @var integer Part of a bitmask.
- */
- const CACHE_PATH_NO_USER = 64;
-
- /**
- * Exclude version salt from cache path.
- *
- * @since 140422 First documented version.
- *
- * @var integer Part of a bitmask.
- */
- const CACHE_PATH_NO_VSALT = 128;
-
- /**
- * Exclude extension from cache path.
- *
- * @since 140422 First documented version.
- *
- * @var integer Part of a bitmask.
- */
- const CACHE_PATH_NO_EXT = 256;
-
- /**
- * Converts a URL into a `cache/path`.
- *
- * @since 140422 First documented version.
- *
- * @param string $url The input URL to convert.
- * @param string $with_user_token Optional user token (if applicable).
- * @param string $with_version_salt Optional version salt (if applicable).
- * @param integer $flags Optional flags; a bitmask provided by `CACHE_PATH_*` constants.
- *
- * @return string The resulting `cache/path` based on the input `$url`.
- */
- public function url_to_cache_path($url, $with_user_token = '', $with_version_salt = '', $flags = 0)
- {
- $cache_path = ''; // Initialize.
- $url = trim((string)$url);
- $with_user_token = trim((string)$with_user_token);
- $with_version_salt = trim((string)$with_version_salt);
-
- if($url && strpos($url, '://') === FALSE)
- $url = '//'.ltrim($url, '/');
-
- if(!$url || !($url = parse_url($url)))
- return ''; // Invalid URL.
-
- if(!($flags & $this::CACHE_PATH_NO_SCHEME))
- {
- if(!empty($url['scheme']))
- $cache_path .= $url['scheme'].'/';
- else $cache_path .= $this->is_ssl() ? 'https/' : 'http/';
- }
- if(!($flags & $this::CACHE_PATH_NO_HOST))
- {
- if(!empty($url['host']))
- $cache_path .= $url['host'].'/';
- else $cache_path .= $_SERVER['HTTP_HOST'].'/';
- }
- if(!($flags & $this::CACHE_PATH_NO_PATH))
- {
- if(!empty($url['path']) && strlen($url['path'] = trim($url['path'], '\\/'." \t\n\r\0\x0B")))
- $cache_path .= $url['path'].'/';
- else if(!($flags & $this::CACHE_PATH_NO_PATH_INDEX)) $cache_path .= 'index/';
- }
- if($this->is_extension_loaded('mbstring') && mb_check_encoding($cache_path, 'UTF-8'))
- $cache_path = mb_strtolower($cache_path, 'UTF-8');
- $cache_path = str_replace('.', '-', strtolower($cache_path));
-
- if(!($flags & $this::CACHE_PATH_NO_QUV))
- {
- if(!($flags & $this::CACHE_PATH_NO_QUERY))
- if(isset($url['query']) && $url['query'] !== '')
- $cache_path = rtrim($cache_path, '/').'.q/'.md5($url['query']).'/';
-
- if(!($flags & $this::CACHE_PATH_NO_USER))
- if($with_user_token !== '') // Allow a `0` value if desirable.
- $cache_path = rtrim($cache_path, '/').'.u/'.str_replace(array('/', '\\'), '-', $with_user_token).'/';
-
- if(!($flags & $this::CACHE_PATH_NO_VSALT))
- if($with_version_salt !== '') // Allow a `0` value if desirable.
- $cache_path = rtrim($cache_path, '/').'.v/'.str_replace(array('/', '\\'), '-', $with_version_salt).'/';
- }
- $cache_path = trim(preg_replace('/\/+/', '/', $cache_path), '/');
- $cache_path = preg_replace('/[^a-z0-9\/.]/i', '-', $cache_path);
-
- if(!($flags & $this::CACHE_PATH_NO_EXT))
- $cache_path .= '.html';
-
- return $cache_path;
- }
-
- /**
- * Produces a token based on the current `$_SERVER['HTTP_HOST']`.
- *
- * @since 140422 First documented version.
- *
- * @param boolean $dashify Optional, defaults to a `FALSE` value.
- * If `TRUE`, the token is returned with dashes in place of `[^a-z0-9\/]`.
- *
- * @return string Token based on the current `$_SERVER['HTTP_HOST']`.
- *
- * @note The return value of this function is cached to reduce overhead on repeat calls.
- */
- public function host_token($dashify = FALSE)
- {
- $dashify = (integer)$dashify;
- static $tokens = array(); // Static cache.
- if(isset($tokens[$dashify])) return $tokens[$dashify];
-
- $host = strtolower($_SERVER['HTTP_HOST']);
- $token_value = ($dashify) ? trim(preg_replace('/[^a-z0-9\/]/i', '-', $host), '-') : $host;
-
- return ($tokens[$dashify] = $token_value);
- }
-
- /**
- * Produces a token based on the current site's base directory.
- *
- * @since 140605 First documented version.
- *
- * @param boolean $dashify Optional, defaults to a `FALSE` value.
- * If `TRUE`, the token is returned with dashes in place of `[^a-z0-9\/]`.
- *
- * @return string Produces a token based on the current site's base directory;
- * (i.e. in the case of a sub-directory multisite network).
- *
- * @note The return value of this function is cached to reduce overhead on repeat calls.
- *
- * @see plugin\clear_cache()
- * @see plugin\update_blog_paths()
- */
- public function host_base_token($dashify = FALSE)
- {
- $dashify = (integer)$dashify;
- static $tokens = array(); // Static cache.
- if(isset($tokens[$dashify])) return $tokens[$dashify];
-
- $host_base_token = '/'; // Assume NOT multisite; or running it's own domain.
-
- if(is_multisite() && (!defined('SUBDOMAIN_INSTALL') || !SUBDOMAIN_INSTALL))
- { // Multisite w/ sub-directories; need a valid sub-directory token.
-
- if(defined('PATH_CURRENT_SITE')) $host_base_token = PATH_CURRENT_SITE;
- else if(!empty($GLOBALS['base'])) $host_base_token = $GLOBALS['base'];
-
- $host_base_token = trim($host_base_token, '\\/'." \t\n\r\0\x0B");
- $host_base_token = (isset($host_base_token[0])) ? '/'.$host_base_token.'/' : '/';
- }
- $token_value = ($dashify) ? trim(preg_replace('/[^a-z0-9\/]/i', '-', $host_base_token), '-') : $host_base_token;
-
- return ($tokens[$dashify] = $token_value);
- }
-
- /**
- * Produces a token based on the current blog's sub-directory.
- *
- * @since 140422 First documented version.
- *
- * @param boolean $dashify Optional, defaults to a `FALSE` value.
- * If `TRUE`, the token is returned with dashes in place of `[^a-z0-9\/]`.
- *
- * @return string Produces a token based on the current blog sub-directory
- * (i.e. in the case of a sub-directory multisite network).
- *
- * @note The return value of this function is cached to reduce overhead on repeat calls.
- *
- * @see plugin\clear_cache()
- * @see plugin\update_blog_paths()
- */
- public function host_dir_token($dashify = FALSE)
- {
- $dashify = (integer)$dashify;
- static $tokens = array(); // Static cache.
- if(isset($tokens[$dashify])) return $tokens[$dashify];
-
- $host_dir_token = '/'; // Assume NOT multisite; or running it's own domain.
-
- if(is_multisite() && (!defined('SUBDOMAIN_INSTALL') || !SUBDOMAIN_INSTALL))
- { // Multisite w/ sub-directories; need a valid sub-directory token.
-
- $uri_minus_base = // Supports `/sub-dir/child-blog-sub-dir/` also.
- preg_replace('/^'.preg_quote($this->host_base_token(), '/').'/', '', $_SERVER['REQUEST_URI']);
-
- list($host_dir_token) = explode('/', trim($uri_minus_base, '/'));
- $host_dir_token = (isset($host_dir_token[0])) ? '/'.$host_dir_token.'/' : '/';
-
- if($host_dir_token !== '/' // Perhaps NOT the main site?
- && (!is_file(QUICK_CACHE_DIR.'/qc-blog-paths') // NOT a read/valid blog path?
- || !in_array($host_dir_token, unserialize(file_get_contents(QUICK_CACHE_DIR.'/qc-blog-paths')), TRUE))
- ) $host_dir_token = '/'; // Main site; e.g. this is NOT a real/valid child blog path.
- }
- $token_value = ($dashify) ? trim(preg_replace('/[^a-z0-9\/]/i', '-', $host_dir_token), '-') : $host_dir_token;
-
- return ($tokens[$dashify] = $token_value);
- }
-
- /**
- * Produces tokens for the current site's base directory & current blog's sub-directory.
- *
- * @since 140422 First documented version.
- *
- * @param boolean $dashify Optional, defaults to a `FALSE` value.
- * If `TRUE`, the tokens are returned with dashes in place of `[^a-z0-9\/]`.
- *
- * @return string Tokens for the current site's base directory & current blog's sub-directory.
- *
- * @note The return value of this function is cached to reduce overhead on repeat calls.
- *
- * @see clear_cache()
- * @see update_blog_paths()
- */
- public function host_base_dir_tokens($dashify = FALSE)
- {
- return preg_replace('/\/{2,}/', '/', $this->host_base_token($dashify).$this->host_dir_token($dashify));
- }
-
- /**
- * Produces a token based on the current user.
- *
- * @since 140422 First documented version.
- *
- * @return string Produces a token based on the current user;
- * else an empty string if that's not possible to do.
- *
- * @note The return value of this function is cached to reduce overhead on repeat calls.
- *
- * @note This routine may trigger a flag which indicates that the current user was logged-in at some point,
- * but now the login cookie can no longer be validated by WordPress; i.e. they are NOT actually logged in any longer.
- * See {@link $user_login_cookie_expired_or_invalid}
- */
- public function user_token()
- {
- static $token; // Cache.
- if(isset($token)) return $token;
-
- if(function_exists('wp_validate_auth_cookie') && ($user_id = (integer)wp_validate_auth_cookie('', 'logged_in')))
- return ($token = $user_id); // A real user in this case.
-
- else if(!empty($_COOKIE['comment_author_email_'.COOKIEHASH]) && is_string($_COOKIE['comment_author_email_'.COOKIEHASH]))
- return ($token = md5(strtolower(stripslashes($_COOKIE['comment_author_email_'.COOKIEHASH]))));
-
- else if(!empty($_COOKIE['wp-postpass_'.COOKIEHASH]) && is_string($_COOKIE['wp-postpass_'.COOKIEHASH]))
- return ($token = md5(stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH])));
-
- else if(defined('SID') && SID) return ($token = preg_replace('/[^a-z0-9]/i', '', SID));
-
- if(function_exists('wp_validate_auth_cookie') // We were unable to validate the login cookie?
- && !empty($_COOKIE['wordpress_logged_in_'.COOKIEHASH]) && is_string($_COOKIE['wordpress_logged_in_'.COOKIEHASH])
- ) $this->user_login_cookie_expired_or_invalid = TRUE; // Flag as `TRUE`.
-
- return ($token = '');
- }
-
- /**
- * Recursive directory iterator based on a regex pattern.
- *
- * @since 140422 First documented version.
- *
- * @param string $dir An absolute server directory path.
- * @param string $regex A regex pattern; compares to each full file path.
- *
- * @return \RegexIterator Navigable with {@link \foreach()}; where each item
- * is a {@link \RecursiveDirectoryIterator}.
- */
- public function dir_regex_iteration($dir, $regex)
- {
- $dir_iterator = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_SELF | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS);
- $iterator_iterator = new \RecursiveIteratorIterator($dir_iterator, \RecursiveIteratorIterator::CHILD_FIRST);
- $regex_iterator = new \RegexIterator($iterator_iterator, $regex, \RegexIterator::MATCH, \RegexIterator::USE_KEY);
-
- return $regex_iterator;
- }
-
- /**
- * Is the current request method `POST|PUT|DELETE`?
- *
- * @since 140422 First documented version.
- *
- * @return boolean `TRUE` if yes; else `FALSE`.
- *
- * @note The return value of this function is cached to reduce overhead on repeat calls.
- */
- public function is_post_put_del_request()
- {
- static $is; // Cache.
- if(isset($is)) return $is;
-
- if(!empty($_SERVER['REQUEST_METHOD']))
- if(in_array(strtoupper($_SERVER['REQUEST_METHOD']), array('POST', 'PUT', 'DELETE'), TRUE))
- return ($is = TRUE);
-
- return ($is = FALSE);
- }
-
- /**
- * Does the current request include a query string?
- *
- * @since 140422 First documented version.
- *
- * @return boolean `TRUE` if yes; else `FALSE`.
- *
- * @note The return value of this function is cached to reduce overhead on repeat calls.
- */
- public function is_get_request_w_query()
- {
- static $is; // Cache.
- if(isset($is)) return $is;
-
- if(!empty($_GET) || isset($_SERVER['QUERY_STRING'][0]))
- if(!(isset($_GET['qcABC']) && count($_GET) === 1)) // Ignore this special case.
- return ($is = TRUE);
-
- return ($is = FALSE);
- }
-
- /**
- * Should the current user be considered a logged-in user?
- *
- * @since 140422 First documented version.
- *
- * @return boolean `TRUE` if yes; else `FALSE`.
- *
- * @note The return value of this function is cached to reduce overhead on repeat calls.
- */
- public function is_like_user_logged_in()
- {
- static $is; // Cache.
- if(isset($is)) return $is;
-
- /* This checks for a PHP session; i.e. session_start() in PHP where you're dealing with a user session.
- * WordPress itself does not use sessions, but some plugins/themes do. If you have a theme/plugin using
- * sessions, and there is an active session open, we consider you logged in; and thus, no caching.
- * SID is a PHP internal constant to identify a PHP session. It's the same regardless of the app. If PHP
- * starts a session, SID is defined.
- */
- if(defined('SID') && SID) return ($is = TRUE); // Session.
-
- $logged_in_cookies[] = 'comment_author_'; // Comment (and/or reply) authors.
- $logged_in_cookies[] = 'wp-postpass_'; // Password access to protected posts.
-
- $logged_in_cookies[] = (defined('AUTH_COOKIE')) ? AUTH_COOKIE : 'wordpress_';
- $logged_in_cookies[] = (defined('SECURE_AUTH_COOKIE')) ? SECURE_AUTH_COOKIE : 'wordpress_sec_';
- $logged_in_cookies[] = (defined('LOGGED_IN_COOKIE')) ? LOGGED_IN_COOKIE : 'wordpress_logged_in_';
- $logged_in_cookies = '/^(?:'.implode('|', array_map(function ($logged_in_cookie)
- {
- return preg_quote($logged_in_cookie, '/'); // Escape.
-
- }, $logged_in_cookies)).')/';
- $test_cookie = (defined('TEST_COOKIE')) ? TEST_COOKIE : 'wordpress_test_cookie';
-
- foreach($_COOKIE as $_key => $_value) if($_key !== $test_cookie)
- if(preg_match($logged_in_cookies, $_key) && $_value) return ($is = TRUE);
- unset($_key, $_value); // Housekeeping.
-
- return ($is = FALSE);
- }
-
- /**
- * Are we in a LOCALHOST environment?
- *
- * @since 140422 First documented version.
- *
- * @return boolean `TRUE` if yes; else `FALSE`.
- *
- * @note The return value of this function is cached to reduce overhead on repeat calls.
- */
- public function is_localhost()
- {
- static $is; // Cache.
- if(isset($is)) return $is;
-
- if(defined('LOCALHOST') && LOCALHOST) return ($is = TRUE);
-
- if(!defined('LOCALHOST') && !empty($_SERVER['HTTP_HOST']))
- if(preg_match('/localhost|127\.0\.0\.1/i', $_SERVER['HTTP_HOST']))
- return ($is = TRUE);
-
- return ($is = FALSE);
- }
-
- /**
- * Is the current request for the Auto-Cache Engine?
- *
- * @since 140422 First documented version.
- *
- * @return boolean `TRUE` if yes; else `FALSE`.
- *
- * @note The return value of this function is cached to reduce overhead on repeat calls.
- */
- public function is_auto_cache_engine()
- {
- static $is; // Cache.
- if(isset($is)) return $is;
-
- if(!empty($_SERVER['HTTP_USER_AGENT']))
- if(stripos($_SERVER['HTTP_USER_AGENT'], __NAMESPACE__) !== FALSE)
- return ($is = TRUE);
-
- return ($is = FALSE);
- }
-
- /**
- * Is the current request for a feed?
- *
- * @since 140422 First documented version.
- *
- * @return boolean `TRUE` if yes; else `FALSE`.
- *
- * @note The return value of this function is cached to reduce overhead on repeat calls.
- */
- public function is_feed()
- {
- static $is; // Cache.
- if(isset($is)) return $is;
-
- if(preg_match('/\/feed(?:[\/?]|$)/', $_SERVER['REQUEST_URI']))
- return ($is = TRUE);
-
- if(isset($_REQUEST['feed']))
- return ($is = TRUE);
-
- return ($is = FALSE);
- }
-
- /**
- * Is the current request over SSL?
- *
- * @since 140422 First documented version.
- *
- * @return boolean `TRUE` if yes; else `FALSE`.
- *
- * @note The return value of this function is cached to reduce overhead on repeat calls.
- */
- public function is_ssl()
- {
- static $is; // Cache.
- if(isset($is)) return $is;
-
- if(!empty($_SERVER['SERVER_PORT']))
- if($_SERVER['SERVER_PORT'] === '443')
- return ($is = TRUE);
-
- if(!empty($_SERVER['HTTPS']))
- if($_SERVER['HTTPS'] === '1' || strcasecmp($_SERVER['HTTPS'], 'on') === 0)
- return ($is = TRUE);
-
- if(!empty($_SERVER['HTTP_X_FORWARDED_PROTO']))
- if(strcasecmp($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') === 0)
- return ($is = TRUE);
-
- return ($is = FALSE);
- }
-
- /**
- * Is a document/string an HTML/XML doc; or no?
- *
- * @since 140422 First documented version.
- *
- * @param string $doc Input string/document to check.
- *
- * @return boolean `TRUE` if yes; else `FALSE`.
- */
- public function is_html_xml_doc($doc)
- {
- if(($doc = (string)$doc))
- if(stripos($doc, '