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
25 * Hash of doctype names to doctype objects
31 * Lookup table of aliases to real doctype names
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 ®ister($doctype, $xml = true, $modules = array(),
47 $tidy_modules = array(), $aliases = array(), $dtd_public = null, $dtd_system = null
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
;
60 foreach ($doctype->aliases
as $alias) {
61 if (isset($this->doctypes
[$alias])) continue;
62 $this->aliases
[$alias] = $name;
65 if (isset($this->aliases
[$name])) unset($this->aliases
[$name]);
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);
83 return $this->doctypes
[$doctype];
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
94 function make($config) {
95 $original_doctype = $this->get($this->getDoctypeFromConfig($config));
96 $doctype = $original_doctype->copy();
101 * Retrieves the doctype from the configuration object
103 function getDoctypeFromConfig($config) {
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';
113 $doctype = 'HTML 4.01';
115 if ($config->get('HTML', 'Strict')) {
116 $doctype .= ' Strict';
118 $doctype .= ' Transitional';