use namespace
This commit is contained in:
parent
9ac6481d85
commit
9a55cd1f2c
6 changed files with 297 additions and 141 deletions
|
@ -10,24 +10,50 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return null;
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\moreCSS;
|
||||
|
||||
use dcAdmin;
|
||||
use dcAuth;
|
||||
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(
|
||||
__('Style sheet'),
|
||||
dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)),
|
||||
[dcPage::getPF(basename(__DIR__) . '/icon.png')],
|
||||
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__))) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
|
||||
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()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs) {
|
||||
$favs->register(basename(__DIR__), [
|
||||
'title' => __('Style sheet'),
|
||||
'url' => dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)),
|
||||
'small-icon' => [dcPage::getPF(basename(__DIR__) . '/icon.png')],
|
||||
'large-icon' => [dcPage::getPF(basename(__DIR__) . '/icon-big.png')],
|
||||
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $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.png')],
|
||||
'large-icon' => [dcPage::getPF(My::id() . '/icon-big.png')],
|
||||
'permissions' => dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CONTENT_ADMIN]),
|
||||
]);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,21 +10,40 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\moreCSS;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use dcUtils;
|
||||
|
||||
class Frontend extends dcNsProcess
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_RC_PATH');
|
||||
|
||||
return static::$init;
|
||||
}
|
||||
|
||||
if (!dcCore::app()->blog->settings->get('themes')->get('morecss_active')) {
|
||||
return null;
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init || !dcCore::app()->blog->settings->get('themes')->get('morecss_active')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
dcCore::app()->addBehavior('publicHeadContent', function () {
|
||||
dcCore::app()->addBehavior('publicHeadContent', function (): void {
|
||||
$css = (string) base64_decode((string) dcCore::app()->blog->settings->get('themes')->get('morecss_min'));
|
||||
if (!empty($css)) {
|
||||
echo dcUtils::cssLoad(
|
||||
dcCore::app()->blog->url . dcCore::app()->url->getURLFor(basename(__DIR__)),
|
||||
dcCore::app()->blog->url . dcCore::app()->url->getURLFor(My::id()),
|
||||
'screen',
|
||||
md5($css) //no cache on content change
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,18 +10,31 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return null;
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\moreCSS;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use Exception;
|
||||
|
||||
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 {
|
||||
if (!dcCore::app()->newVersion(
|
||||
basename(__DIR__),
|
||||
dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version')
|
||||
)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$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', '', 'string', 'Additionnal CSS for the active theme', false, true);
|
||||
|
@ -32,4 +45,6 @@ try {
|
|||
dcCore::app()->error->add($e->getMessage());
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,13 +10,35 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return null;
|
||||
declare(strict_types=1);
|
||||
|
||||
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,
|
||||
]), dcCore::app()->blog->id);
|
||||
|
||||
return static::$init;
|
||||
}
|
||||
|
||||
dcPage::check(dcCore::app()->auth->makePermissions([
|
||||
dcAuth::PERMISSION_CONTENT_ADMIN,
|
||||
]));
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$s = dcCore::app()->blog->settings->get('themes');
|
||||
|
||||
|
@ -36,31 +58,44 @@ if (isset($_POST['morecss'])) {
|
|||
$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.')
|
||||
);
|
||||
dcCore::app()->adminurl->redirect(
|
||||
'admin.plugin.' . basename(__DIR__)
|
||||
'admin.plugin.' . My::id()
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
dcCore::app()->error->add($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
echo '
|
||||
<html><head><title>' . __('Style sheet') . '</title>';
|
||||
if (dcCore::app()->auth->user_prefs->interface->colorsyntax) {
|
||||
echo
|
||||
dcPage::jsJson('dotclear_colorsyntax', ['colorsyntax' => dcCore::app()->auth->user_prefs->interface->colorsyntax]) .
|
||||
dcPage::jsLoadCodeMirror(dcCore::app()->auth->user_prefs->interface->colorsyntax_theme);
|
||||
return true;
|
||||
}
|
||||
echo '
|
||||
</head><body>' .
|
||||
|
||||
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
|
||||
dcPage::breadcrumb([
|
||||
html::escapeHTML(dcCore::app()->blog->name) => '',
|
||||
__('Style sheet') => '',
|
||||
My::name() => '',
|
||||
]) .
|
||||
dcPage::notices() . '
|
||||
|
||||
|
@ -83,13 +118,13 @@ dcCore::app()->formNonce() . '
|
|||
<input type="submit" name="write" value="' . __('Save') . ' (s)" accesskey="s" /></p>
|
||||
</form>';
|
||||
|
||||
if (dcCore::app()->auth->user_prefs->interface->colorsyntax) {
|
||||
if (dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax')) {
|
||||
echo
|
||||
dcPage::jsJson('theme_editor_mode', ['mode' => 'css']) .
|
||||
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 '
|
||||
</body>
|
||||
</html>';
|
||||
dcPage::closeModule();
|
||||
}
|
||||
}
|
||||
|
|
39
src/My.php
Normal file
39
src/My.php
Normal 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'));
|
||||
}
|
||||
}
|
|
@ -10,15 +10,33 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\moreCSS;
|
||||
|
||||
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(
|
||||
basename(__DIR__),
|
||||
My::id(),
|
||||
'morecss.css',
|
||||
'^morecss\.css(.*?)$',
|
||||
function ($args) {
|
||||
function (string $args): void {
|
||||
header('Content-Type: text/css; charset=UTF-8');
|
||||
|
||||
echo "/* CSS for plugin moreCss */ \n";
|
||||
|
@ -27,3 +45,7 @@ dcCore::app()->url->register(
|
|||
exit;
|
||||
}
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue