OSDN Git Service

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