Fix two minor bugs, updating Phorum and removing unused $dir variable.
[htmlpurifier/darkodev.git] / library / HTMLPurifier / DoctypeRegistry.php
blob86049e9391bf5ce11ae708034b1b1ad0bd1d03cd
1 <?php
3 class HTMLPurifier_DoctypeRegistry
6 /**
7 * Hash of doctype names to doctype objects
8 */
9 protected $doctypes;
11 /**
12 * Lookup table of aliases to real doctype names
14 protected $aliases;
16 /**
17 * Registers a doctype to the registry
18 * @note Accepts a fully-formed doctype object, or the
19 * parameters for constructing a doctype object
20 * @param $doctype Name of doctype or literal doctype object
21 * @param $modules Modules doctype will load
22 * @param $modules_for_modes Modules doctype will load for certain modes
23 * @param $aliases Alias names for doctype
24 * @return Editable registered doctype
26 public function register($doctype, $xml = true, $modules = array(),
27 $tidy_modules = array(), $aliases = array(), $dtd_public = null, $dtd_system = null
28 ) {
29 if (!is_array($modules)) $modules = array($modules);
30 if (!is_array($tidy_modules)) $tidy_modules = array($tidy_modules);
31 if (!is_array($aliases)) $aliases = array($aliases);
32 if (!is_object($doctype)) {
33 $doctype = new HTMLPurifier_Doctype(
34 $doctype, $xml, $modules, $tidy_modules, $aliases, $dtd_public, $dtd_system
37 $this->doctypes[$doctype->name] = $doctype;
38 $name = $doctype->name;
39 // hookup aliases
40 foreach ($doctype->aliases as $alias) {
41 if (isset($this->doctypes[$alias])) continue;
42 $this->aliases[$alias] = $name;
44 // remove old aliases
45 if (isset($this->aliases[$name])) unset($this->aliases[$name]);
46 return $doctype;
49 /**
50 * Retrieves reference to a doctype of a certain name
51 * @note This function resolves aliases
52 * @note When possible, use the more fully-featured make()
53 * @param $doctype Name of doctype
54 * @return Editable doctype object
56 public function get($doctype) {
57 if (isset($this->aliases[$doctype])) $doctype = $this->aliases[$doctype];
58 if (!isset($this->doctypes[$doctype])) {
59 trigger_error('Doctype ' . htmlspecialchars($doctype) . ' does not exist', E_USER_ERROR);
60 $anon = new HTMLPurifier_Doctype($doctype);
61 return $anon;
63 return $this->doctypes[$doctype];
66 /**
67 * Creates a doctype based on a configuration object,
68 * will perform initialization on the doctype
69 * @note Use this function to get a copy of doctype that config
70 * can hold on to (this is necessary in order to tell
71 * Generator whether or not the current document is XML
72 * based or not).
74 public function make($config) {
75 return clone $this->get($this->getDoctypeFromConfig($config));
78 /**
79 * Retrieves the doctype from the configuration object
81 public function getDoctypeFromConfig($config) {
82 // recommended test
83 $doctype = $config->get('HTML.Doctype');
84 if (!empty($doctype)) return $doctype;
85 $doctype = $config->get('HTML.CustomDoctype');
86 if (!empty($doctype)) return $doctype;
87 // backwards-compatibility
88 if ($config->get('HTML.XHTML')) {
89 $doctype = 'XHTML 1.0';
90 } else {
91 $doctype = 'HTML 4.01';
93 if ($config->get('HTML.Strict')) {
94 $doctype .= ' Strict';
95 } else {
96 $doctype .= ' Transitional';
98 return $doctype;
103 // vim: et sw=4 sts=4