From 518c32efe6e8d8a70a052b50328c7686cffd00db Mon Sep 17 00:00:00 2001 From: fusionate Date: Wed, 20 Sep 2023 20:49:27 +0000 Subject: [PATCH] Misc: Mitigate PHP 8.1 warnings. --- app/bridges/bridge_edit.php | 54 +++++++++++-------- .../resources/classes/destinations.php | 16 +++--- index.php | 2 +- resources/classes/permissions.php | 2 +- resources/functions.php | 2 +- 5 files changed, 42 insertions(+), 34 deletions(-) diff --git a/app/bridges/bridge_edit.php b/app/bridges/bridge_edit.php index 4621b2e51e..2dbfd4be27 100644 --- a/app/bridges/bridge_edit.php +++ b/app/bridges/bridge_edit.php @@ -234,21 +234,27 @@ //get the variables from inside the { and } brackets preg_match('/^\{([^}]+)\}/', $bridge_destination, $matches); - //create a variables array from the comma delimitted string - $variables = explode(",", $matches[1]); + if (!empty($matches) && is_array($matches) && @sizeof($matches) != 0) { - //strip the variables from the $bridge_destination variable - $bridge_destination = str_replace("{$matches[0]}", '', $bridge_destination); + //create a variables array from the comma delimitted string + $variables = explode(",", $matches[1]); + + //strip the variables from the $bridge_destination variable + $bridge_destination = str_replace("{$matches[0]}", '', $bridge_destination); + + } //build a bridge variables data set $x = 0; - foreach($variables as $variable) { - $pairs = explode("=", $variable); - $database_variables[$x]['name'] = $pairs[0]; - $database_variables[$x]['value'] = $pairs[1]; - $database_variables[$x]['label'] = ucwords(str_replace('_', ' ', $pairs[0])); - $database_variables[$x]['label'] = str_replace('Effective Caller Id', 'Caller ID', $database_variables[$x]['label']); - $x++; + if (!empty($variables) && is_array($variables)) { + foreach($variables as $variable) { + $pairs = explode("=", $variable); + $database_variables[$x]['name'] = $pairs[0]; + $database_variables[$x]['value'] = $pairs[1]; + $database_variables[$x]['label'] = ucwords(str_replace('_', ' ', $pairs[0])); + $database_variables[$x]['label'] = str_replace('Effective Caller Id', 'Caller ID', $database_variables[$x]['label']); + $x++; + } } } @@ -310,9 +316,9 @@ //get the gateways $actions = explode(',', $bridge_destination); - foreach($actions as $action) { + foreach ($actions as $action) { $action_array = explode('/',$action); - if ($action_array[1] == 'gateway') { + if (!empty($action_array) && is_array($action_array) && !empty($action_array[1]) && $action_array[1] == 'gateway') { $bridge_gateways[] = $action_array[2]; $destination_number = $action_array[3]; } @@ -385,9 +391,11 @@ echo " "; echo " }\n"; echo "\n"; - echo " window.onload = function() {\n"; - echo " action_control('".$bridge_action."');\n"; - echo " };\n"; + if (!empty($bridge_action)) { + echo " window.onload = function() {\n"; + echo " action_control('".$bridge_action."');\n"; + echo " };\n"; + } echo "\n"; //show the content @@ -431,7 +439,7 @@ echo " \n"; $i = 0; foreach($bridge_actions as $row) { - echo " \n"; + echo " \n"; } echo " \n"; echo "
\n"; @@ -465,7 +473,7 @@ echo " \n"; + echo "\n"; + echo " \n"; echo "
\n"; echo $text['description-destination_number']."\n"; echo "\n"; diff --git a/app/destinations/resources/classes/destinations.php b/app/destinations/resources/classes/destinations.php index d6e8e18d2c..863c4c99ff 100644 --- a/app/destinations/resources/classes/destinations.php +++ b/app/destinations/resources/classes/destinations.php @@ -506,7 +506,7 @@ if (!class_exists('destinations')) { if (isset($destination_key) && $key == $destination_key) { foreach($value as $k => $row) { $selected = ($row['destination'] == $destination_value) ? "selected='selected'" : ''; - $uuid = isset($row[$this->singular($key).'_uuid']) ? $row[$this->singular($key).'_uuid'] : $row['uuid']; + $uuid = isset($row[$this->singular($key).'_uuid']) ? $row[$this->singular($key).'_uuid'] : ($row['uuid'] ?? ''); $response .= " \n"; } } @@ -881,7 +881,7 @@ if (!class_exists('destinations')) { $name = $row['name']; $label = $row['label']; - $destination = $row['field']['destination']; + $destination = $row['field']['destination'] ?? null; //add multi-lingual support if (file_exists($_SERVER["PROJECT_ROOT"]."/app/".$name."/app_languages.php")) { @@ -889,7 +889,7 @@ if (!class_exists('destinations')) { $text2 = $language2->get($_SESSION['domain']['language']['code'], 'app/'.$name); } - if (is_array($row['result']['data']) && !empty($row['select_value'][$destination_type])) { + if (isset($row['result']) && is_array($row['result']['data']) && !empty($row['select_value'][$destination_type])) { $label2 = $label; foreach ($row['result']['data'] as $data) { $select_value = $row['select_value'][$destination_type]; @@ -920,12 +920,12 @@ if (!class_exists('destinations')) { } } else { - $select_value = str_replace("\${".$key."}", $data[$key], $select_value); + $select_value = str_replace("\${".$key."}", ($data[$key] ?? ''), $select_value); if (empty($data['label'])) { - $select_label = str_replace("\${".$key."}", $data[$key], $select_label); + $select_label = str_replace("\${".$key."}", ($data[$key] ?? ''), $select_label); } else { - $label = $data['label']; +// $label = $data['label']; $select_label = str_replace("\${".$key."}", $text2['option-'.$label], $select_label); } } @@ -949,7 +949,7 @@ if (!class_exists('destinations')) { $select_label = str_replace("✉", 'email-icon', $select_label); $select_label = escape(trim($select_label)); $select_label = str_replace('email-icon', '✉', $select_label); - if ($select_value == $destination_value) { $selected = "true' "; } else { $selected = 'false'; } + if (isset($destination_value) && $select_value == $destination_value) { $selected = "true' "; } else { $selected = 'false'; } if ($label2 == 'destinations') { $select_label = format_phone($select_label); } $array[$name][$i] = $data; @@ -959,7 +959,7 @@ if (!class_exists('destinations')) { //$array[$name][$i]['select_value'] = $select_value; //$array[$name][$i]['selected'] = $selected; $array[$name][$i]['destination'] = $select_value; - $array[$name][$i]["extension"] = $data["extension"]; + $array[$name][$i]["extension"] = $data["extension"] ?? null; $i++; } diff --git a/index.php b/index.php index 0d4e43642d..ad0ffb8c83 100644 --- a/index.php +++ b/index.php @@ -46,7 +46,7 @@ } else { //use custom index, if present, otherwise use custom login, if present, otherwise use default login - if (file_exists($_SERVER["PROJECT_ROOT"]."/themes/".$_SESSION['domain']['template']['name']."/index.php")) { + if (file_exists($_SERVER["PROJECT_ROOT"]."/themes/".($_SESSION['domain']['template']['name'] ?? '')."/index.php")) { require_once "themes/".$_SESSION['domain']['template']['name']."/index.php"; } else { diff --git a/resources/classes/permissions.php b/resources/classes/permissions.php index b0fd62808e..a4b6a6650f 100644 --- a/resources/classes/permissions.php +++ b/resources/classes/permissions.php @@ -90,7 +90,7 @@ if (!class_exists('permissions')) { } if (empty($permissions)) { - $permissions = $_SESSION["permissions"]; + $permissions = $_SESSION["permissions"] ?? []; } //set default to false diff --git a/resources/functions.php b/resources/functions.php index 6a4ab4288a..b48e81202c 100644 --- a/resources/functions.php +++ b/resources/functions.php @@ -1211,7 +1211,7 @@ function number_pad($number,$n) { else { //rgb(a) $rgb = implode(',', $color); if (!empty($alpha)) { $rgb .= ','.$alpha; $a = 'a'; } - if ($wrapper) { $rgb = 'rgb'.$a.'('.$rgb.')'; } + if ($wrapper) { $rgb = 'rgb'.($a ?? '').'('.$rgb.')'; } return $rgb; } }