3 class block_html extends block_base {
6 $this->title = get_string('pluginname', '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 if ($this->content_is_trusted()) {
28 // fancy html allowed only on course, category and system blocks.
29 $filteropt = new stdClass;
30 $filteropt->noclean = true;
35 $this->content = new stdClass;
36 $this->content->text = isset($this->config->text) ? format_text($this->config->text, FORMAT_HTML, $filteropt) : '';
37 $this->content->footer = '';
39 unset($filteropt); // memory footprint
41 return $this->content;
44 function content_is_trusted() {
45 return in_array($this->page->context->contextlevel, array(CONTEXT_COURSE, CONTEXT_COURSECAT, CONTEXT_SYSTEM));
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.
53 function get_backup_encoded_config() {
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();
58 $data = clone($this->config);
59 $data->text = backup_encode_absolute_links($data->text);
60 return base64_encode(serialize($data));
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.
69 * This is called from {@link restore_decode_content_links()} function in the restore process.
71 * NOTE: There is no block instance when this method is called.
73 * @param object $restore Standard restore object
76 function decode_content_links_caller($restore) {
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")) {
80 $restored_blocks = implode(',', array_keys($restored_blocks));
82 FROM {block_instance} bi
83 JOIN {block} b ON b.id = bi.blockid
84 WHERE b.name = 'html' AND bi.id IN ($restored_blocks)";
86 if ($instances = $DB->get_records_sql($sql)) {
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);
91 $blockobject->instance_config_commit();