protected function definition() { global $CFG; $mform =& $this->_form; $version = $this->_customdata['version']; $format = $this->_customdata['format']; $tags = !isset($this->_customdata['tags']) ? "" : $this->_customdata['tags']; if ($format != 'html') { $contextid = $this->_customdata['contextid']; $filearea = $this->_customdata['filearea']; $fileitemid = $this->_customdata['fileitemid']; } if (isset($this->_customdata['pagetitle'])) { $pagetitle = get_string('editingpage', 'wiki', $this->_customdata['pagetitle']); } else { $pagetitle = get_string('editing', 'wiki'); } //editor $mform->addElement('header', 'general', $pagetitle); $fieldname = get_string('format' . $format, 'wiki'); if ($format != 'html') { // Use wiki editor $ft = new filetype_parser(); $extensions = $ft->get_extensions('image'); $fs = get_file_storage(); $tree = $fs->get_area_tree($contextid, 'mod_wiki', 'attachments', $fileitemid); $files = array(); foreach ($tree['files'] as $file) { $filename = $file->get_filename(); foreach ($extensions as $ext) { if (preg_match('#' . $ext . '$#', $filename)) { $files[] = $filename; } } } $mform->addElement('wikieditor', 'newcontent', $fieldname, array('cols' => 100, 'rows' => 20, 'wiki_format' => $format, 'files' => $files)); $mform->addHelpButton('newcontent', 'format' . $format, 'wiki'); } else { $mform->addElement('editor', 'newcontent_editor', $fieldname, null, page_wiki_edit::$attachmentoptions); $mform->addHelpButton('newcontent_editor', 'formathtml', 'wiki'); } //hiddens if ($version >= 0) { $mform->addElement('hidden', 'version'); $mform->setDefault('version', $version); } $mform->addElement('hidden', 'contentformat'); $mform->setDefault('contentformat', $format); if (!empty($CFG->usetags)) { $mform->addElement('header', 'tagshdr', get_string('tags', 'tag')); $mform->addElement('tags', 'tags', get_string('tags')); $mform->setDefault('tags', $tags); } $buttongroup = array(); $buttongroup[] =& $mform->createElement('submit', 'editoption', get_string('save', 'wiki'), array('id' => 'save')); $buttongroup[] =& $mform->createElement('submit', 'editoption', get_string('preview'), array('id' => 'preview')); $buttongroup[] =& $mform->createElement('submit', 'editoption', get_string('cancel'), array('id' => 'cancel')); $mform->addGroup($buttongroup, 'buttonar', '', array(' '), false); $mform->closeHeaderBefore('buttonar'); }
public function filter(&$value) { $pass = false; $accepted_types = optional_param_array('accepted_types', '', PARAM_RAW); $ft = new filetype_parser; //$ext = $ft->get_extensions($this->supported_filetypes()); if (isset($value['children'])) { $pass = true; if (!empty($value['children'])) { $value['children'] = array_filter($value['children'], array($this, 'filter')); } } else { if ($accepted_types == '*' or empty($accepted_types) or (is_array($accepted_types) and in_array('*', $accepted_types))) { $pass = true; } elseif (is_array($accepted_types)) { foreach ($accepted_types as $type) { $extensions = $ft->get_extensions($type); if (!is_array($extensions)) { $pass = true; } else { foreach ($extensions as $ext) { if (preg_match('#'.$ext.'$#i', $value['title'])) { $pass = true; } } } } } } return $pass; }
protected function definition() { global $CFG; $mform = $this->_form; $version = $this->_customdata['version']; $format = $this->_customdata['format']; $pagetitle = $this->_customdata['pagetitle']; if (empty($this->_customdata['contextid'])) { // Hack alert // This is being done ONLY to aid those who may have created there own wiki pages. It should be removed sometime // after the release of 2.3 (not creating an issue because this whole thing should be reviewed) debugging('You must always provide mod_wiki_edit_form with a contextid in its custom data', DEBUG_DEVELOPER); global $PAGE; $contextid = $PAGE->context->id; } else { $contextid = $this->_customdata['contextid']; } if (isset($this->_customdata['pagetitle'])) { // Page title must be formatted properly here as this is output and not an element. $pagetitle = get_string('editingpage', 'wiki', format_string($pagetitle, true, array('context' => get_context_instance_by_id($contextid, MUST_EXIST)))); } else { $pagetitle = get_string('editing', 'wiki'); } //editor $mform->addElement('header', 'general', $pagetitle); $fieldname = get_string('format' . $format, 'wiki'); if ($format != 'html') { // Use wiki editor $ft = new filetype_parser(); $extensions = $ft->get_extensions('image'); $fs = get_file_storage(); $tree = $fs->get_area_tree($contextid, 'mod_wiki', $this->_customdata['filearea'], $this->_customdata['fileitemid']); $files = array(); foreach ($tree['files'] as $file) { $filename = $file->get_filename(); foreach ($extensions as $ext) { if (preg_match('#' . $ext . '$#i', $filename)) { $files[] = $filename; } } } $mform->addElement('wikieditor', 'newcontent', $fieldname, array('cols' => 100, 'rows' => 20, 'wiki_format' => $format, 'files' => $files)); $mform->addHelpButton('newcontent', 'format' . $format, 'wiki'); $mform->setType('newcontent', PARAM_RAW); // processed by trust text or cleaned before the display } else { $mform->addElement('editor', 'newcontent_editor', $fieldname, null, page_wiki_edit::$attachmentoptions); $mform->addHelpButton('newcontent_editor', 'formathtml', 'wiki'); $mform->setType('newcontent_editor', PARAM_RAW); // processed by trust text or cleaned before the display } //hiddens if ($version >= 0) { $mform->addElement('hidden', 'version', $version); $mform->setType('version', PARAM_FLOAT); } $mform->addElement('hidden', 'contentformat', $format); $mform->setType('contentformat', PARAM_ALPHANUMEXT); if (!empty($CFG->usetags)) { $tags = !isset($this->_customdata['tags']) ? "" : $this->_customdata['tags']; $mform->addElement('header', 'tagshdr', get_string('tags', 'tag')); $mform->addElement('tags', 'tags', get_string('tags')); $mform->setDefault('tags', $tags); $mform->setType('tags', PARAM_TEXT); } $buttongroup = array(); $buttongroup[] = $mform->createElement('submit', 'editoption', get_string('save', 'wiki'), array('id' => 'save')); $buttongroup[] = $mform->createElement('submit', 'editoption', get_string('preview'), array('id' => 'preview')); $buttongroup[] = $mform->createElement('submit', 'editoption', get_string('cancel'), array('id' => 'cancel')); $mform->addGroup($buttongroup, 'buttonar', '', array(' '), false); $mform->closeHeaderBefore('buttonar'); }