3 class block_html
extends block_base
{
6 $this->title
= get_string('html', 'block_html');
7 $this->version
= 2007101509;
10 function applicable_formats() {
11 return array('all' => true);
14 function specialization() {
15 $this->title
= isset($this->config
->title
) ?
format_string($this->config
->title
) : format_string(get_string('newhtmlblock', 'block_html'));
18 function instance_allow_multiple() {
22 function get_content() {
23 if ($this->content
!== NULL) {
24 return $this->content
;
27 $filteropt = new stdClass
;
28 $filteropt->noclean
= true;
30 $this->content
= new stdClass
;
31 $this->content
->text
= isset($this->config
->text
) ?
format_text($this->config
->text
, FORMAT_HTML
, $filteropt) : '';
32 $this->content
->footer
= '';
34 unset($filteropt); // memory footprint
36 return $this->content
;
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.
44 function get_backup_encoded_config() {
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();
49 $data = clone($this->config
);
50 $data->text
= backup_encode_absolute_links($data->text
);
51 return base64_encode(serialize($data));
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.
60 * This is called from {@link restore_decode_content_links()} function in the restore process.
62 * NOTE: There is no block instance when this method is called.
64 * @param object $restore Standard restore object
67 function decode_content_links_caller($restore) {
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));
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)";
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
);