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.14 2004/11/21 13:32:30 henoheno Exp $
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()
16 {
17         global $html_transitional;
18
19         $args = func_get_args();
20         $text = array_pop($args); // htmlspecialchars(text)
21
22         list($color, $bgcolor) = array_pad($args, 2, '');
23         if ($text == '' && $bgcolor != '') {
24                 // Maybe the old style: '&color(foreground,text);'
25                 $text    = htmlspecialchars($bgcolor);
26                 $bgcolor = '';
27         }
28         if ($color == '' || $text == '' || func_num_args() > 3)
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) . ';';
35         }
36
37         if (PLUGIN_COLOR_ALLOW_CSS === TRUE && $html_transitional === FALSE) {
38                 if ($bgcolor != '') $bgcolor = ';background-color:' . $bgcolor;
39                 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         }
45 }
46 ?>