release 2.2

This commit is contained in:
Jean-Christian Denis 2023-07-30 10:01:37 +02:00
parent 5bfa2c5c97
commit 18f27cc20a
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
10 changed files with 73 additions and 140 deletions

View file

@ -1,3 +1,9 @@
2.2 - 2023.07.30
* require Dotclear 2.27
* require PHP 7.4+
* use new svg icon
* update to Dotclear 2.27-dev
2.1 - 2023.05.13 2.1 - 2023.05.13
* require Dotclear 2.26 * require Dotclear 2.26
* fix nullsafe warnings * fix nullsafe warnings

View file

@ -3,7 +3,7 @@
[![Release](https://img.shields.io/github/v/release/JcDenis/arlequin)](https://github.com/JcDenis/arlequin/releases) [![Release](https://img.shields.io/github/v/release/JcDenis/arlequin)](https://github.com/JcDenis/arlequin/releases)
[![Date](https://img.shields.io/github/release-date/JcDenis/arlequin)](https://github.com/JcDenis/arlequin/releases) [![Date](https://img.shields.io/github/release-date/JcDenis/arlequin)](https://github.com/JcDenis/arlequin/releases)
[![Issues](https://img.shields.io/github/issues/JcDenis/arlequin)](https://github.com/JcDenis/arlequin/issues) [![Issues](https://img.shields.io/github/issues/JcDenis/arlequin)](https://github.com/JcDenis/arlequin/issues)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.26-blue.svg)](https://fr.dotclear.org/download) [![Dotclear](https://img.shields.io/badge/dotclear-v2.27-blue.svg)](https://fr.dotclear.org/download)
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/arlequin) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/arlequin)
[![License](https://img.shields.io/github/license/JcDenis/arlequin)](https://github.com/JcDenis/arlequin/blob/master/LICENSE) [![License](https://img.shields.io/github/license/JcDenis/arlequin)](https://github.com/JcDenis/arlequin/blob/master/LICENSE)
@ -18,8 +18,9 @@ It allows visitors to select a theme on your blog.
_arlequin_ requires: _arlequin_ requires:
* content admin permissions to manage theme and public menu * content admin permissions to manage theme and public menu
* Dotclear 2.26 * Dotclear 2.27
* PHP 7.4+
## USAGE ## USAGE

View file

@ -10,7 +10,7 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH') || is_null(dcCore::app()->auth)) { if (!defined('DC_RC_PATH')) {
return; return;
} }
@ -18,9 +18,9 @@ $this->registerModule(
'Arlequin', 'Arlequin',
'Allows visitors choose a theme', 'Allows visitors choose a theme',
'Oleksandr Syenchuk, Pierre Van Glabeke and contributors', 'Oleksandr Syenchuk, Pierre Van Glabeke and contributors',
'2.1', '2.2',
[ [
'requires' => [['core', '2.26']], 'requires' => [['core', '2.27']],
'permissions' => dcCore::app()->auth->makePermissions([ 'permissions' => dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), ]),

View file

@ -2,11 +2,11 @@
<modules xmlns:da="http://dotaddict.org/da/"> <modules xmlns:da="http://dotaddict.org/da/">
<module id="arlequin"> <module id="arlequin">
<name>Arlequin</name> <name>Arlequin</name>
<version>2.1</version> <version>2.2</version>
<author>Oleksandr Syenchuk, Pierre Van Glabeke and contributors</author> <author>Oleksandr Syenchuk, Pierre Van Glabeke and contributors</author>
<desc>Allows visitors choose a theme</desc> <desc>Allows visitors choose a theme</desc>
<file>https://github.com/JcDenis/arlequin/releases/download/v2.1/plugin-arlequin.zip</file> <file>https://github.com/JcDenis/arlequin/releases/download/v2.2/plugin-arlequin.zip</file>
<da:dcmin>2.26</da:dcmin> <da:dcmin>2.27</da:dcmin>
<da:details>https://plugins.dotaddict.org/dc2/details/arlequin</da:details> <da:details>https://plugins.dotaddict.org/dc2/details/arlequin</da:details>
<da:support>http://forum.dotclear.org/viewtopic.php?id=48345</da:support> <da:support>http://forum.dotclear.org/viewtopic.php?id=48345</da:support>
</module> </module>

View file

@ -14,61 +14,35 @@ declare(strict_types=1);
namespace Dotclear\Plugin\arlequin; namespace Dotclear\Plugin\arlequin;
use dcAdmin;
use dcCore; use dcCore;
use dcFavorites; use Dotclear\Core\Process;
use dcNsProcess; use Dotclear\Core\Backend\{
use dcPage; Favorites,
Menus
};
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) // nullsafe PHP < 8.0
&& 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 PHP < 8.0 My::addBackendMenuItem(Menus::MENU_BLOG);
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
return false;
}
dcCore::app()->menu[dcAdmin::MENU_BLOG]->addItem(
My::name(),
dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
[dcPage::getPF(My::id() . '/icon.svg'), dcPage::getPF(My::id() . '/icon-dark.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)
);
dcCore::app()->addBehaviors([ dcCore::app()->addBehaviors([
'adminDashboardFavoritesV2' => function (dcFavorites $favs): void { 'adminDashboardFavoritesV2' => function (Favorites $favs): void {
// nullsafe PHP < 8.0
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'), dcPage::getPF(My::id() . '/icon-dark.svg')], 'small-icon' => My::icons(),
'large-icon' => [dcPage::getPF(My::id() . '/icon.svg'), dcPage::getPF(My::id() . '/icon-dark.svg')], 'large-icon' => My::icons(),
'permissions' => dcCore::app()->auth->makePermissions([ 'permissions' => dcCore::app()->auth->makePermissions([
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), ]),

View file

@ -15,24 +15,22 @@ declare(strict_types=1);
namespace Dotclear\Plugin\arlequin; namespace Dotclear\Plugin\arlequin;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use Dotclear\Helper\Network\Http; use Dotclear\Helper\Network\Http;
class Frontend extends dcNsProcess class Frontend extends Process
{ {
public const COOKIE_THEME_PREFIX = 'dc_theme_'; public const COOKIE_THEME_PREFIX = 'dc_theme_';
public const COOKIE_UPDDT_PREFIX = 'dc_user_upddt_'; public const COOKIE_UPDDT_PREFIX = 'dc_user_upddt_';
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;
} }
@ -62,11 +60,6 @@ class Frontend extends dcNsProcess
protected static function cookieSuffix(): string protected static function cookieSuffix(): string
{ {
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->blog)) {
return '';
}
return base_convert(dcCore::app()->blog->uid, 16, 36); return base_convert(dcCore::app()->blog->uid, 16, 36);
} }
@ -79,13 +72,8 @@ class Frontend extends dcNsProcess
public static function switchTheme(string $theme): void public static function switchTheme(string $theme): void
{ {
// nullsafe PHP < 8.0 if (My::settings()->get('mt_exclude')) {
if (is_null(dcCore::app()->blog)) { if (in_array($theme, explode('/', My::settings()->get('mt_exclude')))) {
return;
}
if (dcCore::app()->blog->settings->get(My::id())->get('mt_exclude')) {
if (in_array($theme, explode('/', dcCore::app()->blog->settings->get(My::id())->get('mt_exclude')))) {
return; return;
} }
} }

View file

@ -16,8 +16,11 @@ namespace Dotclear\Plugin\arlequin;
use ArrayObject; use ArrayObject;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use dcPage; use Dotclear\Core\Backend\{
Notices,
Page
};
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Div, Div,
Form, Form,
@ -32,32 +35,21 @@ use Dotclear\Helper\Html\Form\{
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
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 PHP < 8.0
&& 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;
}
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
return false; return false;
} }
try { try {
$s = dcCore::app()->blog->settings->get(My::id()); $s = My::settings();
$model = json_decode((string) $s->get('model'), true); $model = json_decode((string) $s->get('model'), true);
$exclude = $s->get('exclude'); $exclude = $s->get('exclude');
@ -69,7 +61,7 @@ class Manage extends dcNsProcess
$s->put('model', json_encode($model), 'string', 'Arlequin configuration'); $s->put('model', json_encode($model), 'string', 'Arlequin configuration');
$s->put('exclude', 'customCSS', 'string', 'Excluded themes'); $s->put('exclude', 'customCSS', 'string', 'Excluded themes');
dcPage::AddSuccessNotice(__('Settings have been reinitialized.')); Notices::AddSuccessNotice(__('Settings have been reinitialized.'));
dcCore::app()->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
} }
@ -86,9 +78,9 @@ class Manage extends dcNsProcess
$s->put('model', json_encode($model)); $s->put('model', json_encode($model));
$s->put('exclude', $exclude); $s->put('exclude', $exclude);
dcPage::AddSuccessNotice(__('System settings have been updated.')); Notices::AddSuccessNotice(__('System settings have been updated.'));
dcCore::app()->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['config' => 1]); My::redirect(['config' => 1]);
} }
// restore settings // restore settings
@ -96,9 +88,9 @@ class Manage extends dcNsProcess
$s->drop('model'); $s->drop('model');
$s->drop('exclude'); $s->drop('exclude');
dcPage::AddSuccessNotice(__('Settings have been reinitialized.')); Notices::AddSuccessNotice(__('Settings have been reinitialized.'));
dcCore::app()->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['restore' => 1]); My::redirect(['restore' => 1]);
} }
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
@ -109,12 +101,7 @@ class Manage extends dcNsProcess
public static function render(): void public static function render(): void
{ {
if (!static::$init) { if (!self::status()) {
return;
}
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
return; return;
} }
@ -123,7 +110,7 @@ class Manage extends dcNsProcess
dcCore::app()->callBehavior('arlequinAddModels', $models); dcCore::app()->callBehavior('arlequinAddModels', $models);
$models = iterator_to_array($models); $models = iterator_to_array($models);
$s = dcCore::app()->blog->settings->get(My::id()); $s = My::settings();
$model = json_decode((string) $s->get('model'), true); $model = json_decode((string) $s->get('model'), true);
$model = array_merge(My::defaultModel(), is_array($model) ? $model : []); $model = array_merge(My::defaultModel(), is_array($model) ? $model : []);
$header = ''; $header = '';
@ -139,9 +126,9 @@ class Manage extends dcNsProcess
");\n"; ");\n";
} }
dcPage::openModule( Page::openModule(
My::name(), My::name(),
dcPage::jsModuleLoad(My::id() . '/js/models.js') . ' Page::jsLoad('models') . '
<script type="text/javascript"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[
arlequin.msg.predefined_models = "' . Html::escapeJS(__('Predefined models')) . '"; arlequin.msg.predefined_models = "' . Html::escapeJS(__('Predefined models')) . '";
@ -156,13 +143,13 @@ class Manage extends dcNsProcess
); );
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() .
(new Form(My::id() . 'form'))->method('post')->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()))->fields([ (new Form(My::id() . 'form'))->method('post')->action(dcCore::app()->admin->getPageURL())->fields([
(new Text('h4', __('Switcher display format'))), (new Text('h4', __('Switcher display format'))),
(new Div())->id('models'), (new Div())->id('models'),
(new Div())->class('two-boxes odd')->items([ (new Div())->class('two-boxes odd')->items([
@ -189,13 +176,13 @@ class Manage extends dcNsProcess
(new Note())->class('form-note')->text('Semicolon separated list of themes IDs (theme folder name). Ex: ductile;berlin'), (new Note())->class('form-note')->text('Semicolon separated list of themes IDs (theme folder name). Ex: ductile;berlin'),
]), ]),
(new Para())->separator(' ')->items([ (new Para())->separator(' ')->items([
dcCore::app()->formNonce(false),
(new Submit(['mt_action_config']))->value(__('Save')), (new Submit(['mt_action_config']))->value(__('Save')),
(new Submit(['mt_action_restore']))->value(__('Restore defaults')), (new Submit(['mt_action_restore']))->value(__('Restore defaults')),
... My::hiddenFields(),
]), ]),
])->render(); ])->render();
dcPage::helpBlock('arlequin'); Page::helpBlock('arlequin');
dcPage::closeModule(); Page::closeModule();
} }
} }

View file

@ -15,36 +15,20 @@ declare(strict_types=1);
namespace Dotclear\Plugin\arlequin; namespace Dotclear\Plugin\arlequin;
use dcCore; use dcCore;
use Dotclear\Module\MyPlugin;
/** /**
* This module definitions. * This module definitions.
*/ */
class My class My extends MyPlugin
{ {
/** public static function checkCustomContext(int $context): ?bool
* This module id.
*/
public static function id(): string
{ {
return basename(dirname(__DIR__)); return !in_array($context, [My::BACKEND, My::MANAGE, My::MENU]) ? null :
} defined('DC_CONTEXT_ADMIN')
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
/** dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
* This module name. ]), dcCore::app()->blog->id);
*/
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\arlequin; namespace Dotclear\Plugin\arlequin;
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

@ -45,13 +45,8 @@ class Widgets
return ''; return '';
} }
// nullsafe PHP < 8.0 $model = json_decode((string) My::settings()->get('model'), true);
if (is_null(dcCore::app()->blog)) { $exclude = explode(';', (string) My::settings()->get('exclude'));
return '';
}
$model = json_decode((string) dcCore::app()->blog->settings->get(My::id())->get('model'), true);
$exclude = explode(';', (string) dcCore::app()->blog->settings->get(My::id())->get('exclude'));
$modules = array_diff_key(dcCore::app()->themes->getDefines(['state' => dcModuleDefine::STATE_ENABLED], true), array_flip($exclude)); $modules = array_diff_key(dcCore::app()->themes->getDefines(['state' => dcModuleDefine::STATE_ENABLED], true), array_flip($exclude));
if (!is_array($model) || empty($modules)) { if (!is_array($model) || empty($modules)) {
return ''; return '';