Merge branch 'MDL-31071_deprecate-file_encode_url-function' of https://github.com/ziegenberg/moodle
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
issueNumber: MDL-31071
|
||||
notes:
|
||||
core:
|
||||
- message: >-
|
||||
The following function has been deprecated and should no longer be used:
|
||||
`file_encode_url`. Please consider using the `core\url` factory methods
|
||||
instead.
|
||||
type: deprecated
|
||||
@@ -24,6 +24,9 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core\output\html_writer;
|
||||
use core\url;
|
||||
|
||||
class block_private_files_renderer extends plugin_renderer_base {
|
||||
|
||||
/**
|
||||
@@ -78,8 +81,16 @@ class block_private_files_renderer extends plugin_renderer_base {
|
||||
}
|
||||
}
|
||||
foreach ($dir['files'] as $file) {
|
||||
$url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/user/private'.$file->get_filepath().$file->get_filename(), true);
|
||||
$filename = $file->get_filename();
|
||||
$url = url::make_pluginfile_url(
|
||||
contextid: $tree->context->id,
|
||||
component: 'user',
|
||||
area: 'private',
|
||||
itemid: null,
|
||||
pathname: $file->get_filepath(),
|
||||
filename: $filename,
|
||||
forcedownload: true
|
||||
)->out();
|
||||
$image = $this->output->pix_icon(file_file_icon($file), '');
|
||||
$result .= '<li role="treeitem">'.html_writer::link($url, $image.$filename, ['tabindex' => -1]).'</li>';
|
||||
}
|
||||
|
||||
@@ -26,3 +26,5 @@ Feature: The private files block allows users to store files privately in moodle
|
||||
And I upload "blocks/private_files/tests/fixtures/testfile.txt" file to "Files" filemanager
|
||||
And I press "Save changes"
|
||||
Then I should see "testfile.txt" in the "Private files" "block"
|
||||
And following "testfile.txt" should download a file that:
|
||||
| contains text | This is a test file |
|
||||
|
||||
@@ -24,3 +24,5 @@ Feature: The private files block allows users to store files privately in moodle
|
||||
And I upload "blocks/private_files/tests/fixtures/testfile.txt" file to "Files" filemanager
|
||||
And I press "Save changes"
|
||||
Then I should see "testfile.txt" in the "Private files" "block"
|
||||
And following "testfile.txt" should download a file that:
|
||||
| contains text | This is a test file |
|
||||
|
||||
@@ -18,3 +18,5 @@ Feature: The private files block allows users to store files privately in moodle
|
||||
And I upload "blocks/private_files/tests/fixtures/testfile.txt" file to "Files" filemanager
|
||||
And I press "Save changes"
|
||||
Then I should see "testfile.txt" in the "Private files" "block"
|
||||
And following "testfile.txt" should download a file that:
|
||||
| contains text | This is a test file |
|
||||
|
||||
@@ -30,3 +30,5 @@ Feature: The private files block allows users to store files privately in moodle
|
||||
And I upload "blocks/private_files/tests/fixtures/testfile.txt" file to "Files" filemanager
|
||||
And I press "Save changes"
|
||||
Then I should see "testfile.txt" in the "Private files" "block"
|
||||
And following "testfile.txt" should download a file that:
|
||||
| contains text | This is a test file |
|
||||
|
||||
@@ -27,6 +27,8 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir . '/filelib.php');
|
||||
|
||||
use core\url;
|
||||
|
||||
/**
|
||||
* Blog_entry class. Represents an entry in a user's blog. Contains all methods for managing this entry.
|
||||
* This class does not contain any HTML-generating code. See blog_listing sub-classes for such code.
|
||||
@@ -1175,8 +1177,14 @@ class blog_entry_attachment implements renderable {
|
||||
|
||||
$this->file = $file;
|
||||
$this->filename = $file->get_filename();
|
||||
$this->url = file_encode_url($CFG->wwwroot . '/pluginfile.php',
|
||||
'/' . SYSCONTEXTID . '/blog/attachment/' . $entryid . '/' . $this->filename);
|
||||
$this->url = url::make_pluginfile_url(
|
||||
contextid: SYSCONTEXTID,
|
||||
component: 'blog',
|
||||
area: 'attachment',
|
||||
itemid: $entryid,
|
||||
pathname: '/',
|
||||
filename: $this->filename
|
||||
)->out();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ Feature: Blog entries can be added, modified and deleted
|
||||
And I follow "Add a new entry"
|
||||
And I should see "Blogs: Add a new entry"
|
||||
And I set the following fields to these values:
|
||||
| Entry title | Entry 1 |
|
||||
| Blog entry body | Entry 1 content |
|
||||
| Attachment | lib/tests/fixtures/gd-logo.png |
|
||||
| Entry title | Entry 1 |
|
||||
| Blog entry body | Entry 1 content |
|
||||
| Attachment | lib/tests/fixtures/empty.txt |
|
||||
And I press "Save changes"
|
||||
|
||||
Scenario: Modify a blog entry
|
||||
@@ -24,6 +24,10 @@ Feature: Blog entries can be added, modified and deleted
|
||||
| Entry title | Blog entry 1 |
|
||||
And I press "Save changes"
|
||||
Then I should see "Blog entry 1"
|
||||
And I should see "Entry 1 content"
|
||||
And I should see "empty.txt"
|
||||
And following "empty.txt" should download a file that:
|
||||
| contains text | empty file for testing purposes |
|
||||
|
||||
Scenario: Delete a blog entry
|
||||
When I click on "Delete" "link"
|
||||
|
||||
@@ -854,3 +854,48 @@ function imagecopybicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $d
|
||||
\core\deprecation::emit_deprecation_if_present(__FUNCTION__);
|
||||
return imagecopyresampled($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes file serving url
|
||||
*
|
||||
* @deprecated use moodle_url factory methods instead
|
||||
* @todo Final deprecation on Moodle 6.0. See MDL-84939.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
#[\core\attribute\deprecated(
|
||||
replacement: 'core\url factory methods',
|
||||
since: '5.1',
|
||||
mdl: 'MDL-31071'
|
||||
)]
|
||||
function file_encode_url($urlbase, $path, $forcedownload = false, $https = false) {
|
||||
\core\deprecation::emit_deprecation_if_present(__FUNCTION__);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core\url;
|
||||
|
||||
/**
|
||||
* Represents a course context in the tree navigated by {@link file_browser}.
|
||||
*
|
||||
@@ -646,7 +648,11 @@ class file_info_area_course_legacy extends file_info_stored {
|
||||
|
||||
$path = '/'.$courseid.$filepath.$filename;
|
||||
|
||||
return file_encode_url($this->urlbase, $path, $forcedownload, $https);
|
||||
$url = url::make_file_url($this->urlbase, $path, $forcedownload);
|
||||
if ($https) {
|
||||
$url->set_scheme('https');
|
||||
}
|
||||
return $url->out();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core\url;
|
||||
|
||||
/**
|
||||
* Represents an actual file or folder - a row in the file table in the tree navigated by {@link file_browser}.
|
||||
*
|
||||
@@ -182,7 +184,11 @@ class file_info_stored extends file_info {
|
||||
} else {
|
||||
$path = '/'.$contextid.'/'.$component.'/'.$filearea.$filepath.$filename;
|
||||
}
|
||||
return file_encode_url($this->urlbase, $path, $forcedownload, $https);
|
||||
$url = url::make_file_url($this->urlbase, $path, $forcedownload);
|
||||
if ($https) {
|
||||
$url->set_scheme('https');
|
||||
}
|
||||
return $url->out();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,47 +55,6 @@ require_once("$CFG->libdir/filestorage/file_storage.php");
|
||||
require_once("$CFG->libdir/filestorage/zip_packer.php");
|
||||
require_once("$CFG->libdir/filebrowser/file_browser.php");
|
||||
|
||||
/**
|
||||
* Encodes file serving url
|
||||
*
|
||||
* @deprecated use moodle_url factory methods instead
|
||||
*
|
||||
* @todo MDL-31071 deprecate this function
|
||||
* @global stdClass $CFG
|
||||
* @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;
|
||||
|
||||
//TODO: deprecate this
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects if area contains subdirs,
|
||||
* this is intended for file areas that are attached to content
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use core\output\html_writer;
|
||||
use core\url;
|
||||
|
||||
/**
|
||||
* Class picture field for database activity
|
||||
*
|
||||
@@ -21,7 +24,6 @@
|
||||
* @copyright 2005 Martin Dougiamas
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
class data_field_picture extends data_field_base {
|
||||
var $type = 'picture';
|
||||
var $previewwidth = 50;
|
||||
@@ -98,8 +100,15 @@ class data_field_picture extends data_field_base {
|
||||
}
|
||||
$str .= '<noscript>';
|
||||
if ($file) {
|
||||
$src = file_encode_url($CFG->wwwroot.'/pluginfile.php/', $this->context->id.'/mod_data/content/'.$content->id.'/'.$file->get_filename());
|
||||
$str .= '<img width="'.s($this->previewwidth).'" height="'.s($this->previewheight).'" src="'.$src.'" alt="" />';
|
||||
$src = url::make_pluginfile_url(
|
||||
contextid: $this->context->id,
|
||||
component: 'mod_data',
|
||||
area: 'content',
|
||||
itemid: $content->id,
|
||||
pathname: '/',
|
||||
filename: $file->get_filename()
|
||||
);
|
||||
$str .= html_writer::img($src->out(), '', ['width' => $this->previewwidth, 'height' => $this->previewheight]);
|
||||
}
|
||||
$str .= '</noscript>';
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core\url;
|
||||
|
||||
/** Display folder contents on a separate page */
|
||||
define('FOLDER_DISPLAY_PAGE', 0);
|
||||
/** Display folder contents inline in a course */
|
||||
@@ -319,12 +321,20 @@ function folder_export_contents($cm, $baseurl) {
|
||||
$files = $fs->get_area_files($context->id, 'mod_folder', 'content', 0, 'sortorder DESC, id ASC', false);
|
||||
|
||||
foreach ($files as $fileinfo) {
|
||||
$file = array();
|
||||
$file = [];
|
||||
$file['type'] = 'file';
|
||||
$file['filename'] = $fileinfo->get_filename();
|
||||
$file['filepath'] = $fileinfo->get_filepath();
|
||||
$file['filesize'] = $fileinfo->get_filesize();
|
||||
$file['fileurl'] = file_encode_url("$CFG->wwwroot/" . $baseurl, '/'.$context->id.'/mod_folder/content/'.$folder->revision.$fileinfo->get_filepath().$fileinfo->get_filename(), true);
|
||||
$file['fileurl'] = url::make_webservice_pluginfile_url(
|
||||
contextid: $context->id,
|
||||
component: 'mod_folder',
|
||||
area: 'content',
|
||||
itemid: $folder->revision,
|
||||
pathname: $fileinfo->get_filepath(),
|
||||
filename: $fileinfo->get_filename(),
|
||||
forcedownload: true
|
||||
)->out();
|
||||
$file['timecreated'] = $fileinfo->get_timecreated();
|
||||
$file['timemodified'] = $fileinfo->get_timemodified();
|
||||
$file['sortorder'] = $fileinfo->get_sortorder();
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use core\url;
|
||||
use mod_forum\local\entities\forum as forum_entity;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
@@ -2580,7 +2581,14 @@ function forum_print_attachments($post, $cm, $type) {
|
||||
'style' => 'max-width: 24px; max-height: 24px; vertical-align: middle;',
|
||||
]
|
||||
);
|
||||
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$context->id.'/mod_forum/attachment/'.$post->id.'/'.$filename);
|
||||
$path = url::make_pluginfile_url(
|
||||
contextid: $context->id,
|
||||
component: 'mod_forum',
|
||||
area: 'attachment',
|
||||
itemid: $post->id,
|
||||
pathname: '/',
|
||||
filename: $filename
|
||||
)->out();
|
||||
|
||||
if ($type == 'html') {
|
||||
$output .= "<a href=\"$path\">$iconimage</a> ";
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use core\url;
|
||||
|
||||
require_once($CFG->libdir . '/completionlib.php');
|
||||
|
||||
define("GLOSSARY_SHOW_ALL_CATEGORIES", 0);
|
||||
@@ -1590,7 +1593,14 @@ function glossary_print_attachments($entry, $cm, $type=NULL, $unused = null) {
|
||||
$filename = $file->get_filename();
|
||||
$mimetype = $file->get_mimetype();
|
||||
$iconimage = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon'));
|
||||
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$context->id.'/mod_glossary/attachment/'.$entry->id.'/'.$filename);
|
||||
$path = url::make_pluginfile_url(
|
||||
contextid: $context->id,
|
||||
component: 'mod_glossary',
|
||||
area: 'attachment',
|
||||
itemid: $entry->id,
|
||||
pathname: '/',
|
||||
filename: $filename
|
||||
)->out();
|
||||
|
||||
if ($type == 'html') {
|
||||
$output .= "<a href=\"$path\">$iconimage</a> ";
|
||||
|
||||
@@ -61,6 +61,8 @@ Feature: Glossary can be set to various display formats
|
||||
# Confirm that glossary format is full without author style.
|
||||
# In this format, the image link should exist and author's name should not be visible.
|
||||
Then "gd-logo.png" "link" should exist
|
||||
And following "gd-logo.png" should download a file that:
|
||||
| has mimetype | image/png |
|
||||
And I should not see "by Admin User"
|
||||
And ".fullwithoutauthor" "css_element" should exist
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core\url;
|
||||
|
||||
require_once("$CFG->dirroot/mod/imscp/lib.php");
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
require_once("$CFG->libdir/resourcelib.php");
|
||||
@@ -68,9 +70,14 @@ function imscp_htmllize_item($item, $imscp, $cm) {
|
||||
$url = $item['href'];
|
||||
} else {
|
||||
$context = context_module::instance($cm->id);
|
||||
$urlbase = "$CFG->wwwroot/pluginfile.php";
|
||||
$path = '/'.$context->id.'/mod_imscp/content/'.$imscp->revision.'/'.$item['href'];
|
||||
$url = file_encode_url($urlbase, $path, false);
|
||||
$url = url::make_pluginfile_url(
|
||||
contextid: $context->id,
|
||||
component: 'mod_imscp',
|
||||
area: 'content',
|
||||
itemid: $imscp->revision,
|
||||
pathname: '/',
|
||||
filename: $item['href']
|
||||
)->out();
|
||||
}
|
||||
$result = "<li><a href=\"$url\">".$item['title'].'</a>';
|
||||
} else {
|
||||
|
||||
+22
-4
@@ -23,6 +23,8 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
use core\url;
|
||||
|
||||
/**
|
||||
* List of features supported in Page module
|
||||
* @param string $feature FEATURE_xx constant for requested feature
|
||||
@@ -409,12 +411,20 @@ function page_export_contents($cm, $baseurl) {
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($context->id, 'mod_page', 'content', 0, 'sortorder DESC, id ASC', false);
|
||||
foreach ($files as $fileinfo) {
|
||||
$file = array();
|
||||
$file = [];
|
||||
$file['type'] = 'file';
|
||||
$file['filename'] = $fileinfo->get_filename();
|
||||
$file['filepath'] = $fileinfo->get_filepath();
|
||||
$file['filesize'] = $fileinfo->get_filesize();
|
||||
$file['fileurl'] = file_encode_url("$CFG->wwwroot/" . $baseurl, '/'.$context->id.'/mod_page/content/'.$page->revision.$fileinfo->get_filepath().$fileinfo->get_filename(), true);
|
||||
$file['fileurl'] = url::make_webservice_pluginfile_url(
|
||||
contextid: $context->id,
|
||||
component: 'mod_page',
|
||||
area: 'content',
|
||||
itemid: $page->revision,
|
||||
pathname: $fileinfo->get_filepath(),
|
||||
filename: $fileinfo->get_filename(),
|
||||
forcedownload: true
|
||||
)->out();
|
||||
$file['timecreated'] = $fileinfo->get_timecreated();
|
||||
$file['timemodified'] = $fileinfo->get_timemodified();
|
||||
$file['sortorder'] = $fileinfo->get_sortorder();
|
||||
@@ -431,12 +441,20 @@ function page_export_contents($cm, $baseurl) {
|
||||
|
||||
// page html conent
|
||||
$filename = 'index.html';
|
||||
$pagefile = array();
|
||||
$pagefile = [];
|
||||
$pagefile['type'] = 'file';
|
||||
$pagefile['filename'] = $filename;
|
||||
$pagefile['filepath'] = '/';
|
||||
$pagefile['filesize'] = 0;
|
||||
$pagefile['fileurl'] = file_encode_url("$CFG->wwwroot/" . $baseurl, '/'.$context->id.'/mod_page/content/' . $filename, true);
|
||||
$pagefile['fileurl'] = url::make_webservice_pluginfile_url(
|
||||
contextid: $context->id,
|
||||
component: 'mod_page',
|
||||
area: 'content',
|
||||
itemid: null,
|
||||
pathname: '/',
|
||||
filename: $filename,
|
||||
forcedownload: true
|
||||
)->out();
|
||||
$pagefile['timecreated'] = null;
|
||||
$pagefile['timemodified'] = $page->timemodified;
|
||||
// make this file as main file
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
use core\url;
|
||||
|
||||
/**
|
||||
* List of features supported in Resource module
|
||||
* @param string $feature FEATURE_xx constant for requested feature
|
||||
@@ -447,12 +449,20 @@ function resource_export_contents($cm, $baseurl) {
|
||||
$files = $fs->get_area_files($context->id, 'mod_resource', 'content', 0, 'sortorder DESC, id ASC', false);
|
||||
|
||||
foreach ($files as $fileinfo) {
|
||||
$file = array();
|
||||
$file = [];
|
||||
$file['type'] = 'file';
|
||||
$file['filename'] = $fileinfo->get_filename();
|
||||
$file['filepath'] = $fileinfo->get_filepath();
|
||||
$file['filesize'] = $fileinfo->get_filesize();
|
||||
$file['fileurl'] = file_encode_url("$CFG->wwwroot/" . $baseurl, '/'.$context->id.'/mod_resource/content/'.$resource->revision.$fileinfo->get_filepath().$fileinfo->get_filename(), true);
|
||||
$file['fileurl'] = url::make_webservice_pluginfile_url(
|
||||
contextid: $context->id,
|
||||
component: 'mod_resource',
|
||||
area: 'content',
|
||||
itemid: $resource->revision,
|
||||
pathname: $fileinfo->get_filepath(),
|
||||
filename: $fileinfo->get_filename(),
|
||||
forcedownload: true
|
||||
)->out();
|
||||
$file['timecreated'] = $fileinfo->get_timecreated();
|
||||
$file['timemodified'] = $fileinfo->get_timemodified();
|
||||
$file['sortorder'] = $fileinfo->get_sortorder();
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
use core\url;
|
||||
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
require_once("$CFG->libdir/resourcelib.php");
|
||||
require_once("$CFG->dirroot/mod/resource/lib.php");
|
||||
@@ -133,8 +135,14 @@ function resource_display_frame($resource, $cm, $course, $file) {
|
||||
} else {
|
||||
$config = get_config('resource');
|
||||
$context = context_module::instance($cm->id);
|
||||
$path = '/'.$context->id.'/mod_resource/content/'.$resource->revision.$file->get_filepath().$file->get_filename();
|
||||
$fileurl = file_encode_url($CFG->wwwroot.'/pluginfile.php', $path, false);
|
||||
$fileurl = url::make_pluginfile_url(
|
||||
contextid: $context->id,
|
||||
component: 'mod_resource',
|
||||
area: 'content',
|
||||
itemid: $resource->revision,
|
||||
pathname: $file->get_filepath(),
|
||||
filename: $file->get_filename()
|
||||
)->out();
|
||||
$navurl = "$CFG->wwwroot/mod/resource/view.php?id=$cm->id&frameset=top";
|
||||
$title = strip_tags(format_string($course->shortname.': '.$resource->name));
|
||||
$framesize = $config->framesize;
|
||||
@@ -169,8 +177,14 @@ function resource_get_clicktoopen($file, $revision, $extra='') {
|
||||
global $CFG;
|
||||
|
||||
$filename = $file->get_filename();
|
||||
$path = '/'.$file->get_contextid().'/mod_resource/content/'.$revision.$file->get_filepath().$file->get_filename();
|
||||
$fullurl = file_encode_url($CFG->wwwroot.'/pluginfile.php', $path, false);
|
||||
$fullurl = url::make_pluginfile_url(
|
||||
contextid: $file->get_contextid(),
|
||||
component: 'mod_resource',
|
||||
area: 'content',
|
||||
itemid: $revision,
|
||||
pathname: $file->get_filepath(),
|
||||
filename: $filename
|
||||
)->out();
|
||||
|
||||
$string = get_string('clicktoopen2', 'resource', "<a href=\"$fullurl\" $extra>$filename</a>");
|
||||
|
||||
@@ -184,8 +198,15 @@ function resource_get_clicktodownload($file, $revision) {
|
||||
global $CFG;
|
||||
|
||||
$filename = $file->get_filename();
|
||||
$path = '/'.$file->get_contextid().'/mod_resource/content/'.$revision.$file->get_filepath().$file->get_filename();
|
||||
$fullurl = file_encode_url($CFG->wwwroot.'/pluginfile.php', $path, true);
|
||||
$fullurl = url::make_pluginfile_url(
|
||||
$file->get_contextid(),
|
||||
'mod_resource',
|
||||
'content',
|
||||
$revision,
|
||||
$file->get_filepath(),
|
||||
$filename,
|
||||
true
|
||||
)->out();
|
||||
|
||||
$string = get_string('clicktodownload', 'resource', "<a href=\"$fullurl\">$filename</a>");
|
||||
|
||||
@@ -212,8 +233,14 @@ function resource_print_workaround($resource, $cm, $course, $file) {
|
||||
echo '<div class="resourceworkaround">';
|
||||
switch (resource_get_final_display_type($resource)) {
|
||||
case RESOURCELIB_DISPLAY_POPUP:
|
||||
$path = '/'.$file->get_contextid().'/mod_resource/content/'.$resource->revision.$file->get_filepath().$file->get_filename();
|
||||
$fullurl = file_encode_url($CFG->wwwroot.'/pluginfile.php', $path, false);
|
||||
$fullurl = url::make_pluginfile_url(
|
||||
contextid: $file->get_contextid(),
|
||||
component: 'mod_resource',
|
||||
area: 'content',
|
||||
itemid: $resource->revision,
|
||||
pathname: $file->get_filepath(),
|
||||
filename: $file->get_filename()
|
||||
)->out();
|
||||
$options = empty($resource->displayoptions) ? [] : (array) unserialize_array($resource->displayoptions);
|
||||
$width = empty($options['popupwidth']) ? 620 : $options['popupwidth'];
|
||||
$height = empty($options['popupheight']) ? 450 : $options['popupheight'];
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use core\url;
|
||||
|
||||
require_once('HTML/QuickForm/element.php');
|
||||
require_once($CFG->dirroot.'/lib/filelib.php');
|
||||
|
||||
@@ -117,22 +119,48 @@ class MoodleQuickForm_wikifiletable extends HTML_QuickForm_element {
|
||||
}
|
||||
$checkbox .= " />";
|
||||
|
||||
//actions
|
||||
// Get Actions.
|
||||
$icon = file_file_icon($file);
|
||||
$file_url = file_encode_url($CFG->wwwroot.'/pluginfile.php', "/{$this->_contextid}/mod_wiki/attachments/{$this->_fileareaitemid}/".$file->get_filename());
|
||||
$filename = $file->get_filename();
|
||||
$fileurl = url::make_pluginfile_url(
|
||||
contextid: $this->_contextid,
|
||||
component: 'mod_wiki',
|
||||
area: 'attachments',
|
||||
itemid: $this->_fileareaitemid,
|
||||
pathname: '/',
|
||||
filename: $filename
|
||||
)->out();
|
||||
|
||||
$action_icons = "";
|
||||
if(!empty($tags['attach'])) {
|
||||
$action_icons .= "<a href=\"javascript:void(0)\" class=\"wiki-attachment-attach\" ".$this->printInsertTags($tags['attach'], $file->get_filename())." title=\"".get_string('attachmentattach', 'wiki')."\">".$OUTPUT->pix_icon($icon, "Attach")."</a>"; //TODO: localize
|
||||
$actionicons = "";
|
||||
if (!empty($tags['attach'])) {
|
||||
$actionicons .= '<a href="javascript:void(0)" class="wiki-attachment-attach" ';
|
||||
$actionicons .= $this->printInsertTags($tags['attach'], $filename);
|
||||
$actionicons .= ' title="';
|
||||
$actionicons .= get_string('attachmentattach', 'wiki');
|
||||
$actionicons .= '">';
|
||||
$actionicons .= $OUTPUT->pix_icon($icon, "Attach");
|
||||
$actionicons .= '</a>';
|
||||
}
|
||||
|
||||
$action_icons .= " <a href=\"javascript:void(0)\" class=\"wiki-attachment-link\" ".$this->printInsertTags($tags['link'], $file_url)." title=\"".get_string('attachmentlink', 'wiki')."\">".$OUTPUT->pix_icon($icon, "Link")."</a>";
|
||||
$actionicons .= ' <a href="javascript:void(0)" class="wiki-attachment-link" ';
|
||||
$actionicons .= $this->printInsertTags($tags['link'], $fileurl);
|
||||
$actionicons .= ' title="';
|
||||
$actionicons .= get_string('attachmentlink', 'wiki');
|
||||
$actionicons .= '">';
|
||||
$actionicons .= $OUTPUT->pix_icon($icon, 'Link');
|
||||
$actionicons .= '</a>';
|
||||
|
||||
if (file_mimetype_in_typegroup($file->get_mimetype(), 'web_image')) {
|
||||
$action_icons .= " <a href=\"javascript:void(0)\" class=\"wiki-attachment-image\" ".$this->printInsertTags($tags['image'], $file->get_filename())." title=\"".get_string('attachmentimage', 'wiki')."\">".$OUTPUT->pix_icon($icon, "Image")."</a>"; //TODO: localize
|
||||
$actionicons .= ' <a href="javascript:void(0)" class="wiki-attachment-image" ';
|
||||
$actionicons .= $this->printInsertTags($tags['image'], $filename);
|
||||
$actionicons .= 'title="';
|
||||
$actionicons .= get_string('attachmentimage', 'wiki');
|
||||
$actionicons .= '">';
|
||||
$actionicons .= $OUTPUT->pix_icon($icon, 'Image');
|
||||
$actionicons .= '</a>';
|
||||
}
|
||||
|
||||
$htmltable->data[] = array($checkbox, '<a href="'.$file_url.'">'.$file->get_filename().'</a>', $action_icons);
|
||||
$htmltable->data[] = [$checkbox, '<a href="' . $fileurl . '">' . $filename . '</a>', $actionicons];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core\url;
|
||||
|
||||
require_once($CFG->dirroot . '/mod/wiki/lib.php');
|
||||
require_once($CFG->dirroot . '/mod/wiki/parser/parser.php');
|
||||
require_once($CFG->libdir . '/filelib.php');
|
||||
@@ -1487,7 +1489,15 @@ function wiki_print_upload_table($context, $filearea, $fileitemid, $deleteupload
|
||||
|
||||
$checkbox .= " />";
|
||||
|
||||
$htmltable->data[] = array($checkbox, '<a href="' . file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $context->id . '/wiki_upload/' . $fileitemid . '/' . $file->get_filename()) . '">' . $file->get_filename() . '</a>', "");
|
||||
$url = url::make_pluginfile_url(
|
||||
contextid: $context->id,
|
||||
component: 'wiki_upload',
|
||||
area: '',
|
||||
itemid: $fileitemid,
|
||||
pathname: '/',
|
||||
filename: $file->get_filename()
|
||||
);
|
||||
$htmltable->data[] = [$checkbox, '<a href="' . $url->out() . '">' . $file->get_filename() . '</a>', ""];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use core\output\html_writer;
|
||||
use core\output\plugin_renderer_base;
|
||||
use core\url;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
class mod_wiki_renderer extends plugin_renderer_base {
|
||||
@@ -526,10 +530,20 @@ class mod_wiki_renderer extends plugin_renderer_base {
|
||||
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
|
||||
}
|
||||
foreach ($dir['files'] as $file) {
|
||||
$url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/mod_wiki/attachments/' . $tree->subwiki->id . '/'. $file->get_filepath() . $file->get_filename(), true);
|
||||
$filename = $file->get_filename();
|
||||
$url = url::make_pluginfile_url(
|
||||
contextid: $tree->context->id,
|
||||
component: 'mod_wiki',
|
||||
area: 'attachments',
|
||||
itemid: $tree->subwiki->id,
|
||||
pathname: $file->get_filepath(),
|
||||
filename: $filename,
|
||||
forcedownload: true
|
||||
);
|
||||
$image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
|
||||
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.html_writer::link($url, $filename).'</div></li>';
|
||||
$result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>';
|
||||
$result .= '<div>' . $image . ' ' . html_writer::link($url->out(), $filename) . '</div>';
|
||||
$result .= '</li>';
|
||||
}
|
||||
$result .= '</ul>';
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use core\url;
|
||||
use core_question\local\bank\question_edit_contexts;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
@@ -595,14 +596,15 @@ class question_attempt {
|
||||
* @return string the URL of that file.
|
||||
*/
|
||||
public function get_response_file_url(stored_file $file) {
|
||||
return file_encode_url(new moodle_url('/pluginfile.php'), '/' . implode('/', array(
|
||||
$file->get_contextid(),
|
||||
$file->get_component(),
|
||||
$file->get_filearea(),
|
||||
$this->usageid,
|
||||
$this->slot,
|
||||
$file->get_itemid())) .
|
||||
$file->get_filepath() . $file->get_filename(), true);
|
||||
return url::make_pluginfile_url(
|
||||
contextid: $file->get_contextid(),
|
||||
component: $file->get_component(),
|
||||
area: $file->get_filearea(),
|
||||
itemid: implode('/', [$this->usageid, $this->slot, $file->get_itemid()]),
|
||||
pathname: $file->get_filepath(),
|
||||
filename: $file->get_filename(),
|
||||
forcedownload: true
|
||||
)->out();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,6 +55,12 @@ Feature: In a essay question, limit submittable file types
|
||||
# Wait for the page to "settle".
|
||||
And I wait until the page is ready
|
||||
Then I should not see "These file types are not allowed here:"
|
||||
And I press "Finish attempt ..."
|
||||
And I press "Submit all and finish"
|
||||
And I click on "Submit all and finish" "button" in the "Submit all your answers and finish?" "dialogue"
|
||||
Then I should see "empty.txt"
|
||||
And following "empty.txt" should download a file that:
|
||||
| contains text | empty file for testing purposes |
|
||||
|
||||
@javascript
|
||||
Scenario: Preview an Essay question and try to submit a response with an incorrect filetype.
|
||||
|
||||
Reference in New Issue
Block a user