blocklib: MDL-19010 refactor blocklib to use block_manager to get the blocks for...
[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
e8a7edd7 27 if (!empty($this->instance->pinned) or $this->instance->pagetype === 'course-view') {
28 // fancy html allowed only on course page and in pinned blocks for security reasons
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
5cfefc9b 44 /**
45 * Will be called before an instance of this block is backed up, so that any links in
46 * any links in any HTML fields on config can be encoded.
47 * @return string
48 */
49 function get_backup_encoded_config() {
83fc4004 50 /// Prevent clone for non configured block instance. Delegate to parent as fallback.
51 if (empty($this->config)) {
52 return parent::get_backup_encoded_config();
53 }
5cfefc9b 54 $data = clone($this->config);
55 $data->text = backup_encode_absolute_links($data->text);
56 return base64_encode(serialize($data));
43457dc8 57 }
58
5cfefc9b 59 /**
60 * This function makes all the necessary calls to {@link restore_decode_content_links_worker()}
61 * function in order to decode contents of this block from the backup
62 * format to destination site/course in order to mantain inter-activities
63 * working in the backup/restore process.
64 *
65 * This is called from {@link restore_decode_content_links()} function in the restore process.
66 *
67 * NOTE: There is no block instance when this method is called.
68 *
69 * @param object $restore Standard restore object
70 * @return boolean
71 **/
72 function decode_content_links_caller($restore) {
f28f2d90 73 global $CFG, $DB;
5cfefc9b 74
f28f2d90 75 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 76 $restored_blocks = implode(',', array_keys($restored_blocks));
77 $sql = "SELECT bi.*
f28f2d90 78 FROM {block_instance} bi
79 JOIN {block} b ON b.id = bi.blockid
5cfefc9b 80 WHERE b.name = 'html' AND bi.id IN ($restored_blocks)";
81
f28f2d90 82 if ($instances = $DB->get_records_sql($sql)) {
5cfefc9b 83 foreach ($instances as $instance) {
84 $blockobject = block_instance('html', $instance);
85 $blockobject->config->text = restore_decode_absolute_links($blockobject->config->text);
86 $blockobject->config->text = restore_decode_content_links_worker($blockobject->config->text, $restore);
87 $blockobject->instance_config_commit($blockobject->pinned);
88 }
89 }
90 }
91
92 return true;
43457dc8 93 }
86db09ef 94}
95?>