upgrade to Dotclear 2.27

master
Jean-Christian Paul Denis 2023-08-12 23:31:55 +02:00
parent f64d6de462
commit 23ad6f8f07
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
7 changed files with 62 additions and 128 deletions

View File

@ -14,55 +14,32 @@ declare(strict_types=1);
namespace Dotclear\Plugin\filesAlias; namespace Dotclear\Plugin\filesAlias;
use dcAdmin;
use dcCore; use dcCore;
use dcFavorites; use Dotclear\Core\Backend\Favorites;
use dcMenu; use Dotclear\Core\Process;
use dcNsProcess;
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));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }
// nullsafe My::addBackendMenuItem();
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
return false;
}
// backend sidebar menu icon
if ((dcCore::app()->menu[dcAdmin::MENU_BLOG] instanceof dcMenu)) {
dcCore::app()->menu[dcAdmin::MENU_BLOG]->addItem(
My::name(),
dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
dcPage::getPF(My::id() . '/icon.svg'),
preg_match('/' . preg_quote(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 icon // backend user dashboard icon
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void { dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (Favorites $favs): void {
// nullsafe
if (is_null(dcCore::app()->auth) || 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,

View File

@ -15,20 +15,18 @@ declare(strict_types=1);
namespace Dotclear\Plugin\filesAlias; namespace Dotclear\Plugin\filesAlias;
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,25 +15,20 @@ declare(strict_types=1);
namespace Dotclear\Plugin\filesAlias; namespace Dotclear\Plugin\filesAlias;
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
{ {
if (defined('DC_CONTEXT_ADMIN')) { return self::status(My::checkContext(My::INSTALL));
$version = dcCore::app()->plugins->moduleInfo(My::id(), 'version');
static::$init = is_string($version) ? dcCore::app()->newVersion(My::id(), $version) : true;
}
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }
@ -52,8 +47,7 @@ class Install extends dcNsProcess
->reference('fk_filesalias_blog', 'blog_id', 'blog', 'blog_id', 'cascade', 'cascade') ->reference('fk_filesalias_blog', 'blog_id', 'blog', 'blog_id', 'cascade', 'cascade')
; ;
$si = new Structure(dcCore::app()->con, dcCore::app()->prefix); (new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s);
$changes = $si->synchronize($s);
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {

View File

@ -16,8 +16,11 @@ namespace Dotclear\Plugin\filesAlias;
use dcCore; use dcCore;
use dcMedia; use dcMedia;
use dcNsProcess; use Dotclear\Core\Backend\{
use dcPage; Notices,
Page
};
use Dotclear\Core\Process;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox, Checkbox,
@ -32,30 +35,21 @@ use Dotclear\Helper\Html\Form\{
}; };
use Exception; use Exception;
class Manage extends dcNsProcess class Manage 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));
&& !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog) // nullsafe
&& dcCore::app()->auth->check(
dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_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;
} }
// nullsafe // nullsafe
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { if (is_null(dcCore::app()->blog)) {
return false; return false;
} }
@ -67,8 +61,8 @@ class Manage extends dcNsProcess
if (isset($_POST['a']) && is_array($_POST['a'])) { if (isset($_POST['a']) && is_array($_POST['a'])) {
try { try {
Utils::updateAliases($_POST['a']); Utils::updateAliases($_POST['a']);
dcPage::addSuccessNotice(__('Aliases successfully updated.')); Notices::addSuccessNotice(__('Aliases successfully updated.'));
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());
} }
@ -89,8 +83,8 @@ class Manage extends dcNsProcess
if (!empty($found)) { if (!empty($found)) {
try { try {
Utils::createAlias($url, $target, $totrash, $password); Utils::createAlias($url, $target, $totrash, $password);
dcPage::addSuccessNotice(__('Alias for this media created.')); Notices::addSuccessNotice(__('Alias for this media created.'));
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());
} }
@ -103,8 +97,8 @@ class Manage extends dcNsProcess
if (!empty($found)) { if (!empty($found)) {
try { try {
Utils::createAlias($url, $target, $totrash, $password); Utils::createAlias($url, $target, $totrash, $password);
dcPage::addSuccessNotice(__('Alias for this media modified.')); Notices::addSuccessNotice(__('Alias for this media modified.'));
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());
} }
@ -119,11 +113,11 @@ class Manage extends dcNsProcess
public static function render(): void public static function render(): void
{ {
if (!static::$init) { if (!self::status()) {
return; return;
} }
dcPage::openModule(My::name()); Page::openModule(My::name());
if (($_REQUEST['part'] ?? '') == 'new') { if (($_REQUEST['part'] ?? '') == 'new') {
self::displayAliasForm(); self::displayAliasForm();
@ -131,26 +125,26 @@ class Manage extends dcNsProcess
self::displayAliasList(); self::displayAliasList();
} }
dcPage::helpBlock('filesAlias'); Page::helpBlock('filesAlias');
dcPage::closeModule(); Page::closeModule();
} }
private static function displayAliasForm(): void private static function displayAliasForm(): void
{ {
// nullsafe // nullsafe
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl) || is_null(dcCore::app()->media)) { if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->media)) {
return; return;
} }
echo echo
dcPage::breadcrumb([ Page::breadcrumb([
Html::escapeHTML(dcCore::app()->blog->name) => '', Html::escapeHTML(dcCore::app()->blog->name) => '',
My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()), My::name() => My::manageUrl(),
__('New alias') => '', __('New alias') => '',
]) . ]) .
dcPage::notices() . Notices::getNotices() .
(new Form('filesalias_new'))->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()))->method('post')->fields([ (new Form('filesalias_new'))->action(My::manageUrl())->method('post')->fields([
(new Text('h3', Html::escapeHTML(__('New alias')))), (new Text('h3', Html::escapeHTML(__('New alias')))),
(new Note())->text(sprintf(__('Do not put blog media URL "%s" in fields or it will be removed.'), dcCore::app()->media->root_url))->class('form-note'), (new Note())->text(sprintf(__('Do not put blog media URL "%s" in fields or it will be removed.'), dcCore::app()->media->root_url))->class('form-note'),
// destination // destination
@ -178,8 +172,7 @@ class Manage extends dcNsProcess
// submit // submit
(new Para())->items([ (new Para())->items([
(new Submit(['save']))->value(__('Save')), (new Submit(['save']))->value(__('Save')),
(new Hidden(['part'], 'new')), ... My::hiddenFields(['part' => 'new']),
dcCore::app()->formNonce(false),
]), ]),
])->render(); ])->render();
} }
@ -187,20 +180,20 @@ class Manage extends dcNsProcess
private static function displayAliasList(): void private static function displayAliasList(): void
{ {
// nullsafe // nullsafe
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl) || is_null(dcCore::app()->media)) { if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->media)) {
return; return;
} }
$aliases = Utils::getAliases(); $aliases = Utils::getAliases();
echo echo
dcPage::breadcrumb([ Page::breadcrumb([
Html::escapeHTML(dcCore::app()->blog->name) => '', Html::escapeHTML(dcCore::app()->blog->name) => '',
My::name() => '', My::name() => '',
]) . ]) .
dcPage::notices() . Notices::getNotices() .
'<p class="top-add"><a class="button add" href="' . '<p class="top-add"><a class="button add" href="' .
dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'new']) . My::manageUrl(['part' => 'new']) .
'">' . __('New alias') . '</a></p>'; '">' . __('New alias') . '</a></p>';
if ($aliases->isEmpty()) { if ($aliases->isEmpty()) {
@ -233,7 +226,7 @@ class Manage extends dcNsProcess
} }
echo echo
(new Form('filesalias_list'))->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()))->method('post')->fields([ (new Form('filesalias_list'))->action(My::manageUrl())->method('post')->fields([
(new Text( (new Text(
'', '',
'<div class="table-outer">' . '<div class="table-outer">' .
@ -250,8 +243,7 @@ class Manage extends dcNsProcess
)), )),
(new Para())->items([ (new Para())->items([
(new Submit(['save']))->value(__('Update')), (new Submit(['save']))->value(__('Update')),
(new Hidden(['part'], 'list')), ... My::hiddenFields(['part' => 'list']),
dcCore::app()->formNonce(false),
]), ]),
(new Note())->text(__('To remove a link, empty its alias or destination.'))->class('form-note'), (new Note())->text(__('To remove a link, empty its alias or destination.'))->class('form-note'),
])->render(); ])->render();

View File

@ -14,36 +14,13 @@ declare(strict_types=1);
namespace Dotclear\Plugin\filesAlias; namespace Dotclear\Plugin\filesAlias;
use dcCore; use Dotclear\Module\MyPlugin;
/** /**
* This module definitions. * This module definitions.
*/ */
class My extends \initFilesAlias class My extends MyPlugin
{ {
/** /** @var string This plugin table name */
* This module id. public const ALIAS_TABLE_NAME = 'filesalias';
*/
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,20 +15,18 @@ declare(strict_types=1);
namespace Dotclear\Plugin\filesAlias; namespace Dotclear\Plugin\filesAlias;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
class Prepend extends dcNsProcess class Prepend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_RC_PATH'); return self::status(My::checkContext(My::PREPEND));
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,21 +15,19 @@ declare(strict_types=1);
namespace Dotclear\Plugin\filesAlias; namespace Dotclear\Plugin\filesAlias;
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;
} }