diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d2654f..ad2577a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +postExpired 2023.10.19 +=========================================================== +* Require Dotclear 2.28 +* Require PHP 8.1 +* Upgrade to Dotclear 2.28 + postExpired 2023.08.13 =========================================================== * Require Dotclear 2.27 diff --git a/README.md b/README.md index 2135dcc..0273361 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,23 @@ # README [![Release](https://img.shields.io/badge/release-2023.08.13-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/postExpired/releases) -[![Date](https://img.shields.io/badge/date-2023.08.13-c44d58.svg)](https://git.dotclear.watch/JcDenis/postExpired/releases) +![Date](https://img.shields.io/badge/date-2023.08.13-c44d58.svg) [![Dotclear](https://img.shields.io/badge/dotclear-v2.27-137bbb.svg)](https://fr.dotclear.org/download) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/postExpired) -[![License](https://img.shields.io/github/license/JcDenis/postExpired)](https://git.dotclear.watch/JcDenis/postExpired/blob/master/LICENSE) +[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/postExpired/src/branch/master/LICENSE) -## WHAT IS POSTEXPIRED ? +## ABOUT -Post expired is a plugin for the open-source -web publishing software called Dotclear. +_postExpired_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org). -It add options to the sidebar of post edition page +> Add options to the sidebar of post edition page to change some options of a post at a given time. ## REQUIREMENTS -_postExpired_ requires: - -* contentadmin permissions -* Dotclear 2.27 -* PHP 7.4+ +* Dotclear 2.28 +* PHP 8.1+ +* Dotclear contentadmin permissions ## USAGE @@ -39,13 +36,14 @@ Notes: ## LINKS -* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html) -* Source & contribution : [Gitea Page](https://git.dotclear.watch/JcDenis/postExpired) or [GitHub Page](https://github.com/JcDenis/postExpired) -* Packages & details: [Gitea Page](https://git.dotclear.watch/JcDenis/postExpired/releases) or [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/postExpired) -* Discuss & help : [Dotclear Forum](https://forum.dotclear.org/viewtopic.php?id=42305) +* [License](https://git.dotclear.watch/JcDenis/postExpired/src/branch/master/LICENSE) +* [Packages & details](https://git.dotclear.watch/JcDenis/postExpired/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/postExpired)) +* [Sources & contributions](https://git.dotclear.watch/JcDenis/postExpired) (or on [GitHub](https://github.com/JcDenis/postExpired)) +* [Issues & security](https://git.dotclear.watch/JcDenis/postExpired/issues) (or on [GitHub](https://github.com/JcDenis/postExpired/issues)) +* [Discuss & help](https://forum.dotclear.org/viewtopic.php?id=42305) ## CONTRIBUTORS -* Jean-Christian Denis +* Jean-Christian Denis (author) You are welcome to contribute to this code. diff --git a/_define.php b/_define.php index 53a2480..d102ca7 100644 --- a/_define.php +++ b/_define.php @@ -1,33 +1,30 @@ registerModule( 'Expired entries', 'Change entries options at a given date', 'Jean-Christian Denis and Contributors', - '2023.08.13', + '2023.10.19', [ - 'requires' => [['core', '2.27']], - 'permissions' => dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_USAGE, - dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, - ]), - 'type' => 'plugin', - 'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues', - 'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md', - 'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml', + 'requires' => [['core', '2.28']], + 'permissions' => 'My', + 'type' => 'plugin', + 'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues', + 'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md', + 'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml', ] ); diff --git a/dcstore.xml b/dcstore.xml index 93e7ca2..e2ba0fc 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,11 +2,11 @@ Expired entries - 2023.08.13 + 2023.10.19 Jean-Christian Denis and Contributors Change entries options at a given date - https://git.dotclear.watch/JcDenis/postExpired/releases/download/v2023.08.13/plugin-postExpired.zip - 2.27 + https://git.dotclear.watch/JcDenis/postExpired/releases/download/v2023.10.19/plugin-postExpired.zip + 2.28 https://git.dotclear.watch/JcDenis/postExpired/src/branch/master/README.md https://git.dotclear.watch/JcDenis/postExpired/issues diff --git a/src/Backend.php b/src/Backend.php index 952b6ac..b96e5c3 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -1,22 +1,19 @@ addBehaviors([ - 'adminPostsActions' => [BackendBehaviors::class, 'adminPostsActions'], - 'adminPagesActions' => [BackendBehaviors::class, 'adminPostsActions'], - 'adminPostHeaders' => [BackendBehaviors::class, 'adminPostHeaders'], - 'adminPageHeaders' => [BackendBehaviors::class, 'adminPostHeaders'], - 'adminPostFormItems' => [BackendBehaviors::class, 'adminPostFormItems'], - 'adminPageFormItems' => [BackendBehaviors::class, 'adminPostFormItems'], - 'adminBeforePostDelete' => [BackendBehaviors::class, 'adminBeforePostDelete'], - 'adminBeforePageDelete' => [BackendBehaviors::class, 'adminBeforePostDelete'], - 'adminAfterPostUpdate' => [BackendBehaviors::class, 'adminAfterPostSave'], - 'adminAfterPageUpdate' => [BackendBehaviors::class, 'adminAfterPostSave'], - 'adminAfterPostCreate' => [BackendBehaviors::class, 'adminAfterPostSave'], - 'adminAfterPageCreate' => [BackendBehaviors::class, 'adminAfterPostSave'], + App::behavior()->addBehaviors([ + 'adminPostsActions' => BackendBehaviors::adminPostsActions(...), + 'adminPagesActions' => BackendBehaviors::adminPostsActions(...), + 'adminPostHeaders' => BackendBehaviors::adminPostHeaders(...), + 'adminPageHeaders' => BackendBehaviors::adminPostHeaders(...), + 'adminPostFormItems' => BackendBehaviors::adminPostFormItems(...), + 'adminPageFormItems' => BackendBehaviors::adminPostFormItems(...), + 'adminBeforePostDelete' => BackendBehaviors::adminBeforePostDelete(...), + 'adminBeforePageDelete' => BackendBehaviors::adminBeforePostDelete(...), + 'adminAfterPostUpdate' => BackendBehaviors::adminAfterPostSave(...), + 'adminAfterPageUpdate' => BackendBehaviors::adminAfterPostSave(...), + 'adminAfterPostCreate' => BackendBehaviors::adminAfterPostSave(...), + 'adminAfterPageCreate' => BackendBehaviors::adminAfterPostSave(...), ]); return true; diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index 5be5df0..ed1b116 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -1,22 +1,12 @@ 'post_expired_add', ], ], - [self::class, 'callbackAdd'] + self::callbackAdd(...) ); $pa->addAction( @@ -72,7 +64,7 @@ class BackendBehaviors __('Remove expired date') => 'post_expired_remove', ], ], - [self::class, 'callbackRemove'] + self::callbackRemove(...) ); } @@ -183,9 +175,9 @@ class BackendBehaviors $pa->beginPage( Page::breadcrumb([ - Html::escapeHTML(dcCore::app()->blog->name) => '', - $pa->getCallerTitle() => $pa->getRedirection(true), - __('Add expired date to this selection') => '', + Html::escapeHTML(App::blog()->name()) => '', + $pa->getCallerTitle() => $pa->getRedirection(true), + __('Add expired date to this selection') => '', ]), //Page::jsDatePicker() . self::adminPostHeaders() @@ -197,7 +189,7 @@ class BackendBehaviors (new Para())->items([ ... self::fieldsPostExpired($posts->f('post_type'), null, false), ... $pa->hiddenFields(), - dcCore::app()->formNonce(false), + App::nonce()->formNonce(), (new Hidden(['action'], 'post_expired_add')), (new Submit(['do']))->value(__('Save')), ]), @@ -237,7 +229,7 @@ class BackendBehaviors */ private static function delPostExpired(int $post_id): void { - dcCore::app()->meta->delPostMeta($post_id, My::META_TYPE); + App::meta()->delPostMeta($post_id, My::META_TYPE); } /** @@ -281,7 +273,7 @@ class BackendBehaviors $post_expired['newpassword'] = (string) $post['post_expired_newpassword']; } - dcCore::app()->meta->setPostMeta( + App::meta()->setPostMeta( $post_id, My::META_TYPE, My::encode($post_expired) @@ -301,7 +293,7 @@ class BackendBehaviors $fields = $post_expired = []; if ($post_id) { - $rs = dcCore::app()->meta->getMetadata([ + $rs = App::meta()->getMetadata([ 'meta_type' => My::META_TYPE, 'post_id' => $post_id, 'limit' => 1, @@ -328,7 +320,7 @@ class BackendBehaviors $fields['post_expired_category'] = (new Para())->items([ (new Label(__('Category:'), Label::OUTSIDE_LABEL_BEFORE))->for('post_expired_category'), (new Select('post_expired_category'))->default(empty($post_expired['category']) ? '' : $post_expired['category'])->items(self::categoriesCombo( - dcCore::app()->blog->getCategories( + App::blog()->getCategories( ['post_type' => 'post'] ) )), @@ -383,7 +375,7 @@ class BackendBehaviors ]; try { - $categories = dcCore::app()->blog->getCategories( + $categories = App::blog()->getCategories( ['post_type' => 'post'] ); while ($categories->fetch()) { @@ -465,7 +457,7 @@ class BackendBehaviors */ private static function dateFromUser(string $date): string { - $u = !isset(dcCore::app()->auth) ? 'UTC' : dcCore::app()->auth->getInfo('user_tz'); + $u = App::auth()->getInfo('user_tz') ?? 'UTC'; $d = date_create($date, new DateTimeZone($u)); return $d ? date_format($d->setTimezone(new DateTimeZone('UTC')), 'Y-m-d H:i:00') : ''; @@ -480,7 +472,7 @@ class BackendBehaviors */ private static function dateToUser(string $date): string { - $u = !isset(dcCore::app()->auth) ? 'UTC' : dcCore::app()->auth->getInfo('user_tz'); + $u = App::auth()->getInfo('user_tz') ?? 'UTC'; $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 fa9d03e..abed575 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -1,22 +1,19 @@ url->type, ['default', 'feed'])) { - dcCore::app()->addBehavior( + if (in_array(App::url()->type, ['default', 'feed'])) { + App::behavior()->addBehavior( 'publicBeforeDocumentV2', - [FrontendBehaviors::class, 'publicBeforeDocumentV2'] + FrontendBehaviors::publicBeforeDocumentV2(...) ); } - dcCore::app()->addBehavior( + App::behavior()->addBehavior( 'coreBlogGetPosts', - [FrontendBehaviors::class, 'coreBlogGetPosts'] + FrontendBehaviors::coreBlogGetPosts(...) ); - dcCore::app()->tpl->addBlock( + App::frontend()->template()->addBlock( 'EntryExpiredIf', - [FrontendTemplate::class, 'EntryExpiredIf'] + FrontendTemplate::EntryExpiredIf(...) ); - dcCore::app()->tpl->addValue( + App::frontend()->template()->addValue( 'EntryExpiredDate', - [FrontendTemplate::class, 'EntryExpiredDate'] + FrontendTemplate::EntryExpiredDate(...) ); - dcCore::app()->tpl->addValue( + App::frontend()->template()->addValue( 'EntryExpiredTime', - [FrontendTemplate::class, 'EntryExpiredTime'] + FrontendTemplate::EntryExpiredTime(...) ); return true; diff --git a/src/FrontendBehaviors.php b/src/FrontendBehaviors.php index 419fcd9..d1e472b 100644 --- a/src/FrontendBehaviors.php +++ b/src/FrontendBehaviors.php @@ -1,23 +1,11 @@ from($sql->as(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME, 'P')) + $posts = $sql->from($sql->as(App::con()->prefix() . App::blog()::POST_TABLE_NAME, 'P')) ->columns([ 'P.post_id', 'P.post_tz', @@ -47,11 +37,11 @@ class FrontendBehaviors ->join( (new JoinStatement()) ->inner() - ->from($sql->as(dcCore::app()->prefix . dcMeta::META_TABLE_NAME, 'META')) + ->from($sql->as(App::con()->prefix() . App::meta()::META_TABLE_NAME, 'META')) ->on('META.post_id = P.post_id') ->statement() ) - ->where('blog_id = ' . $sql->quote((string) dcCore::app()->blog->id)) + ->where('blog_id = ' . $sql->quote(App::blog()->id())) ->and('META.meta_type = ' . $sql->quote(My::META_TYPE)) ->select(); @@ -65,7 +55,7 @@ class FrontendBehaviors $now_tz = (int) date_format(date_create('now', $utc), 'U'); // Prepared post Cursor - $post_cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME); + $post_cur = App::blog()->openPostCursor(); // Loop through marked posts $updated = false; @@ -79,8 +69,8 @@ class FrontendBehaviors if ($now_tz > $meta_tz) { // Delete meta for expired date - dcCore::app()->auth->sudo( - [dcCore::app()->meta, 'delPostMeta'], + App::auth()->sudo( + App::meta()->delPostMeta(...), $posts->f('post_id'), My::META_TYPE ); @@ -135,7 +125,7 @@ class FrontendBehaviors // Update post $post_cur->update( 'WHERE post_id = ' . $posts->f('post_id') . ' ' . - "AND blog_id = '" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog->id) . "' " + "AND blog_id = '" . App::con()->escapeStr(App::blog()->id()) . "' " ); $updated = true; @@ -144,7 +134,7 @@ class FrontendBehaviors // Say blog is updated if ($updated) { - dcCore::app()->blog->triggerBlog(); + App::blog()->triggerBlog(); } } @@ -155,6 +145,6 @@ class FrontendBehaviors */ public static function coreBlogGetPosts(MetaRecord $rs): void { - $rs->extend('rsExtPostExpired'); + $rs->extend(rsExtPostExpired::class); } } diff --git a/src/FrontendTemplate.php b/src/FrontendTemplate.php index f1abd77..ef52139 100644 --- a/src/FrontendTemplate.php +++ b/src/FrontendTemplate.php @@ -1,28 +1,19 @@ template()->getOperator($attr['operator']) : '&&'; if (isset($attr['has_date'])) { $sign = (bool) $attr['has_date'] ? '!' : '='; - $if[] = '(null ' . $sign . '== dcCore::app()->ctx->posts->postExpiredDate())'; + $if[] = '(null ' . $sign . '== App::frontend()->context()->posts->postExpiredDate())'; } else { - $if[] = '(null !== dcCore::app()->ctx->posts->postExpiredDate())'; + $if[] = '(null !== App::frontend()->context()->posts->postExpiredDate())'; } return @@ -64,19 +55,19 @@ class FrontendTemplate { $format = !empty($attr['format']) ? addslashes($attr['format']) : ''; - $f = dcCore::app()->tpl->getFilters($attr); + $f = App::frontend()->template()->getFilters($attr); if (!empty($attr['rfc822'])) { - $res = sprintf($f, Date::class . '::rfc822(strtotime(dcCore::app()->ctx->posts->postExpiredDate()),dcCore::app()->ctx->posts->post_tz)'); + $res = sprintf($f, Date::class . '::rfc822(strtotime(App::frontend()->context()->posts->postExpiredDate()),App::frontend()->context()->posts->post_tz)'); } elseif (!empty($attr['iso8601'])) { - $res = sprintf($f, Date::class . '::iso8601(strtotime(dcCore::app()->ctx->posts->postExpiredDate(),dcCore::app()->ctx->posts->post_tz)'); + $res = sprintf($f, Date::class . '::iso8601(strtotime(App::frontend()->context()->posts->postExpiredDate(),App::frontend()->context()->posts->post_tz)'); } elseif ($format) { - $res = sprintf($f, Date::class . "::dt2str('" . $format . "',dcCore::app()->ctx->posts->postExpiredDate())"); + $res = sprintf($f, Date::class . "::dt2str('" . $format . "',App::frontend()->context()->posts->postExpiredDate())"); } else { - $res = sprintf($f, Date::class . '::dt2str(dcCore::app()->blog->settings->system->date_format,dcCore::app()->ctx->posts->postExpiredDate())'); + $res = sprintf($f, Date::class . '::dt2str(App::blog()->settings()->system->date_format,App::frontend()->context()->posts->postExpiredDate())'); } - return 'ctx->posts->postExpiredDate()) { echo ' . $res . '; } ?>'; + return 'context()->posts->postExpiredDate()) { echo ' . $res . '; } ?>'; } /** @@ -89,13 +80,13 @@ class FrontendTemplate public static function EntryExpiredTime(ArrayObject $attr): string { return - 'ctx->posts->postExpiredDate()) { echo ' . sprintf( - dcCore::app()->tpl->getFilters($attr), + 'context()->posts->postExpiredDate()) { echo ' . sprintf( + App::frontend()->template()->getFilters($attr), Date::class . '::dt2str(' . ( !empty($attr['format']) ? - "'" . addslashes($attr['format']) . "'" : 'dcCore::app()->blog->settings->system->time_format' - ) . ',dcCore::app()->ctx->posts->postExpiredDate())' + "'" . addslashes($attr['format']) . "'" : 'App::blog()->settings()->system->time_format' + ) . ',App::frontend()->context()->posts->postExpiredDate())' ) . '; } ?>'; } } diff --git a/src/My.php b/src/My.php index cd28bdc..9329dc6 100644 --- a/src/My.php +++ b/src/My.php @@ -1,39 +1,23 @@ auth->check(dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, - ]), dcCore::app()->blog->id); - } - /** * Encode Expired Date settings. * @@ -71,4 +55,6 @@ class My extends MyPlugin return $out; } + + // Use default permissions } diff --git a/src/RsExtPostExpired.php b/src/RsExtPostExpired.php index b42a74c..abbd586 100644 --- a/src/RsExtPostExpired.php +++ b/src/RsExtPostExpired.php @@ -1,29 +1,21 @@ f('post_id')]) { - $rs_date = dcCore::app()->meta->getMetadata([ + $rs_date = App::meta()->getMetadata([ 'meta_type' => My::META_TYPE, 'post_id' => $rs->f('post_id'), 'limit' => 1,