mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-31015 File/URL resource 'Open' and 'Force download' options should work consistently
This commit is contained in:
parent
216f6d8e9d
commit
68828cc431
4 changed files with 23 additions and 31 deletions
|
@ -285,30 +285,6 @@ function resource_get_coursemodule_info($coursemodule) {
|
||||||
$fullurl = "$CFG->wwwroot/mod/resource/view.php?id=$coursemodule->id&redirect=1";
|
$fullurl = "$CFG->wwwroot/mod/resource/view.php?id=$coursemodule->id&redirect=1";
|
||||||
$info->onclick = "window.open('$fullurl'); return false;";
|
$info->onclick = "window.open('$fullurl'); return false;";
|
||||||
|
|
||||||
} else if ($display == RESOURCELIB_DISPLAY_OPEN) {
|
|
||||||
$fullurl = "$CFG->wwwroot/mod/resource/view.php?id=$coursemodule->id&redirect=1";
|
|
||||||
$info->onclick = "window.location.href ='$fullurl';return false;";
|
|
||||||
|
|
||||||
} else if ($display == RESOURCELIB_DISPLAY_DOWNLOAD) {
|
|
||||||
if (empty($mainfile)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
// do not open any window because it would be left there after download
|
|
||||||
$path = '/'.$context->id.'/mod_resource/content/'.$resource->revision.$mainfile->get_filepath().$mainfile->get_filename();
|
|
||||||
$fullurl = addslashes_js(file_encode_url($CFG->wwwroot.'/pluginfile.php', $path, true));
|
|
||||||
|
|
||||||
// When completion information is enabled for download files, make
|
|
||||||
// the JavaScript version go to the view page with redirect set,
|
|
||||||
// instead of directly to the file, otherwise we can't make it tick
|
|
||||||
// the box for them
|
|
||||||
if (!$course = $DB->get_record('course', array('id'=>$coursemodule->course), 'id, enablecompletion')) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
$completion = new completion_info($course);
|
|
||||||
if ($completion->is_enabled($coursemodule) == COMPLETION_TRACKING_AUTOMATIC) {
|
|
||||||
$fullurl = "$CFG->wwwroot/mod/resource/view.php?id=$coursemodule->id&redirect=1";
|
|
||||||
}
|
|
||||||
$info->onclick = "window.open('$fullurl'); return false;";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If any optional extra details are turned on, store in custom data
|
// If any optional extra details are turned on, store in custom data
|
||||||
|
|
|
@ -76,16 +76,26 @@ if (count($files) < 1) {
|
||||||
unset($files);
|
unset($files);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$resource->mainfile = $file->get_filename();
|
||||||
|
$displaytype = resource_get_final_display_type($resource);
|
||||||
|
if ($displaytype == RESOURCELIB_DISPLAY_OPEN || $displaytype == RESOURCELIB_DISPLAY_DOWNLOAD) {
|
||||||
|
// For 'open' and 'download' links, we always redirect to the content - except
|
||||||
|
// if the user just chose 'save and display' from the form then that would be
|
||||||
|
// confusing
|
||||||
|
if (!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], 'modedit.php') === false) {
|
||||||
|
$redirect = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($redirect) {
|
if ($redirect) {
|
||||||
// coming from course page or url index page
|
// coming from course page or url index page
|
||||||
// this redirect trick solves caching problems when tracking views ;-)
|
// this redirect trick solves caching problems when tracking views ;-)
|
||||||
$path = '/'.$context->id.'/mod_resource/content/'.$resource->revision.$file->get_filepath().$file->get_filename();
|
$path = '/'.$context->id.'/mod_resource/content/'.$resource->revision.$file->get_filepath().$file->get_filename();
|
||||||
$fullurl = file_encode_url($CFG->wwwroot.'/pluginfile.php', $path, false);
|
$fullurl = moodle_url::make_file_url('/pluginfile.php', $path, $displaytype == RESOURCELIB_DISPLAY_DOWNLOAD);
|
||||||
redirect($fullurl);
|
redirect($fullurl);
|
||||||
}
|
}
|
||||||
|
|
||||||
$resource->mainfile = $file->get_filename();
|
switch ($displaytype) {
|
||||||
switch (resource_get_final_display_type($resource)) {
|
|
||||||
case RESOURCELIB_DISPLAY_EMBED:
|
case RESOURCELIB_DISPLAY_EMBED:
|
||||||
resource_display_embed($resource, $cm, $course, $file);
|
resource_display_embed($resource, $cm, $course, $file);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -286,9 +286,6 @@ function url_get_coursemodule_info($coursemodule) {
|
||||||
$fullurl = "$CFG->wwwroot/mod/url/view.php?id=$coursemodule->id&redirect=1";
|
$fullurl = "$CFG->wwwroot/mod/url/view.php?id=$coursemodule->id&redirect=1";
|
||||||
$info->onclick = "window.open('$fullurl'); return false;";
|
$info->onclick = "window.open('$fullurl'); return false;";
|
||||||
|
|
||||||
} else if ($display == RESOURCELIB_DISPLAY_OPEN) {
|
|
||||||
$fullurl = "$CFG->wwwroot/mod/url/view.php?id=$coursemodule->id&redirect=1";
|
|
||||||
$info->onclick = "window.location.href ='$fullurl';return false;";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($coursemodule->showdescription) {
|
if ($coursemodule->showdescription) {
|
||||||
|
|
|
@ -67,6 +67,15 @@ if (empty($exturl) or $exturl === 'http://') {
|
||||||
}
|
}
|
||||||
unset($exturl);
|
unset($exturl);
|
||||||
|
|
||||||
|
$displaytype = url_get_final_display_type($url);
|
||||||
|
if ($displaytype == RESOURCELIB_DISPLAY_OPEN) {
|
||||||
|
// For 'open' links, we always redirect to the content - except if the user
|
||||||
|
// just chose 'save and display' from the form then that would be confusing
|
||||||
|
if (!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], 'modedit.php') === false) {
|
||||||
|
$redirect = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($redirect) {
|
if ($redirect) {
|
||||||
// coming from course page or url index page,
|
// coming from course page or url index page,
|
||||||
// the redirection is needed for completion tracking and logging
|
// the redirection is needed for completion tracking and logging
|
||||||
|
@ -74,7 +83,7 @@ if ($redirect) {
|
||||||
redirect(str_replace('&', '&', $fullurl));
|
redirect(str_replace('&', '&', $fullurl));
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (url_get_final_display_type($url)) {
|
switch ($displaytype) {
|
||||||
case RESOURCELIB_DISPLAY_EMBED:
|
case RESOURCELIB_DISPLAY_EMBED:
|
||||||
url_display_embed($url, $cm, $course);
|
url_display_embed($url, $cm, $course);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue