From d349e0f27e8d5722460ff92a5ab81c39ae75aee9 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Fri, 31 Mar 2023 07:49:41 +0000 Subject: [PATCH] prevent php8 warnings, fixes #2496 Closes #2496 Merge request studip/studip!1682 --- .../librarysearch/LibraryDocument.class.php | 24 +++++++++---------- lib/filesystem/FileManager.php | 6 +++-- lib/models/User.class.php | 1 + lib/user_visible.inc.php | 7 +++++- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/classes/librarysearch/LibraryDocument.class.php b/lib/classes/librarysearch/LibraryDocument.class.php index 4a3d1f01dd4..4c90e0b4595 100644 --- a/lib/classes/librarysearch/LibraryDocument.class.php +++ b/lib/classes/librarysearch/LibraryDocument.class.php @@ -121,7 +121,7 @@ class LibraryDocument { if ($format == 'long') { $long_title = ''; - if ($this->csl_data['issued'] && $this->csl_data['author']) { + if (isset($this->csl_data['issued'], $this->csl_data['author'])) { $first_author_last_name = $this->csl_data['author'][0]['family']; $year = $this->getIssueDate(true); if ($year) { @@ -129,11 +129,11 @@ class LibraryDocument } else { $long_title = sprintf('%s - ', $first_author_last_name); } - } elseif ($this->csl_data['author']) { + } elseif (isset($this->csl_data['author'])) { $first_author_last_name = $this->csl_data['author'][0]['family']; $long_title = sprintf('%s - ', $first_author_last_name); } - $long_title .= $this->csl_data['title']; + $long_title .= $this->csl_data['title'] ?? ''; return $long_title; } elseif ($format == 'long-comma') { $data = []; @@ -142,13 +142,13 @@ class LibraryDocument if ($first_author_last_name) { $data[] = $first_author_last_name; } - $data[] = $this->csl_data['title']; + $data[] = $this->csl_data['title'] ?? ''; if ($year) { $data[] = $year; } return implode(', ', $data); } else { - return $this->csl_data['title'] ? $this->csl_data['title'] : ''; + return $this->csl_data['title'] ?? ''; } } @@ -158,7 +158,7 @@ class LibraryDocument */ public function getAuthorNames(): string { - if (!$this->csl_data['author']) { + if (empty($this->csl_data['author'])) { return ''; } @@ -411,22 +411,22 @@ class LibraryDocument public function getSearchDescription() { $description = []; - if ($this->search_params[LibrarySearch::AUTHOR]) { + if (isset($this->search_params[LibrarySearch::AUTHOR])) { $description[] = sprintf(_('Autor: „%s“'), $this->search_params[LibrarySearch::AUTHOR]); } - if ($this->search_params[LibrarySearch::YEAR]) { + if (isset($this->search_params[LibrarySearch::YEAR])) { $description[] = sprintf(_('Jahr: „%s“'), $this->search_params[LibrarySearch::YEAR]); } - if ($this->search_params[LibrarySearch::TITLE]) { + if (isset($this->search_params[LibrarySearch::TITLE])) { $description[] = sprintf(_('Titel: „%s“'), $this->search_params[LibrarySearch::TITLE]); } - if ($this->search_params[LibrarySearch::NUMBER]) { + if (isset($this->search_params[LibrarySearch::NUMBER])) { $description[] = sprintf(_('Nummer: „%s“'), $this->search_params[LibrarySearch::NUMBER]); } - if ($this->search_params[LibrarySearch::PUBLICATION]) { + if (isset($this->search_params[LibrarySearch::PUBLICATION])) { $description[] = sprintf(_('Zeitschrift: „%s“'), $this->search_params[LibrarySearch::PUBLICATION]); } - if ($this->search_params[LibrarySearch::SIGNATURE]) { + if (isset($this->search_params[LibrarySearch::SIGNATURE])) { $description[] = sprintf(_('Signatur: „%s“'), $this->search_params[LibrarySearch::SIGNATURE]); } return $description; diff --git a/lib/filesystem/FileManager.php b/lib/filesystem/FileManager.php index a958c61127d..bfa40424e32 100644 --- a/lib/filesystem/FileManager.php +++ b/lib/filesystem/FileManager.php @@ -111,9 +111,11 @@ class FileManager return 'file-generic'; } - list($category, $type) = explode('/', $mime_type, 2); + $chunks = explode('/', $mime_type, 2); + $category = $chunks[0]; + $type = $chunks[1] ?? null; - switch($category) { + switch ($category) { case 'image': return 'file-pic'; case 'audio': diff --git a/lib/models/User.class.php b/lib/models/User.class.php index 98abd45caef..8219fa7dafc 100644 --- a/lib/models/User.class.php +++ b/lib/models/User.class.php @@ -67,6 +67,7 @@ * @property UserInfo info has_one UserInfo * @property UserOnline online has_one UserOnline * @property Kategorie[]|SimpleORMapCollection $profile_categories has_many Kategorie + * @property UserDomain[]|SimpleORMapCollection $domains * * @property UserConfig config */ diff --git a/lib/user_visible.inc.php b/lib/user_visible.inc.php index 0706b325773..c6b56860cd6 100644 --- a/lib/user_visible.inc.php +++ b/lib/user_visible.inc.php @@ -82,8 +82,13 @@ function get_visibility_by_state ($state, $user_id) { return true; } + $other_user = User::find($user_id); + if (!$other_user) { + return false; + } + $same_domain = UserDomain::checkUserVisibility( - User::find($user_id)->domains, + $other_user->domains, User::findCurrent()->domains ); -- GitLab