Skip to content

Commit

Permalink
Enhancing data storage. Preparing for cross-blog transients used in s…
Browse files Browse the repository at this point in the history
…tats collection. See: wpsharks/comet-cache#83
  • Loading branch information
jaswsinc committed Aug 8, 2015
1 parent 846970f commit fda577d
Show file tree
Hide file tree
Showing 14 changed files with 347 additions and 341 deletions.
4 changes: 2 additions & 2 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

if (require(dirname(__FILE__).'/src/vendor/websharks/wp-php-rv/src/includes/check.php')) {
if (!empty($_REQUEST['zencache_apc_warning_bypass']) && is_admin()) {
update_option('zencache_apc_warning_bypass', time());
update_site_option('zencache_apc_warning_bypass', time());
}
if (extension_loaded('apc') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) && filter_var(ini_get('apc.cache_by_default'), FILTER_VALIDATE_BOOLEAN) && stripos((string) ini_get('apc.filters'), 'zencache') === false && !get_option('zencache_apc_warning_bypass')) {
if (extension_loaded('apc') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) && filter_var(ini_get('apc.cache_by_default'), FILTER_VALIDATE_BOOLEAN) && stripos((string) ini_get('apc.filters'), 'zencache') === false && !get_site_option('zencache_apc_warning_bypass')) {
if (empty($_REQUEST['zencache_apc_warning_bypass']) && is_admin()) {
${__FILE__}['apc_warning'] = '<h3 style="margin:.5em 0 .25em 0;">'.__('<strong>APC EXTENSION WARNING</strong></h3>', 'zencache');
${__FILE__}['apc_warning'] .= '<p style="margin-top:0;">'.sprintf(__('<strong>ZenCache says...</strong> It appears that you\'re currently running PHP v%1$s with APC enabled. APC is <a href="http://zencache.com/r/apc-compatibility/" target="_blank">known to contain bugs</a>.', 'zencache'), esc_html(PHP_VERSION)).'</p>';
Expand Down
56 changes: 7 additions & 49 deletions src/includes/classes/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class Actions extends AbsBase
/*[/pro]*/

'dismissNotice',
'dismissError',
);

/**
Expand Down Expand Up @@ -253,10 +252,8 @@ protected function saveOptions($args)
if (!trim($this->plugin->options['base_dir'], '\\/'." \t\n\r\0\x0B") || strpos(basename($this->plugin->options['base_dir']), 'wp-') === 0) {
$this->plugin->options['base_dir'] = $this->plugin->default_options['base_dir'];
}
update_option(GLOBAL_NS.'_options', $this->plugin->options);
if (is_multisite()) {
update_site_option(GLOBAL_NS.'_options', $this->plugin->options);
}
update_site_option(GLOBAL_NS.'_options', $this->plugin->options);

$redirect_to = self_admin_url('/admin.php'); // Redirect preparations.
$query_args = array('page' => GLOBAL_NS, GLOBAL_NS.'_updated' => '1');

Expand Down Expand Up @@ -298,10 +295,7 @@ protected function restoreDefaultOptions($args)
if (empty($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'])) {
return; // Unauthenticated POST data.
}
delete_option(GLOBAL_NS.'_options');
if (is_multisite()) {
delete_site_option(GLOBAL_NS.'_options');
}
delete_site_option(GLOBAL_NS.'_options');
$this->plugin->options = $this->plugin->default_options;

$redirect_to = self_admin_url('/admin.php'); // Redirect preparations.
Expand Down Expand Up @@ -415,7 +409,7 @@ protected function proUpdate($args)
$error = __('Unknown error. Please wait 15 minutes and try again.', SLUG_TD);
}
$redirect_to = self_admin_url('/admin.php'); // Redirect preparations.
$query_args = array('page' => GLOBAL_NS.'-pro-updater', GLOBAL_NS.'__error' => $error);
$query_args = array('page' => GLOBAL_NS.'-pro-updater', GLOBAL_NS.'_error' => $error);
$redirect_to = add_query_arg(urlencode_deep($query_args), $redirect_to);

wp_redirect($redirect_to).exit();
Expand All @@ -425,13 +419,8 @@ protected function proUpdate($args)
$this->plugin->options['pro_update_username'] = (string) $args['username'];
$this->plugin->options['pro_update_password'] = (string) $args['password'];

update_option(GLOBAL_NS.'_options', $this->plugin->options);
if (is_multisite()) {
update_site_option(GLOBAL_NS.'_options', $this->plugin->options);
}
$notices = is_array($notices = get_option(GLOBAL_NS.'_notices')) ? $notices : array();
unset($notices['persistent-new-pro-version-available']); // Dismiss this notice.
update_option(GLOBAL_NS.'_notices', $notices); // Update notices.
update_site_option(GLOBAL_NS.'_options', $this->plugin->options);
$this->plugin->dismissMainNotice('persistent--new-pro-version-available');

$redirect_to = self_admin_url('/update.php');
$query_args = array(
Expand Down Expand Up @@ -463,38 +452,7 @@ protected function dismissNotice($args)
return; // Unauthenticated POST data.
}
$args = array_map('trim', stripslashes_deep((array) $args));
if (empty($args['key'])) {
return; // Nothing to dismiss.
}
$notices = is_array($notices = get_option(GLOBAL_NS.'_notices')) ? $notices : array();
unset($notices[$args['key']]); // Dismiss this notice.
update_option(GLOBAL_NS.'_notices', $notices);

wp_redirect(remove_query_arg(GLOBAL_NS)).exit();
}

/**
* Action handler.
*
* @since 150422 Rewrite.
*
* @param mixed Input action argument(s).
*/
protected function dismissError($args)
{
if (!current_user_can($this->plugin->cap)) {
return; // Nothing to do.
}
if (empty($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'])) {
return; // Unauthenticated POST data.
}
$args = array_map('trim', stripslashes_deep((array) $args));
if (empty($args['key'])) {
return; // Nothing to dismiss.
}
$errors = is_array($errors = get_option(GLOBAL_NS.'_errors')) ? $errors : array();
unset($errors[$args['key']]); // Dismiss this error.
update_option(GLOBAL_NS.'_errors', $errors);
$this->plugin->dismissNotice($args['key']);

wp_redirect(remove_query_arg(GLOBAL_NS)).exit();
}
Expand Down
2 changes: 1 addition & 1 deletion src/includes/classes/Conflicts.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function maybeEnqueueNotice()
$conflicting_plugin_name = $conflicting_plugin_name.' '.__('Lite', SLUG_TD);
$GLOBALS[GLOBAL_NS.'_conflicting_plugin_lite_pro'] = true;
}
echo '<div class="error">'.
echo '<div class="error">'.// Error notice.
' <p>'.// Running one or more conflicting plugins at the same time.
' '.sprintf(__('<strong>%1$s</strong> is NOT running. A conflicting plugin, <strong>%2$s</strong>, is currently active. Please deactivate the %2$s plugin to clear this message.', SLUG_TD), esc_html($this_plugin_name), esc_html($conflicting_plugin_name)).
' </p>'.
Expand Down
4 changes: 2 additions & 2 deletions src/includes/classes/MenuPageProUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public function __construct()

/* ----------------------------------------------------------------------------------------- */

if (!empty($_REQUEST[GLOBAL_NS.'__error'])) {
if (!empty($_REQUEST[GLOBAL_NS.'_error'])) {
echo '<div class="plugin-menu-page-error error">'."\n";
echo ' <i class="fa fa-thumbs-down"></i> '.esc_html(stripslashes((string) $_REQUEST[GLOBAL_NS.'__error']))."\n";
echo ' <i class="fa fa-thumbs-down"></i> '.esc_html(stripslashes((string) $_REQUEST[GLOBAL_NS.'_error']))."\n";
echo '</div>'."\n";
}
/* ----------------------------------------------------------------------------------------- */
Expand Down
57 changes: 24 additions & 33 deletions src/includes/classes/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,25 +344,19 @@ public function setup()

'uninstall_on_deletion' => '0', // `0|1`.
);
$options = is_array($options = get_option(GLOBAL_NS.'_options')) ? $options : array();
if (is_multisite() && is_array($site_options = get_site_option(GLOBAL_NS.'_options'))) {
$options = array_merge($options, $site_options); // Multisite options.
}
if (!$options && is_multisite() && is_array($quick_cache_site_options = get_site_option('quick_cache_options'))) {
$options = $quick_cache_site_options;
$options['crons_setup'] = $this->default_options['crons_setup'];
}
if (!$options && is_array($quick_cache_options = get_option('quick_cache_options'))) {
$options = $quick_cache_options;
$this->default_options = $this->applyWpFilters(GLOBAL_NS.'_default_options', $this->default_options);

$options = is_array($options = get_site_option(GLOBAL_NS.'_options')) ? $options : array();
if (!$options && is_array($quick_cache_options = get_site_option('quick_cache_options'))) {
$options = $quick_cache_options; // Old Quick Cache options.
$options['crons_setup'] = $this->default_options['crons_setup'];
}
$this->default_options = $this->applyWpFilters(GLOBAL_NS.'_default_options', $this->default_options, get_defined_vars());
$this->options = array_merge($this->default_options, $options); // This considers old options also.
$this->options = $this->applyWpFilters(GLOBAL_NS.'_options', $this->options, get_defined_vars());
$this->options = array_intersect_key($this->options, $this->default_options);
$this->options = array_merge($this->default_options, $options);
$this->options = $this->applyWpFilters(GLOBAL_NS.'_options', $this->options);
$this->options = array_intersect_key($this->options, $this->default_options);

$this->options['base_dir'] = trim($this->options['base_dir'], '\\/'." \t\n\r\0\x0B");
if (!$this->options['base_dir']) {
if (!$this->options['base_dir']) { // Do NOT allow this to be empty--ever!
$this->options['base_dir'] = $this->default_options['base_dir'];
}
$this->cap = $this->applyWpFilters(GLOBAL_NS.'_cap', $this->cap);
Expand Down Expand Up @@ -410,7 +404,6 @@ public function setup()
add_action('admin_enqueue_scripts', array($this, 'enqueueAdminScripts'));

add_action('all_admin_notices', array($this, 'allAdminNotices'));
add_action('all_admin_notices', array($this, 'allAdminErrors'));

add_action('admin_menu', array($this, 'addMenuPages'));
add_action('network_admin_menu', array($this, 'addNetworkMenuPages'));
Expand Down Expand Up @@ -475,29 +468,27 @@ public function setup()
/*[/pro]*/
/* -------------------------------------------------------------- */

add_filter('cron_schedules', array($this, 'extendCronSchedules'));
if (!is_multisite() || is_main_site()) { // Main site only.
add_filter('cron_schedules', array($this, 'extendCronSchedules'));

if ((integer) $this->options['crons_setup'] < 1398051975
|| substr($this->options['crons_setup'], 10) !== '-'.__NAMESPACE__) {
// Purge routine; i.e., automatic cache cleanup.
wp_clear_scheduled_hook('_cron_'.GLOBAL_NS.'_cleanup');
wp_schedule_event(time() + 60, 'daily', '_cron_'.GLOBAL_NS.'_cleanup');
if ((integer) $this->options['crons_setup'] < 1439005906 || substr($this->options['crons_setup'], 10) !== '-'.__NAMESPACE__) {
wp_clear_scheduled_hook('_cron_'.GLOBAL_NS.'_cleanup');
wp_schedule_event(time() + 60, 'daily', '_cron_'.GLOBAL_NS.'_cleanup');

/*[pro strip-from="lite"]*/ // Auto-cache engine.
wp_clear_scheduled_hook('_cron_'.GLOBAL_NS.'_auto_cache');
wp_schedule_event(time() + 60, 'every15m', '_cron_'.GLOBAL_NS.'_auto_cache');
/*[/pro]*/
/*[pro strip-from="lite"]*/ // Auto-cache engine.
wp_clear_scheduled_hook('_cron_'.GLOBAL_NS.'_auto_cache');
wp_schedule_event(time() + 60, 'every15m', '_cron_'.GLOBAL_NS.'_auto_cache');
/*[/pro]*/

$this->options['crons_setup'] = (string) time().'-'.__NAMESPACE__;

update_option(GLOBAL_NS.'_options', $this->options);
if (is_multisite()) {
$this->options['crons_setup'] = time().'-'.__NAMESPACE__;
update_site_option(GLOBAL_NS.'_options', $this->options);
}
}
add_action('_cron_'.GLOBAL_NS.'_auto_cache', array($this, 'autoCache'));
add_action('_cron_'.GLOBAL_NS.'_cleanup', array($this, 'purgeCache'));
add_action('_cron_'.GLOBAL_NS.'_cleanup', array($this, 'purgeCacheDir'));

/*[pro strip-from="lite"]*/ // Auto-cache engine.
add_action('_cron_'.GLOBAL_NS.'_auto_cache', array($this, 'autoCache'));
/*[/pro]*/
}
/* -------------------------------------------------------------- */

$this->doWpAction('after_'.GLOBAL_NS.'_'.__FUNCTION__, get_defined_vars());
Expand Down
Loading

0 comments on commit fda577d

Please sign in to comment.