PageRenderTime 53ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/moodle/lib/htmlpurifier/HTMLPurifier/AttrTypes.php

https://bitbucket.org/geek745/moodle-db2
PHP | 85 lines | 45 code | 14 blank | 26 comment | 3 complexity | 0ec3db8e2e4c489fbd3e4000cc617d4e MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause, LGPL-2.0
  1. <?php
  2. require_once 'HTMLPurifier/AttrDef/Lang.php';
  3. require_once 'HTMLPurifier/AttrDef/Enum.php';
  4. require_once 'HTMLPurifier/AttrDef/HTML/Bool.php';
  5. require_once 'HTMLPurifier/AttrDef/HTML/ID.php';
  6. require_once 'HTMLPurifier/AttrDef/HTML/Length.php';
  7. require_once 'HTMLPurifier/AttrDef/HTML/MultiLength.php';
  8. require_once 'HTMLPurifier/AttrDef/HTML/Nmtokens.php';
  9. require_once 'HTMLPurifier/AttrDef/HTML/Pixels.php';
  10. require_once 'HTMLPurifier/AttrDef/HTML/Color.php';
  11. require_once 'HTMLPurifier/AttrDef/Integer.php';
  12. require_once 'HTMLPurifier/AttrDef/Text.php';
  13. require_once 'HTMLPurifier/AttrDef/URI.php';
  14. /**
  15. * Provides lookup array of attribute types to HTMLPurifier_AttrDef objects
  16. */
  17. class HTMLPurifier_AttrTypes
  18. {
  19. /**
  20. * Lookup array of attribute string identifiers to concrete implementations
  21. * @protected
  22. */
  23. var $info = array();
  24. /**
  25. * Constructs the info array, supplying default implementations for attribute
  26. * types.
  27. */
  28. function HTMLPurifier_AttrTypes() {
  29. // pseudo-types, must be instantiated via shorthand
  30. $this->info['Enum'] = new HTMLPurifier_AttrDef_Enum();
  31. $this->info['Bool'] = new HTMLPurifier_AttrDef_HTML_Bool();
  32. $this->info['CDATA'] = new HTMLPurifier_AttrDef_Text();
  33. $this->info['ID'] = new HTMLPurifier_AttrDef_HTML_ID();
  34. $this->info['Length'] = new HTMLPurifier_AttrDef_HTML_Length();
  35. $this->info['MultiLength'] = new HTMLPurifier_AttrDef_HTML_MultiLength();
  36. $this->info['NMTOKENS'] = new HTMLPurifier_AttrDef_HTML_Nmtokens();
  37. $this->info['Pixels'] = new HTMLPurifier_AttrDef_HTML_Pixels();
  38. $this->info['Text'] = new HTMLPurifier_AttrDef_Text();
  39. $this->info['URI'] = new HTMLPurifier_AttrDef_URI();
  40. $this->info['LanguageCode'] = new HTMLPurifier_AttrDef_Lang();
  41. $this->info['Color'] = new HTMLPurifier_AttrDef_HTML_Color();
  42. // unimplemented aliases
  43. $this->info['ContentType'] = new HTMLPurifier_AttrDef_Text();
  44. // number is really a positive integer (one or more digits)
  45. // FIXME: ^^ not always, see start and value of list items
  46. $this->info['Number'] = new HTMLPurifier_AttrDef_Integer(false, false, true);
  47. }
  48. /**
  49. * Retrieves a type
  50. * @param $type String type name
  51. * @return Object AttrDef for type
  52. */
  53. function get($type) {
  54. // determine if there is any extra info tacked on
  55. if (strpos($type, '#') !== false) list($type, $string) = explode('#', $type, 2);
  56. else $string = '';
  57. if (!isset($this->info[$type])) {
  58. trigger_error('Cannot retrieve undefined attribute type ' . $type, E_USER_ERROR);
  59. return;
  60. }
  61. return $this->info[$type]->make($string);
  62. }
  63. /**
  64. * Sets a new implementation for a type
  65. * @param $type String type name
  66. * @param $impl Object AttrDef for type
  67. */
  68. function set($type, $impl) {
  69. $this->info[$type] = $impl;
  70. }
  71. }