MDL-20700 coding style cleanup - cvs keywords removed, closign php tag removed, trail...
[moodle.git] / blocks / html / block_html.php
CommitLineData
86db09ef 1<?php //$Id$
2
3class block_html extends block_base {
4
5 function init() {
6 $this->title = get_string('html', '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;
e345909c 36 $this->content->text = isset($this->config->text) ? format_text($this->config->text, FORMAT_HTML, $filteropt) : '';
86db09ef 37 $this->content->footer = '';
38
e345909c 39 unset($filteropt); // memory footprint
40
86db09ef 41 return $this->content;
42 }
43457dc8 43
3179b000 44 function content_is_trusted() {
45 return in_array($this->page->context->contextlevel, array(CONTEXT_COURSE, CONTEXT_COURSECAT, CONTEXT_SYSTEM));
46 }
47
5cfefc9b 48 /**
49 * Will be called before an instance of this block is backed up, so that any links in
50 * any links in any HTML fields on config can be encoded.
51 * @return string
52 */
53 function get_backup_encoded_config() {
83fc4004 54 /// Prevent clone for non configured block instance. Delegate to parent as fallback.
55 if (empty($this->config)) {
56 return parent::get_backup_encoded_config();
57 }
5cfefc9b 58 $data = clone($this->config);
59 $data->text = backup_encode_absolute_links($data->text);
60 return base64_encode(serialize($data));
43457dc8 61 }
62
5cfefc9b 63 /**
64 * This function makes all the necessary calls to {@link restore_decode_content_links_worker()}
65 * function in order to decode contents of this block from the backup
66 * format to destination site/course in order to mantain inter-activities
67 * working in the backup/restore process.
68 *
69 * This is called from {@link restore_decode_content_links()} function in the restore process.
70 *
71 * NOTE: There is no block instance when this method is called.
72 *
73 * @param object $restore Standard restore object
74 * @return boolean
75 **/
76 function decode_content_links_caller($restore) {
f28f2d90 77 global $CFG, $DB;
5cfefc9b 78
f28f2d90 79 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 80 $restored_blocks = implode(',', array_keys($restored_blocks));
81 $sql = "SELECT bi.*
f28f2d90 82 FROM {block_instance} bi
83 JOIN {block} b ON b.id = bi.blockid
5cfefc9b 84 WHERE b.name = 'html' AND bi.id IN ($restored_blocks)";
85
f28f2d90 86 if ($instances = $DB->get_records_sql($sql)) {
5cfefc9b 87 foreach ($instances as $instance) {
88 $blockobject = block_instance('html', $instance);
89 $blockobject->config->text = restore_decode_absolute_links($blockobject->config->text);
90 $blockobject->config->text = restore_decode_content_links_worker($blockobject->config->text, $restore);
e92c286c 91 $blockobject->instance_config_commit();
5cfefc9b 92 }
93 }
94 }
95
96 return true;
43457dc8 97 }
86db09ef 98}
99?>