11 static $colors = null;
12 if ($colors === null) $colors =
$config->get(
'Core.ColorKeywords');
14 $color = trim($color);
15 if ($color ===
'')
return false;
17 $lower = strtolower($color);
18 if (isset($colors[$lower]))
return $colors[$lower];
20 if (strpos($color,
'rgb(') !==
false) {
22 $length = strlen($color);
23 if (strpos($color,
')') !== $length - 1)
return false;
24 $triad = substr($color, 4, $length - 4 - 1);
25 $parts = explode(
',', $triad);
26 if (count($parts) !== 3)
return false;
29 foreach ($parts as $part) {
31 if ($part ===
'')
return false;
32 $length = strlen($part);
33 if ($part[$length - 1] ===
'%') {
37 } elseif (
$type !==
'percentage') {
40 $num = (float) substr($part, 0, $length - 1);
43 $new_parts[] =
"$num%";
48 } elseif (
$type !==
'integer') {
54 $new_parts[] = (string)
$num;
57 $new_triad = implode(
',', $new_parts);
58 $color =
"rgb($new_triad)";
61 if ($color[0] ===
'#') {
62 $hex = substr($color, 1);
65 $color =
'#' . $color;
67 $length = strlen($hex);
68 if ($length !== 3 && $length !== 6)
return false;
69 if (!ctype_xdigit($hex))
return false;