4 |
// |
// |
5 |
// $Id$ |
// $Id$ |
6 |
// |
// |
7 |
|
// Text color plugin |
8 |
|
|
9 |
|
// Allow CSS instead of font tag (XHTML 1.0 Transitional only) |
10 |
|
define('PLUGIN_COLOR_ALLOW_CSS', TRUE); // TRUE, FALSE |
11 |
|
|
12 |
|
// ---- |
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() |
function plugin_color_inline() |
16 |
{ |
{ |
17 |
if (func_num_args() == 3) |
global $html_transitional; |
18 |
{ |
|
19 |
list($color,$bgcolor,$body) = func_get_args(); |
$args = func_get_args(); |
20 |
if ($body == '') |
$text = array_pop($args); // htmlspecialchars(text) |
21 |
{ |
|
22 |
$body = $bgcolor; |
list($color, $bgcolor) = array_pad($args, 2, ''); |
23 |
$bgcolor = ''; |
if ($text == '' && $bgcolor != '') { |
24 |
} |
// Maybe the old style: '&color(foreground,text);' |
25 |
} |
$text = htmlspecialchars($bgcolor); |
|
else if (func_num_args() == 2) |
|
|
{ |
|
26 |
$bgcolor = ''; |
$bgcolor = ''; |
|
list($color,$body) = func_get_args(); |
|
|
} |
|
|
else |
|
|
{ |
|
|
return FALSE; |
|
27 |
} |
} |
28 |
|
if ($color == '' || $text == '' || func_num_args() > 3) |
29 |
if ($color == '' or $body == '') |
return PLUGIN_COLOR_USAGE; |
30 |
{ |
|
31 |
return FALSE; |
// Invalid color |
32 |
} |
foreach(array($color, $bgcolor) as $col){ |
33 |
if (!plugin_color_is_valid($color) or !plugin_color_is_valid($bgcolor)) |
if ($col != '' && ! preg_match(PLUGIN_COLOR_REGEX, $col)) |
34 |
{ |
return '&color():Invalid color: ' . htmlspecialchars($col) . ';'; |
|
return $body; |
|
35 |
} |
} |
36 |
|
|
37 |
if ($bgcolor != '') |
if (PLUGIN_COLOR_ALLOW_CSS === TRUE && $html_transitional === FALSE) { |
38 |
{ |
if ($bgcolor != '') $bgcolor = ';background-color:' . $bgcolor; |
39 |
$color .= ';background-color:'.$bgcolor; |
return '<span style="color:' . $color . $bgcolor . '">' . $text . '</span>'; |
40 |
|
} else { |
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>'; |
44 |
} |
} |
|
return "<span style=\"color:$color\">$body</span>"; |
|
|
} |
|
|
function plugin_color_is_valid($color) |
|
|
{ |
|
|
return ($color == '') or preg_match('/^(#[0-9a-f]+|[\w-]+)/i',$color); |
|
45 |
} |
} |
46 |
?> |
?> |