release 2023.07.29
This commit is contained in:
parent
e484f4acd3
commit
2cd2a86a1f
13 changed files with 169 additions and 220 deletions
|
@ -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
|
||||
- require Dotclear 2.26
|
||||
- require PHP 8.1+
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
[![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)
|
||||
[![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)
|
||||
[![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
|
||||
* usage,contentadmin permissions to link feeds
|
||||
* Dotclear 2.26
|
||||
* Dotclear 2.27
|
||||
* PHP 8.1+
|
||||
|
||||
## NOTICE
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_RC_PATH') || is_null(dcCore::app()->auth)) {
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -18,11 +18,11 @@ $this->registerModule(
|
|||
'Periodical',
|
||||
'Published periodically entries',
|
||||
'Jean-Christian Denis and contributors',
|
||||
'2023.05.13',
|
||||
'2023.07.29',
|
||||
[
|
||||
'requires' => [
|
||||
['php', '8.1'],
|
||||
['core', '2.26'],
|
||||
['core', '2.27'],
|
||||
],
|
||||
'permissions' => dcCore::app()->auth->makePermissions([
|
||||
dcCore::app()->auth::PERMISSION_USAGE,
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
<modules xmlns:da="http://dotaddict.org/da/">
|
||||
<module id="periodical">
|
||||
<name>Periodical</name>
|
||||
<version>2023.05.13</version>
|
||||
<version>2023.07.29</version>
|
||||
<author>Jean-Christian Denis and contributors</author>
|
||||
<desc>Published periodically entries</desc>
|
||||
<file>https://github.com/JcDenis/periodical/releases/download/v2023.05.13/plugin-periodical.zip</file>
|
||||
<da:dcmin>2.26</da:dcmin>
|
||||
<file>https://github.com/JcDenis/periodical/releases/download/v2023.07.29/plugin-periodical.zip</file>
|
||||
<da:dcmin>2.27</da:dcmin>
|
||||
<da:details>https://plugins.dotaddict.org/dc2/details/periodical</da:details>
|
||||
<da:support>https://github.com/JcDenis/periodical</da:support>
|
||||
</module>
|
||||
|
|
|
@ -14,54 +14,36 @@ declare(strict_types=1);
|
|||
|
||||
namespace Dotclear\Plugin\periodical;
|
||||
|
||||
use dcAdmin;
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use dcPage;
|
||||
use Dotclear\Core\Process;
|
||||
|
||||
class Backend extends dcNsProcess
|
||||
class Backend extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init == defined('DC_CONTEXT_ADMIN')
|
||||
&& !is_null(dcCore::app()->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;
|
||||
return self::status(My::checkContext(My::BACKEND));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// register backend behaviors
|
||||
dcCore::app()->addBehaviors([
|
||||
'adminBlogPreferencesFormV2' => [BackendBehaviors::class, 'adminBlogPreferencesForm'],
|
||||
'adminBlogPreferencesFormV2' => [BackendBehaviors::class, 'adminBlogPreferencesFormV2'],
|
||||
'adminBeforeBlogSettingsUpdate' => [BackendBehaviors::class, 'adminBeforeBlogSettingsUpdate'],
|
||||
'adminFiltersListsV2' => [BackendBehaviors::class, 'adminFiltersLists'],
|
||||
'adminColumnsListsV2' => [BackendBehaviors::class, 'adminColumnsLists'],
|
||||
'adminPostListHeaderV2' => [BackendBehaviors::class, 'adminPostListHeader'],
|
||||
'adminPostListValueV2' => [BackendBehaviors::class, 'adminPostListValue'],
|
||||
'adminFiltersListsV2' => [BackendBehaviors::class, 'adminFiltersListsV2'],
|
||||
'adminColumnsListsV2' => [BackendBehaviors::class, 'adminColumnsListsV2'],
|
||||
'adminPostListHeaderV2' => [BackendBehaviors::class, 'adminPostListHeaderV2'],
|
||||
'adminPostListValueV2' => [BackendBehaviors::class, 'adminPostListValueV2'],
|
||||
'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
|
||||
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
|
||||
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)
|
||||
);
|
||||
My::addBackendMenuItem();
|
||||
|
||||
// register bakend behaviors required user permissions
|
||||
dcCore::app()->addBehaviors([
|
||||
|
|
|
@ -16,10 +16,13 @@ namespace Dotclear\Plugin\periodical;
|
|||
|
||||
use ArrayObject;
|
||||
use dcCore;
|
||||
use dcFavorites;
|
||||
use dcPage;
|
||||
use dcPostsActions;
|
||||
use dcSettings;
|
||||
use Dotclear\Core\Backend\{
|
||||
Favorites,
|
||||
Notices,
|
||||
Page
|
||||
};
|
||||
use Dotclear\Core\Backend\Action\ActionsPosts;
|
||||
use Dotclear\Database\{
|
||||
Cursor,
|
||||
MetaRecord
|
||||
|
@ -52,9 +55,9 @@ class BackendBehaviors
|
|||
*
|
||||
* @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
|
||||
(new Div())->class('fieldset')->items([
|
||||
|
@ -88,9 +91,9 @@ class BackendBehaviors
|
|||
*/
|
||||
public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings): void
|
||||
{
|
||||
$blog_settings->get('periodical')->put('periodical_active', !empty($_POST['periodical_active']));
|
||||
$blog_settings->get('periodical')->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_active', !empty($_POST['periodical_active']));
|
||||
$blog_settings->get(My::id())->put('periodical_upddate', !empty($_POST['periodical_upddate']));
|
||||
$blog_settings->get(My::id())->put('periodical_updurl', !empty($_POST['periodical_updurl']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,7 +101,7 @@ class BackendBehaviors
|
|||
*
|
||||
* @param ArrayObject $cols Columns
|
||||
*/
|
||||
public static function adminColumnsLists(ArrayObject $cols): void
|
||||
public static function adminColumnsListsV2(ArrayObject $cols): void
|
||||
{
|
||||
$cols[My::id()] = [
|
||||
My::name(),
|
||||
|
@ -119,7 +122,7 @@ class BackendBehaviors
|
|||
*
|
||||
* @param ArrayObject $sorts Sort options
|
||||
*/
|
||||
public static function adminFiltersLists(ArrayObject $sorts): void
|
||||
public static function adminFiltersListsV2(ArrayObject $sorts): void
|
||||
{
|
||||
$sorts[My::id()] = [
|
||||
My::name(),
|
||||
|
@ -136,9 +139,9 @@ class BackendBehaviors
|
|||
* @param MetaRecord $rs record instance
|
||||
* @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>';
|
||||
}
|
||||
}
|
||||
|
@ -149,9 +152,9 @@ class BackendBehaviors
|
|||
* @param MetaRecord $rs record instance
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
@ -159,7 +162,7 @@ class BackendBehaviors
|
|||
if ($r->isEmpty()) {
|
||||
$name = '-';
|
||||
} 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>';
|
||||
}
|
||||
$cols['period'] = '<td class="nowrap">' . $name . '</td>';
|
||||
|
@ -168,18 +171,15 @@ class BackendBehaviors
|
|||
/**
|
||||
* 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(), [
|
||||
'title' => My::name(),
|
||||
'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
|
||||
'small-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
||||
'large-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
||||
'url' => My::manageUrl(),
|
||||
'small-icon' => My::icons(),
|
||||
'large-icon' => My::icons(),
|
||||
'permissions' => dcCore::app()->auth->makePermissions([
|
||||
dcCore::app()->auth::PERMISSION_USAGE,
|
||||
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
|
||||
|
@ -194,7 +194,7 @@ class BackendBehaviors
|
|||
*/
|
||||
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.
|
||||
*
|
||||
* @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(
|
||||
[My::name() => [__('Add to periodical') => 'periodical_add']],
|
||||
|
@ -233,10 +233,10 @@ class BackendBehaviors
|
|||
/**
|
||||
* Posts actions callback to remove period.
|
||||
*
|
||||
* @param dcPostsActions $pa dcPostsActions instance
|
||||
* @param ActionsPosts $pa ActionsPosts instance
|
||||
* @param ArrayObject $post _POST actions
|
||||
*/
|
||||
public static function callbackRemove(dcPostsActions $pa, ArrayObject $post): void
|
||||
public static function callbackRemove(ActionsPosts $pa, ArrayObject $post): void
|
||||
{
|
||||
// No entry
|
||||
$posts_ids = $pa->getIDs();
|
||||
|
@ -257,17 +257,17 @@ class BackendBehaviors
|
|||
self::delPeriod($post_id);
|
||||
}
|
||||
|
||||
dcPage::addSuccessNotice(__('Posts have been removed from periodical.'));
|
||||
Notices::addSuccessNotice(__('Posts have been removed from periodical.'));
|
||||
$pa->redirect(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts actions callback to add period.
|
||||
*
|
||||
* @param dcPostsActions $pa dcPostsActions instance
|
||||
* @param ActionsPosts $pa ActionsPosts instance
|
||||
* @param ArrayObject $post _POST actions
|
||||
*/
|
||||
public static function callbackAdd(dcPostsActions $pa, ArrayObject $post): void
|
||||
public static function callbackAdd(ActionsPosts $pa, ArrayObject $post): void
|
||||
{
|
||||
// No entry
|
||||
$posts_ids = $pa->getIDs();
|
||||
|
@ -284,14 +284,14 @@ class BackendBehaviors
|
|||
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);
|
||||
}
|
||||
|
||||
// Display form
|
||||
else {
|
||||
$pa->beginPage(
|
||||
dcPage::breadcrumb([
|
||||
Page::breadcrumb([
|
||||
Html::escapeHTML((string) dcCore::app()->blog?->name) => '',
|
||||
$pa->getCallerTitle() => $pa->getRedirection(true),
|
||||
__('Add a period to this selection') => '',
|
||||
|
|
|
@ -16,35 +16,32 @@ namespace Dotclear\Plugin\periodical;
|
|||
|
||||
use dcBlog;
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use Dotclear\Core\Process;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Update posts from periods on frontend
|
||||
*/
|
||||
class Frontend extends dcNsProcess
|
||||
class Frontend extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_RC_PATH')
|
||||
&& in_array(dcCore::app()->url->type, ['default', 'feed']);
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::INSTALL) && in_array(dcCore::app()->url->type, ['default', 'feed']));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
dcCore::app()->addBehavior('publicBeforeDocumentV2', function (): void {
|
||||
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog)) {
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$s = dcCore::app()->blog->settings->get(My::id());
|
||||
$s = My::settings();
|
||||
|
||||
Utils::lockUpdate();
|
||||
|
||||
|
|
|
@ -15,23 +15,20 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\periodical;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Database\Structure;
|
||||
use Exception;
|
||||
|
||||
class Install extends dcNsProcess
|
||||
class Install extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||
&& dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::INSTALL));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init || is_null(dcCore::app()->blog)) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -55,7 +52,7 @@ class Install extends dcNsProcess
|
|||
(new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($t);
|
||||
|
||||
// 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_upddate', true, 'boolean', 'Update post date', false, true);
|
||||
$s->put('periodical_updurl', false, 'boolean', 'Update post url', false, true);
|
||||
|
|
|
@ -14,10 +14,13 @@ declare(strict_types=1);
|
|||
|
||||
namespace Dotclear\Plugin\periodical;
|
||||
|
||||
use adminGenericFilter;
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use dcPage;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Core\Backend\{
|
||||
Notices,
|
||||
Page
|
||||
};
|
||||
use Dotclear\Core\Backend\Filter\Filters;
|
||||
use Dotclear\Helper\Html\Form\{
|
||||
Hidden,
|
||||
Select
|
||||
|
@ -28,33 +31,23 @@ use Exception;
|
|||
/**
|
||||
* Admin page for periods
|
||||
*/
|
||||
class Manage extends dcNsProcess
|
||||
class Manage extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init == defined('DC_CONTEXT_ADMIN')
|
||||
&& !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog)
|
||||
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
|
||||
dcCore::app()->auth::PERMISSION_USAGE,
|
||||
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
|
||||
]), dcCore::app()->blog->id);
|
||||
self::status(My::checkContext(My::MANAGE));
|
||||
|
||||
// call period manage page
|
||||
if (($_REQUEST['part'] ?? 'periods') === 'period') {
|
||||
static::$init = ManagePeriod::init();
|
||||
self::status(ManagePeriod::init());
|
||||
}
|
||||
|
||||
return static::$init;
|
||||
return self::status();
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// nullsafe
|
||||
if (is_null(dcCore::app()->adminurl)) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -74,14 +67,14 @@ class Manage extends dcNsProcess
|
|||
Utils::delPeriod($id);
|
||||
}
|
||||
|
||||
dcPage::addSuccessNotice(
|
||||
Notices::addSuccessNotice(
|
||||
__('Periods removed.')
|
||||
);
|
||||
|
||||
if (!empty($vars->redir)) {
|
||||
Http::redirect($vars->redir);
|
||||
} else {
|
||||
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'periods']);
|
||||
My::redirect(['part' => 'periods']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
dcCore::app()->error->add($e->getMessage());
|
||||
|
@ -95,14 +88,14 @@ class Manage extends dcNsProcess
|
|||
Utils::delPeriodPosts($id);
|
||||
}
|
||||
|
||||
dcPage::addSuccessNotice(
|
||||
Notices::addSuccessNotice(
|
||||
__('Periods emptied.')
|
||||
);
|
||||
|
||||
if (!empty($vars->redir)) {
|
||||
Http::redirect($vars->redir);
|
||||
} else {
|
||||
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['part' => 'periods']);
|
||||
My::redirect(['part' => 'periods']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
dcCore::app()->error->add($e->getMessage());
|
||||
|
@ -117,12 +110,7 @@ class Manage extends dcNsProcess
|
|||
*/
|
||||
public static function render(): void
|
||||
{
|
||||
if (!static::$init) {
|
||||
return;
|
||||
}
|
||||
|
||||
// nullsafe
|
||||
if (is_null(dcCore::app()->adminurl)) {
|
||||
if (!self::status()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -134,7 +122,7 @@ class Manage extends dcNsProcess
|
|||
}
|
||||
|
||||
// Filters
|
||||
$p_filter = new adminGenericFilter(dcCore::app(), My::id());
|
||||
$p_filter = new Filters(My::id());
|
||||
$p_filter->add('part', 'periods');
|
||||
|
||||
$params = $p_filter->params();
|
||||
|
@ -143,23 +131,23 @@ class Manage extends dcNsProcess
|
|||
try {
|
||||
$periods = Utils::getPeriods($params);
|
||||
$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) {
|
||||
dcCore::app()->error->add($e->getMessage());
|
||||
}
|
||||
|
||||
// Display
|
||||
dcPage::openModule(
|
||||
Page::openModule(
|
||||
My::name(),
|
||||
dcPage::jsModuleLoad(My::id() . '/js/checkbox.js') .
|
||||
$p_filter->js(dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'periods']))
|
||||
My::jsLoad('checkbox') .
|
||||
$p_filter->js(My::manageUrl(['part' => 'periods']))
|
||||
);
|
||||
|
||||
echo dcPage::breadcrumb([
|
||||
echo Page::breadcrumb([
|
||||
__('Plugins') => '',
|
||||
My::name() => '',
|
||||
]) .
|
||||
dcPage::notices() .
|
||||
Notices::getNotices() .
|
||||
|
||||
'<p class="top-add">
|
||||
<a class="button add" href="' . dcCore::app()->admin->getPageURL() . '&part=period">' . __('New period') . '</a>
|
||||
|
@ -167,7 +155,7 @@ class Manage extends dcNsProcess
|
|||
|
||||
if (isset($period_list)) {
|
||||
// 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
|
||||
$period_list->periodDisplay(
|
||||
|
@ -182,14 +170,13 @@ class Manage extends dcNsProcess
|
|||
'<p class="col right">' . __('Selected periods action:') . ' ' .
|
||||
(new Select('action'))->items(My::periodsActionCombo())->render() .
|
||||
'<input type="submit" value="' . __('ok') . '" /></p>' .
|
||||
dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . My::id(), array_merge(['p' => My::id()], $p_filter->values(true))) .
|
||||
dcCore::app()->formNonce() .
|
||||
My::parsedHiddenFields($p_filter->values(true)) .
|
||||
'</div>' .
|
||||
'</form>'
|
||||
);
|
||||
}
|
||||
dcPage::helpBlock('periodical');
|
||||
Page::helpBlock('periodical');
|
||||
|
||||
dcPage::closeModule();
|
||||
Page::closeModule();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,12 +15,16 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\periodical;
|
||||
|
||||
use ArrayObject;
|
||||
use adminGenericFilter;
|
||||
use adminGenericList;
|
||||
use adminPostFilter;
|
||||
use dcBlog;
|
||||
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\Html\Form\Checkbox;
|
||||
use Dotclear\Helper\Html\Html;
|
||||
|
@ -30,15 +34,15 @@ use Dotclear\Helper\Html\Html;
|
|||
* @brief Periodical - admin pager methods.
|
||||
* @since 2.6
|
||||
*/
|
||||
class ManageList extends adminGenericList
|
||||
class ManageList extends Listing
|
||||
{
|
||||
/**
|
||||
* Display periods list.
|
||||
*
|
||||
* @param adminGenericFilter $filter The periods filter
|
||||
* @param Filters $filter The periods filter
|
||||
* @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 ($filter->show()) {
|
||||
|
@ -47,7 +51,7 @@ class ManageList extends adminGenericList
|
|||
echo '<p><strong>' . __('No period') . '</strong></p>';
|
||||
}
|
||||
} 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';
|
||||
|
||||
$periods = [];
|
||||
|
@ -99,7 +103,7 @@ class ManageList extends adminGenericList
|
|||
{
|
||||
$tz = dcCore::app()->auth?->getInfo('user_tz');
|
||||
$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>';
|
||||
$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()) ?
|
||||
|
@ -126,11 +130,11 @@ class ManageList extends adminGenericList
|
|||
/**
|
||||
* 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 $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 = '';
|
||||
if ($this->rs->isEmpty()) {
|
||||
|
@ -140,7 +144,7 @@ class ManageList extends adminGenericList
|
|||
echo '<p><strong>' . __('No entry') . '</strong></p>';
|
||||
}
|
||||
} 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->var_page = 'page';
|
||||
|
||||
|
|
|
@ -14,10 +14,13 @@ declare(strict_types=1);
|
|||
|
||||
namespace Dotclear\Plugin\periodical;
|
||||
|
||||
use adminPostFilter;
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use dcPage;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Core\Backend\{
|
||||
Notices,
|
||||
Page
|
||||
};
|
||||
use Dotclear\Core\Backend\Filter\FilterPosts;
|
||||
use Dotclear\Helper\Html\Form\{
|
||||
Datetime,
|
||||
Div,
|
||||
|
@ -38,24 +41,16 @@ use Exception;
|
|||
/**
|
||||
* Admin page for a period
|
||||
*/
|
||||
class ManagePeriod extends dcNsProcess
|
||||
class ManagePeriod extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init == defined('DC_CONTEXT_ADMIN')
|
||||
&& !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog)
|
||||
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
|
||||
dcCore::app()->auth::PERMISSION_USAGE,
|
||||
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
|
||||
]), dcCore::app()->blog->id)
|
||||
&& ($_REQUEST['part'] ?? 'periods') === 'period';
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::MANAGE) && ($_REQUEST['part'] ?? 'periods') === 'period');
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -170,12 +165,7 @@ class ManagePeriod extends dcNsProcess
|
|||
*/
|
||||
public static function render(): void
|
||||
{
|
||||
if (!static::$init) {
|
||||
return;
|
||||
}
|
||||
|
||||
// nullsafe
|
||||
if (is_null(dcCore::app()->adminurl)) {
|
||||
if (!self::status()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -187,7 +177,7 @@ class ManagePeriod extends dcNsProcess
|
|||
// Prepare combos for posts list
|
||||
if ($vars->period_id > 0) {
|
||||
// Filters
|
||||
$post_filter = new adminPostFilter();
|
||||
$post_filter = new FilterPosts();
|
||||
$post_filter->add('part', 'period');
|
||||
|
||||
$params = $post_filter->params();
|
||||
|
@ -198,31 +188,31 @@ class ManagePeriod extends dcNsProcess
|
|||
try {
|
||||
$posts = Utils::getPosts($params);
|
||||
$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) {
|
||||
dcCore::app()->error->add($e->getMessage());
|
||||
}
|
||||
|
||||
$starting_script = dcPage::jsModuleLoad(My::id() . '/js/checkbox.js') .
|
||||
$post_filter->js(dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'period', 'period_id' => $vars->period_id], '&') . '#posts');
|
||||
$starting_script = My::jsLoad('checkbox') .
|
||||
$post_filter->js(My::manageUrl(['part' => 'period', 'period_id' => $vars->period_id], '&') . '#posts');
|
||||
}
|
||||
|
||||
// Display
|
||||
dcPage::openModule(
|
||||
Page::openModule(
|
||||
My::name(),
|
||||
dcPage::jsModuleLoad(My::id() . '/js/dates.js') .
|
||||
My::jsLoad('dates') .
|
||||
$starting_script .
|
||||
dcPage::jsDatePicker() .
|
||||
dcPage::jsPageTabs()
|
||||
Page::jsDatePicker() .
|
||||
Page::jsPageTabs()
|
||||
);
|
||||
|
||||
echo
|
||||
dcPage::breadcrumb([
|
||||
Page::breadcrumb([
|
||||
__('Plugins') => '',
|
||||
My::name() => dcCore::app()->admin->getPageURL() . '&part=periods',
|
||||
(null === $vars->period_id ? __('New period') : __('Edit period')) => '',
|
||||
]) .
|
||||
dcPage::notices();
|
||||
Notices::getNotices();
|
||||
|
||||
// Period form
|
||||
echo
|
||||
|
@ -258,10 +248,11 @@ class ManagePeriod extends dcNsProcess
|
|||
(new Div())->class('clear')->items([
|
||||
(new Para())->items([
|
||||
(new Submit(['save']))->value(__('Save')),
|
||||
dcCore::app()->formNonce(false),
|
||||
(new Hidden(['action'], 'setperiod')),
|
||||
(new Hidden(['period_id'], (string) $vars->period_id)),
|
||||
(new Hidden(['part'], 'period')),
|
||||
... My::hiddenFields([
|
||||
'action' => 'setperiod',
|
||||
'period_id' => (string) $vars->period_id,
|
||||
'part' => 'period',
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
|
@ -290,7 +281,7 @@ class ManagePeriod extends dcNsProcess
|
|||
// Filters
|
||||
$post_filter->display(
|
||||
['admin.plugin.periodical', '#posts'],
|
||||
dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.periodical', [
|
||||
My::parsedHiddenFields([
|
||||
'period_id' => $vars->period_id,
|
||||
'part' => 'period',
|
||||
])
|
||||
|
@ -307,18 +298,18 @@ class ManagePeriod extends dcNsProcess
|
|||
'<div class="two-cols">' .
|
||||
'<p class="col checkboxes-helpers"></p>' .
|
||||
|
||||
(new Para())->class('col right')->items(array_merge(
|
||||
dcCore::app()->adminurl->hiddenFormFields('admin.plugin.periodical', array_merge($post_filter->values(), [
|
||||
'period_id' => $vars->period_id,
|
||||
'redir' => sprintf($base_url, $post_filter->value('page', '')),
|
||||
])),
|
||||
[
|
||||
(new Para())->class('col right')
|
||||
->items([
|
||||
(new Label(__('Selected entries action:'), Label::OUTSIDE_LABEL_BEFORE))->for('post_action')->class('classic'),
|
||||
(new Select(['action','post_action']))->items(My::entriesActionsCombo()),
|
||||
(new Submit('do_post_action'))->value(__('ok')),
|
||||
dcCore::app()->formNonce(false),
|
||||
]
|
||||
))->render() .
|
||||
... My::hiddenFields([
|
||||
... $post_filter->values(),
|
||||
'period_id' => $vars->period_id,
|
||||
'redir' => sprintf($base_url, $post_filter->value('page', '')),
|
||||
]),
|
||||
])
|
||||
->render() .
|
||||
'</div>' .
|
||||
'</form>'
|
||||
);
|
||||
|
@ -327,9 +318,9 @@ class ManagePeriod extends dcNsProcess
|
|||
'</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
|
||||
{
|
||||
dcPage::addSuccessNotice($msg);
|
||||
Notices::addSuccessNotice($msg);
|
||||
|
||||
if (!empty($redir)) {
|
||||
Http::redirect($redir);
|
||||
} else {
|
||||
dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id(), ['part' => 'period', 'period_id' => $id], $tab);
|
||||
My::redirect(['part' => 'period', 'period_id' => $id], $tab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
35
src/My.php
35
src/My.php
|
@ -15,11 +15,12 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\periodical;
|
||||
|
||||
use dcCore;
|
||||
use Dotclear\Module\MyPlugin;
|
||||
|
||||
/**
|
||||
* This module definitions.
|
||||
*/
|
||||
class My
|
||||
class My extends MyPlugin
|
||||
{
|
||||
/** @var string This module table name */
|
||||
public const TABLE_NAME = 'periodical';
|
||||
|
@ -27,30 +28,16 @@ class My
|
|||
/** @var string This module meta type */
|
||||
public const META_TYPE = 'periodical';
|
||||
|
||||
/**
|
||||
* This module id.
|
||||
*/
|
||||
public static function id(): string
|
||||
public static function checkCustomContext(int $context): ?bool
|
||||
{
|
||||
return basename(dirname(__DIR__));
|
||||
}
|
||||
|
||||
/**
|
||||
* This module name.
|
||||
*/
|
||||
public static function name(): string
|
||||
{
|
||||
$name = dcCore::app()->plugins->moduleInfo(self::id(), 'name');
|
||||
|
||||
return __(is_string($name) ? $name : self::id());
|
||||
}
|
||||
|
||||
/**
|
||||
* This module path.
|
||||
*/
|
||||
public static function path(): string
|
||||
{
|
||||
return dirname(__DIR__);
|
||||
return in_array($context, [My::MANAGE, My::MENU]) ?
|
||||
defined('DC_CONTEXT_ADMIN')
|
||||
&& !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)
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,21 +15,19 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\periodical;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Plugin\Uninstaller\Uninstaller;
|
||||
|
||||
class Uninstall extends dcNsProcess
|
||||
class Uninstall extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN');
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::UNINSTALL));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
|
||||
if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue