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') . '

' . __('Back') . '

'; } 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

' . __('Back') . '

' . Html::escapeHTML(self::$action->description()) . '

' . - (new Form('form-actions'))->method('post')->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()))->fields([ + (new Form('form-actions'))->method('post')->action(dcCore::app()->adminurl?->get('admin.plugin.' . My::id()))->fields([ empty($res) ? (new Text('p', __('Nothing to configure')))->class('message') : (new Text('', $res)), (new Para())->class('clear')->items([ (new Submit(['save']))->value(__('Save')), @@ -265,7 +268,7 @@ class Manage extends dcNsProcess private static function displayActions(): void { echo - (new Form('improve_menu'))->method('get')->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()))->fields([ + (new Form('improve_menu'))->method('get')->action(dcCore::app()->adminurl?->get('admin.plugin.' . My::id()))->fields([ (new Para())->class('anchor-nav')->items([ (new Label(__('Goto:'), Label::OUTSIDE_LABEL_BEFORE))->for('type')->class('classic'), (new Select('type'))->default(self::$type)->items([__('Plugins') => 'plugin', __('Themes') => 'theme']), @@ -278,7 +281,7 @@ class Manage extends dcNsProcess if (count($combo_modules) == 1) { echo '

' . __('No module to manage') . '

'; } else { - echo '
' . + echo '' . '' . '' . '' . (DC_DEBUG ? '' : '') . /* @phpstan-ignore-line */ @@ -327,7 +330,7 @@ class Manage extends dcNsProcess '
'; - if (!empty($_REQUEST['upd']) && !dcCore::app()->blog->settings->get(My::id())->get('nodetails')) { + if (!empty($_REQUEST['upd']) && !dcCore::app()->blog?->settings->get(My::id())->get('nodetails')) { $logs = self::$improve->parseLogs((int) $_REQUEST['upd']); if (!empty($logs)) { diff --git a/src/My.php b/src/My.php index b7b4780..be84901 100644 --- a/src/My.php +++ b/src/My.php @@ -22,7 +22,7 @@ use dcCore; class My { /** @var string Required php version */ - public const PHP_MIN = '8.0'; + public const PHP_MIN = '8.1'; /** * This module id diff --git a/src/module/cssheader.php b/src/module/cssheader.php index ae19627..61818b9 100644 --- a/src/module/cssheader.php +++ b/src/module/cssheader.php @@ -156,6 +156,12 @@ class cssheader extends Action public function openModule(): ?bool { + if (is_null(dcCore::app()->auth)) { + $this->setWarning(__('Auth is not set')); + + return null; + } + $bloc = trim($this->bloc_content); if (empty($bloc)) { diff --git a/src/module/dcstore.php b/src/module/dcstore.php index 0763596..a5482b8 100644 --- a/src/module/dcstore.php +++ b/src/module/dcstore.php @@ -109,31 +109,31 @@ class dcstore extends Action $rsp = new XmlTag('module'); # id - $rsp->id = $this->module->getId(); + $rsp->insertAttr('id', $this->module->getId()); # name if (empty($this->module->get('name'))) { $this->setError(__('unknow module name')); } - $rsp->name($this->module->get('name')); + $rsp->insertNode(new XmlTag('name', $this->module->get('name'))); # version if (empty($this->module->get('version'))) { $this->setError(__('unknow module version')); } - $rsp->version($this->module->get('version')); + $rsp->insertNode(new XmlTag('version', $this->module->get('version'))); # author if (empty($this->module->get('author'))) { $this->setError(__('unknow module author')); } - $rsp->author($this->module->get('author')); + $rsp->insertNode(new XmlTag('author', $this->module->get('author'))); # desc if (empty($this->module->get('desc'))) { $this->setError(__('unknow module description')); } - $rsp->desc($this->module->get('desc')); + $rsp->insertNode(new XmlTag('desc', $this->module->get('desc'))); # repository if (empty($this->module->get('repository'))) { @@ -145,7 +145,7 @@ class dcstore extends Action if (empty($file_pattern)) { $this->setError(__('no zip file pattern set in configuration')); } - $rsp->file($file_pattern); + $rsp->insertNode(new XmlTag('file', $file_pattern)); # da dc_min or requires core if (!empty($this->module->get('requires')) && is_array($this->module->get('requires'))) { diff --git a/src/module/phpcsfixer.php b/src/module/phpcsfixer.php index 6404bf7..b3abd8f 100644 --- a/src/module/phpcsfixer.php +++ b/src/module/phpcsfixer.php @@ -72,9 +72,11 @@ class phpcsfixer extends Action $this->getPhpPath(); - dcCore::app()->auth->user_prefs->addWorkspace('interface'); - self::$user_ui_colorsyntax = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax'); - self::$user_ui_colorsyntax_theme = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme'); + if (null !== dcCore::app()->auth?->user_prefs) { + dcCore::app()->auth->user_prefs->addWorkspace('interface'); + self::$user_ui_colorsyntax = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax'); + self::$user_ui_colorsyntax_theme = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme'); + } return true; } diff --git a/src/module/phpheader.php b/src/module/phpheader.php index f3f9d03..c850ca4 100644 --- a/src/module/phpheader.php +++ b/src/module/phpheader.php @@ -155,6 +155,12 @@ class phpheader extends Action public function openModule(): ?bool { + if (is_null(dcCore::app()->auth)) { + $this->setWarning(__('Auth is not set')); + + return null; + } + $bloc = trim($this->bloc_content); if (empty($bloc)) { diff --git a/src/module/phpstan.php b/src/module/phpstan.php index c24ab61..c5c8d7f 100644 --- a/src/module/phpstan.php +++ b/src/module/phpstan.php @@ -75,16 +75,18 @@ class phpstan extends Action $ignored_vars = $this->getSetting('ignored_vars'); $this->ignored_vars = is_string($ignored_vars) ? $ignored_vars : ''; - dcCore::app()->auth->user_prefs->addWorkspace('interface'); - self::$user_ui_colorsyntax = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax'); - self::$user_ui_colorsyntax_theme = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme'); + if (null !== dcCore::app()->auth?->user_prefs) { + dcCore::app()->auth->user_prefs->addWorkspace('interface'); + self::$user_ui_colorsyntax = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax'); + self::$user_ui_colorsyntax_theme = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme'); + } return true; } public function isConfigured(): bool { - return !dcCore::app()->blog->settings->get(My::id())->get('nodetails'); + return !dcCore::app()->blog?->settings->get(My::id())->get('nodetails'); } public function header(): ?string @@ -284,7 +286,7 @@ class phpstan extends Action '%MODULE_ROOT%', '%DC_ROOT%', '%BOOTSTRAP_ROOT%', - '%SCAN_DIRECTORIES%' + '%SCAN_DIRECTORIES%', ], [ $this->run_level, @@ -311,18 +313,19 @@ class phpstan extends Action return (bool) file_put_contents(DC_VAR . '/phpstan.neon', $content); } - private function getScanDirectories() + private function getScanDirectories(): string { $ret = ''; if ($this->module->get('type') == 'plugin') { $paths = explode(PATH_SEPARATOR, DC_PLUGINS_ROOT); - foreach($paths as $path) { + foreach ($paths as $path) { $path = Path::real($path, false); if ($path !== false && $path != Path::real(DC_ROOT . DIRECTORY_SEPARATOR . 'plugins', false)) { $ret .= ' - ' . $path . "\n"; } } } + return $ret; } } diff --git a/src/module/zip.php b/src/module/zip.php index 9056075..ba2dd9d 100644 --- a/src/module/zip.php +++ b/src/module/zip.php @@ -121,7 +121,7 @@ class zip extends Action ]), (new Note())->text(sprintf( __('Preconization: %s'), - dcCore::app()->blog->public_path ? + dcCore::app()->blog?->public_path ? Path::real(dcCore::app()->blog->public_path) : __("Blog's public directory") ))->class('form-note'), ]), diff --git a/src/module/zip/Zip.php b/src/module/zip/Zip.php index a281006..9e299be 100644 --- a/src/module/zip/Zip.php +++ b/src/module/zip/Zip.php @@ -26,6 +26,8 @@ class Zip extends \Dotclear\Helper\File\Zip\Zip * @param string $file The file * @param string $size The size * @param int|null $mtime The mtime + * + * @return void */ protected function writeFile($name, $file, $size, $mtime) {
' . __('Action') . '' . '' . __('Description') . '' . @@ -303,7 +306,7 @@ class Manage extends dcNsProcess '' . $action->description() . '' . ( false === $action->configurator() ? '' : - 'name()) . '">' . __('Configure') . '' ) . '' . $action->priority() . '