MDL-21695 Lesson module now uses new help strings
[moodle.git] / blocks / html / block_html.php
CommitLineData
4ca6cfbf 1<?php
86db09ef 2
3class block_html extends block_base {
4
5 function init() {
8c5bba16 6 $this->title = get_string('pluginname', 'block_html');
433c242f 7 $this->version = 2007101509;
86db09ef 8 }
9
b959599b 10 function applicable_formats() {
11 return array('all' => true);
12 }
13
86db09ef 14 function specialization() {
f36acb35 15 $this->title = isset($this->config->title) ? format_string($this->config->title) : format_string(get_string('newhtmlblock', 'block_html'));
86db09ef 16 }
17
18 function instance_allow_multiple() {
19 return true;
20 }
21
22 function get_content() {
86db09ef 23 if ($this->content !== NULL) {
24 return $this->content;
25 }
26
3179b000 27 if ($this->content_is_trusted()) {
e92c286c 28 // fancy html allowed only on course, category and system blocks.
e8a7edd7 29 $filteropt = new stdClass;
30 $filteropt->noclean = true;
31 } else {
32 $filteropt = null;
33 }
e345909c 34
86db09ef 35 $this->content = new stdClass;
86db09ef 36 $this->content->footer = '';
94ee9ae0
MD
37 if (isset($this->config->text)) {
38 $this->content->text = format_text($this->config->text['text'], $this->config->text['format'], $filteropt);
39 } else {
40 $this->content->text = '';
41 }
86db09ef 42
e345909c 43 unset($filteropt); // memory footprint
44
86db09ef 45 return $this->content;
46 }
43457dc8 47
3179b000 48 function content_is_trusted() {
49 return in_array($this->page->context->contextlevel, array(CONTEXT_COURSE, CONTEXT_COURSECAT, CONTEXT_SYSTEM));
50 }
51
5cfefc9b 52 /**
53 * Will be called before an instance of this block is backed up, so that any links in
54 * any links in any HTML fields on config can be encoded.
55 * @return string
56 */
57 function get_backup_encoded_config() {
83fc4004 58 /// Prevent clone for non configured block instance. Delegate to parent as fallback.
59 if (empty($this->config)) {
60 return parent::get_backup_encoded_config();
61 }
5cfefc9b 62 $data = clone($this->config);
63 $data->text = backup_encode_absolute_links($data->text);
64 return base64_encode(serialize($data));
43457dc8 65 }
66
5cfefc9b 67 /**
68 * This function makes all the necessary calls to {@link restore_decode_content_links_worker()}
4ca6cfbf
PS
69 * function in order to decode contents of this block from the backup
70 * format to destination site/course in order to mantain inter-activities
71 * working in the backup/restore process.
72 *
5cfefc9b 73 * This is called from {@link restore_decode_content_links()} function in the restore process.
74 *
75 * NOTE: There is no block instance when this method is called.
76 *
77 * @param object $restore Standard restore object
78 * @return boolean
79 **/
80 function decode_content_links_caller($restore) {
f28f2d90 81 global $CFG, $DB;
5cfefc9b 82
f28f2d90 83 if ($restored_blocks = $DB->get_records_select("backup_ids", "table_name = 'block_instance' AND backup_code = ? AND new_id > 0", array($restore->backup_unique_code), "", "new_id")) {
5cfefc9b 84 $restored_blocks = implode(',', array_keys($restored_blocks));
85 $sql = "SELECT bi.*
f28f2d90 86 FROM {block_instance} bi
87 JOIN {block} b ON b.id = bi.blockid
4ca6cfbf 88 WHERE b.name = 'html' AND bi.id IN ($restored_blocks)";
5cfefc9b 89
f28f2d90 90 if ($instances = $DB->get_records_sql($sql)) {
5cfefc9b 91 foreach ($instances as $instance) {
92 $blockobject = block_instance('html', $instance);
93 $blockobject->config->text = restore_decode_absolute_links($blockobject->config->text);
94 $blockobject->config->text = restore_decode_content_links_worker($blockobject->config->text, $restore);
e92c286c 95 $blockobject->instance_config_commit();
5cfefc9b 96 }
97 }
98 }
99
100 return true;
43457dc8 101 }
86db09ef 102}
4ca6cfbf 103