From 242ab77ccb16a60e6bca99a12bbcb4137fd1a14f Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Thu, 23 Apr 2015 00:10:31 +0000 Subject: [PATCH] Voicemail: Add functionality to Play and Download base64 messages in the database. --- .../resources/classes/voicemail.php | 54 +++++++++++++++++-- app/voicemails/voicemail_messages.php | 6 ++- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/app/voicemails/resources/classes/voicemail.php b/app/voicemails/resources/classes/voicemail.php index bc1989ec31..2ab966ffef 100644 --- a/app/voicemails/resources/classes/voicemail.php +++ b/app/voicemails/resources/classes/voicemail.php @@ -277,15 +277,57 @@ //clear the cache session_cache_limiter('public'); - //prepare and stream the file + //set source folder path $path = $_SESSION['switch']['storage']['dir'].'/voicemail/default/'.$_SESSION['domain_name'].'/'.$this->voicemail_id; + + //prepare base64 content from db, if enabled + if ($_SESSION['voicemail']['storage_type']['text'] == 'base64') { + $sql = "select message_base64 from "; + $sql .= "v_voicemail_messages as m, "; + $sql .= "v_voicemails as v "; + $sql .= "where "; + $sql .= "m.voicemail_uuid = v.voicemail_uuid "; + $sql .= "and v.voicemail_id = '".$this->voicemail_id."' "; + $sql .= "and m.voicemail_uuid = '".$this->voicemail_uuid."' "; + $sql .= "and m.domain_uuid = '".$this->domain_uuid."' "; + $sql .= "and m.voicemail_message_uuid = '".$this->voicemail_message_uuid."' "; + $prep_statement = $this->db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); + if (count($result) > 0) { + foreach($result as &$row) { + if ($row['message_base64'] != '') { + $message_decoded = base64_decode($row['message_base64']); + file_put_contents($path.'/msg_'.$this->voicemail_message_uuid.'.ext', $message_decoded); + $finfo = finfo_open(FILEINFO_MIME_TYPE); //determine mime type (requires PHP >= 5.3.0, must be manually enabled on Windows) + $file_mime = finfo_file($finfo, $path.'/msg_'.$this->voicemail_message_uuid.'.???'); + finfo_close($finfo); + switch ($file_mime) { + case 'audio/x-wav': + case 'audio/wav': + $file_ext = 'wav'; + break; + case 'audio/mpeg': + case 'audio/mp3': + $file_ext = 'mp3'; + break; + } + rename($path.'/msg_'.$this->voicemail_message_uuid.'.ext', $path.'/msg_'.$this->voicemail_message_uuid.'.'.$file_ext); + } + break; + } + } + unset ($sql, $prep_statement, $result, $message_decoded); + } + + //prepare and stream the file if (file_exists($path.'/msg_'.$this->voicemail_message_uuid.'.wav')) { $file_path = $path.'/msg_'.$this->voicemail_message_uuid.'.wav'; } if (file_exists($path.'/msg_'.$this->voicemail_message_uuid.'.mp3')) { $file_path = $path.'/msg_'.$this->voicemail_message_uuid.'.mp3'; } - if (file_exists($file_path)) { + if ($file_path != '') { $fd = fopen($file_path, "rb"); if ($_GET['t'] == "bin") { header("Content-Type: application/force-download"); @@ -306,7 +348,7 @@ header("Content-Type: audio/wav"); } if ($file_ext == "mp3") { - header("Content-Type: audio/mp3"); + header("Content-Type: audio/mpeg"); } } header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 @@ -314,6 +356,12 @@ header("Content-Length: " . filesize($file_path)); fpassthru($fd); } + + //if base64, remove temp file + if ($_SESSION['voicemail']['storage_type']['text'] == 'base64') { + @unlink($path.'/msg_'.$this->voicemail_message_uuid.'.'.$file_ext); + } + } // download } diff --git a/app/voicemails/voicemail_messages.php b/app/voicemails/voicemail_messages.php index 8b965e2150..13942dabdb 100644 --- a/app/voicemails/voicemail_messages.php +++ b/app/voicemails/voicemail_messages.php @@ -45,12 +45,14 @@ if (!(check_str($_REQUEST["action"]) == "download" && check_str($_REQUEST["src"] $voicemail_uuid = check_str($_REQUEST["id"]); } +//required class + require_once "app/voicemails/resources/classes/voicemail.php"; + //download the message if (check_str($_REQUEST["action"]) == "download") { $voicemail_message_uuid = check_str($_REQUEST["uuid"]); $voicemail_id = check_str($_REQUEST["id"]); $voicemail_uuid = check_str($_REQUEST["voicemail_uuid"]); - //require_once "resources/classes/voicemail.php"; if ($voicemail_message_uuid != '' && $voicemail_id != '' && $voicemail_uuid != '') { $voicemail = new voicemail; $voicemail->db = $db; @@ -70,7 +72,6 @@ if (!(check_str($_REQUEST["action"]) == "download" && check_str($_REQUEST["src"] $order = check_str($_GET["order"]); //get the voicemail - require_once "app/voicemails/resources/classes/voicemail.php"; $vm = new voicemail; $vm->db = $db; $vm->domain_uuid = $_SESSION['domain_uuid']; @@ -80,6 +81,7 @@ if (!(check_str($_REQUEST["action"]) == "download" && check_str($_REQUEST["src"] $voicemails = $vm->messages(); //additional includes + $document['title'] = $text['title-voicemail_messages']; require_once "resources/header.php"; require_once "resources/paging.php";