upgrade to Dotclear 2.27

master
Jean-Christian Paul Denis 2023-08-15 20:28:29 +02:00
parent d37c179661
commit 7502423750
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
9 changed files with 81 additions and 155 deletions

View File

@ -14,47 +14,25 @@ declare(strict_types=1);
namespace Dotclear\Plugin\postWidgetText; namespace Dotclear\Plugin\postWidgetText;
use dcAdmin;
use dcCore; use dcCore;
use dcPage; use Dotclear\Core\Process;
use dcNsProcess;
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()->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);
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false;
}
// nullsafe
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
return false; return false;
} }
// backend sidebar menu icon // backend sidebar menu icon
if (Utils::isActive()) { if (Utils::isActive()) {
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_CONTENT_ADMIN]), dcCore::app()->blog->id)
);
// backend user dashboard favorites icon
dcCore::app()->addBehavior('adminDashboardFavoritesV2', [BackendBehaviors::class, 'adminDashboardFavoritesV2']);
} }
// backend pwt management // backend pwt management
@ -82,7 +60,7 @@ class Backend extends dcNsProcess
]); ]);
// add plugin "importExport" features // add plugin "importExport" features
if (!is_null(dcCore::app()->blog) && dcCore::app()->blog->settings->get(My::id())->get('importexport_active')) { if (!My::settings()->get('importexport_active')) {
dcCore::app()->addBehaviors([ dcCore::app()->addBehaviors([
'exportFullV2' => [ImportExport::class, 'exportFullV2'], 'exportFullV2' => [ImportExport::class, 'exportFullV2'],
'exportSingleV2' => [ImportExport::class, 'exportSingleV2'], 'exportSingleV2' => [ImportExport::class, 'exportSingleV2'],

View File

@ -15,10 +15,8 @@ declare(strict_types=1);
namespace Dotclear\Plugin\postWidgetText; namespace Dotclear\Plugin\postWidgetText;
use ArrayObject; use ArrayObject;
use dcCore;
use dcFavorites;
use dcPage;
use dcSettings; use dcSettings;
use Dotclear\Core\Backend\Favorites;
use Dotclear\Database\{ use Dotclear\Database\{
Cursor, Cursor,
MetaRecord MetaRecord
@ -122,24 +120,20 @@ class BackendBehaviors
/** /**
* Add user dashboard icon. * Add user dashboard icon.
* *
* @param dcFavorites $favs The user favorites * @param Favorites $favs The user 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()->adminurl)) { $favs->register(
return; My::id(),
} [
'title' => My::name(),
$favs->register(My::id(), [ 'url' => My::manageUrl(),
'title' => __('Post widget text'), 'small-icon' => My::icons(),
'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()), 'large-icon' => My::icons(),
'small-icon' => dcPage::getPF(My::id() . '/icon.svg'), //'permissions' => null,
'large-icon' => dcPage::getPF(My::id() . '/icon.svg'), ]
'permissions' => dcCore::app()->auth->makePermissions([ );
dcCore::app()->auth::PERMISSION_USAGE,
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]),
]);
} }
/** /**
@ -149,7 +143,7 @@ class BackendBehaviors
*/ */
public static function adminPostHeaders(): string public static function adminPostHeaders(): string
{ {
return dcPage::jsModuleLoad(My::id() . '/js/backend.js'); return My::jsLoad('backend');
} }
/** /**
@ -253,7 +247,7 @@ class BackendBehaviors
} }
# Upddate widget # Upddate widget
else { else {
Utils::updWidget($w->f('option_id'), $wcur); Utils::updWidget((int) $w->f('option_id'), $wcur);
} }
} }
} }

View File

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

View File

@ -15,28 +15,20 @@ declare(strict_types=1);
namespace Dotclear\Plugin\postWidgetText; namespace Dotclear\Plugin\postWidgetText;
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) { if (!self::status()) {
return false;
}
// nullsafe
if (is_null(dcCore::app()->blog)) {
return false; return false;
} }
@ -62,7 +54,7 @@ class Install extends dcNsProcess
(new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s); (new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s);
// Settings // Settings
$s = dcCore::app()->blog->settings->get(My::id()); $s = My::settings();
$s->put( $s->put(
'active', 'active',
true, true,

View File

@ -14,38 +14,29 @@ declare(strict_types=1);
namespace Dotclear\Plugin\postWidgetText; namespace Dotclear\Plugin\postWidgetText;
use dcAdminFilters;
use adminGenericFilterV2;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Backend\Filter\{
use dcPage; Filters,
FiltersLibrary
};
use Dotclear\Core\Backend\{
Notices,
Page
};
use Dotclear\Core\Process;
use Dotclear\Helper\Network\Http; use Dotclear\Helper\Network\Http;
use Exception; use Exception;
use form; class Manage extends Process
class Manage extends dcNsProcess
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') return 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);
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false;
}
// nullsafe check
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
return false; return false;
} }
@ -56,13 +47,13 @@ class Manage extends dcNsProcess
Utils::delWidget((int) $id); Utils::delWidget((int) $id);
} }
dcPage::addSuccessNotice( Notices::addSuccessNotice(
__('Posts widgets successfully delete.') __('Posts widgets successfully delete.')
); );
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
Http::redirect($_POST['redir']); Http::redirect($_POST['redir']);
} else { } else {
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id()); My::redirect();
} }
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
@ -74,21 +65,21 @@ class Manage extends dcNsProcess
public static function render(): void public static function render(): void
{ {
if (!static::$init) { if (!self::status()) {
return; return;
} }
// nullsafe check // nullsafe check
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { if (is_null(dcCore::app()->blog)) {
return; return;
} }
# filters # filters
$filter = new adminGenericFilterV2('pwt'); $filter = new Filters('pwt');
$filter->add(dcAdminFilters::getPageFilter()); $filter->add(FiltersLibrary::getPageFilter());
$filter->add(dcAdminFilters::getInputFilter('search_post_title', __('Entry:'))); $filter->add(FiltersLibrary::getInputFilter('search_post_title', __('Entry:')));
$filter->add(dcAdminFilters::getInputFilter('search_widget_title', __('Widget:'))); $filter->add(FiltersLibrary::getInputFilter('search_widget_title', __('Widget:')));
$filter->add(dcAdminFilters::getInputFilter('user_id', __('User:'))); $filter->add(FiltersLibrary::getInputFilter('user_id', __('User:')));
$params = $filter->params(); $params = $filter->params();
# Get posts with text widget # Get posts with text widget
@ -102,38 +93,37 @@ class Manage extends dcNsProcess
} }
// display // display
dcPage::openModule( Page::openModule(
My::name(), My::name(),
dcPage::jsPageTabs() . Page::jsPageTabs() .
dcPage::jsModuleLoad(My::id() . '/js/manage.js') . My::jsLoad('manage') .
$filter->js(dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '#record') $filter->js(My::manageUrl() . '#record')
); );
echo echo
dcPage::breadcrumb([ Page::breadcrumb([
__('Plugins') => '', __('Plugins') => '',
My::name() => '', My::name() => '',
]) . ]) .
dcPage::notices(); Notices::getNotices();
if ($posts_list) { if ($posts_list) {
$filter->display('admin.plugin.' . My::id(), form::hidden('p', My::id())); $filter->display('admin.plugin.' . My::id());
$posts_list->display( $posts_list->display(
$filter, $filter,
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '" method="post" id="form-entries">' . '<form action="' . My::manageUrl() . '" method="post" id="form-entries">' .
'%s' . '%s' .
'<div class="two-cols">' . '<div class="two-cols">' .
'<p class="col checkboxes-helpers"></p>' . '<p class="col checkboxes-helpers"></p>' .
'<p class="col right">' . '<p class="col right">' .
'<input id="do-action" class="delete" type="submit" name="save" value="' . __('Delete selected widgets') . '" /></p>' . '<input id="do-action" class="delete" type="submit" name="save" value="' . __('Delete selected widgets') . '" /></p>' .
dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . My::id(), array_merge(['p' => My::id()], $filter->values(true))) . My::parsedHiddenFields($filter->values(true)) .
dcCore::app()->formNonce() .
'</div>' . '</div>' .
'</form>' '</form>'
); );
} }
dcPage::closeModule(); Page::closeModule();
} }
} }

View File

@ -15,11 +15,13 @@ declare(strict_types=1);
namespace Dotclear\Plugin\postWidgetText; namespace Dotclear\Plugin\postWidgetText;
use ArrayObject; use ArrayObject;
use adminGenericFilterV2;
use adminGenericListV2;
use context; use context;
use dcCore; use dcCore;
use dcPager; use Dotclear\Core\Backend\Filter\Filters;
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;
@ -29,18 +31,18 @@ use Dotclear\Helper\Html\Html;
* @brief postWidgetText - admin list methods. * @brief postWidgetText - admin list methods.
* @since 2.6 * @since 2.6
*/ */
class ManageList extends adminGenericListV2 class ManageList extends Listing
{ {
public function display(adminGenericFilterV2 $filter, string $enclose = '%s'): void public function display(Filters $filter, string $enclose = '%s'): void
{ {
// nullsafe // nullsafe
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog)) { if (is_null(dcCore::app()->blog)) {
return; return;
} }
// prepare page // prepare page
$blocks = explode('%s', $enclose); $blocks = explode('%s', $enclose);
$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);
$tz = dcCore::app()->auth->getInfo('user_tz') ?? (dcCore::app()->blog->settings->get('system')->get('blog_timezone') ?? 'UTC'); $tz = dcCore::app()->auth->getInfo('user_tz') ?? (dcCore::app()->blog->settings->get('system')->get('blog_timezone') ?? 'UTC');
// no record // no record

View File

@ -14,39 +14,13 @@ declare(strict_types=1);
namespace Dotclear\Plugin\postWidgetText; namespace Dotclear\Plugin\postWidgetText;
use dcCore; use Dotclear\Module\MyPlugin;
/** /**
* This module definitions. * This module definitions.
*/ */
class My class My extends MyPlugin
{ {
/** @var string Plugin table name */ /** @var string Plugin table name */
public const TABLE_NAME = 'post_option'; public const TABLE_NAME = \initPostWidgetText::PWT_TABLE_NAME;
/**
* This module id.
*/
public static function id(): string
{
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__);
}
} }

View File

@ -15,21 +15,19 @@ declare(strict_types=1);
namespace Dotclear\Plugin\postWidgetText; namespace Dotclear\Plugin\postWidgetText;
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;
} }

View File

@ -41,7 +41,7 @@ class Utils
*/ */
public static function isActive(): bool public static function isActive(): bool
{ {
return !is_null(dcCore::app()->blog) && dcCore::app()->blog->settings->get(My::id())->get('active'); return My::settings()->get('active');
} }
/** /**
@ -145,7 +145,7 @@ class Utils
public static function addWidget(Cursor $cur): int public static function addWidget(Cursor $cur): int
{ {
// nullsafe // nullsafe
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog)) { if (is_null(dcCore::app()->blog)) {
throw new Exception(__('Blog is not set')); throw new Exception(__('Blog is not set'));
} }
@ -206,7 +206,7 @@ class Utils
public static function updWidget(int $id, Cursor $cur): void public static function updWidget(int $id, Cursor $cur): void
{ {
// nullsafe // nullsafe
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog)) { if (is_null(dcCore::app()->blog)) {
throw new Exception(__('Blog is not set')); throw new Exception(__('Blog is not set'));
} }
@ -257,7 +257,7 @@ class Utils
public static function delWidget(int $id, ?string $type = null): void public static function delWidget(int $id, ?string $type = null): void
{ {
// nullsafe // nullsafe
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog)) { if (is_null(dcCore::app()->blog)) {
throw new Exception(__('Blog is not set')); throw new Exception(__('Blog is not set'));
} }