Validates Color as defined by CSS.
More...
|
| validate ($color, $config, $context) |
|
| validate ($string, $config, $context) |
| Validates and cleans passed string according to a definition. More...
|
|
| parseCDATA ($string) |
| Convenience method that parses a string as if it were CDATA. More...
|
|
| make ($string) |
| Factory method for creating this class from a string. More...
|
|
|
| $minimized = false |
| Tells us whether or not an HTML attribute is minimized. More...
|
|
| $required = false |
| Tells us whether or not an HTML attribute is required. More...
|
|
| mungeRgb ($string) |
| Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work properly. More...
|
|
| expandCSSEscape ($string) |
| Parses a possibly escaped CSS string and returns the "pure" version of it. More...
|
|
Validates Color as defined by CSS.
Definition at line 6 of file Color.php.
◆ validate()
HTMLPurifier_AttrDef_CSS_Color::validate |
( |
|
$color, |
|
|
|
$config, |
|
|
|
$context |
|
) |
| |
- Parameters
-
- Returns
- bool|string
Definition at line 15 of file Color.php.
17 static $colors = null;
18 if ($colors === null) {
19 $colors = $config->get(
'Core.ColorKeywords');
22 $color = trim($color);
27 $lower = strtolower($color);
28 if (isset($colors[$lower])) {
29 return $colors[$lower];
32 if (strpos($color,
'rgb(') !==
false) {
34 $length = strlen($color);
35 if (strpos($color,
')') !== $length - 1) {
38 $triad = substr($color, 4, $length - 4 - 1);
39 $parts = explode(
',', $triad);
40 if (count($parts) !== 3) {
45 foreach ($parts as $part) {
50 $length = strlen($part);
51 if ($part[$length - 1] ===
'%') {
55 } elseif ($type !==
'percentage') {
58 $num = (float)substr($part, 0, $length - 1);
65 $new_parts[] =
"$num%";
70 } elseif ($type !==
'integer') {
80 $new_parts[] = (string)$num;
83 $new_triad = implode(
',', $new_parts);
84 $color =
"rgb($new_triad)";
87 if ($color[0] ===
'#') {
88 $hex = substr($color, 1);
91 $color =
'#' . $color;
93 $length = strlen($hex);
94 if ($length !== 3 && $length !== 6) {
97 if (!ctype_xdigit($hex)) {
The documentation for this class was generated from the following file:
- Services/Html/HtmlPurifier/library/HTMLPurifier/AttrDef/CSS/Color.php