"MDL-12304, fix double text"
[moodle-linuxchix.git] / lib / htmlpurifier / HTMLPurifier / DoctypeRegistry.php
blobe657b3da4b174038ed2361f7d816b58202c63d31
1 <?php
3 require_once 'HTMLPurifier/Doctype.php';
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.'
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.'
19 HTMLPurifier_ConfigSchema::defineAlias('Core', 'XHTML', 'HTML', 'XHTML');
21 class HTMLPurifier_DoctypeRegistry
24 /**
25 * Hash of doctype names to doctype objects
26 * @protected
28 var $doctypes;
30 /**
31 * Lookup table of aliases to real doctype names
32 * @protected
34 var $aliases;
36 /**
37 * Registers a doctype to the registry
38 * @note Accepts a fully-formed doctype object, or the
39 * parameters for constructing a doctype object
40 * @param $doctype Name of doctype or literal doctype object
41 * @param $modules Modules doctype will load
42 * @param $modules_for_modes Modules doctype will load for certain modes
43 * @param $aliases Alias names for doctype
44 * @return Reference to registered doctype (usable for further editing)
46 function &register($doctype, $xml = true, $modules = array(),
47 $tidy_modules = array(), $aliases = array(), $dtd_public = null, $dtd_system = null
48 ) {
49 if (!is_array($modules)) $modules = array($modules);
50 if (!is_array($tidy_modules)) $tidy_modules = array($tidy_modules);
51 if (!is_array($aliases)) $aliases = array($aliases);
52 if (!is_object($doctype)) {
53 $doctype = new HTMLPurifier_Doctype(
54 $doctype, $xml, $modules, $tidy_modules, $aliases, $dtd_public, $dtd_system
57 $this->doctypes[$doctype->name] =& $doctype;
58 $name = $doctype->name;
59 // hookup aliases
60 foreach ($doctype->aliases as $alias) {
61 if (isset($this->doctypes[$alias])) continue;
62 $this->aliases[$alias] = $name;
64 // remove old aliases
65 if (isset($this->aliases[$name])) unset($this->aliases[$name]);
66 return $doctype;
69 /**
70 * Retrieves reference to a doctype of a certain name
71 * @note This function resolves aliases
72 * @note When possible, use the more fully-featured make()
73 * @param $doctype Name of doctype
74 * @return Reference to doctype object
76 function &get($doctype) {
77 if (isset($this->aliases[$doctype])) $doctype = $this->aliases[$doctype];
78 if (!isset($this->doctypes[$doctype])) {
79 trigger_error('Doctype ' . htmlspecialchars($doctype) . ' does not exist', E_USER_ERROR);
80 $anon = new HTMLPurifier_Doctype($doctype);
81 return $anon;
83 return $this->doctypes[$doctype];
86 /**
87 * Creates a doctype based on a configuration object,
88 * will perform initialization on the doctype
89 * @note Use this function to get a copy of doctype that config
90 * can hold on to (this is necessary in order to tell
91 * Generator whether or not the current document is XML
92 * based or not).
94 function make($config) {
95 $original_doctype = $this->get($this->getDoctypeFromConfig($config));
96 $doctype = $original_doctype->copy();
97 return $doctype;
101 * Retrieves the doctype from the configuration object
103 function getDoctypeFromConfig($config) {
104 // recommended test
105 $doctype = $config->get('HTML', 'Doctype');
106 if (!empty($doctype)) return $doctype;
107 $doctype = $config->get('HTML', 'CustomDoctype');
108 if (!empty($doctype)) return $doctype;
109 // backwards-compatibility
110 if ($config->get('HTML', 'XHTML')) {
111 $doctype = 'XHTML 1.0';
112 } else {
113 $doctype = 'HTML 4.01';
115 if ($config->get('HTML', 'Strict')) {
116 $doctype .= ' Strict';
117 } else {
118 $doctype .= ' Transitional';
120 return $doctype;