diff --git a/main/document/record_audio.php b/main/document/record_audio.php
index 1b87d9b429..0b09ad64c8 100644
--- a/main/document/record_audio.php
+++ b/main/document/record_audio.php
@@ -168,6 +168,7 @@ function submitVoice() {
//
var applet = document.getElementById("nanogong");
var ret = applet.sendGongRequest( "PostToForm", urlnanogong, "voicefile", cookie, "temp");//'PostToForm', postURL, inputname, cookie, filename
+
if (ret == null) {
alert(lang_failled_to_submit);
} else {
diff --git a/main/document/showinframes.php b/main/document/showinframes.php
index 427a1c1ab3..0e316fb318 100644
--- a/main/document/showinframes.php
+++ b/main/document/showinframes.php
@@ -402,19 +402,14 @@ if ($is_nanogong_available) {
}
//get file from tmp directory
- $to_url=api_get_path(WEB_ARCHIVE_PATH).'temp/audio/'.$file_crip;
+ $to_url = api_get_path(WEB_ARCHIVE_PATH).'temp/audio/'.$file_crip;
echo '
';
echo '
'.get_lang('Download').'';
echo '
';
echo '
';
-
- echo '
';
+
+ echo DocumentManager::readNanogongFile($to_url);
//erase temp file in tmp directory when return to documents
$_SESSION['temp_audio_nanogong']=$to_sys;
diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php
index e8b072d2d2..6dee48321b 100644
--- a/main/inc/lib/display.lib.php
+++ b/main/inc/lib/display.lib.php
@@ -1571,11 +1571,21 @@ class Display {
return $html;
}
+ /**
+ * @param string $file
+ * @param array $params
+ * @return null|string
+ */
public static function getMediaPlayer($file, $params = array())
{
$fileInfo = pathinfo($file);
switch ($fileInfo['extension']) {
+ case 'wav':
+ if (isset($params['url'])) {
+ return DocumentManager::readNanogongFile($params['url']);
+ }
+ break;
case 'mp3':
case 'webm':
$autoplay = null;
@@ -1587,14 +1597,13 @@ class Display {
$class = isset($params['class']) ? ' class="'.$params['class'].'"' : null;
$html = '
';
+ $html .= '';
return $html;
break;
-
}
return null;
diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php
index f85c1bb51f..0d85c6e891 100644
--- a/main/inc/lib/document.lib.php
+++ b/main/inc/lib/document.lib.php
@@ -1113,6 +1113,7 @@ class DocumentManager
*
* @param array $courseInfo
* @param string $path
+ * @param int $sessionId
* @return int id of document / false if no doc found
*/
public static function get_document_id($courseInfo, $path, $sessionId = null)
@@ -3212,7 +3213,7 @@ class DocumentManager
* @param bool When set to true, this runs the indexer without actually saving anything to any database
* @return bool Returns true on presumed success, false on failure
*/
- public function index_document(
+ public static function index_document(
$docid,
$course_code,
$session_id = 0,
@@ -3540,4 +3541,139 @@ class DocumentManager
}
}
}
+
+ /**
+ * @param string $file
+ * @return string
+ */
+ public static function readNanogongFile($file)
+ {
+ $nanoGongJarFile = api_get_path(WEB_LIBRARY_PATH).'nanogong/nanogong.jar';
+
+ $html = '
';
+ return $html;
+ }
+
+ /**
+ * @param string $filePath
+ * @param string $path
+ * @param $courseInfo
+ * @param string $whatIfFileExists overwrite|rename
+ * @param null $userId
+ * @param null $groupId
+ * @param null $toUserId
+ * @return bool|path
+ */
+ public static function addFileToDocumentTool(
+ $filePath,
+ $path,
+ $courseInfo,
+ $userId,
+ $whatIfFileExists = 'overwrite',
+ $groupId = null,
+ $toUserId = null
+ ) {
+ if (!file_exists($filePath)) {
+ return false;
+ }
+
+ $fileInfo = pathinfo($filePath);
+
+ $file = array(
+ 'name' => $fileInfo['basename'],
+ 'tmp_name' => $filePath,
+ 'size' => filesize($filePath),
+ 'from_file' => true
+ );
+
+ $course_dir = $courseInfo['path'].'/document';
+ $baseWorkDir = api_get_path(SYS_COURSE_PATH).$course_dir;
+
+ $filePath = handle_uploaded_document(
+ $courseInfo,
+ $file,
+ $baseWorkDir,
+ $path,
+ $userId,
+ $groupId,
+ $toUserId,
+ false,
+ $whatIfFileExists,
+ false
+ );
+
+ if ($filePath) {
+ return DocumentManager::get_document_id($courseInfo, $filePath);
+ }
+ return false;
+ }
+
+ /**
+ * Converts wav to mp3 file.
+ * Requires the ffmpeg lib. In ubuntu: sudo apt-get install ffmpeg
+ * @param string $wavFile
+ * @param bool $removeWavFileIfSuccess
+ * @return bool
+ */
+ public static function convertWavToMp3($wavFile, $removeWavFileIfSuccess = false)
+ {
+ require_once '../../../../vendor/autoload.php';
+
+ if (file_exists($wavFile)) {
+ try {
+ $ffmpeg = \FFMpeg\FFMpeg::create();
+ $video = $ffmpeg->open($wavFile);
+ $mp3File = str_replace('wav', 'mp3', $wavFile);
+ $result = $video->save(new FFMpeg\Format\Audio\Mp3(), $mp3File);
+ if ($result && $removeWavFileIfSuccess) {
+ unlink($wavFile);
+ }
+
+ if (file_exists($mp3File)) {
+ return $mp3File;
+ }
+ } catch (Exception $e) {
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @param string $documentData
+ * @param array $courseInfo
+ * @param string $whatIfFileExists
+ * @return bool|path
+ */
+ public static function addAndConvertWavToMp3($documentData, $courseInfo, $userId, $whatIfFileExists = 'overwrite')
+ {
+ if (empty($documentData)) {
+ return false;
+ }
+
+ if (isset($documentData['absolute_path']) && file_exists($documentData['absolute_path'])) {
+ $mp3FilePath = self::convertWavToMp3($documentData['absolute_path']);
+ //$mp3FilePath = str_replace('wav', 'mp3', $documentData['absolute_path']);
+ if (!empty($mp3FilePath)) {
+
+ $documentId = self::addFileToDocumentTool(
+ $mp3FilePath,
+ dirname($documentData['path']),
+ $courseInfo,
+ $userId,
+ $whatIfFileExists
+ );
+
+ if (!empty($documentId)) {
+ return $documentId;
+ }
+ }
+ }
+
+ return false;
+ }
}
diff --git a/main/inc/lib/fileUpload.lib.php b/main/inc/lib/fileUpload.lib.php
index f7e83c2516..efd785d735 100644
--- a/main/inc/lib/fileUpload.lib.php
+++ b/main/inc/lib/fileUpload.lib.php
@@ -191,6 +191,7 @@ function handle_uploaded_document(
if (!$user_id) {
die('Not a valid user.');
}
+
// Strip slashes
$uploaded_file['name'] = stripslashes($uploaded_file['name']);
// Add extension to files without one (if possible)
@@ -236,8 +237,10 @@ function handle_uploaded_document(
$upload_path = $upload_path.'/';
}
$file_path = $upload_path.$clean_name;
+
// Full path to where we want to store the file with trailing slash
$where_to_save = $base_work_dir.$upload_path;
+
// At least if the directory doesn't exist, tell so
if (!is_dir($where_to_save)) {
if ($output){
@@ -261,8 +264,9 @@ function handle_uploaded_document(
case 'overwrite':
// Check if the target file exists, so we can give another message
$file_exists = file_exists($store_path);
- if (@move_uploaded_file($uploaded_file['tmp_name'], $store_path)) {
+ if (moveUploadedFile($uploaded_file, $store_path)) {
chmod($store_path, $files_perm);
+
if ($file_exists) {
// UPDATE DATABASE
$document_id = DocumentManager::get_document_id($_course, $file_path);
@@ -327,7 +331,7 @@ function handle_uploaded_document(
$store_path = $where_to_save.$new_name;
$new_file_path = $upload_path.$new_name;
- if (@move_uploaded_file($uploaded_file['tmp_name'], $store_path)) {
+ if (moveUploadedFile($uploaded_file, $store_path)) {
chmod($store_path, $files_perm);
@@ -355,15 +359,14 @@ function handle_uploaded_document(
return false;
}
break;
-
- // Only save the file if it doesn't exist or warn user if it does exist
default:
+ // Only save the file if it doesn't exist or warn user if it does exist
if (file_exists($store_path)) {
if ($output) {
Display::display_error_message($clean_name.' '.get_lang('UplAlreadyExists'));
}
} else {
- if (@move_uploaded_file($uploaded_file['tmp_name'], $store_path)) {
+ if (moveUploadedFile($uploaded_file, $store_path)) {
chmod($store_path, $files_perm);
// Put the document data in the database
@@ -396,6 +399,21 @@ function handle_uploaded_document(
}
}
+/**
+ * @param string $file
+ * @param string $storePath
+ * @return bool
+ */
+function moveUploadedFile($file, $storePath)
+{
+ $handleFromFile = isset($file['from_file']) && $file['from_file'] ? true : false;
+ if ($handleFromFile) {
+ return file_exists($file['tmp_name']);
+ } else {
+ return move_uploaded_file($file['tmp_name'], $storePath);
+ }
+}
+
/**
* Checks if there is enough place to add a file on a directory
* on the base of a maximum directory size allowed
@@ -703,7 +721,6 @@ function unzip_uploaded_file($uploaded_file, $upload_path, $base_work_dir, $max_
closedir($dir);
} else {
error_log('Could not create directory '.$base_work_dir.$upload_path.' to unzip files');
-
}
chdir($save_dir); // Back to previous dir position
}
@@ -870,10 +887,25 @@ function filter_extension(&$filename) {
* @param string $filetype
* @param int $filesize
* @param string $title
+ * @param string $comment
+ * @param int $readonly
+ * @param bool $save_visibility
+ * @param int $group_id
* @param int $session_id Session ID, if any
* @return id if inserted document
*/
-function add_document($_course, $path, $filetype, $filesize, $title, $comment = null, $readonly = 0, $save_visibility = true, $group_id = null, $session_id = 0) {
+function add_document(
+ $_course,
+ $path,
+ $filetype,
+ $filesize,
+ $title,
+ $comment = null,
+ $readonly = 0,
+ $save_visibility = true,
+ $group_id = null,
+ $session_id = 0
+) {
if (empty($session_id)) {
$session_id = api_get_session_id();
}
diff --git a/main/inc/lib/nanogong/upload_nanogong_file.php b/main/inc/lib/nanogong/upload_nanogong_file.php
new file mode 100644
index 0000000000..22c410ebb0
--- /dev/null
+++ b/main/inc/lib/nanogong/upload_nanogong_file.php
@@ -0,0 +1,56 @@
+set_modified_on();
+ $lpItem = new learnpathItem($lpItemId);
+ $lpItem->add_audio_from_documents($newDocId);
+ }
+ }
+}
\ No newline at end of file
diff --git a/main/inc/lib/wami-recorder/record_document.php b/main/inc/lib/wami-recorder/record_document.php
index ca1059377e..4d056ba25c 100644
--- a/main/inc/lib/wami-recorder/record_document.php
+++ b/main/inc/lib/wami-recorder/record_document.php
@@ -72,54 +72,39 @@ $fh = fopen($documentPath, 'w') or die("can't open file");
fwrite($fh, $content);
fclose($fh);
-$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($oldWavFile);
-
- $waminame_to_save = str_replace('wav', 'mp3', $waminame_to_save);
- $documentPath = $saveDir.'/'.$waminame_to_save;
- $title_to_save = $waminame_to_save;
- //$video->save(new \FFMpeg\Format\Audio\Vorbis());
- $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);
+$fileInfo = pathinfo($documentPath);
+$courseInfo = api_get_course_info();
+
+$file = array(
+ 'file' => array(
+ 'name' => $fileInfo['basename'],
+ 'tmp_name' => $documentPath,
+ 'size' => filesize($documentPath),
+ 'from_file' => true
+ )
+);
+
+$output = true;
+$documentData = DocumentManager::upload_document($file, $wamidir, null, null, 0, 'overwrite', false, $output);
+
+if (!empty($documentData)) {
+ $newDocId = $documentData['id'];
+ $newMp3DocumentId = DocumentManager::addAndConvertWavToMp3($documentData, $courseInfo, api_get_user_id());
+
+ if ($newMp3DocumentId) {
+ $newDocId = $newMp3DocumentId;
}
-}
+ if (isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id'])) {
+ $lpItemId = $_REQUEST['lp_item_id'];
+ /** @var learnpath $lp */
+ $lp = isset($_SESSION['oLP']) ? $_SESSION['oLP'] : null;
+
+ if (!empty($lp)) {
+ $lp->set_modified_on();
+ $lpItem = new learnpathItem($lpItemId);
+ $lpItem->add_audio_from_documents($newDocId);
+ }
+ }
+}
\ No newline at end of file
diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php
index dcf1414937..cbc2d37878 100644
--- a/main/newscorm/learnpath.class.php
+++ b/main/newscorm/learnpath.class.php
@@ -2080,13 +2080,23 @@ class learnpath
$audio = $row['audio'];
- $file = '../../courses/'.$courseInfo['path'].'/document/audio/'.$audio;
+ $file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$audio;
+ $url = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$audio;
if (!file_exists($file)) {
$lpPathInfo = $_SESSION['oLP']->generate_lp_folder(api_get_course_info());
- $file = '../../courses/'.$_course['path'].'/document'.$lpPathInfo['dir'].$audio;
- }
-
- $player = Display::getMediaPlayer($file, array('id' => 'lp_audio_media_player', 'autoplay' => $autostart_audio, 'width' => '100%'));
+ $file = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$audio;
+ $url = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$audio;
+ }
+
+ $player = Display::getMediaPlayer(
+ $file,
+ array(
+ 'id' => 'lp_audio_media_player',
+ 'url' => $url,
+ 'autoplay' => $autostart_audio,
+ 'width' => '100%'
+ )
+ );
// The mp3 player.
$output = '
';
@@ -2317,7 +2327,13 @@ class learnpath
}
}
- public function get_preview_image_path($size = null, $path_type = 'web') {
+ /**
+ * @param string $size
+ * @param string $path_type
+ * @return bool|string
+ */
+ public function get_preview_image_path($size = null, $path_type = 'web')
+ {
$preview_image = $this->get_preview_image();
if (isset($preview_image) && !empty($preview_image)) {
$image_sys_path = api_get_path(SYS_COURSE_PATH).$this->course_info['path'].'/upload/learning_path/images/';
@@ -4211,7 +4227,8 @@ class learnpath
* @param string Optional string giving the new image of this learnpath
* @return bool Returns true if theme name is not empty
*/
- public function set_preview_image($name = '') {
+ public function set_preview_image($name = '')
+ {
$course_id = api_get_course_int_id();
if ($this->debug > 0) {
error_log('New LP - In learnpath::set_preview_image()', 0);
@@ -4224,7 +4241,7 @@ class learnpath
if ($this->debug > 2) {
error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
}
- $res = Database::query($sql);
+ Database::query($sql);
return true;
}
@@ -4250,7 +4267,7 @@ class learnpath
}
/**
* Sets the hide_toc_frame parameter of a LP (and save)
- * @param int 1 if frame is hiddent 0 thenelse
+ * @param int 1 if frame is hidden 0 then else
* @return bool Returns true if author's name is not empty
*/
public function set_hide_toc_frame($hide) {
@@ -5061,7 +5078,8 @@ class learnpath
if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
$audio .= '
';
if (!empty ($arrLP[$i]['audio'])) {
- $audio .= '
'.Security::remove_XSS($arrLP[$i]['audio']).'
' . get_lang('RemoveAudio');
+ $audio .= '
'.Security::remove_XSS($arrLP[$i]['audio']).'
+
' . get_lang('RemoveAudio');
}
}
}
@@ -5165,7 +5183,6 @@ class learnpath
}
$return .= '
';
-
$return .= '
';
$return .=''.$this->name.'
';
diff --git a/main/newscorm/lp_add_audio.php b/main/newscorm/lp_add_audio.php
index 716c897814..ad2d93148d 100644
--- a/main/newscorm/lp_add_audio.php
+++ b/main/newscorm/lp_add_audio.php
@@ -22,7 +22,6 @@ $isStudentView = (int) $_REQUEST['isStudentView'];
$learnpath_id = (int) $_REQUEST['lp_id'];
$submit = $_POST['submit_button'];
-
$type = isset($_GET['type']) ? $_GET['type'] : null;
$action = isset($_GET['action']) ? $_GET['action'] : null;
@@ -82,13 +81,16 @@ $tpl = new Template($tool_name);
$form = new FormValidator('add_audio', 'post', api_get_self().'?action=add_audio&id='.$lp_item_id, null, array('enctype' => 'multipart/form-data'));
$suredel = trim(get_lang('AreYouSureToDelete'));
-$file = null;
$lpPathInfo = $_SESSION['oLP']->generate_lp_folder(api_get_course_info());
+$file = null;
if (isset($lp_item->audio) && !empty($lp_item->audio)) {
- $file = '../../courses/'.$_course['path'].'/document/audio/'.$lp_item->audio;
+ $file = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/audio/'.$lp_item->audio;
+ $urlFile = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/audio/'.$lp_item->audio;
+
if (!file_exists($file)) {
- $file = '../../courses/'.$_course['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio;
+ $file = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio;
+ $urlFile = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio;
}
}
@@ -101,16 +103,26 @@ $page .= $_SESSION['oLP']->return_new_tree(null, true);
$page .= '
';
$page .= '
+
+
-