MDL-14589 adding missing component to moodle_url factory methods, going to convert code to use these factories instead of old filelib.php functions

This commit is contained in:
Petr Skoda
2010-07-11 09:20:20 +00:00
parent 5652df37fd
commit f28ee49e98
2 changed files with 19 additions and 11 deletions
+7 -4
View File
@@ -37,8 +37,8 @@ require_once("$CFG->libdir/filebrowser/file_browser.php");
/**
* Given a physical path to a file, returns the URL through which it can be reached in Moodle.
*
* @global object
* @global string
* @deprecated use moodle_url factory methods instead
*
* @param string $path Physical path to a file
* @param array $options associative array of GET variables to append to the URL
* @param string $type (questionfile|rssfile|user|usergroup|httpscoursefile|coursefile)
@@ -47,7 +47,7 @@ require_once("$CFG->libdir/filebrowser/file_browser.php");
function get_file_url($path, $options=null, $type='coursefile') {
global $CFG, $HTTPSPAGEREQUIRED;
//TODO: deprecate this
//TODO: deprecate this
$path = str_replace('//', '/', $path);
$path = trim($path, '/'); // no leading and trailing slashes
@@ -123,7 +123,8 @@ function file_draftfile_url($draftid, $filepath, $filename) {
/**
* Encodes file serving url
*
* @todo decide if we really need this
* @deprecated use moodle_url factory methods instead
*
* @global object
* @param string $urlbase
* @param string $path /filearea/itemid/dir/dir/file.exe
@@ -134,6 +135,8 @@ function file_draftfile_url($draftid, $filepath, $filename) {
function file_encode_url($urlbase, $path, $forcedownload=false, $https=false) {
global $CFG;
//TODO: deprecate this
if ($CFG->slasharguments) {
$parts = explode('/', $path);
$parts = array_map('rawurlencode', $parts);
+12 -7
View File
@@ -627,7 +627,7 @@ class moodle_url {
* @param bool $supported usually null, then it depends on $CFG->slasharguments, use true or false for other servers
* @return void
*/
public function set_slashargument($path, $parameter='file', $supported=null) {
public function set_slashargument($path, $parameter = 'file', $supported = NULL) {
global $CFG;
if (is_null($supported)) {
$supported = $CFG->slasharguments;
@@ -655,7 +655,7 @@ class moodle_url {
* @param bool $forcedownload
* @return moodle_url
*/
public static function make_file_url($urlbase, $path, $forcedownload=false) {
public static function make_file_url($urlbase, $path, $forcedownload = false) {
global $CFG;
$params = array();
@@ -674,6 +674,7 @@ class moodle_url {
* Please note this method can be used only from the plugins to
* create urls of own files, it must not be used outside of plugins!
* @param int $contextid
* @param string $component
* @param string $area
* @param int $itemid
* @param string $pathname
@@ -681,10 +682,14 @@ class moodle_url {
* @param bool $forcedownload
* @return moodle_url
*/
public static function make_pluginfile_url($contextid, $area, $itemid, $pathname, $filename, $forcedownload=false) {
public static function make_pluginfile_url($contextid, $component, $area, $itemid, $pathname, $filename, $forcedownload = false) {
global $CFG;
$urlbase = "$CFG->httpswwwroot/pluginfile.php";
return self::make_file_url($urlbase, '/'.$contextid.'/'.$area.'/'.$itemid.$pathname.$filename, $forcedownload);
if ($itemid === NULL) {
return self::make_file_url($urlbase, "/$contextid/$component/$area".$pathname.$filename, $forcedownload);
} else {
return self::make_file_url($urlbase, "/$contextid/$component/$area/$itemid".$pathname.$filename, $forcedownload);
}
}
/**
@@ -696,12 +701,12 @@ class moodle_url {
* @param bool $forcedownload
* @return moodle_url
*/
public static function make_draftfile_url($itemid, $pathname, $filename, $forcedownload=false) {
public static function make_draftfile_url($itemid, $pathname, $filename, $forcedownload = false) {
global $CFG, $USER;
$urlbase = "$CFG->httpswwwroot/draftfile.php";
$context = get_context_instance(CONTEXT_USER, $USER->id);
return self::make_file_url($urlbase, '/'.$context->id.'/user/draft/'.$itemid.$pathname.$filename, $forcedownload);
return self::make_file_url($urlbase, "/$context->id/user/draft/$itemid".$pathname.$filename, $forcedownload);
}
/**
@@ -712,7 +717,7 @@ class moodle_url {
* @param bool $forcedownload
* @return moodle_url
*/
public static function make_legacyfile_url($courseid, $filepath, $forcedownload=false) {
public static function make_legacyfile_url($courseid, $filepath, $forcedownload = false) {
global $CFG;
$urlbase = "$CFG->wwwroot/file.php";