1 |
<?php |
<?php |
|
///////////////////////////////////////////////// |
|
2 |
// PukiWiki - Yet another WikiWikiWeb clone. |
// PukiWiki - Yet another WikiWikiWeb clone. |
|
// |
|
3 |
// $Id$ |
// $Id$ |
4 |
// |
// |
5 |
// Text color plugin |
// Text color plugin |
6 |
|
|
7 |
// Allow CSS instead of font tag (XHTML 1.0 Transitional only) |
// 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 |
define('PLUGIN_COLOR_ALLOW_CSS', TRUE); // TRUE, FALSE |
10 |
|
|
11 |
// ---- |
// ---- |
12 |
define('PLUGIN_COLOR_USAGE', '&color(foreground[,background]){text};'); |
define('PLUGIN_COLOR_USAGE', '&color(foreground[,background]){text};'); |
13 |
define('PLUGIN_COLOR_REGEX', '/^(#[0-9a-f]{6}|[a-z-]+)$/i'); |
define('PLUGIN_COLOR_REGEX', '/^(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z-]+)$/i'); |
14 |
function plugin_color_inline() |
function plugin_color_inline() |
15 |
{ |
{ |
16 |
global $html_transitional; |
global $html_transitional; |
19 |
$text = array_pop($args); // htmlspecialchars(text) |
$text = array_pop($args); // htmlspecialchars(text) |
20 |
|
|
21 |
list($color, $bgcolor) = array_pad($args, 2, ''); |
list($color, $bgcolor) = array_pad($args, 2, ''); |
22 |
if ($text == '' && $bgcolor != '') { |
if ($color != '' && $bgcolor != '' && $text == '') { |
23 |
// Maybe the old style: '&color(foreground,text);' |
// Maybe the old style: '&color(foreground,text);' |
24 |
$text = htmlspecialchars($bgcolor); |
$text = htmlspecialchars($bgcolor); |
25 |
$bgcolor = ''; |
$bgcolor = ''; |
26 |
} |
} |
27 |
if ($color == '' || $text == '' || func_num_args() > 3) |
if (($color == '' && $bgcolor == '') || $text == '' || func_num_args() > 3) |
28 |
return PLUGIN_COLOR_USAGE; |
return PLUGIN_COLOR_USAGE; |
29 |
|
|
30 |
// Invalid color |
// Invalid color |
34 |
} |
} |
35 |
|
|
36 |
if (PLUGIN_COLOR_ALLOW_CSS === TRUE && $html_transitional === FALSE) { |
if (PLUGIN_COLOR_ALLOW_CSS === TRUE && $html_transitional === FALSE) { |
37 |
if ($bgcolor != '') $bgcolor = ';background-color:' . $bgcolor; |
$delimiter = ''; |
38 |
return '<span style="color:' . $color . $bgcolor . '">' . $text . '</span>'; |
if ($color != '' && $bgcolor != '') $delimiter = '; '; |
39 |
|
if ($color != '') $color = 'color:' . $color; |
40 |
|
if ($bgcolor != '') $bgcolor = 'background-color:' . $bgcolor; |
41 |
|
return '<span style="' . $color . $delimiter . $bgcolor . '">' . |
42 |
|
$text . '</span>'; |
43 |
} else { |
} else { |
44 |
// NOTE: <font> tag become invalid from XHTML 1.1 |
if ($bgcolor != '') return '&color(): bgcolor (with CSS) not allowed;'; |
|
if ($bgcolor != '') return '&color(): bgcolor (with CSS) not allowd;'; |
|
45 |
return '<font color="' . $color . '">' . $text . '</font>'; |
return '<font color="' . $color . '">' . $text . '</font>'; |
46 |
} |
} |
47 |
} |
} |