HTMLPurifier 4.4.0
/home/ezyang/Dev/htmlpurifier/library/HTMLPurifier/AttrDef/HTML/Length.php
Go to the documentation of this file.
00001 <?php
00002 
00010 class HTMLPurifier_AttrDef_HTML_Length extends HTMLPurifier_AttrDef_HTML_Pixels
00011 {
00012 
00013     public function validate($string, $config, $context) {
00014 
00015         $string = trim($string);
00016         if ($string === '') return false;
00017 
00018         $parent_result = parent::validate($string, $config, $context);
00019         if ($parent_result !== false) return $parent_result;
00020 
00021         $length = strlen($string);
00022         $last_char = $string[$length - 1];
00023 
00024         if ($last_char !== '%') return false;
00025 
00026         $points = substr($string, 0, $length - 1);
00027 
00028         if (!is_numeric($points)) return false;
00029 
00030         $points = (int) $points;
00031 
00032         if ($points < 0) return '0%';
00033         if ($points > 100) return '100%';
00034 
00035         return ((string) $points) . '%';
00036 
00037     }
00038 
00039 }
00040 
00041 // vim: et sw=4 sts=4