release 2.2
This commit is contained in:
parent
5bfa2c5c97
commit
18f27cc20a
10 changed files with 73 additions and 140 deletions
|
@ -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
|
||||
* require Dotclear 2.26
|
||||
* fix nullsafe warnings
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
[![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)
|
||||
[![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)
|
||||
[![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:
|
||||
|
||||
* content admin permissions to manage theme and public menu
|
||||
* Dotclear 2.26
|
||||
* content admin permissions to manage theme and public menu
|
||||
* Dotclear 2.27
|
||||
* PHP 7.4+
|
||||
|
||||
## USAGE
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
@ -18,9 +18,9 @@ $this->registerModule(
|
|||
'Arlequin',
|
||||
'Allows visitors choose a theme',
|
||||
'Oleksandr Syenchuk, Pierre Van Glabeke and contributors',
|
||||
'2.1',
|
||||
'2.2',
|
||||
[
|
||||
'requires' => [['core', '2.26']],
|
||||
'requires' => [['core', '2.27']],
|
||||
'permissions' => dcCore::app()->auth->makePermissions([
|
||||
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
|
||||
]),
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
<modules xmlns:da="http://dotaddict.org/da/">
|
||||
<module id="arlequin">
|
||||
<name>Arlequin</name>
|
||||
<version>2.1</version>
|
||||
<version>2.2</version>
|
||||
<author>Oleksandr Syenchuk, Pierre Van Glabeke and contributors</author>
|
||||
<desc>Allows visitors choose a theme</desc>
|
||||
<file>https://github.com/JcDenis/arlequin/releases/download/v2.1/plugin-arlequin.zip</file>
|
||||
<da:dcmin>2.26</da:dcmin>
|
||||
<file>https://github.com/JcDenis/arlequin/releases/download/v2.2/plugin-arlequin.zip</file>
|
||||
<da:dcmin>2.27</da:dcmin>
|
||||
<da:details>https://plugins.dotaddict.org/dc2/details/arlequin</da:details>
|
||||
<da:support>http://forum.dotclear.org/viewtopic.php?id=48345</da:support>
|
||||
</module>
|
||||
|
|
|
@ -14,61 +14,35 @@ declare(strict_types=1);
|
|||
|
||||
namespace Dotclear\Plugin\arlequin;
|
||||
|
||||
use dcAdmin;
|
||||
use dcCore;
|
||||
use dcFavorites;
|
||||
use dcNsProcess;
|
||||
use dcPage;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Core\Backend\{
|
||||
Favorites,
|
||||
Menus
|
||||
};
|
||||
|
||||
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) // 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;
|
||||
return self::status(My::checkContext(My::BACKEND));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
);
|
||||
My::addBackendMenuItem(Menus::MENU_BLOG);
|
||||
|
||||
dcCore::app()->addBehaviors([
|
||||
'adminDashboardFavoritesV2' => function (dcFavorites $favs): void {
|
||||
// nullsafe PHP < 8.0
|
||||
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->adminurl)) {
|
||||
return;
|
||||
}
|
||||
|
||||
'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'), dcPage::getPF(My::id() . '/icon-dark.svg')],
|
||||
'large-icon' => [dcPage::getPF(My::id() . '/icon.svg'), dcPage::getPF(My::id() . '/icon-dark.svg')],
|
||||
'url' => My::manageUrl(),
|
||||
'small-icon' => My::icons(),
|
||||
'large-icon' => My::icons(),
|
||||
'permissions' => dcCore::app()->auth->makePermissions([
|
||||
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
|
||||
]),
|
||||
|
|
|
@ -15,24 +15,22 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\arlequin;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Helper\Network\Http;
|
||||
|
||||
class Frontend extends dcNsProcess
|
||||
class Frontend extends Process
|
||||
{
|
||||
public const COOKIE_THEME_PREFIX = 'dc_theme_';
|
||||
public const COOKIE_UPDDT_PREFIX = 'dc_user_upddt_';
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -62,11 +60,6 @@ class Frontend extends dcNsProcess
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -79,13 +72,8 @@ class Frontend extends dcNsProcess
|
|||
|
||||
public static function switchTheme(string $theme): void
|
||||
{
|
||||
// nullsafe PHP < 8.0
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
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')))) {
|
||||
if (My::settings()->get('mt_exclude')) {
|
||||
if (in_array($theme, explode('/', My::settings()->get('mt_exclude')))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,11 @@ namespace Dotclear\Plugin\arlequin;
|
|||
|
||||
use ArrayObject;
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use dcPage;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Core\Backend\{
|
||||
Notices,
|
||||
Page
|
||||
};
|
||||
use Dotclear\Helper\Html\Form\{
|
||||
Div,
|
||||
Form,
|
||||
|
@ -32,32 +35,21 @@ use Dotclear\Helper\Html\Form\{
|
|||
use Dotclear\Helper\Html\Html;
|
||||
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 PHP < 8.0
|
||||
&& 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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// nullsafe PHP < 8.0
|
||||
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$s = dcCore::app()->blog->settings->get(My::id());
|
||||
$s = My::settings();
|
||||
|
||||
$model = json_decode((string) $s->get('model'), true);
|
||||
$exclude = $s->get('exclude');
|
||||
|
@ -69,7 +61,7 @@ class Manage extends dcNsProcess
|
|||
$s->put('model', json_encode($model), 'string', 'Arlequin configuration');
|
||||
$s->put('exclude', 'customCSS', 'string', 'Excluded themes');
|
||||
|
||||
dcPage::AddSuccessNotice(__('Settings have been reinitialized.'));
|
||||
Notices::AddSuccessNotice(__('Settings have been reinitialized.'));
|
||||
dcCore::app()->blog->triggerBlog();
|
||||
}
|
||||
|
||||
|
@ -86,9 +78,9 @@ class Manage extends dcNsProcess
|
|||
$s->put('model', json_encode($model));
|
||||
$s->put('exclude', $exclude);
|
||||
|
||||
dcPage::AddSuccessNotice(__('System settings have been updated.'));
|
||||
Notices::AddSuccessNotice(__('System settings have been updated.'));
|
||||
dcCore::app()->blog->triggerBlog();
|
||||
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['config' => 1]);
|
||||
My::redirect(['config' => 1]);
|
||||
}
|
||||
|
||||
// restore settings
|
||||
|
@ -96,9 +88,9 @@ class Manage extends dcNsProcess
|
|||
$s->drop('model');
|
||||
$s->drop('exclude');
|
||||
|
||||
dcPage::AddSuccessNotice(__('Settings have been reinitialized.'));
|
||||
Notices::AddSuccessNotice(__('Settings have been reinitialized.'));
|
||||
dcCore::app()->blog->triggerBlog();
|
||||
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['restore' => 1]);
|
||||
My::redirect(['restore' => 1]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
dcCore::app()->error->add($e->getMessage());
|
||||
|
@ -109,12 +101,7 @@ class Manage extends dcNsProcess
|
|||
|
||||
public static function render(): void
|
||||
{
|
||||
if (!static::$init) {
|
||||
return;
|
||||
}
|
||||
|
||||
// nullsafe PHP < 8.0
|
||||
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
|
||||
if (!self::status()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -123,7 +110,7 @@ class Manage extends dcNsProcess
|
|||
dcCore::app()->callBehavior('arlequinAddModels', $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 = array_merge(My::defaultModel(), is_array($model) ? $model : []);
|
||||
$header = '';
|
||||
|
@ -139,9 +126,9 @@ class Manage extends dcNsProcess
|
|||
");\n";
|
||||
}
|
||||
|
||||
dcPage::openModule(
|
||||
Page::openModule(
|
||||
My::name(),
|
||||
dcPage::jsModuleLoad(My::id() . '/js/models.js') . '
|
||||
Page::jsLoad('models') . '
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
arlequin.msg.predefined_models = "' . Html::escapeJS(__('Predefined models')) . '";
|
||||
|
@ -156,13 +143,13 @@ class Manage extends dcNsProcess
|
|||
);
|
||||
|
||||
echo
|
||||
dcPage::breadcrumb([
|
||||
Page::breadcrumb([
|
||||
Html::escapeHTML(dcCore::app()->blog->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 Div())->id('models'),
|
||||
(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 Para())->separator(' ')->items([
|
||||
dcCore::app()->formNonce(false),
|
||||
(new Submit(['mt_action_config']))->value(__('Save')),
|
||||
(new Submit(['mt_action_restore']))->value(__('Restore defaults')),
|
||||
... My::hiddenFields(),
|
||||
]),
|
||||
])->render();
|
||||
|
||||
dcPage::helpBlock('arlequin');
|
||||
dcPage::closeModule();
|
||||
Page::helpBlock('arlequin');
|
||||
Page::closeModule();
|
||||
}
|
||||
}
|
||||
|
|
32
src/My.php
32
src/My.php
|
@ -15,36 +15,20 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\arlequin;
|
||||
|
||||
use dcCore;
|
||||
use Dotclear\Module\MyPlugin;
|
||||
|
||||
/**
|
||||
* This module definitions.
|
||||
*/
|
||||
class My
|
||||
class My extends MyPlugin
|
||||
{
|
||||
/**
|
||||
* This module id.
|
||||
*/
|
||||
public static function id(): string
|
||||
public static function checkCustomContext(int $context): ?bool
|
||||
{
|
||||
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__);
|
||||
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,
|
||||
]), dcCore::app()->blog->id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,21 +15,19 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\arlequin;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,13 +45,8 @@ class Widgets
|
|||
return '';
|
||||
}
|
||||
|
||||
// nullsafe PHP < 8.0
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
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'));
|
||||
$model = json_decode((string) My::settings()->get('model'), true);
|
||||
$exclude = explode(';', (string) My::settings()->get('exclude'));
|
||||
$modules = array_diff_key(dcCore::app()->themes->getDefines(['state' => dcModuleDefine::STATE_ENABLED], true), array_flip($exclude));
|
||||
if (!is_array($model) || empty($modules)) {
|
||||
return '';
|
||||
|
|
Loading…
Reference in a new issue