2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
5 // $Id: color.inc.php,v 1.16 2004/11/22 14:09:59 henoheno Exp $
9 // Allow CSS instead of <font> tag
10 // NOTE: <font> tag become invalid from XHTML 1.1
11 define('PLUGIN_COLOR_ALLOW_CSS', TRUE); // TRUE, FALSE
14 define('PLUGIN_COLOR_USAGE', '&color(foreground[,background]){text};');
15 define('PLUGIN_COLOR_REGEX', '/^(#[0-9a-f]{6}|[a-z-]+)$/i');
16 function plugin_color_inline()
18 global $html_transitional;
20 $args = func_get_args();
21 $text = array_pop($args); // htmlspecialchars(text)
23 list($color, $bgcolor) = array_pad($args, 2, '');
24 if ($text == '' && $bgcolor != '') {
25 // Maybe the old style: '&color(foreground,text);'
26 $text = htmlspecialchars($bgcolor);
29 if ($color == '' || $text == '' || func_num_args() > 3)
30 return PLUGIN_COLOR_USAGE;
33 foreach(array($color, $bgcolor) as $col){
34 if ($col != '' && ! preg_match(PLUGIN_COLOR_REGEX, $col))
35 return '&color():Invalid color: ' . htmlspecialchars($col) . ';';
38 if (PLUGIN_COLOR_ALLOW_CSS === TRUE && $html_transitional === FALSE) {
39 if ($bgcolor != '') $bgcolor = ';background-color:' . $bgcolor;
40 return '<span style="color:' . $color . $bgcolor . '">' . $text . '</span>';
42 if ($bgcolor != '') return '&color(): bgcolor (with CSS) not allowed;';
43 return '<font color="' . $color . '">' . $text . '</font>';