From 4120f778936ddf533fb0cba14999e2b954ccdc9c Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Mon, 28 Dec 2015 17:43:32 -0500 Subject: [PATCH] Show Dashboard notice when ACE is enabled and PHP allow_url_fopen=0 See websharks/zencache#644 --- src/includes/classes/Actions.php | 4 ++ src/includes/classes/Plugin.php | 1 + .../closures/Plugin/AutoCacheUtils.php | 48 +++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/src/includes/classes/Actions.php b/src/includes/classes/Actions.php index 1326fe5d..014d45d7 100644 --- a/src/includes/classes/Actions.php +++ b/src/includes/classes/Actions.php @@ -576,6 +576,9 @@ protected function saveOptions($args) if (!($add_advanced_cache = $this->plugin->addAdvancedCache())) { $query_args[GLOBAL_NS.'_advanced_cache_add_failure'] = $add_advanced_cache === null ? 'advanced-cache' : '1'; } + if (!$this->plugin->options['auto_cache_enable']) { + $this->plugin->autoCacheMaybeClearPhpIniError(true); + } if (!$this->plugin->options['auto_cache_enable'] || !$this->plugin->options['auto_cache_sitemap_url']) { $this->plugin->autoCacheMaybeClearPrimaryXmlSitemapError(true); } @@ -591,6 +594,7 @@ protected function saveOptions($args) $query_args[GLOBAL_NS.'_advanced_cache_remove_failure'] = '1'; } $this->plugin->autoCacheMaybeClearPrimaryXmlSitemapError(true); + $this->plugin->autoCacheMaybeClearPhpIniError(true); } $redirect_to = add_query_arg(urlencode_deep($query_args), $redirect_to); diff --git a/src/includes/classes/Plugin.php b/src/includes/classes/Plugin.php index 52695f47..0e2979bb 100644 --- a/src/includes/classes/Plugin.php +++ b/src/includes/classes/Plugin.php @@ -440,6 +440,7 @@ public function setup() /*[pro strip-from="lite"]*/ add_action('admin_init', array($this, 'autoCacheMaybeClearPrimaryXmlSitemapError')); + add_action('admin_init', array($this, 'autoCacheMaybeClearPhpIniError')); add_action('admin_init', array($this, 'statsLogPinger')); /*[/pro]*/ diff --git a/src/includes/closures/Plugin/AutoCacheUtils.php b/src/includes/closures/Plugin/AutoCacheUtils.php index b7d7cbaa..8d387617 100644 --- a/src/includes/closures/Plugin/AutoCacheUtils.php +++ b/src/includes/closures/Plugin/AutoCacheUtils.php @@ -24,6 +24,54 @@ new AutoCache(); }; +/** + * Check if PHP configuration meets minimum requirements for Auto-Cache Engine and remove old notice if necessary. + * + * @since 15xxxx Improving Auto-Cache Engine minimum PHP requirements reporting. + * + * @param bool $force Defaults to a FALSE value. + * + * @attaches-to `admin_init` + * + * @note This routine is also called from `saveOptions()`. + */ +$self->autoCacheMaybeClearPhpIniError = function ($force = false) use ($self) { + if ($force) { + $self->dismissMainNotice('allow_url_fopen_disabled'); + return; // Nothing else to do. + } + if (!$self->options['enable']) { + return; // Nothing to do. + } + if (!$self->options['auto_cache_enable']) { + return; // Nothing to do. + } + $self->autoCacheCheckPhpIni(); +}; + +/** + * Check if PHP configuration meets minimum requirements for Auto-Cache Engine and display a notice if necessary. + * + * @since 15xxxx Improving Auto-Cache Engine minimum PHP requirements reporting. + * + * @return bool `TRUE` if all required PHP configuration is present, else `FALSE`. This also creates a dashboard notice in some cases. + * + * @note Unlike `autoCacheCheckXmlSitemap()`, this routine is NOT used by the Auto-Cache Engine class when the Auto-Cache Engine is running. + */ +$self->autoCacheCheckPhpIni = function () use ($self) { + if (!filter_var(ini_get('allow_url_fopen'), FILTER_VALIDATE_BOOLEAN)) { // Is allow_url_fopen=1? + $self->dismissMainNotice('allow_url_fopen_disabled'); // Clear any previous allow_url_fopen notice. + $self->enqueueMainNotice( + sprintf(__('%1$s says... The Auto-Cache Engine requires PHP URL-aware fopen wrappers (allow_url_fopen=1), however this option has been disabled by your php.ini runtime configuration. Please contact your web hosting company to resolve this issue or disable the Auto-Cache Engine in the settings.', SLUG_TD), esc_html(NAME)), + array('class' => 'error', 'persistent_key' => 'allow_url_fopen_disabled', 'dismissable' => false) + ); + return false; // Nothing more we can do in this case. + } + $self->dismissMainNotice('allow_url_fopen_disabled'); // Any previous problems have been fixed; dismiss any existing failure notice + + return true; +}; + /** * Check if Auto-Cache Engine XML Sitemap is valid and remove old notice if necessary. *