00001 <?php
00002
00006 class HTMLPurifier_AttrDef_HTML_Color extends HTMLPurifier_AttrDef
00007 {
00008
00009 public function validate($string, $config, $context) {
00010
00011 static $colors = null;
00012 if ($colors === null) $colors = $config->get('Core', 'ColorKeywords');
00013
00014 $string = trim($string);
00015
00016 if (empty($string)) return false;
00017 if (isset($colors[$string])) return $colors[$string];
00018 if ($string[0] === '#') $hex = substr($string, 1);
00019 else $hex = $string;
00020
00021 $length = strlen($hex);
00022 if ($length !== 3 && $length !== 6) return false;
00023 if (!ctype_xdigit($hex)) return false;
00024 if ($length === 3) $hex = $hex[0].$hex[0].$hex[1].$hex[1].$hex[2].$hex[2];
00025
00026 return "#$hex";
00027
00028 }
00029
00030 }
00031