/plugins/vjCommentPlugin/lib/tools/htmlpurifier/library/HTMLPurifier/DoctypeRegistry.php

https://bitbucket.org/Kudlaty/360kdw · PHP · 103 lines · 55 code · 9 blank · 39 comment · 14 complexity · 0ab0a6b2a7d358ab8532d897e8bfe729 MD5 · raw file

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