Merge branch 'MDL-51803-master-mouse' of git://github.com/marinaglancy/moodle
[moodle.git] / filter / tidy / filter.php
blob567f9b683bceb2b1997a37dfd2c2e9f3e858256c
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * HTML tidy text filter.
21 * @package filter
22 * @subpackage tiny
23 * @copyright 2004 Hannes Gassert <hannes at mediagonal dot ch>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') || die();
29 // This class looks for text including markup and
30 // applies tidy's repair function to it.
31 // Tidy is a HTML clean and
32 // repair utility, which is currently available for PHP 4.3.x and PHP 5 as a
33 // PECL extension from http://pecl.php.net/package/tidy, in PHP 5 you need only
34 // to compile using the --with-tidy option.
35 // If you don't have the tidy extension installed or don't know, you can enable
36 // or disable this filter, it just won't have any effect.
37 // If you want to know what you can set in $tidyoptions and what their default
38 // values are, see http://php.net/manual/en/function.tidy-get-config.php.
40 class filter_tidy extends moodle_text_filter {
41 function filter($text, array $options = array()) {
43 /// Configuration for tidy. Feel free to tune for your needs, e.g. to allow
44 /// proprietary markup.
45 $tidyoptions = array(
46 'output-xhtml' => true,
47 'show-body-only' => true,
48 'tidy-mark' => false,
49 'drop-proprietary-attributes' => true,
50 'drop-font-tags' => true,
51 'drop-empty-paras' => true,
52 'indent' => true,
53 'quiet' => true,
56 /// Do a quick check using strpos to avoid unnecessary work
57 if (strpos($text, '<') === false) {
58 return $text;
62 /// If enabled: run tidy over the entire string
63 if (function_exists('tidy_repair_string')){
64 $text = tidy_repair_string($text, $tidyoptions, 'utf8');
67 return $text;