1 |
<?php |
2 |
///////////////////////////////////////////////// |
3 |
// PukiWiki - Yet another WikiWikiWeb clone. |
4 |
// |
5 |
// $Id: color.inc.php,v 1.9 2004/07/31 03:09:20 henoheno Exp $ |
6 |
// |
7 |
// Text color plugin |
8 |
|
9 |
define('PLUGIN_COLOR_ALLOW_CSS', FALSE); // TRUE, FALSE |
10 |
|
11 |
// ---- |
12 |
define('PLUGIN_COLOR_REGEX', '/^(#[0-9a-f]{6}|[a-z-]+)$/i'); |
13 |
function plugin_color_inline() |
14 |
{ |
15 |
static $usage = '&color(foreground[,background]){text};'; |
16 |
global $html_transitional; |
17 |
|
18 |
$args = func_get_args(); |
19 |
$text = array_pop($args); // htmlspecialchars(text) |
20 |
|
21 |
list($color, $bgcolor) = array_pad($args, 2, ''); |
22 |
if ($text == '' && $bgcolor != '') { |
23 |
// Maybe the old style: '&color(foreground,text);' |
24 |
$text = htmlspecialchars($bgcolor); |
25 |
$bgcolor = ''; |
26 |
} |
27 |
if ($color == '' || $text == '' || func_num_args() > 3) return $usage; |
28 |
|
29 |
// Invalid color |
30 |
foreach(array($color, $bgcolor) as $col){ |
31 |
if ($col != '' && ! preg_match(PLUGIN_COLOR_REGEX, $col)) |
32 |
return '&color():Invalid color: ' . htmlspecialchars($col) . ';'; |
33 |
} |
34 |
|
35 |
if ($html_transitional === TRUE && PLUGIN_COLOR_ALLOW_CSS === TRUE) { |
36 |
if ($bgcolor != '') $bgcolor = ';background-color:' . $bgcolor; |
37 |
return '<span style="color:' . $color . $bgcolor . '">' . $text . '</span>'; |
38 |
} else { |
39 |
// Using <font> tag with: |
40 |
// NG: XHTML 1.1 |
41 |
// OK: XHTML 1.0 Transitional |
42 |
if ($bgcolor != '') return '&color(): bgcolor (with CSS) not allowd;'; |
43 |
return '<font color="' . $color . '">' . $text . '</font>'; |
44 |
} |
45 |
} |
46 |
?> |