86db09ef |
1 | <?php //$Id$ |
2 | |
3 | class 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 | |
e345909c |
27 | $filteropt = new stdClass; |
28 | $filteropt->noclean = true; |
29 | |
86db09ef |
30 | $this->content = new stdClass; |
e345909c |
31 | $this->content->text = isset($this->config->text) ? format_text($this->config->text, FORMAT_HTML, $filteropt) : ''; |
86db09ef |
32 | $this->content->footer = ''; |
33 | |
e345909c |
34 | unset($filteropt); // memory footprint |
35 | |
86db09ef |
36 | return $this->content; |
37 | } |
43457dc8 |
38 | |
5cfefc9b |
39 | /** |
40 | * Will be called before an instance of this block is backed up, so that any links in |
41 | * any links in any HTML fields on config can be encoded. |
42 | * @return string |
43 | */ |
44 | function get_backup_encoded_config() { |
83fc4004 |
45 | /// Prevent clone for non configured block instance. Delegate to parent as fallback. |
46 | if (empty($this->config)) { |
47 | return parent::get_backup_encoded_config(); |
48 | } |
5cfefc9b |
49 | $data = clone($this->config); |
50 | $data->text = backup_encode_absolute_links($data->text); |
51 | return base64_encode(serialize($data)); |
43457dc8 |
52 | } |
53 | |
5cfefc9b |
54 | /** |
55 | * This function makes all the necessary calls to {@link restore_decode_content_links_worker()} |
56 | * function in order to decode contents of this block from the backup |
57 | * format to destination site/course in order to mantain inter-activities |
58 | * working in the backup/restore process. |
59 | * |
60 | * This is called from {@link restore_decode_content_links()} function in the restore process. |
61 | * |
62 | * NOTE: There is no block instance when this method is called. |
63 | * |
64 | * @param object $restore Standard restore object |
65 | * @return boolean |
66 | **/ |
67 | function decode_content_links_caller($restore) { |
68 | global $CFG; |
69 | |
70 | if ($restored_blocks = get_records_select("backup_ids","table_name = 'block_instance' AND backup_code = $restore->backup_unique_code AND new_id > 0", "", "new_id")) { |
71 | $restored_blocks = implode(',', array_keys($restored_blocks)); |
72 | $sql = "SELECT bi.* |
73 | FROM {$CFG->prefix}block_instance bi |
74 | JOIN {$CFG->prefix}block b ON b.id = bi.blockid |
75 | WHERE b.name = 'html' AND bi.id IN ($restored_blocks)"; |
76 | |
77 | if ($instances = get_records_sql($sql)) { |
78 | foreach ($instances as $instance) { |
79 | $blockobject = block_instance('html', $instance); |
80 | $blockobject->config->text = restore_decode_absolute_links($blockobject->config->text); |
81 | $blockobject->config->text = restore_decode_content_links_worker($blockobject->config->text, $restore); |
82 | $blockobject->instance_config_commit($blockobject->pinned); |
83 | } |
84 | } |
85 | } |
86 | |
87 | return true; |
43457dc8 |
88 | } |
86db09ef |
89 | } |
90 | ?> |