From 6b07e8d1683d5f33ff09490619ed5f89362f7607 Mon Sep 17 00:00:00 2001 From: fusionate Date: Thu, 8 Jun 2023 19:51:18 +0000 Subject: [PATCH] Phrases: Updates for PHP 8.1 --- app/phrases/phrase_edit.php | 16 ++++----- app/phrases/phrases.php | 10 +++--- app/phrases/resources/classes/phrases.php | 44 +++++++++++++---------- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/app/phrases/phrase_edit.php b/app/phrases/phrase_edit.php index b1402898d9..cfaa85ed48 100644 --- a/app/phrases/phrase_edit.php +++ b/app/phrases/phrase_edit.php @@ -128,7 +128,7 @@ } //add the phrase - if ($_POST["persistformvar"] != "true") { + if (empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true") { if ($action == "add" && permission_exists('phrase_add')) { //build data array $phrase_uuid = uuid(); @@ -154,11 +154,11 @@ $array['phrase_details'][0]['domain_uuid'] = $domain_uuid; $array['phrase_details'][0]['phrase_detail_order'] = $_POST['phrase_detail_order']; $array['phrase_details'][0]['phrase_detail_tag'] = $_POST['phrase_detail_tag']; - $array['phrase_details'][0]['phrase_detail_pattern'] = $_POST['phrase_detail_pattern']; + $array['phrase_details'][0]['phrase_detail_pattern'] = $_POST['phrase_detail_pattern'] ?? null; $array['phrase_details'][0]['phrase_detail_function'] = $_POST['phrase_detail_function']; $array['phrase_details'][0]['phrase_detail_data'] = $_POST['phrase_detail_data']; - $array['phrase_details'][0]['phrase_detail_method'] = $_POST['phrase_detail_method']; - $array['phrase_details'][0]['phrase_detail_type'] = $_POST['phrase_detail_type']; + $array['phrase_details'][0]['phrase_detail_method'] = $_POST['phrase_detail_method'] ?? null; + $array['phrase_details'][0]['phrase_detail_type'] = $_POST['phrase_detail_type'] ?? null; $array['phrase_details'][0]['phrase_detail_group'] = $_POST['phrase_detail_group']; } } @@ -218,11 +218,11 @@ $array['phrase_details'][0]['domain_uuid'] = $domain_uuid; $array['phrase_details'][0]['phrase_detail_order'] = $_POST['phrase_detail_order']; $array['phrase_details'][0]['phrase_detail_tag'] = $_POST['phrase_detail_tag']; - $array['phrase_details'][0]['phrase_detail_pattern'] = $_POST['phrase_detail_pattern']; + $array['phrase_details'][0]['phrase_detail_pattern'] = $_POST['phrase_detail_pattern'] ?? null; $array['phrase_details'][0]['phrase_detail_function'] = $_POST['phrase_detail_function']; $array['phrase_details'][0]['phrase_detail_data'] = $_POST['phrase_detail_data']; - $array['phrase_details'][0]['phrase_detail_method'] = $_POST['phrase_detail_method']; - $array['phrase_details'][0]['phrase_detail_type'] = $_POST['phrase_detail_type']; + $array['phrase_details'][0]['phrase_detail_method'] = $_POST['phrase_detail_method'] ?? null; + $array['phrase_details'][0]['phrase_detail_type'] = $_POST['phrase_detail_type'] ?? null; $array['phrase_details'][0]['phrase_detail_group'] = $_POST['phrase_detail_group']; } } @@ -354,7 +354,7 @@ echo "var opt_group = document.createElement('optgroup');\n"; echo "opt_group.label = \"".$text['label-recordings']."\";\n"; foreach ($recordings as &$row) { - if ($_SESSION['recordings']['storage_type']['text'] == 'base64') { + if (!empty($_SESSION['recordings']['storage_type']['text']) && $_SESSION['recordings']['storage_type']['text'] == 'base64') { echo "opt_group.appendChild(new Option(\"".$row["recording_name"]."\", \"\${lua streamfile.lua ".$row["recording_filename"]."}\"));\n"; } else { diff --git a/app/phrases/phrases.php b/app/phrases/phrases.php index a51ff34779..d63dd46a0b 100644 --- a/app/phrases/phrases.php +++ b/app/phrases/phrases.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2018-2020 + Portions created by the Initial Developer are Copyright (C) 2018-2023 the Initial Developer. All Rights Reserved. Contributor(s): @@ -196,7 +196,7 @@ echo "\n"; if (permission_exists('phrase_add') || permission_exists('phrase_edit') || permission_exists('phrase_delete')) { echo " \n"; - echo " \n"; + echo " \n"; echo " \n"; } if ($show == "all" && permission_exists('phrase_all')) { @@ -224,7 +224,7 @@ echo " \n"; echo " \n"; } - if ($_GET['show'] == "all" && permission_exists('phrase_all')) { + if (!empty($_GET['show']) && $_GET['show'] == "all" && permission_exists('phrase_all')) { if (!empty($_SESSION['domains'][$row['domain_uuid']]['domain_name'])) { $domain = $_SESSION['domains'][$row['domain_uuid']]['domain_name']; } @@ -252,7 +252,7 @@ } echo " \n"; echo " ".escape($row['phrase_description'])." \n"; - if (permission_exists('phrase_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + if (permission_exists('phrase_edit') && !empty($_SESSION['theme']['list_row_edit_button']['boolean']) && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { echo " "; echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); echo " \n"; @@ -274,4 +274,4 @@ //include the footer require_once "resources/footer.php"; -?> +?> \ No newline at end of file diff --git a/app/phrases/resources/classes/phrases.php b/app/phrases/resources/classes/phrases.php index 792d21544c..cee405e23b 100644 --- a/app/phrases/resources/classes/phrases.php +++ b/app/phrases/resources/classes/phrases.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2019 + Portions created by the Initial Developer are Copyright (C) 2008-2023 the Initial Developer. All Rights Reserved. Contributor(s): @@ -85,7 +85,7 @@ if (!class_exists('phrases')) { //filter out unchecked phrases, build where clause for below foreach ($records as $record) { - if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { $uuids[] = "'".$record['uuid']."'"; } } @@ -181,7 +181,7 @@ if (!class_exists('phrases')) { //filter out unchecked phrases, build the delete array foreach ($records as $x => $record) { - if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid']; $array[$this->table][$x]['phrase_uuid'] = $this->phrase_uuid; $array[$this->table][$x]['domain_uuid'] = $_SESSION['domain_uuid']; @@ -189,7 +189,7 @@ if (!class_exists('phrases')) { } //get phrase languages - if (is_array($array) && @sizeof($array) != 0) { + if (!empty($array) && is_array($array) && @sizeof($array) != 0) { $sql = "select phrase_language as lang from v_phrases "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and phrase_uuid = :phrase_uuid "; @@ -201,7 +201,7 @@ if (!class_exists('phrases')) { } //delete the checked rows - if (is_array($array) && @sizeof($array) != 0) { + if (!empty($array) && is_array($array) && @sizeof($array) != 0) { //grant temporary permissions $p = new permissions; @@ -251,8 +251,8 @@ if (!class_exists('phrases')) { if (is_array($records) && @sizeof($records) != 0) { //get current toggle state and language - foreach($records as $x => $record) { - if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + foreach ($records as $x => $record) { + if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { $uuids[] = "'".$record['uuid']."'"; } } @@ -291,10 +291,12 @@ if (!class_exists('phrases')) { unset($array); //clear the cache - $phrase_languages = array_unique($phrase_languages); - $cache = new cache; - foreach ($phrase_languages as $phrase_language) { - $cache->delete("languages:".$phrase_language); + if (!empty($phrase_languages) && is_array($phrase_languages) && @sizeof($phrase_languages) != 0) { + $phrase_languages = array_unique($phrase_languages); + $cache = new cache; + foreach ($phrase_languages as $phrase_language) { + $cache->delete("languages:".$phrase_language); + } } //clear the destinations session array @@ -333,8 +335,8 @@ if (!class_exists('phrases')) { if (is_array($records) && @sizeof($records) != 0) { //get checked records - foreach($records as $x => $record) { - if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + foreach ($records as $x => $record) { + if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { $uuids[] = "'".$record['uuid']."'"; } } @@ -384,7 +386,9 @@ if (!class_exists('phrases')) { unset($sql_2, $parameters_2, $rows_2, $row_2); //create array of languages - $phrase_languages[] = $row['phrase_languages']; + if (!empty($row['phrase_languages'])) { + $phrase_languages[] = $row['phrase_languages']; + } } } unset($sql, $parameters, $rows, $row); @@ -408,10 +412,12 @@ if (!class_exists('phrases')) { $p->delete('phrase_detail_add', 'temp'); //clear the cache - $phrase_languages = array_unique($phrase_languages); - $cache = new cache; - foreach ($phrase_languages as $phrase_language) { - $cache->delete("languages:".$phrase_language); + if (!empty($phrase_languages) && is_array($phrase_languages) && @sizeof($phrase_languages) != 0) { + $phrase_languages = array_unique($phrase_languages); + $cache = new cache; + foreach ($phrase_languages as $phrase_language) { + $cache->delete("languages:".$phrase_language); + } } //set message @@ -427,4 +433,4 @@ if (!class_exists('phrases')) { } //class } -?> +?> \ No newline at end of file