Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   1  <?php
   2  
   3  /**

   4   * Post-transform that performs validation to the name attribute; if

   5   * it is present with an equivalent id attribute, it is passed through;

   6   * otherwise validation is performed.

   7   */
   8  class HTMLPurifier_AttrTransform_NameSync extends HTMLPurifier_AttrTransform
   9  {
  10  
  11      public function __construct()
  12      {
  13          $this->idDef = new HTMLPurifier_AttrDef_HTML_ID();
  14      }
  15  
  16      /**

  17       * @param array $attr

  18       * @param HTMLPurifier_Config $config

  19       * @param HTMLPurifier_Context $context

  20       * @return array

  21       */
  22      public function transform($attr, $config, $context)
  23      {
  24          if (!isset($attr['name'])) {
  25              return $attr;
  26          }
  27          $name = $attr['name'];
  28          if (isset($attr['id']) && $attr['id'] === $name) {
  29              return $attr;
  30          }
  31          $result = $this->idDef->validate($name, $config, $context);
  32          if ($result === false) {
  33              unset($attr['name']);
  34          } else {
  35              $attr['name'] = $result;
  36          }
  37          return $attr;
  38      }
  39  }
  40  
  41  // vim: et sw=4 sts=4