'; $is_allowed_to_edit = api_is_allowed_to_edit(null, true); // Please, do not modify this dirname formatting if (strstr($dir, '..')) { $dir = '/'; } if ($dir[0] == '.') { $dir = substr($dir, 1); } if ($dir[0] != '/') { $dir = '/'.$dir; } if ($dir[strlen($dir) - 1] != '/') { $dir .= '/'; } $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir; if (!is_dir($filepath)) { $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/'; $dir = '/'; } //groups //TODO: clean if (isset ($_SESSION['_gid']) && $_SESSION['_gid'] != 0) { $req_gid = '&gidReq='.$_SESSION['_gid']; $interbreadcrumb[] = array( "url" => "../group/group_space.php?gidReq=".$_SESSION['_gid'], "name" => get_lang('GroupSpace') ); $noPHP_SELF = true; $to_group_id = $_SESSION['_gid']; $group = GroupManager :: get_group_properties($to_group_id); $path = explode('/', $dir); if ('/'.$path[1] != $group['directory']) { api_not_allowed(true); } } $interbreadcrumb[] = array( "url" => "./document.php?curdirpath=".urlencode($dir).$req_gid, "name" => get_lang('Documents') ); if (!($is_allowed_to_edit || $_SESSION['group_member_with_upload_rights'] || is_my_shared_folder( api_get_user_id(), Security::remove_XSS($dir), api_get_session_id() )) ) { api_not_allowed(true); } /* Header */ event_access_tool(TOOL_DOCUMENT); $display_dir = $dir; if (isset ($group)) { $display_dir = explode('/', $dir); unset ($display_dir[0]); unset ($display_dir[1]); $display_dir = implode('/', $display_dir); } // Interbreadcrumb for the current directory root path // Copied from document.php $dir_array = explode('/', $dir); $array_len = count($dir_array); $dir_acum = ''; for ($i = 0; $i < $array_len; $i++) { $url_dir = 'document.php?&curdirpath='.$dir_acum.$dir_array[$i]; //Max char 80 $url_to_who = Text::cut($dir_array[$i], 80); if ($is_certificate_mode) { $interbreadcrumb[] = array( 'url' => $url_dir.'&selectcat='.Security::remove_XSS($_GET['selectcat']), 'name' => $url_to_who ); } else { $interbreadcrumb[] = array('url' => $url_dir, 'name' => $url_to_who); } $dir_acum .= $dir_array[$i].'/'; } Display :: display_header($nameTools, 'Doc'); echo '
'; echo ''.Display::return_icon( 'back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'), '', ICON_SIZE_MEDIUM ).''; echo ''.Display::return_icon( 'google.png', get_lang('GoogleAudio'), '', ICON_SIZE_MEDIUM ).''; echo ''.Display::return_icon( 'pediaphon.png', get_lang('Pediaphon'), '', ICON_SIZE_MEDIUM ).''; echo '
'; ?>

'.$icon.get_lang('HelpText2Audio').'

'; if (Security::remove_XSS($_GET['dt2a']) == 'google') { $selected_language = api_get_language_isocode(); //lang default is the course language echo '
'; $form = new FormValidator('form1', 'post', null, '', array('id' => 'form1')); $form->addElement('hidden', 'text2voice_mode', 'google'); $form->addElement('hidden', 'document_id', $document_id); $form->addElement('text', 'title', get_lang('Title')); $form->addElement('select', 'lang', get_lang('Language'), $options); $form->addElement( 'textarea', 'text', get_lang('InsertText2Audio'), array('id' => 'textarea_google', 'class' => 'span6') ); //echo Display :: return_icon('info3.gif', get_lang('HelpGoogleAudio'), array('align' => 'absmiddle', 'hspace' => '3px'), false); $form->addElement('style_submit_button', 'submit', get_lang('SaveMP3'), 'class="save"'); $defaults = array(); $defaults['lang'] = $selected_language; $form->setDefaults($defaults); $form->display(); echo '
'; } if (Security::remove_XSS($_GET['dt2a']) == 'pediaphon') { //lang default is a default message $selected_language = "defaultmessage"; $options['defaultmessage'] = get_lang('FirstSelectALanguage'); echo '
'; $form = new FormValidator('form2', 'post', null, '', array('id' => 'form2')); $form->addElement('hidden', 'text2voice_mode', 'pediaphon'); $form->addElement('hidden', 'document_id', $document_id); $form->addElement('text', 'title', get_lang('Title')); $form->addElement( 'select', 'lang', get_lang('Language'), $options_pedia, array('onclick' => 'update_voices(this.selectedIndex);') ); $form->addElement('select', 'voices', get_lang('Voice'), array(get_lang('FirstSelectALanguage')), array()); $speed_options = array(); $speed_options['1'] = get_lang('Normal'); $speed_options['0.75'] = get_lang('GoFaster'); $speed_options['0.8'] = get_lang('Fast'); $speed_options['1.2'] = get_lang('Slow'); $speed_options['1.6'] = get_lang('SlowDown'); $form->addElement('select', 'speed', get_lang('Speed'), $speed_options, array()); $form->addElement( 'textarea', 'text', get_lang('InsertText2Audio'), array('id' => 'textarea_pediaphon', 'class' => 'span6') ); //echo Display :: return_icon('info3.gif', get_lang('HelpPediaphon'), array('align' => 'absmiddle', 'hspace' => '3px'), false); $form->addElement('style_submit_button', 'submit', get_lang('SaveMP3'), 'class="save"'); $defaults = array(); $defaults['lang'] = $selected_language; $form->setDefaults($defaults); $form->display(); echo '
'; ?>   '.get_lang('vozMe').' '.get_lang('vozMe').''; echo '   '; echo ''; */ echo ''; Display :: display_footer(); //Functions. TODO:all at one /** * This function save a post into a file mp3 from google services * * @param $filepath * @param $dir * @author Juan Carlos Raña Trabado * @version january 2011, chamilo 1.8.8 */ function downloadMP3_google($filepath, $dir) { $location = 'create_audio.php?'.api_get_cidreq().'&id='.Security::remove_XSS($_POST['document_id']).'&dt2a=google'; //security if (!isset($_POST['lang']) && !isset($_POST['text']) && !isset($_POST['title']) && !isset($filepath) && !isset($dir)) { echo ''; return; } global $_course, $_user; $clean_title = trim($_POST['title']); $clean_text = trim($_POST['text']); if (empty($clean_title) || empty($clean_text)) { echo ''; return; } $clean_title = Security::remove_XSS($clean_title); $clean_title = Database::escape_string($clean_title); $clean_title = str_replace(' ', '_', $clean_title); //compound file names $clean_text = Security::remove_XSS($clean_text); $clean_lang = Security::remove_XSS($_POST['lang']); $extension = 'mp3'; $audio_filename = $clean_title.'.'.$extension; $audio_title = str_replace('_', ' ', $clean_title); //prevent duplicates if (file_exists($filepath.'/'.$clean_title.'.'.$extension)) { $i = 1; while (file_exists($filepath.'/'.$clean_title.'_'.$i.'.'.$extension)) { $i++; } $audio_filename = $clean_title.'_'.$i.'.'.$extension; $audio_title = $clean_title.'_'.$i.'.'.$extension; $audio_title = str_replace('_', ' ', $audio_title); } $documentPath = $filepath.'/'.$audio_filename; //prev for a fine unicode, borrowed from main api TODO:clean // Safe replacements for some non-letter characters (whitout blank spaces) $search = array( "\0", "\t", "\n", "\r", "\x0B", '/', "\\", '"', "'", '?', '*', '>', '<', '|', ':', '$', '(', ')', '^', '[', ']', '#', '+', '&', '%' ); $replace = array( '', '_', '_', '_', '_', '-', '-', '-', '_', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ); $filename = $clean_text; // Encoding detection. $encoding = api_detect_encoding($filename); // Converting html-entities into encoded characters. $filename = api_html_entity_decode($filename, ENT_QUOTES, $encoding); // Transliteration to ASCII letters, they are not dangerous for filesystems. $filename = api_transliterate($filename, 'x', $encoding); // Replacing remaining dangerous non-letter characters. $clean_text = str_replace($search, $replace, $filename); $returntext2voice = file_get_contents( "http://translate.google.com/translate_tts?tl=".$clean_lang."&q=".urlencode($clean_text)."" ); //make a temporal file for get the file size $tmpfname = tempnam("/tmp", "CTF"); $handle = fopen($tmpfname, "w"); fwrite($handle, $returntext2voice); fclose($handle); // Check if there is enough space in the course to save the file if (!DocumentManager::enough_space(filesize($tmpfname), DocumentManager::get_course_quota())) { unlink($tmpfname); die(get_lang('UplNotEnoughSpace')); } //erase temporal file unlink($tmpfname); //adding the file //add new file to disk file_put_contents($documentPath, $returntext2voice); //add document to database $current_session_id = api_get_session_id(); $groupId = $_SESSION['_gid']; $file_size = filesize($documentPath); $relativeUrlPath = $dir; $doc_id = FileManager::add_document( $_course, $relativeUrlPath.$audio_filename, 'file', filesize($documentPath), $audio_title ); api_item_property_update( $_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id ); Display::display_confirmation_message(get_lang('DocumentCreated')); //return to location echo ''; } /** * This function save a post into a file mp3 from pediaphon services * * @param $filepath * @param $dir * @author Juan Carlos Raña Trabado * @version january 2011, chamilo 1.8.8 */ function downloadMP3_pediaphon($filepath, $dir) { $location = 'create_audio.php?'.api_get_cidreq().'&id='.Security::remove_XSS( $_POST['document_id'] ).'&dt2a=pediaphon'; //security if (!isset($_POST['lang']) && !isset($_POST['text']) && !isset($_POST['title']) && !isset($filepath) && !isset($dir)) { echo ''; return; } global $_course, $_user; $clean_title = trim($_POST['title']); $clean_title = Database::escape_string($clean_title); $clean_text = trim($_POST['text']); $clean_voices = Security::remove_XSS($_POST['voices']); if (empty($clean_title) || empty($clean_text) || empty($clean_voices)) { echo ''; return; } $clean_title = Security::remove_XSS($clean_title); $clean_title = Database::escape_string($clean_title); $clean_title = str_replace(' ', '_', $clean_title); //compound file names $clean_text = Security::remove_XSS($clean_text); $clean_lang = Security::remove_XSS($_POST['lang']); $clean_speed = Security::remove_XSS($_POST['speed']); $extension = 'mp3'; $audio_filename = $clean_title.'.'.$extension; $audio_title = str_replace('_', ' ', $clean_title); //prevent duplicates if (file_exists($filepath.'/'.$clean_title.'.'.$extension)) { $i = 1; while (file_exists($filepath.'/'.$clean_title.'_'.$i.'.'.$extension)) { $i++; } $audio_filename = $clean_title.'_'.$i.'.'.$extension; $audio_title = $clean_title.'_'.$i.'.'.$extension; $audio_title = str_replace('_', ' ', $audio_title); } $documentPath = $filepath.'/'.$audio_filename; //prev for a fine unicode, borrowed from main api TODO:clean // Safe replacements for some non-letter characters (whitout blank spaces) $search = array( "\0", "\t", "\n", "\r", "\x0B", '/', "\\", '"', "'", '?', '*', '>', '<', '|', ':', '$', '(', ')', '^', '[', ']', '#', '+', '&', '%' ); $replace = array( '', '_', '_', '_', '_', '-', '-', '-', '_', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' ); $filename = $clean_text; // Encoding detection. $encoding = api_detect_encoding($filename); // Converting html-entities into encoded characters. $filename = api_html_entity_decode($filename, ENT_QUOTES, $encoding); // Transliteration to ASCII letters, they are not dangerous for filesystems. $filename = api_transliterate($filename, 'x', $encoding); // Replacing remaining dangerous non-letter characters. $clean_text = str_replace($search, $replace, $filename); //adding the file if ($clean_lang == 'de') { $url_pediaphon = 'http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice.cgi'; $find_t2v = '/http\:\/\/www\.pediaphon\.org\/\~bischoff\/radiopedia\/mp3\/(.*)\.mp3\"/'; } else { $url_pediaphon = 'http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice_'.$clean_lang.'.cgi'; //en, es, fr $find_t2v = '/http\:\/\/www\.pediaphon\.org\/\~bischoff\/radiopedia\/mp3\/'.$clean_lang.'\/(.*)\.mp3\"/'; } $data = "stimme=".$clean_voices."&inputtext=".$clean_text."&speed=".$clean_speed."&go=go"; $opts = array( 'http' => array( 'method' => 'POST', 'header' => "Content-Type: application/x-www-form-urlencoded\r\n", "Content-Length: ".strlen($data)."\r\n", 'content' => $data ) ); $context = stream_context_create($opts); $previous_returntext2voice = file_get_contents($url_pediaphon, false, $context); //clean file contents $search_source = preg_match($find_t2v, $previous_returntext2voice, $hits); $souce_end = substr($hits[0], 0, -1); $returntext2voice = file_get_contents($souce_end); //make a temporal file for get the file size $tmpfname = tempnam("/tmp", "CTF"); $handle = fopen($tmpfname, "w"); fwrite($handle, $returntext2voice); fclose($handle); // Check if there is enough space in the course to save the file if (!DocumentManager::enough_space(filesize($tmpfname), DocumentManager::get_course_quota())) { unlink($tmpfname); die(get_lang('UplNotEnoughSpace')); } //erase temporal file unlink($tmpfname); //save file file_put_contents($documentPath, $returntext2voice); //add document to database $current_session_id = api_get_session_id(); $groupId = $_SESSION['_gid']; $file_size = filesize($documentPath); $relativeUrlPath = $dir; $doc_id = FileManager::add_document( $_course, $relativeUrlPath.$audio_filename, 'file', filesize($documentPath), $audio_title ); api_item_property_update( $_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id ); Display::display_confirmation_message(get_lang('DocumentCreated')); //return to location echo ''; }