From a0908df7961b20fdefc0613dff7b90d791a785a8 Mon Sep 17 00:00:00 2001 From: Charles Fulton Date: Fri, 29 Jun 2018 15:42:20 -0400 Subject: [PATCH] MDL-28501 mod_folder: make force downloading behavior configuable --- .../backup/moodle2/backup_folder_stepslib.php | 2 +- mod/folder/db/access.php | 5 ++--- mod/folder/db/install.xml | 9 +++++---- mod/folder/db/upgrade.php | 18 +++++++++++++++++- mod/folder/lang/en/folder.php | 3 ++- mod/folder/lib.php | 10 +++++++--- mod/folder/mod_form.php | 6 ++++++ mod/folder/renderer.php | 9 +++++++-- mod/folder/version.php | 2 +- 9 files changed, 48 insertions(+), 16 deletions(-) diff --git a/mod/folder/backup/moodle2/backup_folder_stepslib.php b/mod/folder/backup/moodle2/backup_folder_stepslib.php index 0fdd959fe31cb..950ade3aa6012 100644 --- a/mod/folder/backup/moodle2/backup_folder_stepslib.php +++ b/mod/folder/backup/moodle2/backup_folder_stepslib.php @@ -38,7 +38,7 @@ protected function define_structure() { // Define each element separated $folder = new backup_nested_element('folder', array('id'), array( 'name', 'intro', 'introformat', 'revision', - 'timemodified', 'display', 'showexpanded')); + 'timemodified', 'display', 'showexpanded', 'forcedownload')); // Build the tree // (nice mono-tree, lol) diff --git a/mod/folder/db/access.php b/mod/folder/db/access.php index 3900004509297..d7fd6ea626be9 100644 --- a/mod/folder/db/access.php +++ b/mod/folder/db/access.php @@ -58,9 +58,9 @@ ) ),*/ - // can manage files in the folder + // Can manage files in the folder. 'mod/folder:managefiles' => array( - 'riskbitmask' => RISK_SPAM, + 'riskbitmask' => RISK_SPAM | RISK_XSS, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, 'archetypes' => array( @@ -68,4 +68,3 @@ ) ) ); - diff --git a/mod/folder/db/install.xml b/mod/folder/db/install.xml index 9fc25e1a895a4..11e7bb6a5ed1e 100644 --- a/mod/folder/db/install.xml +++ b/mod/folder/db/install.xml @@ -1,5 +1,5 @@ - @@ -14,8 +14,9 @@ - - + + + @@ -25,4 +26,4 @@ - + \ No newline at end of file diff --git a/mod/folder/db/upgrade.php b/mod/folder/db/upgrade.php index 6bb16b9bfab39..7eaf3d1ff7d20 100644 --- a/mod/folder/db/upgrade.php +++ b/mod/folder/db/upgrade.php @@ -45,7 +45,9 @@ defined('MOODLE_INTERNAL') || die(); function xmldb_folder_upgrade($oldversion) { - global $CFG; + global $CFG, $DB; + + $dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes. // Automatically generated Moodle v3.5.0 release upgrade line. // Put any upgrade step following this. @@ -61,6 +63,20 @@ function xmldb_folder_upgrade($oldversion) { // Automatically generated Moodle v3.9.0 release upgrade line. // Put any upgrade step following this. + if ($oldversion < 2021052501) { + + // Define field forcedownload to be added to folder. + $table = new xmldb_table('folder'); + $field = new xmldb_field('forcedownload', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'showdownloadfolder'); + + // Conditionally launch add field forcedownload. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Folder savepoint reached. + upgrade_mod_savepoint(true, 2021052501, 'folder'); + } return true; } diff --git a/mod/folder/lang/en/folder.php b/mod/folder/lang/en/folder.php index a3fa5d00f894b..59e33ab40740a 100644 --- a/mod/folder/lang/en/folder.php +++ b/mod/folder/lang/en/folder.php @@ -1,5 +1,4 @@ addElement('advcheckbox', 'showdownloadfolder', get_string('showdownloadfolder', 'folder')); $mform->addHelpButton('showdownloadfolder', 'showdownloadfolder', 'mod_folder'); $mform->setDefault('showdownloadfolder', true); + + // Adding option to enable viewing of individual files. + $mform->addElement('advcheckbox', 'forcedownload', get_string('forcedownload', 'folder')); + $mform->addHelpButton('forcedownload', 'forcedownload', 'mod_folder'); + $mform->setDefault('forcedownload', true); + //------------------------------------------------------- $this->standard_coursemodule_elements(); diff --git a/mod/folder/renderer.php b/mod/folder/renderer.php index c48bda9881056..74732f49171c6 100644 --- a/mod/folder/renderer.php +++ b/mod/folder/renderer.php @@ -146,9 +146,14 @@ protected function htmllize_tree($tree, $dir) { } $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')). html_writer::tag('span', $filenamedisplay, array('class' => 'fp-filename')); + $urlparams = null; + if ($tree->folder->forcedownload) { + $urlparams = ['forcedownload' => 1]; + } $filename = html_writer::tag('span', - html_writer::link($url->out(false, array('forcedownload' => 1)), $filename), - array('class' => 'fp-filename-icon')); + html_writer::link($url->out(false, $urlparams), $filename), + ['class' => 'fp-filename-icon'] + ); $result .= html_writer::tag('li', $filename); } $result .= ''; diff --git a/mod/folder/version.php b/mod/folder/version.php index 4ed1f1574ffcd..2b515e3723376 100644 --- a/mod/folder/version.php +++ b/mod/folder/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2021052500; // The current module version (Date: YYYYMMDDXX) +$plugin->version = 2021052501; // The current module version (Date: YYYYMMDDXX) $plugin->requires = 2021052500; // Requires this Moodle version $plugin->component = 'mod_folder'; // Full name of the plugin (used for diagnostics) $plugin->cron = 0;