From 1e391aad4f49a7f966f79bb8ac2e9fdcaee8523a Mon Sep 17 00:00:00 2001 From: fusionate Date: Thu, 8 Jun 2023 18:03:37 +0000 Subject: [PATCH] MOH: Updates for PHP 8.1 --- app/music_on_hold/music_on_hold.php | 18 ++++++++++-------- .../resources/classes/switch_music_on_hold.php | 14 ++++++++------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/music_on_hold/music_on_hold.php b/app/music_on_hold/music_on_hold.php index 82a6031c22..2c5a116b0d 100644 --- a/app/music_on_hold/music_on_hold.php +++ b/app/music_on_hold/music_on_hold.php @@ -123,13 +123,9 @@ //download the file if (file_exists($stream_full_path)) { - //content-range - if (isset($_SERVER['HTTP_RANGE']) && $_GET['t'] != "bin") { - range_download($stream_full_path); - } $fd = fopen($stream_full_path, "rb"); - if ($_GET['t'] == "bin") { + if (!empty($_GET['t']) && $_GET['t'] == "bin") { header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); @@ -146,10 +142,16 @@ header('Content-Disposition: attachment; filename="'.$stream_file.'"'); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past - if ($_GET['t'] == "bin") { + if (!empty($_GET['t']) && $_GET['t'] == "bin") { header("Content-Length: ".filesize($stream_full_path)); } ob_clean(); + + //content-range + if (isset($_SERVER['HTTP_RANGE']) && (empty($_GET['t']) || $_GET['t'] != "bin")) { + range_download($stream_full_path); + } + fpassthru($fd); } exit; @@ -659,7 +661,7 @@ // If the range starts with an '-' we start from the beginning // If not, we forward the file pointer // And make sure to get the end byte if spesified - if ($range0 == '-') { + if (!empty($range0) && $range0 == '-') { // The n-number of the last bytes is requested $c_start = $size - substr($range, 1); } @@ -707,4 +709,4 @@ fclose($fp); } -?> +?> \ No newline at end of file diff --git a/app/music_on_hold/resources/classes/switch_music_on_hold.php b/app/music_on_hold/resources/classes/switch_music_on_hold.php index 41b28096cf..9115117be9 100644 --- a/app/music_on_hold/resources/classes/switch_music_on_hold.php +++ b/app/music_on_hold/resources/classes/switch_music_on_hold.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) 2010-2019 + Portions created by the Initial Developer are Copyright (C) 2010-2023 All Rights Reserved. Contributor(s): @@ -336,13 +336,14 @@ if (!class_exists('switch_music_on_hold')) { if (is_array($records) && @sizeof($records) != 0) { //filter checked records +// view_array($records, 0); foreach ($records as $music_on_hold_uuid => $record) { if (is_uuid($music_on_hold_uuid)) { if ($record['checked'] == 'true') { $moh[$music_on_hold_uuid]['delete'] = true; } foreach ($record as $key => $array) { - if (is_numeric($key) && is_array($array) && @sizeof($array) != 0 && $array['checked'] == 'true') { + if (is_numeric($key) && is_array($array) && @sizeof($array) != 0 && !empty($array['checked']) && $array['checked'] == 'true') { $moh[$music_on_hold_uuid][] = $array['file_name']; } } @@ -370,6 +371,7 @@ if (!class_exists('switch_music_on_hold')) { //delete files, folders, build delete array $x = 0; +// view_array($moh); foreach ($moh as $music_on_hold_uuid => $row) { //prepare path @@ -387,7 +389,7 @@ if (!class_exists('switch_music_on_hold')) { } //delete name rate - if ($row['delete']) { + if (!empty($row['delete']) && $row['delete'] == true) { //build delete array $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $music_on_hold_uuid; @@ -411,7 +413,7 @@ if (!class_exists('switch_music_on_hold')) { } //delete the moh records - if (is_array($array) && @sizeof($array) != 0) { + if (!empty($array) && is_array($array) && @sizeof($array) != 0) { //execute delete $database = new database; @@ -427,7 +429,7 @@ if (!class_exists('switch_music_on_hold')) { unset($records, $moh); //post delete - if ($moh_deleted || $files_deleted) { + if ((!empty($moh_deleted) && $moh_deleted == true) || $files_deleted != 0) { //clear the cache $cache = new cache; $cache->delete("configuration:local_stream.conf"); @@ -453,4 +455,4 @@ if (!class_exists('switch_music_on_hold')) { //$moh->xml(); //$moh->save(); -?> +?> \ No newline at end of file