Inheritance: extends HTMLPurifier_AttrDef
Example #1
0
 /**
  * Validates the number and unit.
  */
 function validate()
 {
     // Special case:
     static $allowedUnits = array('em' => true, 'ex' => true, 'px' => true, 'in' => true, 'cm' => true, 'mm' => true, 'pt' => true, 'pc' => true);
     if ($this->n === '+0' || $this->n === '-0') {
         $this->n = '0';
     }
     if ($this->n === '0' && $this->unit === false) {
         return true;
     }
     if (!ctype_lower($this->unit)) {
         $this->unit = strtolower($this->unit);
     }
     if (!isset($allowedUnits[$this->unit])) {
         return false;
     }
     // Hack:
     $def = new HTMLPurifier_AttrDef_CSS_Number();
     $a = false;
     // hack hack
     $result = $def->validate($this->n, $a, $a);
     if ($result === false) {
         return false;
     }
     $this->n = $result;
     return true;
 }
Example #2
0
 public function validate($number, $config, $context)
 {
     $result = parent::validate($number, $config, $context);
     if ($result === false) {
         return $result;
     }
     $float = (double) $result;
     if ($float < 0.0) {
         $result = '0';
     }
     if ($float > 1.0) {
         $result = '1';
     }
     return $result;
 }
Example #3
0
 /**
  * Validates the number and unit.
  */
 protected function validate()
 {
     // Special case:
     if ($this->n === '+0' || $this->n === '-0') {
         $this->n = '0';
     }
     if ($this->n === '0' && $this->unit === false) {
         return true;
     }
     if (!ctype_lower($this->unit)) {
         $this->unit = strtolower($this->unit);
     }
     if (!isset(HTMLPurifier_Length::$allowedUnits[$this->unit])) {
         return false;
     }
     // Hack:
     $def = new HTMLPurifier_AttrDef_CSS_Number();
     $result = $def->validate($this->n, false, false);
     if ($result === false) {
         return false;
     }
     $this->n = $result;
     return true;
 }