Feature #306 - Removing the function replace_accents(). This function is not needed anymore.

skala
Ivan Tcholakov 16 years ago
parent fd9314ca09
commit c81137da87
  1. 4
      main/document/document.php
  2. 81
      main/inc/lib/fileUpload.lib.php
  3. 1
      main/newscorm/learnpath.class.php
  4. 3
      main/newscorm/lp_admin_view.php
  5. 2
      main/wiki/wiki.inc.php
  6. 15
      main/work/work.lib.php
  7. 8
      main/work/work.php
  8. 8
      tests/main/inc/lib/fileUpload.lib.test.php

@ -515,9 +515,7 @@ if($is_allowed_to_edit || $group_member_with_upload_rights) // TEACHER ONLY
{ {
$added_slash = ($curdirpath=='/')?'':'/'; $added_slash = ($curdirpath=='/')?'':'/';
$dir_name = $curdirpath.$added_slash.replace_dangerous_char($post_dir_name); $dir_name = $curdirpath.$added_slash.replace_dangerous_char($post_dir_name);
$clean_val=disable_dangerous_file($dir_name); $dir_name = disable_dangerous_file($dir_name);
$clean_val=replace_accents($dir_name);
$dir_name=$clean_val;
$dir_check=$base_work_dir.''.$dir_name; $dir_check=$base_work_dir.''.$dir_name;
if(!is_dir($dir_check)) if(!is_dir($dir_check))

@ -248,50 +248,49 @@ function handle_uploaded_document($_course,$uploaded_file,$base_work_dir,$upload
} }
else else
{ {
//clean up the name and prevent dangerous files //clean up the name, only ASCII characters should stay.
//remove strange characters $clean_name = replace_dangerous_char($uploaded_file['name']);
$clean_name = replace_dangerous_char($uploaded_file['name']); //no "dangerous" files
$clean_name = replace_accents($clean_name); $clean_name = disable_dangerous_file($clean_name);
//no "dangerous" files if(!filter_extension($clean_name))
$clean_name = disable_dangerous_file($clean_name); {
if(!filter_extension($clean_name)) Display::display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
{
Display::display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
return false;
}
else
{
//extension is good
//echo "<br/>clean name = ".$clean_name;
//echo "<br/>upload_path = ".$upload_path;
//if the upload path differs from / (= root) it will need a slash at the end
if ($upload_path!='/')
$upload_path = $upload_path.'/';
//echo "<br/>upload_path = ".$upload_path;
$file_path = $upload_path.$clean_name;
//echo "<br/>file path = ".$file_path;
//full path to where we want to store the file with trailing slash
$where_to_save = $base_work_dir.$upload_path;
//at least if the directory doesn't exist, tell so
if(!is_dir($where_to_save)){
Display::display_error_message(get_lang('DestDirectoryDoesntExist').' ('.$upload_path.')');
return false; return false;
} }
//echo "<br/>where to save = ".$where_to_save; else
// full path of the destination {
$store_path = $where_to_save.$clean_name; //extension is good
//echo "<br/>store path = ".$store_path; //echo "<br/>clean name = ".$clean_name;
//name of the document without the extension (for the title) //echo "<br/>upload_path = ".$upload_path;
$document_name = get_document_title($uploaded_file['name']); //if the upload path differs from / (= root) it will need a slash at the end
//size of the uploaded file (in bytes) if ($upload_path!='/') {
$file_size = $uploaded_file['size']; $upload_path = $upload_path.'/';
}
$files_perm = api_get_setting('permissions_for_new_files'); //echo "<br/>upload_path = ".$upload_path;
$files_perm = octdec(!empty($files_perm)?$files_perm:'0770'); $file_path = $upload_path.$clean_name;
//echo "<br/>file path = ".$file_path;
//full path to where we want to store the file with trailing slash
$where_to_save = $base_work_dir.$upload_path;
//at least if the directory doesn't exist, tell so
if(!is_dir($where_to_save)){
Display::display_error_message(get_lang('DestDirectoryDoesntExist').' ('.$upload_path.')');
return false;
}
//echo "<br/>where to save = ".$where_to_save;
// full path of the destination
$store_path = $where_to_save.$clean_name;
//echo "<br/>store path = ".$store_path;
//name of the document without the extension (for the title)
$document_name = get_document_title($uploaded_file['name']);
//size of the uploaded file (in bytes)
$file_size = $uploaded_file['size'];
$files_perm = api_get_setting('permissions_for_new_files');
$files_perm = octdec(!empty($files_perm)?$files_perm:'0770');
//what to do if the target file exists //what to do if the target file exists
switch ($what_if_file_exists) switch ($what_if_file_exists)
{ {
//overwrite the file if it exists //overwrite the file if it exists
case 'overwrite': case 'overwrite':
@ -1905,7 +1904,7 @@ $handle=opendir($path);
* @param string The accentuated string * @param string The accentuated string
* @return string The escaped string, not absolutely correct but satisfying * @return string The escaped string, not absolutely correct but satisfying
*/ */
function replace_accents($string, $encoding = null){ function replace_accents($string, $encoding = null) {
/* /*
global $charset; global $charset;
$string = api_htmlentities($string,ENT_QUOTES,$charset); $string = api_htmlentities($string,ENT_QUOTES,$charset);
@ -1918,7 +1917,7 @@ function replace_accents($string, $encoding = null){
/** /**
* @deprecated Use transliteration instead, it is applicable for all languages. * @deprecated Use transliteration instead, it is applicable for all languages.
*/ */
function remove_accents($string, $encoding = null){ function remove_accents($string, $encoding = null) {
/* /*
$string = strtr ( $string, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn"); $string = strtr ( $string, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn");
return $string; return $string;

@ -4931,7 +4931,6 @@ class learnpath {
//is already escaped twice when it gets here //is already escaped twice when it gets here
$title = replace_dangerous_char(stripslashes($_POST['title'])); $title = replace_dangerous_char(stripslashes($_POST['title']));
$title = disable_dangerous_file($title); $title = disable_dangerous_file($title);
$title = replace_accents($title);
$filename = $title; $filename = $title;
$content = $_POST['content_lp']; $content = $_POST['content_lp'];

@ -240,10 +240,9 @@ if (isset($_POST['save_audio']))
$file_name = $_FILES[$key]['name']; $file_name = $_FILES[$key]['name'];
$file_name=stripslashes($file_name); $file_name=stripslashes($file_name);
//add extension to files without one (if possible) //add extension to files without one (if possible)
$file_name=add_ext_on_mime($file_name,$_FILES[$key]['type']); $file_name = add_ext_on_mime($file_name,$_FILES[$key]['type']);
$clean_name = replace_dangerous_char($file_name); $clean_name = replace_dangerous_char($file_name);
$clean_name = replace_accents($clean_name);
//no "dangerous" files //no "dangerous" files
$clean_name = disable_dangerous_file($clean_name); $clean_name = disable_dangerous_file($clean_name);

@ -1718,7 +1718,7 @@ function export2doc($wikiTitle, $wikiContents, $groupId)
} }
$exportDir = api_get_path(SYS_COURSE_PATH).api_get_course_path(). '/document'.$groupPath; $exportDir = api_get_path(SYS_COURSE_PATH).api_get_course_path(). '/document'.$groupPath;
$exportFile = replace_dangerous_char(replace_accents($wikiTitle), 'strict' ) . $groupPart; $exportFile = replace_dangerous_char($wikiTitle, 'strict') . $groupPart;
$wikiContents = stripslashes($wikiContents); $wikiContents = stripslashes($wikiContents);
$wikiContents = trim(preg_replace("/\[\[|\]\]/", " ", $wikiContents)); $wikiContents = trim(preg_replace("/\[\[|\]\]/", " ", $wikiContents));

@ -380,7 +380,7 @@ function display_student_publications_list($work_dir,$sub_course_dir,$currentCou
}else { }else {
$mydir_temp = '/'.$my_sub_dir.$dir; $mydir_temp = '/'.$my_sub_dir.$dir;
} }
$sql_select_directory= "SELECT prop.lastedit_date, id, author, has_properties, view_properties, description, qualification,id FROM ".$iprop_table." prop INNER JOIN ".$work_table." work ON (prop.ref=work.id) WHERE "; $sql_select_directory= "SELECT prop.lastedit_date, id, author, has_properties, view_properties, description, qualification,id FROM ".$iprop_table." prop INNER JOIN ".$work_table." work ON (prop.ref=work.id) WHERE ";
if (!empty($_SESSION['toolgroup'])) { if (!empty($_SESSION['toolgroup'])) {
$sql_select_directory.=" work.post_group_id = '".$_SESSION['toolgroup']."' "; // set to select only messages posted by the user's group $sql_select_directory.=" work.post_group_id = '".$_SESSION['toolgroup']."' "; // set to select only messages posted by the user's group
@ -523,9 +523,8 @@ function display_student_publications_list($work_dir,$sub_course_dir,$currentCou
$values = $form_folder -> exportValues(); $values = $form_folder -> exportValues();
$values = $values['my_group']; $values = $values['my_group'];
$dir_name = disable_dangerous_file($values['dir_name']);
$dir_name = replace_accents($values['dir_name']);
$dir_name = replace_dangerous_char($values['dir_name']); $dir_name = replace_dangerous_char($values['dir_name']);
$dir_name = disable_dangerous_file($dir_name);
update_dir_name($mydir,$dir_name); update_dir_name($mydir,$dir_name);
$mydir = $my_sub_dir.$dir_name; $mydir = $my_sub_dir.$dir_name;
$dir = $dir_name; $dir = $dir_name;
@ -754,9 +753,8 @@ function get_subdirs_list($basedir='',$recurse=0){
$dirs_list = array(); $dirs_list = array();
$dh = opendir($basedir); $dh = opendir($basedir);
while($entry = readdir($dh)) { while($entry = readdir($dh)) {
$entry = replace_accents($entry);
$entry = disable_dangerous_file($entry);
$entry = replace_dangerous_char($entry); $entry = replace_dangerous_char($entry);
$entry = disable_dangerous_file($entry);
if(is_dir($basedir.$entry) && $entry!='..' && $entry!='.') { if(is_dir($basedir.$entry) && $entry!='..' && $entry!='.') {
$dirs_list[] = $entry; $dirs_list[] = $entry;
if($recurse==1) { if($recurse==1) {
@ -1026,10 +1024,9 @@ function update_dir_name($path, $new_name) {
} else { } else {
$path_to_dir .= '/'; $path_to_dir .= '/';
} }
$new_name_filter=Security::remove_XSS($new_name); $new_name = Security::remove_XSS($new_name);
$new_name=replace_accents($new_name_filter); $new_name = replace_dangerous_char($new_name);
$new_name=disable_dangerous_file($new_name_filter); $new_name = disable_dangerous_file($new_name);
//$new_name=replace_dangerous_char($new_name);
my_rename($base_work_dir.'/'.$path,$new_name); my_rename($base_work_dir.'/'.$path,$new_name);
$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);

@ -543,10 +543,10 @@ if (api_is_allowed_to_edit(null,true)) {
include_once (api_get_path(LIBRARY_PATH) . "fileUpload.lib.php"); include_once (api_get_path(LIBRARY_PATH) . "fileUpload.lib.php");
$added_slash = (substr($cur_dir_path, -1, 1) == '/') ? '' : '/'; $added_slash = (substr($cur_dir_path, -1, 1) == '/') ? '' : '/';
$filter_directoy=Security::remove_XSS($_POST['new_dir']); $directory = Security::remove_XSS($_POST['new_dir']);
$directory =disable_dangerous_file($filter_directoy); $directory = replace_dangerous_char($directory);
$directory =replace_accents($filter_directoy); $directory = disable_dangerous_file($directory);
$dir_name = $cur_dir_path . $added_slash . replace_dangerous_char($directory); $dir_name = $cur_dir_path . $added_slash . $directory;
$created_dir = create_unexisting_work_directory($base_work_dir, $dir_name); $created_dir = create_unexisting_work_directory($base_work_dir, $dir_name);
// we insert here the directory in the table $work_table // we insert here the directory in the table $work_table

@ -300,14 +300,6 @@ class TestFileUpload extends UnitTestCase {
ob_end_clean(); ob_end_clean();
} }
function testreplace_accents() {
global $charset;
$string = api_htmlentities($string,ENT_QUOTES,$charset);
$res= replace_accents($string);
$this->assertTrue(is_string($res));
//var_dump($res);
}
function testreplace_img_path_in_html_file() { function testreplace_img_path_in_html_file() {
global $_course; global $_course;
$originalImgPath=''; $originalImgPath='';

Loading…
Cancel
Save