|
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 00032 class block_html_edit_form extends block_edit_form { 00033 protected function specific_definition($mform) { 00034 // Fields for editing HTML block title and contents. 00035 $mform->addElement('header', 'configheader', get_string('blocksettings', 'block')); 00036 00037 $mform->addElement('text', 'config_title', get_string('configtitle', 'block_html')); 00038 $mform->setType('config_title', PARAM_MULTILANG); 00039 00040 $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$this->block->context); 00041 $mform->addElement('editor', 'config_text', get_string('configcontent', 'block_html'), null, $editoroptions); 00042 $mform->addRule('config_text', null, 'required', null, 'client'); 00043 $mform->setType('config_text', PARAM_RAW); // XSS is prevented when printing the block contents and serving files 00044 } 00045 00046 function set_data($defaults) { 00047 if (!empty($this->block->config) && is_object($this->block->config)) { 00048 $text = $this->block->config->text; 00049 $draftid_editor = file_get_submitted_draft_itemid('config_text'); 00050 if (empty($text)) { 00051 $currenttext = ''; 00052 } else { 00053 $currenttext = $text; 00054 } 00055 $defaults->config_text['text'] = file_prepare_draft_area($draftid_editor, $this->block->context->id, 'block_html', 'content', 0, array('subdirs'=>true), $currenttext); 00056 $defaults->config_text['itemid'] = $draftid_editor; 00057 $defaults->config_text['format'] = $this->block->config->format; 00058 } else { 00059 $text = ''; 00060 } 00061 00062 if (!$this->block->user_can_edit() && !empty($this->block->config->title)) { 00063 // If a title has been set but the user cannot edit it format it nicely 00064 $title = $this->block->config->title; 00065 $defaults->config_title = format_string($title, true, $this->page->context); 00066 // Remove the title from the config so that parent::set_data doesn't set it. 00067 unset($this->block->config->title); 00068 } 00069 00070 // have to delete text here, otherwise parent::set_data will empty content 00071 // of editor 00072 unset($this->block->config->text); 00073 parent::set_data($defaults); 00074 // restore $text 00075 if (!isset($this->block->config)) { 00076 $this->block->config = new stdClass(); 00077 } 00078 $this->block->config->text = $text; 00079 if (isset($title)) { 00080 // Reset the preserved title 00081 $this->block->config->title = $title; 00082 } 00083 } 00084 }