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   * Performs miscellaneous cross attribute validation and filtering for

   5   * input elements. This is meant to be a post-transform.

   6   */
   7  class HTMLPurifier_AttrTransform_Input extends HTMLPurifier_AttrTransform
   8  {
   9      /**

  10       * @type HTMLPurifier_AttrDef_HTML_Pixels

  11       */
  12      protected $pixels;
  13  
  14      public function __construct()
  15      {
  16          $this->pixels = new HTMLPurifier_AttrDef_HTML_Pixels();
  17      }
  18  
  19      /**

  20       * @param array $attr

  21       * @param HTMLPurifier_Config $config

  22       * @param HTMLPurifier_Context $context

  23       * @return array

  24       */
  25      public function transform($attr, $config, $context)
  26      {
  27          if (!isset($attr['type'])) {
  28              $t = 'text';
  29          } else {
  30              $t = strtolower($attr['type']);
  31          }
  32          if (isset($attr['checked']) && $t !== 'radio' && $t !== 'checkbox') {
  33              unset($attr['checked']);
  34          }
  35          if (isset($attr['maxlength']) && $t !== 'text' && $t !== 'password') {
  36              unset($attr['maxlength']);
  37          }
  38          if (isset($attr['size']) && $t !== 'text' && $t !== 'password') {
  39              $result = $this->pixels->validate($attr['size'], $config, $context);
  40              if ($result === false) {
  41                  unset($attr['size']);
  42              } else {
  43                  $attr['size'] = $result;
  44              }
  45          }
  46          if (isset($attr['src']) && $t !== 'image') {
  47              unset($attr['src']);
  48          }
  49          if (!isset($attr['value']) && ($t === 'radio' || $t === 'checkbox')) {
  50              $attr['value'] = '';
  51          }
  52          return $attr;
  53      }
  54  }
  55  
  56  // vim: et sw=4 sts=4