PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/htmlpurifier/HTMLPurifier/HTMLModule/Legacy.php

http://github.com/moodle/moodle
PHP | 186 lines | 124 code | 33 blank | 29 comment | 1 complexity | 55503531e199bef03fed75be8c503c7d MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  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. /**
  20. * @type string
  21. */
  22. public $name = 'Legacy';
  23. /**
  24. * @param HTMLPurifier_Config $config
  25. */
  26. public function setup($config)
  27. {
  28. $this->addElement(
  29. 'basefont',
  30. 'Inline',
  31. 'Empty',
  32. null,
  33. array(
  34. 'color' => 'Color',
  35. 'face' => 'Text', // extremely broad, we should
  36. 'size' => 'Text', // tighten it
  37. 'id' => 'ID'
  38. )
  39. );
  40. $this->addElement('center', 'Block', 'Flow', 'Common');
  41. $this->addElement(
  42. 'dir',
  43. 'Block',
  44. 'Required: li',
  45. 'Common',
  46. array(
  47. 'compact' => 'Bool#compact'
  48. )
  49. );
  50. $this->addElement(
  51. 'font',
  52. 'Inline',
  53. 'Inline',
  54. array('Core', 'I18N'),
  55. array(
  56. 'color' => 'Color',
  57. 'face' => 'Text', // extremely broad, we should
  58. 'size' => 'Text', // tighten it
  59. )
  60. );
  61. $this->addElement(
  62. 'menu',
  63. 'Block',
  64. 'Required: li',
  65. 'Common',
  66. array(
  67. 'compact' => 'Bool#compact'
  68. )
  69. );
  70. $s = $this->addElement('s', 'Inline', 'Inline', 'Common');
  71. $s->formatting = true;
  72. $strike = $this->addElement('strike', 'Inline', 'Inline', 'Common');
  73. $strike->formatting = true;
  74. $u = $this->addElement('u', 'Inline', 'Inline', 'Common');
  75. $u->formatting = true;
  76. // setup modifications to old elements
  77. $align = 'Enum#left,right,center,justify';
  78. $address = $this->addBlankElement('address');
  79. $address->content_model = 'Inline | #PCDATA | p';
  80. $address->content_model_type = 'optional';
  81. $address->child = false;
  82. $blockquote = $this->addBlankElement('blockquote');
  83. $blockquote->content_model = 'Flow | #PCDATA';
  84. $blockquote->content_model_type = 'optional';
  85. $blockquote->child = false;
  86. $br = $this->addBlankElement('br');
  87. $br->attr['clear'] = 'Enum#left,all,right,none';
  88. $caption = $this->addBlankElement('caption');
  89. $caption->attr['align'] = 'Enum#top,bottom,left,right';
  90. $div = $this->addBlankElement('div');
  91. $div->attr['align'] = $align;
  92. $dl = $this->addBlankElement('dl');
  93. $dl->attr['compact'] = 'Bool#compact';
  94. for ($i = 1; $i <= 6; $i++) {
  95. $h = $this->addBlankElement("h$i");
  96. $h->attr['align'] = $align;
  97. }
  98. $hr = $this->addBlankElement('hr');
  99. $hr->attr['align'] = $align;
  100. $hr->attr['noshade'] = 'Bool#noshade';
  101. $hr->attr['size'] = 'Pixels';
  102. $hr->attr['width'] = 'Length';
  103. $img = $this->addBlankElement('img');
  104. $img->attr['align'] = 'IAlign';
  105. $img->attr['border'] = 'Pixels';
  106. $img->attr['hspace'] = 'Pixels';
  107. $img->attr['vspace'] = 'Pixels';
  108. // figure out this integer business
  109. $li = $this->addBlankElement('li');
  110. $li->attr['value'] = new HTMLPurifier_AttrDef_Integer();
  111. $li->attr['type'] = 'Enum#s:1,i,I,a,A,disc,square,circle';
  112. $ol = $this->addBlankElement('ol');
  113. $ol->attr['compact'] = 'Bool#compact';
  114. $ol->attr['start'] = new HTMLPurifier_AttrDef_Integer();
  115. $ol->attr['type'] = 'Enum#s:1,i,I,a,A';
  116. $p = $this->addBlankElement('p');
  117. $p->attr['align'] = $align;
  118. $pre = $this->addBlankElement('pre');
  119. $pre->attr['width'] = 'Number';
  120. // script omitted
  121. $table = $this->addBlankElement('table');
  122. $table->attr['align'] = 'Enum#left,center,right';
  123. $table->attr['bgcolor'] = 'Color';
  124. $tr = $this->addBlankElement('tr');
  125. $tr->attr['bgcolor'] = 'Color';
  126. $th = $this->addBlankElement('th');
  127. $th->attr['bgcolor'] = 'Color';
  128. $th->attr['height'] = 'Length';
  129. $th->attr['nowrap'] = 'Bool#nowrap';
  130. $th->attr['width'] = 'Length';
  131. $td = $this->addBlankElement('td');
  132. $td->attr['bgcolor'] = 'Color';
  133. $td->attr['height'] = 'Length';
  134. $td->attr['nowrap'] = 'Bool#nowrap';
  135. $td->attr['width'] = 'Length';
  136. $ul = $this->addBlankElement('ul');
  137. $ul->attr['compact'] = 'Bool#compact';
  138. $ul->attr['type'] = 'Enum#square,disc,circle';
  139. // "safe" modifications to "unsafe" elements
  140. // WARNING: If you want to add support for an unsafe, legacy
  141. // attribute, make a new TrustedLegacy module with the trusted
  142. // bit set appropriately
  143. $form = $this->addBlankElement('form');
  144. $form->content_model = 'Flow | #PCDATA';
  145. $form->content_model_type = 'optional';
  146. $form->attr['target'] = 'FrameTarget';
  147. $input = $this->addBlankElement('input');
  148. $input->attr['align'] = 'IAlign';
  149. $legend = $this->addBlankElement('legend');
  150. $legend->attr['align'] = 'LAlign';
  151. }
  152. }
  153. // vim: et sw=4 sts=4