From fb9958fdcc1d5eb50b3904f2ab07329f5b31943d Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 30 Jul 2023 22:12:02 +0200 Subject: [PATCH] release 2023.07.30 --- CHANGELOG.md | 5 +++ README.md | 7 +++-- _define.php | 6 ++-- dcstore.xml | 6 ++-- src/Backend.php | 18 +++-------- src/BackendBehaviors.php | 64 +++++++++++++++------------------------ src/Frontend.php | 12 +++----- src/FrontendBehaviors.php | 7 +---- src/FrontendTemplate.php | 11 ++++--- src/My.php | 32 +++++--------------- 10 files changed, 64 insertions(+), 104 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3eec0b5..1666080 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +2023.07.30 +- require Dotclear 2.27 +- require PHP 7.4+ +- update to Dotclear 2.27-dev + 2023.05.21 - require dotclear 2.26 - fix sidebar menu toggle diff --git a/README.md b/README.md index 8b1396e..ca82639 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Release](https://img.shields.io/github/v/release/JcDenis/postExpired)](https://github.com/JcDenis/postExpired/releases) [![Date](https://img.shields.io/github/release-date/JcDenis/postExpired)](https://github.com/JcDenis/postExpired/releases) [![Issues](https://img.shields.io/github/issues/JcDenis/postExpired)](https://github.com/JcDenis/postExpired/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/postExpired) [![License](https://img.shields.io/github/license/JcDenis/postExpired)](https://github.com/JcDenis/postExpired/blob/master/LICENSE) @@ -19,8 +19,9 @@ to change some options of a post at a given time. postExpired requires: - * contentadmin permissions - * Dotclear 2.26 + * contentadmin permissions + * Dotclear 2.27 + * PHP 7.4+ ## USAGE diff --git a/_define.php b/_define.php index 8efa6be..0ffcd67 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( 'Expired entries', 'Change entries options at a given date', 'Jean-Christian Denis and Contributors', - '2023.05.21', + '2023.07.30', [ - 'requires' => [['core', '2.26']], + 'requires' => [['core', '2.27']], 'permissions' => dcCore::app()->auth->makePermissions([ dcCore::app()->auth::PERMISSION_USAGE, dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, diff --git a/dcstore.xml b/dcstore.xml index 21de057..b946b7f 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,11 +2,11 @@ Expired entries - 2023.05.21 + 2023.07.30 Jean-Christian Denis and Contributors Change entries options at a given date - https://github.com/JcDenis/postExpired/releases/download/v2023.05.21/plugin-postExpired.zip - 2.26 + https://github.com/JcDenis/postExpired/releases/download/v2023.07.30/plugin-postExpired.zip + 2.27 https://plugins.dotaddict.org/dc2/details/postExpired https://github.com/JcDenis/postExpired diff --git a/src/Backend.php b/src/Backend.php index b25876e..952b6ac 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -15,28 +15,18 @@ declare(strict_types=1); namespace Dotclear\Plugin\postExpired; use dcCore; -use dcNsProcess; +use Dotclear\Core\Process; -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) - && 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; } diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index 1a16dc7..3eadf5b 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -17,8 +17,11 @@ namespace Dotclear\Plugin\postExpired; use ArrayObject; use DateTimeZone; use dcCore; -use dcPostsActions; -use dcPage; +use Dotclear\Core\Backend\Action\ActionsPosts; +use Dotclear\Core\Backend\{ + Notices, + Page +}; use Dotclear\Database\{ Cursor, MetaRecord @@ -50,9 +53,9 @@ class BackendBehaviors /** * Add actions to posts page combo. * - * @param dcPostsActions $pa dcPostsActions instance + * @param ActionsPosts $pa ActionsPosts instance */ - public static function adminPostsActions(dcPostsActions $pa): void + public static function adminPostsActions(ActionsPosts $pa): void { $pa->addAction( [ @@ -80,7 +83,7 @@ class BackendBehaviors */ public static function adminPostHeaders(): string { - return dcPage::jsModuleLoad(My::id() . '/js/backend.js'); + return My::jsLoad('backend'); } /** @@ -143,16 +146,11 @@ class BackendBehaviors /** * Posts actions callback to add expired date. * - * @param dcPostsActions $pa dcPostsActions instance + * @param ActionsPosts $pa ActionsPosts instance * @param ArrayObject $post _POST actions */ - public static function callbackAdd(dcPostsActions $pa, ArrayObject $post): void + public static function callbackAdd(ActionsPosts $pa, ArrayObject $post): void { - // nullsafe - if (is_null(dcCore::app()->blog)) { - return; - } - // No entry $posts_ids = $pa->getIDs(); if (empty($posts_ids)) { @@ -175,7 +173,7 @@ class BackendBehaviors self::setPostExpired($post_id, $post); } - dcPage::addSuccessNotice(__('Expired date added.')); + Notices::addSuccessNotice(__('Expired date added.')); $pa->redirect(true); // Display form @@ -184,27 +182,25 @@ class BackendBehaviors $posts = $pa->getRS(); $pa->beginPage( - dcPage::breadcrumb([ + Page::breadcrumb([ Html::escapeHTML(dcCore::app()->blog->name) => '', $pa->getCallerTitle() => $pa->getRedirection(true), __('Add expired date to this selection') => '', ]), - //dcPage::jsDatePicker() . + //Page::jsDatePicker() . self::adminPostHeaders() ); echo (new Form('peadd'))->method('post')->action($pa->getURI())->fields([ (new Text('', $pa->getCheckboxes())), - (new Para())->items(array_merge( - self::fieldsPostExpired($posts->f('post_type'), null, false), - $pa->hiddenFields(), - [ - dcCore::app()->formNonce(false), - (new Hidden(['action'], 'post_expired_add')), - (new Submit(['do']))->value(__('Save')), - ], - )), + (new Para())->items([ + ... self::fieldsPostExpired($posts->f('post_type'), null, false), + ... $pa->hiddenFields(), + dcCore::app()->formNonce(false), + (new Hidden(['action'], 'post_expired_add')), + (new Submit(['do']))->value(__('Save')), + ]), ])->render(); $pa->endPage(); @@ -214,10 +210,10 @@ class BackendBehaviors /** * Posts actions callback to add expired date. * - * @param dcPostsActions $pa dcPostsActions instance + * @param ActionsPosts $pa ActionsPosts instance * @param ArrayObject $post _POST actions */ - public static function callbackRemove(dcPostsActions $pa, ArrayObject $post): void + public static function callbackRemove(ActionsPosts $pa, ArrayObject $post): void { // No entry $posts_ids = $pa->getIDs(); @@ -230,7 +226,7 @@ class BackendBehaviors self::delPostExpired($post_id); } - dcPage::addSuccessNotice(__('Expired date deleted.')); + Notices::addSuccessNotice(__('Expired date deleted.')); $pa->redirect(true); } @@ -302,11 +298,6 @@ class BackendBehaviors */ private static function fieldsPostExpired(string $post_type, ?int $post_id = null, bool $render = true): array { - // nullsafe - if (is_null(dcCore::app()->blog)) { - return []; - } - $fields = $post_expired = []; if ($post_id) { @@ -385,11 +376,6 @@ class BackendBehaviors */ private static function categoriesCombo(MetaRecord $categories): array { - // nullsafe - if (is_null(dcCore::app()->blog)) { - return []; - } - // Getting categories $categories_combo = [ __('Not changed') => '', @@ -479,7 +465,7 @@ class BackendBehaviors */ private static function dateFromUser(string $date): string { - $u = is_null(dcCore::app()->auth) ? 'UTC' : dcCore::app()->auth->getInfo('user_tz'); + $u = !isset(dcCore::app()->auth) ? 'UTC' : dcCore::app()->auth->getInfo('user_tz'); $d = date_create($date, new DateTimeZone($u)); return $d ? date_format($d->setTimezone(new DateTimeZone('UTC')), 'Y-m-d H:i:00') : ''; @@ -494,7 +480,7 @@ class BackendBehaviors */ private static function dateToUser(string $date): string { - $u = is_null(dcCore::app()->auth) ? 'UTC' : dcCore::app()->auth->getInfo('user_tz'); + $u = !isset(dcCore::app()->auth) ? 'UTC' : dcCore::app()->auth->getInfo('user_tz'); $d = date_create($date, new DateTimeZone('UTC')); return $d ? date_format($d->setTimezone(new DateTimeZone($u)), 'Y-m-d\TH:i') : ''; diff --git a/src/Frontend.php b/src/Frontend.php index 53a7332..fa9d03e 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -15,20 +15,18 @@ declare(strict_types=1); namespace Dotclear\Plugin\postExpired; use dcCore; -use dcNsProcess; +use Dotclear\Core\Process; -class Frontend extends dcNsProcess +class Frontend extends Process { public static function init(): bool { - static::$init = true; - - return static::$init; + return self::status(My::checkContext(My::FRONTEND)); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } @@ -40,7 +38,7 @@ class Frontend extends dcNsProcess if (in_array(dcCore::app()->url->type, ['default', 'feed'])) { dcCore::app()->addBehavior( 'publicBeforeDocumentV2', - [FrontendBehaviors::class, 'publicBeforeDocument'] + [FrontendBehaviors::class, 'publicBeforeDocumentV2'] ); } dcCore::app()->addBehavior( diff --git a/src/FrontendBehaviors.php b/src/FrontendBehaviors.php index 45dcad7..419fcd9 100644 --- a/src/FrontendBehaviors.php +++ b/src/FrontendBehaviors.php @@ -34,13 +34,8 @@ class FrontendBehaviors /** * Check if there are expired dates. */ - public static function publicBeforeDocument(): void + public static function publicBeforeDocumentV2(): void { - // nullsafe - if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog)) { - return; - } - // Get expired dates and post_id $sql = new SelectStatement(); $posts = $sql->from($sql->as(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME, 'P')) diff --git a/src/FrontendTemplate.php b/src/FrontendTemplate.php index d90075b..f1abd77 100644 --- a/src/FrontendTemplate.php +++ b/src/FrontendTemplate.php @@ -17,6 +17,7 @@ namespace Dotclear\Plugin\postExpired; use ArrayObject; use dcCore; use dcTemplate; +use Dotclear\Helper\Date; /** * @ingroup DC_PLUGIN_POSTEXPIRED @@ -66,13 +67,13 @@ class FrontendTemplate $f = dcCore::app()->tpl->getFilters($attr); if (!empty($attr['rfc822'])) { - $res = sprintf($f, 'dt::rfc822(strtotime(dcCore::app()->ctx->posts->postExpiredDate()),dcCore::app()->ctx->posts->post_tz)'); + $res = sprintf($f, Date::class . '::rfc822(strtotime(dcCore::app()->ctx->posts->postExpiredDate()),dcCore::app()->ctx->posts->post_tz)'); } elseif (!empty($attr['iso8601'])) { - $res = sprintf($f, 'dt::iso8601(strtotime(dcCore::app()->ctx->posts->postExpiredDate(),dcCore::app()->ctx->posts->post_tz)'); + $res = sprintf($f, Date::class . '::iso8601(strtotime(dcCore::app()->ctx->posts->postExpiredDate(),dcCore::app()->ctx->posts->post_tz)'); } elseif ($format) { - $res = sprintf($f, "dt::dt2str('" . $format . "',dcCore::app()->ctx->posts->postExpiredDate())"); + $res = sprintf($f, Date::class . "::dt2str('" . $format . "',dcCore::app()->ctx->posts->postExpiredDate())"); } else { - $res = sprintf($f, 'dt::dt2str(dcCore::app()->blog->settings->system->date_format,dcCore::app()->ctx->posts->postExpiredDate())'); + $res = sprintf($f, Date::class . '::dt2str(dcCore::app()->blog->settings->system->date_format,dcCore::app()->ctx->posts->postExpiredDate())'); } return 'ctx->posts->postExpiredDate()) { echo ' . $res . '; } ?>'; @@ -90,7 +91,7 @@ class FrontendTemplate return 'ctx->posts->postExpiredDate()) { echo ' . sprintf( dcCore::app()->tpl->getFilters($attr), - 'dt::dt2str(' . + Date::class . '::dt2str(' . ( !empty($attr['format']) ? "'" . addslashes($attr['format']) . "'" : 'dcCore::app()->blog->settings->system->time_format' diff --git a/src/My.php b/src/My.php index da0c1f8..cd28bdc 100644 --- a/src/My.php +++ b/src/My.php @@ -15,39 +15,23 @@ declare(strict_types=1); namespace Dotclear\Plugin\postExpired; use dcCore; +use Dotclear\Module\MyPlugin; /** * This module definiton. */ -class My +class My extends MyPlugin { /** @var string This module meta type */ public const META_TYPE = 'post_expired'; - /** - * 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 $context !== My::BACKEND ? null : + defined('DC_CONTEXT_ADMIN') + && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ + dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, + ]), dcCore::app()->blog->id); } /**