[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/blocks/html/ -> block_html.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Form for editing HTML block instances.
  19   *
  20   * @package   block_html
  21   * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  class block_html extends block_base {
  26  
  27      function init() {
  28          $this->title = get_string('pluginname', 'block_html');
  29      }
  30  
  31      function has_config() {
  32          return true;
  33      }
  34  
  35      function applicable_formats() {
  36          return array('all' => true);
  37      }
  38  
  39      function specialization() {
  40          $this->title = isset($this->config->title) ? format_string($this->config->title) : format_string(get_string('newhtmlblock', 'block_html'));
  41      }
  42  
  43      function instance_allow_multiple() {
  44          return true;
  45      }
  46  
  47      function get_content() {
  48          global $CFG;
  49  
  50          require_once($CFG->libdir . '/filelib.php');
  51  
  52          if ($this->content !== NULL) {
  53              return $this->content;
  54          }
  55  
  56          $filteropt = new stdClass;
  57          $filteropt->overflowdiv = true;
  58          if ($this->content_is_trusted()) {
  59              // fancy html allowed only on course, category and system blocks.
  60              $filteropt->noclean = true;
  61          }
  62  
  63          $this->content = new stdClass;
  64          $this->content->footer = '';
  65          if (isset($this->config->text)) {
  66              // rewrite url
  67              $this->config->text = file_rewrite_pluginfile_urls($this->config->text, 'pluginfile.php', $this->context->id, 'block_html', 'content', NULL);
  68              // Default to FORMAT_HTML which is what will have been used before the
  69              // editor was properly implemented for the block.
  70              $format = FORMAT_HTML;
  71              // Check to see if the format has been properly set on the config
  72              if (isset($this->config->format)) {
  73                  $format = $this->config->format;
  74              }
  75              $this->content->text = format_text($this->config->text, $format, $filteropt);
  76          } else {
  77              $this->content->text = '';
  78          }
  79  
  80          unset($filteropt); // memory footprint
  81  
  82          return $this->content;
  83      }
  84  
  85  
  86      /**
  87       * Serialize and store config data
  88       */
  89      function instance_config_save($data, $nolongerused = false) {
  90          global $DB;
  91  
  92          $config = clone($data);
  93          // Move embedded files into a proper filearea and adjust HTML links to match
  94          $config->text = file_save_draft_area_files($data->text['itemid'], $this->context->id, 'block_html', 'content', 0, array('subdirs'=>true), $data->text['text']);
  95          $config->format = $data->text['format'];
  96  
  97          parent::instance_config_save($config, $nolongerused);
  98      }
  99  
 100      function instance_delete() {
 101          global $DB;
 102          $fs = get_file_storage();
 103          $fs->delete_area_files($this->context->id, 'block_html');
 104          return true;
 105      }
 106  
 107      function content_is_trusted() {
 108          global $SCRIPT;
 109  
 110          if (!$context = context::instance_by_id($this->instance->parentcontextid, IGNORE_MISSING)) {
 111              return false;
 112          }
 113          //find out if this block is on the profile page
 114          if ($context->contextlevel == CONTEXT_USER) {
 115              if ($SCRIPT === '/my/index.php') {
 116                  // this is exception - page is completely private, nobody else may see content there
 117                  // that is why we allow JS here
 118                  return true;
 119              } else {
 120                  // no JS on public personal pages, it would be a big security issue
 121                  return false;
 122              }
 123          }
 124  
 125          return true;
 126      }
 127  
 128      /**
 129       * The block should only be dockable when the title of the block is not empty
 130       * and when parent allows docking.
 131       *
 132       * @return bool
 133       */
 134      public function instance_can_be_docked() {
 135          return (!empty($this->config->title) && parent::instance_can_be_docked());
 136      }
 137  
 138      /*
 139       * Add custom html attributes to aid with theming and styling
 140       *
 141       * @return array
 142       */
 143      function html_attributes() {
 144          global $CFG;
 145  
 146          $attributes = parent::html_attributes();
 147  
 148          if (!empty($CFG->block_html_allowcssclasses)) {
 149              if (!empty($this->config->classes)) {
 150                  $attributes['class'] .= ' '.$this->config->classes;
 151              }
 152          }
 153  
 154          return $attributes;
 155      }
 156  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1