OSDN Git Service

BugTrack2/176: Respect encoding as rss said (Base patched by matsuo2)
[pukiwiki/pukiwiki.git] / plugin / color.inc.php
index 41f053c..471b43d 100644 (file)
@@ -1,8 +1,6 @@
 <?php
-/////////////////////////////////////////////////
 // PukiWiki - Yet another WikiWikiWeb clone.
-//
-// $Id: color.inc.php,v 1.15 2004/11/21 13:37:53 henoheno Exp $
+// $Id: color.inc.php,v 1.22 2005/06/16 15:04:08 henoheno Exp $
 //
 // Text color plugin
 
@@ -12,21 +10,22 @@ define('PLUGIN_COLOR_ALLOW_CSS', TRUE); // TRUE, FALSE
 
 // ----
 define('PLUGIN_COLOR_USAGE', '&color(foreground[,background]){text};');
-define('PLUGIN_COLOR_REGEX', '/^(#[0-9a-f]{6}|[a-z-]+)$/i');
+define('PLUGIN_COLOR_REGEX', '/^(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z-]+)$/i');
+
 function plugin_color_inline()
 {
-       global $html_transitional;
+       global $pkwk_dtd;
 
        $args = func_get_args();
-       $text = array_pop($args); // htmlspecialchars(text)
+       $text = strip_autolink(array_pop($args)); // Already htmlspecialchars(text)
 
        list($color, $bgcolor) = array_pad($args, 2, '');
-       if ($text == '' && $bgcolor != '') {
+       if ($color != '' && $bgcolor != '' && $text == '') {
                // Maybe the old style: '&color(foreground,text);'
                $text    = htmlspecialchars($bgcolor);
                $bgcolor = '';
        }
-       if ($color == '' || $text == '' || func_num_args() > 3)
+       if (($color == '' && $bgcolor == '') || $text == '' || func_num_args() > 3)
                return PLUGIN_COLOR_USAGE;
 
        // Invalid color
@@ -35,11 +34,15 @@ function plugin_color_inline()
                        return '&color():Invalid color: ' . htmlspecialchars($col) . ';';
        }
 
-       if (PLUGIN_COLOR_ALLOW_CSS === TRUE && $html_transitional === FALSE) {
-               if ($bgcolor != '') $bgcolor = ';background-color:' . $bgcolor;
-               return '<span style="color:' . $color . $bgcolor . '">' . $text . '</span>';
+       if (PLUGIN_COLOR_ALLOW_CSS === TRUE || ! isset($pkwk_dtd) || $pkwk_dtd == PKWK_DTD_XHTML_1_1) {
+               $delimiter = '';
+               if ($color != '' && $bgcolor != '') $delimiter = '; ';
+               if ($color   != '') $color   = 'color:' . $color;
+               if ($bgcolor != '') $bgcolor = 'background-color:' . $bgcolor;
+               return '<span style="' . $color . $delimiter . $bgcolor . '">' .
+                       $text . '</span>';
        } else {
-               if ($bgcolor != '') return '&color(): bgcolor (with CSS) not allowd;';
+               if ($bgcolor != '') return '&color(): bgcolor (with CSS) not allowed;';
                return '<font color="' . $color . '">' . $text . '</font>';
        }
 }