Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 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      /**
  12       * @type HTMLPurifier_AttrDef_HTML_ID
  13       */
  14      public $idDef;
  15  
  16      public function __construct()
  17      {
  18          $this->idDef = new HTMLPurifier_AttrDef_HTML_ID();
  19      }
  20  
  21      /**
  22       * @param array $attr
  23       * @param HTMLPurifier_Config $config
  24       * @param HTMLPurifier_Context $context
  25       * @return array
  26       */
  27      public function transform($attr, $config, $context)
  28      {
  29          if (!isset($attr['name'])) {
  30              return $attr;
  31          }
  32          $name = $attr['name'];
  33          if (isset($attr['id']) && $attr['id'] === $name) {
  34              return $attr;
  35          }
  36          $result = $this->idDef->validate($name, $config, $context);
  37          if ($result === false) {
  38              unset($attr['name']);
  39          } else {
  40              $attr['name'] = $result;
  41          }
  42          return $attr;
  43      }
  44  }
  45  
  46  // vim: et sw=4 sts=4