From 924b96126d665ef924676333183ed572af425fd4 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 30 Jul 2023 08:57:58 +0200 Subject: [PATCH] release 1.8 --- CHANGELOG.md | 5 ++++ README.md | 7 ++--- _define.php | 6 ++--- dcstore.xml | 6 ++--- locales/fr/main.po | 31 +++------------------ src/Backend.php | 37 +++++++------------------ src/Install.php | 10 +++---- src/Manage.php | 67 +++++++++++++++++++--------------------------- src/My.php | 32 ++++++---------------- src/Prepend.php | 12 ++++----- src/Uninstall.php | 10 +++---- 11 files changed, 77 insertions(+), 146 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 640fb5e..8a3891e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +1.8 - 2023.07.30 +- require Dotclear 2.27 +- require PHP 7.4+ +- update to Dotclear 2.27-dev + 1.7.1 - 2023.06.16 - require dotclear 2.26 - fix non php 7.4 type hint diff --git a/README.md b/README.md index c32f6b5..2212144 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Release](https://img.shields.io/github/v/release/JcDenis/alias)](https://github.com/JcDenis/alias/releases) [![Date](https://img.shields.io/github/release-date/JcDenis/alias)](https://github.com/JcDenis/alias/releases) [![Issues](https://img.shields.io/github/issues/JcDenis/alias)](https://github.com/JcDenis/alias/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/alias) [![License](https://img.shields.io/github/license/JcDenis/alias)](https://github.com/JcDenis/alias/blob/master/LICENSE) @@ -18,8 +18,9 @@ This plugin creates public aliases of your blog's URLs. _alias_ requires: - * admin permissions for management - * Dotclear 2.26 + * admin permissions for management + * Dotclear 2.27 + * PHP 7.4+ ## USAGE diff --git a/_define.php b/_define.php index 9b38308..62b6c4e 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 null; } @@ -18,9 +18,9 @@ $this->registerModule( 'alias', "Create aliases of your blog's URLs", 'Olivier Meunier and contributors', - '1.7.1', + '1.8', [ - 'requires' => [['core', '2.26']], + 'requires' => [['core', '2.27']], 'permissions' => dcCore::app()->auth->makePermissions([ dcCore::app()->auth::PERMISSION_ADMIN, ]), diff --git a/dcstore.xml b/dcstore.xml index c365cd5..22638dd 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,11 +2,11 @@ alias - 1.7.1 + 1.8 Olivier Meunier and contributors Create aliases of your blog's URLs - https://github.com/JcDenis/alias/releases/download/v1.7.1/plugin-alias.zip - 2.26 + https://github.com/JcDenis/alias/releases/download/v1.8/plugin-alias.zip + 2.27 https://plugins.dotaddict.org/dc2/details/alias https://github.com/JcDenis/alias diff --git a/locales/fr/main.po b/locales/fr/main.po index a206947..1df05eb 100644 --- a/locales/fr/main.po +++ b/locales/fr/main.po @@ -1,96 +1,71 @@ -# Language: Français -# Module: alias - 1.6 -# Date: 2023-04-30 22:52:13 -# Author: Jean-Christian Denis -# Translated with translater 2023.04.23 - msgid "" msgstr "" "Content-Type: text/plain; charset=UTF-8\n" -"Project-Id-Version: alias 1.6\n" +"Project-Id-Version: alias 1.7.1\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2023-04-30T22:52:13+00:00\n" -"Last-Translator: Jean-Christian Denis\n" +"PO-Revision-Date: 2023-07-29T12:49:07+00:00\n" +"Last-Translator: Jean-Christain Denis\n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" -#: src/Alias.php:75 msgid "Invalid aliases definitions" msgstr "Définitions d'alias invalides" -#: src/Alias.php:116 msgid "Alias URL is empty." msgstr "L'URL de l'alias est vide." -#: src/Alias.php:119 msgid "Alias destination is empty." msgstr "La destination de l'alias est vide." -#: src/Manage.php:74 msgid "Aliases successfully updated." msgstr "Alias mis à jour avec succès." -#: src/Manage.php:85 msgid "Alias successfully created." msgstr "Alias créer avec succès." -#: src/Manage.php:116 msgid "New alias" msgstr "Nouvel alias" -#: src/Manage.php:124 msgid "Alias URL:" msgstr "URL de l'alias :" -#: src/Manage.php:128 msgid "Alias destination:" msgstr "Destination de l'alias :" -#: src/Manage.php:131 msgid "Do not put blog URL \"%s\" in fields." msgstr "Ne pas mettre l'URL du blog \"%s\" dans les champs." -#: src/Manage.php:134 msgid "Do visible redirection to destination" msgstr "Faire une redirection visible vers la destination" -#: src/Manage.php:155 msgid "No alias" msgstr "Aucun alias" -#: src/Manage.php:159 msgid "There is %s alias." msgid_plural "There are %s aliases." msgstr[0] "Il y a %s alias." msgstr[1] "Il y a %s alias." -#: src/Manage.php:162 msgid "Aliases list" msgstr "Liste des alias" -#: src/Manage.php:165 msgid "Alias URL" msgstr "URL de l'alias" -#: src/Manage.php:166 msgid "Alias destination" msgstr "Destination de l'alias" -#: src/Manage.php:167 msgid "Alias position" msgstr "Position de l'alias" -#: src/Manage.php:168 msgid "Redrection" msgstr "Redirection" -#: src/Manage.php:182 msgid "visible redirection to %s" msgstr "Redirection visible vers %s" -#: src/Manage.php:188 msgid "To remove an alias, empty its URL or destination." msgstr "Pour supprimer un alias, videz son URL ou sa destination." diff --git a/src/Backend.php b/src/Backend.php index 976a099..5d9864c 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -14,45 +14,28 @@ declare(strict_types=1); namespace Dotclear\Plugin\alias; -use dcAdmin; use dcCore; -use dcNsProcess; -use dcPage; -use Dotclear\Plugin\importExport\FlatBackupItem; -use Dotclear\Plugin\importExport\FlatExport; -use Dotclear\Plugin\importExport\FlatImportV2; +use Dotclear\Core\Process; +use Dotclear\Plugin\importExport\{ + FlatBackupItem, + FlatExport, + FlatImportV2 +}; -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_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_PLUGINS]->addItem( - My::name(), - dcCore::app()->adminurl->get('admin.plugin.' . My::id()), - dcPage::getPF(My::id() . '/icon.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_ADMIN]), dcCore::app()->blog->id) - ); + My::addBackendMenuItem(); dcCore::app()->addBehaviors([ 'exportFullV2' => function (FlatExport $exp): void { diff --git a/src/Install.php b/src/Install.php index f1dc39c..01b3441 100644 --- a/src/Install.php +++ b/src/Install.php @@ -15,22 +15,20 @@ declare(strict_types=1); namespace Dotclear\Plugin\alias; use dcCore; -use dcNsProcess; +use Dotclear\Core\Process; use Dotclear\Database\Structure; use Exception; -class Install extends dcNsProcess +class Install extends Process { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version')); - - return static::$init; + return self::status(My::checkContext(My::INSTALL)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } diff --git a/src/Manage.php b/src/Manage.php index 454dbbf..6a7b077 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -15,8 +15,11 @@ declare(strict_types=1); namespace Dotclear\Plugin\alias; use dcCore; -use dcNsProcess; -use dcPage; +use Dotclear\Core\Process; +use Dotclear\Core\Backend\{ + Notices, + Page +}; use Dotclear\Helper\Html\Form\{ Checkbox, Div, @@ -36,27 +39,16 @@ use Exception; /** * Manage contributions list */ -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_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; } @@ -71,8 +63,8 @@ class Manage extends dcNsProcess if (isset($_POST['a']) && is_array($_POST['a'])) { try { $alias->updateAliases($_POST['a']); - dcPage::addSuccessNotice(__('Aliases successfully updated.')); - dcCore::app()->adminurl->redirect('admin.plugin.' . My::id()); + Notices::addSuccessNotice(__('Aliases successfully updated.')); + My::redirect(); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } @@ -82,8 +74,8 @@ class Manage extends dcNsProcess if (isset($_POST['alias_url'])) { try { $alias->createAlias($_POST['alias_url'], $_POST['alias_destination'], count($aliases) + 1, !empty($_POST['alias_redirect'])); - dcPage::addSuccessNotice(__('Alias successfully created.')); - dcCore::app()->adminurl->redirect('admin.plugin.' . My::id()); + Notices::addSuccessNotice(__('Alias successfully created.')); + My::redirect(); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } @@ -94,28 +86,23 @@ 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; } $alias = new Alias(); $aliases = $alias->getAliases(); - dcPage::openModule(My::name()); + Page::openModule(My::name()); if (($_REQUEST['part'] ?? 'list') == 'new') { echo - dcPage::breadcrumb([ + Page::breadcrumb([ __('Plugins') => '', - My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'list']), + My::name() => My::manageUrl(['part' => 'list']), __('New alias') => '', ]) . - dcPage::notices() . + Notices::getNotices() . (new Div())->items([ (new Text('h3', __('New alias'))), @@ -134,21 +121,22 @@ class Manage extends dcNsProcess (new Label(__('Do visible redirection to destination'), Label::OUTSIDE_LABEL_AFTER))->for('alias_redirect')->class('classic'), ]), (new Para())->items([ - dcCore::app()->formNonce(false), - (new Hidden('part', 'new')), (new Submit(['do']))->value(__('Save')), + ... My::hiddenFields([ + 'part' => 'new', + ]), ]), ]), ])->render(); } else { echo - dcPage::breadcrumb([ + Page::breadcrumb([ __('Plugins') => '', My::name() => '', ]) . - dcPage::notices() . + Notices::getNotices() . '

' . __('New alias') . '

'; if (empty($aliases)) { @@ -187,15 +175,16 @@ class Manage extends dcNsProcess '' . '

' . __('To remove an alias, empty its URL or destination.') . '

' . (new Para())->items([ - dcCore::app()->formNonce(false), - (new Hidden('part', 'list')), (new Submit(['upd']))->value(__('Update')), + ... My::hiddenFields([ + 'part' => 'list', + ]), ])->render() . ''; } } - dcPage::helpBlock('alias'); - dcPage::closeModule(); + Page::helpBlock('alias'); + Page::closeModule(); } } diff --git a/src/My.php b/src/My.php index 43d7ac6..63d4385 100644 --- a/src/My.php +++ b/src/My.php @@ -15,38 +15,22 @@ declare(strict_types=1); namespace Dotclear\Plugin\alias; use dcCore; +use Dotclear\Module\MyPlugin; /** * This module definitions. */ -class My +class My extends MyPlugin { /** @var string Plugin table name */ public const ALIAS_TABLE_NAME = 'alias'; - /** - * This module id. - */ - public static function id(): string + public static function checkCustomContext(int $context): ?bool { - return basename(dirname(__DIR__)); - } - - /** - * This module name. - */ - public static function name(): string - { - $name = dcCore::app()->plugins->moduleInfo(self::id(), 'name'); - - return __(is_string($name) ? $name : self::id()); - } - - /** - * This module path. - */ - public static function path(): string - { - return dirname(__DIR__); + return !in_array($context, [My::BACKEND, My::MANAGE, My::MENU]) ? null : + defined('DC_CONTEXT_ADMIN') + && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ + dcCore::app()->auth::PERMISSION_ADMIN, + ]), dcCore::app()->blog->id); } } diff --git a/src/Prepend.php b/src/Prepend.php index 1d1eedb..be5810f 100644 --- a/src/Prepend.php +++ b/src/Prepend.php @@ -15,22 +15,20 @@ declare(strict_types=1); namespace Dotclear\Plugin\alias; use dcCore; -use dcNsProcess; use dcUrlHandlers; +use Dotclear\Core\Process; use Dotclear\Helper\Network\Http; -class Prepend extends dcNsProcess +class Prepend extends Process { public static function init(): bool { - static::$init = defined('DC_RC_PATH'); - - return static::$init; + return self::status(My::checkContext(My::PREPEND)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } @@ -64,7 +62,7 @@ class Prepend extends dcNsProcess } // Use visible redirection - if ($redir && !is_null(dcCore::app()->blog)) { + if ($redir) { Http::redirect(dcCore::app()->blog->url . $part); } diff --git a/src/Uninstall.php b/src/Uninstall.php index faf04f6..7fd2a23 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -15,21 +15,19 @@ declare(strict_types=1); namespace Dotclear\Plugin\alias; use dcCore; -use dcNsProcess; +use Dotclear\Core\Process; use Dotclear\Plugin\Uninstaller\Uninstaller; -class Uninstall extends dcNsProcess +class Uninstall extends Process { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN'); - - return static::$init; + return self::status(My::checkContext(My::UNINSTALL)); } public static function process(): bool { - if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) { + if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) { return false; }