OSDN Git Service

Updating...
[pukiwiki/pukiwiki.git] / plugin / color.inc.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // $Id: color.inc.php,v 1.22 2005/06/16 15:04:08 henoheno Exp $
4 //
5 // Text color plugin
6
7 // 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
10
11 // ----
12 define('PLUGIN_COLOR_USAGE', '&color(foreground[,background]){text};');
13 define('PLUGIN_COLOR_REGEX', '/^(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z-]+)$/i');
14
15 function plugin_color_inline()
16 {
17         global $pkwk_dtd;
18
19         $args = func_get_args();
20         $text = strip_autolink(array_pop($args)); // Already htmlspecialchars(text)
21
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)
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 || ! isset($pkwk_dtd) || $pkwk_dtd == PKWK_DTD_XHTML_1_1) {
38                 $delimiter = '';
39                 if ($color != '' && $bgcolor != '') $delimiter = '; ';
40                 if ($color   != '') $color   = 'color:' . $color;
41                 if ($bgcolor != '') $bgcolor = 'background-color:' . $bgcolor;
42                 return '<span style="' . $color . $delimiter . $bgcolor . '">' .
43                         $text . '</span>';
44         } else {
45                 if ($bgcolor != '') return '&color(): bgcolor (with CSS) not allowed;';
46                 return '<font color="' . $color . '">' . $text . '</font>';
47         }
48 }
49 ?>