release 2023.07.29

master
Jean-Christian Paul Denis 2023-07-29 22:48:09 +02:00
parent e484f4acd3
commit 2cd2a86a1f
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
13 changed files with 169 additions and 220 deletions

View File

@ -1,3 +1,9 @@
2023.07.29
- require Dotclear 2.27
- require PHP 8.1+
- use new svg icon
- update to Dotclear 2.27-dev
2023.05.13 2023.05.13
- require Dotclear 2.26 - require Dotclear 2.26
- require PHP 8.1+ - require PHP 8.1+

View File

@ -3,7 +3,7 @@
[![Release](https://img.shields.io/github/v/release/JcDenis/periodical)](https://github.com/JcDenis/periodical/releases) [![Release](https://img.shields.io/github/v/release/JcDenis/periodical)](https://github.com/JcDenis/periodical/releases)
[![Date](https://img.shields.io/github/release-date/JcDenis/periodical)](https://github.com/JcDenis/periodical/releases) [![Date](https://img.shields.io/github/release-date/JcDenis/periodical)](https://github.com/JcDenis/periodical/releases)
[![Issues](https://img.shields.io/github/issues/JcDenis/periodical)](https://github.com/JcDenis/periodical/issues) [![Issues](https://img.shields.io/github/issues/JcDenis/periodical)](https://github.com/JcDenis/periodical/issues)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.26-blue.svg)](https://fr.dotclear.org/download) [![Dotclear](https://img.shields.io/badge/dotclear-v2.27-blue.svg)](https://fr.dotclear.org/download)
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/periodical) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/periodical)
[![License](https://img.shields.io/github/license/JcDenis/periodical)](https://github.com/JcDenis/periodical/blob/master/LICENSE) [![License](https://img.shields.io/github/license/JcDenis/periodical)](https://github.com/JcDenis/periodical/blob/master/LICENSE)
@ -22,7 +22,7 @@ and they will be publish ones after the others every week.
* admin permissions to configure plugin * admin permissions to configure plugin
* usage,contentadmin permissions to link feeds * usage,contentadmin permissions to link feeds
* Dotclear 2.26 * Dotclear 2.27
* PHP 8.1+ * PHP 8.1+
## NOTICE ## NOTICE

View File

@ -10,7 +10,7 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH') || is_null(dcCore::app()->auth)) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -18,11 +18,11 @@ $this->registerModule(
'Periodical', 'Periodical',
'Published periodically entries', 'Published periodically entries',
'Jean-Christian Denis and contributors', 'Jean-Christian Denis and contributors',
'2023.05.13', '2023.07.29',
[ [
'requires' => [ 'requires' => [
['php', '8.1'], ['php', '8.1'],
['core', '2.26'], ['core', '2.27'],
], ],
'permissions' => dcCore::app()->auth->makePermissions([ 'permissions' => dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_USAGE, dcCore::app()->auth::PERMISSION_USAGE,

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.05.13</version> <version>2023.07.29</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://github.com/JcDenis/periodical/releases/download/v2023.05.13/plugin-periodical.zip</file> <file>https://github.com/JcDenis/periodical/releases/download/v2023.07.29/plugin-periodical.zip</file>
<da:dcmin>2.26</da:dcmin> <da:dcmin>2.27</da:dcmin>
<da:details>https://plugins.dotaddict.org/dc2/details/periodical</da:details> <da:details>https://plugins.dotaddict.org/dc2/details/periodical</da:details>
<da:support>https://github.com/JcDenis/periodical</da:support> <da:support>https://github.com/JcDenis/periodical</da:support>
</module> </module>

View File

@ -14,54 +14,36 @@ declare(strict_types=1);
namespace Dotclear\Plugin\periodical; namespace Dotclear\Plugin\periodical;
use dcAdmin;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use dcPage;
class Backend extends dcNsProcess class Backend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init == defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::BACKEND));
&& !is_null(dcCore::app()->blog) && !is_null(dcCore::app()->auth)
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_USAGE,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id);
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }
// register backend behaviors // register backend behaviors
dcCore::app()->addBehaviors([ dcCore::app()->addBehaviors([
'adminBlogPreferencesFormV2' => [BackendBehaviors::class, 'adminBlogPreferencesForm'], 'adminBlogPreferencesFormV2' => [BackendBehaviors::class, 'adminBlogPreferencesFormV2'],
'adminBeforeBlogSettingsUpdate' => [BackendBehaviors::class, 'adminBeforeBlogSettingsUpdate'], 'adminBeforeBlogSettingsUpdate' => [BackendBehaviors::class, 'adminBeforeBlogSettingsUpdate'],
'adminFiltersListsV2' => [BackendBehaviors::class, 'adminFiltersLists'], 'adminFiltersListsV2' => [BackendBehaviors::class, 'adminFiltersListsV2'],
'adminColumnsListsV2' => [BackendBehaviors::class, 'adminColumnsLists'], 'adminColumnsListsV2' => [BackendBehaviors::class, 'adminColumnsListsV2'],
'adminPostListHeaderV2' => [BackendBehaviors::class, 'adminPostListHeader'], 'adminPostListHeaderV2' => [BackendBehaviors::class, 'adminPostListHeaderV2'],
'adminPostListValueV2' => [BackendBehaviors::class, 'adminPostListValue'], 'adminPostListValueV2' => [BackendBehaviors::class, 'adminPostListValueV2'],
'adminBeforePostDelete' => [BackendBehaviors::class, 'adminBeforePostDelete'], 'adminBeforePostDelete' => [BackendBehaviors::class, 'adminBeforePostDelete'],
]); ]);
if (dcCore::app()->blog?->settings->get(My::id())->get('periodical_active')) { if (My::settings()->get('periodical_active')) {
// add backend sidebar icon // add backend sidebar icon
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( My::addBackendMenuItem();
My::name(),
dcCore::app()->adminurl?->get('admin.plugin.' . My::id()),
dcPage::getPF(My::id() . '/icon.svg'),
preg_match('/' . preg_quote((string) dcCore::app()->adminurl?->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
dcCore::app()->auth?->check(dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_USAGE,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id)
);
// register bakend behaviors required user permissions // register bakend behaviors required user permissions
dcCore::app()->addBehaviors([ dcCore::app()->addBehaviors([

View File

@ -16,10 +16,13 @@ namespace Dotclear\Plugin\periodical;
use ArrayObject; use ArrayObject;
use dcCore; use dcCore;
use dcFavorites;
use dcPage;
use dcPostsActions;
use dcSettings; use dcSettings;
use Dotclear\Core\Backend\{
Favorites,
Notices,
Page
};
use Dotclear\Core\Backend\Action\ActionsPosts;
use Dotclear\Database\{ use Dotclear\Database\{
Cursor, Cursor,
MetaRecord MetaRecord
@ -52,9 +55,9 @@ class BackendBehaviors
* *
* @param dcSettings $blog_settings dcSettings instance * @param dcSettings $blog_settings dcSettings instance
*/ */
public static function adminBlogPreferencesForm(dcSettings $blog_settings): void public static function adminBlogPreferencesFormV2(dcSettings $blog_settings): void
{ {
$s = $blog_settings->get('periodical'); $s = $blog_settings->get(My::id());
echo echo
(new Div())->class('fieldset')->items([ (new Div())->class('fieldset')->items([
@ -88,9 +91,9 @@ class BackendBehaviors
*/ */
public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings): void public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings): void
{ {
$blog_settings->get('periodical')->put('periodical_active', !empty($_POST['periodical_active'])); $blog_settings->get(My::id())->put('periodical_active', !empty($_POST['periodical_active']));
$blog_settings->get('periodical')->put('periodical_upddate', !empty($_POST['periodical_upddate'])); $blog_settings->get(My::id())->put('periodical_upddate', !empty($_POST['periodical_upddate']));
$blog_settings->get('periodical')->put('periodical_updurl', !empty($_POST['periodical_updurl'])); $blog_settings->get(My::id())->put('periodical_updurl', !empty($_POST['periodical_updurl']));
} }
/** /**
@ -98,7 +101,7 @@ class BackendBehaviors
* *
* @param ArrayObject $cols Columns * @param ArrayObject $cols Columns
*/ */
public static function adminColumnsLists(ArrayObject $cols): void public static function adminColumnsListsV2(ArrayObject $cols): void
{ {
$cols[My::id()] = [ $cols[My::id()] = [
My::name(), My::name(),
@ -119,7 +122,7 @@ class BackendBehaviors
* *
* @param ArrayObject $sorts Sort options * @param ArrayObject $sorts Sort options
*/ */
public static function adminFiltersLists(ArrayObject $sorts): void public static function adminFiltersListsV2(ArrayObject $sorts): void
{ {
$sorts[My::id()] = [ $sorts[My::id()] = [
My::name(), My::name(),
@ -136,9 +139,9 @@ class BackendBehaviors
* @param MetaRecord $rs record instance * @param MetaRecord $rs record instance
* @param ArrayObject $cols Columns * @param ArrayObject $cols Columns
*/ */
public static function adminPostListHeader(MetaRecord $rs, ArrayObject $cols): void public static function adminPostListHeaderV2(MetaRecord $rs, ArrayObject $cols): void
{ {
if (dcCore::app()->blog?->settings->get('periodical')->get('periodical_active')) { if (My::settings()->get('periodical_active')) {
$cols['period'] = '<th scope="col">' . __('Period') . '</th>'; $cols['period'] = '<th scope="col">' . __('Period') . '</th>';
} }
} }
@ -149,9 +152,9 @@ class BackendBehaviors
* @param MetaRecord $rs record instance * @param MetaRecord $rs record instance
* @param ArrayObject $cols Columns * @param ArrayObject $cols Columns
*/ */
public static function adminPostListValue(MetaRecord $rs, ArrayObject $cols): void public static function adminPostListValueV2(MetaRecord $rs, ArrayObject $cols): void
{ {
if (!dcCore::app()->blog?->settings->get('periodical')->get('periodical_active')) { if (!My::settings()->get('periodical_active')) {
return; return;
} }
@ -159,7 +162,7 @@ class BackendBehaviors
if ($r->isEmpty()) { if ($r->isEmpty()) {
$name = '-'; $name = '-';
} else { } else {
$url = dcCore::app()->adminurl?->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $r->f('periodical_id')]); $url = My::manageUrl(['part' => 'period', 'period_id' => $r->f('periodical_id')]);
$name = '<a href="' . $url . '#period" title="' . __('edit period') . '">' . Html::escapeHTML($r->f('periodical_title')) . '</a>'; $name = '<a href="' . $url . '#period" title="' . __('edit period') . '">' . Html::escapeHTML($r->f('periodical_title')) . '</a>';
} }
$cols['period'] = '<td class="nowrap">' . $name . '</td>'; $cols['period'] = '<td class="nowrap">' . $name . '</td>';
@ -168,18 +171,15 @@ class BackendBehaviors
/** /**
* Dashboard Favorites. * Dashboard Favorites.
* *
* @param dcFavorites $favs Array of favorites * @param Favorites $favs Array of favorites
*/ */
public static function adminDashboardFavoritesV2(dcFavorites $favs): void public static function adminDashboardFavoritesV2(Favorites $favs): void
{ {
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
return;
}
$favs->register(My::id(), [ $favs->register(My::id(), [
'title' => My::name(), 'title' => My::name(),
'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()), 'url' => My::manageUrl(),
'small-icon' => dcPage::getPF(My::id() . '/icon.svg'), 'small-icon' => My::icons(),
'large-icon' => dcPage::getPF(My::id() . '/icon.svg'), 'large-icon' => My::icons(),
'permissions' => dcCore::app()->auth->makePermissions([ 'permissions' => dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_USAGE, dcCore::app()->auth::PERMISSION_USAGE,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
@ -194,7 +194,7 @@ class BackendBehaviors
*/ */
public static function adminPostHeaders(): string public static function adminPostHeaders(): string
{ {
return dcPage::jsModuleLoad(My::id() . '/js/toggle.js'); return My::jsLoad('toggle');
} }
/** /**
@ -210,9 +210,9 @@ class BackendBehaviors
/** /**
* Add actions to posts page combo. * Add actions to posts page combo.
* *
* @param dcPostsActions $pa dcPostsActions instance * @param ActionsPosts $pa ActionsPosts instance
*/ */
public static function adminPostsActions(dcPostsActions $pa): void public static function adminPostsActions(ActionsPosts $pa): void
{ {
$pa->addAction( $pa->addAction(
[My::name() => [__('Add to periodical') => 'periodical_add']], [My::name() => [__('Add to periodical') => 'periodical_add']],
@ -233,10 +233,10 @@ class BackendBehaviors
/** /**
* Posts actions callback to remove period. * Posts actions callback to remove period.
* *
* @param dcPostsActions $pa dcPostsActions instance * @param ActionsPosts $pa ActionsPosts instance
* @param ArrayObject $post _POST actions * @param ArrayObject $post _POST actions
*/ */
public static function callbackRemove(dcPostsActions $pa, ArrayObject $post): void public static function callbackRemove(ActionsPosts $pa, ArrayObject $post): void
{ {
// No entry // No entry
$posts_ids = $pa->getIDs(); $posts_ids = $pa->getIDs();
@ -257,17 +257,17 @@ class BackendBehaviors
self::delPeriod($post_id); self::delPeriod($post_id);
} }
dcPage::addSuccessNotice(__('Posts have been removed from periodical.')); Notices::addSuccessNotice(__('Posts have been removed from periodical.'));
$pa->redirect(true); $pa->redirect(true);
} }
/** /**
* Posts actions callback to add period. * Posts actions callback to add period.
* *
* @param dcPostsActions $pa dcPostsActions instance * @param ActionsPosts $pa ActionsPosts instance
* @param ArrayObject $post _POST actions * @param ArrayObject $post _POST actions
*/ */
public static function callbackAdd(dcPostsActions $pa, ArrayObject $post): void public static function callbackAdd(ActionsPosts $pa, ArrayObject $post): void
{ {
// No entry // No entry
$posts_ids = $pa->getIDs(); $posts_ids = $pa->getIDs();
@ -284,14 +284,14 @@ class BackendBehaviors
self::addPeriod($post_id, (int) $post['periodical']); self::addPeriod($post_id, (int) $post['periodical']);
} }
dcPage::addSuccessNotice(__('Posts have been added to periodical.')); Notices::addSuccessNotice(__('Posts have been added to periodical.'));
$pa->redirect(true); $pa->redirect(true);
} }
// Display form // Display form
else { else {
$pa->beginPage( $pa->beginPage(
dcPage::breadcrumb([ Page::breadcrumb([
Html::escapeHTML((string) dcCore::app()->blog?->name) => '', Html::escapeHTML((string) dcCore::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') => '',

View File

@ -16,35 +16,32 @@ namespace Dotclear\Plugin\periodical;
use dcBlog; use dcBlog;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use Exception; use Exception;
/** /**
* Update posts from periods on frontend * Update posts from periods on frontend
*/ */
class Frontend extends dcNsProcess class Frontend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_RC_PATH') return self::status(My::checkContext(My::INSTALL) && in_array(dcCore::app()->url->type, ['default', 'feed']));
&& in_array(dcCore::app()->url->type, ['default', 'feed']);
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }
dcCore::app()->addBehavior('publicBeforeDocumentV2', function (): void { dcCore::app()->addBehavior('publicBeforeDocumentV2', function (): void {
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog)) { if (is_null(dcCore::app()->blog)) {
return; return;
} }
try { try {
$s = dcCore::app()->blog->settings->get(My::id()); $s = My::settings();
Utils::lockUpdate(); Utils::lockUpdate();

View File

@ -15,23 +15,20 @@ declare(strict_types=1);
namespace Dotclear\Plugin\periodical; namespace Dotclear\Plugin\periodical;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use Dotclear\Database\Structure; use Dotclear\Database\Structure;
use Exception; use Exception;
class Install extends dcNsProcess class Install extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::INSTALL));
&& dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init || is_null(dcCore::app()->blog)) { if (!self::status()) {
return false; return false;
} }
@ -55,7 +52,7 @@ class Install extends dcNsProcess
(new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($t); (new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($t);
// set default settings // set default settings
$s = dcCore::app()->blog->settings->get(My::id()); $s = My::settings();
$s->put('periodical_active', false, 'boolean', 'Enable extension', false, true); $s->put('periodical_active', false, 'boolean', 'Enable extension', false, true);
$s->put('periodical_upddate', true, 'boolean', 'Update post date', false, true); $s->put('periodical_upddate', true, 'boolean', 'Update post date', false, true);
$s->put('periodical_updurl', false, 'boolean', 'Update post url', false, true); $s->put('periodical_updurl', false, 'boolean', 'Update post url', false, true);

View File

@ -14,10 +14,13 @@ declare(strict_types=1);
namespace Dotclear\Plugin\periodical; namespace Dotclear\Plugin\periodical;
use adminGenericFilter;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use dcPage; use Dotclear\Core\Backend\{
Notices,
Page
};
use Dotclear\Core\Backend\Filter\Filters;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Hidden, Hidden,
Select Select
@ -28,33 +31,23 @@ use Exception;
/** /**
* Admin page for periods * Admin page for periods
*/ */
class Manage extends dcNsProcess class Manage extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init == defined('DC_CONTEXT_ADMIN') self::status(My::checkContext(My::MANAGE));
&& !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog)
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_USAGE,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id);
// call period manage page // call period manage page
if (($_REQUEST['part'] ?? 'periods') === 'period') { if (($_REQUEST['part'] ?? 'periods') === 'period') {
static::$init = ManagePeriod::init(); self::status(ManagePeriod::init());
} }
return static::$init; return self::status();
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false;
}
// nullsafe
if (is_null(dcCore::app()->adminurl)) {
return false; return false;
} }
@ -74,14 +67,14 @@ class Manage extends dcNsProcess
Utils::delPeriod($id); Utils::delPeriod($id);
} }
dcPage::addSuccessNotice( Notices::addSuccessNotice(
__('Periods removed.') __('Periods removed.')
); );
if (!empty($vars->redir)) { if (!empty($vars->redir)) {
Http::redirect($vars->redir); Http::redirect($vars->redir);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'periods']); My::redirect(['part' => 'periods']);
} }
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
@ -95,14 +88,14 @@ class Manage extends dcNsProcess
Utils::delPeriodPosts($id); Utils::delPeriodPosts($id);
} }
dcPage::addSuccessNotice( Notices::addSuccessNotice(
__('Periods emptied.') __('Periods emptied.')
); );
if (!empty($vars->redir)) { if (!empty($vars->redir)) {
Http::redirect($vars->redir); Http::redirect($vars->redir);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'periods']); My::redirect(['part' => 'periods']);
} }
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
@ -117,12 +110,7 @@ class Manage extends dcNsProcess
*/ */
public static function render(): void public static function render(): void
{ {
if (!static::$init) { if (!self::status()) {
return;
}
// nullsafe
if (is_null(dcCore::app()->adminurl)) {
return; return;
} }
@ -134,7 +122,7 @@ class Manage extends dcNsProcess
} }
// Filters // Filters
$p_filter = new adminGenericFilter(dcCore::app(), My::id()); $p_filter = new Filters(My::id());
$p_filter->add('part', 'periods'); $p_filter->add('part', 'periods');
$params = $p_filter->params(); $params = $p_filter->params();
@ -143,23 +131,23 @@ class Manage extends dcNsProcess
try { try {
$periods = Utils::getPeriods($params); $periods = Utils::getPeriods($params);
$counter = Utils::getPeriods($params, true); $counter = Utils::getPeriods($params, true);
$period_list = new ManageList(dcCore::app(), $periods, $counter->f(0)); $period_list = new ManageList($periods, $counter->f(0));
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
// Display // Display
dcPage::openModule( Page::openModule(
My::name(), My::name(),
dcPage::jsModuleLoad(My::id() . '/js/checkbox.js') . My::jsLoad('checkbox') .
$p_filter->js(dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'periods'])) $p_filter->js(My::manageUrl(['part' => 'periods']))
); );
echo dcPage::breadcrumb([ echo Page::breadcrumb([
__('Plugins') => '', __('Plugins') => '',
My::name() => '', My::name() => '',
]) . ]) .
dcPage::notices() . 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="' . dcCore::app()->admin->getPageURL() . '&amp;part=period">' . __('New period') . '</a>
@ -167,7 +155,7 @@ class Manage extends dcNsProcess
if (isset($period_list)) { if (isset($period_list)) {
// Filters // Filters
$p_filter->display('admin.plugin.' . My::id(), (new Hidden('p', My::id()))->render() . (new Hidden('part', 'periods'))->render()); $p_filter->display('admin.plugin.' . My::id(), (new Hidden('part', 'periods'))->render());
// Periods list // Periods list
$period_list->periodDisplay( $period_list->periodDisplay(
@ -182,14 +170,13 @@ class Manage extends dcNsProcess
'<p class="col right">' . __('Selected periods action:') . ' ' . '<p class="col right">' . __('Selected periods action:') . ' ' .
(new Select('action'))->items(My::periodsActionCombo())->render() . (new Select('action'))->items(My::periodsActionCombo())->render() .
'<input type="submit" value="' . __('ok') . '" /></p>' . '<input type="submit" value="' . __('ok') . '" /></p>' .
dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . My::id(), array_merge(['p' => My::id()], $p_filter->values(true))) . My::parsedHiddenFields($p_filter->values(true)) .
dcCore::app()->formNonce() .
'</div>' . '</div>' .
'</form>' '</form>'
); );
} }
dcPage::helpBlock('periodical'); Page::helpBlock('periodical');
dcPage::closeModule(); Page::closeModule();
} }
} }

View File

@ -15,12 +15,16 @@ declare(strict_types=1);
namespace Dotclear\Plugin\periodical; namespace Dotclear\Plugin\periodical;
use ArrayObject; use ArrayObject;
use adminGenericFilter;
use adminGenericList;
use adminPostFilter;
use dcBlog; use dcBlog;
use dcCore; use dcCore;
use dcPager; use Dotclear\Core\Backend\Filter\{
Filters,
FilterPosts
};
use Dotclear\Core\Backend\Listing\{
Listing,
Pager
};
use Dotclear\Helper\Date; use Dotclear\Helper\Date;
use Dotclear\Helper\Html\Form\Checkbox; use Dotclear\Helper\Html\Form\Checkbox;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
@ -30,15 +34,15 @@ use Dotclear\Helper\Html\Html;
* @brief Periodical - admin pager methods. * @brief Periodical - admin pager methods.
* @since 2.6 * @since 2.6
*/ */
class ManageList extends adminGenericList class ManageList extends Listing
{ {
/** /**
* Display periods list. * Display periods list.
* *
* @param adminGenericFilter $filter The periods filter * @param Filters $filter The periods filter
* @param string $enclose_block The enclose block * @param string $enclose_block The enclose block
*/ */
public function periodDisplay(adminGenericFilter $filter, string $enclose_block = ''): void public function periodDisplay(Filters $filter, string $enclose_block = ''): void
{ {
if ($this->rs->isEmpty()) { if ($this->rs->isEmpty()) {
if ($filter->show()) { if ($filter->show()) {
@ -47,7 +51,7 @@ class ManageList extends adminGenericList
echo '<p><strong>' . __('No period') . '</strong></p>'; echo '<p><strong>' . __('No period') . '</strong></p>';
} }
} else { } else {
$pager = new dcPager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10); $pager = new Pager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10);
$pager->var_page = 'page'; $pager->var_page = 'page';
$periods = []; $periods = [];
@ -99,7 +103,7 @@ class ManageList extends adminGenericList
{ {
$tz = dcCore::app()->auth?->getInfo('user_tz'); $tz = dcCore::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 = dcCore::app()->adminurl?->get('admin.plugin.periodical', ['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>';
$posts = $nb_posts ? '<a href="' . $url . '#posts" title="' . __('view related entries') . '">' . $nb_posts . '</a>' : '0'; $posts = $nb_posts ? '<a href="' . $url . '#posts" title="' . __('view related entries') . '">' . $nb_posts . '</a>' : '0';
$interval = in_array($this->rs->f('periodical_pub_int'), My::periodCombo()) ? $interval = in_array($this->rs->f('periodical_pub_int'), My::periodCombo()) ?
@ -126,11 +130,11 @@ class ManageList extends adminGenericList
/** /**
* Display period posts list. * Display period posts list.
* *
* @param adminPostFilter $filter The posts filter * @param FilterPosts $filter The posts filter
* @param string $base_url The page base URL * @param string $base_url The page base URL
* @param string $enclose_block The enclose block * @param string $enclose_block The enclose block
*/ */
public function postDisplay(adminPostFilter $filter, string $base_url, string $enclose_block = ''): void public function postDisplay(FilterPosts $filter, string $base_url, string $enclose_block = ''): void
{ {
$echo = ''; $echo = '';
if ($this->rs->isEmpty()) { if ($this->rs->isEmpty()) {
@ -140,7 +144,7 @@ class ManageList extends adminGenericList
echo '<p><strong>' . __('No entry') . '</strong></p>'; echo '<p><strong>' . __('No entry') . '</strong></p>';
} }
} else { } else {
$pager = new dcPager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10); $pager = new Pager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10);
$pager->base_url = $base_url; $pager->base_url = $base_url;
$pager->var_page = 'page'; $pager->var_page = 'page';

View File

@ -14,10 +14,13 @@ declare(strict_types=1);
namespace Dotclear\Plugin\periodical; namespace Dotclear\Plugin\periodical;
use adminPostFilter;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use dcPage; use Dotclear\Core\Backend\{
Notices,
Page
};
use Dotclear\Core\Backend\Filter\FilterPosts;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Datetime, Datetime,
Div, Div,
@ -38,24 +41,16 @@ use Exception;
/** /**
* Admin page for a period * Admin page for a period
*/ */
class ManagePeriod extends dcNsProcess class ManagePeriod extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init == defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::MANAGE) && ($_REQUEST['part'] ?? 'periods') === 'period');
&& !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog)
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_USAGE,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id)
&& ($_REQUEST['part'] ?? 'periods') === 'period';
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }
@ -170,12 +165,7 @@ class ManagePeriod extends dcNsProcess
*/ */
public static function render(): void public static function render(): void
{ {
if (!static::$init) { if (!self::status()) {
return;
}
// nullsafe
if (is_null(dcCore::app()->adminurl)) {
return; return;
} }
@ -187,7 +177,7 @@ class ManagePeriod extends dcNsProcess
// Prepare combos for posts list // Prepare combos for posts list
if ($vars->period_id > 0) { if ($vars->period_id > 0) {
// Filters // Filters
$post_filter = new adminPostFilter(); $post_filter = new FilterPosts();
$post_filter->add('part', 'period'); $post_filter->add('part', 'period');
$params = $post_filter->params(); $params = $post_filter->params();
@ -198,31 +188,31 @@ class ManagePeriod extends dcNsProcess
try { try {
$posts = Utils::getPosts($params); $posts = Utils::getPosts($params);
$counter = Utils::getPosts($params, true); $counter = Utils::getPosts($params, true);
$post_list = new ManageList(dcCore::app(), $posts, $counter->f(0)); $post_list = new ManageList($posts, $counter->f(0));
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
$starting_script = dcPage::jsModuleLoad(My::id() . '/js/checkbox.js') . $starting_script = My::jsLoad('checkbox') .
$post_filter->js(dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'period', 'period_id' => $vars->period_id], '&') . '#posts'); $post_filter->js(My::manageUrl(['part' => 'period', 'period_id' => $vars->period_id], '&') . '#posts');
} }
// Display // Display
dcPage::openModule( Page::openModule(
My::name(), My::name(),
dcPage::jsModuleLoad(My::id() . '/js/dates.js') . My::jsLoad('dates') .
$starting_script . $starting_script .
dcPage::jsDatePicker() . Page::jsDatePicker() .
dcPage::jsPageTabs() Page::jsPageTabs()
); );
echo echo
dcPage::breadcrumb([ Page::breadcrumb([
__('Plugins') => '', __('Plugins') => '',
My::name() => dcCore::app()->admin->getPageURL() . '&amp;part=periods', My::name() => dcCore::app()->admin->getPageURL() . '&amp;part=periods',
(null === $vars->period_id ? __('New period') : __('Edit period')) => '', (null === $vars->period_id ? __('New period') : __('Edit period')) => '',
]) . ]) .
dcPage::notices(); Notices::getNotices();
// Period form // Period form
echo echo
@ -258,10 +248,11 @@ class ManagePeriod extends dcNsProcess
(new Div())->class('clear')->items([ (new Div())->class('clear')->items([
(new Para())->items([ (new Para())->items([
(new Submit(['save']))->value(__('Save')), (new Submit(['save']))->value(__('Save')),
dcCore::app()->formNonce(false), ... My::hiddenFields([
(new Hidden(['action'], 'setperiod')), 'action' => 'setperiod',
(new Hidden(['period_id'], (string) $vars->period_id)), 'period_id' => (string) $vars->period_id,
(new Hidden(['part'], 'period')), 'part' => 'period',
]),
]), ]),
]), ]),
]), ]),
@ -290,7 +281,7 @@ class ManagePeriod extends dcNsProcess
// Filters // Filters
$post_filter->display( $post_filter->display(
['admin.plugin.periodical', '#posts'], ['admin.plugin.periodical', '#posts'],
dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.periodical', [ My::parsedHiddenFields([
'period_id' => $vars->period_id, 'period_id' => $vars->period_id,
'part' => 'period', 'part' => 'period',
]) ])
@ -307,18 +298,18 @@ class ManagePeriod extends dcNsProcess
'<div class="two-cols">' . '<div class="two-cols">' .
'<p class="col checkboxes-helpers"></p>' . '<p class="col checkboxes-helpers"></p>' .
(new Para())->class('col right')->items(array_merge( (new Para())->class('col right')
dcCore::app()->adminurl->hiddenFormFields('admin.plugin.periodical', array_merge($post_filter->values(), [ ->items([
'period_id' => $vars->period_id,
'redir' => sprintf($base_url, $post_filter->value('page', '')),
])),
[
(new Label(__('Selected entries action:'), Label::OUTSIDE_LABEL_BEFORE))->for('post_action')->class('classic'), (new Label(__('Selected entries action:'), Label::OUTSIDE_LABEL_BEFORE))->for('post_action')->class('classic'),
(new Select(['action','post_action']))->items(My::entriesActionsCombo()), (new Select(['action','post_action']))->items(My::entriesActionsCombo()),
(new Submit('do_post_action'))->value(__('ok')), (new Submit('do_post_action'))->value(__('ok')),
dcCore::app()->formNonce(false), ... My::hiddenFields([
] ... $post_filter->values(),
))->render() . 'period_id' => $vars->period_id,
'redir' => sprintf($base_url, $post_filter->value('page', '')),
]),
])
->render() .
'</div>' . '</div>' .
'</form>' '</form>'
); );
@ -327,9 +318,9 @@ class ManagePeriod extends dcNsProcess
'</div>'; '</div>';
} }
dcPage::helpBlock('periodical'); Page::helpBlock('periodical');
dcPage::closeModule(); Page::closeModule();
} }
/** /**
@ -342,12 +333,12 @@ class ManagePeriod extends dcNsProcess
*/ */
private static function redirect(string $redir, int $id, string $tab, string $msg): void private static function redirect(string $redir, int $id, string $tab, string $msg): void
{ {
dcPage::addSuccessNotice($msg); Notices::addSuccessNotice($msg);
if (!empty($redir)) { if (!empty($redir)) {
Http::redirect($redir); Http::redirect($redir);
} else { } else {
dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id(), ['part' => 'period', 'period_id' => $id], $tab); My::redirect(['part' => 'period', 'period_id' => $id], $tab);
} }
} }
} }

View File

@ -15,11 +15,12 @@ declare(strict_types=1);
namespace Dotclear\Plugin\periodical; namespace Dotclear\Plugin\periodical;
use dcCore; use dcCore;
use Dotclear\Module\MyPlugin;
/** /**
* This module definitions. * This module definitions.
*/ */
class My class My extends MyPlugin
{ {
/** @var string This module table name */ /** @var string This module table name */
public const TABLE_NAME = 'periodical'; public const TABLE_NAME = 'periodical';
@ -27,30 +28,16 @@ class My
/** @var string This module meta type */ /** @var string This module meta type */
public const META_TYPE = 'periodical'; public const META_TYPE = 'periodical';
/** public static function checkCustomContext(int $context): ?bool
* This module id.
*/
public static function id(): string
{ {
return basename(dirname(__DIR__)); return in_array($context, [My::MANAGE, My::MENU]) ?
} defined('DC_CONTEXT_ADMIN')
&& !is_null(dcCore::app()->blog)
/** && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
* This module name. dcCore::app()->auth::PERMISSION_USAGE,
*/ dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
public static function name(): string ]), dcCore::app()->blog->id)
{ : null;
$name = dcCore::app()->plugins->moduleInfo(self::id(), 'name');
return __(is_string($name) ? $name : self::id());
}
/**
* This module path.
*/
public static function path(): string
{
return dirname(__DIR__);
} }
/** /**

View File

@ -15,21 +15,19 @@ declare(strict_types=1);
namespace Dotclear\Plugin\periodical; namespace Dotclear\Plugin\periodical;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use Dotclear\Plugin\Uninstaller\Uninstaller; use Dotclear\Plugin\Uninstaller\Uninstaller;
class Uninstall extends dcNsProcess class Uninstall extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN'); return self::status(My::checkContext(My::UNINSTALL));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) { if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
return false; return false;
} }