release 2023.07.30
This commit is contained in:
parent
5618a4c803
commit
fb9958fdcc
10 changed files with 64 additions and 104 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
<modules xmlns:da="http://dotaddict.org/da/">
|
||||
<module id="postExpired">
|
||||
<name>Expired entries</name>
|
||||
<version>2023.05.21</version>
|
||||
<version>2023.07.30</version>
|
||||
<author>Jean-Christian Denis and Contributors</author>
|
||||
<desc>Change entries options at a given date</desc>
|
||||
<file>https://github.com/JcDenis/postExpired/releases/download/v2023.05.21/plugin-postExpired.zip</file>
|
||||
<da:dcmin>2.26</da:dcmin>
|
||||
<file>https://github.com/JcDenis/postExpired/releases/download/v2023.07.30/plugin-postExpired.zip</file>
|
||||
<da:dcmin>2.27</da:dcmin>
|
||||
<da:details>https://plugins.dotaddict.org/dc2/details/postExpired</da:details>
|
||||
<da:support>https://github.com/JcDenis/postExpired</da:support>
|
||||
</module>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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') : '';
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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'))
|
||||
|
|
|
@ -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 '<?php if (null !== dcCore::app()->ctx->posts->postExpiredDate()) { echo ' . $res . '; } ?>';
|
||||
|
@ -90,7 +91,7 @@ class FrontendTemplate
|
|||
return
|
||||
'<?php if (null !== dcCore::app()->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'
|
||||
|
|
32
src/My.php
32
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue