Compare commits

..

No commits in common. "fb9958fdcc1d5eb50b3904f2ab07329f5b31943d" and "a5384aaea6ff488fe29cdf9f8874a54a08e52963" have entirely different histories.

13 changed files with 195 additions and 178 deletions

View File

@ -1,26 +1,3 @@
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
- add ability to change password
2023.05.13
- require dotclear 2.26
- fix sql statement
- fix backend js
- cleanup for dotclear 2.26 stable
2023.04.23
- require dotclear 2.26
- use latest dotclear namespace
- use sql statement
- fix nullsafe warnings
- add some inline code doc
2023.03.21 2023.03.21
- require dotclear 2.25 - require dotclear 2.25
- use namespace - use namespace

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.27-blue.svg)](https://fr.dotclear.org/download) [![Dotclear](https://img.shields.io/badge/dotclear-v2.25-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,8 +20,7 @@ to change some options of a post at a given time.
postExpired requires: postExpired requires:
* contentadmin permissions * contentadmin permissions
* Dotclear 2.27 * Dotclear 2.25
* PHP 7.4+
## USAGE ## USAGE

View File

@ -18,12 +18,12 @@ $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.07.30', '2023.03.21',
[ [
'requires' => [['core', '2.27']], 'requires' => [['core', '2.25']],
'permissions' => dcCore::app()->auth->makePermissions([ 'permissions' => dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_USAGE, dcAuth::PERMISSION_USAGE,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, dcAuth::PERMISSION_CONTENT_ADMIN,
]), ]),
'type' => 'plugin', 'type' => 'plugin',
'support' => 'https://github.com/JcDenis/' . basename(__DIR__), 'support' => 'https://github.com/JcDenis/' . basename(__DIR__),

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.07.30</version> <version>2023.03.21</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.07.30/plugin-postExpired.zip</file> <file>https://github.com/JcDenis/postExpired/releases/download/v2023.03.21/plugin-postExpired.zip</file>
<da:dcmin>2.27</da:dcmin> <da:dcmin>2.25</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

@ -1,17 +1,25 @@
/*global $, dotclear, datePicker */ /* -- BEGIN LICENSE BLOCK ----------------------------------
'use strict'; *
* This file is part of postExpired, a plugin for Dotclear 2.
*
* Copyright (c) 2009-2013 Jean-Christian Denis and contributors
* contact@jcdenis.fr http://jcd.lv
*
* Licensed under the GPL version 2.0 license.
* A copy of this license is available in LICENSE file or at
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
* -- END LICENSE BLOCK ------------------------------------*/
$(() => { $(function(){
if (typeof datePicker === 'function') {
var post_pe_field=document.getElementById('post_expired_date'); var post_pe_field=document.getElementById('post_expired_date');
if(post_pe_field!=undefined){ if(post_pe_field!=undefined){
var post_pe_dtPick=new datePicker(post_pe_field); var post_pe_dtPick=new datePicker(post_pe_field);
post_pe_dtPick.img_top='1.5em'; post_pe_dtPick.img_top='1.5em';
post_pe_dtPick.draw(); post_pe_dtPick.draw();
} }
}
$('#post_expired h4').toggleWithLegend( $('#post_expired h4').toggleWithLegend(
$('#post_expired').children().not('h4'), $('#post_expired').children().not('h4'),
{user_pref:'dcx_postexpired_admin_form_sidebar',legend_click:true} {cookie:'dcx_postexpired_admin_form_sidebar',legend_click:true}
); );
}); });

View File

@ -9,21 +9,19 @@
# DOT NOT MODIFY THIS FILE ! # DOT NOT MODIFY THIS FILE !
# #
use Dotclear\Helper\L10n; l10n::$locales['Expired entries'] = 'Billets périmés';
l10n::$locales['Add expired date'] = 'Ajouter une date de péremption';
L10n::$locales['Expired entries'] = 'Billets périmés'; l10n::$locales['Remove expired date'] = 'Retirer une date de péremption';
L10n::$locales['Add expired date'] = 'Ajouter une date de péremption'; l10n::$locales['Expired date'] = 'Date de péremption';
L10n::$locales['Remove expired date'] = 'Retirer une date de péremption'; l10n::$locales['Expired date added.'] = 'Date de péremption ajoutée.';
L10n::$locales['Expired date'] = 'Date de péremption'; l10n::$locales['Add expired date to this selection'] = 'Ajouter une date de péremtion à cette sélection';
L10n::$locales['Expired date added.'] = 'Date de péremption ajoutée.'; l10n::$locales['Expired date deleted.'] = 'Dtae de péremtion supprimé';
L10n::$locales['Add expired date to this selection'] = 'Ajouter une date de péremtion à cette sélection'; l10n::$locales['On this date, change:'] = 'Á cette date, changer :';
L10n::$locales['Expired date deleted.'] = 'Dtae de péremtion supprimé'; l10n::$locales['Selection:'] = 'Séléction :';
L10n::$locales['On this date, change:'] = 'Á cette date, changer :'; l10n::$locales['Comments status:'] = 'Status des commentaires :';
L10n::$locales['Selection:'] = 'Séléction :'; l10n::$locales['Trackbacks status:'] = 'Status des rétroliens :';
L10n::$locales['Comments status:'] = 'Status des commentaires :'; l10n::$locales['Not changed'] = 'Inchangé';
L10n::$locales['Trackbacks status:'] = 'Status des rétroliens :'; l10n::$locales['Opened'] = 'Ouvert';
L10n::$locales['Change password'] = 'Modifier le mot de passe'; l10n::$locales['Closed'] = 'Fermé';
L10n::$locales['Leave empty to remove it'] = 'Laisser vide pour le supprimer'; l10n::$locales['Expired on'] = 'Expire le';
L10n::$locales['Not changed'] = 'Inchangé'; l10n::$locales['This entry has no expiration date'] = 'Ce billet n\'a pas de date de péremption';
L10n::$locales['Expired on'] = 'Expire le';
L10n::$locales['This entry has no expiration date'] = 'Ce billet n\'a pas de date de péremption';

View File

@ -1,60 +1,87 @@
# Language: Français
# Module: postExpired - 2013.11.03
# Date: 2013-11-03 22:12:31
# Translated with translater 2013.05.11
msgid "" msgid ""
msgstr "" msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Project-Id-Version: postExpired 2023.05.21\n" "Project-Id-Version: postExpired 2013.11.03\n"
"POT-Creation-Date: \n" "POT-Creation-Date: \n"
"PO-Revision-Date: 2023-05-21T13:03:45+00:00\n" "PO-Revision-Date: 2013-11-03T22:12:31+00:00\n"
"Last-Translator: Jean-Christian Denis\n" "Last-Translator: Jean-Christian Denis\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: _admin.php:100
#: _admin.php:110
msgid "Expired entries" msgid "Expired entries"
msgstr "Billets périmés" msgstr "Billets périmés"
#: _admin.php:101
msgid "Add expired date" msgid "Add expired date"
msgstr "Ajouter une date de péremption" msgstr "Ajouter une date de péremption"
#: _admin.php:111
msgid "Remove expired date" msgid "Remove expired date"
msgstr "Retirer une date de péremption" msgstr "Retirer une date de péremption"
#: _admin.php:139
msgid "Expired date" msgid "Expired date"
msgstr "Date de péremption" msgstr "Date de péremption"
#: _admin.php:209
msgid "Expired date added." msgid "Expired date added."
msgstr "Date de péremption ajoutée." msgstr "Date de péremption ajoutée."
#: _admin.php:222
msgid "Add expired date to this selection" msgid "Add expired date to this selection"
msgstr "Ajouter une date de péremtion à cette sélection" msgstr "Ajouter une date de péremtion à cette sélection"
#: _admin.php:269
msgid "Expired date deleted." msgid "Expired date deleted."
msgstr "Dtae de péremtion supprimé" msgstr "Dtae de péremtion supprimé"
#: _admin.php:370
msgid "On this date, change:" msgid "On this date, change:"
msgstr "Á cette date, changer :" msgstr "Á cette date, changer :"
#: _admin.php:398
msgid "Selection:" msgid "Selection:"
msgstr "Séléction :" msgstr "Séléction :"
#: _admin.php:409
msgid "Comments status:" msgid "Comments status:"
msgstr "Status des commentaires :" msgstr "Status des commentaires :"
#: _admin.php:419
msgid "Trackbacks status:" msgid "Trackbacks status:"
msgstr "Status des rétroliens :" msgstr "Status des rétroliens :"
msgid "Change password" #: _admin.php:440
msgstr "Modifier le mot de passe" #: _admin.php:470
#: _admin.php:485
msgid "Leave empty to remove it" #: _admin.php:499
msgstr "Laisser vide pour le supprimer" #: _admin.php:513
msgid "Not changed" msgid "Not changed"
msgstr "Inchangé" msgstr "Inchangé"
#: _admin.php:500
#: _admin.php:514
msgid "Opened"
msgstr "Ouvert"
#: _admin.php:501
#: _admin.php:515
msgid "Closed"
msgstr "Fermé"
#: _public.php:25
msgid "Expired on" msgid "Expired on"
msgstr "Expire le" msgstr "Expire le"
#: _public.php:26
msgid "This entry has no expiration date" msgid "This entry has no expiration date"
msgstr "Ce billet n'a pas de date de péremption" msgstr "Ce billet n'a pas de date de péremption"

View File

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

View File

@ -17,23 +17,17 @@ namespace Dotclear\Plugin\postExpired;
use ArrayObject; use ArrayObject;
use DateTimeZone; use DateTimeZone;
use dcCore; use dcCore;
use Dotclear\Core\Backend\Action\ActionsPosts; use dcPostsActions;
use Dotclear\Core\Backend\{ use dcPage;
Notices,
Page
};
use Dotclear\Database\{ use Dotclear\Database\{
Cursor, Cursor,
MetaRecord MetaRecord
}; };
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox,
Datetime, Datetime,
Form, Form,
Hidden, Hidden,
Input,
Label, Label,
Note,
Option, Option,
Para, Para,
Text, Text,
@ -53,9 +47,9 @@ class BackendBehaviors
/** /**
* Add actions to posts page combo. * Add actions to posts page combo.
* *
* @param ActionsPosts $pa ActionsPosts instance * @param dcPostsActions $pa dcPostsActions instance
*/ */
public static function adminPostsActions(ActionsPosts $pa): void public static function adminPostsActions(dcPostsActions $pa): void
{ {
$pa->addAction( $pa->addAction(
[ [
@ -83,7 +77,7 @@ class BackendBehaviors
*/ */
public static function adminPostHeaders(): string public static function adminPostHeaders(): string
{ {
return My::jsLoad('backend'); return dcPage::jsModuleLoad(My::id() . '/js/backend.js');
} }
/** /**
@ -130,15 +124,11 @@ class BackendBehaviors
self::delPostExpired($post_id); self::delPostExpired($post_id);
if (!empty($_POST['post_expired_date']) if (!empty($_POST['post_expired_date'])
&& ( && (!empty($_POST['post_expired_status'])
!empty($_POST['post_expired_status'])
|| !empty($_POST['post_expired_category']) || !empty($_POST['post_expired_category'])
|| !empty($_POST['post_expired_selected']) || !empty($_POST['post_expired_selected'])
|| !empty($_POST['post_expired_comment']) || !empty($_POST['post_expired_comment'])
|| !empty($_POST['post_expired_trackback']) || !empty($_POST['post_expired_trackback']))) {
|| !empty($_POST['post_expired_password'])
)
) {
self::setPostExpired($post_id, new ArrayObject($_POST)); self::setPostExpired($post_id, new ArrayObject($_POST));
} }
} }
@ -146,34 +136,35 @@ class BackendBehaviors
/** /**
* Posts actions callback to add expired date. * Posts actions callback to add expired date.
* *
* @param ActionsPosts $pa ActionsPosts instance * @param dcPostsActions $pa dcPostsActions instance
* @param ArrayObject $post _POST actions * @param ArrayObject $post _POST actions
*/ */
public static function callbackAdd(ActionsPosts $pa, ArrayObject $post): void public static function callbackAdd(dcPostsActions $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)) {
throw new Exception(__('No entry selected')); throw new Exception(__('No entry selected'));
} }
// Add expired date // Add epired date
if (!empty($post['post_expired_date']) if (!empty($post['post_expired_date'])
&& ( && (!empty($post['post_expired_status'])
!empty($post['post_expired_status'])
|| !empty($post['post_expired_category']) || !empty($post['post_expired_category'])
|| !empty($post['post_expired_selected']) || !empty($post['post_expired_selected'])
|| !empty($post['post_expired_comment']) || !empty($post['post_expired_comment'])
|| !empty($post['post_expired_trackback']) || !empty($post['post_expired_trackback']))) {
|| !empty($post['post_expired_password'])
)
) {
foreach ($posts_ids as $post_id) { foreach ($posts_ids as $post_id) {
self::delPostExpired($post_id); self::delPostExpired($post_id);
self::setPostExpired($post_id, $post); self::setPostExpired($post_id, $post);
} }
Notices::addSuccessNotice(__('Expired date added.')); dcPage::addSuccessNotice(__('Expired date added.'));
$pa->redirect(true); $pa->redirect(true);
// Display form // Display form
@ -182,25 +173,27 @@ class BackendBehaviors
$posts = $pa->getRS(); $posts = $pa->getRS();
$pa->beginPage( $pa->beginPage(
Page::breadcrumb([ dcPage::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') => '',
]), ]),
//Page::jsDatePicker() . //dcPage::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([ (new Para())->items(array_merge(
... 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();
@ -210,10 +203,10 @@ class BackendBehaviors
/** /**
* Posts actions callback to add expired date. * Posts actions callback to add expired date.
* *
* @param ActionsPosts $pa ActionsPosts instance * @param dcPostsActions $pa dcPostsActions instance
* @param ArrayObject $post _POST actions * @param ArrayObject $post _POST actions
*/ */
public static function callbackRemove(ActionsPosts $pa, ArrayObject $post): void public static function callbackRemove(dcPostsActions $pa, ArrayObject $post): void
{ {
// No entry // No entry
$posts_ids = $pa->getIDs(); $posts_ids = $pa->getIDs();
@ -226,7 +219,7 @@ class BackendBehaviors
self::delPostExpired($post_id); self::delPostExpired($post_id);
} }
Notices::addSuccessNotice(__('Expired date deleted.')); dcPage::addSuccessNotice(__('Expired date deleted.'));
$pa->redirect(true); $pa->redirect(true);
} }
@ -254,8 +247,6 @@ class BackendBehaviors
'selected' => '', 'selected' => '',
'comment' => '', 'comment' => '',
'trackback' => '', 'trackback' => '',
'password' => '',
'newpassword' => '',
'date' => self::dateFromUser($post['post_expired_date']), 'date' => self::dateFromUser($post['post_expired_date']),
]; ];
@ -274,12 +265,6 @@ class BackendBehaviors
if (!empty($post['post_expired_trackback'])) { if (!empty($post['post_expired_trackback'])) {
$post_expired['trackback'] = (string) $post['post_expired_trackback']; $post_expired['trackback'] = (string) $post['post_expired_trackback'];
} }
if (!empty($post['post_expired_password'])) {
$post_expired['password'] = (string) $post['post_expired_password'];
}
if (!empty($post['post_expired_newpassword'])) {
$post_expired['newpassword'] = (string) $post['post_expired_newpassword'];
}
dcCore::app()->meta->setPostMeta( dcCore::app()->meta->setPostMeta(
$post_id, $post_id,
@ -298,6 +283,11 @@ 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) {
@ -313,20 +303,20 @@ class BackendBehaviors
} }
$fields['post_expired_date'] = (new Para())->items([ $fields['post_expired_date'] = (new Para())->items([
(new Label(__('Date:'), Label::OUTSIDE_LABEL_BEFORE))->for('post_expired_date'), (new Label(__('Date:')))->for('post_expired_date'),
(new Datetime('post_expired_date', Html::escapeHTML(self::dateToUser($post_expired['date'] ?? 'now'))))->class(empty($post_expired['date']) ? 'invalid' : ''), (new Datetime('post_expired_date', Html::escapeHTML(self::dateToUser($post_expired['date'] ?? 'now'))))->class(empty($post_expired['date']) ? 'invalid' : ''),
]); ]);
$fields['post_expired_status'] = (new Para())->items([ $fields['post_expired_status'] = (new Para())->items([
(new Text('strong', __('On this date, change:'))), (new Text('strong', __('On this date, change:'))),
(new Text('br')), (new Text('br')),
(new Label(__('Status:'), Label::OUTSIDE_LABEL_BEFORE))->for('post_expired_status'), (new Label(__('Status:')))->for('post_expired_status'),
(new Select('post_expired_status'))->default(empty($post_expired['status']) ? '' : $post_expired['status'])->items(self::statusCombo()), (new Select('post_expired_status'))->default(empty($post_expired['status']) ? '' : $post_expired['status'])->items(self::statusCombo()),
]); ]);
if ($post_type == 'post') { if ($post_type == 'post') {
$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:')))->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( dcCore::app()->blog->getCategories(
['post_type' => 'post'] ['post_type' => 'post']
@ -335,29 +325,21 @@ class BackendBehaviors
]); ]);
$fields['post_expired_selected'] = (new Para())->items([ $fields['post_expired_selected'] = (new Para())->items([
(new Label(__('Selection:'), Label::OUTSIDE_LABEL_BEFORE))->for('post_expired_selected'), (new Label(__('Selection:')))->for('post_expired_selected'),
(new Select('post_expired_selected'))->default(empty($post_expired['selected']) ? '' : $post_expired['selected'])->items(self::selectedCombo()), (new Select('post_expired_selected'))->default(empty($post_expired['selected']) ? '' : $post_expired['selected'])->items(self::selectedCombo()),
]); ]);
} }
$fields['post_expired_comment'] = (new Para())->items([ $fields['post_expired_comment'] = (new Para())->items([
(new Label(__('Comments status:'), Label::OUTSIDE_LABEL_BEFORE))->for('post_expired_comment'), (new Label(__('Comments status:')))->for('post_expired_comment'),
(new Select('post_expired_comment'))->default(empty($post_expired['comment']) ? '' : $post_expired['comment'])->items(self::commentCombo()), (new Select('post_expired_comment'))->default(empty($post_expired['comment']) ? '' : $post_expired['comment'])->items(self::commentCombo()),
]); ]);
$fields['post_expired_trackback'] = (new Para())->items([ $fields['post_expired_trackback'] = (new Para())->items([
(new Label(__('Trackbacks status:'), Label::OUTSIDE_LABEL_BEFORE))->for('post_expired_trackback'), (new Label(__('Trackbacks status:')))->for('post_expired_trackback'),
(new Select('post_expired_trackback'))->default(empty($post_expired['trackback']) ? '' : $post_expired['trackback'])->items(self::trackbackCombo()), (new Select('post_expired_trackback'))->default(empty($post_expired['trackback']) ? '' : $post_expired['trackback'])->items(self::trackbackCombo()),
]); ]);
$fields['post_expired_password'] = (new Para())->items([
(new Checkbox('post_expired_password', !empty($post_expired['password'])))->value(1),
(new Label(__('Change password'), Label::OUTSIDE_LABEL_AFTER))->for('post_expired_password')->class('classic'),
(new Label(__('New password:'), Label::OUTSIDE_LABEL_BEFORE))->for('post_expired_newpassword'),
(new Input('post_expired_newpassword'))->size(65)->maxlenght(255)->class('maximal')->value(empty($post_expired['newpassword']) ? '' : $post_expired['newpassword']),
(new Note())->text(__('Leave empty to remove it'))->class('form-note'),
]);
if ($render) { if ($render) {
foreach ($fields as $k => $v) { foreach ($fields as $k => $v) {
$fields[$k] = $v->render(); $fields[$k] = $v->render();
@ -376,6 +358,11 @@ 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') => '',
@ -465,7 +452,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 = is_null(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') : '';
@ -480,7 +467,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 = is_null(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,18 +15,20 @@ declare(strict_types=1);
namespace Dotclear\Plugin\postExpired; namespace Dotclear\Plugin\postExpired;
use dcCore; use dcCore;
use Dotclear\Core\Process; use dcNsProcess;
class Frontend extends Process class Frontend extends dcNsProcess
{ {
public static function init(): bool public static function init(): bool
{ {
return self::status(My::checkContext(My::FRONTEND)); static::$init = true;
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!self::status()) { if (!static::$init) {
return false; return false;
} }
@ -38,7 +40,7 @@ class Frontend extends Process
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, 'publicBeforeDocumentV2'] [FrontendBehaviors::class, 'publicBeforeDocument']
); );
} }
dcCore::app()->addBehavior( dcCore::app()->addBehavior(

View File

@ -34,11 +34,16 @@ class FrontendBehaviors
/** /**
* Check if there are expired dates. * Check if there are expired dates.
*/ */
public static function publicBeforeDocumentV2(): void public static function publicBeforeDocument(): 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(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME)
->columns([ ->columns([
'P.post_id', 'P.post_id',
'P.post_tz', 'P.post_tz',
@ -56,7 +61,7 @@ class FrontendBehaviors
->select(); ->select();
// No expired date // No expired date
if (is_null($posts) || $posts->isEmpty()) { if ($posts->isEmpty()) {
return; return;
} }
@ -123,11 +128,6 @@ class FrontendBehaviors
case 'trackback': case 'trackback':
$post_cur->setField('post_open_tb', $v); $post_cur->setField('post_open_tb', $v);
break;
case 'password':
$post_cur->setField('post_password', empty($post_expired['newpassword']) ? '' : $post_expired['newpassword']);
break; break;
} }
} }

View File

@ -17,7 +17,6 @@ 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
@ -67,13 +66,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, Date::class . '::rfc822(strtotime(dcCore::app()->ctx->posts->postExpiredDate()),dcCore::app()->ctx->posts->post_tz)'); $res = sprintf($f, 'dt::rfc822(strtotime(dcCore::app()->ctx->posts->postExpiredDate()),dcCore::app()->ctx->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, 'dt::iso8601(strtotime(dcCore::app()->ctx->posts->postExpiredDate(),dcCore::app()->ctx->posts->post_tz)');
} elseif ($format) { } elseif ($format) {
$res = sprintf($f, Date::class . "::dt2str('" . $format . "',dcCore::app()->ctx->posts->postExpiredDate())"); $res = sprintf($f, "dt::dt2str('" . $format . "',dcCore::app()->ctx->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, 'dt::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 . '; } ?>';
@ -91,7 +90,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),
Date::class . '::dt2str(' . 'dt::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,23 +15,33 @@ declare(strict_types=1);
namespace Dotclear\Plugin\postExpired; namespace Dotclear\Plugin\postExpired;
use dcCore; use dcCore;
use Dotclear\Module\MyPlugin;
/** /**
* This module definiton. * Module definiton shortcut.
*/ */
class My extends MyPlugin class My
{ {
/** @var string This module meta type */ /** @var string This plugin meta type */
public const META_TYPE = 'post_expired'; public const META_TYPE = 'post_expired';
public static function checkCustomContext(int $context): ?bool /**
* This module id.
*
* @return string The module id
*/
public static function id(): string
{ {
return $context !== My::BACKEND ? null : return basename(dirname(__DIR__));
defined('DC_CONTEXT_ADMIN') }
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, /**
]), dcCore::app()->blog->id); * This module name.
*
* @return string The module translated name
*/
public static function name(): string
{
return __((string) dcCore::app()->plugins->moduleInfo(self::id(), 'name'));
} }
/** /**