HTMLPurifier 4.4.0
|
00001 <?php 00002 00006 class HTMLPurifier_AttrDef_CSS_Percentage extends HTMLPurifier_AttrDef 00007 { 00008 00012 protected $number_def; 00013 00017 public function __construct($non_negative = false) { 00018 $this->number_def = new HTMLPurifier_AttrDef_CSS_Number($non_negative); 00019 } 00020 00021 public function validate($string, $config, $context) { 00022 00023 $string = $this->parseCDATA($string); 00024 00025 if ($string === '') return false; 00026 $length = strlen($string); 00027 if ($length === 1) return false; 00028 if ($string[$length - 1] !== '%') return false; 00029 00030 $number = substr($string, 0, $length - 1); 00031 $number = $this->number_def->validate($number, $config, $context); 00032 00033 if ($number === false) return false; 00034 return "$number%"; 00035 00036 } 00037 00038 } 00039 00040 // vim: et sw=4 sts=4