diff --git a/src/Backend.php b/src/Backend.php index 211bb93..24bf31f 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -14,7 +14,6 @@ declare(strict_types=1); namespace Dotclear\Plugin\httpPassword; -use dcAuth; use dcAdmin; use dcCore; use dcPage; @@ -31,10 +30,11 @@ 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()), diff --git a/src/Frontend.php b/src/Frontend.php index 9936da4..57d07ab 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -33,7 +33,12 @@ class Frontend extends dcNsProcess return false; } + // check password on frontend dcCore::app()->addBehavior('publicPrependV2', function (): void { + // nullsafe + if (is_null(dcCore::app()->blog)) { + return; + } $PHP_AUTH_USER = $PHP_AUTH_PW = ''; if (isset($_SERVER['PHP_AUTH_USER']) and isset($_SERVER['PHP_AUTH_PW'])) { diff --git a/src/Install.php b/src/Install.php index f8774f6..cd47085 100644 --- a/src/Install.php +++ b/src/Install.php @@ -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; } diff --git a/src/Manage.php b/src/Manage.php index 4e57fff..3186d54 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -40,18 +40,21 @@ class Manage extends dcNsProcess { public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->auth->check( - dcCore::app()->auth->makePermissions([ - My::PERMISSION, - ]), dcCore::app()->blog->id - ); + static::$init = defined('DC_CONTEXT_ADMIN') + && !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog) // nullsafe + && dcCore::app()->auth->check( + dcCore::app()->auth->makePermissions([ + My::PERMISSION, + ]), + dcCore::app()->blog->id + ); return static::$init; } public static function process(): bool { - if (!static::$init) { + if (!static::$init || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { return false; } @@ -67,6 +70,7 @@ class Manage extends dcNsProcess return true; } + // save settings if ('savesettings' == $action) { $s = dcCore::app()->blog->settings->get(My::id()); $s->put('active', !empty($_POST['active'])); @@ -85,6 +89,7 @@ class Manage extends dcNsProcess ); } + // delete users logins if ('savelogins' == $action) { $logs = dcCore::app()->log->getLogs(['log_table' => My::id()]); if (!$logs->isEmpty()) { @@ -105,6 +110,7 @@ class Manage extends dcNsProcess } } + // save users logins / passwords in frontend passwords file if ('savepasswords' == $action) { $passwords = self::getPasswords(); $lines = []; @@ -153,7 +159,7 @@ class Manage extends dcNsProcess public static function render(): void { - if (!static::$init) { + if (!static::$init || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { return; } @@ -173,7 +179,7 @@ class Manage extends dcNsProcess ]) . dcPage::notices() . - # Filters select menu list + // Filters select menu list (new Form('section_menu'))->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()))->method('get')->fields([ (new Para())->class('anchor-nav')->items([ (new Label(__('Select section:')))->for('part')->class('classic'), @@ -185,6 +191,7 @@ class Manage extends dcNsProcess '