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() { |
48f7fa4a |
15 | $this->title = isset($this->config->title) ? $this->config->title : 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() { |
45 | $data = clone($this->config); |
46 | $data->text = backup_encode_absolute_links($data->text); |
47 | return base64_encode(serialize($data)); |
43457dc8 |
48 | } |
49 | |
5cfefc9b |
50 | /** |
51 | * This function makes all the necessary calls to {@link restore_decode_content_links_worker()} |
52 | * function in order to decode contents of this block from the backup |
53 | * format to destination site/course in order to mantain inter-activities |
54 | * working in the backup/restore process. |
55 | * |
56 | * This is called from {@link restore_decode_content_links()} function in the restore process. |
57 | * |
58 | * NOTE: There is no block instance when this method is called. |
59 | * |
60 | * @param object $restore Standard restore object |
61 | * @return boolean |
62 | **/ |
63 | function decode_content_links_caller($restore) { |
64 | global $CFG; |
65 | |
66 | 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")) { |
67 | $restored_blocks = implode(',', array_keys($restored_blocks)); |
68 | $sql = "SELECT bi.* |
69 | FROM {$CFG->prefix}block_instance bi |
70 | JOIN {$CFG->prefix}block b ON b.id = bi.blockid |
71 | WHERE b.name = 'html' AND bi.id IN ($restored_blocks)"; |
72 | |
73 | if ($instances = get_records_sql($sql)) { |
74 | foreach ($instances as $instance) { |
75 | $blockobject = block_instance('html', $instance); |
76 | $blockobject->config->text = restore_decode_absolute_links($blockobject->config->text); |
77 | $blockobject->config->text = restore_decode_content_links_worker($blockobject->config->text, $restore); |
78 | $blockobject->instance_config_commit($blockobject->pinned); |
79 | } |
80 | } |
81 | } |
82 | |
83 | return true; |
43457dc8 |
84 | } |
86db09ef |
85 | } |
86 | ?> |