1: | <?php
|
2: |
|
3: | class HTMLPurifier_DoctypeRegistry
|
4: | {
|
5: |
|
6: | |
7: | |
8: | |
9: |
|
10: | protected $doctypes;
|
11: |
|
12: | |
13: | |
14: | |
15: |
|
16: | protected $aliases;
|
17: |
|
18: | |
19: | |
20: | |
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | |
30: |
|
31: | public function register(
|
32: | $doctype,
|
33: | $xml = true,
|
34: | $modules = array(),
|
35: | $tidy_modules = array(),
|
36: | $aliases = array(),
|
37: | $dtd_public = null,
|
38: | $dtd_system = null
|
39: | ) {
|
40: | if (!is_array($modules)) {
|
41: | $modules = array($modules);
|
42: | }
|
43: | if (!is_array($tidy_modules)) {
|
44: | $tidy_modules = array($tidy_modules);
|
45: | }
|
46: | if (!is_array($aliases)) {
|
47: | $aliases = array($aliases);
|
48: | }
|
49: | if (!is_object($doctype)) {
|
50: | $doctype = new HTMLPurifier_Doctype(
|
51: | $doctype,
|
52: | $xml,
|
53: | $modules,
|
54: | $tidy_modules,
|
55: | $aliases,
|
56: | $dtd_public,
|
57: | $dtd_system
|
58: | );
|
59: | }
|
60: | $this->doctypes[$doctype->name] = $doctype;
|
61: | $name = $doctype->name;
|
62: |
|
63: | foreach ($doctype->aliases as $alias) {
|
64: | if (isset($this->doctypes[$alias])) {
|
65: | continue;
|
66: | }
|
67: | $this->aliases[$alias] = $name;
|
68: | }
|
69: |
|
70: | if (isset($this->aliases[$name])) {
|
71: | unset($this->aliases[$name]);
|
72: | }
|
73: | return $doctype;
|
74: | }
|
75: |
|
76: | |
77: | |
78: | |
79: | |
80: | |
81: | |
82: |
|
83: | public function get($doctype)
|
84: | {
|
85: | if (isset($this->aliases[$doctype])) {
|
86: | $doctype = $this->aliases[$doctype];
|
87: | }
|
88: | if (!isset($this->doctypes[$doctype])) {
|
89: | trigger_error('Doctype ' . htmlspecialchars($doctype) . ' does not exist', E_USER_ERROR);
|
90: | $anon = new HTMLPurifier_Doctype($doctype);
|
91: | return $anon;
|
92: | }
|
93: | return $this->doctypes[$doctype];
|
94: | }
|
95: |
|
96: | |
97: | |
98: | |
99: | |
100: | |
101: | |
102: | |
103: | |
104: | |
105: |
|
106: | public function make($config)
|
107: | {
|
108: | return clone $this->get($this->getDoctypeFromConfig($config));
|
109: | }
|
110: |
|
111: | |
112: | |
113: | |
114: | |
115: |
|
116: | public function getDoctypeFromConfig($config)
|
117: | {
|
118: |
|
119: | $doctype = $config->get('HTML.Doctype');
|
120: | if (!empty($doctype)) {
|
121: | return $doctype;
|
122: | }
|
123: | $doctype = $config->get('HTML.CustomDoctype');
|
124: | if (!empty($doctype)) {
|
125: | return $doctype;
|
126: | }
|
127: |
|
128: | if ($config->get('HTML.XHTML')) {
|
129: | $doctype = 'XHTML 1.0';
|
130: | } else {
|
131: | $doctype = 'HTML 4.01';
|
132: | }
|
133: | if ($config->get('HTML.Strict')) {
|
134: | $doctype .= ' Strict';
|
135: | } else {
|
136: | $doctype .= ' Transitional';
|
137: | }
|
138: | return $doctype;
|
139: | }
|
140: | }
|
141: |
|
142: |
|
143: | |