use namespace

This commit is contained in:
Jean-Christian Denis 2023-03-25 00:19:15 +01:00
parent 9ac6481d85
commit 9a55cd1f2c
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
6 changed files with 297 additions and 141 deletions

View file

@ -10,24 +10,50 @@
* @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_CONTEXT_ADMIN')) { declare(strict_types=1);
return null;
}
dcCore::app()->menu[dcAdmin::MENU_BLOG]->addItem( namespace Dotclear\Plugin\moreCSS;
__('Style sheet'),
dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)), use dcAdmin;
[dcPage::getPF(basename(__DIR__) . '/icon.png')], use dcAuth;
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__))) . '(&.*)?$/', $_SERVER['REQUEST_URI']), use dcCore;
use dcFavorites;
use dcNsProcess;
use dcPage;
class Backend extends dcNsProcess
{
public static function init(): bool
{
static::$init = defined('DC_CONTEXT_ADMIN');
return static::$init;
}
public static function process(): bool
{
if (!static::$init) {
return false;
}
dcCore::app()->menu[dcAdmin::MENU_BLOG]->addItem(
My::name(),
dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
[dcPage::getPF(My::id() . '/icon.png')],
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CONTENT_ADMIN]), dcCore::app()->blog->id) dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CONTENT_ADMIN]), dcCore::app()->blog->id)
); );
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs) { dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {
$favs->register(basename(__DIR__), [ $favs->register(My::id(), [
'title' => __('Style sheet'), 'title' => My::name(),
'url' => dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)), 'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
'small-icon' => [dcPage::getPF(basename(__DIR__) . '/icon.png')], 'small-icon' => [dcPage::getPF(My::id() . '/icon.png')],
'large-icon' => [dcPage::getPF(basename(__DIR__) . '/icon-big.png')], 'large-icon' => [dcPage::getPF(My::id() . '/icon-big.png')],
'permissions' => dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CONTENT_ADMIN]), 'permissions' => dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CONTENT_ADMIN]),
]); ]);
}); });
return true;
}
}

View file

@ -10,21 +10,40 @@
* @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')) { declare(strict_types=1);
return null;
}
if (!dcCore::app()->blog->settings->get('themes')->get('morecss_active')) { namespace Dotclear\Plugin\moreCSS;
return null;
}
dcCore::app()->addBehavior('publicHeadContent', function () { use dcCore;
use dcNsProcess;
use dcUtils;
class Frontend extends dcNsProcess
{
public static function init(): bool
{
static::$init = defined('DC_RC_PATH');
return static::$init;
}
public static function process(): bool
{
if (!static::$init || !dcCore::app()->blog->settings->get('themes')->get('morecss_active')) {
return false;
}
dcCore::app()->addBehavior('publicHeadContent', function (): void {
$css = (string) base64_decode((string) dcCore::app()->blog->settings->get('themes')->get('morecss_min')); $css = (string) base64_decode((string) dcCore::app()->blog->settings->get('themes')->get('morecss_min'));
if (!empty($css)) { if (!empty($css)) {
echo dcUtils::cssLoad( echo dcUtils::cssLoad(
dcCore::app()->blog->url . dcCore::app()->url->getURLFor(basename(__DIR__)), dcCore::app()->blog->url . dcCore::app()->url->getURLFor(My::id()),
'screen', 'screen',
md5($css) //no cache on content change md5($css) //no cache on content change
); );
} }
}); });
return true;
}
}

View file

@ -10,26 +10,41 @@
* @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_CONTEXT_ADMIN')) { declare(strict_types=1);
return null;
}
try { namespace Dotclear\Plugin\moreCSS;
if (!dcCore::app()->newVersion(
basename(__DIR__), use dcCore;
dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version') use dcNsProcess;
)) { use Exception;
return null;
class Install extends dcNsProcess
{
public static function init(): bool
{
static::$init = defined('DC_CONTEXT_ADMIN')
&& dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
return static::$init;
} }
public static function process(): bool
{
if (!static::$init) {
return false;
}
try {
$s = dcCore::app()->blog->settings->get('themes'); $s = dcCore::app()->blog->settings->get('themes');
$s->put('morecss_active', true, 'boolean', 'Enable additionnal CSS for the active theme', false, true); $s->put('morecss_active', true, 'boolean', 'Enable additionnal CSS for the active theme', false, true);
$s->put('morecss', '', 'string', 'Additionnal CSS for the active theme', false, true); $s->put('morecss', '', 'string', 'Additionnal CSS for the active theme', false, true);
$s->put('morecss_min', '', 'string', 'Minified addtionnal CSS for the active theme', false, true); $s->put('morecss_min', '', 'string', 'Minified addtionnal CSS for the active theme', false, true);
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
return false; return true;
}
}

View file

@ -10,17 +10,39 @@
* @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_CONTEXT_ADMIN')) { declare(strict_types=1);
return null;
}
dcPage::check(dcCore::app()->auth->makePermissions([ namespace Dotclear\Plugin\moreCSS;
use dcAuth;
use dcCore;
use dcNsProcess;
use dcPage;
use Exception;
use html;
use form;
class Manage extends dcNsProcess
{
public static function init(): bool
{
static::$init = defined('DC_CONTEXT_ADMIN')
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_CONTENT_ADMIN, dcAuth::PERMISSION_CONTENT_ADMIN,
])); ]), dcCore::app()->blog->id);
$s = dcCore::app()->blog->settings->get('themes'); return static::$init;
}
if (isset($_POST['morecss'])) { public static function process(): bool
{
if (!static::$init) {
return false;
}
$s = dcCore::app()->blog->settings->get('themes');
if (isset($_POST['morecss'])) {
try { try {
// Save CSS // Save CSS
$css = base64_encode($_POST['morecss']); $css = base64_encode($_POST['morecss']);
@ -36,60 +58,73 @@ if (isset($_POST['morecss'])) {
$css_min = str_replace([' : ', ' :', ': '], ':', $css_min); $css_min = str_replace([' : ', ' :', ': '], ':', $css_min);
$css_min = str_replace([' ; ', ' ;', '; '], ';', $css_min); $css_min = str_replace([' ; ', ' ;', '; '], ';', $css_min);
$css_min = str_replace([' , ', ' ,', ', '], ',', $css_min); $css_min = str_replace([' , ', ' ,', ', '], ',', $css_min);
$s->put('morecss_min', base64_encode($css_min)); $s->put('morecss_min', is_string($css_min) ? base64_encode($css_min) : '');
dcAdminNotices::addSuccessNotice( dcPage::addSuccessNotice(
__('Configuration successfully updated.') __('Configuration successfully updated.')
); );
dcCore::app()->adminurl->redirect( dcCore::app()->adminurl->redirect(
'admin.plugin.' . basename(__DIR__) 'admin.plugin.' . My::id()
); );
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
return true;
}
public static function render(): void
{
if (!static::$init) {
return;
}
$s = dcCore::app()->blog->settings->get('themes');
dcPage::openModule(
My::name(),
(
dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax') ?
dcPage::jsJson('dotclear_colorsyntax', ['colorsyntax' => dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax')]) .
dcPage::jsLoadCodeMirror(dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme'))
: ''
)
);
echo '
<html><head><title>' . __('Style sheet') . '</title>';
if (dcCore::app()->auth->user_prefs->interface->colorsyntax) {
echo echo
dcPage::jsJson('dotclear_colorsyntax', ['colorsyntax' => dcCore::app()->auth->user_prefs->interface->colorsyntax]) . dcPage::breadcrumb([
dcPage::jsLoadCodeMirror(dcCore::app()->auth->user_prefs->interface->colorsyntax_theme);
}
echo '
</head><body>' .
dcPage::breadcrumb([
html::escapeHTML(dcCore::app()->blog->name) => '', html::escapeHTML(dcCore::app()->blog->name) => '',
__('Style sheet') => '', My::name() => '',
]) . ]) .
dcPage::notices() . ' dcPage::notices() . '
<form action="' . dcCore::app()->admin->getPageURL() . '" id="file-form" method="post"> <form action="' . dcCore::app()->admin->getPageURL() . '" id="file-form" method="post">
<div><h3><label for="morecss">' . __('Style sheet:') . '</strong></label></h3> <div><h3><label for="morecss">' . __('Style sheet:') . '</strong></label></h3>
<p>' . form::textarea('morecss', 72, 25, [ <p>' . form::textarea('morecss', 72, 25, [
'default' => html::escapeHTML((string) base64_decode((string) $s->get('morecss'))), 'default' => html::escapeHTML((string) base64_decode((string) $s->get('morecss'))),
'class' => 'maximal', 'class' => 'maximal',
]) . '</p> ]) . '</p>
<p><label class="classic" for="morecss_active">' . <p><label class="classic" for="morecss_active">' .
form::checkbox('morecss_active', 1, $s->get('morecss_active')) . ' ' . form::checkbox('morecss_active', 1, $s->get('morecss_active')) . ' ' .
__('Enable additionnal CSS for the active theme') . __('Enable additionnal CSS for the active theme') .
'</label></p> '</label></p>
<p>' . <p>' .
form::hidden('p', 'moreCSS') . form::hidden('p', 'moreCSS') .
dcCore::app()->formNonce() . ' dcCore::app()->formNonce() . '
<input type="submit" name="write" value="' . __('Save') . ' (s)" accesskey="s" /></p> <input type="submit" name="write" value="' . __('Save') . ' (s)" accesskey="s" /></p>
</form>'; </form>';
if (dcCore::app()->auth->user_prefs->interface->colorsyntax) { if (dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax')) {
echo echo
dcPage::jsJson('theme_editor_mode', ['mode' => 'css']) . dcPage::jsJson('theme_editor_mode', ['mode' => 'css']) .
dcPage::jsModuleLoad('themeEditor/js/mode.js') . dcPage::jsModuleLoad('themeEditor/js/mode.js') .
dcPage::jsRunCodeMirror('editor', 'morecss', 'dotclear', dcCore::app()->auth->user_prefs->interface->colorsyntax_theme); dcPage::jsRunCodeMirror('editor', 'morecss', 'dotclear', dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme'));
} }
echo ' dcPage::closeModule();
</body> }
</html>'; }

39
src/My.php Normal file
View file

@ -0,0 +1,39 @@
<?php
/**
* @brief moreCSS, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\moreCSS;
use dcCore;
/**
* Plugin definitions
*/
class My
{
/**
* This module id
*/
public static function id(): string
{
return basename(dirname(__DIR__));
}
/**
* This module name
*/
public static function name(): string
{
return __((string) dcCore::app()->plugins->moduleInfo(self::id(), 'name'));
}
}

View file

@ -10,15 +10,33 @@
* @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')) { declare(strict_types=1);
return null;
}
dcCore::app()->url->register( namespace Dotclear\Plugin\moreCSS;
basename(__DIR__),
use dcCore;
use dcNsProcess;
class Prepend extends dcNsProcess
{
public static function init(): bool
{
static::$init = defined('DC_RC_PATH');
return static::$init;
}
public static function process(): bool
{
if (!static::$init) {
return false;
}
dcCore::app()->url->register(
My::id(),
'morecss.css', 'morecss.css',
'^morecss\.css(.*?)$', '^morecss\.css(.*?)$',
function ($args) { function (string $args): void {
header('Content-Type: text/css; charset=UTF-8'); header('Content-Type: text/css; charset=UTF-8');
echo "/* CSS for plugin moreCss */ \n"; echo "/* CSS for plugin moreCss */ \n";
@ -26,4 +44,8 @@ dcCore::app()->url->register(
exit; exit;
} }
); );
return true;
}
}