upgrade to Dotclear 2.27

This commit is contained in:
Jean-Christian 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;
use dcAdmin;
use dcCore;
use dcFavorites;
use dcMenu;
use dcNsProcess;
use dcPage;
use Dotclear\Core\Backend\Favorites;
use Dotclear\Core\Process;
class Backend extends dcNsProcess
class Backend extends Process
{
public static function init(): bool
{
static::$init = defined('DC_CONTEXT_ADMIN');
return static::$init;
return self::status(My::checkContext(My::BACKEND));
}
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;
}
// 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)
);
}
My::addBackendMenuItem();
// backend user dashboard icon
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {
// nullsafe
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->adminurl)) {
return;
}
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (Favorites $favs): void {
$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,

View file

@ -15,20 +15,18 @@ declare(strict_types=1);
namespace Dotclear\Plugin\filesAlias;
use dcCore;
use dcNsProcess;
use Dotclear\Core\Process;
class Frontend extends dcNsProcess
class Frontend extends Process
{
public static function init(): bool
{
static::$init = defined('DC_RC_PATH');
return static::$init;
return self::status(My::checkContext(My::FRONTEND));
}
public static function process(): bool
{
if (!static::$init) {
if (!self::status()) {
return false;
}

View file

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

View file

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

View file

@ -14,36 +14,13 @@ declare(strict_types=1);
namespace Dotclear\Plugin\filesAlias;
use dcCore;
use Dotclear\Module\MyPlugin;
/**
* This module definitions.
*/
class My extends \initFilesAlias
class My extends MyPlugin
{
/**
* 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__);
}
/** @var string This plugin table name */
public const ALIAS_TABLE_NAME = 'filesalias';
}

View file

@ -15,20 +15,18 @@ declare(strict_types=1);
namespace Dotclear\Plugin\filesAlias;
use dcCore;
use dcNsProcess;
use Dotclear\Core\Process;
class Prepend extends dcNsProcess
class Prepend extends Process
{
public static function init(): bool
{
static::$init = defined('DC_RC_PATH');
return static::$init;
return self::status(My::checkContext(My::PREPEND));
}
public static function process(): bool
{
if (!static::$init) {
if (!self::status()) {
return false;
}

View file

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