|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00030 if (!defined('MOODLE_INTERNAL')) { 00031 die('Direct access to this script is forbidden.'); 00032 } 00033 00034 require_once($CFG->dirroot . '/mod/wiki/editors/wikieditor.php'); 00035 00036 class mod_wiki_edit_form extends moodleform { 00037 00038 protected function definition() { 00039 global $CFG; 00040 00041 $mform =& $this->_form; 00042 00043 $version = $this->_customdata['version']; 00044 $format = $this->_customdata['format']; 00045 $tags = !isset($this->_customdata['tags'])?"":$this->_customdata['tags']; 00046 00047 if ($format != 'html') { 00048 $contextid = $this->_customdata['contextid']; 00049 $filearea = $this->_customdata['filearea']; 00050 $fileitemid = $this->_customdata['fileitemid']; 00051 } 00052 00053 if (isset($this->_customdata['pagetitle'])) { 00054 $pagetitle = get_string('editingpage', 'wiki', $this->_customdata['pagetitle']); 00055 } else { 00056 $pagetitle = get_string('editing', 'wiki'); 00057 } 00058 00059 //editor 00060 $mform->addElement('header', 'general', $pagetitle); 00061 00062 $fieldname = get_string('format' . $format, 'wiki'); 00063 if ($format != 'html') { 00064 // Use wiki editor 00065 $ft = new filetype_parser; 00066 $extensions = $ft->get_extensions('image'); 00067 $fs = get_file_storage(); 00068 $tree = $fs->get_area_tree($contextid, 'mod_wiki', 'attachments', $fileitemid); 00069 $files = array(); 00070 foreach ($tree['files'] as $file) { 00071 $filename = $file->get_filename(); 00072 foreach ($extensions as $ext) { 00073 if (preg_match('#'.$ext.'$#i', $filename)) { 00074 $files[] = $filename; 00075 } 00076 } 00077 } 00078 $mform->addElement('wikieditor', 'newcontent', $fieldname, array('cols' => 100, 'rows' => 20, 'wiki_format' => $format, 'files'=>$files)); 00079 $mform->addHelpButton('newcontent', 'format'.$format, 'wiki'); 00080 } else { 00081 $mform->addElement('editor', 'newcontent_editor', $fieldname, null, page_wiki_edit::$attachmentoptions); 00082 $mform->addHelpButton('newcontent_editor', 'formathtml', 'wiki'); 00083 } 00084 00085 //hiddens 00086 if ($version >= 0) { 00087 $mform->addElement('hidden', 'version'); 00088 $mform->setDefault('version', $version); 00089 } 00090 00091 $mform->addElement('hidden', 'contentformat'); 00092 $mform->setDefault('contentformat', $format); 00093 00094 if (!empty($CFG->usetags)) { 00095 $mform->addElement('header', 'tagshdr', get_string('tags', 'tag')); 00096 $mform->addElement('tags', 'tags', get_string('tags')); 00097 $mform->setDefault('tags', $tags); 00098 } 00099 00100 $buttongroup = array(); 00101 $buttongroup[] =& $mform->createElement('submit', 'editoption', get_string('save', 'wiki'), array('id' => 'save')); 00102 $buttongroup[] =& $mform->createElement('submit', 'editoption', get_string('preview'), array('id' => 'preview')); 00103 $buttongroup[] =& $mform->createElement('submit', 'editoption', get_string('cancel'), array('id' => 'cancel')); 00104 00105 $mform->addGroup($buttongroup, 'buttonar', '', array(' '), false); 00106 $mform->closeHeaderBefore('buttonar'); 00107 } 00108 00109 }