| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Validates a ratio as defined by the CSS spec. |
| 5 |
*/ |
| 6 |
class HTMLPurifier_AttrDef_CSS_Ratio extends HTMLPurifier_AttrDef |
| 7 |
{ |
| 8 |
/** |
| 9 |
* @param string $ratio Ratio to validate |
| 10 |
* @param HTMLPurifier_Config $config Configuration options |
| 11 |
* @param HTMLPurifier_Context $context Context |
| 12 |
* |
| 13 |
* @return string|boolean |
| 14 |
* |
| 15 |
* @warning Some contexts do not pass $config, $context. These |
| 16 |
* variables should not be used without checking HTMLPurifier_Length |
| 17 |
*/ |
| 18 |
public function validate($ratio, $config, $context) |
| 19 |
{ |
| 20 |
$ratio = $this->parseCDATA($ratio); |
| 21 |
|
| 22 |
$parts = explode('/', $ratio, 2); |
| 23 |
$length = count($parts); |
| 24 |
|
| 25 |
if ($length < 1 || $length > 2) { |
| 26 |
return false; |
| 27 |
} |
| 28 |
|
| 29 |
$num = new \HTMLPurifier_AttrDef_CSS_Number(); |
| 30 |
|
| 31 |
if ($length === 1) { |
| 32 |
return $num->validate($parts[0], $config, $context); |
| 33 |
} |
| 34 |
|
| 35 |
$num1 = $num->validate($parts[0], $config, $context); |
| 36 |
$num2 = $num->validate($parts[1], $config, $context); |
| 37 |
|
| 38 |
if ($num1 === false || $num2 === false) { |
| 39 |
return false; |
| 40 |
} |
| 41 |
|
| 42 |
return $num1 . '/' . $num2; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
// vim: et sw=4 sts=4 |