diff --git a/src/Action.php b/src/Action.php index 5780b94..a6ed7ac 100644 --- a/src/Action.php +++ b/src/Action.php @@ -82,7 +82,7 @@ abstract class Action $this->class_name = str_replace(__NAMESPACE__ . '\\Module\\', '', get_called_class()); $this->module = new dcModuleDefine('undefined'); - $settings = dcCore::app()->blog->settings->get(My::id())->get('settings_' . $this->class_name); + $settings = dcCore::app()->blog?->settings->get(My::id())->get('settings_' . $this->class_name); if (null != $settings) { $settings = json_decode($settings, true); } @@ -91,7 +91,7 @@ abstract class Action $this->init(); // can overload priority by settings - if (1 < ($p = (int) dcCore::app()->blog->settings->get(My::id())->get('priority_' . $this->class_name))) { + if (1 < ($p = (int) dcCore::app()->blog?->settings->get(My::id())->get('priority_' . $this->class_name))) { $this->priority = $p; } } @@ -232,16 +232,18 @@ abstract class Action */ final protected function redirect(string $url): bool { - dcCore::app()->blog->settings->get(My::id())->put( - 'settings_' . $this->class_name, - json_encode($this->settings), - 'string', - null, - true, - true - ); - dcCore::app()->blog->triggerBlog(); - dcPage::addSuccessNotice(__('Configuration successfully updated')); + if (!is_null(dcCore::app()->blog)) { + dcCore::app()->blog->settings->get(My::id())->put( + 'settings_' . $this->class_name, + json_encode($this->settings), + 'string', + null, + true, + true + ); + dcCore::app()->blog->triggerBlog(); + dcPage::addSuccessNotice(__('Configuration successfully updated')); + } Http::redirect($url); return true; diff --git a/src/Backend.php b/src/Backend.php index c60f309..c85b8e2 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -31,6 +31,7 @@ class Backend extends dcNsProcess public static function init(): bool { static::$init = defined('DC_CONTEXT_ADMIN') + && !is_null(dcCore::app()->auth) && dcCore::app()->auth->isSuperAdmin() && My::phpCompliant(); @@ -43,18 +44,9 @@ class Backend extends dcNsProcess return false; } - 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.svg'), - 'large-icon' => dcPage::getPF(My::id() . '/icon.svg'), - //'permissions' => null, - ] - ); - }); + if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { + return false; + } dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( My::name(), @@ -64,6 +56,19 @@ class Backend extends dcNsProcess dcCore::app()->auth->isSuperAdmin() ); + 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.svg'), + 'large-icon' => dcPage::getPF(My::id() . '/icon.svg'), + //'permissions' => null, + ] + ); + }); + $dir = __DIR__ . DIRECTORY_SEPARATOR . 'module' . DIRECTORY_SEPARATOR; $ns = __NAMESPACE__ . '\\Module\\'; diff --git a/src/Config.php b/src/Config.php index b0b3999..becdf42 100644 --- a/src/Config.php +++ b/src/Config.php @@ -39,6 +39,7 @@ class Config extends dcNsProcess public static function init(): bool { static::$init = defined('DC_CONTEXT_ADMIN') + && !is_null(dcCore::app()->auth) && dcCore::app()->auth->isSuperAdmin() && My::phpCompliant(); @@ -55,6 +56,10 @@ class Config extends dcNsProcess return true; } + if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { + return false; + } + try { $pdisabled = ''; if (!empty($_POST['disabled']) && is_array($_POST['disabled'])) { @@ -84,8 +89,13 @@ class Config extends dcNsProcess return; } - $improve = new Core(); - $modules = $items = []; + if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { + return; + } + + $improve = new Core(); + $modules = $items = []; + $settings = dcCore::app()->blog->settings->get(My::id()); foreach ($improve->modules() as $action) { $modules[$action->name()] = $action->id(); @@ -103,16 +113,16 @@ class Config extends dcNsProcess (new Fieldset())->class('fieldset')->legend(new Legend(__('List of disabled actions')))->fields($items), (new Fieldset())->class('fieldset')->legend(new Legend(__('Options')))->fields([ (new Para())->items([ - (new Checkbox('nodetails', (bool) dcCore::app()->blog->settings->get(My::id())->get('nodetails')))->value('1'), + (new Checkbox('nodetails', (bool) $settings->get('nodetails')))->value('1'), (new Label(__('Hide details of rendered actions'), Label::OUTSIDE_LABEL_AFTER))->class('classic')->for('nodetails'), ]), (new Para())->items([ - (new Checkbox('allow_distrib', (bool) dcCore::app()->blog->settings->get(My::id())->get('allow_distrib')))->value('1'), + (new Checkbox('allow_distrib', (bool) $settings->get('allow_distrib')))->value('1'), (new Label(__('Show dotclear distributed modules'), Label::OUTSIDE_LABEL_AFTER))->class('classic')->for('allow_distrib'), ]), (new Para())->items([ (new Label(__('Sort modules seletion by:'), Label::OUTSIDE_LABEL_BEFORE))->for('combosortby'), - (new Select('combosortby'))->items([__('Name') => 'name', __('Id') => 'id'])->default(dcCore::app()->blog->settings->get(My::id())->get('combosortby')), + (new Select('combosortby'))->items([__('Name') => 'name', __('Id') => 'id'])->default($settings->get('combosortby')), ]), ]), ])->render(); diff --git a/src/Core.php b/src/Core.php index 3831a19..bcf2678 100644 --- a/src/Core.php +++ b/src/Core.php @@ -51,7 +51,7 @@ class Core */ public function __construct() { - $disabled = explode(';', (string) dcCore::app()->blog->settings->get(My::id())->get('disabled')); + $disabled = explode(';', (string) dcCore::app()->blog?->settings->get(My::id())->get('disabled')); $list = new ArrayObject(); try { @@ -307,11 +307,6 @@ class Core return $res; } - public function getURL(array $params = []): string - { - return dcCore::app()->adminurl->get('admin.plugin.' . My::id(), $params, '&'); - } - /** * Check and clean file extension * diff --git a/src/Install.php b/src/Install.php index 2ac5887..7d07d9c 100644 --- a/src/Install.php +++ b/src/Install.php @@ -66,7 +66,7 @@ class Install extends dcNsProcess private static function putSettings(): void { foreach (self::$default_settings as $v) { - dcCore::app()->blog->settings->get(My::id())->put( + dcCore::app()->blog?->settings->get(My::id())->put( $v[0], $v[2], $v[3], @@ -80,7 +80,7 @@ class Install extends dcNsProcess /** Update improve < 0.8 : action modules settings name */ private static function update_0_8_0(): void { - if (version_compare(dcCore::app()->getVersion(My::id()) ?? '0', '0.8', '<')) { + if (!is_null(dcCore::app()->blog) && version_compare(dcCore::app()->getVersion(My::id()) ?? '0', '0.8', '<')) { foreach (dcCore::app()->blog->settings->get(My::id())->dumpGlobalSettings() as $id => $values) { $newId = str_replace('ImproveAction', '', $id); if ($id != $newId) { diff --git a/src/Manage.php b/src/Manage.php index d335e41..18254b1 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -51,11 +51,10 @@ class Manage extends dcNsProcess /** @var Action|null $action Current action module */ private static $action = null; - protected static $init = false; - public static function init(): bool { static::$init = defined('DC_CONTEXT_ADMIN') + && !is_null(dcCore::app()->auth) && dcCore::app()->auth->isSuperAdmin() && My::phpCompliant(); @@ -86,7 +85,7 @@ class Manage extends dcNsProcess { try { if (!empty(self::$type)) { - $preferences = dcCore::app()->blog->settings->get(My::id())->get('preferences'); + $preferences = dcCore::app()->blog?->settings->get(My::id())->get('preferences'); if (is_string($preferences)) { $preferences = json_decode($preferences, true); if (is_array($preferences)) { @@ -102,7 +101,7 @@ class Manage extends dcNsProcess private static function setPreferences(): bool { - if (!empty($_POST['save_preferences'])) { + if (!empty($_POST['save_preferences']) && !is_null(dcCore::app()->blog)) { $preferences = self::getPreference(true); $preferences[self::$type] = []; if (!empty($_POST['actions'])) { @@ -123,6 +122,10 @@ class Manage extends dcNsProcess private static function comboModules(): array { + if (is_null(dcCore::app()->blog)) { + return []; + } + if (!(dcCore::app()->themes instanceof dcThemes)) { dcCore::app()->themes = new dcThemes(); dcCore::app()->themes->loadModules(dcCore::app()->blog->themes_path, null); @@ -175,7 +178,7 @@ class Manage extends dcNsProcess $_POST['actions'] ); $log_id = self::$improve->writeLogs(); - dcCore::app()->blog->triggerBlog(); + dcCore::app()->blog?->triggerBlog(); if (self::$improve->hasLog('error')) { $notice = ['type' => dcAdminNotices::NOTICE_ERROR, 'msg' => __('Fix of "%s" complete in %s secondes with errors')]; @@ -197,7 +200,7 @@ class Manage extends dcNsProcess } if ($done) { - dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['type' => self::$type, 'module' => self::$module, 'upd' => $log_id]); + dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id(), ['type' => self::$type, 'module' => self::$module, 'upd' => $log_id]); } return true; @@ -234,14 +237,14 @@ class Manage extends dcNsProcess private static function displayConfigurator(): void { - $back_url = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['type' => self::$type]); + $back_url = $_REQUEST['redir'] ?? dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), ['type' => self::$type]); if (null === self::$action) { echo '
' . __('Unknow module') . '
'; } else { - $redir = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['type' => self::$type, 'config' => self::$action->id()]); + $redir = $_REQUEST['redir'] ?? dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), ['type' => self::$type, 'config' => self::$action->id()]); $res = self::$action->configure($redir); echo ' @@ -249,7 +252,7 @@ class Manage extends dcNsProcess