mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 05:25:08 +02:00
MDL-59008 mod_resource: add option to serve external files embed
This commit is contained in:
parent
5a651b43fb
commit
1fad6ff3f5
@ -972,7 +972,9 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea
|
||||
if (!empty($repoid)) {
|
||||
$context = context::instance_by_id($contextid, MUST_EXIST);
|
||||
$repo = repository::get_repository_by_id($repoid, $context);
|
||||
|
||||
if (!empty($options)) {
|
||||
$repo->options = $options;
|
||||
}
|
||||
$file_record['repositoryid'] = $repoid;
|
||||
// This hook gives the repo a place to do some house cleaning, and update the $reference before it's saved
|
||||
// to the file store. E.g. transfer ownership of the file to a system account etc.
|
||||
@ -3886,9 +3888,10 @@ class curl_cache {
|
||||
* @param null|string $preview the preview mode, defaults to serving the original file
|
||||
* @param boolean $offline If offline is requested - don't serve a redirect to an external file, return a file suitable for viewing
|
||||
* offline (e.g. mobile app).
|
||||
* @param bool $embed Whether this file will be served embed into an iframe.
|
||||
* @todo MDL-31088 file serving improments
|
||||
*/
|
||||
function file_pluginfile($relativepath, $forcedownload, $preview = null, $offline = false) {
|
||||
function file_pluginfile($relativepath, $forcedownload, $preview = null, $offline = false, $embed = false) {
|
||||
global $DB, $CFG, $USER;
|
||||
// relative path must start with '/'
|
||||
if (!$relativepath) {
|
||||
@ -3912,7 +3915,7 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null, $offlin
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$sendfileoptions = ['preview' => $preview, 'offline' => $offline];
|
||||
$sendfileoptions = ['preview' => $preview, 'offline' => $offline, 'embed' => $embed];
|
||||
|
||||
// ========================================================================================================================
|
||||
if ($component === 'blog') {
|
||||
|
@ -93,8 +93,11 @@ function resource_display_embed($resource, $cm, $course, $file) {
|
||||
$code = $mediamanager->embed_url($moodleurl, $title, 0, 0, $embedoptions);
|
||||
|
||||
} else {
|
||||
// We need a way to discover if we are loading remote docs inside an iframe.
|
||||
$moodleurl->param('embed', 1);
|
||||
|
||||
// anything else - just try object tag enlarged as much as possible
|
||||
$code = resourcelib_embed_general($fullurl, $title, $clicktoopen, $mimetype);
|
||||
$code = resourcelib_embed_general($moodleurl, $title, $clicktoopen, $mimetype);
|
||||
}
|
||||
|
||||
resource_print_header($resource, $cm, $course);
|
||||
@ -525,7 +528,11 @@ function resource_set_mainfile($data) {
|
||||
|
||||
$context = context_module::instance($cmid);
|
||||
if ($draftitemid) {
|
||||
file_save_draft_area_files($draftitemid, $context->id, 'mod_resource', 'content', 0, array('subdirs'=>true));
|
||||
$options = array('subdirs' => true, 'embed' => false);
|
||||
if ($data->display == RESOURCELIB_DISPLAY_EMBED) {
|
||||
$options['embed'] = true;
|
||||
}
|
||||
file_save_draft_area_files($draftitemid, $context->id, 'mod_resource', 'content', 0, $options);
|
||||
}
|
||||
$files = $fs->get_area_files($context->id, 'mod_resource', 'content', 0, 'sortorder', false);
|
||||
if (count($files) == 1) {
|
||||
|
@ -36,5 +36,5 @@ $preview = optional_param('preview', null, PARAM_ALPHANUM);
|
||||
// Offline means download the file from the repository and serve it, even if it was an external link.
|
||||
// The repository may have to export the file to an offline format.
|
||||
$offline = optional_param('offline', 0, PARAM_BOOL);
|
||||
|
||||
file_pluginfile($relativepath, $forcedownload, $preview, $offline);
|
||||
$embed = optional_param('embed', 0, PARAM_BOOL);
|
||||
file_pluginfile($relativepath, $forcedownload, $preview, $offline, $embed);
|
||||
|
Loading…
x
Reference in New Issue
Block a user