release 2023.07.30

This commit is contained in:
Jean-Christian Paul Denis 2023-07-30 22:12:02 +02:00
parent 5618a4c803
commit fb9958fdcc
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
10 changed files with 64 additions and 104 deletions

View File

@ -1,3 +1,8 @@
2023.07.30
- require Dotclear 2.27
- require PHP 7.4+
- update to Dotclear 2.27-dev
2023.05.21 2023.05.21
- require dotclear 2.26 - require dotclear 2.26
- fix sidebar menu toggle - fix sidebar menu toggle

View File

@ -3,7 +3,7 @@
[![Release](https://img.shields.io/github/v/release/JcDenis/postExpired)](https://github.com/JcDenis/postExpired/releases) [![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) [![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) [![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) [![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) [![License](https://img.shields.io/github/license/JcDenis/postExpired)](https://github.com/JcDenis/postExpired/blob/master/LICENSE)
@ -20,7 +20,8 @@ to change some options of a post at a given time.
postExpired requires: postExpired requires:
* contentadmin permissions * contentadmin permissions
* Dotclear 2.26 * Dotclear 2.27
* PHP 7.4+
## USAGE ## USAGE

View File

@ -10,7 +10,7 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @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; return null;
} }
@ -18,9 +18,9 @@ $this->registerModule(
'Expired entries', 'Expired entries',
'Change entries options at a given date', 'Change entries options at a given date',
'Jean-Christian Denis and Contributors', 'Jean-Christian Denis and Contributors',
'2023.05.21', '2023.07.30',
[ [
'requires' => [['core', '2.26']], 'requires' => [['core', '2.27']],
'permissions' => dcCore::app()->auth->makePermissions([ 'permissions' => dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_USAGE, dcCore::app()->auth::PERMISSION_USAGE,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,

View File

@ -2,11 +2,11 @@
<modules xmlns:da="http://dotaddict.org/da/"> <modules xmlns:da="http://dotaddict.org/da/">
<module id="postExpired"> <module id="postExpired">
<name>Expired entries</name> <name>Expired entries</name>
<version>2023.05.21</version> <version>2023.07.30</version>
<author>Jean-Christian Denis and Contributors</author> <author>Jean-Christian Denis and Contributors</author>
<desc>Change entries options at a given date</desc> <desc>Change entries options at a given date</desc>
<file>https://github.com/JcDenis/postExpired/releases/download/v2023.05.21/plugin-postExpired.zip</file> <file>https://github.com/JcDenis/postExpired/releases/download/v2023.07.30/plugin-postExpired.zip</file>
<da:dcmin>2.26</da:dcmin> <da:dcmin>2.27</da:dcmin>
<da:details>https://plugins.dotaddict.org/dc2/details/postExpired</da:details> <da:details>https://plugins.dotaddict.org/dc2/details/postExpired</da:details>
<da:support>https://github.com/JcDenis/postExpired</da:support> <da:support>https://github.com/JcDenis/postExpired</da:support>
</module> </module>

View File

@ -15,28 +15,18 @@ declare(strict_types=1);
namespace Dotclear\Plugin\postExpired; namespace Dotclear\Plugin\postExpired;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
class Backend extends dcNsProcess class Backend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::BACKEND));
&& !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;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }

View File

@ -17,8 +17,11 @@ namespace Dotclear\Plugin\postExpired;
use ArrayObject; use ArrayObject;
use DateTimeZone; use DateTimeZone;
use dcCore; use dcCore;
use dcPostsActions; use Dotclear\Core\Backend\Action\ActionsPosts;
use dcPage; use Dotclear\Core\Backend\{
Notices,
Page
};
use Dotclear\Database\{ use Dotclear\Database\{
Cursor, Cursor,
MetaRecord MetaRecord
@ -50,9 +53,9 @@ class BackendBehaviors
/** /**
* Add actions to posts page combo. * 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( $pa->addAction(
[ [
@ -80,7 +83,7 @@ class BackendBehaviors
*/ */
public static function adminPostHeaders(): string 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. * Posts actions callback to add expired date.
* *
* @param dcPostsActions $pa dcPostsActions instance * @param ActionsPosts $pa ActionsPosts instance
* @param ArrayObject $post _POST actions * @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 // No entry
$posts_ids = $pa->getIDs(); $posts_ids = $pa->getIDs();
if (empty($posts_ids)) { if (empty($posts_ids)) {
@ -175,7 +173,7 @@ class BackendBehaviors
self::setPostExpired($post_id, $post); self::setPostExpired($post_id, $post);
} }
dcPage::addSuccessNotice(__('Expired date added.')); Notices::addSuccessNotice(__('Expired date added.'));
$pa->redirect(true); $pa->redirect(true);
// Display form // Display form
@ -184,27 +182,25 @@ class BackendBehaviors
$posts = $pa->getRS(); $posts = $pa->getRS();
$pa->beginPage( $pa->beginPage(
dcPage::breadcrumb([ Page::breadcrumb([
Html::escapeHTML(dcCore::app()->blog->name) => '', Html::escapeHTML(dcCore::app()->blog->name) => '',
$pa->getCallerTitle() => $pa->getRedirection(true), $pa->getCallerTitle() => $pa->getRedirection(true),
__('Add expired date to this selection') => '', __('Add expired date to this selection') => '',
]), ]),
//dcPage::jsDatePicker() . //Page::jsDatePicker() .
self::adminPostHeaders() self::adminPostHeaders()
); );
echo echo
(new Form('peadd'))->method('post')->action($pa->getURI())->fields([ (new Form('peadd'))->method('post')->action($pa->getURI())->fields([
(new Text('', $pa->getCheckboxes())), (new Text('', $pa->getCheckboxes())),
(new Para())->items(array_merge( (new Para())->items([
self::fieldsPostExpired($posts->f('post_type'), null, false), ... self::fieldsPostExpired($posts->f('post_type'), null, false),
$pa->hiddenFields(), ... $pa->hiddenFields(),
[
dcCore::app()->formNonce(false), dcCore::app()->formNonce(false),
(new Hidden(['action'], 'post_expired_add')), (new Hidden(['action'], 'post_expired_add')),
(new Submit(['do']))->value(__('Save')), (new Submit(['do']))->value(__('Save')),
], ]),
)),
])->render(); ])->render();
$pa->endPage(); $pa->endPage();
@ -214,10 +210,10 @@ class BackendBehaviors
/** /**
* Posts actions callback to add expired date. * Posts actions callback to add expired date.
* *
* @param dcPostsActions $pa dcPostsActions instance * @param ActionsPosts $pa ActionsPosts instance
* @param ArrayObject $post _POST actions * @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 // No entry
$posts_ids = $pa->getIDs(); $posts_ids = $pa->getIDs();
@ -230,7 +226,7 @@ class BackendBehaviors
self::delPostExpired($post_id); self::delPostExpired($post_id);
} }
dcPage::addSuccessNotice(__('Expired date deleted.')); Notices::addSuccessNotice(__('Expired date deleted.'));
$pa->redirect(true); $pa->redirect(true);
} }
@ -302,11 +298,6 @@ class BackendBehaviors
*/ */
private static function fieldsPostExpired(string $post_type, ?int $post_id = null, bool $render = true): array 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 = []; $fields = $post_expired = [];
if ($post_id) { if ($post_id) {
@ -385,11 +376,6 @@ class BackendBehaviors
*/ */
private static function categoriesCombo(MetaRecord $categories): array private static function categoriesCombo(MetaRecord $categories): array
{ {
// nullsafe
if (is_null(dcCore::app()->blog)) {
return [];
}
// Getting categories // Getting categories
$categories_combo = [ $categories_combo = [
__('Not changed') => '', __('Not changed') => '',
@ -479,7 +465,7 @@ class BackendBehaviors
*/ */
private static function dateFromUser(string $date): string 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)); $d = date_create($date, new DateTimeZone($u));
return $d ? date_format($d->setTimezone(new DateTimeZone('UTC')), 'Y-m-d H:i:00') : ''; 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 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')); $d = date_create($date, new DateTimeZone('UTC'));
return $d ? date_format($d->setTimezone(new DateTimeZone($u)), 'Y-m-d\TH:i') : ''; return $d ? date_format($d->setTimezone(new DateTimeZone($u)), 'Y-m-d\TH:i') : '';

View File

@ -15,20 +15,18 @@ declare(strict_types=1);
namespace Dotclear\Plugin\postExpired; namespace Dotclear\Plugin\postExpired;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
class Frontend extends dcNsProcess class Frontend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = true; return self::status(My::checkContext(My::FRONTEND));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }
@ -40,7 +38,7 @@ class Frontend extends dcNsProcess
if (in_array(dcCore::app()->url->type, ['default', 'feed'])) { if (in_array(dcCore::app()->url->type, ['default', 'feed'])) {
dcCore::app()->addBehavior( dcCore::app()->addBehavior(
'publicBeforeDocumentV2', 'publicBeforeDocumentV2',
[FrontendBehaviors::class, 'publicBeforeDocument'] [FrontendBehaviors::class, 'publicBeforeDocumentV2']
); );
} }
dcCore::app()->addBehavior( dcCore::app()->addBehavior(

View File

@ -34,13 +34,8 @@ class FrontendBehaviors
/** /**
* Check if there are expired dates. * 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 // Get expired dates and post_id
$sql = new SelectStatement(); $sql = new SelectStatement();
$posts = $sql->from($sql->as(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME, 'P')) $posts = $sql->from($sql->as(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME, 'P'))

View File

@ -17,6 +17,7 @@ namespace Dotclear\Plugin\postExpired;
use ArrayObject; use ArrayObject;
use dcCore; use dcCore;
use dcTemplate; use dcTemplate;
use Dotclear\Helper\Date;
/** /**
* @ingroup DC_PLUGIN_POSTEXPIRED * @ingroup DC_PLUGIN_POSTEXPIRED
@ -66,13 +67,13 @@ class FrontendTemplate
$f = dcCore::app()->tpl->getFilters($attr); $f = dcCore::app()->tpl->getFilters($attr);
if (!empty($attr['rfc822'])) { 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'])) { } 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) { } 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 { } 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 '<?php if (null !== dcCore::app()->ctx->posts->postExpiredDate()) { echo ' . $res . '; } ?>'; return '<?php if (null !== dcCore::app()->ctx->posts->postExpiredDate()) { echo ' . $res . '; } ?>';
@ -90,7 +91,7 @@ class FrontendTemplate
return return
'<?php if (null !== dcCore::app()->ctx->posts->postExpiredDate()) { echo ' . sprintf( '<?php if (null !== dcCore::app()->ctx->posts->postExpiredDate()) { echo ' . sprintf(
dcCore::app()->tpl->getFilters($attr), dcCore::app()->tpl->getFilters($attr),
'dt::dt2str(' . Date::class . '::dt2str(' .
( (
!empty($attr['format']) ? !empty($attr['format']) ?
"'" . addslashes($attr['format']) . "'" : 'dcCore::app()->blog->settings->system->time_format' "'" . addslashes($attr['format']) . "'" : 'dcCore::app()->blog->settings->system->time_format'

View File

@ -15,39 +15,23 @@ declare(strict_types=1);
namespace Dotclear\Plugin\postExpired; namespace Dotclear\Plugin\postExpired;
use dcCore; use dcCore;
use Dotclear\Module\MyPlugin;
/** /**
* This module definiton. * This module definiton.
*/ */
class My class My extends MyPlugin
{ {
/** @var string This module meta type */ /** @var string This module meta type */
public const META_TYPE = 'post_expired'; public const META_TYPE = 'post_expired';
/** public static function checkCustomContext(int $context): ?bool
* This module id.
*/
public static function id(): string
{ {
return basename(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,
* This module name. ]), dcCore::app()->blog->id);
*/
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__);
} }
/** /**