Merge branch 'MDL-73142-311' of https://github.com/susyzan/moodle into MOODLE_311_STABLE
[moodle.git] / lib / html2text / lib.php
blob18972d4c700fb6787d3c75c97f5915fca2dc814b
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.
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/>.
17 /**
18 * Wrapper for Html2Text
20 * This wrapper allows us to modify the upstream library without hacking it too much.
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
27 defined('MOODLE_INTERNAL') || die();
29 require_once($CFG->libdir . '/html2text/Html2Text.php');
30 require_once(__DIR__ . '/override.php');
32 /**
33 * Wrapper for Html2Text
35 * This wrapper allows us to modify the upstream library without hacking it too much.
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
41 class core_html2text extends \Html2Text\Html2Text {
43 /**
44 * Constructor.
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().
50 * @param string $html Source HTML
51 * @param array $options Set configuration options
53 function __construct($html = '', $options = array()) {
54 // Call the parent constructor.
55 parent::__construct($html, $options);
57 // MDL-27736: Trailing spaces before newline or tab.
58 $this->entSearch[] = '/[ ]+([\n\t])/';
59 $this->entReplace[] = '\\1';
62 /**
63 * Strtoupper multibyte wrapper function with HTML entities handling.
65 * @param string $str Text to convert
66 * @return string Converted text
68 protected function strtoupper($str) {
69 return core_text::strtoupper($str);