Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   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  /**
  19   * htmleditor type form element
  20   *
  21   * Contains HTML class for htmleditor type element
  22   *
  23   * @deprecated since 3.6
  24   * @package   core_form
  25   * @copyright 2006 Jamie Pratt <me@jamiep.org>
  26   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27   */
  28  
  29  global $CFG;
  30  require_once("$CFG->libdir/form/textarea.php");
  31  
  32  /**
  33   * htmleditor type form element
  34   *
  35   * HTML class for htmleditor type element
  36   *
  37   * @package   core_form
  38   * @category  form
  39   * @copyright 2006 Jamie Pratt <me@jamiep.org>
  40   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41   */
  42  class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{
  43      /** @var string defines the type of editor */
  44      var $_type;
  45  
  46      /** @var array default options for html editor, which can be overridden */
  47      var $_options=array('rows'=>10, 'cols'=>45, 'width'=>0,'height'=>0);
  48  
  49      /**
  50       * Constructor
  51       *
  52       * @param string $elementName (optional) name of the html editor
  53       * @param string $elementLabel (optional) editor label
  54       * @param array $options set of options to create html editor
  55       * @param array $attributes (optional) Either a typical HTML attribute string
  56       *              or an associative array
  57       */
  58      public function __construct($elementName=null, $elementLabel=null, $options=array(), $attributes=null){
  59          debugging("The form element 'htmleditor' has been deprecated. Please use the 'editor' element instead.", DEBUG_DEVELOPER);
  60  
  61          parent::__construct($elementName, $elementLabel, $attributes);
  62          // set the options, do not bother setting bogus ones
  63          if (is_array($options)) {
  64              foreach ($options as $name => $value) {
  65                  if (array_key_exists($name, $this->_options)) {
  66                      if (is_array($value) && is_array($this->_options[$name])) {
  67                          $this->_options[$name] = @array_merge($this->_options[$name], $value);
  68                      } else {
  69                          $this->_options[$name] = $value;
  70                      }
  71                  }
  72              }
  73          }
  74          $this->_type='htmleditor';
  75  
  76          editors_head_setup();
  77      }
  78  
  79      /**
  80       * Old syntax of class constructor. Deprecated in PHP7.
  81       *
  82       * @deprecated since Moodle 3.1
  83       */
  84      public function MoodleQuickForm_htmleditor($elementName=null, $elementLabel=null, $options=array(), $attributes=null) {
  85          debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
  86          self::__construct($elementName, $elementLabel, $options, $attributes);
  87      }
  88  
  89      /**
  90       * Returns the input field in HTML
  91       *
  92       * @return string
  93       */
  94      public function toHtml() {
  95          global $OUTPUT;
  96  
  97          if ($this->_flagFrozen) {
  98              return $this->getFrozenHtml();
  99          } else {
 100              $value = preg_replace("/(\r\n|\n|\r)/", '&#010;', $this->getValue());
 101  
 102              return $this->_getTabs() .
 103                  $OUTPUT->print_textarea($this->getName(), $this->getAttribute('id'), $value, $this->_options['rows'],
 104                      $this->_options['cols']);
 105          }
 106      }
 107  
 108      /**
 109       * What to display when element is frozen.
 110       *
 111       * @return string
 112       */
 113      function getFrozenHtml()
 114      {
 115          $html = format_text($this->getValue());
 116          return $html . $this->_getPersistantData();
 117      }
 118  }