Should fix error while loading wav files using the LP tool BT#8157

1.9.x
Julio Montoya 11 years ago
parent 347df91ac3
commit a98ab8c51f
  1. 1
      main/course_home/course_home.php
  2. 10
      main/document/document.php
  3. 48
      main/document/showinframes.php
  4. 19
      main/inc/lib/display.lib.php
  5. 59
      main/inc/lib/document.lib.php
  6. 37
      main/inc/lib/nanogong.lib.php
  7. 15
      main/newscorm/learnpath.class.php
  8. 8
      main/newscorm/lp_add_audio.php
  9. 1
      main/newscorm/lp_list.php

@ -268,3 +268,4 @@ $tpl->assign('course_code', $course_code);
$tpl->display_one_col_template();
Session::erase('_gid');
DocumentManager::removeGeneratedAudioTempFile();

@ -48,18 +48,14 @@ require_once $lib_path.'fileManage.lib.php';
api_protect_course_script(true);
//erase temp nanogons' audio, image edit
if (isset($_SESSION['temp_audio_nanogong'])
&& !empty($_SESSION['temp_audio_nanogong'])
&& is_file($_SESSION['temp_audio_nanogong'])) {
unlink($_SESSION['temp_audio_nanogong']);
}
DocumentManager::removeGeneratedAudioTempFile();
if (isset($_SESSION['temp_realpath_image'])
&& !empty($_SESSION['temp_realpath_image'])
&& is_file($_SESSION['temp_realpath_image'])) {
unlink($_SESSION['temp_realpath_image']);
}
$courseInfo = api_get_course_info();
$course_dir = $courseInfo['directory'].'/document';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
@ -1516,7 +1512,7 @@ if (isset($documentAndFolders) && is_array($documentAndFolders)) {
$row = array();
$row['id'] = $document_data['id'];
$row['type'] = $document_data['filetype'];
// If the item is invisible, wrap it in a span with class invisible.
$is_visible = DocumentManager::is_visible_by_id(
$document_data['id'],

@ -64,7 +64,6 @@ $path_array = array_map('urldecode', $path_array);
$header_file = implode('/', $path_array);
$file = Security::remove_XSS(urldecode($document_data['path']));
$file_root = $course_info['path'].'/document'.str_replace('%2F', '/', $file);
$file_url_sys = api_get_path(SYS_COURSE_PATH).$file_root;
$file_url_web = api_get_path(WEB_COURSE_PATH).$file_root;
@ -377,49 +376,16 @@ if ($is_freemind_available) {
if ($is_nanogong_available) {
//make temp audio
$temp_folder=api_get_path(SYS_ARCHIVE_PATH).'temp/audio';
if (!file_exists($temp_folder)) {
@mkdir($temp_folder, api_get_permissions_for_new_directories(), true);
}
//make htaccess with allow from all, and file index.html into temp/audio
$htaccess = api_get_path(SYS_ARCHIVE_PATH).'temp/audio/.htaccess';
if (!file_exists($htaccess)) {
$htaccess_content="order deny,allow\r\nallow from all\r\nOptions -Indexes";
$fp = @ fopen(api_get_path(SYS_ARCHIVE_PATH).'temp/audio/.htaccess', 'w');
if ($fp) {
fwrite($fp, $htaccess_content);
fclose($fp);
}
}
//encript temp name file
$name_crip = sha1(uniqid());//encript
$findext= explode(".", $file);
$extension= $findext[count($findext)-1];
$file_crip=$name_crip.'.'.$extension;
$file_url_web = DocumentManager::generateAudioTempFolder($file_url_sys);
//copy file to temp/audio directory
$from_sys=$file_url_sys;
$to_sys=api_get_path(SYS_ARCHIVE_PATH).'temp/audio/'.$file_crip;
if (file_exists($from_sys)) {
copy($from_sys, $to_sys);
}
//get file from tmp directory
$to_url = api_get_path(WEB_ARCHIVE_PATH).'temp/audio/'.$file_crip;
echo '<div align="center">';
echo '<a class="btn" href="'.$file_url_web.'" target="_blank">'.get_lang('Download').'</a>';
echo '<br/>';
echo '<br/>';
echo '<div align="center">';
echo '<a class="btn" href="'.$file_url_web.'" target="_blank">'.get_lang('Download').'</a>';
echo '<br/>';
echo '<br/>';
echo DocumentManager::readNanogongFile($to_url);
echo DocumentManager::readNanogongFile($to_url);
//erase temp file in tmp directory when return to documents
$_SESSION['temp_audio_nanogong']=$to_sys;
//erase temp file in tmp directory when return to documents
echo '</div>';
}

@ -1205,6 +1205,7 @@ class Display
$notifications = array();
// Filter all last edits of all tools of the course
while ($res && ($item_property = Database::fetch_array($res))) {
// First thing to check is if the user never entered the tool
// or if his last visit was earlier than the last modification.
if ((!isset($lastTrackInCourseDate[$item_property['tool']])
@ -1217,12 +1218,15 @@ class Display
&& $item_property['tool'] != TOOL_NOTEBOOK
&& $item_property['tool'] != TOOL_CHAT)
)
)
)
// Take only what's visible or "invisible but where the user is a teacher" or where the visibility is unset.
&& ($item_property['visibility'] == '1'
|| ($course_info['status'] == '1' && $item_property['visibility'] == '0')
|| !isset($item_property['visibility'])))
{
|| !isset($item_property['visibility']))
) {
if ($course_info['real_id'] == 1) {
// var_dump($item_property);
}
// Also drop announcements and events that are not for the user or his group.
if (($item_property['tool'] == TOOL_ANNOUNCEMENT
|| $item_property['tool'] == TOOL_CALENDAR_EVENT)
@ -1250,6 +1254,12 @@ class Display
$notifications[$item_property['tool']] = $item_property;
}
}
if ($course_info['real_id'] == 1) {
/*var_dump($notifications);
exit;*/
}
// Show all tool icons where there is something new.
$retvalue = '&nbsp;';
while (list($key, $notification) = each($notifications)) {
@ -1715,7 +1725,8 @@ class Display
switch ($fileInfo['extension']) {
case 'wav':
if (isset($params['url'])) {
return DocumentManager::readNanogongFile($params['url']);
$url = DocumentManager::generateAudioTempFile(basename($file), $file);
return DocumentManager::readNanogongFile($url);
}
break;
case 'mp3':

@ -3899,7 +3899,6 @@ class DocumentManager
public static function readNanogongFile($file)
{
$nanoGongJarFile = api_get_path(WEB_LIBRARY_PATH).'nanogong/nanogong.jar';
$html = '<applet id="applet" archive="'.$nanoGongJarFile.'" code="gong.NanoGong" width="160" height="95">';
$html .= '<param name="SoundFileURL" value="'.$file.'" />';
$html .= '<param name="ShowSaveButton" value="false" />';
@ -4026,4 +4025,62 @@ class DocumentManager
return false;
}
/**
* @param string $file ($document_data['path'])
* @param string $file_url_sys
* @return string
*/
public static function generateAudioTempFile($file, $file_url_sys)
{
//make temp audio
$temp_folder = api_get_path(SYS_ARCHIVE_PATH).'temp/audio';
if (!file_exists($temp_folder)) {
@mkdir($temp_folder, api_get_permissions_for_new_directories(), true);
}
//make htaccess with allow from all, and file index.html into temp/audio
$htaccess = api_get_path(SYS_ARCHIVE_PATH).'temp/audio/.htaccess';
if (!file_exists($htaccess)) {
$htaccess_content="order deny,allow\r\nallow from all\r\nOptions -Indexes";
$fp = @ fopen(api_get_path(SYS_ARCHIVE_PATH).'temp/audio/.htaccess', 'w');
if ($fp) {
fwrite($fp, $htaccess_content);
fclose($fp);
}
}
//encript temp name file
$name_crip = sha1(uniqid());//encript
$findext= explode(".", $file);
$extension = $findext[count($findext)-1];
$file_crip = $name_crip.'.'.$extension;
//copy file to temp/audio directory
$from_sys = $file_url_sys;
$to_sys = api_get_path(SYS_ARCHIVE_PATH).'temp/audio/'.$file_crip;
if (file_exists($from_sys)) {
copy($from_sys, $to_sys);
}
//get file from tmp directory
$_SESSION['temp_audio_nanogong'] = $to_sys;
return api_get_path(WEB_ARCHIVE_PATH).'temp/audio/'.$file_crip;
}
/**
* Erase temp nanogons' audio, image edit
*/
public static function removeGeneratedAudioTempFile()
{
if (isset($_SESSION['temp_audio_nanogong'])
&& !empty($_SESSION['temp_audio_nanogong'])
&& is_file($_SESSION['temp_audio_nanogong'])) {
unlink($_SESSION['temp_audio_nanogong']);
unset($_SESSION['temp_audio_nanogong']);
}
}
}

@ -230,18 +230,22 @@ class Nanogong
}
}
//temp_exe
// temp_exe
if ($load_from_database) {
//Load the real filename just if exists
if (isset($this->params['exe_id']) && isset($this->params['user_id']) && isset($this->params['question_id']) && isset($this->params['session_id']) && isset($this->params['course_id'])) {
if (isset($this->params['exe_id']) && isset($this->params['user_id']) &&
isset($this->params['question_id']) && isset($this->params['session_id']) && isset($this->params['course_id'])
) {
$attempt_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$sql = "SELECT filename FROM $attempt_table
WHERE exe_id = ".$this->params['exe_id']." AND
user_id = ".$this->params['user_id']." AND
question_id = ".$this->params['question_id']." AND
session_id = ".$this->params['session_id']." AND
course_code = '".$this->course_info['code']."' LIMIT 1";
WHERE
exe_id = ".$this->params['exe_id']." AND
user_id = ".$this->params['user_id']." AND
question_id = ".$this->params['question_id']." AND
session_id = ".$this->params['session_id']." AND
course_code = '".$this->course_info['code']."'
LIMIT 1";
$result = Database::query($sql);
$result = Database::fetch_row($result,'ASSOC');
@ -254,6 +258,7 @@ class Nanogong
if (is_file($this->store_path.$filename)) {
return $this->store_path.$filename;
}
return null;
}
@ -267,8 +272,8 @@ class Nanogong
*/
public function get_public_url($force_download = 0)
{
$params = $this->get_params(true);
$url = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=get_file&download='.$force_download.'&'.$params;
//$params = $this->get_params(true);
//$url = api_get_path(WEB_AJAX_PATH).'nanogong.ajax.php?a=get_file&download='.$force_download.'&'.$params;
$params = $this->get_params();
$filename = basename($this->load_filename_if_exists());
$url = api_get_path(WEB_COURSE_PATH).$this->course_info['path'].'/exercises/'.$params['session_id'].'/'.$params['exercise_id'].'/'.$params['question_id'].'/'.$params['user_id'].'/'.$filename;
@ -320,6 +325,7 @@ class Nanogong
}
}
}
return 0;
}
@ -364,7 +370,6 @@ class Nanogong
$html .= '<div class="action_player">'.$actions.'</div>';
$html .= '<div class="nanogong_player">';
$html .= '<applet id="nanogong_player" archive="'.api_get_path(WEB_LIBRARY_PATH).'nanogong/nanogong.jar" code="gong.NanoGong" width="250" height="95" ALIGN="middle">';
$html .= '<param name="ShowRecordButton" value="false" />'; // default true
$html .= '<param name="ShowSaveButton" value="false" />'; //you can save in local computer | (default true)
//echo '<param name="ShowAudioLevel" value="false" />'; // it displays the audiometer | (default true)
@ -375,7 +380,6 @@ class Nanogong
//echo '<param name="EndTime" value="65" />';
$html .= '<param name="AudioFormat" value="ImaADPCM" />';// ImaADPCM (more speed), Speex (more compression)|(default Speex)
//$html .= '<param name="AudioFormat" value="Speex" />';// ImaADPCM (more speed), Speex (more compression)|(default Speex)
//Quality for ImaADPCM (low 8000, medium 11025, normal 22050, hight 44100) OR Quality for Speex (low 8000, medium 16000, normal 32000, hight 44100) | (default 44100)
//echo '<param name="SamplingRate" value="32000" />';
//echo '<param name="MaxDuration" value="60" />';
@ -383,15 +387,10 @@ class Nanogong
$html .= '</applet>';
$html .= '</div>';
$html .= '</div>';
$html .= '<div id="nanogong_warning">'.Display::return_message(
get_lang('BrowserDoesNotSupportNanogongPlayer'),
'warning'
).$download_button.'</div>';
$html .= '<div id="nanogong_warning">'.Display::return_message(get_lang('BrowserDoesNotSupportNanogongPlayer'), 'warning').$download_button.'</div>';
} elseif(in_array($path_info['extension'],array('mp3', 'ogg','wav'))) {
$js_path = api_get_path(WEB_LIBRARY_PATH).'javascript/';
$js_path = api_get_path(WEB_LIBRARY_PATH).'javascript/';
$html .= '<link rel="stylesheet" href="'.$js_path.'jquery-jplayer/skins/blue/jplayer.blue.monday.css" type="text/css">';
//$html .= '<link rel="stylesheet" href="' . $js_path . 'jquery-jplayer/skins/chamilo/jplayer.blue.monday.css" type="text/css">';
$html .= '<script type="text/javascript" src="'.$js_path.'jquery-jplayer/jquery.jplayer.min.js"></script>';
@ -405,8 +404,6 @@ class Nanogong
'count'=> 1
);
$jquery = DocumentManager::generate_jplayer_jquery($params);
$html .= '<script>
$(document).ready( function() {
//Experimental changes to preview mp3, ogg files

@ -2117,10 +2117,12 @@ class learnpath
$tbl_lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
// Getting all the information about the item.
$sql = "SELECT * FROM ".$tbl_lp_item." as lp INNER JOIN ".$tbl_lp_item_view." as lp_view on lp.id = lp_view.lp_item_id ".
"WHERE lp.id = '".$_SESSION['oLP']->current."' AND
lp.c_id = $course_id AND
lp_view.c_id = $course_id";
$sql = "SELECT * FROM ".$tbl_lp_item." as lp
INNER JOIN ".$tbl_lp_item_view." as lp_view on lp.id = lp_view.lp_item_id
WHERE
lp.id = '".$_SESSION['oLP']->current."' AND
lp.c_id = $course_id AND
lp_view.c_id = $course_id";
$result = Database::query($sql);
$row = Database::fetch_assoc($result);
$output = '';
@ -2151,11 +2153,12 @@ class learnpath
$audio = $row['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;
$url = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$audio.'?'.api_get_cidreq();
if (!file_exists($file)) {
$lpPathInfo = $_SESSION['oLP']->generate_lp_folder(api_get_course_info());
$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;
$url = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$audio.'?'.api_get_cidreq();
}
$player = Display::getMediaPlayer(

@ -86,11 +86,11 @@ $lpPathInfo = $_SESSION['oLP']->generate_lp_folder(api_get_course_info());
$file = null;
if (isset($lp_item->audio) && !empty($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;
$urlFile = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/audio/'.$lp_item->audio.'?'.api_get_cidreq();
if (!file_exists($file)) {
$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;
$urlFile = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio.'?'.api_get_cidreq();
}
}
@ -127,7 +127,9 @@ if (!empty($file)) {
$form->addElement('hidden', 'id', $lp_item_id);
if (!empty($file)) {
$audioPlayer = '<div id="preview">'.Display::getMediaPlayer($file, array('url' => $urlFile))."</div>";
$audioPlayer = '<div id="preview">'.
Display::getMediaPlayer($file, array('url' => $urlFile)).
"</div>";
$form->addElement('label', get_lang('Preview'), $audioPlayer);
}

@ -459,4 +459,5 @@ learnpath::generate_learning_path_folder($course_info);
//Deleting the objects
Session::erase('oLP');
Session::erase('lpobject');
DocumentManager::removeGeneratedAudioTempFile();
Display::display_footer();

Loading…
Cancel
Save