weekly release
[moodle.git] / blocks / html / block_html.php
CommitLineData
4ca6cfbf 1<?php
86db09ef 2
64f93798
PS
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * Form for editing HTML block instances.
20 *
21 * @package block_html
22 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
86db09ef 26class block_html extends block_base {
27
28 function init() {
8c5bba16 29 $this->title = get_string('pluginname', 'block_html');
86db09ef 30 }
31
b959599b 32 function applicable_formats() {
33 return array('all' => true);
34 }
35
86db09ef 36 function specialization() {
f36acb35 37 $this->title = isset($this->config->title) ? format_string($this->config->title) : format_string(get_string('newhtmlblock', 'block_html'));
86db09ef 38 }
39
40 function instance_allow_multiple() {
41 return true;
42 }
43
44 function get_content() {
86db09ef 45 if ($this->content !== NULL) {
46 return $this->content;
47 }
48
367a75fa
SH
49 $filteropt = new stdClass;
50 $filteropt->overflowdiv = true;
3179b000 51 if ($this->content_is_trusted()) {
e92c286c 52 // fancy html allowed only on course, category and system blocks.
e8a7edd7 53 $filteropt->noclean = true;
e8a7edd7 54 }
e345909c 55
86db09ef 56 $this->content = new stdClass;
86db09ef 57 $this->content->footer = '';
94ee9ae0 58 if (isset($this->config->text)) {
41976db3 59 // rewrite url
ce162914
DC
60 $this->config->text = file_rewrite_pluginfile_urls($this->config->text, 'pluginfile.php', $this->context->id, 'block_html', 'content', NULL);
61 $this->content->text = format_text($this->config->text, $this->config->format, $filteropt);
94ee9ae0
MD
62 } else {
63 $this->content->text = '';
64 }
86db09ef 65
e345909c 66 unset($filteropt); // memory footprint
67
86db09ef 68 return $this->content;
69 }
43457dc8 70
41976db3
DC
71
72 /**
73 * Serialize and store config data
74 */
75 function instance_config_save($data, $nolongerused = false) {
76 global $DB;
77
ce162914 78 $config = clone($data);
41976db3 79 // Move embedded files into a proper filearea and adjust HTML links to match
ce162914
DC
80 $config->text = file_save_draft_area_files($data->text['itemid'], $this->context->id, 'block_html', 'content', 0, array('subdirs'=>true), $data->text['text']);
81 $config->format = $data->text['format'];
41976db3 82
ce162914 83 parent::instance_config_save($config, $nolongerused);
41976db3
DC
84 }
85
af140288
DC
86 function instance_delete() {
87 global $DB;
88 $fs = get_file_storage();
64f93798 89 $fs->delete_area_files($this->context->id, 'block_html');
af140288
DC
90 return true;
91 }
41976db3 92
3179b000 93 function content_is_trusted() {
d449b246
PS
94 global $SCRIPT;
95
758bfdf6
PS
96 if (!$context = get_context_instance_by_id($this->instance->parentcontextid)) {
97 return false;
98 }
d449b246
PS
99 //find out if this block is on the profile page
100 if ($context->contextlevel == CONTEXT_USER) {
101 if ($SCRIPT === '/my/index.php') {
102 // this is exception - page is completely private, nobody else may see content there
103 // that is why we allow JS here
104 return true;
105 } else {
106 // no JS on public personal pages, it would be a big security issue
107 return false;
108 }
109 }
110
111 return true;
3179b000 112 }
86db09ef 113}