From 18f27cc20ab3016560703453a1dc8253395d58eb Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 30 Jul 2023 10:01:37 +0200 Subject: [PATCH] release 2.2 --- CHANGELOG.md | 6 +++++ README.md | 7 +++--- _define.php | 6 ++--- dcstore.xml | 6 ++--- src/Backend.php | 52 ++++++++++------------------------------ src/Frontend.php | 24 +++++-------------- src/Manage.php | 61 +++++++++++++++++++---------------------------- src/My.php | 32 +++++++------------------ src/Uninstall.php | 10 ++++---- src/Widgets.php | 9 ++----- 10 files changed, 73 insertions(+), 140 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6662821..13af997 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +2.2 - 2023.07.30 +* require Dotclear 2.27 +* require PHP 7.4+ +* use new svg icon +* update to Dotclear 2.27-dev + 2.1 - 2023.05.13 * require Dotclear 2.26 * fix nullsafe warnings diff --git a/README.md b/README.md index 5301266..1399af9 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Release](https://img.shields.io/github/v/release/JcDenis/arlequin)](https://github.com/JcDenis/arlequin/releases) [![Date](https://img.shields.io/github/release-date/JcDenis/arlequin)](https://github.com/JcDenis/arlequin/releases) [![Issues](https://img.shields.io/github/issues/JcDenis/arlequin)](https://github.com/JcDenis/arlequin/issues) -[![Dotclear](https://img.shields.io/badge/dotclear-v2.26-blue.svg)](https://fr.dotclear.org/download) +[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-blue.svg)](https://fr.dotclear.org/download) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/arlequin) [![License](https://img.shields.io/github/license/JcDenis/arlequin)](https://github.com/JcDenis/arlequin/blob/master/LICENSE) @@ -18,8 +18,9 @@ It allows visitors to select a theme on your blog. _arlequin_ requires: - * content admin permissions to manage theme and public menu - * Dotclear 2.26 + * content admin permissions to manage theme and public menu + * Dotclear 2.27 + * PHP 7.4+ ## USAGE diff --git a/_define.php b/_define.php index 09f0642..99e2a84 100644 --- a/_define.php +++ b/_define.php @@ -10,7 +10,7 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -if (!defined('DC_RC_PATH') || is_null(dcCore::app()->auth)) { +if (!defined('DC_RC_PATH')) { return; } @@ -18,9 +18,9 @@ $this->registerModule( 'Arlequin', 'Allows visitors choose a theme', 'Oleksandr Syenchuk, Pierre Van Glabeke and contributors', - '2.1', + '2.2', [ - 'requires' => [['core', '2.26']], + 'requires' => [['core', '2.27']], 'permissions' => dcCore::app()->auth->makePermissions([ dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, ]), diff --git a/dcstore.xml b/dcstore.xml index 8be627f..eef4130 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,11 +2,11 @@ Arlequin - 2.1 + 2.2 Oleksandr Syenchuk, Pierre Van Glabeke and contributors Allows visitors choose a theme - https://github.com/JcDenis/arlequin/releases/download/v2.1/plugin-arlequin.zip - 2.26 + https://github.com/JcDenis/arlequin/releases/download/v2.2/plugin-arlequin.zip + 2.27 https://plugins.dotaddict.org/dc2/details/arlequin http://forum.dotclear.org/viewtopic.php?id=48345 diff --git a/src/Backend.php b/src/Backend.php index 9d57a5d..de1e51a 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -14,61 +14,35 @@ declare(strict_types=1); namespace Dotclear\Plugin\arlequin; -use dcAdmin; use dcCore; -use dcFavorites; -use dcNsProcess; -use dcPage; +use Dotclear\Core\Process; +use Dotclear\Core\Backend\{ + Favorites, + Menus +}; -class Backend extends dcNsProcess +class Backend extends Process { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') - && !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog) // nullsafe PHP < 8.0 - && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, - ]), dcCore::app()->blog->id); - - return static::$init; + return self::status(My::checkContext(My::BACKEND)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } - // nullsafe PHP < 8.0 - if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { - return false; - } - - dcCore::app()->menu[dcAdmin::MENU_BLOG]->addItem( - My::name(), - dcCore::app()->adminurl->get('admin.plugin.' . My::id()), - [dcPage::getPF(My::id() . '/icon.svg'), dcPage::getPF(My::id() . '/icon-dark.svg')], - preg_match( - '/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', - $_SERVER['REQUEST_URI'] - ), - dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, - ]), dcCore::app()->blog->id) - ); + My::addBackendMenuItem(Menus::MENU_BLOG); dcCore::app()->addBehaviors([ - 'adminDashboardFavoritesV2' => function (dcFavorites $favs): void { - // nullsafe PHP < 8.0 - if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->adminurl)) { - return; - } - + 'adminDashboardFavoritesV2' => function (Favorites $favs): void { $favs->register(My::id(), [ 'title' => My::name(), - 'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()), - 'small-icon' => [dcPage::getPF(My::id() . '/icon.svg'), dcPage::getPF(My::id() . '/icon-dark.svg')], - 'large-icon' => [dcPage::getPF(My::id() . '/icon.svg'), dcPage::getPF(My::id() . '/icon-dark.svg')], + 'url' => My::manageUrl(), + 'small-icon' => My::icons(), + 'large-icon' => My::icons(), 'permissions' => dcCore::app()->auth->makePermissions([ dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, ]), diff --git a/src/Frontend.php b/src/Frontend.php index acf6c06..d1e5e8a 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -15,24 +15,22 @@ declare(strict_types=1); namespace Dotclear\Plugin\arlequin; use dcCore; -use dcNsProcess; +use Dotclear\Core\Process; use Dotclear\Helper\Network\Http; -class Frontend extends dcNsProcess +class Frontend extends Process { public const COOKIE_THEME_PREFIX = 'dc_theme_'; public const COOKIE_UPDDT_PREFIX = 'dc_user_upddt_'; public static function init(): bool { - static::$init = defined('DC_RC_PATH'); - - return static::$init; + return self::status(My::checkContext(My::FRONTEND)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } @@ -62,11 +60,6 @@ class Frontend extends dcNsProcess protected static function cookieSuffix(): string { - // nullsafe PHP < 8.0 - if (is_null(dcCore::app()->blog)) { - return ''; - } - return base_convert(dcCore::app()->blog->uid, 16, 36); } @@ -79,13 +72,8 @@ class Frontend extends dcNsProcess public static function switchTheme(string $theme): void { - // nullsafe PHP < 8.0 - if (is_null(dcCore::app()->blog)) { - return; - } - - if (dcCore::app()->blog->settings->get(My::id())->get('mt_exclude')) { - if (in_array($theme, explode('/', dcCore::app()->blog->settings->get(My::id())->get('mt_exclude')))) { + if (My::settings()->get('mt_exclude')) { + if (in_array($theme, explode('/', My::settings()->get('mt_exclude')))) { return; } } diff --git a/src/Manage.php b/src/Manage.php index ece65fa..c01cb46 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -16,8 +16,11 @@ namespace Dotclear\Plugin\arlequin; use ArrayObject; use dcCore; -use dcNsProcess; -use dcPage; +use Dotclear\Core\Process; +use Dotclear\Core\Backend\{ + Notices, + Page +}; use Dotclear\Helper\Html\Form\{ Div, Form, @@ -32,32 +35,21 @@ use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Html; use Exception; -class Manage extends dcNsProcess +class Manage extends Process { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') - && !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog) // nullsafe PHP < 8.0 - && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, - ]), dcCore::app()->blog->id); - - return static::$init; + return self::status(My::checkContext(My::MANAGE)); } public static function process(): bool { - if (!static::$init) { - return false; - } - - // nullsafe PHP < 8.0 - if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { + if (!self::status()) { return false; } try { - $s = dcCore::app()->blog->settings->get(My::id()); + $s = My::settings(); $model = json_decode((string) $s->get('model'), true); $exclude = $s->get('exclude'); @@ -69,7 +61,7 @@ class Manage extends dcNsProcess $s->put('model', json_encode($model), 'string', 'Arlequin configuration'); $s->put('exclude', 'customCSS', 'string', 'Excluded themes'); - dcPage::AddSuccessNotice(__('Settings have been reinitialized.')); + Notices::AddSuccessNotice(__('Settings have been reinitialized.')); dcCore::app()->blog->triggerBlog(); } @@ -86,9 +78,9 @@ class Manage extends dcNsProcess $s->put('model', json_encode($model)); $s->put('exclude', $exclude); - dcPage::AddSuccessNotice(__('System settings have been updated.')); + Notices::AddSuccessNotice(__('System settings have been updated.')); dcCore::app()->blog->triggerBlog(); - dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['config' => 1]); + My::redirect(['config' => 1]); } // restore settings @@ -96,9 +88,9 @@ class Manage extends dcNsProcess $s->drop('model'); $s->drop('exclude'); - dcPage::AddSuccessNotice(__('Settings have been reinitialized.')); + Notices::AddSuccessNotice(__('Settings have been reinitialized.')); dcCore::app()->blog->triggerBlog(); - dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['restore' => 1]); + My::redirect(['restore' => 1]); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); @@ -109,12 +101,7 @@ class Manage extends dcNsProcess public static function render(): void { - if (!static::$init) { - return; - } - - // nullsafe PHP < 8.0 - if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { + if (!self::status()) { return; } @@ -123,7 +110,7 @@ class Manage extends dcNsProcess dcCore::app()->callBehavior('arlequinAddModels', $models); $models = iterator_to_array($models); - $s = dcCore::app()->blog->settings->get(My::id()); + $s = My::settings(); $model = json_decode((string) $s->get('model'), true); $model = array_merge(My::defaultModel(), is_array($model) ? $model : []); $header = ''; @@ -139,9 +126,9 @@ class Manage extends dcNsProcess ");\n"; } - dcPage::openModule( + Page::openModule( My::name(), - dcPage::jsModuleLoad(My::id() . '/js/models.js') . ' + Page::jsLoad('models') . '