]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13792 - Commiting Patch by Skodak, fixing problem with japanese characters under...
authorscyrma <scyrma>
Tue, 8 Apr 2008 03:04:52 +0000 (03:04 +0000)
committerscyrma <scyrma>
Tue, 8 Apr 2008 03:04:52 +0000 (03:04 +0000)
comes foward with bugs related to this, it will need to be changed everywhere else where there is no urlencoding done at this time. (merge from 1.8
and 1.9)

lib/filelib.php
mod/assignment/lib.php
mod/assignment/type/upload/assignment.class.php
mod/assignment/type/uploadsingle/assignment.class.php

index c4e5d5268f30d3d034a09da0e972eb62347cc7a4..55ceabcfa64703ce41613f4ab917121106b5ef81 100644 (file)
@@ -2,6 +2,40 @@
 
 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 = '&amp;';
+    }
+
+    if ($options) {
+        foreach ($options as $name=>$value) {
+            $ffurl = $ffurl.$separator.$name.'='.$value;
+            $separator = '&amp;';
+        }
+    }
+
+    return $ffurl;
+}
+
 /**
  * Fetches content of file from Internet (using proxy if defined). Uses cURL extension if present.
  * Due to security concerns only downloads from http(s) sources are supported.
index 193286513a57e794a1d9ce4510f190e8cd0e00e4..1dbd08f7cf6d22307612e924dc908ae683c0137c 100644 (file)
@@ -1684,12 +1684,7 @@ class assignment_base {
                 foreach ($files as $key => $file) {
 
                     $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 .= '<img src="'.$CFG->pixpath.'/f/'.$icon.'" class="icon" alt="'.$icon.'" />'.
                             '<a href="'.$ffurl.'" >'.$file.'</a><br />';
index 428d4aed644b41139233698829409a4b43d1dc7b..aaa0f335c63d82a08c8f28919ae89523ee62eab0 100644 (file)
@@ -300,10 +300,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 .= '<a href="'.$ffurl.'" ><img class="icon" src="'.$CFG->pixpath.'/f/'.$icon.'" alt="'.$icon.'" />'.$file.'</a>&nbsp;';
                 }
             }
@@ -361,9 +361,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 .= '<a href="'.$ffurl.'" ><img src="'.$CFG->pixpath.'/f/'.$icon.'" class="icon" alt="'.$icon.'" />'.$file.'</a>';
 
@@ -419,7 +417,7 @@ class assignment_upload extends assignment_base {
 
                     $icon = mimeinfo('icon', $file);
 
-                    $ffurl   = "$CFG->wwwroot/file.php?file=/$filearea/$file";
+                    $ffurl = get_file_url("$filearea/$file");
 
                     $output .= '<a href="'.$ffurl.'" ><img src="'.$CFG->pixpath.'/f/'.$icon.'" alt="'.$icon.'" />'.$file.'</a>';
 
index c6624e714e06912b526c8c4c0d3bd188f0672d5a..cf71718524486c1df8c78304993197298352e6bf 100644 (file)
@@ -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);
+                    $ffurl = get_file_url("$filearea/$file");
 
-                    if ($CFG->slasharguments) {
-                        $ffurl = "$CFG->wwwroot/file.php/$filearea/$file";
-                    } else {
-                        $ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file";
-                    }
                     //died right here
                     //require_once($ffurl);
                     $output = '<img src="'.$CFG->pixpath.'/f/'.$icon.'" class="icon" alt="'.$icon.'" />'.