2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // $Id: color.inc.php,v 1.20 2005/01/08 04:13:19 henoheno Exp $
7 // Allow CSS instead of <font> tag
8 // NOTE: <font> tag become invalid from XHTML 1.1
9 define('PLUGIN_COLOR_ALLOW_CSS', TRUE); // TRUE, FALSE
12 define('PLUGIN_COLOR_USAGE', '&color(foreground[,background]){text};');
13 define('PLUGIN_COLOR_REGEX', '/^(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z-]+)$/i');
14 function plugin_color_inline()
18 $args = func_get_args();
19 $text = array_pop($args); // htmlspecialchars(text)
21 list($color, $bgcolor) = array_pad($args, 2, '');
22 if ($color != '' && $bgcolor != '' && $text == '') {
23 // Maybe the old style: '&color(foreground,text);'
24 $text = htmlspecialchars($bgcolor);
27 if (($color == '' && $bgcolor == '') || $text == '' || func_num_args() > 3)
28 return PLUGIN_COLOR_USAGE;
31 foreach(array($color, $bgcolor) as $col){
32 if ($col != '' && ! preg_match(PLUGIN_COLOR_REGEX, $col))
33 return '&color():Invalid color: ' . htmlspecialchars($col) . ';';
36 if (PLUGIN_COLOR_ALLOW_CSS === TRUE || ! isset($pkwk_dtd) || $pkwk_dtd == PKWK_DTD_XHTML_1_1) {
38 if ($color != '' && $bgcolor != '') $delimiter = '; ';
39 if ($color != '') $color = 'color:' . $color;
40 if ($bgcolor != '') $bgcolor = 'background-color:' . $bgcolor;
41 return '<span style="' . $color . $delimiter . $bgcolor . '">' .
44 if ($bgcolor != '') return '&color(): bgcolor (with CSS) not allowed;';
45 return '<font color="' . $color . '">' . $text . '</font>';