upgrade to Dotclear 2.27

This commit is contained in:
Jean-Christian Denis 2023-08-15 13:24:10 +02:00
parent 9207ae32c1
commit 7f4689c244
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
8 changed files with 50 additions and 115 deletions

View file

@ -14,46 +14,22 @@ declare(strict_types=1);
namespace Dotclear\Plugin\noodles; namespace Dotclear\Plugin\noodles;
use dcAdmin; use Dotclear\Core\Process;
use dcCore;
use dcMenu;
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));
&& !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog)
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
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;
} }
if (is_null(dcCore::app()->auth) My::addBackendMenuItem();
|| is_null(dcCore::app()->blog)
|| is_null(dcCore::app()->adminurl)
|| !(dcCore::app()->menu[dcAdmin::MENU_PLUGINS] instanceof dcMenu)
) {
return false;
}
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(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)
);
return true; return true;
} }

View file

@ -15,21 +15,19 @@ declare(strict_types=1);
namespace Dotclear\Plugin\noodles; namespace Dotclear\Plugin\noodles;
use dcCore; use dcCore;
use dcNsProcess;
use dcUtils; use dcUtils;
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,24 @@ declare(strict_types=1);
namespace Dotclear\Plugin\noodles; namespace Dotclear\Plugin\noodles;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
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));
&& is_string(dcCore::app()->plugins->moduleInfo(My::id(), 'version'))
&& 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; return false;
} }
try { try {
$s = dcCore::app()->blog?->settings->get(My::id()); $s = My::settings();
if (is_null($s)) { if (is_null($s)) {
return false; return false;
} }

View file

@ -15,8 +15,11 @@ declare(strict_types=1);
namespace Dotclear\Plugin\noodles; namespace Dotclear\Plugin\noodles;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Backend\{
use dcPage; Notices,
Page
};
use Dotclear\Core\Process;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox, Checkbox,
Div, Div,
@ -30,27 +33,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)
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
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;
} }
// nullsafe check // nullsafe check
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { if (is_null(dcCore::app()->blog)) {
return false; return false;
} }
@ -58,7 +55,7 @@ class Manage extends dcNsProcess
return true; return true;
} }
$s = dcCore::app()->blog->settings->get(My::id()); $s = My::settings();
$targets = Targets::instance(); $targets = Targets::instance();
try { try {
@ -85,8 +82,8 @@ class Manage extends dcNsProcess
$targets->export(); $targets->export();
dcCore::app()->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
dcPage::addSuccessNotice(__('Configuration successfully updated')); Notices::addSuccessNotice(__('Configuration successfully updated'));
dcCore::app()->adminurl->redirect('admin.plugin.noodles'); My::redirect();
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
@ -96,12 +93,12 @@ 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;
} }
@ -113,16 +110,16 @@ class Manage extends dcNsProcess
$note = '<a href="' . Image::getURL() . '">' . __('See local default avatar.') . '</a>'; $note = '<a href="' . Image::getURL() . '">' . __('See local default avatar.') . '</a>';
} }
dcPage::openModule(My::name()); Page::openModule(My::name());
echo echo
dcPage::breadcrumb([ Page::breadcrumb([
__('Plugin') => '', __('Plugin') => '',
My::name() => '', My::name() => '',
]) . ]) .
dcPage::notices() . ' Notices::getNotices() . '
<form id="module_config" action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '" method="post" enctype="multipart/form-data"> <form id="module_config" action="' . My::manageUrl() . '" method="post" enctype="multipart/form-data">
<h3>' . sprintf(__('Configure "%s"'), __('Noodles')) . '</h3>' . <h3>' . sprintf(__('Configure "%s"'), __('Noodles')) . '</h3>' .
(new Div()) (new Div())
->class('fieldset') ->class('fieldset')
@ -200,11 +197,11 @@ class Manage extends dcNsProcess
->class('clear') ->class('clear')
->items([ ->items([
(new Submit('save', __('Save') . ' (s)'))->accesskey('s'), (new Submit('save', __('Save') . ' (s)'))->accesskey('s'),
dcCore::app()->formNonce(false), ... My::hiddenFields(),
]) ])
->render() . ' ->render() . '
</form>'; </form>';
dcPage::closeModule(); Page::closeModule();
} }
} }

View file

@ -14,39 +14,13 @@ declare(strict_types=1);
namespace Dotclear\Plugin\noodles; namespace Dotclear\Plugin\noodles;
use dcCore; use Dotclear\Module\MyPlugin;
/** /**
* This module definitions. * This module definitions.
*/ */
class My class My extends MyPlugin
{ {
/** @var string Default image name */ /** @var string Default image name */
public const IMAGE = 'default-avatar.png'; public const IMAGE = 'default-avatar.png';
/**
* 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,20 +15,18 @@ declare(strict_types=1);
namespace Dotclear\Plugin\noodles; namespace Dotclear\Plugin\noodles;
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

@ -44,12 +44,10 @@ final class Targets
{ {
// try to read main settings // try to read main settings
$active = $api = $local = null; $active = $api = $local = null;
if (!is_null(dcCore::app()->blog)) { $s = My::settings();
$s = dcCore::app()->blog->settings->get(My::id()); $active = $s->get('active');
$active = $s->get('active'); $api = $s->get('api');
$api = $s->get('api'); $local = $s->get('local');
$local = $s->get('local');
}
// set main settings // set main settings
$this->active = is_bool($active) ? $active : false; $this->active = is_bool($active) ? $active : false;
@ -95,7 +93,7 @@ final class Targets
*/ */
public function import(): void public function import(): void
{ {
$s = dcCore::app()->blog?->settings->get(My::id())->get('settings'); $s = My::settings()->get('settings');
if (!is_string($s)) { if (!is_string($s)) {
return; return;
} }
@ -122,7 +120,7 @@ final class Targets
$targets[$target->id] = $target->exportSettings(); $targets[$target->id] = $target->exportSettings();
} }
dcCore::app()->blog?->settings->get(My::id())->put('settings', json_encode($targets), 'string'); My::settings()->put('settings', json_encode($targets), 'string');
} }
/** /**

View file

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