dirroot.'/lib/filelib.php'); require_once($CFG->dirroot.'/repository/lib.php'); //TODO: // * locking // * freezing // * ajax format conversion class MoodleQuickForm_editor extends HTML_QuickForm_element { public $_helpbutton = ''; public $_type = 'editor'; protected $_options = array('subdirs'=>0, 'maxbytes'=>0, 'maxfiles'=>0, 'changeformat'=>0, 'context'=>null, 'noclean'=>0, 'trusttext'=>0); protected $_values = array('text'=>null, 'format'=>null, 'itemid'=>null); function MoodleQuickForm_editor($elementName=null, $elementLabel=null, $attributes=null, $options=null) { global $CFG, $PAGE; $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']); } if (!$this->_options['context']) { // trying to set context to the current page context to make legacy files show in filepicker (e.g. forum post) if (!empty($PAGE->context->id)) { $this->_options['context'] = $PAGE->context; } else { $this->_options['context'] = context_system::instance(); } } $this->_options['trusted'] = trusttext_trusted($this->_options['context']); parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes); editors_head_setup(); } function setName($name) { $this->updateAttributes(array('name'=>$name)); } function getName() { return $this->getAttribute('name'); } function setValue($values) { $values = (array)$values; foreach ($values as $name=>$value) { if (array_key_exists($name, $this->_values)) { $this->_values[$name] = $value; } } } function getValue() { return $this->_values; } function getMaxbytes() { return $this->_options['maxbytes']; } function setMaxbytes($maxbytes) { global $CFG; $this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $maxbytes); } function getMaxfiles() { return $this->_options['maxfiles']; } function setMaxfiles($num) { $this->_options['maxfiles'] = $num; } function getSubdirs() { return $this->_options['subdirs']; } function setSubdirs($allow) { $this->_options['subdirs'] = $allow; } /** * Returns editor format * * @return int. */ function getFormat() { return $this->_values['format']; } /** * Checks if editor used is tinymce and is required field * * @return true if required field. */ function isRequired() { return (isset($this->_options['required']) && $this->_options['required']); } function setHelpButton($_helpbuttonargs, $function='_helpbutton') { if (!is_array($_helpbuttonargs)) { $_helpbuttonargs = array($_helpbuttonargs); } else { $_helpbuttonargs = $_helpbuttonargs; } //we do this to to return html instead of printing it //without having to specify it in every call to make a button. if ('_helpbutton' == $function){ $defaultargs = array('', '', 'moodle', true, false, '', true); $_helpbuttonargs = $_helpbuttonargs + $defaultargs ; } $this->_helpbutton=call_user_func_array($function, $_helpbuttonargs); } function getHelpButton() { return $this->_helpbutton; } function getElementTemplateType() { if ($this->_flagFrozen){ return 'nodisplay'; } else { return 'default'; } } function toHtml() { global $CFG, $PAGE; require_once($CFG->dirroot.'/repository/lib.php'); if ($this->_flagFrozen) { return $this->getFrozenHtml(); } $ctx = $this->_options['context']; $id = $this->_attributes['id']; $elname = $this->_attributes['name']; $subdirs = $this->_options['subdirs']; $maxbytes = $this->_options['maxbytes']; $maxfiles = $this->_options['maxfiles']; $changeformat = $this->_options['changeformat']; // TO DO: implement as ajax calls $text = $this->_values['text']; $format = $this->_values['format']; $draftitemid = $this->_values['itemid']; // security - never ever allow guest/not logged in user to upload anything if (isguestuser() or !isloggedin()) { $maxfiles = 0; } $str = $this->_getTabs(); $str .= '