HTMLPurifier 4.4.0
/home/ezyang/Dev/htmlpurifier/library/HTMLPurifier/AttrDef/CSS/Length.php
Go to the documentation of this file.
00001 <?php
00002 
00006 class HTMLPurifier_AttrDef_CSS_Length extends HTMLPurifier_AttrDef
00007 {
00008 
00009     protected $min, $max;
00010 
00015     public function __construct($min = null, $max = null) {
00016         $this->min = $min !== null ? HTMLPurifier_Length::make($min) : null;
00017         $this->max = $max !== null ? HTMLPurifier_Length::make($max) : null;
00018     }
00019 
00020     public function validate($string, $config, $context) {
00021         $string = $this->parseCDATA($string);
00022 
00023         // Optimizations
00024         if ($string === '') return false;
00025         if ($string === '0') return '0';
00026         if (strlen($string) === 1) return false;
00027 
00028         $length = HTMLPurifier_Length::make($string);
00029         if (!$length->isValid()) return false;
00030 
00031         if ($this->min) {
00032             $c = $length->compareTo($this->min);
00033             if ($c === false) return false;
00034             if ($c < 0) return false;
00035         }
00036         if ($this->max) {
00037             $c = $length->compareTo($this->max);
00038             if ($c === false) return false;
00039             if ($c > 0) return false;
00040         }
00041 
00042         return $length->toString();
00043     }
00044 
00045 }
00046 
00047 // vim: et sw=4 sts=4