MDL-30070 message: Optimised search for users over multiple courses
[moodle.git] / filter / tidy / filter.php
CommitLineData
e5912bca 1<?php
4317f92f 2
35716b86
PS
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.
14//
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/>.
17
18/**
19 * HTML tidy text filter.
20 *
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
25 */
26
27defined('MOODLE_INTERNAL') || die();
28
9e3f34d1 29// This class looks for text including markup and
e5912bca 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.
4317f92f 35// If you don't have the tidy extension installed or don't know, you can enable
e5912bca 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.
4317f92f 39
35716b86 40class filter_tidy extends moodle_text_filter {
dcfffe30 41 function filter($text, array $options = array()) {
4317f92f 42
9e3f34d1 43 /// Configuration for tidy. Feel free to tune for your needs, e.g. to allow
44 /// proprietary markup.
4317f92f 45 $tidyoptions = array(
9e3f34d1 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,
54 );
4317f92f 55
9e3f34d1 56 /// Do a quick check using strpos to avoid unnecessary work
57 if (strpos($text, '<') === false) {
58 return $text;
59 }
60
4317f92f 61
9e3f34d1 62 /// If enabled: run tidy over the entire string
63 if (function_exists('tidy_repair_string')){
64 $text = tidy_repair_string($text, $tidyoptions, 'utf8');
65 }
e5912bca 66
9e3f34d1 67 return $text;
68 }
e5912bca 69}
4317f92f 70