OSDN Git Service

BugTrack/2436 ESLint - Linting utility for JavaScript
[pukiwiki/pukiwiki.git] / plugin / color.inc.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // color.inc.php
4 // Copyright
5 //   2003-2016 PukiWiki Development Team
6 // License: GPL v2 or (at your option) any later version
7 //
8 // Text color plugin
9
10 // Allow CSS instead of <font> tag
11 // NOTE: <font> tag become invalid from XHTML 1.1
12 define('PLUGIN_COLOR_ALLOW_CSS', TRUE); // TRUE, FALSE
13
14 // ----
15 define('PLUGIN_COLOR_USAGE', '&color(foreground[,background]){text};');
16 define('PLUGIN_COLOR_REGEX', '/^(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z-]+)$/i');
17
18 function plugin_color_inline()
19 {
20         $args = func_get_args();
21         $text = strip_autolink(array_pop($args)); // Already htmlsc(text)
22
23         list($color, $bgcolor) = array_pad($args, 2, '');
24         if ($color != '' && $bgcolor != '' && $text == '') {
25                 // Maybe the old style: '&color(foreground,text);'
26                 $text    = htmlsc($bgcolor);
27                 $bgcolor = '';
28         }
29         if (($color == '' && $bgcolor == '') || $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: ' . htmlsc($col) . ';';
36         }
37
38         if (PLUGIN_COLOR_ALLOW_CSS) {
39                 $delimiter = '';
40                 if ($color != '' && $bgcolor != '') $delimiter = '; ';
41                 if ($color   != '') $color   = 'color:' . $color;
42                 if ($bgcolor != '') $bgcolor = 'background-color:' . $bgcolor;
43                 return '<span style="' . $color . $delimiter . $bgcolor . '">' .
44                         $text . '</span>';
45         } else {
46                 if ($bgcolor != '') return '&color(): bgcolor (with CSS) not allowed;';
47                 return '<font color="' . $color . '">' . $text . '</font>';
48         }
49 }