From 1e5b66729afbb87337035f70fbd9beb6ed8b9f00 Mon Sep 17 00:00:00 2001 From: Michael Grace <56653532+michael-grace@users.noreply.github.com> Date: Thu, 30 May 2024 14:04:59 +0100 Subject: [PATCH] Fix Warnings and Errors for Deprecated Things in PHP8 --- src/Classes/MyRadio/MyRadioFormField.php | 7 +++++++ src/Classes/MyRadio/MyRadioMenu.php | 5 +++++ src/Classes/MyRadioTwig.php | 10 +++++----- src/Classes/ServiceAPI/MyRadio_ChartRelease.php | 2 +- src/Classes/ServiceAPI/MyRadio_Event.php | 4 ++-- src/Classes/ServiceAPI/MyRadio_Season.php | 2 +- src/Classes/ServiceAPI/MyRadio_Show.php | 12 +++--------- src/Classes/ServiceAPI/MyRadio_Timeslot.php | 2 +- src/Classes/ServiceAPI/MyRadio_User.php | 9 +++++++-- src/Classes/ServiceAPI/MyRadio_UserOfficership.php | 4 ++-- src/Controllers/Events/duplicateEvent.php | 4 ++-- 11 files changed, 36 insertions(+), 25 deletions(-) diff --git a/src/Classes/MyRadio/MyRadioFormField.php b/src/Classes/MyRadio/MyRadioFormField.php index e531ec1ab..0e6af68b2 100644 --- a/src/Classes/MyRadio/MyRadioFormField.php +++ b/src/Classes/MyRadio/MyRadioFormField.php @@ -331,6 +331,13 @@ class MyRadioFormField */ private $redacted = false; + /** + * Placeholder for the field + * + * @var mixed + */ + private $placeholder = null; + /** * Settings that cannot be altered by the $options parameter. * diff --git a/src/Classes/MyRadio/MyRadioMenu.php b/src/Classes/MyRadio/MyRadioMenu.php index 784beefce..49e3a779d 100644 --- a/src/Classes/MyRadio/MyRadioMenu.php +++ b/src/Classes/MyRadio/MyRadioMenu.php @@ -93,6 +93,11 @@ private function getFullMenu() */ private function getFullSubMenu($module) { + if ($module == "MyRadio") { + // bypass for the MyRadio module, which doesn't have header menus + return []; + } + $menu = json_decode(@file_get_contents('Menus/'.$module.'.json', FILE_USE_INCLUDE_PATH), true); if (is_null($menu)) { diff --git a/src/Classes/MyRadioTwig.php b/src/Classes/MyRadioTwig.php index 705332f9d..dc1fbf090 100644 --- a/src/Classes/MyRadioTwig.php +++ b/src/Classes/MyRadioTwig.php @@ -10,8 +10,8 @@ use MyRadio\MyRadioException; use MyRadio\MyRadioError; use Twig\TwigFunction; -use Twig_Loader_Filesystem; -use Twig_Environment; +use Twig\Loader\FilesystemLoader; +use Twig\Environment; use Twig_Extension_Debug; /** @@ -32,9 +32,9 @@ class MyRadioTwig implements \MyRadio\Iface\TemplateEngine */ public function __construct() { - $twig_loader = new Twig_Loader_Filesystem(__DIR__.'/../Templates/'); + $twig_loader = new FilesystemLoader(__DIR__.'/../Templates/'); $this->contextVariables['notices'] = []; - $this->twig = new Twig_Environment($twig_loader, ['auto_reload' => true]); + $this->twig = new Environment($twig_loader, ['auto_reload' => true]); if (Config::$template_debug) { $this->twig->addExtension(new Twig_Extension_Debug()); $this->twig->enableDebug(); @@ -175,7 +175,7 @@ public function setTemplate($template) //Validate template try { $this->twig->parse($this->twig->tokenize( - new \Twig_Source(file_get_contents(__DIR__.'/../Templates/'.$template), $template) + new \Twig\Source(file_get_contents(__DIR__.'/../Templates/'.$template), $template) )); // the $template is valid diff --git a/src/Classes/ServiceAPI/MyRadio_ChartRelease.php b/src/Classes/ServiceAPI/MyRadio_ChartRelease.php index 9f68ca685..1d6e2afd9 100644 --- a/src/Classes/ServiceAPI/MyRadio_ChartRelease.php +++ b/src/Classes/ServiceAPI/MyRadio_ChartRelease.php @@ -448,7 +448,7 @@ public function toDataSource($mixins = []) { return [ 'type' => $this->getChartType()->getDescription(), - 'date' => strftime('%c', $this->getReleaseTime()), + 'date' => date('d/m/Y', $this->getReleaseTime()), 'editlink' => [ 'display' => 'icon', 'value' => 'pencil', diff --git a/src/Classes/ServiceAPI/MyRadio_Event.php b/src/Classes/ServiceAPI/MyRadio_Event.php index cd80b32fb..7928079a3 100644 --- a/src/Classes/ServiceAPI/MyRadio_Event.php +++ b/src/Classes/ServiceAPI/MyRadio_Event.php @@ -364,8 +364,8 @@ public function getEditForm() [ 'title' => $this->getTitle(), 'description_html' => $this->getDescriptionHtml(), - 'start_time' => strftime('%d/%m/%Y %H:%M', $this->getStartTime()), - 'end_time' => strftime('%d/%m/%Y %H:%M', $this->getEndTime()) + 'start_time' => date('d/m/Y H:i', $this->getStartTime()), + 'end_time' => date('d/m/Y H:i', $this->getEndTime()) ] ); } diff --git a/src/Classes/ServiceAPI/MyRadio_Season.php b/src/Classes/ServiceAPI/MyRadio_Season.php index 2a8f43cb6..ff0cbe5a8 100644 --- a/src/Classes/ServiceAPI/MyRadio_Season.php +++ b/src/Classes/ServiceAPI/MyRadio_Season.php @@ -109,7 +109,7 @@ protected function __construct($season_id) //Deal with the easy bits $this->owner = MyRadio_User::getInstance($result['memberid']); $this->show_id = (int) $result['show_id']; - $this->submitted = strtotime($result['submitted']); + $this->submitted = $result['submitted'] !== null ? strtotime($result['submitted']) : null; $this->term_id = (int) $result['termid']; $this->season_num = (int) $result['season_num']; $this->subtype_id = (int) $result['subtype_id']; diff --git a/src/Classes/ServiceAPI/MyRadio_Show.php b/src/Classes/ServiceAPI/MyRadio_Show.php index 997bf0360..634abfd5d 100755 --- a/src/Classes/ServiceAPI/MyRadio_Show.php +++ b/src/Classes/ServiceAPI/MyRadio_Show.php @@ -146,14 +146,8 @@ protected function __construct($result) } //Deal with the Credits arrays - $credit_types = json_decode($result['credit_types']); - $credits = json_decode($result['credits']); - if ($credit_types === null) { - $credit_types = []; - } - if ($credits === null) { - $credits = []; - } + $credit_types = $result['credit_types'] !== null ? json_decode($result['credit_types']) : []; + $credits = $result['credits'] !== null ? json_decode($result['credits']) : []; for ($i = 0; $i < sizeof($credits); ++$i) { if (empty($credits[$i])) { @@ -190,8 +184,8 @@ protected function __construct($result) * @todo Support general photo attachment? */ $this->photo_url = Config::$default_person_uri; - $image_metadata = json_decode($result['image_metadata_values']); if ($result['image_metadata_values'] !== null) { + $image_metadata = json_decode($result['image_metadata_values']); $this->photo_url = Config::$public_media_uri.'/'.$image_metadata[0]; } diff --git a/src/Classes/ServiceAPI/MyRadio_Timeslot.php b/src/Classes/ServiceAPI/MyRadio_Timeslot.php index 52900e778..9319ab02f 100644 --- a/src/Classes/ServiceAPI/MyRadio_Timeslot.php +++ b/src/Classes/ServiceAPI/MyRadio_Timeslot.php @@ -1295,7 +1295,7 @@ function ($x) { 'user' => MyRadio_User::getInstance($x['memberid']), 'signedby' => $x['signerid'] ? MyRadio_User::getInstance($x['signerid']) : null, 'location' => $x['location_name'], - 'time' => strtotime($x['sign_time']) + 'time' => $x['sign_time'] !== null ? strtotime($x['sign_time']) : null ]; }, $result diff --git a/src/Classes/ServiceAPI/MyRadio_User.php b/src/Classes/ServiceAPI/MyRadio_User.php index 723c73a06..6c6702732 100755 --- a/src/Classes/ServiceAPI/MyRadio_User.php +++ b/src/Classes/ServiceAPI/MyRadio_User.php @@ -550,6 +550,10 @@ public function getPermissionsInfo() */ public function getEmail() { + if (empty($this->email)) { + return $this->getEduroam().'@'.Config::$eduroam_domain; + } + $domain = $domain = substr(strrchr($this->email, '@'), 1); if (in_array($domain, Config::$local_email_domains)) { //The user has set an alias or their local mailbox here. @@ -566,8 +570,6 @@ public function getEmail() return $eduroam.'@'.Config::$eduroam_domain; } } - } elseif (empty($this->email)) { - return $this->getEduroam().'@'.Config::$eduroam_domain; } else { return $this->email; } @@ -596,6 +598,9 @@ public function getPublicEmail() */ public function getEduroam() { + if ($this->eduroam == null) { + return ""; + } return str_replace('@'.Config::$eduroam_domain, '', $this->eduroam); } diff --git a/src/Classes/ServiceAPI/MyRadio_UserOfficership.php b/src/Classes/ServiceAPI/MyRadio_UserOfficership.php index 589decf70..8f42934a2 100644 --- a/src/Classes/ServiceAPI/MyRadio_UserOfficership.php +++ b/src/Classes/ServiceAPI/MyRadio_UserOfficership.php @@ -85,8 +85,8 @@ public function toDataSource($mixins = []) // Ensure we don't get infinite recursion 'member' => $this->getUser()->toDataSource(), 'officer' => $this->getOfficer()->toDataSource(), - 'from_date' => strftime("%Y-%m-%d", $this->from_date), - 'till_date' => $this->till_date === null ? null : strftime("%Y-%m-%d", $this->till_date), + 'from_date' => date("Y-m-d", $this->from_date), + 'till_date' => $this->till_date === null ? null : date("Y-m-d", $this->till_date), // Compatibility with old MyRadio_User::getOfficerships 'officer_name' => $this->getOfficer()->getName(), ]; diff --git a/src/Controllers/Events/duplicateEvent.php b/src/Controllers/Events/duplicateEvent.php index 8ef9e22a2..2c2e9e67a 100644 --- a/src/Controllers/Events/duplicateEvent.php +++ b/src/Controllers/Events/duplicateEvent.php @@ -16,8 +16,8 @@ unset($vals['host']); unset($vals['start']); unset($vals['end']); -$vals['start_time'] = strftime('%d/%m/%Y %H:%M', $event->getStartTime()); -$vals['end_time'] = strftime('%d/%m/%Y %H:%M', $event->getEndTime()); +$vals['start_time'] = date('d/m/Y H:i', $event->getStartTime()); +$vals['end_time'] = date('d/m/Y H:i', $event->getEndTime()); MyRadio_Event::getForm() ->setValues($vals)