Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / lib / htmlpurifier / HTMLPurifier / AttrDef / HTML / Pixels.php
blob38bc7d684e52f74d224dd1c60aa1ff5d56ead393
1 <?php
3 require_once 'HTMLPurifier/AttrDef.php';
5 /**
6 * Validates an integer representation of pixels according to the HTML spec.
7 */
8 class HTMLPurifier_AttrDef_HTML_Pixels extends HTMLPurifier_AttrDef
11 function validate($string, $config, &$context) {
13 $string = trim($string);
14 if ($string === '0') return $string;
15 if ($string === '') return false;
16 $length = strlen($string);
17 if (substr($string, $length - 2) == 'px') {
18 $string = substr($string, 0, $length - 2);
20 if (!is_numeric($string)) return false;
21 $int = (int) $string;
23 if ($int < 0) return '0';
25 // upper-bound value, extremely high values can
26 // crash operating systems, see <http://ha.ckers.org/imagecrash.html>
27 // WARNING, above link WILL crash you if you're using Windows
29 if ($int > 1200) return '1200';
31 return (string) $int;