From d081835649738594fb9d99dd0644d50b9faa3451 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 26 Nov 2022 21:19:55 +0100 Subject: [PATCH] check if plugin is configured --- _admin.php | 56 +++++++++++++++-------------- inc/class.zoneclear.feed.server.php | 8 ++++- index.php | 15 ++++++-- locales/fr/resources.php | 1 - 4 files changed, 50 insertions(+), 30 deletions(-) diff --git a/_admin.php b/_admin.php index 9c77a35..7aa2e27 100644 --- a/_admin.php +++ b/_admin.php @@ -18,36 +18,40 @@ dcCore::app()->blog->settings->addNamespace('zoneclearFeedServer'); require_once __DIR__ . '/_widgets.php'; -dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( - __('Feeds server'), - dcCore::app()->adminurl->get('admin.plugin.zoneclearFeedServer'), - dcPage::getPF('zoneclearFeedServer/icon.svg'), - preg_match( - '/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.zoneclearFeedServer')) . '(&.*)?$/', - $_SERVER['REQUEST_URI'] - ), - dcCore::app()->auth->check(dcAuth::PERMISSION_CONTENT_ADMIN, dcCore::app()->blog->id) -); +if (dcCore::app()->blog->settings->zoneclearFeedServer->zoneclearFeedServer_active + && '' != dcCore::app()->blog->settings->zoneclearFeedServer->zoneclearFeedServer_user +) { + dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( + __('Feeds server'), + dcCore::app()->adminurl->get('admin.plugin.zoneclearFeedServer'), + dcPage::getPF('zoneclearFeedServer/icon.svg'), + preg_match( + '/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.zoneclearFeedServer')) . '(&.*)?$/', + $_SERVER['REQUEST_URI'] + ), + dcCore::app()->auth->check(dcAuth::PERMISSION_CONTENT_ADMIN, dcCore::app()->blog->id) + ); + + if (dcCore::app()->auth->check(dcAuth::PERMISSION_CONTENT_ADMIN, dcCore::app()->blog->id)) { + # Dashboard icon + dcCore::app()->addBehavior('adminDashboardFavoritesV2', ['zcfsAdminBehaviors', 'adminDashboardFavoritesV2']); + # User pref + dcCore::app()->addBehavior('adminColumnsListsV2', ['zcfsAdminBehaviors', 'adminColumnsListsV2']); + dcCore::app()->addBehavior('adminFiltersListsV2', ['zcfsAdminBehaviors', 'adminFiltersListsV2']); + # Add info about feed on post page sidebar + dcCore::app()->addBehavior('adminPostHeaders', ['zcfsAdminBehaviors', 'adminPostHeaders']); + dcCore::app()->addBehavior('adminPostFormItems', ['zcfsAdminBehaviors', 'adminPostFormItems']); + } + + # Take care about tweakurls (thanks Mathieu M.) + if (version_compare(dcCore::app()->plugins->moduleInfo('tweakurls', 'version'), '0.8', '>=')) { + dcCore::app()->addbehavior('zcfsAfterPostCreate', ['zoneclearFeedServer', 'tweakurlsAfterPostCreate']); + } +} # Delete related info about feed post in meta table dcCore::app()->addBehavior('adminBeforePostDelete', ['zcfsAdminBehaviors', 'adminBeforePostDelete']); -if (dcCore::app()->auth->check(dcAuth::PERMISSION_CONTENT_ADMIN, dcCore::app()->blog->id)) { - # Dashboard icon - dcCore::app()->addBehavior('adminDashboardFavoritesV2', ['zcfsAdminBehaviors', 'adminDashboardFavoritesV2']); - # User pref - dcCore::app()->addBehavior('adminColumnsListsV2', ['zcfsAdminBehaviors', 'adminColumnsListsV2']); - dcCore::app()->addBehavior('adminFiltersListsV2', ['zcfsAdminBehaviors', 'adminFiltersListsV2']); - # Add info about feed on post page sidebar - dcCore::app()->addBehavior('adminPostHeaders', ['zcfsAdminBehaviors', 'adminPostHeaders']); - dcCore::app()->addBehavior('adminPostFormItems', ['zcfsAdminBehaviors', 'adminPostFormItems']); -} - -# Take care about tweakurls (thanks Mathieu M.) -if (version_compare(dcCore::app()->plugins->moduleInfo('tweakurls', 'version'), '0.8', '>=')) { - dcCore::app()->addbehavior('zcfsAfterPostCreate', ['zoneclearFeedServer', 'tweakurlsAfterPostCreate']); -} - /** * @ingroup DC_PLUGIN_ZONECLEARFEEDSERVER * @brief Mix your blog with a feeds planet - admin methods. diff --git a/inc/class.zoneclear.feed.server.php b/inc/class.zoneclear.feed.server.php index d83bc8b..fa3309e 100644 --- a/inc/class.zoneclear.feed.server.php +++ b/inc/class.zoneclear.feed.server.php @@ -395,6 +395,13 @@ class zoneclearFeedServer */ public function checkFeedsUpdate($id = null, $throw = false) { + $s = dcCore::app()->blog->settings->zoneclearFeedServer; + + # Not configured + if (!$s->zoneclearFeedServer_active || !$s->zoneclearFeedServer_user) { + return false; + } + # Limit to one update at a time try { $this->lockUpdate(); @@ -408,7 +415,6 @@ class zoneclearFeedServer dt::setTZ(dcCore::app()->blog->settings->system->blog_timezone); $time = time(); - $s = dcCore::app()->blog->settings->zoneclearFeedServer; # All feeds or only one (from admin) $f = !$id ? diff --git a/index.php b/index.php index deb977e..6981136 100644 --- a/index.php +++ b/index.php @@ -23,13 +23,24 @@ dcPage::check(dcAuth::PERMISSION_CONTENT_ADMIN); $zcfs = new zoneclearFeedServer(); +# Not configured +if (!dcCore::app()->blog->settings->zoneclearFeedServer->zoneclearFeedServer_active + || !dcCore::app()->blog->settings->zoneclearFeedServer->zoneclearFeedServer_user +) { + echo + '' . __('Feeds server') . '' . + dcPage::breadcrumb([ + __('Plugins') => '', + __('Feeds server') => '', + ]) . + dcPage::notices(); + ############################################################ # # One feed # ############################################################ - -if (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') { +} elseif (isset($_REQUEST['part']) && $_REQUEST['part'] == 'feed') { $feed_id = ''; $feed_name = ''; $feed_desc = ''; diff --git a/locales/fr/resources.php b/locales/fr/resources.php index faed843..e464987 100644 --- a/locales/fr/resources.php +++ b/locales/fr/resources.php @@ -10,5 +10,4 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ - dcCore::app()->resources['help']['zoneclearFeedServer'] = __DIR__ . '/help/zoneclearFeedServer.html';