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.

Differences Between: [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   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   * Wrapper for Html2Text
  19   *
  20   * This wrapper allows us to modify the upstream library without hacking it too much.
  21   *
  22   * @package    core
  23   * @copyright  2015 Andrew Nicols <andrew@nicols.uk>
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  require_once($CFG->libdir . '/html2text/Html2Text.php');
  30  require_once (__DIR__ . '/override.php');
  31  
  32  /**
  33   * Wrapper for Html2Text
  34   *
  35   * This wrapper allows us to modify the upstream library without hacking it too much.
  36   *
  37   * @package    core
  38   * @copyright  2015 Andrew Nicols <andrew@nicols.uk>
  39   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  40   */
  41  class core_html2text extends \Html2Text\Html2Text {
  42  
  43      /**
  44       * Constructor.
  45       *
  46       * If the HTML source string (or file) is supplied, the class
  47       * will instantiate with that source propagated, all that has
  48       * to be done it to call get_text().
  49       *
  50       * @param string $html    Source HTML
  51       * @param array  $options Set configuration options
  52       */
  53      function __construct($html = '', $options = array()) {
  54          // Call the parent constructor.
  55          parent::__construct($html, $options);
  56  
  57          // MDL-27736: Trailing spaces before newline or tab.
  58          $this->entSearch[] = '/[ ]+([\n\t])/';
  59          $this->entReplace[] = '\\1';
  60      }
  61  
  62      /**
  63       * Strtoupper multibyte wrapper function with HTML entities handling.
  64       *
  65       * @param string $str Text to convert
  66       * @return string Converted text
  67       */
  68      protected function strtoupper($str) {
  69          return core_text::strtoupper($str);
  70      }
  71  }