Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/blocks/html/block_html.php
Go to the documentation of this file.
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 
00026 class block_html extends block_base {
00027 
00028     function init() {
00029         $this->title = get_string('pluginname', 'block_html');
00030     }
00031 
00032     function applicable_formats() {
00033         return array('all' => true);
00034     }
00035 
00036     function specialization() {
00037         $this->title = isset($this->config->title) ? format_string($this->config->title) : format_string(get_string('newhtmlblock', 'block_html'));
00038     }
00039 
00040     function instance_allow_multiple() {
00041         return true;
00042     }
00043 
00044     function get_content() {
00045         global $CFG;
00046 
00047         require_once($CFG->libdir . '/filelib.php');
00048 
00049         if ($this->content !== NULL) {
00050             return $this->content;
00051         }
00052 
00053         $filteropt = new stdClass;
00054         $filteropt->overflowdiv = true;
00055         if ($this->content_is_trusted()) {
00056             // fancy html allowed only on course, category and system blocks.
00057             $filteropt->noclean = true;
00058         }
00059 
00060         $this->content = new stdClass;
00061         $this->content->footer = '';
00062         if (isset($this->config->text)) {
00063             // rewrite url
00064             $this->config->text = file_rewrite_pluginfile_urls($this->config->text, 'pluginfile.php', $this->context->id, 'block_html', 'content', NULL);
00065             // Default to FORMAT_HTML which is what will have been used before the
00066             // editor was properly implemented for the block.
00067             $format = FORMAT_HTML;
00068             // Check to see if the format has been properly set on the config
00069             if (isset($this->config->format)) {
00070                 $format = $this->config->format;
00071             }
00072             $this->content->text = format_text($this->config->text, $format, $filteropt);
00073         } else {
00074             $this->content->text = '';
00075         }
00076 
00077         unset($filteropt); // memory footprint
00078 
00079         return $this->content;
00080     }
00081 
00082 
00086     function instance_config_save($data, $nolongerused = false) {
00087         global $DB;
00088 
00089         $config = clone($data);
00090         // Move embedded files into a proper filearea and adjust HTML links to match
00091         $config->text = file_save_draft_area_files($data->text['itemid'], $this->context->id, 'block_html', 'content', 0, array('subdirs'=>true), $data->text['text']);
00092         $config->format = $data->text['format'];
00093 
00094         parent::instance_config_save($config, $nolongerused);
00095     }
00096 
00097     function instance_delete() {
00098         global $DB;
00099         $fs = get_file_storage();
00100         $fs->delete_area_files($this->context->id, 'block_html');
00101         return true;
00102     }
00103 
00104     function content_is_trusted() {
00105         global $SCRIPT;
00106 
00107         if (!$context = get_context_instance_by_id($this->instance->parentcontextid)) {
00108             return false;
00109         }
00110         //find out if this block is on the profile page
00111         if ($context->contextlevel == CONTEXT_USER) {
00112             if ($SCRIPT === '/my/index.php') {
00113                 // this is exception - page is completely private, nobody else may see content there
00114                 // that is why we allow JS here
00115                 return true;
00116             } else {
00117                 // no JS on public personal pages, it would be a big security issue
00118                 return false;
00119             }
00120         }
00121 
00122         return true;
00123     }
00124 
00131     public function instance_can_be_docked() {
00132         return (!empty($this->config->title) && parent::instance_can_be_docked());
00133     }
00134 }
 All Data Structures Namespaces Files Functions Variables Enumerations