Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
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
 
27
defined('MOODLE_INTERNAL') || die();
28
 
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.
39
 
40
class filter_tidy extends moodle_text_filter {
41
    function filter($text, array $options = array()) {
42
 
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-empty-paras' => true,
51
                 'indent' => true,
52
                 'quiet' => true,
53
        );
54
 
55
    /// Do a quick check using strpos to avoid unnecessary work
56
        if (strpos($text, '<') === false) {
57
            return $text;
58
        }
59
 
60
 
61
    /// If enabled: run tidy over the entire string
62
        if (function_exists('tidy_repair_string')){
11 efrain 63
            $currentlocale = \core\locale::get_locale();
64
            try {
65
                $text = tidy_repair_string($text, $tidyoptions, 'utf8');
66
            } finally {
67
                \core\locale::set_locale(LC_ALL, $currentlocale);
68
            }
1 efrain 69
        }
70
 
71
        return $text;
72
    }
73
}