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