From 9d54b8cd95db05b2deb7a744426bb8f9dc98d3b3 Mon Sep 17 00:00:00 2001 From: skodak Date: Mon, 11 May 2009 18:49:04 +0000 Subject: [PATCH] MDL-19002 file size limits in filepicker + improved options --- lib/form/filemanager.php | 14 ++------------ lib/form/filepicker.php | 20 +++++++++++++++----- mod/forum/post_form.php | 2 +- mod/glossary/edit_form.php | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/form/filemanager.php b/lib/form/filemanager.php index 81acd13d4c..b70daa16bb 100644 --- a/lib/form/filemanager.php +++ b/lib/form/filemanager.php @@ -5,9 +5,9 @@ require_once(dirname(dirname(dirname(__FILE__))) . '/lib/filelib.php'); class MoodleQuickForm_filemanager extends HTML_QuickForm_element { protected $_helpbutton = ''; - protected $_options = array('subdirs'=>0, 'maxbytes'=>0, 'maxfiles'=>-1); + protected $_options = array('subdirs'=>0, 'maxbytes'=>0, 'maxfiles'=>-1, 'filetypes'=>'*', 'returnvalue'=>'*'); - function MoodleQuickForm_filemanager($elementName=null, $elementLabel=null, $options=null, $attributes=null) { + function MoodleQuickForm_filemanager($elementName=null, $elementLabel=null, $attributes=null, $options=null) { global $CFG; $options = (array)$options; @@ -16,16 +16,6 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element { $this->_options[$name] = $value; } } - if (!empty($options['filetypes'])) { - $this->filetypes = $options['filetypes']; - } else { - $this->filetypes = '*'; - } - if (!empty($options['returnvalue'])) { - $this->returnvalue = $options['returnvalue']; - } else { - $this->returnvalue = '*'; - } if (!empty($options['maxbytes'])) { $this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']); } diff --git a/lib/form/filepicker.php b/lib/form/filepicker.php index 93f809789e..ae0c06dc7b 100644 --- a/lib/form/filepicker.php +++ b/lib/form/filepicker.php @@ -13,11 +13,21 @@ require_once(dirname(dirname(dirname(__FILE__))) . '/repository/lib.php'); * @access public */ class MoodleQuickForm_filepicker extends HTML_QuickForm_input { - var $_helpbutton=''; + protected $_helpbutton = ''; + protected $_options = array('maxbytes'=>0, 'filetypes'=>'*', 'returnvalue'=>'*'); + + function MoodleQuickForm_filepicker($elementName=null, $elementLabel=null, $attributes=null, $options=null) { + global $CFG; - function MoodleQuickForm_filepicker($elementName=null, $elementLabel=null, $attributes=null, $filetypes = '*', $returnvalue = '*') { - $this->filetypes = $filetypes; - $this->returnvalue = $returnvalue; + $options = (array)$options; + foreach ($options as $name=>$value) { + if (array_key_exists($name, $this->_options)) { + $this->_options[$name] = $value; + } + } + if (!empty($options['maxbytes'])) { + $this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']); + } parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes); } @@ -73,7 +83,7 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input { $context = get_context_instance(CONTEXT_COURSE, $COURSE->id); } $client_id = uniqid(); - $repository_info = repository_get_client($context, $client_id, $this->filetypes, $this->returnvalue); + $repository_info = repository_get_client($context, $client_id, $this->_options['filetypes'], $this->_options['returnvalue']); $id = $this->_attributes['id']; $elname = $this->_attributes['name']; diff --git a/mod/forum/post_form.php b/mod/forum/post_form.php index ff0a0fa585..244066b9a3 100644 --- a/mod/forum/post_form.php +++ b/mod/forum/post_form.php @@ -50,7 +50,7 @@ class mod_forum_post_form extends moodleform { } if (!empty($forum->maxattachments) && $forum->maxbytes != 1 && has_capability('mod/forum:createattachment', $modcontext)) { // 1 = No attachments at all - $mform->addElement('filemanager', 'attachments', get_string('attachment', 'forum'), + $mform->addElement('filemanager', 'attachments', get_string('attachment', 'forum'), null, array('subdirs'=>0, 'maxbytes'=>$forum->maxbytes, 'maxfiles'=>$forum->maxattachments, diff --git a/mod/glossary/edit_form.php b/mod/glossary/edit_form.php index 2ede126b13..de29588385 100644 --- a/mod/glossary/edit_form.php +++ b/mod/glossary/edit_form.php @@ -36,7 +36,7 @@ class mod_glossary_entry_form extends moodleform { $mform->setType('aliases', PARAM_TEXT); $mform->setHelpButton('aliases', array('aliases2', strip_tags(get_string('aliases', 'glossary')), 'glossary')); - $mform->addElement('filemanager', 'attachment_filemanager', get_string('attachment', 'glossary'), $attachmentoptions); + $mform->addElement('filemanager', 'attachment_filemanager', get_string('attachment', 'glossary'), null, $attachmentoptions); $mform->setHelpButton('attachment_filemanager', array('attachment2', get_string('attachment', 'glossary'), 'glossary')); if (!$glossary->usedynalink) { -- 2.39.5