upgrade to Dotclear 2.27
parent
9207ae32c1
commit
7f4689c244
|
@ -14,46 +14,22 @@ declare(strict_types=1);
|
|||
|
||||
namespace Dotclear\Plugin\noodles;
|
||||
|
||||
use dcAdmin;
|
||||
use dcCore;
|
||||
use dcMenu;
|
||||
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()->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;
|
||||
return self::status(My::checkContext(My::BACKEND));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_null(dcCore::app()->auth)
|
||||
|| 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)
|
||||
);
|
||||
My::addBackendMenuItem();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -15,21 +15,19 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\noodles;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use dcUtils;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,28 +15,24 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\noodles;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use Dotclear\Core\Process;
|
||||
use Exception;
|
||||
|
||||
class Install extends dcNsProcess
|
||||
class Install extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||
&& is_string(dcCore::app()->plugins->moduleInfo(My::id(), 'version'))
|
||||
&& 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) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$s = dcCore::app()->blog?->settings->get(My::id());
|
||||
$s = My::settings();
|
||||
if (is_null($s)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -15,8 +15,11 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\noodles;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use dcPage;
|
||||
use Dotclear\Core\Backend\{
|
||||
Notices,
|
||||
Page
|
||||
};
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Helper\Html\Form\{
|
||||
Checkbox,
|
||||
Div,
|
||||
|
@ -30,27 +33,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)
|
||||
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
|
||||
dcCore::app()->auth::PERMISSION_CONTENT_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 check
|
||||
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -58,7 +55,7 @@ class Manage extends dcNsProcess
|
|||
return true;
|
||||
}
|
||||
|
||||
$s = dcCore::app()->blog->settings->get(My::id());
|
||||
$s = My::settings();
|
||||
$targets = Targets::instance();
|
||||
|
||||
try {
|
||||
|
@ -85,8 +82,8 @@ class Manage extends dcNsProcess
|
|||
$targets->export();
|
||||
|
||||
dcCore::app()->blog->triggerBlog();
|
||||
dcPage::addSuccessNotice(__('Configuration successfully updated'));
|
||||
dcCore::app()->adminurl->redirect('admin.plugin.noodles');
|
||||
Notices::addSuccessNotice(__('Configuration successfully updated'));
|
||||
My::redirect();
|
||||
} catch (Exception $e) {
|
||||
dcCore::app()->error->add($e->getMessage());
|
||||
}
|
||||
|
@ -96,12 +93,12 @@ class Manage extends dcNsProcess
|
|||
|
||||
public static function render(): void
|
||||
{
|
||||
if (!static::$init) {
|
||||
if (!self::status()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// nullsafe check
|
||||
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -113,16 +110,16 @@ class Manage extends dcNsProcess
|
|||
$note = '<a href="' . Image::getURL() . '">' . __('See local default avatar.') . '</a>';
|
||||
}
|
||||
|
||||
dcPage::openModule(My::name());
|
||||
Page::openModule(My::name());
|
||||
|
||||
echo
|
||||
dcPage::breadcrumb([
|
||||
Page::breadcrumb([
|
||||
__('Plugin') => '',
|
||||
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>' .
|
||||
(new Div())
|
||||
->class('fieldset')
|
||||
|
@ -200,11 +197,11 @@ class Manage extends dcNsProcess
|
|||
->class('clear')
|
||||
->items([
|
||||
(new Submit('save', __('Save') . ' (s)'))->accesskey('s'),
|
||||
dcCore::app()->formNonce(false),
|
||||
... My::hiddenFields(),
|
||||
])
|
||||
->render() . '
|
||||
</form>';
|
||||
|
||||
dcPage::closeModule();
|
||||
Page::closeModule();
|
||||
}
|
||||
}
|
||||
|
|
30
src/My.php
30
src/My.php
|
@ -14,39 +14,13 @@ declare(strict_types=1);
|
|||
|
||||
namespace Dotclear\Plugin\noodles;
|
||||
|
||||
use dcCore;
|
||||
use Dotclear\Module\MyPlugin;
|
||||
|
||||
/**
|
||||
* This module definitions.
|
||||
*/
|
||||
class My
|
||||
class My extends MyPlugin
|
||||
{
|
||||
/** @var string Default image name */
|
||||
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__);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,20 +15,18 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\noodles;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,12 +44,10 @@ final class Targets
|
|||
{
|
||||
// try to read main settings
|
||||
$active = $api = $local = null;
|
||||
if (!is_null(dcCore::app()->blog)) {
|
||||
$s = dcCore::app()->blog->settings->get(My::id());
|
||||
$s = My::settings();
|
||||
$active = $s->get('active');
|
||||
$api = $s->get('api');
|
||||
$local = $s->get('local');
|
||||
}
|
||||
|
||||
// set main settings
|
||||
$this->active = is_bool($active) ? $active : false;
|
||||
|
@ -95,7 +93,7 @@ final class Targets
|
|||
*/
|
||||
public function import(): void
|
||||
{
|
||||
$s = dcCore::app()->blog?->settings->get(My::id())->get('settings');
|
||||
$s = My::settings()->get('settings');
|
||||
if (!is_string($s)) {
|
||||
return;
|
||||
}
|
||||
|
@ -122,7 +120,7 @@ final class Targets
|
|||
$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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,21 +15,19 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\noodles;
|
||||
|
||||
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 New Issue