mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-14589 file browsing refactoring - moving url encoding to filelib.php for now
This commit is contained in:
parent
c05e9754ce
commit
4eef139962
@ -279,7 +279,7 @@
|
||||
}
|
||||
|
||||
$filename = $file->get_filename();
|
||||
$ffurl = $browser->encodepath($CFG->wwwroot.'/pluginfile.php', '/'.SYSCONTEXTID.'/blog/'.$blogentry->id.'/'.$filename);
|
||||
$ffurl = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.SYSCONTEXTID.'/blog/'.$blogentry->id.'/'.$filename);
|
||||
$type = $file->get_mimetype();
|
||||
$icon = mimeinfo_from_type("icon", $type);
|
||||
$type = mimeinfo_from_type("type", $type);
|
||||
|
@ -133,7 +133,7 @@
|
||||
|
||||
} else {
|
||||
$icon = mimeinfo_from_type('icon', $mimetype);
|
||||
$viewurl = $browser->encodepath("$CFG->wwwroot/draftfile.php", "/$contextid/user_draft/$itemid".$filepath.$filename, false, false);
|
||||
$viewurl = file_encode_url("$CFG->wwwroot/draftfile.php", "/$contextid/user_draft/$itemid".$filepath.$filename, false, false);
|
||||
echo '<div class="file">';
|
||||
echo "<a href=\"$viewurl\"><img src=\"$CFG->pixpath/f/$icon\" class=\"icon\" alt=\"$strfile\" /> ".s($filename)." ($filesize)</a> ";
|
||||
echo "<a href=\"draftfiles.php?itemid=$itemid&filepath=$filepath&delete=$filenameurl&subdirs=$subdirs&maxbytes=$maxbytes\"><img src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a>";;
|
||||
|
@ -79,32 +79,6 @@ class file_browser {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function encodepath($urlbase, $path, $forcedownload=false, $https=false) {
|
||||
global $CFG;
|
||||
|
||||
if ($CFG->slasharguments) {
|
||||
$parts = explode('/', $path);
|
||||
$parts = array_map('rawurlencode', $parts);
|
||||
$path = implode('/', $parts);
|
||||
$return = $urlbase.$path;
|
||||
if ($forcedownload) {
|
||||
$return .= '?forcedownload=1';
|
||||
}
|
||||
} else {
|
||||
$path = rawurlencode($path);
|
||||
$return = $urlbase.'?file='.$path;
|
||||
if ($forcedownload) {
|
||||
$return .= '&forcedownload=1';
|
||||
}
|
||||
}
|
||||
|
||||
if ($https) {
|
||||
$return = str_replace('http://', 'https://', $return);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns info about the files at System context
|
||||
* @param object $context
|
||||
|
@ -51,7 +51,7 @@ class file_info_coursefile extends file_info_stored {
|
||||
|
||||
$path = '/'.$courseid.$filepath.$filename;
|
||||
|
||||
return $this->browser->encodepath($this->urlbase, $path, $forcedownload, $https);
|
||||
return file_encode_url($this->urlbase, $path, $forcedownload, $https);
|
||||
}
|
||||
|
||||
public function get_children() {
|
||||
|
@ -99,7 +99,7 @@ class file_info_stored extends file_info {
|
||||
} else {
|
||||
$path = '/'.$contextid.'/'.$filearea.$filepath.$filename;
|
||||
}
|
||||
return $this->browser->encodepath($this->urlbase, $path, $forcedownload, $https);
|
||||
return file_encode_url($this->urlbase, $path, $forcedownload, $https);
|
||||
}
|
||||
|
||||
public function is_readable() {
|
||||
|
@ -107,6 +107,42 @@ function get_file_url($path, $options=null, $type='coursefile') {
|
||||
return $ffurl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encodes file serving url
|
||||
* TODO: decide if we really need this
|
||||
* @param string $urlbase
|
||||
* @param string $path /filearea/itemid/dir/dir/file.exe
|
||||
* @param bool $forcedownload
|
||||
* @param bool $https https url required
|
||||
* @return string encoded file url
|
||||
*/
|
||||
function file_encode_url($urlbase, $path, $forcedownload=false, $https=false) {
|
||||
global $CFG;
|
||||
|
||||
if ($CFG->slasharguments) {
|
||||
$parts = explode('/', $path);
|
||||
$parts = array_map('rawurlencode', $parts);
|
||||
$path = implode('/', $parts);
|
||||
$return = $urlbase.$path;
|
||||
if ($forcedownload) {
|
||||
$return .= '?forcedownload=1';
|
||||
}
|
||||
} else {
|
||||
$path = rawurlencode($path);
|
||||
$return = $urlbase.'?file='.$path;
|
||||
if ($forcedownload) {
|
||||
$return .= '&forcedownload=1';
|
||||
}
|
||||
}
|
||||
|
||||
if ($https) {
|
||||
$return = str_replace('http://', 'https://', $return);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares standardised text field fro editing with Editor formslib element
|
||||
* @param object $data $database entry field
|
||||
|
@ -116,7 +116,7 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
|
||||
$filesize = $filesize ? display_size($filesize) : '';
|
||||
$mimetype = $file->get_mimetype();
|
||||
$icon = mimeinfo_from_type('icon', $mimetype);
|
||||
$viewurl = $browser->encodepath("$CFG->wwwroot/draftfile.php", "/$contextid/user_draft/$draftid".$filepath.$filename, false, false);
|
||||
$viewurl = file_encode_url("$CFG->wwwroot/draftfile.php", "/$contextid/user_draft/$draftid".$filepath.$filename, false, false);
|
||||
$html .= '<li>';
|
||||
$html .= "<a href=\"$viewurl\"><img src=\"$CFG->pixpath/f/$icon\" class=\"icon\" /> ".s($filename)." ($filesize)</a> ";
|
||||
$html .= "<a href=\"###\" onclick='rm_$suffix(".$file->get_itemid().", \"".$filename."\", this)'><img src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" /></a>";;
|
||||
|
@ -251,18 +251,18 @@ class file_browser_test extends filelib_test {
|
||||
$fb = new file_browser();
|
||||
|
||||
$CFG->slasharguments = true;
|
||||
$this->assertEqual('http://test.url.com/path/to/page.php', $fb->encodepath('http://test.url.com', '/path/to/page.php'));
|
||||
$this->assertEqual('http://test.url.com/path/to/page.php?forcedownload=1', $fb->encodepath('http://test.url.com', '/path/to/page.php', true));
|
||||
$this->assertEqual('https://test.url.com/path/to/page.php?forcedownload=1', $fb->encodepath('http://test.url.com', '/path/to/page.php', true, true));
|
||||
$this->assertEqual('http://test.url.com/path/to/page.php', file_encode_url('http://test.url.com', '/path/to/page.php'));
|
||||
$this->assertEqual('http://test.url.com/path/to/page.php?forcedownload=1', file_encode_url('http://test.url.com', '/path/to/page.php', true));
|
||||
$this->assertEqual('https://test.url.com/path/to/page.php?forcedownload=1', file_encode_url('http://test.url.com', '/path/to/page.php', true, true));
|
||||
|
||||
// TODO add error checking for malformed path (does method support get variables?)
|
||||
$this->assertEqual('http://test.url.com/path/to/page.php?var1=value1&var2=value2', $fb->encodepath('http://test.url.com', '/path/to/page.php?var1=value1&var2=value2'));
|
||||
$this->assertEqual('http://test.url.com/path/to/page.php?var1=value1&var2=value2&forcedownload=1', $fb->encodepath('http://test.url.com', '/path/to/page.php?var1=value1&var2=value2', true));
|
||||
$this->assertEqual('http://test.url.com/path/to/page.php?var1=value1&var2=value2', file_encode_url('http://test.url.com', '/path/to/page.php?var1=value1&var2=value2'));
|
||||
$this->assertEqual('http://test.url.com/path/to/page.php?var1=value1&var2=value2&forcedownload=1', file_encode_url('http://test.url.com', '/path/to/page.php?var1=value1&var2=value2', true));
|
||||
|
||||
$CFG->slasharguments = false;
|
||||
$this->assertEqual('http://test.url.com?file=%2Fpath%2Fto%2Fpage.php', $fb->encodepath('http://test.url.com', '/path/to/page.php'));
|
||||
$this->assertEqual('http://test.url.com?file=%2Fpath%2Fto%2Fpage.php&forcedownload=1', $fb->encodepath('http://test.url.com', '/path/to/page.php', true));
|
||||
$this->assertEqual('https://test.url.com?file=%2Fpath%2Fto%2Fpage.php&forcedownload=1', $fb->encodepath('http://test.url.com', '/path/to/page.php', true, true));
|
||||
$this->assertEqual('http://test.url.com?file=%2Fpath%2Fto%2Fpage.php', file_encode_url('http://test.url.com', '/path/to/page.php'));
|
||||
$this->assertEqual('http://test.url.com?file=%2Fpath%2Fto%2Fpage.php&forcedownload=1', file_encode_url('http://test.url.com', '/path/to/page.php', true));
|
||||
$this->assertEqual('https://test.url.com?file=%2Fpath%2Fto%2Fpage.php&forcedownload=1', file_encode_url('http://test.url.com', '/path/to/page.php', true, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1705,7 +1705,7 @@ class assignment_base {
|
||||
$found = true;
|
||||
$mimetype = $file->get_mimetype();
|
||||
$icon = mimeinfo_from_type('icon', $mimetype);
|
||||
$path = $browser->encodepath($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$userid.'/'.$filename);
|
||||
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$userid.'/'.$filename);
|
||||
$output .= '<a href="'.$path.'" ><img src="'.$CFG->pixpath.'/f/'.$icon.'" class="icon" alt="'.$icon.'" />'.s($filename).'</a>';
|
||||
if ($this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
|
||||
$button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()));
|
||||
|
@ -287,7 +287,7 @@ class assignment_upload extends assignment_base {
|
||||
$found = true;
|
||||
$mimetype = $file->get_mimetype();
|
||||
$icon = mimeinfo_from_type('icon', $mimetype);
|
||||
$path = $browser->encodepath($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$userid.'/'.$filename);
|
||||
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$userid.'/'.$filename);
|
||||
$output .= '<a href="'.$path.'" ><img class="icon" src="'.$CFG->pixpath.'/f/'.$icon.'" alt="'.$icon.'" />'.s($filename).'</a> ';
|
||||
|
||||
}
|
||||
@ -347,7 +347,7 @@ class assignment_upload extends assignment_base {
|
||||
$filename = $file->get_filename();
|
||||
$mimetype = $file->get_mimetype();
|
||||
$icon = mimeinfo_from_type('icon', $mimetype);
|
||||
$path = $browser->encodepath($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$userid.'/'.$filename);
|
||||
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$userid.'/'.$filename);
|
||||
$output .= '<a href="'.$path.'" ><img src="'.$CFG->pixpath.'/f/'.$icon.'" class="icon" alt="'.$icon.'" />'.s($filename).'</a>';
|
||||
|
||||
if ($candelete) {
|
||||
@ -409,7 +409,7 @@ class assignment_upload extends assignment_base {
|
||||
$found = true;
|
||||
$mimetype = $file->get_mimetype();
|
||||
$icon = mimeinfo_from_type('icon', $mimetype);
|
||||
$path = $browser->encodepath($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_response/'.$userid.'/'.$filename);
|
||||
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_response/'.$userid.'/'.$filename);
|
||||
|
||||
$output .= '<a href="'.$path.'" ><img src="'.$CFG->pixpath.'/f/'.$icon.'" alt="'.$icon.'" />'.$filename.'</a>';
|
||||
|
||||
|
@ -22,7 +22,7 @@ class assignment_uploadsingle extends assignment_base {
|
||||
$found = true;
|
||||
$mimetype = $file->get_mimetype();
|
||||
$icon = mimeinfo_from_type('icon', $mimetype);
|
||||
$path = $browser->encodepath($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$userid.'/'.$filename);
|
||||
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$userid.'/'.$filename);
|
||||
$output .= '<a href="'.$path.'" ><img class="icon" src="'.$CFG->pixpath.'/f/'.$icon.'" alt="'.$icon.'" />'.s($filename).'</a><br />';
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ class data_field_file extends data_field_base {
|
||||
// Print icon if file already exists
|
||||
$browser = get_file_browser();
|
||||
$icon = mimeinfo_from_type('icon', $file->get_mimetype());
|
||||
$src = $browser->encodepath($CFG->wwwroot.'/pluginfile.php', $this->context->id.'/data_content/'.$content->id.'/'.$file->get_filename());
|
||||
$src = file_encode_url($CFG->wwwroot.'/pluginfile.php', $this->context->id.'/data_content/'.$content->id.'/'.$file->get_filename());
|
||||
$str .= '<img src="'.$CFG->pixpath.'/f/'.$icon.'" class="icon" alt="'.$icon.'" />'.
|
||||
'<a href="'.$src.'" >'.s($file->get_filename()).'</a>';
|
||||
}
|
||||
@ -119,7 +119,7 @@ class data_field_file extends data_field_base {
|
||||
|
||||
$name = empty($content->content1) ? $file->get_filename() : $content->content1;
|
||||
$icon = mimeinfo_from_type('icon', $file->get_mimetype());
|
||||
$src = $browser->encodepath($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/data_content/'.$content->id.'/'.$file->get_filename());
|
||||
$src = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/data_content/'.$content->id.'/'.$file->get_filename());
|
||||
$width = $this->field->param1 ? ' width = "'.s($this->field->param1).'" ':' ';
|
||||
$height = $this->field->param2 ? ' height = "'.s($this->field->param2).'" ':' ';
|
||||
|
||||
|
@ -59,7 +59,7 @@ class data_field_picture extends data_field_base {
|
||||
//$str .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.s($this->field->param3).'" />';
|
||||
if ($file) {
|
||||
$browser = get_file_browser();
|
||||
$src = $browser->encodepath($CFG->wwwroot.'/pluginfile.php', $this->context->id.'/data_content/'.$content->id.'/'.$file->get_filename());
|
||||
$src = file_encode_url($CFG->wwwroot.'/pluginfile.php', $this->context->id.'/data_content/'.$content->id.'/'.$file->get_filename());
|
||||
$str .= '<img width="'.s($this->previewwidth).'" height="'.s($this->previewheight).'" src="'.$src.'" alt="" />';
|
||||
}
|
||||
$str .= '</fieldset>';
|
||||
@ -121,12 +121,12 @@ class data_field_picture extends data_field_base {
|
||||
$title = $alt;
|
||||
|
||||
if ($template == 'listtemplate') {
|
||||
$src = $browser->encodepath($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/data_content/'.$content->id.'/'.'thumb_'.$content->content);
|
||||
$src = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/data_content/'.$content->id.'/'.'thumb_'.$content->content);
|
||||
// no need to add width/height, because the thumb is resized properly
|
||||
$str = '<a href="view.php?d='.$this->field->dataid.'&rid='.$recordid.'"><img src="'.$src.'" alt="'.s($alt).'" title="'.s($title).'" style="border:0px" /></a>';
|
||||
|
||||
} else {
|
||||
$src = $browser->encodepath($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/data_content/'.$content->id.'/'.$content->content);
|
||||
$src = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/data_content/'.$content->id.'/'.$content->content);
|
||||
$width = $this->field->param1 ? ' width="'.s($this->field->param1).'" ':' ';
|
||||
$height = $this->field->param2 ? ' height="'.s($this->field->param2).'" ':' ';
|
||||
$str = '<a href="'.$src.'"><img '.$width.$height.' src="'.$src.'" alt="'.s($alt).'" title="'.s($title).'" style="border:0px" /></a>';
|
||||
|
@ -4005,7 +4005,7 @@ function forum_print_attachments($post, $cm, $type) {
|
||||
$mimetype = $file->get_mimetype();
|
||||
$icon = mimeinfo_from_type('icon', $mimetype);
|
||||
$iconimage = '<img src="'.$CFG->pixpath.'/f/'.$icon.'" class="icon" alt="'.$icon.'" />';
|
||||
$path = $browser->encodepath($CFG->wwwroot.'/pluginfile.php', '/'.$context->id.'/forum_attachment/'.$post->id.'/'.$filename);
|
||||
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$context->id.'/forum_attachment/'.$post->id.'/'.$filename);
|
||||
|
||||
if ($type == 'html') {
|
||||
$output .= "<a href=\"$path\">$iconimage</a> ";
|
||||
|
@ -1032,7 +1032,7 @@ function glossary_print_attachments($entry, $cm, $type=NULL, $align="left") {
|
||||
$mimetype = $file->get_mimetype();
|
||||
$icon = mimeinfo_from_type('icon', $mimetype);
|
||||
$iconimage = '<img src="'.$CFG->pixpath.'/f/'.$icon.'" class="icon" alt="'.$icon.'" />';
|
||||
$path = $browser->encodepath($CFG->wwwroot.'/pluginfile.php', '/'.$context->id.'/glossary_attachment/'.$entry->id.'/'.$filename);
|
||||
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$context->id.'/glossary_attachment/'.$entry->id.'/'.$filename);
|
||||
|
||||
if ($type == 'html') {
|
||||
$output .= "<a href=\"$path\">$iconimage</a> ";
|
||||
|
Loading…
x
Reference in New Issue
Block a user