From 0f4aa108d9a43abc3d14c5faab2e54335cfabc9f Mon Sep 17 00:00:00 2001 From: scyrma Date: Tue, 8 Apr 2008 03:00:30 +0000 Subject: [PATCH] MDL-13792 - Commiting Patch by Skodak, fixing problem with japanese characters under some conditions. This has been reported to work, if nobody else comes foward with bugs related to this, it will need to be changed everywhere else where there is no urlencoding done at this time. --- lib/filelib.php | 34 +++++++++++++++++++ mod/assignment/lib.php | 8 ++--- .../type/upload/assignment.class.php | 11 +++--- .../type/uploadsingle/assignment.class.php | 11 ++---- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/lib/filelib.php b/lib/filelib.php index 8a384d7eda8..131c96649a5 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -4,6 +4,40 @@ require_once($CFG->libdir.'/libcurlemu/libcurlemu.inc.php'); // might be moved t define('BYTESERVING_BOUNDARY', 's1k2o3d4a5k6s7'); //unique string constant +function get_file_url($path, $options=null, $type='coursefile') { + global $CFG; + + $path = trim($path, '/'); // no leading and trailing slashes + + // type of file + switch ($type) { + case 'coursefile': + default: + $url = "$CFG->wwwroot/file.php"; + } + + if ($CFG->slasharguments) { + $parts = explode('/', $path); + $parts = array_map('urlencode', $parts); + $path = implode('/', $parts); + $ffurl = "$CFG->wwwroot/file.php/$path"; + $separator = '?'; + } else { + $path = urlencode("/$path"); + $ffurl = "$CFG->wwwroot/file.php?file=$path"; + $separator = '&'; + } + + if ($options) { + foreach ($options as $name=>$value) { + $ffurl = $ffurl.$separator.$name.'='.$value; + $separator = '&'; + } + } + + return $ffurl; +} + /** * Fetches content of file from Internet (using proxy if defined). * diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index e6f607e614b..b359978c6f1 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -1494,12 +1494,8 @@ class assignment_base { $icon = mimeinfo('icon', $file); - if ($CFG->slasharguments) { - $ffurl = "$CFG->wwwroot/file.php/$filearea/$file"; - } else { - $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file"; - } - + $ffurl = get_file_url("$filearea/$file", array('forcedownload'=>1)); + $output .= ''.$icon.''. ''.$file.'
'; } diff --git a/mod/assignment/type/upload/assignment.class.php b/mod/assignment/type/upload/assignment.class.php index bd5acaec03d..51ac9c82e3e 100644 --- a/mod/assignment/type/upload/assignment.class.php +++ b/mod/assignment/type/upload/assignment.class.php @@ -265,10 +265,10 @@ class assignment_upload extends assignment_base { } if ($files = get_directory_list($basedir, 'responses')) { + require_once($CFG->libdir.'/filelib.php'); foreach ($files as $key => $file) { - require_once($CFG->libdir.'/filelib.php'); $icon = mimeinfo('icon', $file); - $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file"; + $ffurl = get_file_url("$filearea/$file"); $output .= ''.$icon.''.$file.' '; } } @@ -326,9 +326,7 @@ class assignment_upload extends assignment_base { foreach ($files as $key => $file) { $icon = mimeinfo('icon', $file); - - $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file"; - + $ffurl = get_file_url("$filearea/$file"); $output .= ''.$icon.''.$file.''; @@ -381,8 +379,7 @@ class assignment_upload extends assignment_base { foreach ($files as $key => $file) { $icon = mimeinfo('icon', $file); - - $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file"; + $ffurl = get_file_url("$filearea/$file"); $output .= ''.$icon.''.$file.''; diff --git a/mod/assignment/type/uploadsingle/assignment.class.php b/mod/assignment/type/uploadsingle/assignment.class.php index 853422d1d1f..2ebfc6ed0bb 100644 --- a/mod/assignment/type/uploadsingle/assignment.class.php +++ b/mod/assignment/type/uploadsingle/assignment.class.php @@ -16,17 +16,12 @@ class assignment_uploadsingle extends assignment_base { if ($basedir = $this->file_area($userid)) { if ($files = get_directory_list($basedir)) { - + require_once($CFG->libdir.'/filelib.php'); foreach ($files as $key => $file) { - require_once($CFG->libdir.'/filelib.php'); $icon = mimeinfo('icon', $file); - - if ($CFG->slasharguments) { - $ffurl = "$CFG->wwwroot/file.php/$filearea/$file"; - } else { - $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file"; - } + $ffurl = get_file_url("$filearea/$file"); + //died right here //require_once($ffurl); $output = ''.$icon.''.