• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision01618398dbe99a0d550a97acd25e8d986491b75b (tree)
Time2007-11-11 18:36:53
Authorhenoheno <henoheno>
Commiterhenoheno

Log Message

* BugTrack2/285: & => &amp;
* BugTrack/779: Show error ASAP
* BugTrack/779: Not using list() and array_pad()
* BugTrack/779: trim(color)
* BugTrack/779: Simplify

Change Summary

Incremental Difference

--- a/plugin/color.inc.php
+++ b/plugin/color.inc.php
@@ -1,15 +1,19 @@
11 <?php
22 // PukiWiki - Yet another WikiWikiWeb clone.
3-// $Id: color.inc.php,v 1.22 2005/06/16 15:04:08 henoheno Exp $
3+// $Id: color.inc.php,v 1.23 2007/11/11 09:36:53 henoheno Exp $
44 //
55 // Text color plugin
6+//
7+// See Also:
8+// CCS 2.1 Specification: 4.3.6 Colors
9+// http://www.w3.org/TR/CSS21/syndata.html#value-def-color
610
711 // Allow CSS instead of <font> tag
812 // NOTE: <font> tag become invalid from XHTML 1.1
9-define('PLUGIN_COLOR_ALLOW_CSS', TRUE); // TRUE, FALSE
13+define('PLUGIN_COLOR_ALLOW_CSS', 1);
1014
1115 // ----
12-define('PLUGIN_COLOR_USAGE', '&color(foreground[,background]){text};');
16+define('PLUGIN_COLOR_USAGE', '&amp;color(foreground[,background]){text};');
1317 define('PLUGIN_COLOR_REGEX', '/^(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z-]+)$/i');
1418
1519 function plugin_color_inline()
@@ -17,32 +21,38 @@ function plugin_color_inline()
1721 global $pkwk_dtd;
1822
1923 $args = func_get_args();
20- $text = strip_autolink(array_pop($args)); // Already htmlspecialchars(text)
24+ $text = strip_autolink(array_pop($args)); // htmlspecialchars(text) already
25+ $color = isset($args[0]) ? trim($args[0]) : '';
26+ $bgcolor = isset($args[1]) ? trim($args[1]) : '';
2127
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)
28+ if (($color == '' && $bgcolor == '') || func_num_args() > 3) {
2929 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) . ';';
30+ }
31+ if ($text == '' ) {
32+ if ($color != '' && $bgcolor != '') {
33+ // The old style like: '&color(foreground,text);'
34+ $text = htmlspecialchars($bgcolor);
35+ $bgcolor = '';
36+ } else {
37+ return PLUGIN_COLOR_USAGE;
38+ }
39+ }
40+ foreach(array($color, $bgcolor) as $_color){
41+ if ($_color != '' && ! preg_match(PLUGIN_COLOR_REGEX, $_color)) {
42+ return '&amp;color():Invalid color: ' . htmlspecialchars($_color) . ';';
43+ }
3544 }
3645
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;
46+ if (PLUGIN_COLOR_ALLOW_CSS || ! isset($pkwk_dtd) || $pkwk_dtd == PKWK_DTD_XHTML_1_1) {
47+ if ($color != '') $color = 'color:' . $color;
4148 if ($bgcolor != '') $bgcolor = 'background-color:' . $bgcolor;
49+ $delimiter = ($color != '' && $bgcolor != '') ? ';' : '';
4250 return '<span style="' . $color . $delimiter . $bgcolor . '">' .
4351 $text . '</span>';
4452 } else {
45- if ($bgcolor != '') return '&color(): bgcolor (with CSS) not allowed;';
53+ if ($bgcolor != '') {
54+ return '&amp;color(): bgcolor not allowed;';
55+ }
4656 return '<font color="' . $color . '">' . $text . '</font>';
4757 }
4858 }