upgrade to dotclear 2.28
This commit is contained in:
parent
06ccf7bf1e
commit
a1470bd16f
11 changed files with 155 additions and 209 deletions
|
@ -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
|
postExpired 2023.08.13
|
||||||
===========================================================
|
===========================================================
|
||||||
* Require Dotclear 2.27
|
* Require Dotclear 2.27
|
||||||
|
|
30
README.md
30
README.md
|
@ -1,26 +1,23 @@
|
||||||
# README
|
# README
|
||||||
|
|
||||||
[![Release](https://img.shields.io/badge/release-2023.08.13-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/postExpired/releases)
|
[![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)
|
[![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)
|
[![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
|
_postExpired_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org).
|
||||||
web publishing software called Dotclear.
|
|
||||||
|
|
||||||
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.
|
to change some options of a post at a given time.
|
||||||
|
|
||||||
## REQUIREMENTS
|
## REQUIREMENTS
|
||||||
|
|
||||||
_postExpired_ requires:
|
* Dotclear 2.28
|
||||||
|
* PHP 8.1+
|
||||||
* contentadmin permissions
|
* Dotclear contentadmin permissions
|
||||||
* Dotclear 2.27
|
|
||||||
* PHP 7.4+
|
|
||||||
|
|
||||||
## USAGE
|
## USAGE
|
||||||
|
|
||||||
|
@ -39,13 +36,14 @@ Notes:
|
||||||
|
|
||||||
## LINKS
|
## LINKS
|
||||||
|
|
||||||
* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html)
|
* [License](https://git.dotclear.watch/JcDenis/postExpired/src/branch/master/LICENSE)
|
||||||
* Source & contribution : [Gitea Page](https://git.dotclear.watch/JcDenis/postExpired) or [GitHub Page](https://github.com/JcDenis/postExpired)
|
* [Packages & details](https://git.dotclear.watch/JcDenis/postExpired/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/postExpired))
|
||||||
* Packages & details: [Gitea Page](https://git.dotclear.watch/JcDenis/postExpired/releases) or [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/postExpired)
|
* [Sources & contributions](https://git.dotclear.watch/JcDenis/postExpired) (or on [GitHub](https://github.com/JcDenis/postExpired))
|
||||||
* Discuss & help : [Dotclear Forum](https://forum.dotclear.org/viewtopic.php?id=42305)
|
* [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
|
## CONTRIBUTORS
|
||||||
|
|
||||||
* Jean-Christian Denis
|
* Jean-Christian Denis (author)
|
||||||
|
|
||||||
You are welcome to contribute to this code.
|
You are welcome to contribute to this code.
|
||||||
|
|
35
_define.php
35
_define.php
|
@ -1,33 +1,30 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @brief postExpired, a plugin for Dotclear 2
|
* @file
|
||||||
|
* @brief The plugin postExpired definition
|
||||||
|
* @ingroup postExpired
|
||||||
*
|
*
|
||||||
* @package Dotclear
|
* @defgroup postExpired Plugin postExpired.
|
||||||
* @subpackage Plugin
|
|
||||||
*
|
*
|
||||||
* @author Jean-Christian Denis and Contributors
|
* Change entries options at a given date.
|
||||||
*
|
*
|
||||||
* @copyright Jean-Christian Denis
|
* @author Tomtom (author)
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @author Jean-Christian Denis (latest)
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
if (!defined('DC_RC_PATH')) {
|
declare(strict_types=1);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->registerModule(
|
$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.08.13',
|
'2023.10.19',
|
||||||
[
|
[
|
||||||
'requires' => [['core', '2.27']],
|
'requires' => [['core', '2.28']],
|
||||||
'permissions' => dcCore::app()->auth->makePermissions([
|
'permissions' => 'My',
|
||||||
dcCore::app()->auth::PERMISSION_USAGE,
|
'type' => 'plugin',
|
||||||
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
|
'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues',
|
||||||
]),
|
'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md',
|
||||||
'type' => 'plugin',
|
'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml',
|
||||||
'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',
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
|
@ -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.08.13</version>
|
<version>2023.10.19</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://git.dotclear.watch/JcDenis/postExpired/releases/download/v2023.08.13/plugin-postExpired.zip</file>
|
<file>https://git.dotclear.watch/JcDenis/postExpired/releases/download/v2023.10.19/plugin-postExpired.zip</file>
|
||||||
<da:dcmin>2.27</da:dcmin>
|
<da:dcmin>2.28</da:dcmin>
|
||||||
<da:details>https://git.dotclear.watch/JcDenis/postExpired/src/branch/master/README.md</da:details>
|
<da:details>https://git.dotclear.watch/JcDenis/postExpired/src/branch/master/README.md</da:details>
|
||||||
<da:support>https://git.dotclear.watch/JcDenis/postExpired/issues</da:support>
|
<da:support>https://git.dotclear.watch/JcDenis/postExpired/issues</da:support>
|
||||||
</module>
|
</module>
|
||||||
|
|
|
@ -1,22 +1,19 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* @brief postExpired, a plugin for Dotclear 2
|
|
||||||
*
|
|
||||||
* @package Dotclear
|
|
||||||
* @subpackage Plugin
|
|
||||||
*
|
|
||||||
* @author Jean-Christian Denis and Contributors
|
|
||||||
*
|
|
||||||
* @copyright Jean-Christian Denis
|
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\postExpired;
|
namespace Dotclear\Plugin\postExpired;
|
||||||
|
|
||||||
use dcCore;
|
use Dotclear\App;
|
||||||
use Dotclear\Core\Process;
|
use Dotclear\Core\Process;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief postExpired backend class.
|
||||||
|
* @ingroup postExpired
|
||||||
|
*
|
||||||
|
* @author Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
class Backend extends Process
|
class Backend extends Process
|
||||||
{
|
{
|
||||||
public static function init(): bool
|
public static function init(): bool
|
||||||
|
@ -30,19 +27,19 @@ class Backend extends Process
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dcCore::app()->addBehaviors([
|
App::behavior()->addBehaviors([
|
||||||
'adminPostsActions' => [BackendBehaviors::class, 'adminPostsActions'],
|
'adminPostsActions' => BackendBehaviors::adminPostsActions(...),
|
||||||
'adminPagesActions' => [BackendBehaviors::class, 'adminPostsActions'],
|
'adminPagesActions' => BackendBehaviors::adminPostsActions(...),
|
||||||
'adminPostHeaders' => [BackendBehaviors::class, 'adminPostHeaders'],
|
'adminPostHeaders' => BackendBehaviors::adminPostHeaders(...),
|
||||||
'adminPageHeaders' => [BackendBehaviors::class, 'adminPostHeaders'],
|
'adminPageHeaders' => BackendBehaviors::adminPostHeaders(...),
|
||||||
'adminPostFormItems' => [BackendBehaviors::class, 'adminPostFormItems'],
|
'adminPostFormItems' => BackendBehaviors::adminPostFormItems(...),
|
||||||
'adminPageFormItems' => [BackendBehaviors::class, 'adminPostFormItems'],
|
'adminPageFormItems' => BackendBehaviors::adminPostFormItems(...),
|
||||||
'adminBeforePostDelete' => [BackendBehaviors::class, 'adminBeforePostDelete'],
|
'adminBeforePostDelete' => BackendBehaviors::adminBeforePostDelete(...),
|
||||||
'adminBeforePageDelete' => [BackendBehaviors::class, 'adminBeforePostDelete'],
|
'adminBeforePageDelete' => BackendBehaviors::adminBeforePostDelete(...),
|
||||||
'adminAfterPostUpdate' => [BackendBehaviors::class, 'adminAfterPostSave'],
|
'adminAfterPostUpdate' => BackendBehaviors::adminAfterPostSave(...),
|
||||||
'adminAfterPageUpdate' => [BackendBehaviors::class, 'adminAfterPostSave'],
|
'adminAfterPageUpdate' => BackendBehaviors::adminAfterPostSave(...),
|
||||||
'adminAfterPostCreate' => [BackendBehaviors::class, 'adminAfterPostSave'],
|
'adminAfterPostCreate' => BackendBehaviors::adminAfterPostSave(...),
|
||||||
'adminAfterPageCreate' => [BackendBehaviors::class, 'adminAfterPostSave'],
|
'adminAfterPageCreate' => BackendBehaviors::adminAfterPostSave(...),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,22 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* @brief postExpired, a plugin for Dotclear 2
|
|
||||||
*
|
|
||||||
* @package Dotclear
|
|
||||||
* @subpackage Plugin
|
|
||||||
*
|
|
||||||
* @author Jean-Christian Denis and Contributors
|
|
||||||
*
|
|
||||||
* @copyright Jean-Christian Denis
|
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\postExpired;
|
namespace Dotclear\Plugin\postExpired;
|
||||||
|
|
||||||
use ArrayObject;
|
use ArrayObject;
|
||||||
use DateTimeZone;
|
use DateTimeZone;
|
||||||
use dcCore;
|
use Dotclear\App;
|
||||||
use Dotclear\Core\Backend\Action\ActionsPosts;
|
use Dotclear\Core\Backend\Action\ActionsPosts;
|
||||||
use Dotclear\Core\Backend\{
|
use Dotclear\Core\Backend\{
|
||||||
Notices,
|
Notices,
|
||||||
|
@ -44,9 +34,11 @@ use Dotclear\Helper\Html\Html;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup DC_PLUGIN_POSTEXPIRED
|
* @brief postExpired backend behaviors class.
|
||||||
* @brief Scheduled post change - admin methods.
|
* @ingroup postExpired
|
||||||
* @since 2.6
|
*
|
||||||
|
* @author Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
class BackendBehaviors
|
class BackendBehaviors
|
||||||
{
|
{
|
||||||
|
@ -63,7 +55,7 @@ class BackendBehaviors
|
||||||
__('Add expired date') => 'post_expired_add',
|
__('Add expired date') => 'post_expired_add',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
[self::class, 'callbackAdd']
|
self::callbackAdd(...)
|
||||||
);
|
);
|
||||||
|
|
||||||
$pa->addAction(
|
$pa->addAction(
|
||||||
|
@ -72,7 +64,7 @@ class BackendBehaviors
|
||||||
__('Remove expired date') => 'post_expired_remove',
|
__('Remove expired date') => 'post_expired_remove',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
[self::class, 'callbackRemove']
|
self::callbackRemove(...)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,9 +175,9 @@ class BackendBehaviors
|
||||||
|
|
||||||
$pa->beginPage(
|
$pa->beginPage(
|
||||||
Page::breadcrumb([
|
Page::breadcrumb([
|
||||||
Html::escapeHTML(dcCore::app()->blog->name) => '',
|
Html::escapeHTML(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') => '',
|
||||||
]),
|
]),
|
||||||
//Page::jsDatePicker() .
|
//Page::jsDatePicker() .
|
||||||
self::adminPostHeaders()
|
self::adminPostHeaders()
|
||||||
|
@ -197,7 +189,7 @@ class BackendBehaviors
|
||||||
(new Para())->items([
|
(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),
|
App::nonce()->formNonce(),
|
||||||
(new Hidden(['action'], 'post_expired_add')),
|
(new Hidden(['action'], 'post_expired_add')),
|
||||||
(new Submit(['do']))->value(__('Save')),
|
(new Submit(['do']))->value(__('Save')),
|
||||||
]),
|
]),
|
||||||
|
@ -237,7 +229,7 @@ class BackendBehaviors
|
||||||
*/
|
*/
|
||||||
private static function delPostExpired(int $post_id): void
|
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'];
|
$post_expired['newpassword'] = (string) $post['post_expired_newpassword'];
|
||||||
}
|
}
|
||||||
|
|
||||||
dcCore::app()->meta->setPostMeta(
|
App::meta()->setPostMeta(
|
||||||
$post_id,
|
$post_id,
|
||||||
My::META_TYPE,
|
My::META_TYPE,
|
||||||
My::encode($post_expired)
|
My::encode($post_expired)
|
||||||
|
@ -301,7 +293,7 @@ class BackendBehaviors
|
||||||
$fields = $post_expired = [];
|
$fields = $post_expired = [];
|
||||||
|
|
||||||
if ($post_id) {
|
if ($post_id) {
|
||||||
$rs = dcCore::app()->meta->getMetadata([
|
$rs = App::meta()->getMetadata([
|
||||||
'meta_type' => My::META_TYPE,
|
'meta_type' => My::META_TYPE,
|
||||||
'post_id' => $post_id,
|
'post_id' => $post_id,
|
||||||
'limit' => 1,
|
'limit' => 1,
|
||||||
|
@ -328,7 +320,7 @@ class BackendBehaviors
|
||||||
$fields['post_expired_category'] = (new Para())->items([
|
$fields['post_expired_category'] = (new Para())->items([
|
||||||
(new Label(__('Category:'), Label::OUTSIDE_LABEL_BEFORE))->for('post_expired_category'),
|
(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(
|
(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']
|
['post_type' => 'post']
|
||||||
)
|
)
|
||||||
)),
|
)),
|
||||||
|
@ -383,7 +375,7 @@ class BackendBehaviors
|
||||||
];
|
];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$categories = dcCore::app()->blog->getCategories(
|
$categories = App::blog()->getCategories(
|
||||||
['post_type' => 'post']
|
['post_type' => 'post']
|
||||||
);
|
);
|
||||||
while ($categories->fetch()) {
|
while ($categories->fetch()) {
|
||||||
|
@ -465,7 +457,7 @@ class BackendBehaviors
|
||||||
*/
|
*/
|
||||||
private static function dateFromUser(string $date): string
|
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));
|
$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') : '';
|
||||||
|
@ -480,7 +472,7 @@ class BackendBehaviors
|
||||||
*/
|
*/
|
||||||
private static function dateToUser(string $date): string
|
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'));
|
$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') : '';
|
||||||
|
|
|
@ -1,22 +1,19 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* @brief postExpired, a plugin for Dotclear 2
|
|
||||||
*
|
|
||||||
* @package Dotclear
|
|
||||||
* @subpackage Plugin
|
|
||||||
*
|
|
||||||
* @author Jean-Christian Denis and Contributors
|
|
||||||
*
|
|
||||||
* @copyright Jean-Christian Denis
|
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\postExpired;
|
namespace Dotclear\Plugin\postExpired;
|
||||||
|
|
||||||
use dcCore;
|
use Dotclear\App;
|
||||||
use Dotclear\Core\Process;
|
use Dotclear\Core\Process;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief postExpired frontend class.
|
||||||
|
* @ingroup postExpired
|
||||||
|
*
|
||||||
|
* @author Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
class Frontend extends Process
|
class Frontend extends Process
|
||||||
{
|
{
|
||||||
public static function init(): bool
|
public static function init(): bool
|
||||||
|
@ -35,27 +32,27 @@ class Frontend extends Process
|
||||||
__('This entry has no expiration date');
|
__('This entry has no expiration date');
|
||||||
|
|
||||||
# launch update only on public home page and feed
|
# launch update only on public home page and feed
|
||||||
if (in_array(dcCore::app()->url->type, ['default', 'feed'])) {
|
if (in_array(App::url()->type, ['default', 'feed'])) {
|
||||||
dcCore::app()->addBehavior(
|
App::behavior()->addBehavior(
|
||||||
'publicBeforeDocumentV2',
|
'publicBeforeDocumentV2',
|
||||||
[FrontendBehaviors::class, 'publicBeforeDocumentV2']
|
FrontendBehaviors::publicBeforeDocumentV2(...)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
dcCore::app()->addBehavior(
|
App::behavior()->addBehavior(
|
||||||
'coreBlogGetPosts',
|
'coreBlogGetPosts',
|
||||||
[FrontendBehaviors::class, 'coreBlogGetPosts']
|
FrontendBehaviors::coreBlogGetPosts(...)
|
||||||
);
|
);
|
||||||
dcCore::app()->tpl->addBlock(
|
App::frontend()->template()->addBlock(
|
||||||
'EntryExpiredIf',
|
'EntryExpiredIf',
|
||||||
[FrontendTemplate::class, 'EntryExpiredIf']
|
FrontendTemplate::EntryExpiredIf(...)
|
||||||
);
|
);
|
||||||
dcCore::app()->tpl->addValue(
|
App::frontend()->template()->addValue(
|
||||||
'EntryExpiredDate',
|
'EntryExpiredDate',
|
||||||
[FrontendTemplate::class, 'EntryExpiredDate']
|
FrontendTemplate::EntryExpiredDate(...)
|
||||||
);
|
);
|
||||||
dcCore::app()->tpl->addValue(
|
App::frontend()->template()->addValue(
|
||||||
'EntryExpiredTime',
|
'EntryExpiredTime',
|
||||||
[FrontendTemplate::class, 'EntryExpiredTime']
|
FrontendTemplate::EntryExpiredTime(...)
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,23 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* @brief postExpired, a plugin for Dotclear 2
|
|
||||||
*
|
|
||||||
* @package Dotclear
|
|
||||||
* @subpackage Plugin
|
|
||||||
*
|
|
||||||
* @author Jean-Christian Denis and Contributors
|
|
||||||
*
|
|
||||||
* @copyright Jean-Christian Denis
|
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\postExpired;
|
namespace Dotclear\Plugin\postExpired;
|
||||||
|
|
||||||
use DateTimeZone;
|
use DateTimeZone;
|
||||||
use dcBlog;
|
use Dotclear\App;
|
||||||
use dcCore;
|
|
||||||
use dcMeta;
|
|
||||||
use Dotclear\Database\MetaRecord;
|
use Dotclear\Database\MetaRecord;
|
||||||
use Dotclear\Database\Statement\{
|
use Dotclear\Database\Statement\{
|
||||||
JoinStatement,
|
JoinStatement,
|
||||||
|
@ -25,9 +13,11 @@ use Dotclear\Database\Statement\{
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup DC_PLUGIN_POSTEXPIRED
|
* @brief postExpired frontend behaviors class.
|
||||||
* @brief Scheduled post change - public methods.
|
* @ingroup postExpired
|
||||||
* @since 2.6
|
*
|
||||||
|
* @author Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
class FrontendBehaviors
|
class FrontendBehaviors
|
||||||
{
|
{
|
||||||
|
@ -38,7 +28,7 @@ class FrontendBehaviors
|
||||||
{
|
{
|
||||||
// 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(App::con()->prefix() . App::blog()::POST_TABLE_NAME, 'P'))
|
||||||
->columns([
|
->columns([
|
||||||
'P.post_id',
|
'P.post_id',
|
||||||
'P.post_tz',
|
'P.post_tz',
|
||||||
|
@ -47,11 +37,11 @@ class FrontendBehaviors
|
||||||
->join(
|
->join(
|
||||||
(new JoinStatement())
|
(new JoinStatement())
|
||||||
->inner()
|
->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')
|
->on('META.post_id = P.post_id')
|
||||||
->statement()
|
->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))
|
->and('META.meta_type = ' . $sql->quote(My::META_TYPE))
|
||||||
->select();
|
->select();
|
||||||
|
|
||||||
|
@ -65,7 +55,7 @@ class FrontendBehaviors
|
||||||
$now_tz = (int) date_format(date_create('now', $utc), 'U');
|
$now_tz = (int) date_format(date_create('now', $utc), 'U');
|
||||||
|
|
||||||
// Prepared post Cursor
|
// 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
|
// Loop through marked posts
|
||||||
$updated = false;
|
$updated = false;
|
||||||
|
@ -79,8 +69,8 @@ class FrontendBehaviors
|
||||||
|
|
||||||
if ($now_tz > $meta_tz) {
|
if ($now_tz > $meta_tz) {
|
||||||
// Delete meta for expired date
|
// Delete meta for expired date
|
||||||
dcCore::app()->auth->sudo(
|
App::auth()->sudo(
|
||||||
[dcCore::app()->meta, 'delPostMeta'],
|
App::meta()->delPostMeta(...),
|
||||||
$posts->f('post_id'),
|
$posts->f('post_id'),
|
||||||
My::META_TYPE
|
My::META_TYPE
|
||||||
);
|
);
|
||||||
|
@ -135,7 +125,7 @@ class FrontendBehaviors
|
||||||
// Update post
|
// Update post
|
||||||
$post_cur->update(
|
$post_cur->update(
|
||||||
'WHERE post_id = ' . $posts->f('post_id') . ' ' .
|
'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;
|
$updated = true;
|
||||||
|
@ -144,7 +134,7 @@ class FrontendBehaviors
|
||||||
|
|
||||||
// Say blog is updated
|
// Say blog is updated
|
||||||
if ($updated) {
|
if ($updated) {
|
||||||
dcCore::app()->blog->triggerBlog();
|
App::blog()->triggerBlog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,6 +145,6 @@ class FrontendBehaviors
|
||||||
*/
|
*/
|
||||||
public static function coreBlogGetPosts(MetaRecord $rs): void
|
public static function coreBlogGetPosts(MetaRecord $rs): void
|
||||||
{
|
{
|
||||||
$rs->extend('rsExtPostExpired');
|
$rs->extend(rsExtPostExpired::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,19 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* @brief postExpired, a plugin for Dotclear 2
|
|
||||||
*
|
|
||||||
* @package Dotclear
|
|
||||||
* @subpackage Plugin
|
|
||||||
*
|
|
||||||
* @author Jean-Christian Denis and Contributors
|
|
||||||
*
|
|
||||||
* @copyright Jean-Christian Denis
|
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\postExpired;
|
namespace Dotclear\Plugin\postExpired;
|
||||||
|
|
||||||
use ArrayObject;
|
use ArrayObject;
|
||||||
use dcCore;
|
use Dotclear\App;
|
||||||
use dcTemplate;
|
|
||||||
use Dotclear\Helper\Date;
|
use Dotclear\Helper\Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup DC_PLUGIN_POSTEXPIRED
|
* @brief postExpired frontend template class.
|
||||||
* @brief Scheduled post change - template methods.
|
* @ingroup postExpired
|
||||||
* @since 2.6
|
*
|
||||||
|
* @author Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
class FrontendTemplate
|
class FrontendTemplate
|
||||||
{
|
{
|
||||||
|
@ -38,13 +29,13 @@ class FrontendTemplate
|
||||||
{
|
{
|
||||||
$if = [];
|
$if = [];
|
||||||
$operator = isset($attr['operator']) ?
|
$operator = isset($attr['operator']) ?
|
||||||
dcTemplate::getOperator($attr['operator']) : '&&';
|
App::frontend()->template()->getOperator($attr['operator']) : '&&';
|
||||||
|
|
||||||
if (isset($attr['has_date'])) {
|
if (isset($attr['has_date'])) {
|
||||||
$sign = (bool) $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 {
|
} else {
|
||||||
$if[] = '(null !== dcCore::app()->ctx->posts->postExpiredDate())';
|
$if[] = '(null !== App::frontend()->context()->posts->postExpiredDate())';
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -64,19 +55,19 @@ class FrontendTemplate
|
||||||
{
|
{
|
||||||
$format = !empty($attr['format']) ?
|
$format = !empty($attr['format']) ?
|
||||||
addslashes($attr['format']) : '';
|
addslashes($attr['format']) : '';
|
||||||
$f = dcCore::app()->tpl->getFilters($attr);
|
$f = App::frontend()->template()->getFilters($attr);
|
||||||
|
|
||||||
if (!empty($attr['rfc822'])) {
|
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'])) {
|
} 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) {
|
} 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 {
|
} 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 '<?php if (null !== dcCore::app()->ctx->posts->postExpiredDate()) { echo ' . $res . '; } ?>';
|
return '<?php if (null !== App::frontend()->context()->posts->postExpiredDate()) { echo ' . $res . '; } ?>';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,13 +80,13 @@ class FrontendTemplate
|
||||||
public static function EntryExpiredTime(ArrayObject $attr): string
|
public static function EntryExpiredTime(ArrayObject $attr): string
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
'<?php if (null !== dcCore::app()->ctx->posts->postExpiredDate()) { echo ' . sprintf(
|
'<?php if (null !== App::frontend()->context()->posts->postExpiredDate()) { echo ' . sprintf(
|
||||||
dcCore::app()->tpl->getFilters($attr),
|
App::frontend()->template()->getFilters($attr),
|
||||||
Date::class . '::dt2str(' .
|
Date::class . '::dt2str(' .
|
||||||
(
|
(
|
||||||
!empty($attr['format']) ?
|
!empty($attr['format']) ?
|
||||||
"'" . addslashes($attr['format']) . "'" : 'dcCore::app()->blog->settings->system->time_format'
|
"'" . addslashes($attr['format']) . "'" : 'App::blog()->settings()->system->time_format'
|
||||||
) . ',dcCore::app()->ctx->posts->postExpiredDate())'
|
) . ',App::frontend()->context()->posts->postExpiredDate())'
|
||||||
) . '; } ?>';
|
) . '; } ?>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
30
src/My.php
30
src/My.php
|
@ -1,39 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* @brief postExpired, a plugin for Dotclear 2
|
|
||||||
*
|
|
||||||
* @package Dotclear
|
|
||||||
* @subpackage Plugin
|
|
||||||
*
|
|
||||||
* @author Jean-Christian Denis and Contributors
|
|
||||||
*
|
|
||||||
* @copyright Jean-Christian Denis
|
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\postExpired;
|
namespace Dotclear\Plugin\postExpired;
|
||||||
|
|
||||||
use dcCore;
|
|
||||||
use Dotclear\Module\MyPlugin;
|
use Dotclear\Module\MyPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This module definiton.
|
* @brief postExpired My helper.
|
||||||
|
* @ingroup postExpired
|
||||||
|
*
|
||||||
|
* @author Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
class My extends MyPlugin
|
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
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode Expired Date settings.
|
* Encode Expired Date settings.
|
||||||
*
|
*
|
||||||
|
@ -71,4 +55,6 @@ class My extends MyPlugin
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use default permissions
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +1,21 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* @brief postExpired, a plugin for Dotclear 2
|
|
||||||
*
|
|
||||||
* @package Dotclear
|
|
||||||
* @subpackage Plugin
|
|
||||||
*
|
|
||||||
* @author Jean-Christian Denis and Contributors
|
|
||||||
*
|
|
||||||
* @copyright Jean-Christian Denis
|
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\postExpired;
|
namespace Dotclear\Plugin\postExpired;
|
||||||
|
|
||||||
use dcCore;
|
use Dotclear\App;
|
||||||
use Dotclear\Database\MetaRecord;
|
use Dotclear\Database\MetaRecord;
|
||||||
use rsExtPost;
|
use Dotclear\Schema\Extension\Post;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup DC_PLUGIN_POSTEXPIRED
|
* @brief postExpired record extension class.
|
||||||
* @brief Scheduled post change - extends recordset.
|
* @ingroup postExpired
|
||||||
* @since 2.6
|
*
|
||||||
|
* @author Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
class rsExtPostExpired extends rsExtPost
|
class rsExtPostExpired extends Post
|
||||||
{
|
{
|
||||||
/** @var array $memory Memory to prevent redondant call */
|
/** @var array $memory Memory to prevent redondant call */
|
||||||
protected static array $memory = [];
|
protected static array $memory = [];
|
||||||
|
@ -38,7 +30,7 @@ class rsExtPostExpired extends rsExtPost
|
||||||
public static function postExpiredDate(MetaRecord $rs): string
|
public static function postExpiredDate(MetaRecord $rs): string
|
||||||
{
|
{
|
||||||
if (!static::$memory[$rs->f('post_id')]) {
|
if (!static::$memory[$rs->f('post_id')]) {
|
||||||
$rs_date = dcCore::app()->meta->getMetadata([
|
$rs_date = App::meta()->getMetadata([
|
||||||
'meta_type' => My::META_TYPE,
|
'meta_type' => My::META_TYPE,
|
||||||
'post_id' => $rs->f('post_id'),
|
'post_id' => $rs->f('post_id'),
|
||||||
'limit' => 1,
|
'limit' => 1,
|
||||||
|
|
Loading…
Reference in a new issue