diff --git a/backup/restorelib.php b/backup/restorelib.php index 1f8132a96b209..95ffc51ddbe03 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -3636,6 +3636,7 @@ function restore_create_events($restore,$xml_file) { //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 @@ function restore_decode_absolute_links($content) { //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 diff --git a/blog/lib.php b/blog/lib.php index 08822530c1e63..f37e084f58a6a 100755 --- a/blog/lib.php +++ b/blog/lib.php @@ -309,11 +309,7 @@ function blog_print_attachments($blogentry, $return=NULL) { 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 = "pixpath/f/$icon\" class=\"icon\" alt=\"\" />"; if ($return == "html") { diff --git a/blog/rsslib.php b/blog/rsslib.php index 0b2119b487462..a0ad2dc09c67e 100755 --- a/blog/rsslib.php +++ b/blog/rsslib.php @@ -38,11 +38,8 @@ function blog_rss_print_link($filtertype, $filterselect, $tagid=0, $tooltiptext= $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 '
'.get_string('rss').'
'; } diff --git a/file.php b/file.php index 51cc06247e347..23e484983a1b1 100644 --- a/file.php +++ b/file.php @@ -1,5 +1,9 @@ ", 'checkbox'); echo ""; - 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", "pixpath/f/$icon\" class=\"icon\" alt=\"$strfile\" /> ".htmlspecialchars($file), 480, 640); diff --git a/lib/editor/htmlarea/coursefiles.php b/lib/editor/htmlarea/coursefiles.php index 7a818f50d2cd5..2a8496eaa16d9 100644 --- a/lib/editor/htmlarea/coursefiles.php +++ b/lib/editor/htmlarea/coursefiles.php @@ -755,17 +755,13 @@ function displaydir ($wdir) { print_cell("center", ""); } echo ""; - 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", "pixpath/f/$icon\" class=\"icon\" alt=\"$strfile\" />", 480, 640); $file_size = filesize($filename); - echo "wwwroot.$ffurl."',"; + echo "$file"; echo "\n"; diff --git a/lib/filelib.php b/lib/filelib.php index 53c01e60bc750..1adf6803bdff5 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -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 = '&'; } diff --git a/lib/questionlib.php b/lib/questionlib.php index 670dbb262f24d..ce91e500f3013 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -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'); diff --git a/lib/rsslib.php b/lib/rsslib.php index d70cfa8a76c9d..d615aab835914 100644 --- a/lib/rsslib.php +++ b/lib/rsslib.php @@ -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'); } /** diff --git a/lib/weblib.php b/lib/weblib.php index fe732d4f9dd20..e5f2ab12f42fd 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -4226,11 +4226,8 @@ function print_file_picture($path, $courseid=0, $height='', $width='', $link='', } else if ($courseid) { $output .= '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 .= ''.s(get_string('group').' '.$group->name).''; - } else { - $output .= ''.s(get_string('group').' '.$group->name).''; - } + require_once($CFG->libdir.'/filelib.php'); + $grouppictureurl = get_file_url($group->id.'/'.$file.'.jpg', null, 'usergroup'); + $output .= ''.s(get_string('group').' '.$group->name).''; } if ($link or has_capability('moodle/site:accessallgroups', $context)) { $output .= ''; diff --git a/lib/wiki_to_markdown.php b/lib/wiki_to_markdown.php index 55458b0ca9f9c..6c35633b09b88 100644 --- a/lib/wiki_to_markdown.php +++ b/lib/wiki_to_markdown.php @@ -264,24 +264,16 @@ function line_replace( $line ) { $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; } diff --git a/mod/data/field/file/field.class.php b/mod/data/field/file/field.class.php index ca9a68c77e820..fff1789db36a8 100755 --- a/mod/data/field/file/field.class.php +++ b/mod/data/field/file/field.class.php @@ -42,12 +42,8 @@ function display_add_field($recordid=0) { $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 = ''; diff --git a/mod/data/field/picture/field.class.php b/mod/data/field/picture/field.class.php index 60872d604a75d..6bc8b1c2e2d70 100755 --- a/mod/data/field/picture/field.class.php +++ b/mod/data/field/picture/field.class.php @@ -46,11 +46,8 @@ function display_add_field($recordid=0) { $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 = '
'; $str .= '
'.$this->field->name.''; @@ -102,14 +99,11 @@ function display_browse_field($recordid, $template) { $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).'" ' : ' '; diff --git a/mod/data/preset_class.php b/mod/data/preset_class.php index 8d73098f31798..8b65f242391ec 100644 --- a/mod/data/preset_class.php +++ b/mod/data/preset_class.php @@ -711,7 +711,8 @@ function action_export($params) { print_error('movezipfailed', 'data'); } - $html .= ''.get_string('download', 'data').""; + require_once($CFG->libdir.'/filelib.php'); + $html .= ''. get_string('download', 'data') .''; $html .= '
'; return $html; } diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 29ff1f37e1c2e..518bbe505e60f 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -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 = "pixpath/f/$icon\" class=\"icon\" alt=\"\" />"; if ($return == "html") { diff --git a/mod/forum/rsslib.php b/mod/forum/rsslib.php index e946649abc43c..7b8d606feda95 100644 --- a/mod/forum/rsslib.php +++ b/mod/forum/rsslib.php @@ -237,6 +237,8 @@ function forum_rss_feed_posts($forum, $newsince=0) { $formatoptions = new object; $formatoptions->trusttext = true; + require_once($CFG->libdir.'/filelib.php'); + foreach ($recs as $rec) { unset($item); unset($user); @@ -257,11 +259,7 @@ function forum_rss_feed_posts($forum, $newsince=0) { $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; } diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 009b910188aa1..e09f7e40f9ab9 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -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 = "pixpath/f/$icon\" class=\"icon\" alt=\"\" />"; if ($return == "html") { diff --git a/mod/hotpot/lib.php b/mod/hotpot/lib.php index 437c31593f143..c7b8cbe0510ec 100644 --- a/mod/hotpot/lib.php +++ b/mod/hotpot/lib.php @@ -1803,11 +1803,8 @@ function get_baseurl() { // 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; } diff --git a/mod/lesson/importppt.php b/mod/lesson/importppt.php index b2931044cdf3d..8f6a4287673a2 100644 --- a/mod/lesson/importppt.php +++ b/mod/lesson/importppt.php @@ -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 diff --git a/mod/lesson/mediafile.php b/mod/lesson/mediafile.php index 26fd50ca008ad..a8cdcefc8b16d 100644 --- a/mod/lesson/mediafile.php +++ b/mod/lesson/mediafile.php @@ -57,13 +57,7 @@ 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 diff --git a/mod/resource/type/file/resource.class.php b/mod/resource/type/file/resource.class.php index 47283a0d9cbbf..9f5ac4679b82b 100644 --- a/mod/resource/type/file/resource.class.php +++ b/mod/resource/type/file/resource.class.php @@ -262,8 +262,8 @@ function display() { $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 @@ function display() { } else { // Normal uploaded file $forcedownloadsep = '?'; - if ($CFG->slasharguments) { - $relativeurl = "/file.php/{$course->id}/{$resource->reference}"; - if ($querystring) { - $relativeurl .= '?'.$querystring; - $forcedownloadsep = '&'; - } - } else { - $relativeurl = "/file.php?file=/{$course->id}/{$resource->reference}"; - if ($querystring) { - $relativeurl .= '&'.$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 diff --git a/mod/resource/type/ims/resource.class.php b/mod/resource/type/ims/resource.class.php index ae5dc09d9ba7a..0ab7c2ba667ce 100644 --- a/mod/resource/type/ims/resource.class.php +++ b/mod/resource/type/ims/resource.class.php @@ -508,11 +508,8 @@ function print_ims($cm, $course, $items, $resource, $page) { /// 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; diff --git a/mod/scorm/loadSCO.php b/mod/scorm/loadSCO.php index 3a40273df9a1b..1df8a94a3d0a3 100755 --- a/mod/scorm/loadSCO.php +++ b/mod/scorm/loadSCO.php @@ -108,11 +108,8 @@ } 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); } } ?> diff --git a/question/export.php b/question/export.php index 0406b3b08ae0e..7836e4a4b9c4a 100644 --- a/question/export.php +++ b/question/export.php @@ -116,12 +116,7 @@ echo '

' . get_string('downloadextra', 'quiz') . '

'; } 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 '

' . get_string('yourfileshoulddownload', 'question', $efile) . '

'; echo ' diff --git a/question/format/hotpot/format.php b/question/format/hotpot/format.php index 3ae0dc90f7060..55cada9bdaf28 100644 --- a/question/format/hotpot/format.php +++ b/question/format/hotpot/format.php @@ -43,11 +43,8 @@ function readquestions ($lines) { // 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; diff --git a/question/format/qti2/format.php b/question/format/qti2/format.php index 4e897bb65215f..7488dd967cd2f 100644 --- a/question/format/qti2/format.php +++ b/question/format/qti2/format.php @@ -405,6 +405,7 @@ function exportprocess_quiz($quiz, $questions, $result, $submiturl, $course) { 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 quiz_export_prepare_questions($questions, $quizid, $courseid, $shufflea 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 file_full_path($file, $courseid) { 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; } diff --git a/question/format/qti2/qt_common.php b/question/format/qti2/qt_common.php index 10229a2e4af86..d83e6016f4c8e 100644 --- a/question/format/qti2/qt_common.php +++ b/question/format/qti2/qt_common.php @@ -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; diff --git a/theme/standardlogo/header.html b/theme/standardlogo/header.html index 3ade464c5e43f..bde61b4da5611 100644 --- a/theme/standardlogo/header.html +++ b/theme/standardlogo/header.html @@ -23,17 +23,11 @@ } 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'; } diff --git a/userpix/index.php b/userpix/index.php index 33cb895c9799c..b375de47a2482 100644 --- a/userpix/index.php +++ b/userpix/index.php @@ -25,13 +25,10 @@ $fullname = fullname($user); echo "wwwroot/user/view.php?id=$user->id&course=1\" ". "title=\"$fullname\">"; - if ($CFG->slasharguments) { // Use this method if possible for better caching - echo ''.$fullname.''; - } else { - echo ''.$fullname.''; - } + require_once($CFG->libdir.'/filelib.php'); + $userpictureurl = get_file_url($user->id.'/f1.jpg', null, 'user'); + echo ''.$fullname.''; echo " \n"; } diff --git a/userpix/upgrade.php b/userpix/upgrade.php index e83f2fdba47e4..15d7cf49e1748 100644 --- a/userpix/upgrade.php +++ b/userpix/upgrade.php @@ -22,13 +22,10 @@ $fullname = fullname($user); echo "wwwroot/user/view.php?id=$user->id&course=1\"". "title=\"$fullname\">"; - if ($CFG->slasharguments) { // Use this method if possible for better caching - echo ''.$fullname.''; - } else { - echo ''.$fullname.''; - } + require_once($CFG->libdir.'/filelib.php'); + $userpictureurl = get_file_url($user->id.'/f1.jpg', null, 'user'); + echo ''.$fullname.''; echo " \n"; }