/**
* 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)
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
/**
* 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
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);
* @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;
* @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();
* 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
* @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);
+ }
}
/**
* @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);
}
/**
* @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";