MDL-33766 files: Improved validation of areamaxbytes

This commit is contained in:
Frederic Massart
2012-11-01 16:47:06 +08:00
parent 380c122fe2
commit 68acd1157e
13 changed files with 78 additions and 16 deletions
+26 -2
View File
@@ -51,8 +51,9 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
public $_type = 'editor';
/** @var array options provided to initalize filepicker */
protected $_options = array('subdirs'=>0, 'maxbytes'=>0, 'maxfiles'=>0, 'changeformat'=>0,
'context'=>null, 'noclean'=>0, 'trusttext'=>0, 'return_types'=>7);
protected $_options = array('subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 0, 'changeformat' => 0,
'areamaxbytes' => FILE_AREA_MAX_BYTES_UNLIMITED, 'context' => null, 'noclean' => 0, 'trusttext' => 0,
'return_types' => 7);
// $_options['return_types'] = FILE_INTERNAL | FILE_EXTERNAL | FILE_REFERENCE
/** @var array values for editor */
@@ -153,6 +154,24 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $maxbytes);
}
/**
* Returns the maximum size of the area.
*
* @return int
*/
function getAreamaxbytes() {
return $this->_options['areamaxbytes'];
}
/**
* Sets the maximum size of the area.
*
* @param int $areamaxbytes size limit
*/
function setAreamaxbytes($areamaxbytes) {
$this->_options['areamaxbytes'] = $areamaxbytes;
}
/**
* Returns maximum number of files which can be uploaded
*
@@ -274,6 +293,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
$subdirs = $this->_options['subdirs'];
$maxbytes = $this->_options['maxbytes'];
$areamaxbytes = $this->_options['areamaxbytes'];
$maxfiles = $this->_options['maxfiles'];
$changeformat = $this->_options['changeformat']; // TO DO: implement as ajax calls
@@ -318,6 +338,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
$image_options->context = $ctx;
$image_options->client_id = uniqid();
$image_options->maxbytes = $this->_options['maxbytes'];
$image_options->areamaxbytes = $this->_options['areamaxbytes'];
$image_options->env = 'editor';
$image_options->itemid = $draftitemid;
@@ -327,6 +348,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
$media_options->context = $ctx;
$media_options->client_id = uniqid();
$media_options->maxbytes = $this->_options['maxbytes'];
$media_options->areamaxbytes = $this->_options['areamaxbytes'];
$media_options->env = 'editor';
$media_options->itemid = $draftitemid;
@@ -336,6 +358,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
$link_options->context = $ctx;
$link_options->client_id = uniqid();
$link_options->maxbytes = $this->_options['maxbytes'];
$link_options->areamaxbytes = $this->_options['areamaxbytes'];
$link_options->env = 'editor';
$link_options->itemid = $draftitemid;
@@ -389,6 +412,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
'itemid'=>$draftitemid,
'subdirs'=>$subdirs,
'maxbytes'=>$maxbytes,
'areamaxbytes' => $areamaxbytes,
'maxfiles'=>$maxfiles,
'ctx_id'=>$ctx->id,
'course'=>$PAGE->course->id,