MDL-13903 New file resource option for forcing the download of the file instead of embedding it. Backporting from HEAD
This commit is contained in:
@@ -2,9 +2,6 @@
|
||||
|
||||
/**
|
||||
* Extend the base resource class for file resources
|
||||
*
|
||||
* Extend the base resource class for file resources
|
||||
*
|
||||
*/
|
||||
class resource_file extends resource_base {
|
||||
|
||||
@@ -19,8 +16,6 @@ class resource_file extends resource_base {
|
||||
/**
|
||||
* Sets the parameters property of the extended class
|
||||
*
|
||||
* Sets the parameters property of the extended file resource class
|
||||
*
|
||||
* @param USER global object
|
||||
* @param CFG global object
|
||||
*/
|
||||
@@ -168,6 +163,10 @@ class resource_file extends resource_base {
|
||||
unset($resource->$parametername);
|
||||
}
|
||||
|
||||
if ($resource->forcedownload) {
|
||||
$resource->options = 'forcedownload';
|
||||
}
|
||||
|
||||
$resource->alltext = implode(',', $optionlist);
|
||||
}
|
||||
|
||||
@@ -197,10 +196,10 @@ class resource_file extends resource_base {
|
||||
///////////////////////////////////////////////
|
||||
|
||||
/// Possible display modes are:
|
||||
/// File displayed in a frame in a normal window
|
||||
/// File displayed embedded in a normal page
|
||||
/// File displayed in a popup window
|
||||
/// File displayed emebedded in a popup window
|
||||
/// File displayed embedded in a popup window
|
||||
/// File not displayed at all, but downloaded
|
||||
|
||||
|
||||
/// First, find out what sort of file we are dealing with.
|
||||
@@ -215,7 +214,7 @@ class resource_file extends resource_base {
|
||||
$formatoptions = new object();
|
||||
$formatoptions->noclean = true;
|
||||
|
||||
if ($resource->options != "bogusoption_usedtobe_frame") { // TODO nicolasconnault 14-03-07: This option should be renamed "embed"
|
||||
if ($resource->options != "forcedownload") { // TODO nicolasconnault 14-03-07: This option should be renamed "embed"
|
||||
if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) { // It's an image
|
||||
$resourcetype = "image";
|
||||
$embedded = true;
|
||||
@@ -244,10 +243,6 @@ class resource_file extends resource_base {
|
||||
$resourcetype = "mpeg";
|
||||
$embedded = true;
|
||||
|
||||
} else if ($mimetype == "audio/x-pn-realaudio") { // It's a realmedia file
|
||||
$resourcetype = "rm";
|
||||
$embedded = true;
|
||||
|
||||
} else if ($mimetype == "text/html") { // It's a web page
|
||||
$resourcetype = "html";
|
||||
|
||||
@@ -308,10 +303,12 @@ class resource_file extends resource_base {
|
||||
$localpath = true;
|
||||
|
||||
} else { // Normal uploaded file
|
||||
$forcedownloadsep = '?';
|
||||
if ($CFG->slasharguments) {
|
||||
$relativeurl = "/file.php/{$course->id}/{$resource->reference}";
|
||||
if ($querystring) {
|
||||
$relativeurl .= '?'.$querystring;
|
||||
$forcedownloadsep = '&';
|
||||
}
|
||||
} else {
|
||||
$relativeurl = "/file.php?file=/{$course->id}/{$resource->reference}";
|
||||
@@ -320,6 +317,9 @@ class resource_file extends resource_base {
|
||||
}
|
||||
}
|
||||
$fullurl = "$CFG->wwwroot$relativeurl";
|
||||
if ($resource->options == 'forcedownload') {
|
||||
$fullurl .= $forcedownloadsep . 'forcedownload=1';
|
||||
}
|
||||
}
|
||||
|
||||
/// Print a notice and redirect if we are trying to access a file on a local file system
|
||||
@@ -547,21 +547,6 @@ class resource_file extends resource_base {
|
||||
echo '</object>';
|
||||
echo '</div>';
|
||||
|
||||
} else if ($resourcetype == "rm") {
|
||||
|
||||
echo '<div class="resourcecontent resourcerm">';
|
||||
echo '<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="320" height="240">';
|
||||
echo '<param name="src" value="' . $fullurl . '" />';
|
||||
echo '<param name="controls" value="All" />';
|
||||
echo '<!--[if !IE]>-->';
|
||||
echo '<object type="audio/x-pn-realaudio-plugin" data="' . $fullurl . '" width="320" height="240">';
|
||||
echo '<param name="controls" value="All" />';
|
||||
echo '<a href="' . $fullurl . '">' . $fullurl .'</a>';
|
||||
echo '</object>';
|
||||
echo '<!--<![endif]-->';
|
||||
echo '</object>';
|
||||
echo '</div>';
|
||||
|
||||
} else if ($resourcetype == "quicktime") {
|
||||
echo '<div class="resourcecontent resourceqt">';
|
||||
|
||||
@@ -694,6 +679,9 @@ class resource_file extends resource_base {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO document
|
||||
*/
|
||||
function setup_elements(&$mform) {
|
||||
global $CFG, $RESOURCE_WINDOW_OPTIONS;
|
||||
|
||||
@@ -722,15 +710,21 @@ class resource_file extends resource_base {
|
||||
|
||||
$mform->addElement('header', 'displaysettings', get_string('display', 'resource'));
|
||||
|
||||
$mform->addElement('checkbox', 'forcedownload', get_string('forcedownload', 'resource'));
|
||||
$mform->setHelpButton('forcedownload', array('forcedownload', get_string('forcedownload', 'resource'), 'resource'));
|
||||
$mform->disabledIf('forcedownload', 'windowpopup', 'eq', 1);
|
||||
|
||||
$woptions = array(0 => get_string('pagewindow', 'resource'), 1 => get_string('newwindow', 'resource'));
|
||||
$mform->addElement('select', 'windowpopup', get_string('display', 'resource'), $woptions);
|
||||
$mform->setDefault('windowpopup', !empty($CFG->resource_popup));
|
||||
$mform->disabledIf('windowpopup', 'forcedownload', 'checked');
|
||||
|
||||
$mform->addElement('checkbox', 'framepage', get_string('keepnavigationvisible', 'resource'));
|
||||
|
||||
$mform->setHelpButton('framepage', array('frameifpossible', get_string('keepnavigationvisible', 'resource'), 'resource'));
|
||||
$mform->setDefault('framepage', 0);
|
||||
$mform->disabledIf('framepage', 'windowpopup', 'eq', 1);
|
||||
$mform->disabledIf('framepage', 'forcedownload', 'checked');
|
||||
$mform->setAdvanced('framepage');
|
||||
|
||||
foreach ($RESOURCE_WINDOW_OPTIONS as $option) {
|
||||
|
||||
Reference in New Issue
Block a user