XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
DoctypeRegistry.php
Go to the documentation of this file.
1 <?php
2 
4 {
5 
9  protected $doctypes;
10 
14  protected $aliases;
15 
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
35  );
36  }
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;
43  }
44  // remove old aliases
45  if (isset($this->aliases[$name])) unset($this->aliases[$name]);
46  return $doctype;
47  }
48 
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;
62  }
63  return $this->doctypes[$doctype];
64  }
65 
74  public function make($config) {
75  return clone $this->get($this->getDoctypeFromConfig($config));
76  }
77 
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';
92  }
93  if ($config->get('HTML.Strict')) {
94  $doctype .= ' Strict';
95  } else {
96  $doctype .= ' Transitional';
97  }
98  return $doctype;
99  }
100 
101 }
102 
103 // vim: et sw=4 sts=4