9 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
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
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
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');
26 function plugin_color_inline()
30 $args = func_get_args();
31 $text = strip_autolink(array_pop($args)); // Already htmlspecialchars(text)
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);
39 if (($color == '' && $bgcolor == '') || $text == '' || func_num_args() > 3)
40 return PLUGIN_COLOR_USAGE;
43 foreach(array($color, $bgcolor) as $col){
44 if ($col != '' && ! preg_match(PLUGIN_COLOR_REGEX, $col))
45 return '&color():Invalid color: ' . htmlspecialchars($col) . ';';
48 if (PLUGIN_COLOR_ALLOW_CSS === TRUE || ! isset($pkwk_dtd) || $pkwk_dtd == PKWK_DTD_XHTML_1_1) {
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 . '">' .
56 if ($bgcolor != '') return '&color(): bgcolor (with CSS) not allowed;';
57 return '<font color="' . $color . '">' . $text . '</font>';