]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14279: use get_file_url instead of checking $CFG->slashargument manually (merge...
authorscyrma <scyrma>
Thu, 10 Jul 2008 09:55:11 +0000 (09:55 +0000)
committerscyrma <scyrma>
Thu, 10 Jul 2008 09:55:11 +0000 (09:55 +0000)
30 files changed:
backup/restorelib.php
blog/lib.php
blog/rsslib.php
file.php
files/index.php
lib/editor/htmlarea/coursefiles.php
lib/filelib.php
lib/questionlib.php
lib/rsslib.php
lib/weblib.php
lib/wiki_to_markdown.php
mod/data/field/file/field.class.php
mod/data/field/picture/field.class.php
mod/data/preset_class.php
mod/forum/lib.php
mod/forum/rsslib.php
mod/glossary/lib.php
mod/hotpot/lib.php
mod/lesson/importppt.php
mod/lesson/mediafile.php
mod/resource/type/file/resource.class.php
mod/resource/type/ims/resource.class.php
mod/scorm/loadSCO.php
question/export.php
question/format/hotpot/format.php
question/format/qti2/format.php
question/format/qti2/qt_common.php
theme/standardlogo/header.html
userpix/index.php
userpix/upgrade.php

index 1f8132a96b20999cf8eeadb9330c4476a1b160e1..95ffc51ddbe0378a9b9d5b0f13583f972b271a73 100644 (file)
@@ -3636,6 +3636,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
     //finished to know all the oldid, newid equivaleces
     function restore_decode_absolute_links($content) {
         global $CFG, $restore;
+        require_once($CFG->libdir.'/filelib.php');
 
     /// MDL-14072: Prevent NULLs, empties and numbers to be processed by the
     /// heavy interlinking. Just a few cpu cycles saved.
@@ -3649,17 +3650,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
 
         //Now decode wwwroot and file.php calls
         $search = array ("$@FILEPHP@$");
-
-        //Check for the status of the slasharguments config variable
-        $slash = $CFG->slasharguments;
-
-        //Build the replace string as needed
-        if ($slash == 1) {
-            $replace = array ($CFG->wwwroot."/file.php/".$restore->course_id);
-        } else {
-            $replace = array ($CFG->wwwroot."/file.php?file=/".$restore->course_id);
-        }
-
+        $replace = array(get_file_url($restore->course_id));
         $result = str_replace($search,$replace,$content);
 
         if ($result != $content && debugging()) {                                  //Debug
index 08822530c1e630c6b07c499ef55426cfbbfc79f8..f37e084f58a6a97f86d7d3299bdbce8aa62dd057 100755 (executable)
                     include_once($CFG->libdir.'/filelib.php');
                     $icon = mimeinfo("icon", $file);
                     $type = mimeinfo("type", $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");
                     $image = "<img src=\"$CFG->pixpath/f/$icon\" class=\"icon\" alt=\"\" />";
 
                     if ($return == "html") {
index 0b2119b4874626a55e23bf7a9871b44906bdaadc..a0ad2dc09c67edaa632d86dfa4bd10584bde859b 100755 (executable)
         $path .= '/rss.xml';
         $rsspix = $CFG->pixpath .'/i/rss.gif';
 
-        if ($CFG->slasharguments) {
-            $path = $CFG->wwwroot.'/rss/file.php/'.$path;
-        } else {
-            $path = $CFG->wwwroot.'/rss/file.php?file='.$path;
-        }
+        require_once($CFG->libdir.'/filelib.php');
+        $path = get_file_url($path, null, 'rssfile');
         print '<div align="right"><a href="'. $path .'"><img src="'. $rsspix .'" title="'. strip_tags($tooltiptext) .'" alt="'.get_string('rss').'" /></a></div>';
 
     }
index 51cc06247e3472cebdfdf40f36f263ef25283d4b..23e484983a1b1396483d8f79bc3fd650c97a76e2 100644 (file)
--- a/file.php
+++ b/file.php
@@ -1,5 +1,9 @@
 <?php // $Id$
       // This script fetches files from the dataroot directory
+      //
+      // You should use the get_file_url() function, available in lib/filelib.php, to link to file.php.
+      // This ensures proper formatting and offers useful options.
+      //
       // Syntax:      file.php/courseid/dir/dir/dir/filename.ext
       //              file.php/courseid/dir/dir/dir/filename.ext?forcedownload=1 (download instead of inline)
       //              file.php/courseid/dir (returns index.html from dir)
index a0f055500b8030eca64c5e1dc3eb00309b2dc994..69e148b9f0c538bf6da7e0cd35c0fdd5e913fece 100644 (file)
@@ -812,11 +812,8 @@ function displaydir ($wdir) {
 
             print_cell("center", "<input type=\"checkbox\" name=\"file$count\" value=\"$fileurl\" />", 'checkbox');
             echo "<td align=\"left\" style=\"white-space:nowrap\" class=\"name\">";
-            if ($CFG->slasharguments) {
-                $ffurl = str_replace('//', '/', "/file.php/$id/$fileurl");
-            } else {
-                $ffurl = str_replace('//', '/', "/file.php?file=/$id/$fileurl");
-            }
+
+            $ffurl = str_replace('//', '/', get_file_url("$id/$fileurl"));
             link_to_popup_window ($ffurl, "display",
                                   "<img src=\"$CFG->pixpath/f/$icon\" class=\"icon\" alt=\"$strfile\" />&nbsp;".htmlspecialchars($file),
                                   480, 640);
index 7a818f50d2cd5dc39729e8be04dd7de3902e715a..2a8496eaa16d9aaf55fc0fe8c8bbcbdb0d244567 100644 (file)
@@ -755,17 +755,13 @@ function displaydir ($wdir) {
                 print_cell("center", "<input type=\"checkbox\" name=\"file$count\" value=\"$fileurl\" onclick=\";return set_rename('$file');\" />");
             }
             echo "<td align=\"left\" nowrap=\"nowrap\">";
-            if ($CFG->slasharguments) {
-                $ffurl = "/file.php/$id$fileurl";
-            } else {
-                $ffurl = "/file.php?file=/$id$fileurl";
-            }
+            $ffurl = get_file_url($id$fileurl);
             link_to_popup_window ($ffurl, "display",
                                   "<img src=\"$CFG->pixpath/f/$icon\" class=\"icon\" alt=\"$strfile\" />",
                                   480, 640);
             $file_size = filesize($filename);
 
-            echo "<a onclick=\"return set_value(info = {url: '".$CFG->wwwroot.$ffurl."',";
+            echo "<a onclick=\"return set_value(info = {url: '".$ffurl."',";
             echo " isize: '".$file_size."', itype: '".$imgtype."', iwidth: '".$imgwidth."',";
             echo " iheight: '".$imgheight."', imodified: '".$filedate."' })\" href=\"#\">$file</a>";
             echo "</td>\n";
index 53c01e60bc75045873f20ee87c0afadaa1ecf41c..1adf6803bdff50c330b23b74781691aaa9830395 100644 (file)
@@ -9,20 +9,35 @@ function get_file_url($path, $options=null, $type='coursefile') {
 
     // type of file
     switch ($type) {
-        case 'coursefile':
+       case 'questionfile':
+            $url = $CFG->wwwroot."/question/exportfile.php";
+            break;
+       case 'rssfile':
+            $url = $CFG->wwwroot."/rss/file.php";
+            break;
+        case 'user':
+            $url = $CFG->wwwroot."/user/pix.php";
+            break;
+        case 'usergroup':
+            $url = $CFG->wwwroot."/user/pixgroup.php";
+            break;
+        case 'httpscoursefile':
+            $url = $CFG->httpswwwroot."/file.php";
+            break;
+         case 'coursefile':
         default:
-            $url = "$CFG->wwwroot/file.php";
+            $url = $CFG->wwwroot."/file.php";
     }
 
     if ($CFG->slasharguments) {
         $parts = explode('/', $path);
         $parts = array_map('rawurlencode', $parts);
         $path  = implode('/', $parts);
-        $ffurl = "$CFG->wwwroot/file.php/$path";
+        $ffurl = $url.'/'.$path;
         $separator = '?';
     } else {
-        $path = rawurlencode("/$path");
-        $ffurl = "$CFG->wwwroot/file.php?file=$path";
+        $path = rawurlencode('/'.$path);
+        $ffurl = $url.'?file='.$path;
         $separator = '&amp;';
     }
 
index 670dbb262f24d06ed2a0e8d7b66df20d132adc44..ce91e500f3013943c7856e38668fc5a464a326e0 100644 (file)
@@ -1558,12 +1558,10 @@ function get_question_image($question) {
         if (substr(strtolower($question->image), 0, 7) == 'http://') {
             $img .= $question->image;
 
-        } else if ($CFG->slasharguments) {        // Use this method if possible for better caching
-            $img .= "$CFG->wwwroot/file.php/$coursefilesdir/$question->image";
-
         } else {
-            $img .= "$CFG->wwwroot/file.php?file=/$coursefilesdir/$question->image";
-        }
+            require_once($CFG->libdir .'/filelib.php');
+            $img = get_file_url("$courseid/{$question->image}");
+        }      
     }
     return $img;
 }
@@ -2363,12 +2361,8 @@ function question_url_check($url){
  */
 function question_replace_file_links_in_html($html, $fromcourseid, $tocourseid, $url, $destination, &$changed){
     global $CFG;
-    if ($CFG->slasharguments) {        // Use this method if possible for better caching
-        $tourl = "$CFG->wwwroot/file.php/$tocourseid/$destination";
-
-    } else {
-        $tourl = "$CFG->wwwroot/file.php?file=/$tocourseid/$destination";
-    }
+    require_once($CFG->libdir .'/filelib.php');
+    $tourl = get_file_url("$tocourseid/$destination");
     $fromurl = question_file_links_base_url($fromcourseid).preg_quote($url, '!');
     $searchfor = array('!(<\s*(a|img)\s[^>]*(href|src)\s*=\s*")'.$fromurl.'(")!i',
                    '!(<\s*(a|img)\s[^>]*(href|src)\s*=\s*\')'.$fromurl.'(\')!i');
index d70cfa8a76c9d43cd692feb524ace74a1f110ae4..d615aab835914c0b51b15e9f646bc679e59e2d20 100644 (file)
@@ -29,12 +29,8 @@ function rss_get_link($courseid, $userid, $modulename, $id, $tooltiptext='') {
  */
 function rss_get_url($courseid, $userid, $modulename, $id) {
     global $CFG;
-    if ($CFG->slasharguments) {
-        $rsspath = "$CFG->wwwroot/rss/file.php/$courseid/$userid/$modulename/$id/rss.xml";
-    } else {
-        $rsspath = "$CFG->wwwroot/rss/file.php?file=/$courseid/$userid/$modulename/$id/rss.xml";
-    }
-    return $rsspath;
+    require_once($CFG->libdir.'/filelib.php');
+    return get_file_url($courseid.'/'.$userid.'/'.$modulename.'/'.$id.'/rss.xml', null, 'rssfile');
 }
 
 /**
index fe732d4f9dd200363f063ca2e74c2a2b24f9babc..e5f2ab12f42fd1f23c980e937331855fd29dbfc1 100644 (file)
@@ -4226,11 +4226,8 @@ function print_file_picture($path, $courseid=0, $height='', $width='', $link='',
 
     } else if ($courseid) {
         $output .= '<img style="height:'.$height.'px;width:'.$width.'px;" src="';
-        if ($CFG->slasharguments) {        // Use this method if possible for better caching
-            $output .= $CFG->wwwroot .'/file.php/'. $courseid .'/'. $path;
-        } else {
-            $output .= $CFG->wwwroot .'/file.php?file=/'. $courseid .'/'. $path;
-        }
+        require_once($CFG->libdir.'/filelib.php');
+        $output .= get_file_url("$courseid/$path");
         $output .= '" />';
     } else {
         $output .= 'Error: must pass URL or course';
@@ -4330,11 +4327,8 @@ function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=fa
     }
 
     if ($picture) {  // Print custom user picture
-        if ($CFG->slasharguments) {        // Use this method if possible for better caching
-            $src =  $wwwroot .'/user/pix.php/'. $user->id .'/'. $file .'.jpg';
-        } else {
-            $src =  $wwwroot .'/user/pix.php?file=/'. $user->id .'/'. $file .'.jpg';
-        }
+        require_once($CFG->libdir.'/filelib.php');
+        $src = get_file_url($user->id.'/'.$file.'.jpg', null, 'user');
     } else {         // Print default user pictures (use theme version if available)
         $class .= " defaultuserpic";
         $src =  "$CFG->pixpath/u/$file.png";
@@ -4536,13 +4530,10 @@ function print_group_picture($group, $courseid, $large=false, $return=false, $li
         $size = 35;
     }
     if ($group->picture) {  // Print custom group picture
-        if ($CFG->slasharguments) {        // Use this method if possible for better caching
-            $output .= '<img class="grouppicture" src="'.$CFG->wwwroot.'/user/pixgroup.php/'.$group->id.'/'.$file.'.jpg"'.
-                       ' style="width:'.$size.'px;height:'.$size.'px;" alt="'.s(get_string('group').' '.$group->name).'" title="'.s($group->name).'"/>';
-        } else {
-            $output .= '<img class="grouppicture" src="'.$CFG->wwwroot.'/user/pixgroup.php?file=/'.$group->id.'/'.$file.'.jpg"'.
-                       ' style="width:'.$size.'px;height:'.$size.'px;" alt="'.s(get_string('group').' '.$group->name).'" title="'.s($group->name).'"/>';
-        }
+        require_once($CFG->libdir.'/filelib.php');
+        $grouppictureurl = get_file_url($group->id.'/'.$file.'.jpg', null, 'usergroup');
+        $output .= '<img class="grouppicture" src="'.$grouppictureurl.'"'.
+            ' style="width:'.$size.'px;height:'.$size.'px;" alt="'.s(get_string('group').' '.$group->name).'" title="'.s($group->name).'"/>';
     }
     if ($link or has_capability('moodle/site:accessallgroups', $context)) {
         $output .= '</a>';
index 55458b0ca9f9c1515cad7205877158fa7c36ca1d..6c35633b09b88e87aa3c35e9831c09ba8439162a 100644 (file)
@@ -264,24 +264,16 @@ class WikiToMarkdown {
     $line = eregi_replace( " ([a-zA-Z]+):([0-9]+)\(([^)]+)\)",
        " [\\3](".$CFG->wwwroot."/mod/\\1/view.php?id=\\2) ", $line );
 
+    require_once($CFG->libdir.'/filelib.php');
+    $coursefileurl = get_file_url($this->courseid);
+
     // Replace picture resource link 
-    if ($CFG->slasharguments) {
-      $line = eregi_replace( "/([a-zA-Z0-9./_-]+)(png|gif|jpg)\(([^)]+)\)",
-        "![\\3]($CFG->wwwroot/file.php/$this->courseid/\\1\\2)", $line );
-    } else {
-      $line = eregi_replace( "/([a-zA-Z0-9./_-]+)(png|gif|jpg)\(([^)]+)\)",
-        "![\\3]($CFG->wwwroot/file.php?file=/$this->courseid/\\1\\2)", $line );
-    }
+    $line = eregi_replace( "/([a-zA-Z0-9./_-]+)(png|gif|jpg)\(([^)]+)\)",
+            "![\\3](".$coursefileurl."/\\1\\2)", $line );
 
     // Replace file resource link
-    if ($CFG->slasharguments) {
-      $line = eregi_replace( "file:/([[:alnum:]/._-]+)\(([^)]+)\)",
-        "[\\2]($CFG->wwwroot/file.php/$this->courseid/\\1)", $line );
-    } else {
-      $line = eregi_replace( "file:/([[:alnum:]/._-]+)\(([^)]+)\)",
-        "[\\2]($CFG->wwwroot/file.php?file=/$this->courseid/\\1)", $line );
-    }
+    $line = eregi_replace( "file:/([[:alnum:]/._-]+)\(([^)]+)\)",
+            "[\\2](".$coursefileurl."/\\1)", $line );
 
     return $line;
   }
index ca9a68c77e8206ffa51d32d89fade7960d70a309..fff1789db36a8a36803a4abc40eb65e3c5397edf 100755 (executable)
@@ -42,12 +42,8 @@ class data_field_file extends data_field_base {
             $src         = empty($contents[0]) ? '' : $contents[0];
             $name        = empty($contents[1]) ? $src : $contents[1];
             $displayname = empty($contents[1]) ? '' : $contents[1];
-            $path = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid;
-            if ($CFG->slasharguments) {
-                $source = $CFG->wwwroot.'/file.php/'.$path;
-            } else {
-                $source = $CFG->wwwroot.'/file.php?file=/'.$path;
-            }
+            require_once($CFG->libdir.'/filelib.php');
+            $source = get_file_url($this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid);
         } else {
             $src = '';
             $name = '';
index 60872d604a75d2ecc1861c6b99a7e66155f6b221..6bc8b1c2e2d7014469a65c96c8bb2b7100f26830 100755 (executable)
@@ -46,11 +46,8 @@ class data_field_picture extends data_field_file {
                 $description = $content->content1;
             }
             $path = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid;
-            if ($CFG->slasharguments) {
-                $filepath = $CFG->wwwroot.'/file.php/'.$path.'/'.$filename;
-            } else {
-                $filepath = $CFG->wwwroot.'/file.php?file=/'.$path.'/'.$filename;
-            }
+            require_once($CFG->libdir.'/filelib.php');
+            $filepath = get_file_url("$path/$filename");
         }
         $str = '<div title="'.s($this->field->description).'">';
         $str .= '<fieldset><legend><span class="accesshide">'.$this->field->name.'</span></legend>';
@@ -102,14 +99,11 @@ class data_field_picture extends data_field_file {
             $title = empty($contents[1])? '':$contents[1];
             $src = $contents[0];
             $path = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid;
-            $thumbnaillocation = $CFG->dataroot .'/'.$this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid.'/thumb/'.$src;
-            if ($CFG->slasharguments) {
-                $source = $CFG->wwwroot.'/file.php/'.$path.'/'.$src;
-                $thumbnailsource = file_exists($thumbnaillocation) ? $CFG->wwwroot.'/file.php/'.$path.'/thumb/'.$src : $source;
-            } else {
-                $source = $CFG->wwwroot.'/file.php?file=/'.$path.'/'.$src;
-                $thumbnailsource = file_exists($thumbnaillocation) ? $CFG->wwwroot.'/file.php?file=/'.$path.'/thumb/'.$src : $source;
-            }
+
+            $thumbnaillocation = $CFG->dataroot .'/'. $path .'/thumb/'.$src;
+            require_once($CFG->libdir.'/filelib.php');
+            $source = get_file_url("$path/$src");
+            $thumbnailsource = file_exists($thumbnaillocation) ? get_file_url("$path/thumb/$src") : $source;
 
             if ($template == 'listtemplate') {
                 $width = $this->field->param4 ? ' width="'.s($this->field->param4).'" ' : ' ';
index 8d73098f31798621e976bcb93760c6b7ce55346f..8b65f242391ec9a18e2286cb49c3d04a5e9c2313 100644 (file)
@@ -711,7 +711,8 @@ class Data_Preset
             print_error('movezipfailed', 'data'); 
         }
         
-        $html .= '<a href="' . $CFG->wwwroot . '/file.php/' . $course->id . '/moddata/data/' . $this->data->id . '/preset.zip">'.get_string('download', 'data')."</a>";
+        require_once($CFG->libdir.'/filelib.php');
+        $html .= '<a href="'. get_file_url($course->id .'/moddata/data/'. $this->data->id .'/preset.zip') .'">'. get_string('download', 'data') .'</a>';
         $html .= '</div>'; 
         return $html;
     }
index 29ff1f37e1c2e009ed73744c2f830075d57ded8b..518bbe505e60f714f981c1159b14d4dc148f5ced 100644 (file)
@@ -3716,11 +3716,7 @@ function forum_print_attachments($post, $return=NULL) {
             foreach ($files as $file) {
                 $icon = mimeinfo("icon", $file);
                 $type = mimeinfo("type", $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");
                 $image = "<img src=\"$CFG->pixpath/f/$icon\" class=\"icon\" alt=\"\" />";
 
                 if ($return == "html") {
index e946649abc43cf5fa5c453fecf9d45fb54fe864e..7b8d606feda959350f08a6a6d0b87357da8f76f9 100644 (file)
             $formatoptions = new object;
             $formatoptions->trusttext = true;
 
+            require_once($CFG->libdir.'/filelib.php');
+
             foreach ($recs as $rec) {
                 unset($item);
                 unset($user);
                     $item->attachments = array();
                     foreach ($post_files as $file) {
                         $attachment = new stdClass;
-                        if ($CFG->slasharguments) {
-                            $attachment->url = "{$CFG->wwwroot}/file.php/$post_file_area_name/$file";
-                        } else {
-                            $attachment->url = "{$CFG->wwwroot}/file.php?file=/$post_file_area_name/$file";
-                        }
+                        $attachment->url = get_file_url($post_file_area_name.'/'.$file);
                         $attachment->length = filesize("$CFG->dataroot/$post_file_area_name/$file");
                         $item->attachments[] = $attachment;
                     }
index 009b910188aa17081609db9769df12d4ce003e8b..e09f7e40f9ab96d2497c00fd61df690a1bef2048 100644 (file)
@@ -1222,11 +1222,7 @@ function glossary_print_attachments($entry, $return=NULL, $align="left") {
             $strattachment = get_string("attachment", "glossary");
             foreach ($files as $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");
                 $image = "<img src=\"$CFG->pixpath/f/$icon\" class=\"icon\" alt=\"\" />";
 
                 if ($return == "html") {
index 437c31593f1430c01bfa36f338a1d6079edb6b18..c7b8cbe0510ec2b55889260b4601492463aa99b2 100644 (file)
@@ -1803,11 +1803,8 @@ class hotpot_xml_quiz extends hotpot_xml_tree {
         // set the url base (first time only)
         if (!isset($this->baseurl)) {
             global $CFG;
-            if ($CFG->slasharguments) {
-                $this->baseurl = "$CFG->wwwroot/file.php/$this->filedir/";
-            } else {
-                $this->baseurl = "$CFG->wwwroot/file.php?file=/$this->filedir/";
-            }
+            require_once($CFG->libdir.'/filelib.php');
+            $this->baseurl = get_file_url($this->filedir .'/');
         }
         return $this->baseurl;
     }
index b2931044cdf3d449b53d5e5d6a1c0dba18ceee6e..8f6a4287673a23c976ca85e4201c36e7b1a944ad 100644 (file)
@@ -195,11 +195,8 @@ function extract_data($pages, $courseid, $lessonname, $modname) {
     
     $imagedir = $CFG->dataroot.'/'.$courseid.'/moddata/'.$modname;
     
-    if ($CFG->slasharguments) {
-        $imagelink = $CFG->wwwroot.'/file.php/'.$courseid.'/moddata/'.$modname;
-    } else {
-        $imagelink = $CFG->wwwroot.'/file.php?file=/'.$courseid.'/moddata/'.$modname;
-    }
+    require_once($CFG->libdir .'/filelib.php');
+    $imagelink = get_file_url($courseid.'/moddata/'.$modname);
     
     // try to make a unique subfolder to store the images
     $lessonname = str_replace(' ', '_', $lessonname); // get rid of spaces
index 26fd50ca008adaf203223ec9fc8f0e2d56cc3553..a8cdcefc8b16d02eeb50cc00a771c69e7e283947 100644 (file)
     if (is_url($lesson->mediafile)) {
         $fullurl = $lesson->mediafile;        
     } else {
-        // get the full url to the file while taking into consideration $CFG->slasharguments    
-        if ($CFG->slasharguments) {
-            $relativeurl = "/file.php/{$course->id}/{$lesson->mediafile}";
-        } else {
-            $relativeurl = "/file.php?file=/{$course->id}/{$lesson->mediafile}";
-        }
-        $fullurl = "$CFG->wwwroot$relativeurl";
+        $fullurl = get_file_url($course->id .'/'. $lesson->mediafile);
     }
 
     // find the correct type and print it out
index 47283a0d9cbbf42d2283709baa1e9b1687d4228b..9f5ac4679b82b3f1a17260ef5b1f44adee8674ef 100644 (file)
@@ -262,8 +262,8 @@ class resource_file extends resource_base {
         $isteamspeak = (stripos($resource->reference, 'teamspeak://') === 0);
 
     /// Form the parse string
+        $querys = array();
         if (!empty($resource->alltext)) {
-            $querys = array();
             $parray = explode(',', $resource->alltext);
             foreach ($parray as $fieldstring) {
                 $field = explode('=', $fieldstring);
@@ -307,22 +307,10 @@ class resource_file extends resource_base {
 
         } else {   // Normal uploaded file
             $forcedownloadsep = '?';
-            if ($CFG->slasharguments) {
-                $relativeurl = "/file.php/{$course->id}/{$resource->reference}";
-                if ($querystring) {
-                    $relativeurl .= '?'.$querystring;
-                    $forcedownloadsep = '&amp';
-                }
-            } else {
-                $relativeurl = "/file.php?file=/{$course->id}/{$resource->reference}";
-                if ($querystring) {
-                    $relativeurl .= '&amp;'.$querystring;
-                }
-            }
-            $fullurl = "$CFG->wwwroot$relativeurl";
             if ($resource->options == 'forcedownload') {
-                $fullurl .=  $forcedownloadsep . 'forcedownload=1';
+                $querys[] = 'forcedownload=1';
             }
+            $fullurl = get_file_url($course->id.'/'.$resource->reference, $querys);
         }
 
         /// Print a notice and redirect if we are trying to access a file on a local file system
index ae5dc09d9ba7adde8aa203f8e485a39cf6efb4ef..0ab7c2ba667ce3ee2cd687b8e01680a2a523b5d0 100644 (file)
@@ -508,11 +508,8 @@ class resource_ims extends resource_base {
 
     /// Calculate the file.php correct url
         if (!$this->isrepository) {
-            if ($CFG->slasharguments) {
-                $fileurl = "{$CFG->wwwroot}/file.php/{$course->id}/{$CFG->moddata}/resource/{$resource->id}";
-            } else {
-                $fileurl = "{$CFG->wwwroot}/file.php?file=/{$course->id}/{$CFG->moddata}/resource/{$resource->id}";
-            }
+            require_once($CFG->libdir.'/filelib.php');
+            $fileurl = get_file_url($course->id.'/'.$CFG->moddata.'/resource/'.$resource->id);
         }
         else {
             $fileurl = $CFG->repositorywebroot . $resource->reference;
index 3a40273df9a1b1203aa0ebe2a07d3b80487f6fa1..1df8a94a3d0a310e22a4a6679dd71b6da24561a1 100755 (executable)
             } else {
                 $basedir = $CFG->moddata.'/scorm/'.$scorm->id;
             }
-            if ($CFG->slasharguments) {
-                $result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/'.$basedir.'/'.$launcher;
-            } else {
-                $result = $CFG->wwwroot.'/file.php?file=/'.$scorm->course.'/'.$basedir.'/'.$launcher;
-            }
+            require_once($CFG->libdir.'/filelib.php');
+            $result = get_file_url($scorm->course .'/'. $basedir .'/'. $launcher);
         }
     }
 ?>
index 0406b3b08ae0e4d41ad2eb3bbe80b003d7e39e72..7836e4a4b9c4afc61ac8aef5e74a4afa06c7de74 100644 (file)
             echo '<p><div class="boxaligncenter"><font size="-1">' .
                     get_string('downloadextra', 'quiz') . '</font></div></p>';
         } else {
-            if ($CFG->slasharguments) {
-                $efile = $CFG->wwwroot . '/question/exportfile.php/' . rawurlencode($filename);
-            } else {
-                $efile = $CFG->wwwroot . '/question/exportfile.php/?file=' . rawurlencode($filename);
-            }
-            
+            $efile = get_file_url($filename, null, 'questionfile');
             echo '<p><div class="boxaligncenter">' .
                     get_string('yourfileshoulddownload', 'question', $efile) . '</a></div></p>';
             echo '
index 3ae0dc90f70608c0c8d294859deeb88463c344df..55cada9bdaf287d1f4fad92ca9113a76052da15a 100644 (file)
@@ -43,11 +43,8 @@ class qformat_hotpot extends qformat_default {
                 // shouldn't happen !!
                 $courseid = 0; 
         }
-        if ($CFG->slasharguments) {
-            $baseurl = "$CFG->wwwroot/file.php/$courseid/";
-        } else {
-            $baseurl = "$CFG->wwwroot/file.php?file=/$courseid/";
-        }
+        require_once($CFG->libdir.'/filelib.php');
+        $baseurl = get_file_url($courseid).'/';
 
         // get import file name
         global $params;
index 4e897bb65215faacfd451930e42c5acd1c3fae9a..7488dd967cd2f9c8ed79c71e9d2603d2f46b0987 100644 (file)
@@ -405,6 +405,7 @@ function handle_questions_media(&$questions, $path, $courseid) {
     function quiz_export_prepare_questions($questions, $quizid, $courseid, $shuffleanswers = null) {
         global $CFG;
         // add the answers to the questions and format the image property
+        require_once($CFG->libdir.'/filelib.php');
         foreach ($questions as $key=>$question) {
             $questions[$key] = get_question_data($question);
             $questions[$key]->courseid = $courseid;
@@ -420,11 +421,7 @@ function handle_questions_media(&$questions, $path, $courseid) {
 
                 if ($localfile) {
                     // create the http url that the player will need to access the file
-                    if ($CFG->slasharguments) {        // Use this method if possible for better caching
-                        $questions[$key]->mediaurl = "$CFG->wwwroot/file.php/$question->image";
-                    } else {
-                        $questions[$key]->mediaurl = "$CFG->wwwroot/file.php?file=$question->image";
-                    }
+                    $questions[$key]->mediaurl = get_file_url($question->image);
                 } else {
                     $questions[$key]->mediaurl = $question->image;
                 }
@@ -908,10 +905,9 @@ function xml_entitize(&$collection) {
         global $CFG;
         if (substr(strtolower($file), 0, 7) == 'http://') {
             $url = $file;
-        } else if ($CFG->slasharguments) {        // Use this method if possible for better caching
-            $url = "{$CFG->wwwroot}/file.php/$courseid/{$file}";
         } else {
-            $url = "{$CFG->wwwroot}/file.php?file=/$courseid/{$file}";
+            require_once($CFG->libdir.'/filelib.php');
+            $url = get_file_url("$courseid/$file");
         }
         return $url;
     }
index 10229a2e4af86b04603c87a7d3897c49a88fb100..d83e6016f4c8e309700091c461dab2ffd3f5ff88 100644 (file)
@@ -102,10 +102,9 @@ function get_media_tag($file, $courseid = 0, $alt = 'media file', $width = 0, $h
     // if it's a moodle library file, it will be served through file.php
     if (substr(strtolower($file), 0, 7) == 'http://') {
         $media = $file;
-    } else if ($CFG->slasharguments) {        // Use this method if possible for better caching
-        $media = "{$CFG->wwwroot}/file.php/$courseid/$file";
     } else {
-        $media = "{$CFG->wwwroot}/file.php?file=/$courseid/$file";
+        require_once($CFG->libdir.'/filelib.php');
+        $media = get_file_url("$courseid/$file");
     }
 
     $ismultimedia = false;
index 3ade464c5e43fa1484a0fcbcee43d31832246bd4..bde61b4da56119f67bf2bce4b32f73a8fe255d81 100644 (file)
       } else if (file_exists($CFG->dirroot.'/logo.gif')) {
           $standardlogo = $CFG->httpswwwroot.'/logo.gif';
       } else if (file_exists($CFG->dataroot.'/1/logo.jpg')) {
-          if (empty($CFG->slasharguments)) {
-              $standardlogo = $CFG->httpswwwroot.'/file.php?file=/1/logo.jpg';
-          } else {
-              $standardlogo = $CFG->httpswwwroot.'/file.php/1/logo.jpg';
-          }
+          require_once($CFG->libdir.'/filelib.php');
+          $standardlogo = get_file_url('1/logo.jpg', null, 'httpscoursefile');
       } else if (file_exists($CFG->dataroot.'/1/logo.gif')) {
-          if (empty($CFG->slasharguments)) {
-              $standardlogo = $CFG->httpswwwroot.'/file.php?file=/1/logo.gif';
-          } else {
-              $standardlogo = $CFG->httpswwwroot.'/file.php/1/logo.gif';
-          }
+          require_once($CFG->libdir.'/filelib.php');
+          $standardlogo = get_file_url('1/logo.gif', null, 'httpscoursefile');
       } else {
           $standardlogo = $CFG->httpsthemewww .'/'. current_theme().'/logo.gif';
       }
index 33cb895c9799cbad9f9df8903c6fc21f2883de64..b375de47a2482fec05e8ac5f9c0e04df48a063a4 100644 (file)
         $fullname = fullname($user);
         echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=1\" ".
              "title=\"$fullname\">";
-        if ($CFG->slasharguments) {        // Use this method if possible for better caching
-            echo '<img src="'. $CFG->wwwroot .'/user/pix.php/'.$user->id.'/f1.jpg"'.
-                 ' style="border:0px; width:100px; height:100px" alt="'.$fullname.'" />';
-        } else {
-            echo '<img src="'. $CFG->wwwroot .'/user/pix.php?file=/'. $user->id .'/f1.jpg"'.
-                 ' style="border:0px; width:100px; height:100px" alt="'.$fullname.'" />';
-        }
+        require_once($CFG->libdir.'/filelib.php');
+        $userpictureurl = get_file_url($user->id.'/f1.jpg', null, 'user');
+        echo '<img src="'. $userpictureurl .'"'.
+            ' style="border:0px; width:100px; height:100px" alt="'.$fullname.'" />';
         echo "</a> \n";
     }
 
index e83f2fdba47e4ffb8c06a428ceaee3318fe90361..15d7cf49e174881a840a4ac4e1dbb15304c3d103 100644 (file)
         $fullname = fullname($user);
         echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&amp;course=1\"".
              "title=\"$fullname\">";
-        if ($CFG->slasharguments) {        // Use this method if possible for better caching
-            echo '<img src="'. $CFG->wwwroot .'/user/pix.php/'.$user->id.'/f1.jpg"'.
-                 ' style="border:0px; width:100px; height:100px" alt="'.$fullname.'" />';
-        } else {
-            echo '<img src="'. $CFG->wwwroot .'/user/pix.php?file=/'. $user->id .'/f1.jpg"'.
-                 ' style="border:0px; width:100px; height:100px" alt="'.$fullname.'" />';
-        }
+        require_once($CFG->libdir.'/filelib.php');
+        $userpictureurl = get_file_url($user->id.'/f1.jpg', null, 'user');
+        echo '<img src="'. $userpictureurl .'"'.
+            ' style="border:0px; width:100px; height:100px" alt="'.$fullname.'" />';
         echo "</a> \n";
     }