From 7ebc446999286d42affc5d27ea888dd997a3d95c Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Tue, 29 Aug 2023 15:29:26 +0000 Subject: [PATCH] prevent php8 warnings, fixes #3106 Closes #3106 Merge request studip/studip!2095 --- app/controllers/course/contentmodules.php | 8 ++++---- app/controllers/course/elearning.php | 5 ++++- app/controllers/course/wizard.php | 2 +- app/controllers/new_password.php | 1 + app/controllers/resources/room_request.php | 2 +- app/views/course/contentmodules/info.php | 4 ++-- .../coursewizardsteps/BasicDataWizardStep.php | 6 +++--- lib/elearning/ELearningUtils.class.php | 14 +++++++++----- lib/filesystem/PublicFolder.php | 2 +- lib/models/Course.class.php | 6 ++++-- lib/models/OERMaterial.php | 6 ++++-- lib/models/SimpleCollection.class.php | 2 +- lib/plugins/core/CorePlugin.php | 4 ++-- lib/plugins/core/StudIPPlugin.class.php | 4 ++-- lib/plugins/engine/PluginManager.class.php | 6 +++--- lib/visual.inc.php | 13 ++++++------- 16 files changed, 48 insertions(+), 37 deletions(-) diff --git a/app/controllers/course/contentmodules.php b/app/controllers/course/contentmodules.php index 06d46deab4c..04eb8464dde 100644 --- a/app/controllers/course/contentmodules.php +++ b/app/controllers/course/contentmodules.php @@ -298,22 +298,22 @@ class Course_ContentmodulesController extends AuthenticatedController 'visibility' => $visibility, 'active' => (bool) $tool, ]; - if ($metadata['icon_clickable']) { + if (!empty($metadata['icon_clickable'])) { $list[$plugin_id]['icon'] = $metadata['icon_clickable'] instanceof Icon ? $metadata['icon_clickable']->asImagePath() : Icon::create($plugin->getPluginURL().'/'.$metadata['icon_clickable'])->asImagePath(); - } elseif ($metadata['icon']) { + } elseif (!empty($metadata['icon'])) { $list[$plugin_id]['icon'] = $metadata['icon'] instanceof Icon ? $metadata['icon']->asImagePath() : Icon::create($plugin->getPluginURL().'/'.$metadata['icon'])->asImagePath(); } else { $list[$plugin_id]['icon'] = null; } - $list[$plugin_id]['summary'] = $metadata['summary']; + $list[$plugin_id]['summary'] = $metadata['summary'] ?? null; $list[$plugin_id]['mandatory'] = $this->sem_class->isModuleMandatory(get_class($plugin)); $list[$plugin_id]['highlighted'] = (bool) $plugin->isHighlighted(); $list[$plugin_id]['highlight_text'] = $plugin->getHighlightText(); - $list[$plugin_id]['category'] = $metadata['category']; + $list[$plugin_id]['category'] = $metadata['category'] ?? null; } return $list; diff --git a/app/controllers/course/elearning.php b/app/controllers/course/elearning.php index a8a7626bed8..6e67b64a653 100644 --- a/app/controllers/course/elearning.php +++ b/app/controllers/course/elearning.php @@ -57,7 +57,10 @@ class Course_ElearningController extends AuthenticatedController if (!isset($GLOBALS['ELEARNING_INTERFACE_MODULES'][$this->cms_select])) { unset($this->cms_select); } - if ($this->seminar_id != $_SESSION['elearning_open_close']["id"]) { + if ( + isset($_SESSION['elearning_open_close']['id']) + && $this->seminar_id !== $_SESSION['elearning_open_close']['id'] + ) { unset($_SESSION['cache_data']); unset($_SESSION['elearning_open_close']); } diff --git a/app/controllers/course/wizard.php b/app/controllers/course/wizard.php index 009e0520892..636d6eb4fe5 100644 --- a/app/controllers/course/wizard.php +++ b/app/controllers/course/wizard.php @@ -118,7 +118,7 @@ class Course_WizardController extends AuthenticatedController $values[$iterator->key()] = $iterator->current(); $iterator->next(); } - if ($this->steps[$step_number]['classname']) { + if (!empty($this->steps[$step_number]['classname'])) { $this->setStepValues($this->steps[$step_number]['classname'], $values); } // Back or forward button clicked -> set next step accordingly. diff --git a/app/controllers/new_password.php b/app/controllers/new_password.php index 5132c4804f2..525d73b6623 100644 --- a/app/controllers/new_password.php +++ b/app/controllers/new_password.php @@ -111,6 +111,7 @@ class NewPasswordController extends StudipController $password = Request::get('new_password'); $confirm = Request::get('new_password_confirm'); + $errors = []; if (!$validator->ValidatePassword($password)) { $errors[] = _('Das Passwort ist zu kurz. Es sollte mindestens 8 Zeichen lang sein.'); } else if ($password !== $confirm) { diff --git a/app/controllers/resources/room_request.php b/app/controllers/resources/room_request.php index f128f23bae3..db892e09d2e 100644 --- a/app/controllers/resources/room_request.php +++ b/app/controllers/resources/room_request.php @@ -1997,7 +1997,7 @@ class Resources_RoomRequestController extends AuthenticatedController if ($save_only) { // redirect to reload all infos and showing the most current ones $this->redirect('resources/room_request/resolve/' . $request_id); - } elseif (Request::isDialog()) { + } elseif (Request::isDialog() && Context::get()) { $this->response->add_header('X-Dialog-Execute', '{"func": "STUDIP.AdminCourses.App.loadCourse", "payload": "'.Context::get()->id.'"}'); } } diff --git a/app/views/course/contentmodules/info.php b/app/views/course/contentmodules/info.php index 18d7ccf7363..11bf9dc581a 100644 --- a/app/views/course/contentmodules/info.php +++ b/app/views/course/contentmodules/info.php @@ -29,8 +29,8 @@ </div> </div> <div class="content-modules-controls-vue-app" is="ContentModulesControl" module_id="<?= htmlReady($plugin->getPluginId()) ?>"></div> - <? $keywords = preg_split( "/;/", $metadata['keywords'], -1, PREG_SPLIT_NO_EMPTY) ?> - <? if (count($keywords)) : ?> + <? $keywords = preg_split( "/;/", $metadata['keywords'] ?? '', -1, PREG_SPLIT_NO_EMPTY) ?> + <? if (count($keywords) > 0) : ?> <ul class="keywords"> <? foreach ($keywords as $keyword) : ?> <li> diff --git a/lib/classes/coursewizardsteps/BasicDataWizardStep.php b/lib/classes/coursewizardsteps/BasicDataWizardStep.php index ce3b57f0752..100786b0573 100644 --- a/lib/classes/coursewizardsteps/BasicDataWizardStep.php +++ b/lib/classes/coursewizardsteps/BasicDataWizardStep.php @@ -344,13 +344,13 @@ class BasicDataWizardStep implements CourseWizardStep if (!trim($values['name'])) { $errors[] = _('Bitte geben Sie den Namen der Veranstaltung an.'); } - if ($values['number'] != '') { + if (!empty($values['number'])) { $course_number_format = Config::get()->COURSE_NUMBER_FORMAT; if ($course_number_format && !preg_match('/^' . $course_number_format . '$/', $values['number'])) { $errors[] = _('Die Veranstaltungsnummer hat ein ungültiges Format.'); } } - if (!$values['lecturers']) { + if (empty($values['lecturers'])) { $errors[] = sprintf( _('Bitte tragen Sie mindestens eine Person als %s ein.'), htmlReady(get_title_for_status('dozent', 1, $values['coursetype'])) @@ -411,7 +411,7 @@ class BasicDataWizardStep implements CourseWizardStep $course->status = $values['coursetype']; $course->name = new I18NString($values['name'], $values['name_i18n'] ?? []); - $course->veranstaltungsnummer = $values['number']; + $course->veranstaltungsnummer = $values['number'] ?? null; $course->beschreibung = new I18NString($values['description'], $values['description_i18n'] ?? []); $course->start_semester = Semester::findByTimestamp($values['start_time']); $course->institut_id = $values['institute']; diff --git a/lib/elearning/ELearningUtils.class.php b/lib/elearning/ELearningUtils.class.php index 30c40c401a2..d027e372102 100644 --- a/lib/elearning/ELearningUtils.class.php +++ b/lib/elearning/ELearningUtils.class.php @@ -472,6 +472,7 @@ class ELearningUtils FROM object_contentmodules WHERE module_type = 'crs' AND object_id = " . $db->quote($sem_id)) ->fetchAll(PDO::FETCH_ASSOC); + $courses = []; foreach ($rs as $row) { $courses[$row['system_type']] = $row['module_id']; } @@ -479,23 +480,26 @@ class ELearningUtils $connected_courses = [ 'courses' => [], ]; - if (is_array($courses)) - foreach ($courses as $system_type => $crs_id) + if (is_array($courses)) { + foreach ($courses as $system_type => $crs_id) { if (self::isCMSActive($system_type)) { self::loadClass($system_type); $connected_courses['courses'][$system_type] = [ - 'url' => URLHelper::getLink($connected_cms[$system_type]->link->cms_link . '?client_id=' . $connected_cms[$system_type]->getClientId() . '&cms_select=' . $system_type . '&ref_id=' . $crs_id . '&type=crs&target=start'), - 'cms_name' => $connected_cms[$system_type]->getName()]; + 'url' => URLHelper::getLink($connected_cms[$system_type]->link->cms_link . '?client_id=' . $connected_cms[$system_type]->getClientId() . '&cms_select=' . $system_type . '&ref_id=' . $crs_id . '&type=crs&target=start'), + 'cms_name' => $connected_cms[$system_type]->getName() + ]; // gegebenenfalls zugeordnete Module aktualisieren if (Request::option('update')) { if ((method_exists($connected_cms[$system_type], "updateConnections"))) { - $connected_cms[$system_type]->updateConnections( $crs_id ); + $connected_cms[$system_type]->updateConnections($crs_id); } } if (method_exists($connected_cms[$system_type]->permissions, 'CheckUserPermissions')) { $connected_cms[$system_type]->permissions->CheckUserPermissions($crs_id); } } + } + } if ($connected_courses['courses']) { if (count($connected_courses['courses']) > 1) { diff --git a/lib/filesystem/PublicFolder.php b/lib/filesystem/PublicFolder.php index 15fdf34cd28..6b06ac905a4 100644 --- a/lib/filesystem/PublicFolder.php +++ b/lib/filesystem/PublicFolder.php @@ -60,7 +60,7 @@ class PublicFolder extends StandardFolder public function __get($attribute) { if ($attribute === 'viewable') { - return $this->folderdata['data_content']['viewable']; + return !empty($this->folderdata['data_content']['viewable']); } return $this->folderdata[$attribute]; } diff --git a/lib/models/Course.class.php b/lib/models/Course.class.php index e16df06e5f3..4c471ea64e4 100644 --- a/lib/models/Course.class.php +++ b/lib/models/Course.class.php @@ -341,7 +341,7 @@ class Course extends SimpleORMap implements Range, PrivacyObject, StudipItem, Fe { $end_semester = $this->semesters->last(); $start_semester = $this->semesters->first(); - if ($start_semester->id === $semester->id) { + if ($start_semester && $start_semester->id === $semester->id) { return; } if ($end_semester) { @@ -369,7 +369,9 @@ class Course extends SimpleORMap implements Range, PrivacyObject, StudipItem, Fe { $end_semester = $this->semesters->last(); $start_semester = $this->semesters->first(); - if ((is_null($end_semester) && is_null($semester)) || ($end_semester->id === $semester->id)) { + if ( + (is_null($end_semester) && is_null($semester)) + || ($end_semester && $semester && $end_semester->id === $semester->id)) { return; } if ($start_semester) { diff --git a/lib/models/OERMaterial.php b/lib/models/OERMaterial.php index ea36035d78e..f0e101d94df 100644 --- a/lib/models/OERMaterial.php +++ b/lib/models/OERMaterial.php @@ -390,8 +390,10 @@ class OERMaterial extends SimpleORMap } $url = $this->getDownloadUrl(); $headers = get_headers($url, true, get_default_http_stream_context($url)); - if ($headers['Content-Disposition'] - && substr($headers['Content-Disposition'], 0, strlen('attachment')) === 'attachment') { + if ( + !empty($headers['Content-Disposition']) + && substr($headers['Content-Disposition'], 0, strlen('attachment')) === 'attachment' + ) { //in this case the server forces to download the document and we cannot display it in an iframe: return false; } diff --git a/lib/models/SimpleCollection.class.php b/lib/models/SimpleCollection.class.php index 11dd2965301..42285998aad 100644 --- a/lib/models/SimpleCollection.class.php +++ b/lib/models/SimpleCollection.class.php @@ -592,7 +592,7 @@ class SimpleCollection extends StudipArrayObject public function val($key) { $first = $this->first(); - return $first[$key] ?: null; + return $first[$key] ?? null; } /** diff --git a/lib/plugins/core/CorePlugin.php b/lib/plugins/core/CorePlugin.php index 0bba2897b13..7f1aaed7c54 100644 --- a/lib/plugins/core/CorePlugin.php +++ b/lib/plugins/core/CorePlugin.php @@ -64,10 +64,10 @@ abstract class CorePlugin { $metadata = $this->getMetadata(); $language = getUserLanguage(User::findCurrent()->id); - if ($metadata['descriptionlong_' . $language]) { + if (!empty($metadata['descriptionlong_' . $language])) { return $metadata['descriptionlong_' . $language]; } - if ($metadata['description_' . $language]) { + if (!empty($metadata['description_' . $language])) { return $metadata['description_' . $language]; } $description = $metadata['descriptionlong'] ?? $metadata['description']; diff --git a/lib/plugins/core/StudIPPlugin.class.php b/lib/plugins/core/StudIPPlugin.class.php index a3dacb6b8b0..be2c776b2ae 100644 --- a/lib/plugins/core/StudIPPlugin.class.php +++ b/lib/plugins/core/StudIPPlugin.class.php @@ -89,10 +89,10 @@ abstract class StudIPPlugin { $metadata = $this->getMetadata(); $language = getUserLanguage(User::findCurrent()->id); - if ($metadata['descriptionlong_' . $language]) { + if (!empty($metadata['descriptionlong_' . $language])) { return $metadata['descriptionlong_' . $language]; } - if ($metadata['description_' . $language]) { + if (!empty($metadata['description_' . $language])) { return $metadata['description_' . $language]; } $description = $metadata['descriptionlong'] ?? $metadata['description']; diff --git a/lib/plugins/engine/PluginManager.class.php b/lib/plugins/engine/PluginManager.class.php index 7fb69bc8e3f..39f4e870c4e 100644 --- a/lib/plugins/engine/PluginManager.class.php +++ b/lib/plugins/engine/PluginManager.class.php @@ -87,9 +87,9 @@ class PluginManager 'automatic_update_url' => $plugin['automatic_update_url'], 'automatic_update_secret' => $plugin['automatic_update_secret'], 'description' => $plugin['description'], - 'description_mode' => $plugin['description_mode'], - 'highlight_until' => $plugin['highlight_until'], - 'highlight_text' => $plugin['highlight_text'] + 'description_mode' => $plugin['description_mode'] ?? null, + 'highlight_until' => $plugin['highlight_until'] ?? null, + 'highlight_text' => $plugin['highlight_text'] ?? null, ]; } } diff --git a/lib/visual.inc.php b/lib/visual.inc.php index 8503a5c7f79..2b37a64a17b 100644 --- a/lib/visual.inc.php +++ b/lib/visual.inc.php @@ -399,14 +399,13 @@ function symbol ($text = '') function mila ($titel, $size = 60) { global $auth; - if ($auth->auth["jscript"] AND $size == 60) { + if (!empty($auth->auth['jscript']) && $size == 60) { //hier wird die maximale Laenge berechnet, nach der Abgeschnitten wird (JS dynamisch) - if (mb_strlen ($titel) >$auth->auth["xres"] / 13) - $titel=mb_substr($titel, 0, $auth->auth["xres"] / 13)."... "; - } - else { - if (mb_strlen ($titel) >$size) - $titel=mb_substr($titel, 0, $size)."... "; + if (mb_strlen($titel) > $auth->auth['xres'] / 13) { + $titel = mb_substr($titel, 0, $auth->auth['xres'] / 13) . '... '; + } + } elseif (mb_strlen ($titel) >$size) { + $titel = mb_substr($titel, 0, $size) . '... '; } return $titel; } -- GitLab