Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-31015 File/URL resource 'Open' and 'Force download' options shoul…

…d work consistently
  • Loading branch information...
commit 6abd4cde9c5c9e6214ff95f403ac448312037dfe 1 parent d7630cc
sam marshall sammarshallou authored wdjunaidi committed
24 mod/resource/lib.php
@@ -285,30 +285,6 @@ function resource_get_coursemodule_info($coursemodule) {
285 285 $fullurl = "$CFG->wwwroot/mod/resource/view.php?id=$coursemodule->id&redirect=1";
286 286 $info->onclick = "window.open('$fullurl'); return false;";
287 287
288   - } else if ($display == RESOURCELIB_DISPLAY_OPEN) {
289   - $fullurl = "$CFG->wwwroot/mod/resource/view.php?id=$coursemodule->id&redirect=1";
290   - $info->onclick = "window.location.href ='$fullurl';return false;";
291   -
292   - } else if ($display == RESOURCELIB_DISPLAY_DOWNLOAD) {
293   - if (empty($mainfile)) {
294   - return NULL;
295   - }
296   - // do not open any window because it would be left there after download
297   - $path = '/'.$context->id.'/mod_resource/content/'.$resource->revision.$mainfile->get_filepath().$mainfile->get_filename();
298   - $fullurl = addslashes_js(file_encode_url($CFG->wwwroot.'/pluginfile.php', $path, true));
299   -
300   - // When completion information is enabled for download files, make
301   - // the JavaScript version go to the view page with redirect set,
302   - // instead of directly to the file, otherwise we can't make it tick
303   - // the box for them
304   - if (!$course = $DB->get_record('course', array('id'=>$coursemodule->course), 'id, enablecompletion')) {
305   - return NULL;
306   - }
307   - $completion = new completion_info($course);
308   - if ($completion->is_enabled($coursemodule) == COMPLETION_TRACKING_AUTOMATIC) {
309   - $fullurl = "$CFG->wwwroot/mod/resource/view.php?id=$coursemodule->id&redirect=1";
310   - }
311   - $info->onclick = "window.open('$fullurl'); return false;";
312 288 }
313 289
314 290 // If any optional extra details are turned on, store in custom data
16 mod/resource/view.php
@@ -76,16 +76,26 @@
76 76 unset($files);
77 77 }
78 78
  79 +$resource->mainfile = $file->get_filename();
  80 +$displaytype = resource_get_final_display_type($resource);
  81 +if ($displaytype == RESOURCELIB_DISPLAY_OPEN || $displaytype == RESOURCELIB_DISPLAY_DOWNLOAD) {
  82 + // For 'open' and 'download' links, we always redirect to the content - except
  83 + // if the user just chose 'save and display' from the form then that would be
  84 + // confusing
  85 + if (!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], 'modedit.php') === false) {
  86 + $redirect = true;
  87 + }
  88 +}
  89 +
79 90 if ($redirect) {
80 91 // coming from course page or url index page
81 92 // this redirect trick solves caching problems when tracking views ;-)
82 93 $path = '/'.$context->id.'/mod_resource/content/'.$resource->revision.$file->get_filepath().$file->get_filename();
83   - $fullurl = file_encode_url($CFG->wwwroot.'/pluginfile.php', $path, false);
  94 + $fullurl = moodle_url::make_file_url('/pluginfile.php', $path, $displaytype == RESOURCELIB_DISPLAY_DOWNLOAD);
84 95 redirect($fullurl);
85 96 }
86 97
87   -$resource->mainfile = $file->get_filename();
88   -switch (resource_get_final_display_type($resource)) {
  98 +switch ($displaytype) {
89 99 case RESOURCELIB_DISPLAY_EMBED:
90 100 resource_display_embed($resource, $cm, $course, $file);
91 101 break;
3  mod/url/lib.php
@@ -286,9 +286,6 @@ function url_get_coursemodule_info($coursemodule) {
286 286 $fullurl = "$CFG->wwwroot/mod/url/view.php?id=$coursemodule->id&redirect=1";
287 287 $info->onclick = "window.open('$fullurl'); return false;";
288 288
289   - } else if ($display == RESOURCELIB_DISPLAY_OPEN) {
290   - $fullurl = "$CFG->wwwroot/mod/url/view.php?id=$coursemodule->id&redirect=1";
291   - $info->onclick = "window.location.href ='$fullurl';return false;";
292 289 }
293 290
294 291 if ($coursemodule->showdescription) {
11 mod/url/view.php
@@ -67,6 +67,15 @@
67 67 }
68 68 unset($exturl);
69 69
  70 +$displaytype = url_get_final_display_type($url);
  71 +if ($displaytype == RESOURCELIB_DISPLAY_OPEN) {
  72 + // For 'open' links, we always redirect to the content - except if the user
  73 + // just chose 'save and display' from the form then that would be confusing
  74 + if (!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], 'modedit.php') === false) {
  75 + $redirect = true;
  76 + }
  77 +}
  78 +
70 79 if ($redirect) {
71 80 // coming from course page or url index page,
72 81 // the redirection is needed for completion tracking and logging
@@ -74,7 +83,7 @@
74 83 redirect(str_replace('&', '&', $fullurl));
75 84 }
76 85
77   -switch (url_get_final_display_type($url)) {
  86 +switch ($displaytype) {
78 87 case RESOURCELIB_DISPLAY_EMBED:
79 88 url_display_embed($url, $cm, $course);
80 89 break;

0 comments on commit 6abd4cd

Please sign in to comment.
Something went wrong with that request. Please try again.