Old modules and plugins

Note: This database has been replaced by the Moodle Plugins Directory.

Page: ()  1 ...  521  522  523  524  525  526  527  528  529  530  531  532  533  534  535  536  537  538 ...783   ()

Small Hack: Resource Always Download Hack

Type: Small Hack
Requires: Moodle 1.7 or later
Status: Contributed
Maintainer(s):

Resource Always Download Hack


This is a small hack that enables you to configure certain files to ALWAYS be downloaded and not displayed inline.

This is useful for power point files where some users have encountered problems with presentations being displayed inline.


1) Add the media types you want to be forced to download to your config file as in following example:


// GT Mod 2008/01/18 - Always Download Hack - Configure your mime types to always download here
$CFG->allwaysdownload=array('application/vnd.ms-powerpoint');

2) Modify moodle/lib/filelib.php arround line 255 with the following hack (hack code is blue and starts with //GT Mod):

function send_file($path, $filename, $lifetime=86400 , $filter=0, $pathisstring=false, $forcedownload=false, $mimetype='') {
global $CFG, $COURSE;

// GT Mod 2008/01/18 - Always Download Hack - Part 1 - force download of mime types in config array $CFG->allwaysdownload
$allwaysdownload=isset($CFG->allwaysdownload) ? $CFG->allwaysdownload : array();
if (in_array(mimeinfo('type', $filename), $allwaysdownload)){
$forcedownload=true;
}
// End GT Mod 2008/01/18 - Always Download Hack - Part 1

3) Modify moodle/lib/filelib.php arround line 300 with following hack (hack code is blue and starts with //GT Mod)

//do not put '@' before the next header to detect incorrect moodle configurations,
//error should be better than "weird" empty lines for admins/users
//TODO: should we remove all those @ before the header()? Are all of the values supported on all servers?
header('Last-Modified: '. gmdate('D, d M Y H:i:s', $lastmodified) .' GMT');

// GT Mod 2008/01/18 - Always Download Hack - Part 2 - force download of mime types in config array $CFG->allwaysdownload
if (in_array(mimeinfo('type', $filename), $allwaysdownload)){
$forcedownload=true;
} else {
$forcedownload=false;
}
// GT Mod 2008/01/18 - Always Download Hack - Part 2

Note:

All the mime types are listed in moodle/lib/filelib.php within the function get_mimetypes_array.

So if you wanted to force mp3s to download, you would need to get the mime type from get_mimetypes_array-

'mp3' => array ('type'=>'audio/mp3', 'icon'=>'audio.gif'),

We can see that an mp3's type is 'audio/mp3'.
Your config file would therefore need to include:

$CFG->allwaysdownload=array('audio/mp3');

To force more than one file to download, add multiple types to the 'allwaysdownload' array: e.g.

$CFG->allwaysdownload=array('audio/mp3', 'video/mpeg');


Record added by Guy Thomas - Friday, January 18, 2008, 7:55 PM
Last modified - Tuesday, April 15, 2008, 6:30 PM
Page: ()  1 ...  521  522  523  524  525  526  527  528  529  530  531  532  533  534  535  536  537  538 ...783   ()