From fd582fa42c1a176b2a60e75d45d57def3e00f04a Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Fri, 28 Jul 2023 23:39:25 +0200 Subject: [PATCH] release 1.5 --- CHANGELOG.md | 5 +++++ README.md | 4 ++-- _define.php | 4 ++-- dcstore.xml | 6 +++--- src/Backend.php | 41 ++++++++++++----------------------------- src/BackendList.php | 10 ++++++---- src/Manage.php | 43 +++++++++++++++++++++---------------------- src/ManageVars.php | 22 ++++++++++++---------- src/My.php | 31 ++++--------------------------- 9 files changed, 67 insertions(+), 99 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c86d9ab..5ca31da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +1.5 - 2023.07.28 +- require dotclear 2.27 +- require PHP 8.1+ +- update to dotclear 2.27-dev + 1.4 - 2023.05.13 - require dotclear 2.26 - require PHP 8.1+ diff --git a/README.md b/README.md index ac51625..9e6e368 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Release](https://img.shields.io/github/v/release/JcDenis/dcLog)](https://github.com/JcDenis/dcLog/releases) [![Date](https://img.shields.io/github/release-date/JcDenis/dcLog)](https://github.com/JcDenis/dcLog/releases) [![Issues](https://img.shields.io/github/issues/JcDenis/dcLog)](https://github.com/JcDenis/dcLog/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/dcLog) [![License](https://img.shields.io/github/license/JcDenis/dcLog)](https://github.com/JcDenis/dcLog/blob/master/LICENSE) @@ -19,7 +19,7 @@ Display dotclear's logs. _dcLog_ requires: * PHP 8.1+ - * Dotclear 2.26 + * Dotclear 2.27 * super admin permission ## USAGE diff --git a/_define.php b/_define.php index 5513bbb..a38a245 100644 --- a/_define.php +++ b/_define.php @@ -18,11 +18,11 @@ $this->registerModule( "Dotclear's logs", 'Displays Dotclear logs', 'Tomtom and Contributors', - '1.4', + '1.5', [ 'requires' => [ ['php', '8.1'], - ['core', '2.26'], + ['core', '2.27'], ], 'permissions' => null, 'type' => 'plugin', diff --git a/dcstore.xml b/dcstore.xml index 058e4d5..2a93cb4 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,11 +2,11 @@ Dotclear's logs - 1.4 + 1.5 Tomtom and Contributors Displays Dotclear logs - https://github.com/JcDenis/dcLog/releases/download/v1.4/plugin-dcLog.zip - 2.26 + https://github.com/JcDenis/dcLog/releases/download/v1.5/plugin-dcLog.zip + 2.27 https://plugins.dotaddict.org/dc2/details/dcLog https://github.com/JcDenis/dcLog diff --git a/src/Backend.php b/src/Backend.php index a5397b3..bfa537b 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -15,43 +15,26 @@ declare(strict_types=1); namespace Dotclear\Plugin\dcLog; use ArrayObject; -use dcAdmin; use dcCore; -use dcFavorites; -use dcMenu; -use dcNsProcess; -use dcPage; +use Dotclear\Core\Process; +use Dotclear\Core\Backend\Favorites; +use Dotclear\Core\Backend\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) - && dcCore::app()->auth->isSuperAdmin(); - - return static::$init; + return self::status(My::checkContext(My::BACKEND)); + ; } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } - // backend sidebar menu icon - if (!is_null(dcCore::app()->auth) - && !is_null(dcCore::app()->adminurl) - && (dcCore::app()->menu[dcAdmin::MENU_SYSTEM] instanceof dcMenu) - ) { - dcCore::app()->menu[dcAdmin::MENU_SYSTEM]->addItem( - My::name(), - dcCore::app()->adminurl->get('admin.plugin.' . My::id()), - dcPage::getPF(My::id() . '/icon.svg'), - preg_match('/' . preg_quote((string) dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']), - dcCore::app()->auth->isSuperAdmin() - ); - } + My::addBackendMenuItem(Menus::MENU_SYSTEM); dcCore::app()->addBehaviors([ // backend user preference for logs list columns @@ -86,12 +69,12 @@ class Backend extends dcNsProcess ]; }, // backend user preference for dashboard icon - 'adminDashboardFavoritesV2' => function (dcFavorites $favs): void { + 'adminDashboardFavoritesV2' => function (Favorites $favs): void { $favs->register(My::BACKEND_LIST_ID, [ 'title' => My::name(), - 'url' => dcCore::app()->adminurl?->get('admin.plugin.' . My::id()), - 'small-icon' => dcPage::getPF(My::id() . '/icon.svg'), - 'large-icon' => dcPage::getPF(My::id() . '/icon.svg'), + 'url' => My::manageUrl(), + 'small-icon' => My::icons(), + 'large-icon' => My::icons(), //'permissions' => null, ]); }, diff --git a/src/BackendList.php b/src/BackendList.php index 3fe91e8..06e013a 100644 --- a/src/BackendList.php +++ b/src/BackendList.php @@ -15,8 +15,10 @@ declare(strict_types=1); namespace Dotclear\Plugin\dcLog; use ArrayObject; -use adminGenericListV2; -use dcPager; +use Dotclear\Core\Backend\Listing\{ + Listing, + Pager +}; use Dotclear\Helper\Date; use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Form\{ @@ -30,7 +32,7 @@ use Dotclear\Helper\Html\Form\{ /** * Backend logs list helper. */ -class BackendList extends adminGenericListV2 +class BackendList extends Listing { /** * Display logs record. @@ -51,7 +53,7 @@ class BackendList extends adminGenericListV2 return; } - $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); + $pager = new Pager($page, $this->rs_count, $nb_per_page, 10); $cols = new ArrayObject([ 'date' => (new Text('th', __('Date'))) diff --git a/src/Manage.php b/src/Manage.php index 80eff3d..152ca50 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -15,8 +15,11 @@ declare(strict_types=1); namespace Dotclear\Plugin\dcLog; use dcCore; -use dcNsProcess; -use dcPage; +use Dotclear\Core\Process; +use Dotclear\Core\Backend\{ + Notices, + Page +}; use Dotclear\Helper\Html\Form\{ Div, Form, @@ -30,20 +33,16 @@ use Exception; /** * Manage logs 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) - && dcCore::app()->auth->isSuperAdmin(); - - return static::$init; + return self::status(My::checkContext(My::MANAGE)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } @@ -53,12 +52,12 @@ class Manage extends dcNsProcess if ($current->selected_logs && !empty($current->entries) || $current->all_logs) { try { dcCore::app()->log->delLogs($current->entries, $current->all_logs); - dcPage::addSuccessNotice( + Notices::addSuccessNotice( $current->all_logs ? __('All logs have been successfully deleted') : __('Selected logs have been successfully deleted') ); - dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id()); + My::redirect(); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } @@ -69,30 +68,30 @@ class Manage extends dcNsProcess public static function render(): void { - if (!static::$init) { + if (!self::status()) { return; } $current = ManageVars::init(); - dcPage::openModule( + Page::openModule( My::name(), - dcPage::jsJson('dcLog_msg', [ + Page::jsJson('dcLog_msg', [ 'confirm_delete_selected_log' => __('Are you sure you want to delete selected logs?'), 'confirm_delete_all_log' => __('Are you sure you want to delete all logs?'), ]) . - $current->filter->js((string) dcCore::app()->adminurl?->get('admin.plugin.' . My::id())) . - dcPage::jsLoad(dcPage::getPF(My::id() . '/js/backend.js')) + $current->filter->js((string) My::manageUrl()) . + My::jsLoad('backend') ); echo - dcPage::breadcrumb( + Page::breadcrumb( [ __('System') => '', - My::name() => dcCore::app()->adminurl?->get('admin.plugin.' . My::id()), + My::name() => My::manageUrl(), ] ) . - dcPage::notices(); + Notices::getNotices(); if ($current->logs !== null && $current->list != null) { if ($current->logs->isEmpty() && !$current->filter->show()) { @@ -109,7 +108,7 @@ class Manage extends dcNsProcess is_numeric($current->filter->__get('page')) ? (int) $current->filter->__get('page') : 1, is_numeric($current->filter->__get('nb')) ? (int) $current->filter->__get('nb') : 10, (new Form('dcLog_form')) - ->action(dcCore::app()->adminurl?->get('admin.plugin.' . My::id())) + ->action(My::manageUrl()) ->method('post') ->fields([ (new Text('', '%s')), @@ -131,7 +130,7 @@ class Manage extends dcNsProcess ]), (new Text( '', - dcCore::app()->adminurl?->getHiddenFormFields('admin.plugin.' . My::id(), $current->filter->values()) . + dcCore::app()->admin->url->getHiddenFormFields('admin.plugin.' . My::id(), $current->filter->values()) . dcCore::app()->formNonce() )), ]), @@ -141,6 +140,6 @@ class Manage extends dcNsProcess } } - dcPage::closeModule(); + Page::closeModule(); } } diff --git a/src/ManageVars.php b/src/ManageVars.php index 329702e..35285ea 100644 --- a/src/ManageVars.php +++ b/src/ManageVars.php @@ -14,9 +14,11 @@ declare(strict_types=1); namespace Dotclear\Plugin\dcLog; -use adminGenericFilterV2; -use dcAdminFilters; use dcCore; +use Dotclear\Core\Backend\Filter\{ + Filters, + FiltersLibrary +}; use Dotclear\Database\MetaRecord; use Exception; @@ -28,8 +30,8 @@ class ManageVars /** @var ManageVars $container self instance */ private static $container; - /** @var adminGenericFilterV2 $filter The filter instance */ - public readonly adminGenericFilterV2 $filter; + /** @var Filters $filter The filter instance */ + public readonly Filters $filter; /** @var null|MetaRecord $logs The current records */ public readonly ?MetaRecord $logs; @@ -55,12 +57,12 @@ class ManageVars $this->all_logs = isset($_POST['all_logs']); $this->selected_logs = isset($_POST['selected_logs']); - $this->filter = new adminGenericFilterV2('dcloglist'); - $this->filter->add(dcAdminFilters::getPageFilter()); - $this->filter->add(dcAdminFilters::getInputFilter('blog_id', __('Blog:'))); - $this->filter->add(dcAdminFilters::getInputFilter('user_id', __('User:'))); - $this->filter->add(dcAdminFilters::getInputFilter('log_table', __('Component:'))); - $this->filter->add(dcAdminFilters::getInputFilter('log_ip', __('IP:'))); + $this->filter = new Filters('dcloglist'); + $this->filter->add(FiltersLibrary::getPageFilter()); + $this->filter->add(FiltersLibrary::getInputFilter('blog_id', __('Blog:'))); + $this->filter->add(FiltersLibrary::getInputFilter('user_id', __('User:'))); + $this->filter->add(FiltersLibrary::getInputFilter('log_table', __('Component:'))); + $this->filter->add(FiltersLibrary::getInputFilter('log_ip', __('IP:'))); $params = $this->filter->params(); try { diff --git a/src/My.php b/src/My.php index b880782..5366d34 100644 --- a/src/My.php +++ b/src/My.php @@ -15,38 +15,15 @@ declare(strict_types=1); namespace Dotclear\Plugin\dcLog; use dcCore; +use Dotclear\Module\MyPlugin; -/** - * This module definition. - */ -class My +class My extends MyPlugin { /** @var string Admin list ID */ public const BACKEND_LIST_ID = 'dcloglist'; - /** - * 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 dcCore::app()->auth->isSuperAdmin(); } }