Feature #2497 add google service and save mp3 feature

skala
Juan Carlos Raña 15 years ago
parent a0de43d00a
commit 0908cd33fe
  1. 252
      main/document/create_audio.php
  2. 4
      main/document/document.php
  3. 163
      main/inc/lib/javascript/textareacounter/jquery.textareaCounter.plugin.js
  4. 2
      main/wiki/index.php

@ -7,20 +7,17 @@
* @package chamilo.document
*
* @author Juan Carlos Raña Trabado
* @since 8/janvier/2011
* TODO:clean all file and check lang for languages
* @since 8/January/2011
* TODO:clean all file
*/
/* INIT SECTION */
// Name of the language file that needs to be included
$language_file = array('document');
require_once '../inc/global.inc.php';
$_SESSION['whereami'] = 'document/createaudio';
$this_section = SECTION_COURSES;
require_once api_get_path(SYS_CODE_PATH).'document/document.inc.php';
require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
$nameTools = get_lang('CreateAudio');
@ -34,6 +31,30 @@ if (!isset($_GET['dir'])){
api_not_allowed(true);
}
//javascript jquery
$htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery-1.4.4.min.js" type="text/javascript"></script>';
//jquery textareaCounter
$htmlHeadXtra[] = '<script src="../inc/lib/javascript/textareacounter/jquery.textareaCounter.plugin.js" type="text/javascript"></script>';
//need jquery for hide menus
$htmlHeadXtra[] = '<script type="text/javascript" language="javascript">
function advanced_parameters() {
if(document.getElementById(\'options\').style.display == \'none\') {
document.getElementById(\'options\').style.display = \'block\';
document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
} else {
document.getElementById(\'options\').style.display = \'none\';
document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
}
}
function setFocus(){
$("#search_title").focus();
}
$(document).ready(function () {
setFocus();
});
</script>';
$dir = isset($_GET['dir']) ? Security::remove_XSS($_GET['dir']) : Security::remove_XSS($_POST['dir']);
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
@ -122,40 +143,195 @@ echo '<div class="actions">';
echo '<a href="document.php?curdirpath='.Security::remove_XSS($_GET['dir']).'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview')).get_lang('BackTo').' '.get_lang('DocumentsOverview').'</a>';
echo '</div>';
?>
<div align="center">
<?php Display::display_icon('sound.gif', get_lang('CreateAudio')); echo get_lang('HelpText2Audio'); ?>
<form id="form1" name="form1" method="post" action="http://vozme.com/text2voice.php" target="mymp3" class="formw">
<p>
<label><?php echo get_lang('Language')?>:
<select name="lang" id="select">
<option value="en" selected="selected">English</option>
<option value="es">Español</option>
<option value="pt">Português</option>
<option value="it">Italiano</option>
<option value="ca">Català</option>
<option value="hi">ि</option>
</select>
</label>
<label><?php echo get_lang('Voice')?>:
<select name="gn" id="select1">
<option value="ml"><?php echo get_lang('Male')?></option>
<option value="fm"><?php echo get_lang('Female')?></option>
</select>
</label>
</p>
<div><?php echo get_lang('InsertText2Audio')?></div>
<p>
<label>
<textarea name="text" id="textarea" cols="55" rows="6"></textarea>
</label>
</p>
<p>
<button class="save" type="submit" name="SendText2Audio"><?php echo get_lang('BuildMP3');?></button>
</p>
</form>
</div>
<!-- javascript and styles for textareaCounter-->
<script type="text/javascript">
var info;
$(document).ready(function(){
var options = {
'maxCharacterSize': 100,
'originalStyle': 'originalTextareaInfo',
'warningStyle' : 'warningTextareaInfo',
'warningNumber': 10,
'displayFormat' : '#input/#max'
};
$('#textarea').textareaCount(options, function(data){
$('#textareaCallBack').html(result);
});
});
</script>
<style>
.overview {
background: #FFEC9D;
padding: 10px;
width: 90%;
border: 1px solid #CCCCCC;
}
.originalTextareaInfo {
font-size: 12px;
color: #000000;
text-align: right;
}
.warningTextareaInfo {
color: #FF0000;
font-weight:bold;
text-align: right;
}
#showData {
height: 70px;
width: 200px;
border: 1px solid #CCCCCC;
padding: 10px;
margin: 10px;
}
</style>
<?php
echo '<div align="center">';
Display::display_icon('sound.gif', get_lang('CreateAudio')); echo get_lang('HelpText2Audio');
//Google services
echo '<div>&nbsp;</div><input type="checkbox" value="1" name="checktask" onclick="javascript: if(this.checked){document.getElementById(\'option1\').style.display=\'block\';}else{document.getElementById(\'option1\').style.display=\'none\';}"/>&nbsp;<img src="../img/file_sound.gif" title="'.get_lang('HelpGoogleAudio').'" alt="'.get_lang('GoogleAudio').'"/>&nbsp;'.get_lang('GoogleAudio').'';
echo '&nbsp;&nbsp;&nbsp;<span id="msg_error1" style="display:none;color:red"></span>';
echo '<div id="option1" style="padding:4px; margin:5px; border:1px dotted; display:none;">';
echo '<form id="form1" name="form1" method="post" action="'.downloadMP3($filepath, $dir).'" class="formw">';
echo '<br/>';
echo '<label>'.get_lang('Language').': ';
$tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
$sql_select = "SELECT * FROM $tbl_admin_languages";
$result_select = Database::query($sql_select);
echo '<select name="lang" id="select">';
while ($row = Database::fetch_array($result_select)) {
if (api_get_setting('platformLanguage')==$row['english_name']){
echo '<option value="'.$row['isocode'].'" selected="selected">'.$row['original_name'].' ('.$row['english_name'].')</option>';
}
else{
echo '<option value="'.$row['isocode'].'">'.$row['original_name'].' ('.$row['english_name'].')</option>';
}
}
echo '</select>';
echo '</label>';
echo '<br/><br/>';
echo '<div>'.get_lang('InsertText2Audio').'</div>';
echo '<br/>';
echo '<label>';
echo '<textarea name="text" id="textarea" cols="70" rows="2"></textarea>';
echo '</label>';
echo '<br/>';
echo '<label>'.get_lang('Title').': ';
echo '<input name="title" type="text" size="40" maxlength="40" />';
echo '</label>';
echo '<br/><br/>';
echo '<button class="save" type="submit" name="SendText2Audio">'.get_lang('SaveMP3').'</button>';
echo '<br/>';
echo '</form>';
echo '</div>';
//vozMe services
echo '<div>&nbsp;</div><input type="checkbox" value="1" name="checktask" onclick="javascript: if(this.checked){document.getElementById(\'option2\').style.display=\'block\';}else{document.getElementById(\'option2\').style.display=\'none\';}"/>&nbsp;<img src="../img/file_sound.gif" title="'.get_lang('HelpvozMe').'" alt="'.get_lang('vozMe').'"/>&nbsp;'.get_lang('vozMe').'';
echo '&nbsp;&nbsp;&nbsp;<span id="msg_error2" style="display:none;color:red"></span>';
echo '<div id="option2" style="padding:4px; margin:5px; border:1px dotted; display:none;">';
echo '<form id="form2" name="form2" method="post" action="http://vozme.com/text2voice.php" target="mymp3" class="formw">';
echo '<br/>';
echo '<label>'.get_lang('Language').': ';
$tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
$sql_select = "SELECT * FROM $tbl_admin_languages";
$result_select = Database::query($sql_select);
echo '<select name="lang" id="select">';
while ($row = Database::fetch_array($result_select)) {
if (in_array($row['isocode'], array('ca', 'en', 'es', 'hi', 'it', 'pt'))){
if (api_get_setting('platformLanguage')==$row['english_name']){
echo '<option value="'.$row['isocode'].'" selected="selected">'.$row['original_name'].' ('.$row['english_name'].')</option>';
}
else{
echo '<option value="'.$row['isocode'].'">'.$row['original_name'].' ('.$row['english_name'].')</option>';
}
}
}
echo '</select>';
echo '</label>';
echo '<label>&nbsp;&nbsp;'.get_lang('Voice').': ';
echo '<select name="gn" id="select1">';
echo '<option value="ml">'.get_lang('Male').'</option>';
echo '<option value="fm">'.get_lang('Female').'</option>';
echo '</select>';
echo '</label>';
echo '<br/><br/>';
echo '<div>'.get_lang('InsertText2Audio').'</div>';
echo '<br/>';
echo '<label>';
echo '<textarea name="text" id="textarea" cols="70" rows="10"></textarea>';
echo '</label>';
echo '<br/><br/>';
echo '<button class="save" type="submit" name="SendText2Audio">'.get_lang('BuildMP3').'</button>';
echo '<br/>';
echo '</form>';
echo '</div>';
echo '</div>';
Display :: display_footer();
//Functions
/**
* This function save a post into a file mp3
*
* @param $filepath
* @param $dir
* @author Juan Carlos Raña Trabado <herodoto@telefonica.net>
* @version january 2011, chamilo 1.8.8
*/
function downloadMP3($filepath, $dir){
//security
if(!isset($_POST['lang']) && !isset($_POST['text']) && !isset($_POST['title']) && !isset($filepath) && !isset($dir)) {
return;
}
$clean_title=trim(Security::remove_XSS($_POST['title']));
$clean_text=trim(Security::remove_XSS($_POST['text']));
$clean_lang=Security::remove_XSS($_POST['lang']);
if (strlen($clean_title) < "1") {
return;
}
$AudioFilename=$clean_title.'.mp3';
$documentPath = $filepath.$AudioFilename;
//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 (!file_exists($documentPath)){
//add new file to disk
file_put_contents($documentPath, file_get_contents("http://translate.google.com/translate_tts?tl=".$clean_lang."&q=".urlencode($clean_text).""));
//add document to database
$current_session_id = api_get_session_id();
$groupId=$_SESSION['_gid'];
$file_size = filesize($documentPath);
$relativeUrlPath=$dir;
$doc_id = add_document($_course, $relativeUrlPath.$AudioFilename, 'file', filesize($documentPath), $AudioFilename);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id);
}
}
?>

@ -929,12 +929,12 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold
}
// Create new audio
//if (api_get_setting('enabled_text2audio') == 'true'){
if (api_get_setting('enabled_text2audio') == 'true'){
?>
<a href="create_audio.php?<?php echo api_get_cidreq(); ?>&dir=<?php echo $curdirpathurl.$req_gid; ?>">
<?php Display::display_icon('new_text2audio.png', get_lang('CreateAudio')); echo get_lang('CreateAudio'); ?></a>&nbsp;
<?php
// }
}
// Create new certificate
if ($is_certificate_mode) {

@ -0,0 +1,163 @@
/*
* jQuery Textarea Characters Counter Plugin v 2.0
* Examples and documentation at: http://roy-jin.appspot.com/jsp/textareaCounter.jsp
* Copyright (c) 2010 Roy Jin
* Version: 2.0 (11-JUN-2010)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* Requires: jQuery v1.4.2 or later
*/
(function($){
$.fn.textareaCount = function(options, fn) {
var defaults = {
maxCharacterSize: -1,
originalStyle: 'originalTextareaInfo',
warningStyle: 'warningTextareaInfo',
warningNumber: 20,
displayFormat: '#input characters | #words words'
};
var options = $.extend(defaults, options);
var container = $(this);
$("<div class='charleft'>&nbsp;</div>").insertAfter(container);
//create charleft css
var charLeftCss = {
'width' : container.width()
};
var charLeftInfo = getNextCharLeftInformation(container);
charLeftInfo.addClass(options.originalStyle);
charLeftInfo.css(charLeftCss);
var numInput = 0;
var maxCharacters = options.maxCharacterSize;
var numLeft = 0;
var numWords = 0;
container.bind('keyup', function(event){limitTextAreaByCharacterCount();})
.bind('mouseover', function(event){setTimeout(function(){limitTextAreaByCharacterCount();}, 10);})
.bind('paste', function(event){setTimeout(function(){limitTextAreaByCharacterCount();}, 10);});
function limitTextAreaByCharacterCount(){
charLeftInfo.html(countByCharacters());
//function call back
if(typeof fn != 'undefined'){
fn.call(this, getInfo());
}
return true;
}
function countByCharacters(){
var content = container.val();
var contentLength = content.length;
//Start Cut
if(options.maxCharacterSize > 0){
//If copied content is already more than maxCharacterSize, chop it to maxCharacterSize.
if(contentLength >= options.maxCharacterSize) {
content = content.substring(0, options.maxCharacterSize);
}
var newlineCount = getNewlineCount(content);
// newlineCount new line character. For windows, it occupies 2 characters
var systemmaxCharacterSize = options.maxCharacterSize - newlineCount;
if (!isWin()){
systemmaxCharacterSize = options.maxCharacterSize
}
if(contentLength > systemmaxCharacterSize){
//avoid scroll bar moving
var originalScrollTopPosition = this.scrollTop;
container.val(content.substring(0, systemmaxCharacterSize));
this.scrollTop = originalScrollTopPosition;
}
charLeftInfo.removeClass(options.warningStyle);
if(systemmaxCharacterSize - contentLength <= options.warningNumber){
charLeftInfo.addClass(options.warningStyle);
}
numInput = container.val().length + newlineCount;
if(!isWin()){
numInput = container.val().length;
}
numWords = countWord(getCleanedWordString(container.val()));
numLeft = maxCharacters - numInput;
} else {
//normal count, no cut
var newlineCount = getNewlineCount(content);
numInput = container.val().length + newlineCount;
if(!isWin()){
numInput = container.val().length;
}
numWords = countWord(getCleanedWordString(container.val()));
}
return formatDisplayInfo();
}
function formatDisplayInfo(){
var format = options.displayFormat;
format = format.replace('#input', numInput);
format = format.replace('#words', numWords);
//When maxCharacters <= 0, #max, #left cannot be substituted.
if(maxCharacters > 0){
format = format.replace('#max', maxCharacters);
format = format.replace('#left', numLeft);
}
return format;
}
function getInfo(){
var info = {
input: numInput,
max: maxCharacters,
left: numLeft,
words: numWords
};
return info;
}
function getNextCharLeftInformation(container){
return container.next('.charleft');
}
function isWin(){
var strOS = navigator.appVersion;
if (strOS.toLowerCase().indexOf('win') != -1){
return true;
}
return false;
}
function getNewlineCount(content){
var newlineCount = 0;
for(var i=0; i<content.length;i++){
if(content.charAt(i) == '\n'){
newlineCount++;
}
}
return newlineCount;
}
function getCleanedWordString(content){
var fullStr = content + " ";
var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
var splitString = cleanedStr.split(" ");
return splitString;
}
function countWord(cleanedWordString){
var word_count = cleanedWordString.length-1;
return word_count;
}
};
})(jQuery);

@ -32,7 +32,7 @@ require_once 'wiki.inc.php';
$htmlHeadXtra[] ='<link rel="stylesheet" type="text/css" href="'.api_get_path(WEB_CODE_PATH).'wiki/css/default.css"/>';
// javascript for advanced parameters menu
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-1.4.4.min.js" type="text/javascript" language="javascript"></script>'; //jQuery
$htmlHeadXtra[] = '<script type="text/javascript" language="javascript">
function advanced_parameters() {
if(document.getElementById(\'options\').style.display == \'none\') {

Loading…
Cancel
Save