Revision | 01618398dbe99a0d550a97acd25e8d986491b75b (tree) |
---|---|
Time | 2007-11-11 18:36:53 |
Author | henoheno <henoheno> |
Commiter | henoheno |
* BugTrack2/285: & => &
* BugTrack/779: Show error ASAP
* BugTrack/779: Not using list() and array_pad()
* BugTrack/779: trim(color)
* BugTrack/779: Simplify
@@ -1,15 +1,19 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone. |
3 | -// $Id: color.inc.php,v 1.22 2005/06/16 15:04:08 henoheno Exp $ | |
3 | +// $Id: color.inc.php,v 1.23 2007/11/11 09:36:53 henoheno Exp $ | |
4 | 4 | // |
5 | 5 | // Text color plugin |
6 | +// | |
7 | +// See Also: | |
8 | +// CCS 2.1 Specification: 4.3.6 Colors | |
9 | +// http://www.w3.org/TR/CSS21/syndata.html#value-def-color | |
6 | 10 | |
7 | 11 | // Allow CSS instead of <font> tag |
8 | 12 | // NOTE: <font> tag become invalid from XHTML 1.1 |
9 | -define('PLUGIN_COLOR_ALLOW_CSS', TRUE); // TRUE, FALSE | |
13 | +define('PLUGIN_COLOR_ALLOW_CSS', 1); | |
10 | 14 | |
11 | 15 | // ---- |
12 | -define('PLUGIN_COLOR_USAGE', '&color(foreground[,background]){text};'); | |
16 | +define('PLUGIN_COLOR_USAGE', '&color(foreground[,background]){text};'); | |
13 | 17 | define('PLUGIN_COLOR_REGEX', '/^(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z-]+)$/i'); |
14 | 18 | |
15 | 19 | function plugin_color_inline() |
@@ -17,32 +21,38 @@ function plugin_color_inline() | ||
17 | 21 | global $pkwk_dtd; |
18 | 22 | |
19 | 23 | $args = func_get_args(); |
20 | - $text = strip_autolink(array_pop($args)); // Already htmlspecialchars(text) | |
24 | + $text = strip_autolink(array_pop($args)); // htmlspecialchars(text) already | |
25 | + $color = isset($args[0]) ? trim($args[0]) : ''; | |
26 | + $bgcolor = isset($args[1]) ? trim($args[1]) : ''; | |
21 | 27 | |
22 | - list($color, $bgcolor) = array_pad($args, 2, ''); | |
23 | - if ($color != '' && $bgcolor != '' && $text == '') { | |
24 | - // Maybe the old style: '&color(foreground,text);' | |
25 | - $text = htmlspecialchars($bgcolor); | |
26 | - $bgcolor = ''; | |
27 | - } | |
28 | - if (($color == '' && $bgcolor == '') || $text == '' || func_num_args() > 3) | |
28 | + if (($color == '' && $bgcolor == '') || func_num_args() > 3) { | |
29 | 29 | return PLUGIN_COLOR_USAGE; |
30 | - | |
31 | - // Invalid color | |
32 | - foreach(array($color, $bgcolor) as $col){ | |
33 | - if ($col != '' && ! preg_match(PLUGIN_COLOR_REGEX, $col)) | |
34 | - return '&color():Invalid color: ' . htmlspecialchars($col) . ';'; | |
30 | + } | |
31 | + if ($text == '' ) { | |
32 | + if ($color != '' && $bgcolor != '') { | |
33 | + // The old style like: '&color(foreground,text);' | |
34 | + $text = htmlspecialchars($bgcolor); | |
35 | + $bgcolor = ''; | |
36 | + } else { | |
37 | + return PLUGIN_COLOR_USAGE; | |
38 | + } | |
39 | + } | |
40 | + foreach(array($color, $bgcolor) as $_color){ | |
41 | + if ($_color != '' && ! preg_match(PLUGIN_COLOR_REGEX, $_color)) { | |
42 | + return '&color():Invalid color: ' . htmlspecialchars($_color) . ';'; | |
43 | + } | |
35 | 44 | } |
36 | 45 | |
37 | - if (PLUGIN_COLOR_ALLOW_CSS === TRUE || ! isset($pkwk_dtd) || $pkwk_dtd == PKWK_DTD_XHTML_1_1) { | |
38 | - $delimiter = ''; | |
39 | - if ($color != '' && $bgcolor != '') $delimiter = '; '; | |
40 | - if ($color != '') $color = 'color:' . $color; | |
46 | + if (PLUGIN_COLOR_ALLOW_CSS || ! isset($pkwk_dtd) || $pkwk_dtd == PKWK_DTD_XHTML_1_1) { | |
47 | + if ($color != '') $color = 'color:' . $color; | |
41 | 48 | if ($bgcolor != '') $bgcolor = 'background-color:' . $bgcolor; |
49 | + $delimiter = ($color != '' && $bgcolor != '') ? ';' : ''; | |
42 | 50 | return '<span style="' . $color . $delimiter . $bgcolor . '">' . |
43 | 51 | $text . '</span>'; |
44 | 52 | } else { |
45 | - if ($bgcolor != '') return '&color(): bgcolor (with CSS) not allowed;'; | |
53 | + if ($bgcolor != '') { | |
54 | + return '&color(): bgcolor not allowed;'; | |
55 | + } | |
46 | 56 | return '<font color="' . $color . '">' . $text . '</font>'; |
47 | 57 | } |
48 | 58 | } |