From 4e40406d0ba304c407ed5aec9372a1cdcd73a2a5 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Mon, 18 Jan 2010 12:39:44 +0000 Subject: [PATCH] MDL-21362 finally finished full support for our slasharguments in moodle_url --- lib/weblib.php | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/weblib.php b/lib/weblib.php index 92efed6f45e..9bca76a874b 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -620,6 +620,32 @@ class moodle_url { } } + /** + * Sets the url slashargument value + * @param string $path usually file path + * @param string $parameter name of page parameter if slasharguments not supported + * @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) { + global $CFG; + if (is_null($supported)) { + $supported = $CFG->slasharguments; + } + + if ($supported) { + $parts = explode('/', $path); + $parts = array_map('rawurlencode', $parts); + $path = implode('/', $parts); + $this->slashargument = $path; + unset($this->params[$parameter]); + + } else { + $this->slashargument = ''; + $this->params[$parameter] = $path; + } + } + // == static factory methods == /** @@ -633,22 +659,14 @@ class moodle_url { global $CFG; $params = array(); - - if ($CFG->slasharguments) { - $parts = explode('/', $path); - $parts = array_map('rawurlencode', $parts); - $path = implode('/', $parts); - $url = $urlbase.$path; - } else { - $params['file'] = rawurlencode($path); - $url = $urlbase; - } - if ($forcedownload) { $params['forcedownload'] = 1; } - return new moodle_url($url, $params); + $url = new moodle_url($urlbase, $params); + $url->set_slashargument($path); + + return $url; } /**