~ubuntu-branches/ubuntu/natty/moodle/natty

« back to all changes in this revision

Viewing changes to lib/htmlpurifier/HTMLPurifier/DoctypeRegistry.php

  • Committer: Bazaar Package Importer
  • Author(s): Tomasz Muras
  • Date: 2010-10-30 12:19:28 UTC
  • mfrom: (1.1.12 upstream) (3.1.10 squeeze)
  • Revision ID: james.westby@ubuntu.com-20101030121928-qzobi6mctpnk4dif
Tags: 1.9.9.dfsg2-2
* Added Romanian translation
* Updated Japanese translation (closes: #596820)
* Backporting security fixes from Moodle 1.9.10 (closes: #601384)
   - Updated embedded CAS to 1.1.3
   - Added patch for MDL-24523:
     clean_text() not filtering text in markdown format
   - Added patch for MDL-24810 and upgraded customized HTML Purifier to 4.2.0 
   - Added patch for MDL-24258:
     students can delete their forum posts later than $CFG->maxeditingtime 
     under certain conditions
   - Added patch for MDL-23377:
     Can't delete quiz attempts in course without enrolled students

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
 
3
 
require_once 'HTMLPurifier/Doctype.php';
4
 
 
5
 
// Legacy directives for doctype specification
6
 
HTMLPurifier_ConfigSchema::define(
7
 
    'HTML', 'Strict', false, 'bool',
8
 
    'Determines whether or not to use Transitional (loose) or Strict rulesets. '.
9
 
    'This directive is deprecated in favor of %HTML.Doctype. '.
10
 
    'This directive has been available since 1.3.0.'
11
 
);
12
 
 
13
 
HTMLPurifier_ConfigSchema::define(
14
 
    'HTML', 'XHTML', true, 'bool',
15
 
    'Determines whether or not output is XHTML 1.0 or HTML 4.01 flavor. '.
16
 
    'This directive is deprecated in favor of %HTML.Doctype. '.
17
 
    'This directive was available since 1.1.'
18
 
);
19
 
HTMLPurifier_ConfigSchema::defineAlias('Core', 'XHTML', 'HTML', 'XHTML');
20
 
 
21
3
class HTMLPurifier_DoctypeRegistry
22
4
{
23
 
    
 
5
 
24
6
    /**
25
7
     * Hash of doctype names to doctype objects
26
 
     * @protected
27
8
     */
28
 
    var $doctypes;
29
 
    
 
9
    protected $doctypes;
 
10
 
30
11
    /**
31
12
     * Lookup table of aliases to real doctype names
32
 
     * @protected
33
13
     */
34
 
    var $aliases;
35
 
    
 
14
    protected $aliases;
 
15
 
36
16
    /**
37
17
     * Registers a doctype to the registry
38
18
     * @note Accepts a fully-formed doctype object, or the
41
21
     * @param $modules Modules doctype will load
42
22
     * @param $modules_for_modes Modules doctype will load for certain modes
43
23
     * @param $aliases Alias names for doctype
44
 
     * @return Reference to registered doctype (usable for further editing)
 
24
     * @return Editable registered doctype
45
25
     */
46
 
    function &register($doctype, $xml = true, $modules = array(),
 
26
    public function register($doctype, $xml = true, $modules = array(),
47
27
        $tidy_modules = array(), $aliases = array(), $dtd_public = null, $dtd_system = null
48
28
    ) {
49
29
        if (!is_array($modules)) $modules = array($modules);
54
34
                $doctype, $xml, $modules, $tidy_modules, $aliases, $dtd_public, $dtd_system
55
35
            );
56
36
        }
57
 
        $this->doctypes[$doctype->name] =& $doctype;
 
37
        $this->doctypes[$doctype->name] = $doctype;
58
38
        $name = $doctype->name;
59
39
        // hookup aliases
60
40
        foreach ($doctype->aliases as $alias) {
65
45
        if (isset($this->aliases[$name])) unset($this->aliases[$name]);
66
46
        return $doctype;
67
47
    }
68
 
    
 
48
 
69
49
    /**
70
50
     * Retrieves reference to a doctype of a certain name
71
51
     * @note This function resolves aliases
72
52
     * @note When possible, use the more fully-featured make()
73
53
     * @param $doctype Name of doctype
74
 
     * @return Reference to doctype object
 
54
     * @return Editable doctype object
75
55
     */
76
 
    function &get($doctype) {
 
56
    public function get($doctype) {
77
57
        if (isset($this->aliases[$doctype])) $doctype = $this->aliases[$doctype];
78
58
        if (!isset($this->doctypes[$doctype])) {
79
59
            trigger_error('Doctype ' . htmlspecialchars($doctype) . ' does not exist', E_USER_ERROR);
82
62
        }
83
63
        return $this->doctypes[$doctype];
84
64
    }
85
 
    
 
65
 
86
66
    /**
87
67
     * Creates a doctype based on a configuration object,
88
68
     * will perform initialization on the doctype
91
71
     *       Generator whether or not the current document is XML
92
72
     *       based or not).
93
73
     */
94
 
    function make($config) {
95
 
        $original_doctype = $this->get($this->getDoctypeFromConfig($config));
96
 
        $doctype = $original_doctype->copy();
97
 
        return $doctype;
 
74
    public function make($config) {
 
75
        return clone $this->get($this->getDoctypeFromConfig($config));
98
76
    }
99
 
    
 
77
 
100
78
    /**
101
79
     * Retrieves the doctype from the configuration object
102
80
     */
103
 
    function getDoctypeFromConfig($config) {
 
81
    public function getDoctypeFromConfig($config) {
104
82
        // recommended test
105
 
        $doctype = $config->get('HTML', 'Doctype');
 
83
        $doctype = $config->get('HTML.Doctype');
106
84
        if (!empty($doctype)) return $doctype;
107
 
        $doctype = $config->get('HTML', 'CustomDoctype');
 
85
        $doctype = $config->get('HTML.CustomDoctype');
108
86
        if (!empty($doctype)) return $doctype;
109
87
        // backwards-compatibility
110
 
        if ($config->get('HTML', 'XHTML')) {
 
88
        if ($config->get('HTML.XHTML')) {
111
89
            $doctype = 'XHTML 1.0';
112
90
        } else {
113
91
            $doctype = 'HTML 4.01';
114
92
        }
115
 
        if ($config->get('HTML', 'Strict')) {
 
93
        if ($config->get('HTML.Strict')) {
116
94
            $doctype .= ' Strict';
117
95
        } else {
118
96
            $doctype .= ' Transitional';
119
97
        }
120
98
        return $doctype;
121
99
    }
122
 
    
 
100
 
123
101
}
124
102
 
 
103
// vim: et sw=4 sts=4