Completed
Push — 1.10.x ( 3c862d...f834ff )
by
unknown
69:56 queued 21:48
created
main/document/create_audio.php 2 patches
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -23,26 +23,26 @@  discard block
 block discarded – undo
23 23
 $groupId = api_get_group_id();
24 24
 
25 25
 if (api_get_setting('enabled_text2audio') == 'false') {
26
-	api_not_allowed(true);
26
+    api_not_allowed(true);
27 27
 }
28 28
 
29 29
 $document_data = DocumentManager::get_document_data_by_id(
30
-	$_REQUEST['id'],
31
-	api_get_course_id()
30
+    $_REQUEST['id'],
31
+    api_get_course_id()
32 32
 );
33 33
 if (empty($document_data)) {
34 34
     if (api_is_in_group()) {
35
-		$group_properties = GroupManager::get_group_properties(
36
-			$groupId
37
-		);
38
-		$document_id = DocumentManager::get_document_id(
39
-			api_get_course_info(),
40
-			$group_properties['directory']
41
-		);
42
-		$document_data = DocumentManager::get_document_data_by_id(
43
-			$document_id,
44
-			api_get_course_id()
45
-		);
35
+        $group_properties = GroupManager::get_group_properties(
36
+            $groupId
37
+        );
38
+        $document_id = DocumentManager::get_document_id(
39
+            api_get_course_info(),
40
+            $group_properties['directory']
41
+        );
42
+        $document_data = DocumentManager::get_document_data_by_id(
43
+            $document_id,
44
+            api_get_course_id()
45
+        );
46 46
     }
47 47
 }
48 48
 $document_id = $document_data['id'];
@@ -55,39 +55,39 @@  discard block
 block discarded – undo
55 55
 // Please, do not modify this dirname formatting
56 56
 
57 57
 if (strstr($dir, '..')) {
58
-	$dir = '/';
58
+    $dir = '/';
59 59
 }
60 60
 
61 61
 if ($dir[0] == '.') {
62
-	$dir = substr($dir, 1);
62
+    $dir = substr($dir, 1);
63 63
 }
64 64
 
65 65
 if ($dir[0] != '/') {
66
-	$dir = '/'.$dir;
66
+    $dir = '/'.$dir;
67 67
 }
68 68
 
69 69
 if ($dir[strlen($dir) - 1] != '/') {
70
-	$dir .= '/';
70
+    $dir .= '/';
71 71
 }
72 72
 
73 73
 $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
74 74
 
75 75
 if (!is_dir($filepath)) {
76
-	$filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
77
-	$dir = '/';
76
+    $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
77
+    $dir = '/';
78 78
 }
79 79
 
80 80
 //groups //TODO: clean
81 81
 if (!empty($groupId)) {
82
-	$interbreadcrumb[] = array(
83
-		"url" => "../group/group_space.php?".api_get_cidreq(),
84
-		"name" => get_lang('GroupSpace')
85
-	);
86
-	$group = GroupManager :: get_group_properties($groupId);
87
-	$path = explode('/', $dir);
88
-	if ('/'.$path[1] != $group['directory']) {
89
-		api_not_allowed(true);
90
-	}
82
+    $interbreadcrumb[] = array(
83
+        "url" => "../group/group_space.php?".api_get_cidreq(),
84
+        "name" => get_lang('GroupSpace')
85
+    );
86
+    $group = GroupManager :: get_group_properties($groupId);
87
+    $path = explode('/', $dir);
88
+    if ('/'.$path[1] != $group['directory']) {
89
+        api_not_allowed(true);
90
+    }
91 91
 }
92 92
 
93 93
 $interbreadcrumb[] = array (
@@ -96,18 +96,18 @@  discard block
 block discarded – undo
96 96
 );
97 97
 
98 98
 if (!$is_allowed_in_course) {
99
-	api_not_allowed(true);
99
+    api_not_allowed(true);
100 100
 }
101 101
 
102 102
 
103 103
 if (!($is_allowed_to_edit || $_SESSION['group_member_with_upload_rights'] ||
104
-	DocumentManager::is_my_shared_folder(
105
-		api_get_user_id(),
106
-		Security::remove_XSS($dir),
107
-		api_get_session_id()
108
-	))
104
+    DocumentManager::is_my_shared_folder(
105
+        api_get_user_id(),
106
+        Security::remove_XSS($dir),
107
+        api_get_session_id()
108
+    ))
109 109
 ) {
110
-	api_not_allowed(true);
110
+    api_not_allowed(true);
111 111
 }
112 112
 
113 113
 
@@ -116,10 +116,10 @@  discard block
 block discarded – undo
116 116
 
117 117
 $display_dir = $dir;
118 118
 if (isset ($group)) {
119
-	$display_dir = explode('/', $dir);
120
-	unset ($display_dir[0]);
121
-	unset ($display_dir[1]);
122
-	$display_dir = implode('/', $display_dir);
119
+    $display_dir = explode('/', $dir);
120
+    unset ($display_dir[0]);
121
+    unset ($display_dir[1]);
122
+    $display_dir = implode('/', $display_dir);
123 123
 }
124 124
 
125 125
 // Interbreadcrumb for the current directory root path
@@ -129,22 +129,22 @@  discard block
 block discarded – undo
129 129
 
130 130
 $dir_acum = '';
131 131
 for ($i = 0; $i < $array_len; $i++) {
132
-	$url_dir = 'document.php?&curdirpath='.$dir_acum.$dir_array[$i];
133
-	//Max char 80
134
-	$url_to_who = cut($dir_array[$i],80);
135
-	$interbreadcrumb[] = array('url' => $url_dir, 'name' => $url_to_who);
136
-	$dir_acum .= $dir_array[$i].'/';
132
+    $url_dir = 'document.php?&curdirpath='.$dir_acum.$dir_array[$i];
133
+    //Max char 80
134
+    $url_to_who = cut($dir_array[$i],80);
135
+    $interbreadcrumb[] = array('url' => $url_dir, 'name' => $url_to_who);
136
+    $dir_acum .= $dir_array[$i].'/';
137 137
 }
138 138
 
139 139
 Display :: display_header($nameTools, 'Doc');
140 140
 
141 141
 echo '<div class="actions">';
142 142
 echo '<a href="document.php?id='.$document_id.'">'.
143
-		Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).'</a>';
143
+        Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).'</a>';
144 144
 echo '<a href="create_audio.php?'.api_get_cidreq().'&amp;id='.$document_id.'&amp;dt2a=google">'.
145
-		Display::return_icon('google.png',get_lang('GoogleAudio'),'',ICON_SIZE_MEDIUM).'</a>';
145
+        Display::return_icon('google.png',get_lang('GoogleAudio'),'',ICON_SIZE_MEDIUM).'</a>';
146 146
 echo '<a href="create_audio.php?'.api_get_cidreq().'&amp;id='.$document_id.'&amp;dt2a=pediaphon">'.
147
-	Display::return_icon('pediaphon.png', get_lang('Pediaphon'),'',ICON_SIZE_MEDIUM).'</a>';
147
+    Display::return_icon('pediaphon.png', get_lang('Pediaphon'),'',ICON_SIZE_MEDIUM).'</a>';
148 148
 echo '</div>';
149 149
 
150 150
 ?>
@@ -197,9 +197,9 @@  discard block
 block discarded – undo
197 197
 <?php
198 198
 
199 199
 if (isset($_POST['text2voice_mode']) && $_POST['text2voice_mode'] == 'google') {
200
-	downloadMP3_google($filepath, $dir);
200
+    downloadMP3_google($filepath, $dir);
201 201
 } elseif (isset($_POST['text2voice_mode']) && $_POST['text2voice_mode'] == 'pediaphon') {
202
-	downloadMP3_pediaphon($filepath, $dir);
202
+    downloadMP3_pediaphon($filepath, $dir);
203 203
 }
204 204
 
205 205
 $tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
@@ -217,35 +217,35 @@  discard block
 block discarded – undo
217 217
 }
218 218
 
219 219
 if (Security::remove_XSS($_GET['dt2a']) == 'google') {
220
-	$selected_language = api_get_language_isocode();//lang default is the course language
220
+    $selected_language = api_get_language_isocode();//lang default is the course language
221 221
 
222
-	$form = new FormValidator('form1', 'post', null, '', array('id' => 'form1'));
222
+    $form = new FormValidator('form1', 'post', null, '', array('id' => 'form1'));
223 223
     $form->addHeader(get_lang('HelpText2Audio'));
224
-	$form->addElement('hidden', 'text2voice_mode', 'google');
225
-	$form->addElement('hidden', 'id', $document_id);
226
-	$form->addElement('text', 'title', get_lang('Title'));
227
-	$form->addElement('select', 'lang', get_lang('Language'), $options);
228
-	$form->addElement('textarea', 'text', get_lang('InsertText2Audio'), array('id' => 'textarea_google'));
224
+    $form->addElement('hidden', 'text2voice_mode', 'google');
225
+    $form->addElement('hidden', 'id', $document_id);
226
+    $form->addElement('text', 'title', get_lang('Title'));
227
+    $form->addElement('select', 'lang', get_lang('Language'), $options);
228
+    $form->addElement('textarea', 'text', get_lang('InsertText2Audio'), array('id' => 'textarea_google'));
229 229
     $form->addButtonSave(get_lang('SaveMP3'));
230
-	$defaults = array();
231
-	$defaults['lang'] = $selected_language;
232
-	$form->setDefaults($defaults);
233
-	$form->display();
230
+    $defaults = array();
231
+    $defaults['lang'] = $selected_language;
232
+    $form->setDefaults($defaults);
233
+    $form->display();
234 234
 
235 235
 }
236 236
 
237 237
 if (Security::remove_XSS($_GET['dt2a']) == 'pediaphon') {
238
-	//lang default is a default message
239
-	$selected_language = "defaultmessage";
240
-	$options_pedia['defaultmessage'] =get_lang('FirstSelectALanguage');
241
-	$options['defaultmessage'] =get_lang('FirstSelectALanguage');
238
+    //lang default is a default message
239
+    $selected_language = "defaultmessage";
240
+    $options_pedia['defaultmessage'] =get_lang('FirstSelectALanguage');
241
+    $options['defaultmessage'] =get_lang('FirstSelectALanguage');
242 242
 
243
-	$form = new FormValidator('form2', 'post', null, '', array('id' => 'form2'));
243
+    $form = new FormValidator('form2', 'post', null, '', array('id' => 'form2'));
244 244
     $form->addHeader(get_lang('HelpText2Audio'));
245
-	$form->addElement('hidden', 'text2voice_mode','pediaphon');
246
-	$form->addElement('hidden', 'id', $document_id);
247
-	$form->addElement('text', 'title', get_lang('Title'));
248
-	$form->addSelect('lang', get_lang('Language'), $options_pedia, array('class' => 'lang'));
245
+    $form->addElement('hidden', 'text2voice_mode','pediaphon');
246
+    $form->addElement('hidden', 'id', $document_id);
247
+    $form->addElement('text', 'title', get_lang('Title'));
248
+    $form->addSelect('lang', get_lang('Language'), $options_pedia, array('class' => 'lang'));
249 249
     $form->addSelect('voices', get_lang('Voice'), array(get_lang('FirstSelectALanguage')), array('id' => 'voices'));
250 250
     $speed_options = array();
251 251
     $speed_options['1'] = get_lang('Normal');
@@ -254,15 +254,15 @@  discard block
 block discarded – undo
254 254
     $speed_options['1.2'] = get_lang('Slow');
255 255
     $speed_options['1.6'] = get_lang('SlowDown');
256 256
 
257
-	$form->addElement('select', 'speed', get_lang('Speed'), $speed_options, array());
258
-	$form->addElement('textarea', 'text', get_lang('InsertText2Audio'), array('id' => 'textarea_pediaphon'));
259
-	//echo Display :: return_icon('info3.gif', get_lang('HelpPediaphon'), array('align' => 'absmiddle', 'hspace' => '3px'), false);
260
-	$form->addButtonSave(get_lang('SaveMP3'));
261
-	$defaults = array();
262
-	$defaults['lang'] = $selected_language;
263
-	$form->setDefaults($defaults);
264
-	$form->display();
265
-	?>
257
+    $form->addElement('select', 'speed', get_lang('Speed'), $speed_options, array());
258
+    $form->addElement('textarea', 'text', get_lang('InsertText2Audio'), array('id' => 'textarea_pediaphon'));
259
+    //echo Display :: return_icon('info3.gif', get_lang('HelpPediaphon'), array('align' => 'absmiddle', 'hspace' => '3px'), false);
260
+    $form->addButtonSave(get_lang('SaveMP3'));
261
+    $defaults = array();
262
+    $defaults['lang'] = $selected_language;
263
+    $form->setDefaults($defaults);
264
+    $form->display();
265
+    ?>
266 266
 
267 267
 	<!-- javascript form name form2 update voices -->
268 268
 	<script>
@@ -314,90 +314,90 @@  discard block
 block discarded – undo
314 314
 {
315 315
     $location='create_audio.php?'.api_get_cidreq().'&id='.intval($_POST['id']).'&dt2a=google';
316 316
 
317
-	//security
318
-	if (!isset($_POST['lang']) && !isset($_POST['text']) && !isset($_POST['title']) && !isset($filepath) && !isset($dir)) {
319
-		echo '<script>window.location.href="'.$location.'"</script>';
320
-		return;
321
-	}
322
-
323
-	$_course = api_get_course_info();
324
-	$_user = api_get_user_info();
325
-
326
-	$clean_title=trim($_POST['title']);
327
-	$clean_text=trim($_POST['text']);
328
-	if(empty($clean_title) || empty($clean_text)){
329
-		echo '<script>window.location.href="'.$location.'"</script>';
330
-		return;
331
-	}
332
-	$clean_title = Security::remove_XSS($clean_title);
333
-	$clean_title = Database::escape_string($clean_title);
334
-	$clean_title = str_replace(' ', '_', $clean_title);//compound file names
335
-
336
-	$clean_text = Security::remove_XSS($clean_text);
337
-	$clean_lang = Security::remove_XSS($_POST['lang']);
338
-
339
-	$extension='mp3';
340
-	$audio_filename=$clean_title.'.'.$extension;
341
-	$audio_title = str_replace('_',' ',$clean_title);
342
-
343
-	//prevent duplicates
344
-	if (file_exists($filepath.'/'.$clean_title.'.'.$extension)){
345
-		$i = 1;
346
-		while (file_exists($filepath.'/'.$clean_title.'_'.$i.'.'.$extension)) $i++;
347
-		$audio_filename = $clean_title . '_' . $i . '.'.$extension;
348
-		$audio_title = $clean_title . '_' . $i . '.'.$extension;
349
-		$audio_title = str_replace('_',' ',$audio_title);
350
-	}
351
-
352
-	$documentPath = $filepath.'/'.$audio_filename;
353
-
354
-	$clean_text = api_replace_dangerous_char($clean_text);
355
-
356
-	// adding the file
357
-	// add new file to disk
358
-
359
-	$proxySettings = api_get_configuration_value('proxy_settings');
317
+    //security
318
+    if (!isset($_POST['lang']) && !isset($_POST['text']) && !isset($_POST['title']) && !isset($filepath) && !isset($dir)) {
319
+        echo '<script>window.location.href="'.$location.'"</script>';
320
+        return;
321
+    }
322
+
323
+    $_course = api_get_course_info();
324
+    $_user = api_get_user_info();
325
+
326
+    $clean_title=trim($_POST['title']);
327
+    $clean_text=trim($_POST['text']);
328
+    if(empty($clean_title) || empty($clean_text)){
329
+        echo '<script>window.location.href="'.$location.'"</script>';
330
+        return;
331
+    }
332
+    $clean_title = Security::remove_XSS($clean_title);
333
+    $clean_title = Database::escape_string($clean_title);
334
+    $clean_title = str_replace(' ', '_', $clean_title);//compound file names
335
+
336
+    $clean_text = Security::remove_XSS($clean_text);
337
+    $clean_lang = Security::remove_XSS($_POST['lang']);
338
+
339
+    $extension='mp3';
340
+    $audio_filename=$clean_title.'.'.$extension;
341
+    $audio_title = str_replace('_',' ',$clean_title);
342
+
343
+    //prevent duplicates
344
+    if (file_exists($filepath.'/'.$clean_title.'.'.$extension)){
345
+        $i = 1;
346
+        while (file_exists($filepath.'/'.$clean_title.'_'.$i.'.'.$extension)) $i++;
347
+        $audio_filename = $clean_title . '_' . $i . '.'.$extension;
348
+        $audio_title = $clean_title . '_' . $i . '.'.$extension;
349
+        $audio_title = str_replace('_',' ',$audio_title);
350
+    }
351
+
352
+    $documentPath = $filepath.'/'.$audio_filename;
353
+
354
+    $clean_text = api_replace_dangerous_char($clean_text);
355
+
356
+    // adding the file
357
+    // add new file to disk
358
+
359
+    $proxySettings = api_get_configuration_value('proxy_settings');
360 360
     $key = api_get_configuration_value('translate_app_google_key');
361
-	$url = "https://www.googleapis.com/language/translate/v2?key=$key&".$clean_lang."&target=$clean_lang&q=".urlencode($clean_text)."";
361
+    $url = "https://www.googleapis.com/language/translate/v2?key=$key&".$clean_lang."&target=$clean_lang&q=".urlencode($clean_text)."";
362 362
 
363
-	if (empty($proxySettings)) {
364
-		$content = file_get_contents($url);
365
-	} else {
366
-		$context = stream_context_create($proxySettings);
367
-		$content = file_get_contents($url, false, $context);
368
-	}
363
+    if (empty($proxySettings)) {
364
+        $content = file_get_contents($url);
365
+    } else {
366
+        $context = stream_context_create($proxySettings);
367
+        $content = file_get_contents($url, false, $context);
368
+    }
369 369
 
370 370
     file_put_contents(
371 371
         $documentPath,
372 372
         $content
373 373
     );
374 374
 
375
-	// add document to database
376
-	$current_session_id = api_get_session_id();
377
-	$groupId = api_get_group_id();
378
-	$relativeUrlPath=$dir;
379
-	$doc_id = add_document(
380
-		$_course,
381
-		$relativeUrlPath.$audio_filename,
382
-		'file',
383
-		filesize($documentPath),
384
-		$audio_title
385
-	);
386
-	api_item_property_update(
387
-		$_course,
388
-		TOOL_DOCUMENT,
389
-		$doc_id,
390
-		'DocumentAdded',
391
-		$_user['user_id'],
392
-		$groupId,
393
-		null,
394
-		null,
395
-		null,
396
-		$current_session_id
397
-	);
398
-	Display::display_confirmation_message(get_lang('DocumentCreated'));
399
-	//return to location
400
-	echo '<script>window.location.href="'.$location.'"</script>';
375
+    // add document to database
376
+    $current_session_id = api_get_session_id();
377
+    $groupId = api_get_group_id();
378
+    $relativeUrlPath=$dir;
379
+    $doc_id = add_document(
380
+        $_course,
381
+        $relativeUrlPath.$audio_filename,
382
+        'file',
383
+        filesize($documentPath),
384
+        $audio_title
385
+    );
386
+    api_item_property_update(
387
+        $_course,
388
+        TOOL_DOCUMENT,
389
+        $doc_id,
390
+        'DocumentAdded',
391
+        $_user['user_id'],
392
+        $groupId,
393
+        null,
394
+        null,
395
+        null,
396
+        $current_session_id
397
+    );
398
+    Display::display_confirmation_message(get_lang('DocumentCreated'));
399
+    //return to location
400
+    echo '<script>window.location.href="'.$location.'"</script>';
401 401
 }
402 402
 
403 403
 /**
@@ -410,12 +410,12 @@  discard block
 block discarded – undo
410 410
  */
411 411
 function downloadMP3_pediaphon($filepath, $dir)
412 412
 {
413
-	$location='create_audio.php?'.api_get_cidreq().'&id='.intval($_POST['id']).'&dt2a=pediaphon';
414
-	//security
415
-	if (!isset($_POST['lang']) && !isset($_POST['text']) && !isset($_POST['title']) && !isset($filepath) && !isset($dir)) {
416
-		echo '<script>window.location.href="'.$location.'"</script>';
417
-		return;
418
-	}
413
+    $location='create_audio.php?'.api_get_cidreq().'&id='.intval($_POST['id']).'&dt2a=pediaphon';
414
+    //security
415
+    if (!isset($_POST['lang']) && !isset($_POST['text']) && !isset($_POST['title']) && !isset($filepath) && !isset($dir)) {
416
+        echo '<script>window.location.href="'.$location.'"</script>';
417
+        return;
418
+    }
419 419
     $_course = api_get_course_info();
420 420
     $_user = api_get_user_info();
421 421
     $clean_title = trim($_POST['title']);
@@ -427,70 +427,70 @@  discard block
 block discarded – undo
427 427
 
428 428
         return;
429 429
     }
430
-	$clean_title = Security::remove_XSS($clean_title);
431
-	$clean_title = Database::escape_string($clean_title);
432
-	$clean_title = str_replace(' ', '_', $clean_title);//compound file names
433
-	$clean_text = Security::remove_XSS($clean_text);
434
-	$clean_lang = Security::remove_XSS($_POST['lang']);
435
-	$clean_speed = Security::remove_XSS($_POST['speed']);
436
-
437
-	$extension='mp3';
438
-	$audio_filename=$clean_title.'.'.$extension;
439
-	$audio_title = str_replace('_',' ',$clean_title);
440
-
441
-	//prevent duplicates
442
-	if (file_exists($filepath.'/'.$clean_title.'.'.$extension)){
443
-		$i = 1;
444
-		while (file_exists($filepath.'/'.$clean_title.'_'.$i.'.'.$extension)) $i++;
445
-		$audio_filename = $clean_title . '_' . $i . '.'.$extension;
446
-		$audio_title = $clean_title . '_' . $i . '.'.$extension;
447
-		$audio_title = str_replace('_',' ',$audio_title);
448
-	}
449
-
450
-	$documentPath = $filepath.'/'.$audio_filename;
451
-	$clean_text = api_replace_dangerous_char($clean_text);
452
-
453
-	//adding the file
454
-
455
-	if ($clean_lang == 'de') {
456
-		$url_pediaphon='http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice.cgi';
457
-		$find_t2v = '/http\:\/\/www\.pediaphon\.org\/\~bischoff\/radiopedia\/mp3\/(.*)\.mp3\"/';
458
-	} else {
459
-		$url_pediaphon='http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice_'.$clean_lang.'.cgi';//en, es, fr
460
-		$find_t2v = '/http\:\/\/www\.pediaphon\.org\/\~bischoff\/radiopedia\/mp3\/'.$clean_lang.'\/(.*)\.mp3\"/';
461
-	}
462
-
463
-	$data="stimme=".$clean_voices."&inputtext=".$clean_text."&speed=".$clean_speed."&go=speak";
464
-	$opts = array('http' =>
465
-		array(
466
-		 'method'  => 'POST',
467
-		 'header'  =>"Content-Type: application/x-www-form-urlencoded\r\n",
468
-		 "Content-Length: " . strlen($data) . "\r\n",
469
-		 'content' => $data
470
-		)
471
-	);
472
-
473
-	$context  = stream_context_create($opts);
474
-	// Download the whole HTML page
475
-	$previous_returntext2voice = file_get_contents($url_pediaphon,false,$context);
476
-
477
-	//extract the audio file path
478
-	$search_source = preg_match($find_t2v, $previous_returntext2voice, $hits);
479
-	$souce_end = substr($hits[0], 0, -1);
480
-	//download file
481
-	$returntext2voice = file_get_contents($souce_end);
482
-	//save file
483
-	$f = @file_put_contents($documentPath, $returntext2voice);
484
-	if ($f === false && !empty($php_errormsg)) {
430
+    $clean_title = Security::remove_XSS($clean_title);
431
+    $clean_title = Database::escape_string($clean_title);
432
+    $clean_title = str_replace(' ', '_', $clean_title);//compound file names
433
+    $clean_text = Security::remove_XSS($clean_text);
434
+    $clean_lang = Security::remove_XSS($_POST['lang']);
435
+    $clean_speed = Security::remove_XSS($_POST['speed']);
436
+
437
+    $extension='mp3';
438
+    $audio_filename=$clean_title.'.'.$extension;
439
+    $audio_title = str_replace('_',' ',$clean_title);
440
+
441
+    //prevent duplicates
442
+    if (file_exists($filepath.'/'.$clean_title.'.'.$extension)){
443
+        $i = 1;
444
+        while (file_exists($filepath.'/'.$clean_title.'_'.$i.'.'.$extension)) $i++;
445
+        $audio_filename = $clean_title . '_' . $i . '.'.$extension;
446
+        $audio_title = $clean_title . '_' . $i . '.'.$extension;
447
+        $audio_title = str_replace('_',' ',$audio_title);
448
+    }
449
+
450
+    $documentPath = $filepath.'/'.$audio_filename;
451
+    $clean_text = api_replace_dangerous_char($clean_text);
452
+
453
+    //adding the file
454
+
455
+    if ($clean_lang == 'de') {
456
+        $url_pediaphon='http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice.cgi';
457
+        $find_t2v = '/http\:\/\/www\.pediaphon\.org\/\~bischoff\/radiopedia\/mp3\/(.*)\.mp3\"/';
458
+    } else {
459
+        $url_pediaphon='http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice_'.$clean_lang.'.cgi';//en, es, fr
460
+        $find_t2v = '/http\:\/\/www\.pediaphon\.org\/\~bischoff\/radiopedia\/mp3\/'.$clean_lang.'\/(.*)\.mp3\"/';
461
+    }
462
+
463
+    $data="stimme=".$clean_voices."&inputtext=".$clean_text."&speed=".$clean_speed."&go=speak";
464
+    $opts = array('http' =>
465
+        array(
466
+            'method'  => 'POST',
467
+            'header'  =>"Content-Type: application/x-www-form-urlencoded\r\n",
468
+            "Content-Length: " . strlen($data) . "\r\n",
469
+            'content' => $data
470
+        )
471
+    );
472
+
473
+    $context  = stream_context_create($opts);
474
+    // Download the whole HTML page
475
+    $previous_returntext2voice = file_get_contents($url_pediaphon,false,$context);
476
+
477
+    //extract the audio file path
478
+    $search_source = preg_match($find_t2v, $previous_returntext2voice, $hits);
479
+    $souce_end = substr($hits[0], 0, -1);
480
+    //download file
481
+    $returntext2voice = file_get_contents($souce_end);
482
+    //save file
483
+    $f = @file_put_contents($documentPath, $returntext2voice);
484
+    if ($f === false && !empty($php_errormsg)) {
485 485
                 error_log($php_errormsg);
486 486
             }
487
-	//add document to database
488
-	$current_session_id = api_get_session_id();
489
-	$groupId = api_get_group_id();
490
-	$relativeUrlPath=$dir;
491
-	$doc_id = add_document($_course, $relativeUrlPath.$audio_filename, 'file', filesize($documentPath), $audio_title);
492
-	api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id);
487
+    //add document to database
488
+    $current_session_id = api_get_session_id();
489
+    $groupId = api_get_group_id();
490
+    $relativeUrlPath=$dir;
491
+    $doc_id = add_document($_course, $relativeUrlPath.$audio_filename, 'file', filesize($documentPath), $audio_title);
492
+    api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id);
493 493
     Display::display_confirmation_message(get_lang('DocumentCreated'));
494
-	//return to location
495
-	echo '<script>window.location.href="'.$location.'"</script>';
494
+    //return to location
495
+    echo '<script>window.location.href="'.$location.'"</script>';
496 496
 }
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	}
91 91
 }
92 92
 
93
-$interbreadcrumb[] = array (
93
+$interbreadcrumb[] = array(
94 94
     "url" => "./document.php?curdirpath=".urlencode($dir)."&".api_get_cidreq(),
95 95
     "name" => get_lang('Documents')
96 96
 );
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 for ($i = 0; $i < $array_len; $i++) {
132 132
 	$url_dir = 'document.php?&curdirpath='.$dir_acum.$dir_array[$i];
133 133
 	//Max char 80
134
-	$url_to_who = cut($dir_array[$i],80);
134
+	$url_to_who = cut($dir_array[$i], 80);
135 135
 	$interbreadcrumb[] = array('url' => $url_dir, 'name' => $url_to_who);
136 136
 	$dir_acum .= $dir_array[$i].'/';
137 137
 }
@@ -140,11 +140,11 @@  discard block
 block discarded – undo
140 140
 
141 141
 echo '<div class="actions">';
142 142
 echo '<a href="document.php?id='.$document_id.'">'.
143
-		Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).'</a>';
143
+		Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'), '', ICON_SIZE_MEDIUM).'</a>';
144 144
 echo '<a href="create_audio.php?'.api_get_cidreq().'&amp;id='.$document_id.'&amp;dt2a=google">'.
145
-		Display::return_icon('google.png',get_lang('GoogleAudio'),'',ICON_SIZE_MEDIUM).'</a>';
145
+		Display::return_icon('google.png', get_lang('GoogleAudio'), '', ICON_SIZE_MEDIUM).'</a>';
146 146
 echo '<a href="create_audio.php?'.api_get_cidreq().'&amp;id='.$document_id.'&amp;dt2a=pediaphon">'.
147
-	Display::return_icon('pediaphon.png', get_lang('Pediaphon'),'',ICON_SIZE_MEDIUM).'</a>';
147
+	Display::return_icon('pediaphon.png', get_lang('Pediaphon'), '', ICON_SIZE_MEDIUM).'</a>';
148 148
 echo '</div>';
149 149
 
150 150
 ?>
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 }
218 218
 
219 219
 if (Security::remove_XSS($_GET['dt2a']) == 'google') {
220
-	$selected_language = api_get_language_isocode();//lang default is the course language
220
+	$selected_language = api_get_language_isocode(); //lang default is the course language
221 221
 
222 222
 	$form = new FormValidator('form1', 'post', null, '', array('id' => 'form1'));
223 223
     $form->addHeader(get_lang('HelpText2Audio'));
@@ -237,12 +237,12 @@  discard block
 block discarded – undo
237 237
 if (Security::remove_XSS($_GET['dt2a']) == 'pediaphon') {
238 238
 	//lang default is a default message
239 239
 	$selected_language = "defaultmessage";
240
-	$options_pedia['defaultmessage'] =get_lang('FirstSelectALanguage');
241
-	$options['defaultmessage'] =get_lang('FirstSelectALanguage');
240
+	$options_pedia['defaultmessage'] = get_lang('FirstSelectALanguage');
241
+	$options['defaultmessage'] = get_lang('FirstSelectALanguage');
242 242
 
243 243
 	$form = new FormValidator('form2', 'post', null, '', array('id' => 'form2'));
244 244
     $form->addHeader(get_lang('HelpText2Audio'));
245
-	$form->addElement('hidden', 'text2voice_mode','pediaphon');
245
+	$form->addElement('hidden', 'text2voice_mode', 'pediaphon');
246 246
 	$form->addElement('hidden', 'id', $document_id);
247 247
 	$form->addElement('text', 'title', get_lang('Title'));
248 248
 	$form->addSelect('lang', get_lang('Language'), $options_pedia, array('class' => 'lang'));
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
  */
313 313
 function downloadMP3_google($filepath, $dir)
314 314
 {
315
-    $location='create_audio.php?'.api_get_cidreq().'&id='.intval($_POST['id']).'&dt2a=google';
315
+    $location = 'create_audio.php?'.api_get_cidreq().'&id='.intval($_POST['id']).'&dt2a=google';
316 316
 
317 317
 	//security
318 318
 	if (!isset($_POST['lang']) && !isset($_POST['text']) && !isset($_POST['title']) && !isset($filepath) && !isset($dir)) {
@@ -323,30 +323,30 @@  discard block
 block discarded – undo
323 323
 	$_course = api_get_course_info();
324 324
 	$_user = api_get_user_info();
325 325
 
326
-	$clean_title=trim($_POST['title']);
327
-	$clean_text=trim($_POST['text']);
328
-	if(empty($clean_title) || empty($clean_text)){
326
+	$clean_title = trim($_POST['title']);
327
+	$clean_text = trim($_POST['text']);
328
+	if (empty($clean_title) || empty($clean_text)) {
329 329
 		echo '<script>window.location.href="'.$location.'"</script>';
330 330
 		return;
331 331
 	}
332 332
 	$clean_title = Security::remove_XSS($clean_title);
333 333
 	$clean_title = Database::escape_string($clean_title);
334
-	$clean_title = str_replace(' ', '_', $clean_title);//compound file names
334
+	$clean_title = str_replace(' ', '_', $clean_title); //compound file names
335 335
 
336 336
 	$clean_text = Security::remove_XSS($clean_text);
337 337
 	$clean_lang = Security::remove_XSS($_POST['lang']);
338 338
 
339
-	$extension='mp3';
340
-	$audio_filename=$clean_title.'.'.$extension;
341
-	$audio_title = str_replace('_',' ',$clean_title);
339
+	$extension = 'mp3';
340
+	$audio_filename = $clean_title.'.'.$extension;
341
+	$audio_title = str_replace('_', ' ', $clean_title);
342 342
 
343 343
 	//prevent duplicates
344
-	if (file_exists($filepath.'/'.$clean_title.'.'.$extension)){
344
+	if (file_exists($filepath.'/'.$clean_title.'.'.$extension)) {
345 345
 		$i = 1;
346 346
 		while (file_exists($filepath.'/'.$clean_title.'_'.$i.'.'.$extension)) $i++;
347
-		$audio_filename = $clean_title . '_' . $i . '.'.$extension;
348
-		$audio_title = $clean_title . '_' . $i . '.'.$extension;
349
-		$audio_title = str_replace('_',' ',$audio_title);
347
+		$audio_filename = $clean_title.'_'.$i.'.'.$extension;
348
+		$audio_title = $clean_title.'_'.$i.'.'.$extension;
349
+		$audio_title = str_replace('_', ' ', $audio_title);
350 350
 	}
351 351
 
352 352
 	$documentPath = $filepath.'/'.$audio_filename;
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
 	// add document to database
376 376
 	$current_session_id = api_get_session_id();
377 377
 	$groupId = api_get_group_id();
378
-	$relativeUrlPath=$dir;
378
+	$relativeUrlPath = $dir;
379 379
 	$doc_id = add_document(
380 380
 		$_course,
381 381
 		$relativeUrlPath.$audio_filename,
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
  */
411 411
 function downloadMP3_pediaphon($filepath, $dir)
412 412
 {
413
-	$location='create_audio.php?'.api_get_cidreq().'&id='.intval($_POST['id']).'&dt2a=pediaphon';
413
+	$location = 'create_audio.php?'.api_get_cidreq().'&id='.intval($_POST['id']).'&dt2a=pediaphon';
414 414
 	//security
415 415
 	if (!isset($_POST['lang']) && !isset($_POST['text']) && !isset($_POST['title']) && !isset($filepath) && !isset($dir)) {
416 416
 		echo '<script>window.location.href="'.$location.'"</script>';
@@ -429,22 +429,22 @@  discard block
 block discarded – undo
429 429
     }
430 430
 	$clean_title = Security::remove_XSS($clean_title);
431 431
 	$clean_title = Database::escape_string($clean_title);
432
-	$clean_title = str_replace(' ', '_', $clean_title);//compound file names
432
+	$clean_title = str_replace(' ', '_', $clean_title); //compound file names
433 433
 	$clean_text = Security::remove_XSS($clean_text);
434 434
 	$clean_lang = Security::remove_XSS($_POST['lang']);
435 435
 	$clean_speed = Security::remove_XSS($_POST['speed']);
436 436
 
437
-	$extension='mp3';
438
-	$audio_filename=$clean_title.'.'.$extension;
439
-	$audio_title = str_replace('_',' ',$clean_title);
437
+	$extension = 'mp3';
438
+	$audio_filename = $clean_title.'.'.$extension;
439
+	$audio_title = str_replace('_', ' ', $clean_title);
440 440
 
441 441
 	//prevent duplicates
442
-	if (file_exists($filepath.'/'.$clean_title.'.'.$extension)){
442
+	if (file_exists($filepath.'/'.$clean_title.'.'.$extension)) {
443 443
 		$i = 1;
444 444
 		while (file_exists($filepath.'/'.$clean_title.'_'.$i.'.'.$extension)) $i++;
445
-		$audio_filename = $clean_title . '_' . $i . '.'.$extension;
446
-		$audio_title = $clean_title . '_' . $i . '.'.$extension;
447
-		$audio_title = str_replace('_',' ',$audio_title);
445
+		$audio_filename = $clean_title.'_'.$i.'.'.$extension;
446
+		$audio_title = $clean_title.'_'.$i.'.'.$extension;
447
+		$audio_title = str_replace('_', ' ', $audio_title);
448 448
 	}
449 449
 
450 450
 	$documentPath = $filepath.'/'.$audio_filename;
@@ -453,26 +453,26 @@  discard block
 block discarded – undo
453 453
 	//adding the file
454 454
 
455 455
 	if ($clean_lang == 'de') {
456
-		$url_pediaphon='http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice.cgi';
456
+		$url_pediaphon = 'http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice.cgi';
457 457
 		$find_t2v = '/http\:\/\/www\.pediaphon\.org\/\~bischoff\/radiopedia\/mp3\/(.*)\.mp3\"/';
458 458
 	} else {
459
-		$url_pediaphon='http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice_'.$clean_lang.'.cgi';//en, es, fr
459
+		$url_pediaphon = 'http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice_'.$clean_lang.'.cgi'; //en, es, fr
460 460
 		$find_t2v = '/http\:\/\/www\.pediaphon\.org\/\~bischoff\/radiopedia\/mp3\/'.$clean_lang.'\/(.*)\.mp3\"/';
461 461
 	}
462 462
 
463
-	$data="stimme=".$clean_voices."&inputtext=".$clean_text."&speed=".$clean_speed."&go=speak";
463
+	$data = "stimme=".$clean_voices."&inputtext=".$clean_text."&speed=".$clean_speed."&go=speak";
464 464
 	$opts = array('http' =>
465 465
 		array(
466 466
 		 'method'  => 'POST',
467 467
 		 'header'  =>"Content-Type: application/x-www-form-urlencoded\r\n",
468
-		 "Content-Length: " . strlen($data) . "\r\n",
468
+		 "Content-Length: ".strlen($data)."\r\n",
469 469
 		 'content' => $data
470 470
 		)
471 471
 	);
472 472
 
473
-	$context  = stream_context_create($opts);
473
+	$context = stream_context_create($opts);
474 474
 	// Download the whole HTML page
475
-	$previous_returntext2voice = file_get_contents($url_pediaphon,false,$context);
475
+	$previous_returntext2voice = file_get_contents($url_pediaphon, false, $context);
476 476
 
477 477
 	//extract the audio file path
478 478
 	$search_source = preg_match($find_t2v, $previous_returntext2voice, $hits);
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
 	//add document to database
488 488
 	$current_session_id = api_get_session_id();
489 489
 	$groupId = api_get_group_id();
490
-	$relativeUrlPath=$dir;
490
+	$relativeUrlPath = $dir;
491 491
 	$doc_id = add_document($_course, $relativeUrlPath.$audio_filename, 'file', filesize($documentPath), $audio_title);
492 492
 	api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id);
493 493
     Display::display_confirmation_message(get_lang('DocumentCreated'));
Please login to merge, or discard this patch.