MDL-23479 backup - choice revised & old code deleted (but restore logs)
[moodle.git] / filter / tidy / filter.php
CommitLineData
e5912bca 1<?php
4317f92f 2
9e3f34d1 3// This class looks for text including markup and
e5912bca 4// applies tidy's repair function to it.
5// Tidy is a HTML clean and
6// repair utility, which is currently available for PHP 4.3.x and PHP 5 as a
7// PECL extension from http://pecl.php.net/package/tidy, in PHP 5 you need only
8// to compile using the --with-tidy option.
4317f92f 9// If you don't have the tidy extension installed or don't know, you can enable
e5912bca 10// or disable this filter, it just won't have any effect.
11// If you want to know what you can set in $tidyoptions and what their default
12// values are, see http://php.net/manual/en/function.tidy-get-config.php.
4317f92f 13
ccc161f8 14class tidy_filter extends moodle_text_filter {
9e3f34d1 15 /**
16 * @author Hannes Gassert <hannes at mediagonal dot ch>
17 * @param string text to be filtered
18 */
19 function filter($text) {
4317f92f 20
9e3f34d1 21 /// Configuration for tidy. Feel free to tune for your needs, e.g. to allow
22 /// proprietary markup.
4317f92f 23 $tidyoptions = array(
9e3f34d1 24 'output-xhtml' => true,
25 'show-body-only' => true,
26 'tidy-mark' => false,
27 'drop-proprietary-attributes' => true,
28 'drop-font-tags' => true,
29 'drop-empty-paras' => true,
30 'indent' => true,
31 'quiet' => true,
32 );
4317f92f 33
9e3f34d1 34 /// Do a quick check using strpos to avoid unnecessary work
35 if (strpos($text, '<') === false) {
36 return $text;
37 }
38
4317f92f 39
9e3f34d1 40 /// If enabled: run tidy over the entire string
41 if (function_exists('tidy_repair_string')){
42 $text = tidy_repair_string($text, $tidyoptions, 'utf8');
43 }
e5912bca 44
9e3f34d1 45 return $text;
46 }
e5912bca 47}
4317f92f 48