OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / wiki_main / include / plugin / color.inc.php
1 <?php
2 /**
3  * colorプラグイン
4  *
5  * 機能:テキストに色を付ける。
6  *
7  * PHP versions 5
8  *
9  * LICENSE: This source file is licensed under the terms of the GNU General Public License.
10  *
11  * @package    Magic3 Framework
12  * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
13  * @copyright  Copyright 2006-2008 Magic3 Project.
14  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
15  * @version    SVN: $Id: color.inc.php 1098 2008-10-22 11:43:09Z fishbone $
16  * @link       http://www.magic3.org
17  */
18 // Allow CSS instead of <font> tag
19 // NOTE: <font> tag become invalid from XHTML 1.1
20 define('PLUGIN_COLOR_ALLOW_CSS', TRUE); // TRUE, FALSE
21
22 // ----
23 define('PLUGIN_COLOR_USAGE', '&color(foreground[,background]){text};');
24 define('PLUGIN_COLOR_REGEX', '/^(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z-]+)$/i');
25
26 function plugin_color_inline()
27 {
28         global $pkwk_dtd;
29
30         $args = func_get_args();
31         $text = strip_autolink(array_pop($args)); // Already htmlspecialchars(text)
32
33         list($color, $bgcolor) = array_pad($args, 2, '');
34         if ($color != '' && $bgcolor != '' && $text == '') {
35                 // Maybe the old style: '&color(foreground,text);'
36                 $text    = htmlspecialchars($bgcolor);
37                 $bgcolor = '';
38         }
39         if (($color == '' && $bgcolor == '') || $text == '' || func_num_args() > 3)
40                 return PLUGIN_COLOR_USAGE;
41
42         // Invalid color
43         foreach(array($color, $bgcolor) as $col){
44                 if ($col != '' && ! preg_match(PLUGIN_COLOR_REGEX, $col))
45                         return '&color():Invalid color: ' . htmlspecialchars($col) . ';';
46         }
47
48         if (PLUGIN_COLOR_ALLOW_CSS === TRUE || ! isset($pkwk_dtd) || $pkwk_dtd == PKWK_DTD_XHTML_1_1) {
49                 $delimiter = '';
50                 if ($color != '' && $bgcolor != '') $delimiter = '; ';
51                 if ($color   != '') $color   = 'color:' . $color;
52                 if ($bgcolor != '') $bgcolor = 'background-color:' . $bgcolor;
53                 return '<span style="' . $color . $delimiter . $bgcolor . '">' .
54                         $text . '</span>';
55         } else {
56                 if ($bgcolor != '') return '&color(): bgcolor (with CSS) not allowed;';
57                 return '<font color="' . $color . '">' . $text . '</font>';
58         }
59 }
60 ?>