e5912bca |
1 | <?php |
2 | |
3 | // This function looks for text including markup and |
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. |
9 | // If you don't have the tidy extension installed or don't know, you can enable |
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. |
13 | |
14 | /** |
15 | * @author Hannes Gassert <hannes at mediagonal dot ch> |
16 | * @param int course id |
17 | * @param string text to be filtered |
18 | */ |
19 | function tidy_filter($courseid, $text) { |
20 | |
21 | /// Configuration for tidy. Feel free to tune for your needs, e.g. to allow |
22 | /// proprietary markup. |
23 | $tidyoptions = array( |
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 | ); |
33 | |
34 | /// Do a quick check using strpos to avoid unnecessary work |
35 | if (strpos($text, '<') === false) { |
36 | return $text; |
37 | } |
38 | |
39 | |
40 | /// If enabled: run tidy over the entire string |
41 | if (function_exists('tidy_repair_string')){ |
7cff0cae |
42 | $text = tidy_repair_string($text, $tidyoptions, 'utf8'); |
e5912bca |
43 | } |
44 | |
45 | return $text; |
46 | } |
47 | ?> |