=====Development page for the Color / Colour action===== >> **See also** [[Docs:ColorActionInfo | Documentation page]] >> The color action, as of version 1.1.6.0, has some disadvantages: 1) it does no verification if a color is actually given or if it is valid, therefore produces invalid html 1) it causes two php-notices 1) it has problems with some kinds of text 1) it does not use the standard for action-params the code below solves this issues and adds support for a background-color, too: ''Update 27/03/2006: new version which (hopefully) addresses the issues raised by jw in the comments. Please test.'' ''Update 28/03/2006: Regexp for hex-values works now. Error-messages wraped in class.'' %%(php;1) '.ERROR_NO_TEXT_GIVEN.''; $style = $colorcode = $backgroundcolor = $output = ''; // *** User input section *** if (is_array($vars)) { foreach ($vars as $param => $value) { switch ($param) { case 'text': $text = $this->htmlspecialchars_ent($value); break; case 'c': case 'hex': if (in_array(strtolower($value), $html_color_names)) $colorcode = strtolower($value); else if (preg_match($hex_color_regexp, $value)) $colorcode = $value; break; case 'bg': if (in_array(strtolower($value), $html_color_names)) $backgroundcolor = strtolower($value); else if (preg_match($hex_color_regexp, $value)) $backgroundcolor = $value; } } } // *** prepare the output *** if ($colorcode !== '') $style .= 'color:'.$colorcode.';'; if ($backgroundcolor !== '') $style .= 'background-color:'.$backgroundcolor.';'; if ($style !== '') $output .= ''.$text.''; else $output = $text.' '.ERROR_NO_COLOR_SPECIFIED.''; // *** Output section *** print ($output); ?> %%