From 68053abcb91cda3c9d4aebc1244b8cd3740b21ba Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 30 Aug 2013 15:30:45 +0200 Subject: [PATCH] Adding wami support if browser is not chrome. see BT#6613 --- .../inc/lib/wami-recorder/record_document.php | 74 +++++++-- main/newscorm/learnpath.class.php | 5 +- main/newscorm/lp_add_audio.php | 34 ++-- .../default/learnpath/record_voice.tpl | 154 +++++++++++++----- 4 files changed, 189 insertions(+), 78 deletions(-) diff --git a/main/inc/lib/wami-recorder/record_document.php b/main/inc/lib/wami-recorder/record_document.php index 7e41ba6762..05efff625a 100644 --- a/main/inc/lib/wami-recorder/record_document.php +++ b/main/inc/lib/wami-recorder/record_document.php @@ -26,7 +26,6 @@ if ($wamiuserid != api_get_user_id() || api_get_user_id() == 0 || $wamiuserid == die(); } - //clean $waminame = Security::remove_XSS($waminame); $waminame = Database::escape_string($waminame); @@ -34,9 +33,12 @@ $waminame = addslashes(trim($waminame)); $waminame = replace_dangerous_char($waminame, 'strict'); $waminame = disable_dangerous_file($waminame); $wamidir = Security::remove_XSS($wamidir); - $content = file_get_contents('php://input'); +if (empty($content)) { + exit; +} + //security extension $ext = explode('.', $waminame); $ext = strtolower($ext[sizeof($ext) - 1]); @@ -50,7 +52,7 @@ if ($ext != 'wav') { $dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; $saveDir = $dirBaseDocuments.$wamidir; $current_session_id = api_get_session_id(); -$groupId = $_SESSION['_gid']; +$groupId = api_get_group_id(); //avoid duplicates $waminame_to_save = $waminame; @@ -68,22 +70,58 @@ if (file_exists($saveDir.'/'.$waminame_noex.'.'.$ext)) { $documentPath = $saveDir.'/'.$waminame_to_save; -//add to disk +// Add to disk $fh = fopen($documentPath, 'w') or die("can't open file"); fwrite($fh, $content); fclose($fh); -//add document to database -$doc_id = add_document($_course, $wamidir.'/'.$waminame_to_save, 'file', filesize($documentPath), $title_to_save); -api_item_property_update( - $_course, - TOOL_DOCUMENT, - $doc_id, - 'DocumentAdded', - $_user['user_id'], - $groupId, - null, - null, - null, - $current_session_id -); +$addToLP = false; + +if (isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id'])) { + $lpItemId = $_REQUEST['lp_item_id']; + $lp = isset($_SESSION['oLP']) ? $_SESSION['oLP'] : null; + + if (!empty($lp)) { + $addToLP = true; + // Converts wav into mp3 + require_once '../../../../vendor/autoload.php'; + $ffmpeg = \FFMpeg\FFMpeg::create(); + $oldWavFile = $documentPath; + if (file_exists($oldWavFile)) { + $video = $ffmpeg->open($documentPath); + $waminame_to_save = str_replace('wav', 'mp3', $waminame_to_save); + $documentPath = $saveDir.'/'.$waminame_to_save; + $title_to_save = $waminame_to_save; + + $result = $video->save(new FFMpeg\Format\Audio\Mp3(), $documentPath); + if ($result) { + unlink($oldWavFile); + } + } + } +} + +if (file_exists($documentPath)) { + // Add document to database + $newDocId = add_document($_course, $wamidir.'/'.$waminame_to_save, 'file', filesize($documentPath), $title_to_save); + + api_item_property_update( + $_course, + TOOL_DOCUMENT, + $newDocId, + 'DocumentAdded', + api_get_user_id(), + $groupId, + null, + null, + null, + $current_session_id + ); + + if ($addToLP) { + $lp->set_modified_on(); + $lpItem = new learnpathItem($lpItemId); + $lpItem->add_audio_from_documents($newDocId); + } +} + diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 27f0f2f70d..c0a1e1b593 100644 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -4922,7 +4922,8 @@ class learnpath { public function return_new_tree($update_audio = 'false', $drop_element_here = false) { $ajax_url = api_get_path(WEB_AJAX_PATH).'lp.ajax.php'; - echo ' - - -
- - + + + + +
+ + +
+ {{ 'RecordAudio' | get_lang }} + +
+ +
+ {{ 'ActivateAudioRecorder' | get_lang }} +
+
+
+ +
+ - - -