diff --git a/_define.php b/_define.php index 220fd4f..2cd2983 100644 --- a/_define.php +++ b/_define.php @@ -10,7 +10,7 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -if (!defined('DC_RC_PATH')) { +if (!defined('DC_RC_PATH') || is_null(dcCore::app()->auth)) { return null; } @@ -22,7 +22,7 @@ $this->registerModule( [ 'requires' => [['core', '2.25']], 'permissions' => dcCore::app()->auth->makePermissions([ - dcAuth::PERMISSION_CONTENT_ADMIN, + dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, ]), 'type' => 'plugin', 'support' => 'http://forum.dotclear.org/viewtopic.php?pid=333002#p333002', diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index d2b4074..235e587 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -114,6 +114,11 @@ class BackendBehaviors public static function adminAfterDashboardOptionsUpdate(?string $user_id): void { + // nullsafe + if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs)) { + return; + } + dcCore::app()->auth->user_prefs->get('dashboard')->put( 'topWriterPostsItems', !empty($_POST['topWriterPostsItems']), @@ -149,6 +154,11 @@ class BackendBehaviors private static function setDefaultPref(): array { + // nullsafe + if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->auth->user_prefs)) { + return []; + } + if (!dcCore::app()->auth->user_prefs->get('dashboard')->prefExists('topWriterPostsItems')) { dcCore::app()->auth->user_prefs->get('dashboard')->put( 'topWriterPostsItems', diff --git a/src/Utils.php b/src/Utils.php index 23aa669..e94514a 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -24,6 +24,11 @@ class Utils { public static function posts(string $period, int $limit, bool $sort_desc = true): array { + // nullsafe + if (is_null(dcCore::app()->blog)) { + return []; + } + $req = 'SELECT COUNT(*) AS count, U.user_id ' . 'FROM ' . dcCore::app()->prefix . dcBlog::POST_TABLE_NAME . ' P ' . 'INNER JOIN ' . dcCore::app()->prefix . dcAuth::USER_TABLE_NAME . ' U ON U.user_id = P.user_id ' . @@ -82,6 +87,11 @@ class Utils public static function comments(string $period, int $limit, bool $sort_desc = true, bool $exclude = false): array { + // nullsafe + if (is_null(dcCore::app()->blog)) { + return []; + } + $req = 'SELECT COUNT(*) AS count, comment_email ' . 'FROM ' . dcCore::app()->prefix . dcBlog::POST_TABLE_NAME . ' P, ' . dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME . ' C ' . 'WHERE P.post_id=C.post_id ' .