Legacy.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * XHTML 1.1 Legacy module defines elements that were previously
  4. * deprecated.
  5. *
  6. * @note Not all legacy elements have been implemented yet, which
  7. * is a bit of a reverse problem as compared to browsers! In
  8. * addition, this legacy module may implement a bit more than
  9. * mandated by XHTML 1.1.
  10. *
  11. * This module can be used in combination with TransformToStrict in order
  12. * to transform as many deprecated elements as possible, but retain
  13. * questionably deprecated elements that do not have good alternatives
  14. * as well as transform elements that don't have an implementation.
  15. * See docs/ref-strictness.txt for more details.
  16. */
  17. class HTMLPurifier_HTMLModule_Legacy extends HTMLPurifier_HTMLModule
  18. {
  19. public $name = 'Legacy';
  20. public function setup($config) {
  21. $this->addElement('basefont', 'Inline', 'Empty', false, array(
  22. 'color' => 'Color',
  23. 'face' => 'Text', // extremely broad, we should
  24. 'size' => 'Text', // tighten it
  25. 'id' => 'ID'
  26. ));
  27. $this->addElement('center', 'Block', 'Flow', 'Common');
  28. $this->addElement('dir', 'Block', 'Required: li', 'Common', array(
  29. 'compact' => 'Bool#compact'
  30. ));
  31. $this->addElement('font', 'Inline', 'Inline', array('Core', 'I18N'), array(
  32. 'color' => 'Color',
  33. 'face' => 'Text', // extremely broad, we should
  34. 'size' => 'Text', // tighten it
  35. ));
  36. $this->addElement('menu', 'Block', 'Required: li', 'Common', array(
  37. 'compact' => 'Bool#compact'
  38. ));
  39. $s = $this->addElement('s', 'Inline', 'Inline', 'Common');
  40. $s->formatting = true;
  41. $strike = $this->addElement('strike', 'Inline', 'Inline', 'Common');
  42. $strike->formatting = true;
  43. $u = $this->addElement('u', 'Inline', 'Inline', 'Common');
  44. $u->formatting = true;
  45. // setup modifications to old elements
  46. $align = 'Enum#left,right,center,justify';
  47. $address = $this->addBlankElement('address');
  48. $address->content_model = 'Inline | #PCDATA | p';
  49. $address->content_model_type = 'optional';
  50. $address->child = false;
  51. $blockquote = $this->addBlankElement('blockquote');
  52. $blockquote->content_model = 'Flow | #PCDATA';
  53. $blockquote->content_model_type = 'optional';
  54. $blockquote->child = false;
  55. $br = $this->addBlankElement('br');
  56. $br->attr['clear'] = 'Enum#left,all,right,none';
  57. $caption = $this->addBlankElement('caption');
  58. $caption->attr['align'] = 'Enum#top,bottom,left,right';
  59. $div = $this->addBlankElement('div');
  60. $div->attr['align'] = $align;
  61. $dl = $this->addBlankElement('dl');
  62. $dl->attr['compact'] = 'Bool#compact';
  63. for ($i = 1; $i <= 6; $i++) {
  64. $h = $this->addBlankElement("h$i");
  65. $h->attr['align'] = $align;
  66. }
  67. $hr = $this->addBlankElement('hr');
  68. $hr->attr['align'] = $align;
  69. $hr->attr['noshade'] = 'Bool#noshade';
  70. $hr->attr['size'] = 'Pixels';
  71. $hr->attr['width'] = 'Length';
  72. $img = $this->addBlankElement('img');
  73. $img->attr['align'] = 'IAlign';
  74. $img->attr['border'] = 'Pixels';
  75. $img->attr['hspace'] = 'Pixels';
  76. $img->attr['vspace'] = 'Pixels';
  77. // figure out this integer business
  78. $li = $this->addBlankElement('li');
  79. $li->attr['value'] = new HTMLPurifier_AttrDef_Integer();
  80. $li->attr['type'] = 'Enum#s:1,i,I,a,A,disc,square,circle';
  81. $ol = $this->addBlankElement('ol');
  82. $ol->attr['compact'] = 'Bool#compact';
  83. $ol->attr['start'] = new HTMLPurifier_AttrDef_Integer();
  84. $ol->attr['type'] = 'Enum#s:1,i,I,a,A';
  85. $p = $this->addBlankElement('p');
  86. $p->attr['align'] = $align;
  87. $pre = $this->addBlankElement('pre');
  88. $pre->attr['width'] = 'Number';
  89. // script omitted
  90. $table = $this->addBlankElement('table');
  91. $table->attr['align'] = 'Enum#left,center,right';
  92. $table->attr['bgcolor'] = 'Color';
  93. $tr = $this->addBlankElement('tr');
  94. $tr->attr['bgcolor'] = 'Color';
  95. $th = $this->addBlankElement('th');
  96. $th->attr['bgcolor'] = 'Color';
  97. $th->attr['height'] = 'Length';
  98. $th->attr['nowrap'] = 'Bool#nowrap';
  99. $th->attr['width'] = 'Length';
  100. $td = $this->addBlankElement('td');
  101. $td->attr['bgcolor'] = 'Color';
  102. $td->attr['height'] = 'Length';
  103. $td->attr['nowrap'] = 'Bool#nowrap';
  104. $td->attr['width'] = 'Length';
  105. $ul = $this->addBlankElement('ul');
  106. $ul->attr['compact'] = 'Bool#compact';
  107. $ul->attr['type'] = 'Enum#square,disc,circle';
  108. // "safe" modifications to "unsafe" elements
  109. // WARNING: If you want to add support for an unsafe, legacy
  110. // attribute, make a new TrustedLegacy module with the trusted
  111. // bit set appropriately
  112. $form = $this->addBlankElement('form');
  113. $form->content_model = 'Flow | #PCDATA';
  114. $form->content_model_type = 'optional';
  115. $form->attr['target'] = 'FrameTarget';
  116. $input = $this->addBlankElement('input');
  117. $input->attr['align'] = 'IAlign';
  118. $legend = $this->addBlankElement('legend');
  119. $legend->attr['align'] = 'LAlign';
  120. }
  121. }
  122. // vim: et sw=4 sts=4