Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
   1  <?php
   2  
   3  /**

   4   * Validates the border property as defined by CSS.

   5   */
   6  class HTMLPurifier_AttrDef_CSS_Border extends HTMLPurifier_AttrDef
   7  {
   8  
   9      /**

  10       * Local copy of properties this property is shorthand for.

  11       * @type HTMLPurifier_AttrDef[]

  12       */
  13      protected $info = array();
  14  
  15      /**

  16       * @param HTMLPurifier_Config $config

  17       */
  18      public function __construct($config)
  19      {
  20          $def = $config->getCSSDefinition();
  21          $this->info['border-width'] = $def->info['border-width'];
  22          $this->info['border-style'] = $def->info['border-style'];
  23          $this->info['border-top-color'] = $def->info['border-top-color'];
  24      }
  25  
  26      /**

  27       * @param string $string

  28       * @param HTMLPurifier_Config $config

  29       * @param HTMLPurifier_Context $context

  30       * @return bool|string

  31       */
  32      public function validate($string, $config, $context)
  33      {
  34          $string = $this->parseCDATA($string);
  35          $string = $this->mungeRgb($string);
  36          $bits = explode(' ', $string);
  37          $done = array(); // segments we've finished

  38          $ret = ''; // return value

  39          foreach ($bits as $bit) {
  40              foreach ($this->info as $propname => $validator) {
  41                  if (isset($done[$propname])) {
  42                      continue;
  43                  }
  44                  $r = $validator->validate($bit, $config, $context);
  45                  if ($r !== false) {
  46                      $ret .= $r . ' ';
  47                      $done[$propname] = true;
  48                      break;
  49                  }
  50              }
  51          }
  52          return rtrim($ret);
  53      }
  54  }
  55  
  56  // vim: et sw=4 sts=4