Implement CSS.AllowedFonts.
[htmlpurifier/bfroehle.git] / library / HTMLPurifier / AttrDef / CSS / Percentage.php
blobc34b8fc3c392b90fa09652d6af38742937948c41
1 <?php
3 /**
4 * Validates a Percentage as defined by the CSS spec.
5 */
6 class HTMLPurifier_AttrDef_CSS_Percentage extends HTMLPurifier_AttrDef
9 /**
10 * Instance of HTMLPurifier_AttrDef_CSS_Number to defer number validation
12 protected $number_def;
14 /**
15 * @param Bool indicating whether to forbid negative values
17 public function __construct($non_negative = false) {
18 $this->number_def = new HTMLPurifier_AttrDef_CSS_Number($non_negative);
21 public function validate($string, $config, $context) {
23 $string = $this->parseCDATA($string);
25 if ($string === '') return false;
26 $length = strlen($string);
27 if ($length === 1) return false;
28 if ($string[$length - 1] !== '%') return false;
30 $number = substr($string, 0, $length - 1);
31 $number = $this->number_def->validate($number, $config, $context);
33 if ($number === false) return false;
34 return "$number%";
40 // vim: et sw=4 sts=4