diff --git a/main/document/create_audio.php b/main/document/create_audio.php
index 0867240ff6..a2224eabf4 100644
--- a/main/document/create_audio.php
+++ b/main/document/create_audio.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[] = '';
+//jquery textareaCounter
+$htmlHeadXtra[] = '';
+//need jquery for hide menus
+$htmlHeadXtra[] = '';
+
$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 '
';
-
?>
-
+
+
+
+
';
+
+ Display::display_icon('sound.gif', get_lang('CreateAudio')); echo get_lang('HelpText2Audio');
+
+ //Google services
+ echo '
'.get_lang('GoogleAudio').'';
+ echo ' ';
+ echo '';
+ echo '
';
+ echo '
';
+
+ //vozMe services
+
+ echo '
'.get_lang('vozMe').'';
+ echo ' ';
+ echo '';
+
+ echo '
';
+ echo '
';
+
+echo '';
+
Display :: display_footer();
+
+//Functions
+
+/**
+ * This function save a post into a file mp3
+ *
+ * @param $filepath
+ * @param $dir
+ * @author Juan Carlos Raña Trabado
+ * @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);
+ }
+}
?>
\ No newline at end of file
diff --git a/main/document/document.php b/main/document/document.php
index 3d41e4deec..5d1d1d5b57 100755
--- a/main/document/document.php
+++ b/main/document/document.php
@@ -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'){
?>
").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';
// javascript for advanced parameters menu
-$htmlHeadXtra[] = ''; //jQuery
+$htmlHeadXtra[] = ''; //jQuery
$htmlHeadXtra[] = '