fix nullsafe warnings
parent
21b200af81
commit
ad15681e09
|
@ -14,7 +14,6 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\myUrlHandlers;
|
namespace Dotclear\Plugin\myUrlHandlers;
|
||||||
|
|
||||||
use dcAuth;
|
|
||||||
use dcAdmin;
|
use dcAdmin;
|
||||||
use dcCore;
|
use dcCore;
|
||||||
use dcFavorites;
|
use dcFavorites;
|
||||||
|
@ -32,25 +31,30 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add backend sidebar menu icon
|
||||||
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
|
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
|
||||||
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(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 {
|
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]),
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -22,14 +22,15 @@ class Install extends dcNsProcess
|
||||||
{
|
{
|
||||||
public static function init(): bool
|
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;
|
return static::$init;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,14 +59,14 @@ class Install extends dcNsProcess
|
||||||
);
|
);
|
||||||
|
|
||||||
while ($record->fetch()) {
|
while ($record->fetch()) {
|
||||||
$value = @unserialize($record->f('setting_value'));
|
$value = @unserialize($record->f('setting_value'));
|
||||||
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
|
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
|
||||||
$cur->setting_id = My::NS_SETTING_ID;
|
$cur->setField('setting_id', My::NS_SETTING_ID);
|
||||||
$cur->setting_ns = My::id();
|
$cur->setField('setting_ns', My::id());
|
||||||
$cur->setting_value = json_encode(is_array($value) ? $value : []);
|
$cur->setField('setting_value', json_encode(is_array($value) ? $value : []));
|
||||||
$cur->update(
|
$cur->update(
|
||||||
"WHERE setting_id = '" . $record->f('setting_id') . "' and setting_ns = '" . $record->f('setting_ns') . "' " .
|
"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')) . "' "))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\myUrlHandlers;
|
namespace Dotclear\Plugin\myUrlHandlers;
|
||||||
|
|
||||||
use dcAuth;
|
|
||||||
use dcCore;
|
use dcCore;
|
||||||
use dcNsProcess;
|
use dcNsProcess;
|
||||||
use dcPage;
|
use dcPage;
|
||||||
|
@ -31,19 +30,17 @@ 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')
|
||||||
&& dcCore::app()->auth->check(
|
&& !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog)
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function process(): bool
|
public static function process(): bool
|
||||||
{
|
{
|
||||||
if (!static::$init) {
|
if (!static::$init || is_null(dcCore::app()->adminurl)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +114,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()->blog)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,18 @@ use dcCore;
|
||||||
|
|
||||||
class MyUrlHandlers
|
class MyUrlHandlers
|
||||||
{
|
{
|
||||||
private static $defaults = [];
|
/** @var array $defaults The default URLs handlers */
|
||||||
private static $url2post = [];
|
private static array $defaults = [];
|
||||||
private static $post_adm_url = [];
|
|
||||||
|
|
||||||
|
/** @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
|
public static function init(): void
|
||||||
{
|
{
|
||||||
# Set defaults
|
# 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
|
public static function overrideHandler(string $name, string $url): void
|
||||||
{
|
{
|
||||||
if (!isset(self::$defaults[$name])) {
|
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
|
public static function getDefaults(): array
|
||||||
{
|
{
|
||||||
$res = [];
|
$res = [];
|
||||||
|
@ -80,15 +99,31 @@ class MyUrlHandlers
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get custom blog URLs handlers.
|
||||||
|
*
|
||||||
|
* @return array The blog URLs handlers
|
||||||
|
*/
|
||||||
public static function getBlogHandlers(): array
|
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);
|
$handlers = json_decode((string) dcCore::app()->blog->settings->get(My::id())->get(My::NS_SETTING_ID), true);
|
||||||
|
|
||||||
return is_array($handlers) ? $handlers : [];
|
return is_array($handlers) ? $handlers : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save custom URLs handlers
|
||||||
|
*
|
||||||
|
* @param array $handlers The custom URLs handlers
|
||||||
|
*/
|
||||||
public static function saveBlogHandlers(array $handlers): void
|
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->settings->get(My::id())->put(My::NS_SETTING_ID, json_encode($handlers));
|
||||||
dcCore::app()->blog->triggerBlog();
|
dcCore::app()->blog->triggerBlog();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue