fix nullsafe warnings

This commit is contained in:
Jean-Christian Paul Denis 2023-04-22 15:25:25 +02:00
parent 21b200af81
commit ad15681e09
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
4 changed files with 61 additions and 24 deletions

View File

@ -14,7 +14,6 @@ declare(strict_types=1);
namespace Dotclear\Plugin\myUrlHandlers;
use dcAuth;
use dcAdmin;
use dcCore;
use dcFavorites;
@ -32,25 +31,30 @@ class Backend extends dcNsProcess
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;
}
// add backend sidebar menu icon
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->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([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]), dcCore::app()->blog->id)
);
// register user backend dashboard icon
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->adminurl)) {
return;
}
$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]),
'permissions' => dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]),
]);
});

View File

@ -22,14 +22,15 @@ 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'));
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) {
if (!static::$init || is_null(dcCore::app()->blog)) {
return false;
}
@ -60,12 +61,12 @@ class Install extends dcNsProcess
while ($record->fetch()) {
$value = @unserialize($record->f('setting_value'));
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
$cur->setting_id = My::NS_SETTING_ID;
$cur->setting_ns = My::id();
$cur->setting_value = json_encode(is_array($value) ? $value : []);
$cur->setField('setting_id', My::NS_SETTING_ID);
$cur->setField('setting_ns', My::id());
$cur->setField('setting_value', json_encode(is_array($value) ? $value : []));
$cur->update(
"WHERE setting_id = '" . $record->f('setting_id') . "' and setting_ns = '" . $record->f('setting_ns') . "' " .
'AND blog_id ' . (null === $record->f('blog_id') ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->f('blog_id')) . "' "))
'AND blog_id ' . (null === $record->f('blog_id') ? 'IS NULL ' : ("= '" . dcCore::app()->con->escapeStr((string) $record->f('blog_id')) . "' "))
);
}
}

View File

@ -14,7 +14,6 @@ declare(strict_types=1);
namespace Dotclear\Plugin\myUrlHandlers;
use dcAuth;
use dcCore;
use dcNsProcess;
use dcPage;
@ -31,19 +30,17 @@ 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
);
&& !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog)
&& 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
{
if (!static::$init) {
if (!static::$init || is_null(dcCore::app()->adminurl)) {
return false;
}
@ -117,7 +114,7 @@ class Manage extends dcNsProcess
public static function render(): void
{
if (!static::$init) {
if (!static::$init || is_null(dcCore::app()->blog)) {
return;
}

View File

@ -18,10 +18,18 @@ use dcCore;
class MyUrlHandlers
{
private static $defaults = [];
private static $url2post = [];
private static $post_adm_url = [];
/** @var array $defaults The default URLs handlers */
private static array $defaults = [];
/** @var array $url2post The posts types URLs */
private static array $url2post = [];
/** @var array $post_adm_url The posts types admin URLs */
private static array $post_adm_url = [];
/**
* Initialize handlers list.
*/
public static function init(): void
{
# Set defaults
@ -50,6 +58,12 @@ class MyUrlHandlers
}
}
/**
* Override handler.
*
* @param string $name The handler name
* @param string $url The new url
*/
public static function overrideHandler(string $name, string $url): void
{
if (!isset(self::$defaults[$name])) {
@ -70,6 +84,11 @@ class MyUrlHandlers
}
}
/**
* Get default URLs handlers
*
* @return array The default URLs handlers
*/
public static function getDefaults(): array
{
$res = [];
@ -80,15 +99,31 @@ class MyUrlHandlers
return $res;
}
/**
* Get custom blog URLs handlers.
*
* @return array The blog URLs handlers
*/
public static function getBlogHandlers(): array
{
if (is_null(dcCore::app()->blog)) {
return [];
}
$handlers = json_decode((string) dcCore::app()->blog->settings->get(My::id())->get(My::NS_SETTING_ID), true);
return is_array($handlers) ? $handlers : [];
}
/**
* Save custom URLs handlers
*
* @param array $handlers The custom URLs handlers
*/
public static function saveBlogHandlers(array $handlers): void
{
if (is_null(dcCore::app()->blog)) {
return;
}
dcCore::app()->blog->settings->get(My::id())->put(My::NS_SETTING_ID, json_encode($handlers));
dcCore::app()->blog->triggerBlog();
}