From a689ad487cb47245b0aa7e07df01036b54c70b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Ra=C3=B1a?= Date: Sat, 25 Aug 2012 13:34:05 +0200 Subject: [PATCH] Feature #5346 check space documents size of images and audios before save --- main/document/create_audio.php | 38 +++++++++++++++++-- main/document/save_pixlr.php | 16 ++++++++ main/inc/lib/jpegcam/webcam_receiver.php | 25 ++++++------ main/inc/lib/nanogong/receiver.php | 5 +++ main/inc/lib/svg-edit/extensions/filesave.php | 13 +++++++ .../inc/lib/wami-recorder/record_document.php | 13 +++++++ 6 files changed, 93 insertions(+), 17 deletions(-) diff --git a/main/document/create_audio.php b/main/document/create_audio.php index 031c27b975..9d6cb35696 100644 --- a/main/document/create_audio.php +++ b/main/document/create_audio.php @@ -199,6 +199,7 @@ $(document).ready(function(){ $options = $options_pedia = array(); $selected_language = null; + $options_pedia['defaultmessage'] = get_lang('FirstSelectALanguage');//need read before platform languages while ($row = Database::fetch_array($result_select)) { if (api_get_setting('platformLanguage')==$row['english_name']) { @@ -238,8 +239,8 @@ $(document).ready(function(){ if(Security::remove_XSS($_GET['dt2a'])=='pediaphon'){ //lang default is a default message $selected_language = "defaultmessage"; - $options_pedia['defaultmessage'] =get_lang('FirstSelectALanguage'); - $options['defaultmessage'] =get_lang('FirstSelectALanguage'); + + $options['defaultmessage'] = get_lang('FirstSelectALanguage'); echo '
'; $form = new FormValidator('form2', 'post', null, '', array('id' => 'form2')); @@ -413,9 +414,25 @@ function downloadMP3_google($filepath, $dir) { // 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, file_get_contents("http://translate.google.com/translate_tts?tl=".$clean_lang."&q=".urlencode($clean_text)."")); + file_put_contents($documentPath, $returntext2voice); //add document to database $current_session_id = api_get_session_id(); $groupId=$_SESSION['_gid']; @@ -520,7 +537,20 @@ function downloadMP3_pediaphon($filepath, $dir){ $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); diff --git a/main/document/save_pixlr.php b/main/document/save_pixlr.php index f836a2850c..05aaa3614d 100644 --- a/main/document/save_pixlr.php +++ b/main/document/save_pixlr.php @@ -110,6 +110,22 @@ if(strpos($current_mime, 'image')===false) { } +//make a temporal file for get the file size +$tmpfname = tempnam("/tmp", "CTF"); +$handle = fopen($tmpfname, "w"); +fwrite($handle, $contents); +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); + + //path, file and title $paintFileName = $filename.'.'.$extension; $title = $title.'.'.$extension; diff --git a/main/inc/lib/jpegcam/webcam_receiver.php b/main/inc/lib/jpegcam/webcam_receiver.php index 01bc173e07..5b900b30f8 100644 --- a/main/inc/lib/jpegcam/webcam_receiver.php +++ b/main/inc/lib/jpegcam/webcam_receiver.php @@ -77,20 +77,19 @@ if (!$content) { //make a temporal file for get the file size - -$tmpfname = tempnam("/tmp", "CTF"); -$handle = fopen($tmpfname, "w"); -fwrite($handle, $content); -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())) { + $tmpfname = tempnam("/tmp", "CTF"); + $handle = fopen($tmpfname, "w"); + fwrite($handle, $content); + 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); - die(get_lang('UplNotEnoughSpace')); -} - -//erase temporal file -unlink($tmpfname); //add to disk $fh = fopen($documentPath, 'w') or die("can't open file"); diff --git a/main/inc/lib/nanogong/receiver.php b/main/inc/lib/nanogong/receiver.php index 73417df9a6..379a8de0e0 100644 --- a/main/inc/lib/nanogong/receiver.php +++ b/main/inc/lib/nanogong/receiver.php @@ -57,6 +57,11 @@ if ($nano_user_id!= api_get_user_id() || api_get_user_id()==0 || $nano_user_id== //Do not use here check Fileinfo method because return: text/plain +// Check if there is enough space in the course to save the file +if (!DocumentManager::enough_space(filesize($_FILES['voicefile']['tmp_name']), DocumentManager::get_course_quota())) { + die(get_lang('UplNotEnoughSpace')); +} + if (!file_exists($documentPath)){ //add document to disk move_uploaded_file($_FILES['voicefile']['tmp_name'], $documentPath); diff --git a/main/inc/lib/svg-edit/extensions/filesave.php b/main/inc/lib/svg-edit/extensions/filesave.php index c4e58538cf..09bb14d5ad 100644 --- a/main/inc/lib/svg-edit/extensions/filesave.php +++ b/main/inc/lib/svg-edit/extensions/filesave.php @@ -110,6 +110,19 @@ if (file_exists($saveDir.'/'.$filename.$i.'.'.$extension) && $currentTool=='docu } $documentPath = $saveDir.'/'.$drawFileName; +//make a temporal file for get the file size + $tmpfname = tempnam("/tmp", "CTF"); + $handle = fopen($tmpfname, "w"); + fwrite($handle, $contents); + 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); + //add new document to disk file_put_contents( $documentPath, $contents ); diff --git a/main/inc/lib/wami-recorder/record_document.php b/main/inc/lib/wami-recorder/record_document.php index 720bb87621..3625a2ab99 100644 --- a/main/inc/lib/wami-recorder/record_document.php +++ b/main/inc/lib/wami-recorder/record_document.php @@ -65,6 +65,19 @@ if (file_exists($saveDir.'/'.$waminame_noex.'.'.$ext)){ $documentPath = $saveDir.'/'.$waminame_to_save; +//make a temporal file for get the file size + $tmpfname = tempnam("/tmp", "CTF"); + $handle = fopen($tmpfname, "w"); + fwrite($handle, $content); + 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); + //add to disk $fh = fopen($documentPath, 'w') or die("can't open file");