Skip to content

Commit

Permalink
MDL-59008 mod_resource: add option to serve external files embed
Browse files Browse the repository at this point in the history
  • Loading branch information
lameze committed Jul 3, 2017
1 parent 5a651b4 commit 1fad6ff
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
9 changes: 6 additions & 3 deletions lib/filelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -3886,9 +3888,10 @@ public function refresh() {
* @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) {
Expand All @@ -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') {
Expand Down
11 changes: 9 additions & 2 deletions mod/resource/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions pluginfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
// 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);

0 comments on commit 1fad6ff

Please sign in to comment.