Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   1  <?php
   2  
   3  /**

   4   * XHTML 1.1 Legacy module defines elements that were previously

   5   * deprecated.

   6   *

   7   * @note Not all legacy elements have been implemented yet, which

   8   *       is a bit of a reverse problem as compared to browsers! In

   9   *       addition, this legacy module may implement a bit more than

  10   *       mandated by XHTML 1.1.

  11   *

  12   * This module can be used in combination with TransformToStrict in order

  13   * to transform as many deprecated elements as possible, but retain

  14   * questionably deprecated elements that do not have good alternatives

  15   * as well as transform elements that don't have an implementation.

  16   * See docs/ref-strictness.txt for more details.

  17   */
  18  
  19  class HTMLPurifier_HTMLModule_Legacy extends HTMLPurifier_HTMLModule
  20  {
  21      /**

  22       * @type string

  23       */
  24      public $name = 'Legacy';
  25  
  26      /**

  27       * @param HTMLPurifier_Config $config

  28       */
  29      public function setup($config)
  30      {
  31          $this->addElement(
  32              'basefont',
  33              'Inline',
  34              'Empty',
  35              null,
  36              array(
  37                  'color' => 'Color',
  38                  'face' => 'Text', // extremely broad, we should
  39                  'size' => 'Text', // tighten it
  40                  'id' => 'ID'
  41              )
  42          );
  43          $this->addElement('center', 'Block', 'Flow', 'Common');
  44          $this->addElement(
  45              'dir',
  46              'Block',
  47              'Required: li',
  48              'Common',
  49              array(
  50                  'compact' => 'Bool#compact'
  51              )
  52          );
  53          $this->addElement(
  54              'font',
  55              'Inline',
  56              'Inline',
  57              array('Core', 'I18N'),
  58              array(
  59                  'color' => 'Color',
  60                  'face' => 'Text', // extremely broad, we should
  61                  'size' => 'Text', // tighten it
  62              )
  63          );
  64          $this->addElement(
  65              'menu',
  66              'Block',
  67              'Required: li',
  68              'Common',
  69              array(
  70                  'compact' => 'Bool#compact'
  71              )
  72          );
  73  
  74          $s = $this->addElement('s', 'Inline', 'Inline', 'Common');
  75          $s->formatting = true;
  76  
  77          $strike = $this->addElement('strike', 'Inline', 'Inline', 'Common');
  78          $strike->formatting = true;
  79  
  80          $u = $this->addElement('u', 'Inline', 'Inline', 'Common');
  81          $u->formatting = true;
  82  
  83          // setup modifications to old elements

  84  
  85          $align = 'Enum#left,right,center,justify';
  86  
  87          $address = $this->addBlankElement('address');
  88          $address->content_model = 'Inline | #PCDATA | p';
  89          $address->content_model_type = 'optional';
  90          $address->child = false;
  91  
  92          $blockquote = $this->addBlankElement('blockquote');
  93          $blockquote->content_model = 'Flow | #PCDATA';
  94          $blockquote->content_model_type = 'optional';
  95          $blockquote->child = false;
  96  
  97          $br = $this->addBlankElement('br');
  98          $br->attr['clear'] = 'Enum#left,all,right,none';
  99  
 100          $caption = $this->addBlankElement('caption');
 101          $caption->attr['align'] = 'Enum#top,bottom,left,right';
 102  
 103          $div = $this->addBlankElement('div');
 104          $div->attr['align'] = $align;
 105  
 106          $dl = $this->addBlankElement('dl');
 107          $dl->attr['compact'] = 'Bool#compact';
 108  
 109          for ($i = 1; $i <= 6; $i++) {
 110              $h = $this->addBlankElement("h$i");
 111              $h->attr['align'] = $align;
 112          }
 113  
 114          $hr = $this->addBlankElement('hr');
 115          $hr->attr['align'] = $align;
 116          $hr->attr['noshade'] = 'Bool#noshade';
 117          $hr->attr['size'] = 'Pixels';
 118          $hr->attr['width'] = 'Length';
 119  
 120          $img = $this->addBlankElement('img');
 121          $img->attr['align'] = 'IAlign';
 122          $img->attr['border'] = 'Pixels';
 123          $img->attr['hspace'] = 'Pixels';
 124          $img->attr['vspace'] = 'Pixels';
 125  
 126          // figure out this integer business

 127  
 128          $li = $this->addBlankElement('li');
 129          $li->attr['value'] = new HTMLPurifier_AttrDef_Integer();
 130          $li->attr['type'] = 'Enum#s:1,i,I,a,A,disc,square,circle';
 131  
 132          $ol = $this->addBlankElement('ol');
 133          $ol->attr['compact'] = 'Bool#compact';
 134          $ol->attr['start'] = new HTMLPurifier_AttrDef_Integer();
 135          $ol->attr['type'] = 'Enum#s:1,i,I,a,A';
 136  
 137          $p = $this->addBlankElement('p');
 138          $p->attr['align'] = $align;
 139  
 140          $pre = $this->addBlankElement('pre');
 141          $pre->attr['width'] = 'Number';
 142  
 143          // script omitted

 144  
 145          $table = $this->addBlankElement('table');
 146          $table->attr['align'] = 'Enum#left,center,right';
 147          $table->attr['bgcolor'] = 'Color';
 148  
 149          $tr = $this->addBlankElement('tr');
 150          $tr->attr['bgcolor'] = 'Color';
 151  
 152          $th = $this->addBlankElement('th');
 153          $th->attr['bgcolor'] = 'Color';
 154          $th->attr['height'] = 'Length';
 155          $th->attr['nowrap'] = 'Bool#nowrap';
 156          $th->attr['width'] = 'Length';
 157  
 158          $td = $this->addBlankElement('td');
 159          $td->attr['bgcolor'] = 'Color';
 160          $td->attr['height'] = 'Length';
 161          $td->attr['nowrap'] = 'Bool#nowrap';
 162          $td->attr['width'] = 'Length';
 163  
 164          $ul = $this->addBlankElement('ul');
 165          $ul->attr['compact'] = 'Bool#compact';
 166          $ul->attr['type'] = 'Enum#square,disc,circle';
 167  
 168          // "safe" modifications to "unsafe" elements

 169          // WARNING: If you want to add support for an unsafe, legacy

 170          // attribute, make a new TrustedLegacy module with the trusted

 171          // bit set appropriately

 172  
 173          $form = $this->addBlankElement('form');
 174          $form->content_model = 'Flow | #PCDATA';
 175          $form->content_model_type = 'optional';
 176          $form->attr['target'] = 'FrameTarget';
 177  
 178          $input = $this->addBlankElement('input');
 179          $input->attr['align'] = 'IAlign';
 180  
 181          $legend = $this->addBlankElement('legend');
 182          $legend->attr['align'] = 'LAlign';
 183      }
 184  }
 185  
 186  // vim: et sw=4 sts=4