Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / blocks / html / block_html.php
blobe894deae2f788a22ecbf941350a0783e4edda747
1 <?php //$Id$
3 class block_html extends block_base {
5 function init() {
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() {
19 return true;
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;
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
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));
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.
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
65 * @return boolean
66 **/
67 function decode_content_links_caller($restore) {
68 global $CFG;
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)";
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);
87 return true;