upgrade to Dotclear 2.28

This commit is contained in:
Jean-Christian Paul Denis 2023-10-19 22:32:21 +02:00
parent 77e84f4ed8
commit a31b05e990
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
19 changed files with 277 additions and 386 deletions

View File

@ -1,3 +1,9 @@
periodical 2023.10.20
===========================================================
* Require Dotclear 2.28
* Require PHP 8.1
* Upgrade to Dotclear 2.28
periodical 2023.08.15 periodical 2023.08.15
=========================================================== ===========================================================
* Require Dotclear 2.27 * Require Dotclear 2.27

View File

@ -1,28 +1,25 @@
# README # README
[![Release](https://img.shields.io/badge/release-2023.08.15-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/periodical/releases) [![Release](https://img.shields.io/badge/release-2023.08.15-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/periodical/releases)
[![Date](https://img.shields.io/badge/date-2023.08.15-c44d58.svg)](https://git.dotclear.watch/JcDenis/periodical/releases) ![Date](https://img.shields.io/badge/date-2023.08.15-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/periodical) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/periodical)
[![License](https://img.shields.io/github/license/JcDenis/periodical)](https://git.dotclear.watch/JcDenis/periodical/blob/master/LICENSE) [![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/periodical/src/branch/master/LICENSE)
## WHAT IS PERIODICAL ? ## ABOUT
_Periodical_ is a plugin for the open-source _periodical_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org).
web publishing software called Dotclear.
You can manage and publish automatically lists of posts > Manage and publish automatically lists of posts
at regular periods. For exemple, you just need to add posts to a period at regular periods. For exemple, you just need to add posts to a period
and they will be publish ones after the others every week. and they will be publish ones after the others every week.
## REQUIREMENTS ## REQUIREMENTS
_periodical_ requires: * Dotclear 2.28
* admin permissions to configure plugin
* usage,contentadmin permissions to link feeds
* Dotclear 2.27
* PHP 8.1+ * PHP 8.1+
* Dotclear admin permissions to configure plugin
* Dotclear usage,contentadmin permissions to link feeds
## NOTICE ## NOTICE
@ -45,10 +42,11 @@ You can also add or remove period to multiple posts from posts actions page.
## LINKS ## LINKS
* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html) * [License](https://git.dotclear.watch/JcDenis/periodical/src/branch/master/LICENSE)
* Source & contribution : [Gitea Page](https://git.dotclear.watch/JcDenis/periodical) or [GitHub Page](https://github.com/JcDenis/periodical) * [Packages & details](https://git.dotclear.watch/JcDenis/periodical/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/periodical))
* Packages & details: [Gitea Page](https://git.dotclear.watch/JcDenis/periodical/releases) or [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/periodical) * [Sources & contributions](https://git.dotclear.watch/JcDenis/periodical) (or on [GitHub](https://github.com/JcDenis/periodical))
* Discuss & help : [Dotclear Forum](https://forum.dotclear.org/viewtopic.php?id=42289) * [Issues & security](https://git.dotclear.watch/JcDenis/periodical/issues) (or on [GitHub](https://github.com/JcDenis/periodical/issues))
* [Discuss & help](https://forum.dotclear.org/viewtopic.php?id=42289)
## CONTRIBUTORS ## CONTRIBUTORS

View File

@ -1,39 +1,30 @@
<?php <?php
/** /**
* @brief periodical, a plugin for Dotclear 2 * @file
* @brief The plugin periodical definition
* @ingroup periodical
* *
* @package Dotclear * @defgroup periodical Plugin periodical.
* @subpackage Plugin
* *
* @author Jean-Christian Denis and contributors * Published periodically entries.
* *
* @copyright Jean-Christian Denis * @author 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')) { declare(strict_types=1);
return null;
}
$this->registerModule( $this->registerModule(
'Periodical', 'Periodical',
'Published periodically entries', 'Published periodically entries',
'Jean-Christian Denis and contributors', 'Jean-Christian Denis and contributors',
'2023.08.15', '2023.10.20',
[ [
'requires' => [ 'requires' => [['core', '2.28']],
['php', '8.1'], 'permissions' => 'My',
['core', '2.27'], 'settings' => ['blog' => '#params.' . basename(__DIR__) . '_params'],
], 'type' => 'plugin',
'permissions' => dcCore::app()->auth->makePermissions([ 'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues',
dcCore::app()->auth::PERMISSION_USAGE, 'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md',
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, 'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml',
]),
'settings' => [
'blog' => '#params.' . basename(__DIR__) . '_params',
],
'type' => 'plugin',
'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues',
'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md',
'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml',
] ]
); );

View File

@ -1,21 +0,0 @@
<?php
/**
* @brief periodical, 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
*/
if (!defined('DC_RC_PATH')) {
return null;
}
class initPeriodical
{
// now use My::id()
public const PERIOD_TABLE_NAME = 'periodical';
}

View File

@ -2,11 +2,11 @@
<modules xmlns:da="http://dotaddict.org/da/"> <modules xmlns:da="http://dotaddict.org/da/">
<module id="periodical"> <module id="periodical">
<name>Periodical</name> <name>Periodical</name>
<version>2023.08.15</version> <version>2023.10.20</version>
<author>Jean-Christian Denis and contributors</author> <author>Jean-Christian Denis and contributors</author>
<desc>Published periodically entries</desc> <desc>Published periodically entries</desc>
<file>https://git.dotclear.watch/JcDenis/periodical/releases/download/v2023.08.15/plugin-periodical.zip</file> <file>https://git.dotclear.watch/JcDenis/periodical/releases/download/v2023.10.20/plugin-periodical.zip</file>
<da:dcmin>2.27</da:dcmin> <da:dcmin>2.28</da:dcmin>
<da:details>https://git.dotclear.watch/JcDenis/periodical/src/branch/master/README.md</da:details> <da:details>https://git.dotclear.watch/JcDenis/periodical/src/branch/master/README.md</da:details>
<da:support>https://git.dotclear.watch/JcDenis/periodical/issues</da:support> <da:support>https://git.dotclear.watch/JcDenis/periodical/issues</da:support>
</module> </module>

View File

@ -1,19 +1,10 @@
<?php <?php
/**
# -- BEGIN LICENSE BLOCK ---------------------------------- * @file
# * @brief The plugin periodical definition
# This file is part of periodical, a plugin for Dotclear 2. * @ingroup periodical
# *
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors * @author Jean-Christian Denis
# * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# Licensed under the GPL version 2.0 license. */
# A copy of this license is available in LICENSE file or at \Dotclear\App::backend()->resources()->set('help', 'periodical', __DIR__ . '/help/help.html');
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) {
return null;
}
dcCore::app()->resources['help']['periodical'] = __DIR__ . '/help/help.html';

View File

@ -1,19 +1,10 @@
<?php <?php
/**
# -- BEGIN LICENSE BLOCK ---------------------------------- * @file
# * @brief The plugin periodical definition
# This file is part of periodical, a plugin for Dotclear 2. * @ingroup periodical
# *
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors * @author Jean-Christian Denis
# * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# Licensed under the GPL version 2.0 license. */
# A copy of this license is available in LICENSE file or at \Dotclear\App::backend()->resources()->set('help', 'periodical', __DIR__ . '/help/help.html');
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) {
return null;
}
dcCore::app()->resources['help']['periodical'] = __DIR__ . '/help/help.html';

View File

@ -1,22 +1,19 @@
<?php <?php
/**
* @brief periodical, 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\periodical; namespace Dotclear\Plugin\periodical;
use dcCore; use Dotclear\App;
use Dotclear\Core\Process; use Dotclear\Core\Process;
/**
* @brief periodical backend class.
* @ingroup periodical
*
* @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
@ -31,14 +28,14 @@ class Backend extends Process
} }
// register backend behaviors // register backend behaviors
dcCore::app()->addBehaviors([ App::behavior()->addBehaviors([
'adminBlogPreferencesFormV2' => [BackendBehaviors::class, 'adminBlogPreferencesFormV2'], 'adminBlogPreferencesFormV2' => BackendBehaviors::adminBlogPreferencesFormV2(...),
'adminBeforeBlogSettingsUpdate' => [BackendBehaviors::class, 'adminBeforeBlogSettingsUpdate'], 'adminBeforeBlogSettingsUpdate' => BackendBehaviors::adminBeforeBlogSettingsUpdate(...),
'adminFiltersListsV2' => [BackendBehaviors::class, 'adminFiltersListsV2'], 'adminFiltersListsV2' => BackendBehaviors::adminFiltersListsV2(...),
'adminColumnsListsV2' => [BackendBehaviors::class, 'adminColumnsListsV2'], 'adminColumnsListsV2' => BackendBehaviors::adminColumnsListsV2(...),
'adminPostListHeaderV2' => [BackendBehaviors::class, 'adminPostListHeaderV2'], 'adminPostListHeaderV2' => BackendBehaviors::adminPostListHeaderV2(...),
'adminPostListValueV2' => [BackendBehaviors::class, 'adminPostListValueV2'], 'adminPostListValueV2' => BackendBehaviors::adminPostListValueV2(...),
'adminBeforePostDelete' => [BackendBehaviors::class, 'adminBeforePostDelete'], 'adminBeforePostDelete' => BackendBehaviors::adminBeforePostDelete(...),
]); ]);
if (My::settings()->get('periodical_active')) { if (My::settings()->get('periodical_active')) {
@ -46,13 +43,13 @@ class Backend extends Process
My::addBackendMenuItem(); My::addBackendMenuItem();
// register bakend behaviors required user permissions // register bakend behaviors required user permissions
dcCore::app()->addBehaviors([ App::behavior()->addBehaviors([
'adminDashboardFavoritesV2' => [BackendBehaviors::class, 'adminDashboardFavoritesV2'], 'adminDashboardFavoritesV2' => BackendBehaviors::adminDashboardFavoritesV2(...),
'adminPostHeaders' => [BackendBehaviors::class, 'adminPostHeaders'], 'adminPostHeaders' => BackendBehaviors::adminPostHeaders(...),
'adminPostsActions' => [BackendBehaviors::class, 'adminPostsActions'], 'adminPostsActions' => BackendBehaviors::adminPostsActions(...),
'adminPostFormItems' => [BackendBehaviors::class, 'adminPostFormItems'], 'adminPostFormItems' => BackendBehaviors::adminPostFormItems(...),
'adminAfterPostUpdate' => [BackendBehaviors::class, 'adminAfterPostSave'], 'adminAfterPostUpdate' => BackendBehaviors::adminAfterPostSave(...),
'adminAfterPostCreate' => [BackendBehaviors::class, 'adminAfterPostSave'], 'adminAfterPostCreate' => BackendBehaviors::adminAfterPostSave(...),
]); ]);
} }

View File

@ -1,22 +1,11 @@
<?php <?php
/**
* @brief periodical, 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\periodical; namespace Dotclear\Plugin\periodical;
use ArrayObject; use ArrayObject;
use dcCore; use Dotclear\App;
use dcSettings;
use Dotclear\Core\Backend\{ use Dotclear\Core\Backend\{
Favorites, Favorites,
Notices, Notices,
@ -39,12 +28,15 @@ use Dotclear\Helper\Html\Form\{
Text Text
}; };
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Dotclear\Interface\Core\BlogSettingsInterface;
use Exception; use Exception;
/** /**
* @ingroup DC_PLUGIN_PERIODICAL * @brief periodical backend behaviors class.
* @brief Periodical - admin methods. * @ingroup periodical
* @since 2.6 *
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class BackendBehaviors class BackendBehaviors
{ {
@ -53,9 +45,9 @@ class BackendBehaviors
/** /**
* Add settings to blog preference. * Add settings to blog preference.
* *
* @param dcSettings $blog_settings dcSettings instance * @param BlogSettingsInterface $blog_settings BlogSettingsInterface instance
*/ */
public static function adminBlogPreferencesFormV2(dcSettings $blog_settings): void public static function adminBlogPreferencesFormV2(BlogSettingsInterface $blog_settings): void
{ {
$s = $blog_settings->get(My::id()); $s = $blog_settings->get(My::id());
@ -87,9 +79,9 @@ class BackendBehaviors
/** /**
* Save blog settings. * Save blog settings.
* *
* @param dcSettings $blog_settings dcSettings instance * @param BlogSettingsInterface $blog_settings BlogSettingsInterface instance
*/ */
public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings): void public static function adminBeforeBlogSettingsUpdate(BlogSettingsInterface $blog_settings): void
{ {
$blog_settings->get(My::id())->put('periodical_active', !empty($_POST['periodical_active'])); $blog_settings->get(My::id())->put('periodical_active', !empty($_POST['periodical_active']));
$blog_settings->get(My::id())->put('periodical_upddate', !empty($_POST['periodical_upddate'])); $blog_settings->get(My::id())->put('periodical_upddate', !empty($_POST['periodical_upddate']));
@ -180,9 +172,9 @@ class BackendBehaviors
'url' => My::manageUrl(), 'url' => My::manageUrl(),
'small-icon' => My::icons(), 'small-icon' => My::icons(),
'large-icon' => My::icons(), 'large-icon' => My::icons(),
'permissions' => dcCore::app()->auth->makePermissions([ 'permissions' => App::auth()->makePermissions([
dcCore::app()->auth::PERMISSION_USAGE, App::auth()::PERMISSION_USAGE,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, App::auth()::PERMISSION_CONTENT_ADMIN,
]), ]),
]); ]);
} }
@ -216,16 +208,16 @@ class BackendBehaviors
{ {
$pa->addAction( $pa->addAction(
[My::name() => [__('Add to periodical') => 'periodical_add']], [My::name() => [__('Add to periodical') => 'periodical_add']],
[self::class, 'callbackAdd'] self::callbackAdd(...)
); );
if (dcCore::app()->auth?->check(dcCore::app()->auth->makePermissions([ if (App::auth()->check(App::auth()->makePermissions([
dcCore::app()->auth::PERMISSION_DELETE, App::auth()::PERMISSION_DELETE,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, App::auth()::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog?->id)) { ]), App::blog()->id())) {
$pa->addAction( $pa->addAction(
[My::name() => [__('Remove from periodical') => 'periodical_remove']], [My::name() => [__('Remove from periodical') => 'periodical_remove']],
[self::class, 'callbackRemove'] self::callbackRemove(...)
); );
} }
} }
@ -245,10 +237,10 @@ class BackendBehaviors
} }
// No right // No right
if (!dcCore::app()->auth?->check(dcCore::app()->auth->makePermissions([ if (!App::auth()->check(App::auth()->makePermissions([
dcCore::app()->auth::PERMISSION_DELETE, App::auth()::PERMISSION_DELETE,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, App::auth()::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog?->id)) { ]), App::blog()->id())) {
throw new Exception(__('No enough right')); throw new Exception(__('No enough right'));
} }
@ -292,9 +284,9 @@ class BackendBehaviors
else { else {
$pa->beginPage( $pa->beginPage(
Page::breadcrumb([ Page::breadcrumb([
Html::escapeHTML((string) dcCore::app()->blog?->name) => '', Html::escapeHTML(App::blog()->name()) => '',
$pa->getCallerTitle() => $pa->getRedirection(true), $pa->getCallerTitle() => $pa->getRedirection(true),
__('Add a period to this selection') => '', __('Add a period to this selection') => '',
]) ])
); );
@ -302,14 +294,12 @@ class BackendBehaviors
(new Form('periodicaladd'))->method('post')->action($pa->getURI())->fields([ (new Form('periodicaladd'))->method('post')->action($pa->getURI())->fields([
(new Text('', $pa->getCheckboxes())), (new Text('', $pa->getCheckboxes())),
self::formPeriod(0), self::formPeriod(0),
(new Para())->items(array_merge( (new Para())->items([
[ App::nonce()->formNonce(),
dcCore::app()->formNonce(false), (new Hidden(['action'], 'periodical_add')),
(new Hidden(['action'], 'periodical_add')), (new Submit(['do']))->value(__('Save')),
(new Submit(['do']))->value(__('Save')), ... $pa->hiddenFields(),
], ]),
$pa->hiddenFields()
)),
])->render(); ])->render();
$pa->endPage(); $pa->endPage();

View File

@ -1,25 +1,21 @@
<?php <?php
/**
* @brief periodical, 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\periodical; namespace Dotclear\Plugin\periodical;
use DateTimeZone; use DateTimeZone;
use dcCore; use Dotclear\App;
use Exception; use Exception;
/** /**
* @brief periodical date helper.
* @ingroup periodical
*
* Tools to manupilate period date * Tools to manupilate period date
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Dater class Dater
{ {
@ -33,7 +29,7 @@ class Dater
*/ */
public static function fromUser(string $date, string $format = 'Y-m-d H:i:00'): string public static function fromUser(string $date, string $format = 'Y-m-d H:i:00'): string
{ {
$tz = dcCore::app()->auth?->getInfo('user_tz'); $tz = App::auth()->getInfo('user_tz');
$d = date_create($date, new DateTimeZone($tz ?? 'UTC')); $d = date_create($date, new DateTimeZone($tz ?? 'UTC'));
return $d ? date_format($d->setTimezone(new DateTimeZone('UTC')), $format) : ''; return $d ? date_format($d->setTimezone(new DateTimeZone('UTC')), $format) : '';
@ -49,7 +45,7 @@ class Dater
*/ */
public static function toUser(string $date, string $format = 'Y-m-d\TH:i'): string public static function toUser(string $date, string $format = 'Y-m-d\TH:i'): string
{ {
$tz = dcCore::app()->auth?->getInfo('user_tz'); $tz = 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($tz ?? 'UTC')), $format) : ''; return $d ? date_format($d->setTimezone(new DateTimeZone($tz ?? 'UTC')), $format) : '';

View File

@ -1,32 +1,25 @@
<?php <?php
/**
* @brief periodical, 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\periodical; namespace Dotclear\Plugin\periodical;
use dcBlog; use Dotclear\App;
use dcCore;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Exception; use Exception;
/** /**
* Update posts from periods on frontend * @brief periodical frontend class.
* @ingroup periodical
*
* @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
{ {
return self::status(My::checkContext(My::FRONTEND) && in_array(dcCore::app()->url->type, ['default', 'feed'])); return self::status(My::checkContext(My::FRONTEND) && in_array((string) App::url()->type, ['default', 'feed']));
} }
public static function process(): bool public static function process(): bool
@ -35,8 +28,8 @@ class Frontend extends Process
return false; return false;
} }
dcCore::app()->addBehavior('publicBeforeDocumentV2', function (): void { App::behavior()->addBehavior('publicBeforeDocumentV2', function (): void {
if (is_null(dcCore::app()->blog)) { if (!App::blog()->isDefined()) {
return; return;
} }
@ -46,7 +39,7 @@ class Frontend extends Process
Utils::lockUpdate(); Utils::lockUpdate();
// Get periods // Get periods
$periods = dcCore::app()->auth->sudo([Utils::class, 'getPeriods']); $periods = App::auth()->sudo(Utils::getPeriods(...));
// No period // No period
if ($periods->isEmpty()) { if ($periods->isEmpty()) {
@ -60,7 +53,7 @@ class Frontend extends Process
if (!preg_match('/^(post_dt|post_creadt|post_id) (asc|desc)$/', $posts_order)) { if (!preg_match('/^(post_dt|post_creadt|post_id) (asc|desc)$/', $posts_order)) {
$posts_order = 'post_dt asc'; $posts_order = 'post_dt asc';
} }
$cur_period = dcCore::app()->con->openCursor(dcCore::app()->prefix . My::id()); $cur_period = App::con()->openCursor(App::con()->prefix() . My::id());
while ($periods->fetch()) { while ($periods->fetch()) {
// Check if period is ongoing // Check if period is ongoing
@ -89,19 +82,19 @@ class Frontend extends Process
// Get posts to publish related to this period // Get posts to publish related to this period
$posts_params = []; $posts_params = [];
$posts_params['periodical_id'] = $periods->f('periodical_id'); $posts_params['periodical_id'] = $periods->f('periodical_id');
$posts_params['post_status'] = dcBlog::POST_PENDING; $posts_params['post_status'] = App::blog()::POST_PENDING;
$posts_params['order'] = $posts_order; $posts_params['order'] = $posts_order;
$posts_params['limit'] = $limit * $max_nb; $posts_params['limit'] = $limit * $max_nb;
$posts_params['no_content'] = true; $posts_params['no_content'] = true;
$posts = dcCore::app()->auth->sudo([Utils::class, 'getPosts'], $posts_params); $posts = App::auth()->sudo(Utils::getPosts(...), $posts_params);
if (!$posts->isEmpty()) { if (!$posts->isEmpty()) {
$cur_post = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME); $cur_post = App::blgo()->openPostCursor();
while ($posts->fetch()) { while ($posts->fetch()) {
// Publish post with right date // Publish post with right date
$cur_post->clean(); $cur_post->clean();
$cur_post->setField('post_status', dcBlog::POST_PUBLISHED); $cur_post->setField('post_status', App::blog()::POST_PUBLISHED);
// Update post date with right date // Update post date with right date
if ($s->get('periodical_upddate')) { if ($s->get('periodical_upddate')) {
@ -112,7 +105,7 @@ class Frontend extends Process
// Also update post url with right date // Also update post url with right date
if ($s->get('periodical_updurl')) { if ($s->get('periodical_updurl')) {
$cur_post->setField('post_url', dcCore::app()->blog->getPostURL( $cur_post->setField('post_url', App::blog()->getPostURL(
'', '',
$cur_post->getField('post_dt'), $cur_post->getField('post_dt'),
$posts->f('post_title'), $posts->f('post_title'),
@ -122,7 +115,7 @@ class Frontend extends Process
$cur_post->update( $cur_post->update(
'WHERE post_id = ' . $posts->f('post_id') . ' ' . 'WHERE post_id = ' . $posts->f('post_id') . ' ' .
"AND blog_id = '" . dcCore::app()->con->escapeStr(dcCore::app()->blog->id) . "' " "AND blog_id = '" . App::con()->escapeStr(App::blog()->id()) . "' "
); );
// Delete post relation to this period // Delete post relation to this period
@ -137,9 +130,9 @@ class Frontend extends Process
} }
// --BEHAVIOR-- periodicalAfterPublishedPeriodicalEntry // --BEHAVIOR-- periodicalAfterPublishedPeriodicalEntry
dcCore::app()->callBehavior('periodicalAfterPublishedPeriodicalEntry', $posts, $periods); App::behavior()->callBehavior('periodicalAfterPublishedPeriodicalEntry', $posts, $periods);
} }
dcCore::app()->blog->triggerBlog(); App::blog()->triggerBlog();
} }
} }
@ -148,7 +141,7 @@ class Frontend extends Process
$cur_period->setField('periodical_curdt', Dater::toDate($loop_ts, 'Y-m-d H:i:00')); $cur_period->setField('periodical_curdt', Dater::toDate($loop_ts, 'Y-m-d H:i:00'));
$cur_period->update( $cur_period->update(
'WHERE periodical_id = ' . $periods->f('periodical_id') . ' ' . 'WHERE periodical_id = ' . $periods->f('periodical_id') . ' ' .
"AND blog_id = '" . dcCore::app()->con->escapeStr(dcCore::app()->blog->id) . "' " "AND blog_id = '" . App::con()->escapeStr(App::blog()->id()) . "' "
); );
} }
} }

View File

@ -1,24 +1,21 @@
<?php <?php
/**
* @brief periodical, 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\periodical; namespace Dotclear\Plugin\periodical;
use dcCore; use Dotclear\App;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Database\Structure; use Dotclear\Database\Structure;
use Exception; use Exception;
/**
* @brief periodical insatll class.
* @ingroup periodical
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Install extends Process class Install extends Process
{ {
public static function init(): bool public static function init(): bool
@ -33,7 +30,7 @@ class Install extends Process
} }
try { try {
$t = new Structure(dcCore::app()->con, dcCore::app()->prefix); $t = new Structure(App::con(), App::con()->prefix());
// create database table // create database table
$t->__get(My::id()) $t->__get(My::id())
@ -49,7 +46,7 @@ class Install extends Process
->primary('pk_periodical', 'periodical_id') ->primary('pk_periodical', 'periodical_id')
->index('idx_periodical_type', 'btree', 'periodical_type'); ->index('idx_periodical_type', 'btree', 'periodical_type');
(new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($t); (new Structure(App::con(), App::con()->prefix()))->synchronize($t);
// set default settings // set default settings
$s = My::settings(); $s = My::settings();
@ -60,7 +57,7 @@ class Install extends Process
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); App::error()->add($e->getMessage());
return false; return false;
} }

View File

@ -1,20 +1,10 @@
<?php <?php
/**
* @brief periodical, 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\periodical; namespace Dotclear\Plugin\periodical;
use dcCore; use Dotclear\App;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Core\Backend\{ use Dotclear\Core\Backend\{
Notices, Notices,
@ -29,7 +19,11 @@ use Dotclear\Helper\Network\Http;
use Exception; use Exception;
/** /**
* Admin page for periods * @brief periodical manage periods class.
* @ingroup periodical
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Manage extends Process class Manage extends Process
{ {
@ -77,7 +71,7 @@ class Manage extends Process
My::redirect(['part' => 'periods']); My::redirect(['part' => 'periods']);
} }
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); App::error()->add($e->getMessage());
} }
} }
@ -98,7 +92,7 @@ class Manage extends Process
My::redirect(['part' => 'periods']); My::redirect(['part' => 'periods']);
} }
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); App::error()->add($e->getMessage());
} }
} }
@ -133,7 +127,7 @@ class Manage extends Process
$counter = Utils::getPeriods($params, true); $counter = Utils::getPeriods($params, true);
$period_list = new ManageList($periods, $counter->f(0)); $period_list = new ManageList($periods, $counter->f(0));
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); App::error()->add($e->getMessage());
} }
// Display // Display
@ -150,7 +144,7 @@ class Manage extends Process
Notices::getNotices() . Notices::getNotices() .
'<p class="top-add"> '<p class="top-add">
<a class="button add" href="' . dcCore::app()->admin->getPageURL() . '&amp;part=period">' . __('New period') . '</a> <a class="button add" href="' . My::manageUrl(['part' => 'period']) . '">' . __('New period') . '</a>
</p>'; </p>';
if (isset($period_list)) { if (isset($period_list)) {
@ -160,7 +154,7 @@ class Manage extends Process
// Periods list // Periods list
$period_list->periodDisplay( $period_list->periodDisplay(
$p_filter, $p_filter,
'<form action="' . dcCore::app()->admin->getPageURL() . '" method="post" id="form-periods">' . '<form action="' . My::manageUrl() . '" method="post" id="form-periods">' .
'%s' . '%s' .

View File

@ -1,22 +1,11 @@
<?php <?php
/**
* @brief periodical, 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\periodical; namespace Dotclear\Plugin\periodical;
use ArrayObject; use ArrayObject;
use dcBlog; use Dotclear\App;
use dcCore;
use Dotclear\Core\Backend\Filter\{ use Dotclear\Core\Backend\Filter\{
Filters, Filters,
FilterPosts FilterPosts
@ -30,9 +19,11 @@ use Dotclear\Helper\Html\Form\Checkbox;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
/** /**
* @ingroup DC_PLUGIN_PERIODICAL * @brief periodical periods list class.
* @brief Periodical - admin pager methods. * @ingroup periodical
* @since 2.6 *
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class ManageList extends Listing class ManageList extends Listing
{ {
@ -101,7 +92,7 @@ class ManageList extends Listing
*/ */
private function periodLine(bool $checked): void private function periodLine(bool $checked): void
{ {
$tz = dcCore::app()->auth?->getInfo('user_tz'); $tz = App::auth()->getInfo('user_tz');
$nb_posts = Utils::getPosts(['periodical_id' => $this->rs->f('periodical_id')], true)->f(0); $nb_posts = Utils::getPosts(['periodical_id' => $this->rs->f('periodical_id')], true)->f(0);
$url = My::manageUrl(['part' => 'period', 'period_id' => $this->rs->f('periodical_id')]); $url = My::manageUrl(['part' => 'period', 'period_id' => $this->rs->f('periodical_id')]);
$name = '<a href="' . $url . '#period" title="' . __('edit period') . '">' . Html::escapeHTML($this->rs->periodical_title) . '</a>'; $name = '<a href="' . $url . '#period" title="' . __('edit period') . '">' . Html::escapeHTML($this->rs->periodical_title) . '</a>';
@ -203,7 +194,7 @@ class ManageList extends Listing
*/ */
private function postLine(bool $checked): void private function postLine(bool $checked): void
{ {
if (dcCore::app()->auth?->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CATEGORIES]), dcCore::app()->blog?->id)) { if (App::auth()->check(App::auth()->makePermissions([App::auth()::PERMISSION_CATEGORIES]), App::blog()->id())) {
$cat_link = '<a href="category.php?id=%s">%s</a>'; $cat_link = '<a href="category.php?id=%s">%s</a>';
} else { } else {
$cat_link = '%2$s'; $cat_link = '%2$s';
@ -222,22 +213,22 @@ class ManageList extends Listing
$img_status = ''; $img_status = '';
$img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
switch ((int) $this->rs->f('post_status')) { switch ((int) $this->rs->f('post_status')) {
case dcBlog::POST_PUBLISHED: case App::blog()::POST_PUBLISHED:
$img_status = sprintf($img, __('published'), 'check-on.png'); $img_status = sprintf($img, __('published'), 'check-on.png');
break; break;
case dcBlog::POST_UNPUBLISHED: case App::blog()::POST_UNPUBLISHED:
$img_status = sprintf($img, __('unpublished'), 'check-off.png'); $img_status = sprintf($img, __('unpublished'), 'check-off.png');
break; break;
case dcBlog::POST_SCHEDULED: case App::blog()::POST_SCHEDULED:
$img_status = sprintf($img, __('scheduled'), 'scheduled.png'); $img_status = sprintf($img, __('scheduled'), 'scheduled.png');
break; break;
case dcBlog::POST_PENDING: case App::blog()::POST_PENDING:
$img_status = sprintf($img, __('pending'), 'check-wrn.png'); $img_status = sprintf($img, __('pending'), 'check-wrn.png');
break; break;
@ -260,11 +251,11 @@ class ManageList extends Listing
$attach = sprintf($img, sprintf($attach_str, $nb_media), 'attach.png'); $attach = sprintf($img, sprintf($attach_str, $nb_media), 'attach.png');
} }
$tz = dcCore::app()->auth?->getInfo('user_tz'); $tz = App::auth()->getInfo('user_tz');
$cols = [ $cols = [
'check' => '<td class="minimal">' . (new Checkbox(['periodical_entries[]'], $checked))->value($this->rs->f('post_id'))->render() . '</td>', 'check' => '<td class="minimal">' . (new Checkbox(['periodical_entries[]'], $checked))->value($this->rs->f('post_id'))->render() . '</td>',
'title' => '<td class="maximal"><a href="' . dcCore::app()->getPostAdminURL($this->rs->f('post_type'), $this->rs->f('post_id')) . '" ' . 'title' => '<td class="maximal"><a href="' . App::postTypes()->getPostAdminURL($this->rs->f('post_type'), $this->rs->f('post_id')) . '" ' .
'title="' . Html::escapeHTML($this->rs->getURL()) . '">' . Html::escapeHTML($this->rs->post_title) . '</a></td>', 'title="' . Html::escapeHTML($this->rs->getURL()) . '">' . Html::escapeHTML($this->rs->post_title) . '</a></td>',
'date' => '<td class="nowrap">' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('post_dt')) . '</td>', 'date' => '<td class="nowrap">' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->f('post_dt')) . '</td>',
'category' => '<td class="nowrap">' . $cat_title . '</td>', 'category' => '<td class="nowrap">' . $cat_title . '</td>',

View File

@ -14,7 +14,7 @@ declare(strict_types=1);
namespace Dotclear\Plugin\periodical; namespace Dotclear\Plugin\periodical;
use dcCore; use Dotclear\App;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Core\Backend\{ use Dotclear\Core\Backend\{
Notices, Notices,
@ -39,7 +39,11 @@ use Dotclear\Helper\Network\Http;
use Exception; use Exception;
/** /**
* Admin page for a period * @brief periodical manage a period class.
* @ingroup periodical
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class ManagePeriod extends Process class ManagePeriod extends Process
{ {
@ -54,7 +58,7 @@ class ManagePeriod extends Process
return false; return false;
} }
if (is_null(dcCore::app()->blog)) { if (!App::blog()->isDefined()) {
return false; return false;
} }
@ -63,13 +67,13 @@ class ManagePeriod extends Process
// Get period // Get period
if ($vars->bad_period_id) { if ($vars->bad_period_id) {
dcCore::app()->error->add(__('This period does not exist.')); App::error()->add(__('This period does not exist.'));
} }
// Set period // Set period
if ($vars->action == 'setperiod') { if ($vars->action == 'setperiod') {
if ($vars->bad_period_curdt || $vars->bad_period_enddt) { if ($vars->bad_period_curdt || $vars->bad_period_enddt) {
dcCore::app()->error->add(__('Invalid date')); App::error()->add(__('Invalid date'));
} }
// Check period title and dates // Check period title and dates
@ -79,19 +83,19 @@ class ManagePeriod extends Process
if (!$old_titles->isEmpty()) { if (!$old_titles->isEmpty()) {
while ($old_titles->fetch()) { while ($old_titles->fetch()) {
if (!$vars->period_id || $old_titles->f('periodical_id') != $vars->period_id) { if (!$vars->period_id || $old_titles->f('periodical_id') != $vars->period_id) {
dcCore::app()->error->add(__('Period title is already taken')); App::error()->add(__('Period title is already taken'));
} }
} }
} }
if (empty($vars->period_title)) { if (empty($vars->period_title)) {
dcCore::app()->error->add(__('Period title is required')); App::error()->add(__('Period title is required'));
} }
if (strtotime($vars->period_curdt) > strtotime($vars->period_enddt)) { if (strtotime($vars->period_curdt) > strtotime($vars->period_enddt)) {
dcCore::app()->error->add(__('Start date must be older than end date')); App::error()->add(__('Start date must be older than end date'));
} }
// If no error, set period // If no error, set period
if (!dcCore::app()->error->flag()) { if (!App::error()->flag()) {
$cur = Utils::openCursor(); $cur = Utils::openCursor();
$cur->setField('periodical_title', $vars->period_title); $cur->setField('periodical_title', $vars->period_title);
$cur->setField('periodical_curdt', $vars->period_curdt); $cur->setField('periodical_curdt', $vars->period_curdt);
@ -114,18 +118,18 @@ class ManagePeriod extends Process
} }
// Actions on related posts // Actions on related posts
if (!dcCore::app()->error->flag() && $vars->period_id && $vars->action && !empty($vars->entries)) { if (!App::error()->flag() && $vars->period_id && $vars->action && !empty($vars->entries)) {
// Publish posts // Publish posts
if ($vars->action == 'publish') { if ($vars->action == 'publish') {
try { try {
foreach ($vars->entries as $id) { foreach ($vars->entries as $id) {
dcCore::app()->blog->updPostStatus($id, 1); App::blog()->updPostStatus($id, 1);
Utils::delPost($id); Utils::delPost($id);
} }
self::redirect($vars->redir, $vars->period_id, '#posts', __('Entries successfully published.')); self::redirect($vars->redir, $vars->period_id, '#posts', __('Entries successfully published.'));
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); App::error()->add($e->getMessage());
} }
} }
@ -133,13 +137,13 @@ class ManagePeriod extends Process
if ($vars->action == 'unpublish') { if ($vars->action == 'unpublish') {
try { try {
foreach ($vars->entries as $id) { foreach ($vars->entries as $id) {
dcCore::app()->blog->updPostStatus($id, 0); App::blog()->updPostStatus($id, 0);
Utils::delPost($id); Utils::delPost($id);
} }
self::redirect($vars->redir, $vars->period_id, '#posts', __('Entries successfully unpublished.')); self::redirect($vars->redir, $vars->period_id, '#posts', __('Entries successfully unpublished.'));
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); App::error()->add($e->getMessage());
} }
} }
@ -152,7 +156,7 @@ class ManagePeriod extends Process
self::redirect($vars->redir, $vars->period_id, '#posts', __('Entries successfully removed.')); self::redirect($vars->redir, $vars->period_id, '#posts', __('Entries successfully removed.'));
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); App::error()->add($e->getMessage());
} }
} }
} }
@ -190,7 +194,7 @@ class ManagePeriod extends Process
$counter = Utils::getPosts($params, true); $counter = Utils::getPosts($params, true);
$post_list = new ManageList($posts, $counter->f(0)); $post_list = new ManageList($posts, $counter->f(0));
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); App::error()->add($e->getMessage());
} }
$starting_script = My::jsLoad('checkbox') . $starting_script = My::jsLoad('checkbox') .
@ -209,7 +213,7 @@ class ManagePeriod extends Process
echo echo
Page::breadcrumb([ Page::breadcrumb([
__('Plugins') => '', __('Plugins') => '',
My::name() => dcCore::app()->admin->getPageURL() . '&amp;part=periods', My::name() => App::backend()->getPageURL() . '&amp;part=periods',
(null === $vars->period_id ? __('New period') : __('Edit period')) => '', (null === $vars->period_id ? __('New period') : __('Edit period')) => '',
]) . ]) .
Notices::getNotices(); Notices::getNotices();
@ -218,7 +222,7 @@ class ManagePeriod extends Process
echo echo
(new Div('period'))->items([ (new Div('period'))->items([
(new Text('h3', null === $vars->period_id ? __('New period') : __('Edit period'))), (new Text('h3', null === $vars->period_id ? __('New period') : __('Edit period'))),
(new Form('periodicalbhv'))->method('post')->action(dcCore::app()->admin->getPageURL())->fields([ (new Form('periodicalbhv'))->method('post')->action(App::backend()->getPageURL())->fields([
(new Para())->items([ (new Para())->items([
(new Label(__('Title:')))->for('period_title'), (new Label(__('Title:')))->for('period_title'),
(new Input('period_title'))->size(65)->maxlenght(255)->class('maximal')->value(Html::escapeHTML($vars->period_title)), (new Input('period_title'))->size(65)->maxlenght(255)->class('maximal')->value(Html::escapeHTML($vars->period_title)),
@ -258,8 +262,8 @@ class ManagePeriod extends Process
]), ]),
])->render(); ])->render();
if ($vars->period_id && isset($post_filter) && isset($post_list) && !dcCore::app()->error->flag()) { if ($vars->period_id && isset($post_filter) && isset($post_list) && !App::error()->flag()) {
$base_url = dcCore::app()->admin->getPageURL() . $base_url = App::backend()->getPageURL() .
'&amp;period_id=' . $vars->period_id . '&amp;period_id=' . $vars->period_id .
'&amp;part=period' . '&amp;part=period' .
'&amp;user_id=' . $post_filter->value('user_id', '') . '&amp;user_id=' . $post_filter->value('user_id', '') .
@ -291,7 +295,7 @@ class ManagePeriod extends Process
$post_list->postDisplay( $post_list->postDisplay(
$post_filter, $post_filter,
$base_url, $base_url,
'<form action="' . dcCore::app()->admin->getPageURL() . '" method="post" id="form-entries">' . '<form action="' . App::backend()->getPageURL() . '" method="post" id="form-entries">' .
'%s' . '%s' .

View File

@ -1,21 +1,15 @@
<?php <?php
/**
* @brief periodical, 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\periodical; namespace Dotclear\Plugin\periodical;
/** /**
* Admin page vars * @brief periodical vars helper class.
* @ingroup periodical
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class ManageVars class ManageVars
{ {

View File

@ -1,37 +1,32 @@
<?php <?php
/**
* @brief periodical, 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\periodical; namespace Dotclear\Plugin\periodical;
use dcCore; use Dotclear\App;
use Dotclear\Module\MyPlugin; use Dotclear\Module\MyPlugin;
/** /**
* This module definitions. * @brief periodical My helper.
* @ingroup periodical
*
* @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
{ {
public static function checkCustomContext(int $context): ?bool public static function checkCustomContext(int $context): ?bool
{ {
return in_array($context, [My::MANAGE, My::MENU]) ? return match ($context) {
defined('DC_CONTEXT_ADMIN') self::MANAGE, self::MENU => App::task()->checkContext('BACKEND')
&& !is_null(dcCore::app()->blog) && App::auth()->check(App::auth()->makePermissions([
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ App::auth()::PERMISSION_USAGE,
dcCore::app()->auth::PERMISSION_USAGE, App::auth()::PERMISSION_CONTENT_ADMIN,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, ]), App::blog()->id()),
]), dcCore::app()->blog->id)
: null; default => null,
};
} }
/** /**

View File

@ -1,23 +1,19 @@
<?php <?php
/**
* @brief periodical, 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\periodical; namespace Dotclear\Plugin\periodical;
use dcCore;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Plugin\Uninstaller\Uninstaller; use Dotclear\Plugin\Uninstaller\Uninstaller;
/**
* @brief periodical uninstall class.
* @ingroup periodical
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Uninstall extends Process class Uninstall extends Process
{ {
public static function init(): bool public static function init(): bool
@ -27,7 +23,7 @@ class Uninstall extends Process
public static function process(): bool public static function process(): bool
{ {
if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) { if (!self::status()) {
return false; return false;
} }

View File

@ -1,23 +1,11 @@
<?php <?php
/**
* @brief periodical, 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\periodical; namespace Dotclear\Plugin\periodical;
use ArrayObject; use ArrayObject;
use dcBlog; use Dotclear\App;
use dcCore;
use dcMeta;
use Dotclear\Database\{ use Dotclear\Database\{
Cursor, Cursor,
MetaRecord MetaRecord
@ -34,7 +22,11 @@ use Dotclear\Helper\File\{
use Exception; use Exception;
/** /**
* Manage periodical records * @brief periodical utils class.
* @ingroup periodical
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Utils class Utils
{ {
@ -48,7 +40,7 @@ class Utils
*/ */
public static function openCursor(): Cursor public static function openCursor(): Cursor
{ {
return dcCore::app()->con->openCursor(dcCore::app()->prefix . My::id()); return App::con()->openCursor(App::con()->prefix() . My::id());
} }
/** /**
@ -82,7 +74,7 @@ class Utils
]); ]);
} }
$sql->from($sql->as(dcCore::app()->prefix . My::id(), 'T'), false, true); $sql->from($sql->as(App::con()->prefix() . My::id(), 'T'), false, true);
if (!empty($params['join'])) { if (!empty($params['join'])) {
$sql->join($params['join']); $sql->join($params['join']);
@ -94,9 +86,9 @@ class Utils
if (!empty($params['where'])) { if (!empty($params['where'])) {
$sql->where($params['where']); $sql->where($params['where']);
$sql->and('T.blog_id = ' . $sql->quote((string) dcCore::app()->blog?->id)); $sql->and('T.blog_id = ' . $sql->quote(App::blog()->id()));
} else { } else {
$sql->where('T.blog_id = ' . $sql->quote((string) dcCore::app()->blog?->id)); $sql->where('T.blog_id = ' . $sql->quote(App::blog()->id()));
} }
if (isset($params['periodical_type'])) { if (isset($params['periodical_type'])) {
@ -136,9 +128,7 @@ class Utils
$sql->limit($params['limit']); $sql->limit($params['limit']);
} }
$rs = $sql->select(); return $sql->select() ?? MetaRecord::newFromArray([]);
return is_null($rs) ? MetaRecord::newFromArray([]) : $rs;
} }
/** /**
@ -150,12 +140,12 @@ class Utils
*/ */
public static function addPeriod(Cursor $cur): int public static function addPeriod(Cursor $cur): int
{ {
dcCore::app()->con->writeLock(dcCore::app()->prefix . My::id()); App::con()->writeLock(App::con()->prefix() . My::id());
try { try {
// get next id // get next id
$sql = new SelectStatement(); $sql = new SelectStatement();
$rs = $sql->from(dcCore::app()->prefix . My::id()) $rs = $sql->from(App::con()->prefix() . My::id())
->column($sql->max('periodical_id')) ->column($sql->max('periodical_id'))
->select(); ->select();
@ -163,12 +153,12 @@ class Utils
// insert // insert
$cur->setField('periodical_id', $id); $cur->setField('periodical_id', $id);
$cur->setField('blog_id', (string) dcCore::app()->blog?->id); $cur->setField('blog_id', App::blog()->id());
$cur->setField('periodical_type', 'post'); $cur->setField('periodical_type', 'post');
$cur->insert(); $cur->insert();
dcCore::app()->con->unlock(); App::con()->unlock();
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->con->unlock(); App::con()->unlock();
throw $e; throw $e;
} }
@ -185,7 +175,7 @@ class Utils
public static function updPeriod(int $period_id, Cursor $cur): void public static function updPeriod(int $period_id, Cursor $cur): void
{ {
$cur->update( $cur->update(
"WHERE blog_id = '" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog?->id) . "' " . "WHERE blog_id = '" . App::con()->escapeStr(App::blog()->id()) . "' " .
'AND periodical_id = ' . $period_id . ' ' 'AND periodical_id = ' . $period_id . ' '
); );
} }
@ -207,8 +197,8 @@ class Utils
} }
$sql = new DeleteStatement(); $sql = new DeleteStatement();
$sql->from(dcCore::app()->prefix . My::id()) $sql->from(App::con()->prefix() . My::id())
->where('blog_id = ' . $sql->quote((string) dcCore::app()->blog?->id)) ->where('blog_id = ' . $sql->quote(App::blog()->id()))
->and('periodical_id = ' . $period_id) ->and('periodical_id = ' . $period_id)
->delete(); ->delete();
} }
@ -235,7 +225,7 @@ class Utils
} }
$sql = new DeleteStatement(); $sql = new DeleteStatement();
$sql->from(dcCore::app()->prefix . dcMeta::META_TABLE_NAME) $sql->from(App::con()->prefix() . App::meta()::META_TABLE_NAME)
->where('meta_type = ' . $sql->quote(My::id())) ->where('meta_type = ' . $sql->quote(My::id()))
->and('post_id ' . $sql->in($ids)) ->and('post_id ' . $sql->in($ids))
->delete(); ->delete();
@ -275,14 +265,14 @@ class Utils
->join( ->join(
(new JoinStatement()) (new JoinStatement())
->left() ->left()
->from($sql->as(dcCore::app()->prefix . dcMeta::META_TABLE_NAME, 'R')) ->from($sql->as(App::con()->prefix() . App::meta()::META_TABLE_NAME, 'R'))
->on('P.post_id = R.post_id') ->on('P.post_id = R.post_id')
->statement() ->statement()
) )
->join( ->join(
(new JoinStatement()) (new JoinStatement())
->left() ->left()
->from($sql->as(dcCore::app()->prefix . My::id(), 'T')) ->from($sql->as(App::con()->prefix() . My::id(), 'T'))
->on('CAST(T.periodical_id as char) = CAST(R.meta_id as char)') ->on('CAST(T.periodical_id as char) = CAST(R.meta_id as char)')
->statement() ->statement()
) )
@ -303,7 +293,7 @@ class Utils
$sql->and('T.periodical_id ' . $sql->in($params['periodical_id'])); $sql->and('T.periodical_id ' . $sql->in($params['periodical_id']));
unset($params['periodical_id']); unset($params['periodical_id']);
} }
if (dcCore::app()->auth?->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_ADMIN]), dcCore::app()->blog?->id)) { if (App::auth()->check(App::auth()->makePermissions([App::auth()::PERMISSION_ADMIN]), App::blog()->id())) {
if (isset($params['post_status'])) { if (isset($params['post_status'])) {
if ($params['post_status'] != '') { if ($params['post_status'] != '') {
$sql->and('P.post_status = ' . (int) $params['post_status']); $sql->and('P.post_status = ' . (int) $params['post_status']);
@ -311,12 +301,10 @@ class Utils
unset($params['post_status']); unset($params['post_status']);
} }
} else { } else {
$sql->and('P.post_status = ' . dcBlog::POST_PENDING); $sql->and('P.post_status = ' . App::blog()::POST_PENDING);
} }
$rs = dcCore::app()->blog?->getPosts($params, $count_only, $sql); return App::blog()->getPosts($params, $count_only, $sql) ?? MetaRecord::newFromArray([]);
return is_null($rs) ? MetaRecord::newFromArray([]) : $rs;
} }
/** /**
@ -337,17 +325,17 @@ class Utils
return; return;
} }
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcMeta::META_TABLE_NAME); $cur = App::meta()->openMetaCursor();
dcCore::app()->con->writeLock(dcCore::app()->prefix . dcMeta::META_TABLE_NAME); App::con()->writeLock(App::con()->prefix() . App::meta()::META_TABLE_NAME);
try { try {
$cur->setField('post_id', $post_id); $cur->setField('post_id', $post_id);
$cur->setField('meta_id', $period_id); $cur->setField('meta_id', $period_id);
$cur->setField('meta_type', My::id()); $cur->setField('meta_type', My::id());
$cur->insert(); $cur->insert();
dcCore::app()->con->unlock(); App::con()->unlock();
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->con->unlock(); App::con()->unlock();
throw $e; throw $e;
} }
@ -361,7 +349,7 @@ class Utils
public static function delPost(int $post_id): void public static function delPost(int $post_id): void
{ {
$sql = new DeleteStatement(); $sql = new DeleteStatement();
$sql->from(dcCore::app()->prefix . dcMeta::META_TABLE_NAME) $sql->from(App::con()->prefix() . App::meta()::META_TABLE_NAME)
->where('meta_type = ' . $sql->quote(My::id())) ->where('meta_type = ' . $sql->quote(My::id()))
->and('post_id = ' . $post_id) ->and('post_id = ' . $post_id)
->delete(); ->delete();
@ -374,10 +362,10 @@ class Utils
*/ */
public static function cleanPosts(?int $period_id = null): void public static function cleanPosts(?int $period_id = null): void
{ {
// hack post status of dcBlog::getPost() // hack post status of App::blog()->getPost()
$params = [ $params = [
'post_status' => '', 'post_status' => '',
'sql' => 'AND post_status != ' . dcBlog::POST_PENDING . ' ', 'sql' => 'AND post_status != ' . App::blog()::POST_PENDING . ' ',
]; ];
if ($period_id !== null) { if ($period_id !== null) {
$params['periodical_id'] = $period_id; $params['periodical_id'] = $period_id;
@ -394,7 +382,7 @@ class Utils
} }
$sql = new DeleteStatement(); $sql = new DeleteStatement();
$sql->from(dcCore::app()->prefix . dcMeta::META_TABLE_NAME) $sql->from(App::con()->prefix() . App::meta()::META_TABLE_NAME)
->where('meta_type = ' . $sql->quote(My::id())) ->where('meta_type = ' . $sql->quote(My::id()))
->and('post_id ' . $sql->in($ids)) ->and('post_id ' . $sql->in($ids))
->delete(); ->delete();
@ -409,14 +397,14 @@ class Utils
{ {
try { try {
# Cache writable ? # Cache writable ?
if (!is_writable(DC_TPL_CACHE)) { if (!is_writable(App::config()->cacheRoot())) {
throw new Exception("Can't write in cache fodler"); throw new Exception("Can't write in cache fodler");
} }
# Set file path # Set file path
$f_md5 = md5((string) dcCore::app()->blog?->id); $f_md5 = md5(App::blog()->id());
$file = sprintf( $file = sprintf(
'%s/%s/%s/%s/%s.txt', '%s/%s/%s/%s/%s.txt',
DC_TPL_CACHE, App::config()->cacheRoot(),
My::id(), My::id(),
substr($f_md5, 0, 2), substr($f_md5, 0, 2),
substr($f_md5, 2, 2), substr($f_md5, 2, 2),