create_audio.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file allows creating audio files from a text.
  5. *
  6. * @package chamilo.document
  7. *
  8. * @author Juan Carlos Raña Trabado
  9. * @since 8/January/2011
  10. * TODO:clean all file
  11. */
  12. /**
  13. * Code
  14. */
  15. /* INIT SECTION */
  16. $language_file = array('document');
  17. require_once '../inc/global.inc.php';
  18. $_SESSION['whereami'] = 'document/createaudio';
  19. $this_section = SECTION_COURSES;
  20. require_once 'document.inc.php';
  21. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  22. $nameTools = get_lang('CreateAudio');
  23. api_protect_course_script();
  24. api_block_anonymous_users();
  25. if (api_get_setting('enabled_text2audio') == 'false'){
  26. api_not_allowed(true);
  27. }
  28. $document_data = DocumentManager::get_document_data_by_id($_GET['id'], api_get_course_id());
  29. if (empty($document_data)) {
  30. if (api_is_in_group()) {
  31. $group_properties = GroupManager::get_group_properties(api_get_group_id());
  32. $document_id = DocumentManager::get_document_id(api_get_course_info(), $group_properties['directory']);
  33. $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
  34. }
  35. }
  36. $document_id = $document_data['id'];
  37. $dir = $document_data['path'];
  38. //jquery textareaCounter
  39. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/textareacounter/jquery.textareaCounter.plugin.js" type="text/javascript"></script>';
  40. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  41. // Please, do not modify this dirname formatting
  42. if (strstr($dir, '..')) {
  43. $dir = '/';
  44. }
  45. if ($dir[0] == '.') {
  46. $dir = substr($dir, 1);
  47. }
  48. if ($dir[0] != '/') {
  49. $dir = '/'.$dir;
  50. }
  51. if ($dir[strlen($dir) - 1] != '/') {
  52. $dir .= '/';
  53. }
  54. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
  55. if (!is_dir($filepath)) {
  56. $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
  57. $dir = '/';
  58. }
  59. //groups //TODO: clean
  60. if (isset ($_SESSION['_gid']) && $_SESSION['_gid'] != 0) {
  61. $req_gid = '&amp;gidReq='.$_SESSION['_gid'];
  62. $interbreadcrumb[] = array ("url" => "../group/group_space.php?gidReq=".$_SESSION['_gid'], "name" => get_lang('GroupSpace'));
  63. $noPHP_SELF = true;
  64. $to_group_id = $_SESSION['_gid'];
  65. $group = GroupManager :: get_group_properties($to_group_id);
  66. $path = explode('/', $dir);
  67. if ('/'.$path[1] != $group['directory']) {
  68. api_not_allowed(true);
  69. }
  70. }
  71. $interbreadcrumb[] = array ("url" => "./document.php?curdirpath=".urlencode($dir).$req_gid, "name" => get_lang('Documents'));
  72. if (!$is_allowed_in_course) {
  73. api_not_allowed(true);
  74. }
  75. 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()))) {
  76. api_not_allowed(true);
  77. }
  78. /* Header */
  79. event_access_tool(TOOL_DOCUMENT);
  80. $display_dir = $dir;
  81. if (isset ($group)) {
  82. $display_dir = explode('/', $dir);
  83. unset ($display_dir[0]);
  84. unset ($display_dir[1]);
  85. $display_dir = implode('/', $display_dir);
  86. }
  87. // Interbreadcrumb for the current directory root path
  88. // Copied from document.php
  89. $dir_array = explode('/', $dir);
  90. $array_len = count($dir_array);
  91. $dir_acum = '';
  92. for ($i = 0; $i < $array_len; $i++) {
  93. $url_dir = 'document.php?&curdirpath='.$dir_acum.$dir_array[$i];
  94. //Max char 80
  95. $url_to_who = cut($dir_array[$i],80);
  96. if ($is_certificate_mode) {
  97. $interbreadcrumb[] = array('url' => $url_dir.'&selectcat='.Security::remove_XSS($_GET['selectcat']), 'name' => $url_to_who);
  98. } else {
  99. $interbreadcrumb[] = array('url' => $url_dir, 'name' => $url_to_who);
  100. }
  101. $dir_acum .= $dir_array[$i].'/';
  102. }
  103. Display :: display_header($nameTools, 'Doc');
  104. echo '<div class="actions">';
  105. echo '<a href="document.php?id='.$document_id.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).'</a>';
  106. echo '<a href="create_audio.php?'.api_get_cidreq().'&amp;id='.$document_id.'&amp;dt2a=google">'.Display::return_icon('google.png',get_lang('GoogleAudio'),'',ICON_SIZE_MEDIUM).'</a>';
  107. echo '<a href="create_audio.php?'.api_get_cidreq().'&amp;id='.$document_id.'&amp;dt2a=pediaphon">'.Display::return_icon('pediaphon.png', get_lang('Pediaphon'),'',ICON_SIZE_MEDIUM).'</a>';
  108. echo '</div>';
  109. ?>
  110. <!-- javascript and styles for textareaCounter-->
  111. <script type="text/javascript">
  112. var info;
  113. $(document).ready(function(){
  114. var options = {
  115. 'maxCharacterSize': 100,
  116. 'originalStyle': 'originalTextareaInfo',
  117. 'warningStyle' : 'warningTextareaInfo',
  118. 'warningNumber': 20,
  119. 'displayFormat' : '#input/#max'
  120. };
  121. $('#textarea_google').textareaCount(options, function(data){
  122. $('#textareaCallBack').html(data);
  123. });
  124. });
  125. </script>
  126. <style>
  127. .overview {
  128. background: #FFEC9D;
  129. padding: 10px;
  130. width: 90%;
  131. border: 1px solid #CCCCCC;
  132. }
  133. .originalTextareaInfo {
  134. font-size: 12px;
  135. color: #000000;
  136. text-align: right;
  137. }
  138. .warningTextareaInfo {
  139. color: #FF0000;
  140. font-weight:bold;
  141. text-align: right;
  142. }
  143. #showData {
  144. height: 70px;
  145. width: 200px;
  146. border: 1px solid #CCCCCC;
  147. padding: 10px;
  148. margin: 10px;
  149. }
  150. </style>
  151. <div id="textareaCallBack"></div>
  152. <?php
  153. if(Security::remove_XSS($_POST['text2voice_mode'])=='google'){
  154. downloadMP3_google($filepath, $dir);
  155. }
  156. elseif(Security::remove_XSS($_POST['text2voice_mode'])=='pediaphon'){
  157. downloadMP3_pediaphon($filepath, $dir);
  158. }
  159. $tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
  160. $sql_select = "SELECT * FROM $tbl_admin_languages";
  161. $result_select = Database::query($sql_select);
  162. $options = $options_pedia = array();
  163. $selected_language = null;
  164. //$selected_language = api_get_language_isocode();//lang default is the course language
  165. //lang default is a default message
  166. $selected_language = "defaultmessage";
  167. $options_pedia['defaultmessage'] =get_lang('FirstSelectALanguage');
  168. $options['defaultmessage'] =get_lang('FirstSelectALanguage');
  169. while ($row = Database::fetch_array($result_select)) {
  170. if (api_get_setting('platformLanguage')==$row['english_name']) {
  171. //$selected_language = $row['isocode'];//lang default is the default platform language
  172. }
  173. $options[$row['isocode']] =$row['original_name'].' ('.$row['english_name'].')';
  174. if (in_array($row['isocode'], array('de', 'en', 'es', 'fr'))){
  175. $options_pedia[$row['isocode']] =$row['original_name'].' ('.$row['english_name'].')';
  176. }
  177. }
  178. $icon = Display::return_icon('text2audio.png', get_lang('HelpText2Audio'),'',ICON_SIZE_MEDIUM);
  179. echo '<div class="page-header"><h2>'.$icon.get_lang('HelpText2Audio').'</h2></div>';
  180. if(Security::remove_XSS($_GET['dt2a'])=='google'){
  181. echo '<div>';
  182. $form = new FormValidator('form1', 'post', null, '', array('id' => 'form1'));
  183. $form->addElement('hidden', 'text2voice_mode', 'google');
  184. $form->addElement('hidden', 'document_id', $document_id);
  185. $form->addElement('text', 'title', get_lang('Title'));
  186. $form->addElement('select', 'lang', get_lang('Language'), $options);
  187. $form->addElement('textarea', 'text', get_lang('InsertText2Audio'), array('id' => 'textarea_google', 'class' =>'span6' ));
  188. //echo Display :: return_icon('info3.gif', get_lang('HelpGoogleAudio'), array('align' => 'absmiddle', 'hspace' => '3px'), false);
  189. $form->addElement('style_submit_button', 'submit', get_lang('SaveMP3'), 'class="save"');
  190. $defaults = array();
  191. $defaults['lang'] = $selected_language;
  192. $form->setDefaults($defaults);
  193. $form->display();
  194. echo '</div>';
  195. }
  196. if(Security::remove_XSS($_GET['dt2a'])=='pediaphon'){
  197. echo '<div>';
  198. $form = new FormValidator('form2', 'post', null, '', array('id' => 'form2'));
  199. $form->addElement('hidden', 'text2voice_mode','pediaphon');
  200. $form->addElement('hidden', 'document_id', $document_id);
  201. $form->addElement('text', 'title', get_lang('Title'));
  202. $form->addElement('select', 'lang', get_lang('Language'), $options_pedia, array('onclick' => 'update_voices(this.selectedIndex);'));
  203. $form->addElement('select', 'voices', get_lang('Voice'), array(get_lang('FirstSelectALanguage')), array());
  204. $speed_options = array();
  205. $speed_options['1'] = get_lang('Normal');
  206. $speed_options['0.75'] = get_lang('GoFaster');
  207. $speed_options['0.8'] = get_lang('Fast');
  208. $speed_options['1.2'] = get_lang('Slow');
  209. $speed_options['1.6'] = get_lang('SlowDown');
  210. $form->addElement('select', 'speed', get_lang('Speed'), $speed_options, array());
  211. $form->addElement('textarea', 'text', get_lang('InsertText2Audio'), array('id' => 'textarea_pediaphon', 'class' =>'span6'));
  212. //echo Display :: return_icon('info3.gif', get_lang('HelpPediaphon'), array('align' => 'absmiddle', 'hspace' => '3px'), false);
  213. $form->addElement('style_submit_button', 'submit', get_lang('SaveMP3'), 'class="save"');
  214. $defaults = array();
  215. $defaults['lang'] = $selected_language;
  216. $form->setDefaults($defaults);
  217. $form->display();
  218. echo '</div>';
  219. ?>
  220. <!-- javascript form name form2 update voices -->
  221. <script type="text/javascript">
  222. var langslist=document.form2.lang
  223. var voiceslist=document.form2.voices
  224. var voices=new Array()
  225. <!--Default message -->
  226. voices[0]=["<?php echo get_lang('FirstSelectALanguage'); ?>"]
  227. <!--German -->
  228. voices[1]=["<?php echo get_lang('Female').' (de1)'; ?>|de1", "<?php echo get_lang('Male').' (de2)'; ?>|de2", "<?php echo get_lang('Female').' (de3)'; ?>|de3", "<?php echo get_lang('Male').' (de4)'; ?>|de4", "<?php echo get_lang('Female').' (de5)'; ?>|de5", "<?php echo get_lang('Male').' (de6)'; ?>|de6", "<?php echo get_lang('Female').' (de7)'; ?>|de7", "<?php echo get_lang('Female').' (de8 HQ)'; ?>|de8"]
  229. <!--English -->
  230. voices[2]=["<?php echo get_lang('Male').' (en1)'; ?>|en1", "<?php echo get_lang('Male').' (en2 HQ)'; ?>|en2", "<?php echo get_lang('Female').' (us1)'; ?>| us1", "<?php echo get_lang('Male').' (us2)'; ?>|us2", "<?php echo get_lang('Male').' (us3)'; ?>|us3", "<?php echo get_lang('Female').'(us4 HQ)'; ?>|us4"]
  231. <!--Spanish -->
  232. voices[3]=["<?php echo get_lang('Male').' (es5 HQ)'; ?>|es5"]
  233. <!--French -->
  234. voices[4]=["<?php echo get_lang('Female').' (fr8 HQ)'; ?>|fr8"]
  235. function update_voices(selectedvoicegroup){
  236. voiceslist.options.length=0
  237. for (i=0; i<voices[selectedvoicegroup].length; i++)
  238. voiceslist.options[voiceslist.options.length]=new Option(voices[selectedvoicegroup][i].split("|")[0], voices[selectedvoicegroup][i].split("|")[1])
  239. }
  240. </script>
  241. <?php
  242. }//end pediaphon
  243. //vozMe services
  244. //disabled for a time
  245. /*
  246. echo '<div>&nbsp;</div><input type="checkbox" value="1" name="checktext2voice" onclick="javascript: if(this.checked){document.getElementById(\'option3\').style.display=\'block\';}else{document.getElementById(\'option3\').style.display=\'none\';}"/>&nbsp;<img src="../img/file_sound.gif" title="'.get_lang('HelpvozMe').'" alt="'.get_lang('vozMe').'"/>&nbsp;'.get_lang('vozMe').'';
  247. echo '&nbsp;&nbsp;&nbsp;<span id="msg_error3" style="display:none;color:red"></span>';
  248. echo '<div id="option3" style="padding:4px; margin:5px; border:1px dotted; display:none;">';
  249. echo '<form id="form3" name="form3" method="post" action="http://vozme.com/text2voice.php" target="mymp3" class="formw">';
  250. echo '<br/>';
  251. echo '<label>'.get_lang('Language').': ';
  252. $tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
  253. $sql_select = "SELECT * FROM $tbl_admin_languages";
  254. $result_select = Database::query($sql_select);
  255. echo '<select name="lang" id="select">';
  256. while ($row = Database::fetch_array($result_select)) {
  257. if (in_array($row['isocode'], array('ca', 'en', 'es', 'hi', 'it', 'pt'))){
  258. if (api_get_setting('platformLanguage')==$row['english_name']){
  259. echo '<option value="'.$row['isocode'].'" selected="selected">'.$row['original_name'].' ('.$row['english_name'].')</option>';
  260. }
  261. else{
  262. echo '<option value="'.$row['isocode'].'">'.$row['original_name'].' ('.$row['english_name'].')</option>';
  263. }
  264. }
  265. }
  266. echo '</select>';
  267. echo '</label>';
  268. echo '<label>&nbsp;&nbsp;'.get_lang('Voice').': ';
  269. echo '<select name="gn" id="select1">';
  270. echo '<option value="ml">'.get_lang('Male').'</option>';
  271. echo '<option value="fm">'.get_lang('Female').'</option>';
  272. echo '</select>';
  273. echo '</label>';
  274. echo '<br/><br/>';
  275. echo '<div>'.get_lang('InsertText2Audio').'</div>';
  276. echo '<br/>';
  277. echo '<label>';
  278. echo '<textarea name="text" id="textarea" cols="70" rows="10"></textarea>';
  279. echo '</label>';
  280. echo '<br/><br/>';
  281. echo '<button class="save" type="submit" name="SendText2Audio">'.get_lang('BuildMP3').'</button>';
  282. echo '<br/>';
  283. echo '</form>';
  284. echo '</div>';
  285. */
  286. echo '</div>';
  287. Display :: display_footer();
  288. //Functions. TODO:all at one
  289. /**
  290. * This function save a post into a file mp3 from google services
  291. *
  292. * @param $filepath
  293. * @param $dir
  294. * @author Juan Carlos Raña Trabado <herodoto@telefonica.net>
  295. * @version january 2011, chamilo 1.8.8
  296. */
  297. function downloadMP3_google($filepath, $dir) {
  298. $location='create_audio.php?'.api_get_cidreq().'&id='.Security::remove_XSS($_POST['document_id']).'&dt2a=google';
  299. //security
  300. if (!isset($_POST['lang']) && !isset($_POST['text']) && !isset($_POST['title']) && !isset($filepath) && !isset($dir)) {
  301. echo '<script>window.location.href="'.$location.'"</script>';
  302. return;
  303. }
  304. global $_course, $_user;
  305. $clean_title=trim($_POST['title']);
  306. $clean_text=trim($_POST['text']);
  307. if(empty($clean_title) || empty($clean_text)){
  308. echo '<script>window.location.href="'.$location.'"</script>';
  309. return;
  310. }
  311. $clean_title=Security::remove_XSS($clean_title);
  312. $clean_title=Database::escape_string($clean_title);
  313. $clean_title=str_replace(' ','_', $clean_title);//compound file names
  314. $clean_text=Security::remove_XSS($clean_text);
  315. $clean_lang=Security::remove_XSS($_POST['lang']);
  316. $extension='mp3';
  317. $audio_filename=$clean_title.'.'.$extension;
  318. $audio_title = str_replace('_',' ',$clean_title);
  319. //prevent duplicates
  320. if (file_exists($filepath.'/'.$clean_title.'.'.$extension)){
  321. $i = 1;
  322. while (file_exists($filepath.'/'.$clean_title.'_'.$i.'.'.$extension)) $i++;
  323. $audio_filename = $clean_title . '_' . $i . '.'.$extension;
  324. $audio_title = $clean_title . '_' . $i . '.'.$extension;
  325. $audio_title = str_replace('_',' ',$audio_title);
  326. }
  327. $documentPath = $filepath.'/'.$audio_filename;
  328. //prev for a fine unicode, borrowed from main api TODO:clean
  329. // Safe replacements for some non-letter characters (whitout blank spaces)
  330. $search = array("\0", "\t", "\n", "\r", "\x0B", '/', "\\", '"', "'", '?', '*', '>', '<', '|', ':', '$', '(', ')', '^', '[', ']', '#', '+', '&', '%');
  331. $replace = array('', '_', '_', '_', '_', '-', '-', '-', '_', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-');
  332. $filename=$clean_text;
  333. // Encoding detection.
  334. $encoding = api_detect_encoding($filename);
  335. // Converting html-entities into encoded characters.
  336. $filename = api_html_entity_decode($filename, ENT_QUOTES, $encoding);
  337. // Transliteration to ASCII letters, they are not dangerous for filesystems.
  338. $filename = api_transliterate($filename, 'x', $encoding);
  339. // Replacing remaining dangerous non-letter characters.
  340. $clean_text = str_replace($search, $replace, $filename);
  341. //adding the file
  342. //add new file to disk
  343. file_put_contents($documentPath, file_get_contents("http://translate.google.com/translate_tts?tl=".$clean_lang."&q=".urlencode($clean_text).""));
  344. //add document to database
  345. $current_session_id = api_get_session_id();
  346. $groupId=$_SESSION['_gid'];
  347. $file_size = filesize($documentPath);
  348. $relativeUrlPath=$dir;
  349. $doc_id = add_document($_course, $relativeUrlPath.$audio_filename, 'file', filesize($documentPath), $audio_title);
  350. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id);
  351. Display::display_confirmation_message(get_lang('DocumentCreated'));
  352. //return to location
  353. echo '<script>window.location.href="'.$location.'"</script>';
  354. }
  355. /**
  356. * This function save a post into a file mp3 from pediaphon services
  357. *
  358. * @param $filepath
  359. * @param $dir
  360. * @author Juan Carlos Raña Trabado <herodoto@telefonica.net>
  361. * @version january 2011, chamilo 1.8.8
  362. */
  363. function downloadMP3_pediaphon($filepath, $dir){
  364. $location='create_audio.php?'.api_get_cidreq().'&id='.Security::remove_XSS($_POST['document_id']).'&dt2a=pediaphon';
  365. //security
  366. if(!isset($_POST['lang']) && !isset($_POST['text']) && !isset($_POST['title']) && !isset($filepath) && !isset($dir)) {
  367. echo '<script>window.location.href="'.$location.'"</script>';
  368. return;
  369. }
  370. global $_course, $_user;
  371. $clean_title=trim($_POST['title']);
  372. $clean_title= Database::escape_string($clean_title);
  373. $clean_text=trim($_POST['text']);
  374. $clean_voices=Security::remove_XSS($_POST['voices']);
  375. if(empty($clean_title) || empty($clean_text) || empty($clean_voices)){
  376. echo '<script>window.location.href="'.$location.'"</script>';
  377. return;
  378. }
  379. $clean_title=Security::remove_XSS($clean_title);
  380. $clean_title=Database::escape_string($clean_title);
  381. $clean_title=str_replace(' ','_', $clean_title);//compound file names
  382. $clean_text=Security::remove_XSS($clean_text);
  383. $clean_lang=Security::remove_XSS($_POST['lang']);
  384. $clean_speed=Security::remove_XSS($_POST['speed']);
  385. $extension='mp3';
  386. $audio_filename=$clean_title.'.'.$extension;
  387. $audio_title = str_replace('_',' ',$clean_title);
  388. //prevent duplicates
  389. if (file_exists($filepath.'/'.$clean_title.'.'.$extension)){
  390. $i = 1;
  391. while (file_exists($filepath.'/'.$clean_title.'_'.$i.'.'.$extension)) $i++;
  392. $audio_filename = $clean_title . '_' . $i . '.'.$extension;
  393. $audio_title = $clean_title . '_' . $i . '.'.$extension;
  394. $audio_title = str_replace('_',' ',$audio_title);
  395. }
  396. $documentPath = $filepath.'/'.$audio_filename;
  397. //prev for a fine unicode, borrowed from main api TODO:clean
  398. // Safe replacements for some non-letter characters (whitout blank spaces)
  399. $search = array("\0", "\t", "\n", "\r", "\x0B", '/', "\\", '"', "'", '?', '*', '>', '<', '|', ':', '$', '(', ')', '^', '[', ']', '#', '+', '&', '%');
  400. $replace = array('', '_', '_', '_', '_', '-', '-', '-', '_', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-');
  401. $filename=$clean_text;
  402. // Encoding detection.
  403. $encoding = api_detect_encoding($filename);
  404. // Converting html-entities into encoded characters.
  405. $filename = api_html_entity_decode($filename, ENT_QUOTES, $encoding);
  406. // Transliteration to ASCII letters, they are not dangerous for filesystems.
  407. $filename = api_transliterate($filename, 'x', $encoding);
  408. // Replacing remaining dangerous non-letter characters.
  409. $clean_text = str_replace($search, $replace, $filename);
  410. //adding the file
  411. if($clean_lang=='de'){
  412. $url_pediaphon='http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice.cgi';
  413. $find_t2v = '/http\:\/\/www\.pediaphon\.org\/\~bischoff\/radiopedia\/mp3\/(.*)\.mp3\"/';
  414. }
  415. else{
  416. $url_pediaphon='http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice_'.$clean_lang.'.cgi';//en, es, fr
  417. $find_t2v = '/http\:\/\/www\.pediaphon\.org\/\~bischoff\/radiopedia\/mp3\/'.$clean_lang.'\/(.*)\.mp3\"/';
  418. }
  419. $data="stimme=".$clean_voices."&inputtext=".$clean_text."&speed=".$clean_speed."&go=go";
  420. $opts = array('http' =>
  421. array(
  422. 'method' => 'POST',
  423. 'header' =>"Content-Type: application/x-www-form-urlencoded\r\n",
  424. "Content-Length: " . strlen($data) . "\r\n",
  425. 'content' => $data
  426. )
  427. );
  428. $context = stream_context_create($opts);
  429. $previous_returntext2voice = file_get_contents($url_pediaphon,false,$context);
  430. //clean file contents
  431. $search_source=preg_match($find_t2v, $previous_returntext2voice, $hits);
  432. $souce_end=substr($hits[0], 0,-1);
  433. $returntext2voice = file_get_contents($souce_end);
  434. //save file
  435. file_put_contents($documentPath, $returntext2voice);
  436. //add document to database
  437. $current_session_id = api_get_session_id();
  438. $groupId=$_SESSION['_gid'];
  439. $file_size = filesize($documentPath);
  440. $relativeUrlPath=$dir;
  441. $doc_id = add_document($_course, $relativeUrlPath.$audio_filename, 'file', filesize($documentPath), $audio_title);
  442. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id);
  443. Display::display_confirmation_message(get_lang('DocumentCreated'));
  444. //return to location
  445. echo '<script>window.location.href="'.$location.'"</script>';
  446. }