[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1