fix nullsafe warnings

This commit is contained in:
Jean-Christian Denis 2023-04-22 14:52:57 +02:00
parent eff0446740
commit c4e8ff1db9
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
5 changed files with 24 additions and 16 deletions

View file

@ -15,7 +15,6 @@ declare(strict_types=1);
namespace Dotclear\Plugin\moreCSS; namespace Dotclear\Plugin\moreCSS;
use dcAdmin; use dcAdmin;
use dcAuth;
use dcCore; use dcCore;
use dcFavorites; use dcFavorites;
use dcNsProcess; use dcNsProcess;
@ -32,7 +31,7 @@ class Backend extends dcNsProcess
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!static::$init || is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
return false; return false;
} }
@ -40,17 +39,20 @@ class Backend extends dcNsProcess
My::name(), My::name(),
dcCore::app()->adminurl->get('admin.plugin.' . My::id()), dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
[dcPage::getPF(My::id() . '/icon.png')], [dcPage::getPF(My::id() . '/icon.png')],
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']), preg_match('/' . preg_quote((string) 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([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]), dcCore::app()->blog->id)
); );
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void { dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {
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' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
'small-icon' => [dcPage::getPF(My::id() . '/icon.png')], 'small-icon' => [dcPage::getPF(My::id() . '/icon.png')],
'large-icon' => [dcPage::getPF(My::id() . '/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([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]),
]); ]);
}); });

View file

@ -29,11 +29,14 @@ class Frontend extends dcNsProcess
public static function process(): bool public static function process(): bool
{ {
if (!static::$init || !dcCore::app()->blog->settings->get('themes')->get('morecss_active')) { if (!static::$init || is_null(dcCore::app()->blog) || !dcCore::app()->blog->settings->get('themes')->get('morecss_active')) {
return false; return false;
} }
dcCore::app()->addBehavior('publicHeadContent', function (): void { dcCore::app()->addBehavior('publicHeadContent', function (): void {
if (is_null(dcCore::app()->blog)) {
return;
}
$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(

View file

@ -30,7 +30,7 @@ class Install extends dcNsProcess
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!static::$init || is_null(dcCore::app()->blog)) {
return false; return false;
} }

View file

@ -14,7 +14,6 @@ declare(strict_types=1);
namespace Dotclear\Plugin\moreCSS; namespace Dotclear\Plugin\moreCSS;
use dcAuth;
use dcCore; use dcCore;
use dcNsProcess; use dcNsProcess;
use dcPage; use dcPage;
@ -35,8 +34,9 @@ class Manage extends dcNsProcess
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') 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->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_CONTENT_ADMIN, dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id); ]), dcCore::app()->blog->id);
return static::$init; return static::$init;
@ -44,7 +44,7 @@ class Manage extends dcNsProcess
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!static::$init || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
return false; return false;
} }
@ -58,15 +58,15 @@ class Manage extends dcNsProcess
$s->put('morecss_active', !empty($_POST['morecss_active'])); $s->put('morecss_active', !empty($_POST['morecss_active']));
// Minify it // Minify it
$css_min = preg_replace('` {2,}`', ' ', $_POST['morecss']); $css_min = (string) preg_replace('` {2,}`', ' ', $_POST['morecss']);
$css_min = preg_replace('/(\/\*[\s\S]*?\*\/)/', '', $css_min); $css_min = (string) preg_replace('/(\/\*[\s\S]*?\*\/)/', '', $css_min);
$css_min = preg_replace('/(\t|\r|\n)/', '', $css_min); $css_min = (string) preg_replace('/(\t|\r|\n)/', '', $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); $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', is_string($css_min) ? base64_encode($css_min) : ''); $s->put('morecss_min', base64_encode($css_min));
dcPage::addSuccessNotice( dcPage::addSuccessNotice(
__('Configuration successfully updated.') __('Configuration successfully updated.')
@ -84,7 +84,7 @@ class Manage extends dcNsProcess
public static function render(): void public static function render(): void
{ {
if (!static::$init) { if (!static::$init || is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs) || is_null(dcCore::app()->blog)) {
return; return;
} }
@ -113,7 +113,7 @@ class Manage extends dcNsProcess
(new Textarea('morecss', Html::escapeHTML((string) base64_decode((string) $s->get('morecss')))))->class('maximal')->cols(72)->rows(25), (new Textarea('morecss', Html::escapeHTML((string) base64_decode((string) $s->get('morecss')))))->class('maximal')->cols(72)->rows(25),
]), ]),
(new Para())->items([ (new Para())->items([
(new Checkbox('morecss_active'))->value(1), (new Checkbox('morecss_active', (bool) $s->get('morecss_active')))->value(1),
(new Label(__('Enable additionnal CSS for the active theme'), Label::OUTSIDE_LABEL_AFTER))->for('morecss_active')->class('classic'), (new Label(__('Enable additionnal CSS for the active theme'), Label::OUTSIDE_LABEL_AFTER))->for('morecss_active')->class('classic'),
]), ]),
(new Para())->items([ (new Para())->items([

View file

@ -37,6 +37,9 @@ class Prepend extends dcNsProcess
'morecss.css', 'morecss.css',
'^morecss\.css(.*?)$', '^morecss\.css(.*?)$',
function (string $args): void { function (string $args): void {
if (is_null(dcCore::app()->blog)) {
return;
}
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";