2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // $Id: color.inc.php,v 1.21 2005/05/07 07:36:35 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');
15 function plugin_color_inline()
19 $args = func_get_args();
20 $text = strip_htmltag(array_pop($args)); // htmlspecialchars(text)
21 // strip_htmltag() is just for avoiding AutoLink insertion
23 list($color, $bgcolor) = array_pad($args, 2, '');
24 if ($color != '' && $bgcolor != '' && $text == '') {
25 // Maybe the old style: '&color(foreground,text);'
26 $text = htmlspecialchars($bgcolor);
29 if (($color == '' && $bgcolor == '') || $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 || ! isset($pkwk_dtd) || $pkwk_dtd == PKWK_DTD_XHTML_1_1) {
40 if ($color != '' && $bgcolor != '') $delimiter = '; ';
41 if ($color != '') $color = 'color:' . $color;
42 if ($bgcolor != '') $bgcolor = 'background-color:' . $bgcolor;
43 return '<span style="' . $color . $delimiter . $bgcolor . '">' .
46 if ($bgcolor != '') return '&color(): bgcolor (with CSS) not allowed;';
47 return '<font color="' . $color . '">' . $text . '</font>';