修订版 | 3184f3842465cfab1497761d3acb852801cd3581 (tree) |
---|---|
时间 | 2011-02-15 00:45:07 |
作者 | henoheno <henoheno> |
Commiter | henoheno |
BugTrack2/343 BugTrack/779 Cleanup transition (3):
* Add/Correct/Simplify more comments, checks
* Simplify $param
@@ -1,6 +1,6 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone |
3 | -// $Id: ref.inc.php,v 1.55 2011-02-08 14:07:34 henoheno Exp $ | |
3 | +// $Id: ref.inc.php,v 1.56 2011-02-14 15:45:07 henoheno Exp $ | |
4 | 4 | // Copyright (C) |
5 | 5 | // 2002-2006, 2011 PukiWiki Developers Team |
6 | 6 | // 2001-2002 Originally written by yu-ji |
@@ -45,14 +45,17 @@ define('PLUGIN_REF_USAGE', '([pagename/]attached-file-name[,parameters, ... ][,t | ||
45 | 45 | |
46 | 46 | function plugin_ref_inline() |
47 | 47 | { |
48 | - // "$aryargs[] = & $body" at plugin.php | |
48 | + // NOTE: Already "$aryargs[] = & $body" at plugin.php | |
49 | 49 | if (func_num_args() == 1) { |
50 | 50 | return htmlsc('&ref(): Usage:' . PLUGIN_REF_USAGE . ';'); |
51 | 51 | } |
52 | 52 | |
53 | 53 | $params = plugin_ref_body(func_get_args()); |
54 | - if (isset($params['_error']) && $params['_error'] != '') { | |
55 | - return htmlsc('&ref(): ' . $params['_error'] . ';'); | |
54 | + if (isset($params['_error'])) { | |
55 | + return htmlsc('&ref(): ERROR: ' . $params['_error'] . ';'); | |
56 | + } | |
57 | + if (! isset($params['_body'])) { | |
58 | + return htmlsc('&ref(): ERROR: No _body;'); | |
56 | 59 | } |
57 | 60 | |
58 | 61 | return $params['_body']; |
@@ -65,12 +68,15 @@ function plugin_ref_convert() | ||
65 | 68 | } |
66 | 69 | |
67 | 70 | $params = plugin_ref_body(func_get_args()); |
68 | - if (isset($params['_error']) && $params['_error'] != '') { | |
69 | - return '<p>' . htmlsc('#ref(): ' . $params['_error']) . '</p>' . "\n"; | |
71 | + if (isset($params['_error'])) { | |
72 | + return '<p>' . htmlsc('#ref(): ERROR: ' . $params['_error']) . '</p>' . "\n"; | |
73 | + } | |
74 | + if (! isset($params['_body'])) { | |
75 | + return '<p>' . htmlsc('#ref(): ERROR: No _body') . '</p>' . "\n"; | |
70 | 76 | } |
71 | 77 | |
72 | 78 | // Wrap with a table |
73 | - if ((PLUGIN_REF_WRAP_TABLE && ! $params['nowrap']) || $params['wrap']) { | |
79 | + if ((PLUGIN_REF_WRAP_TABLE && ! isset($params['nowrap'])) || isset($params['wrap'])) { | |
74 | 80 | // margin:auto |
75 | 81 | // Mozilla 1.x = x (wrap, and around are ignored) |
76 | 82 | // Opera 6 = o |
@@ -81,9 +87,12 @@ function plugin_ref_convert() | ||
81 | 87 | // Opera 6 = x (aligning seems ignored with wrap) |
82 | 88 | // Netscape 6 = x (aligning seems ignored with wrap) |
83 | 89 | // IE6 = o |
84 | - $s_margin = htmlsc($params['around'] ? '0px' : 'auto'); | |
85 | - $s_margin_align = htmlsc(($params['_align'] == 'center') ? '' : | |
86 | - ';margin-' . $params['_align'] . ':0px'); | |
90 | + $s_margin = isset($params['around']) ? '0px' : 'auto'; | |
91 | + if (! isset($params['_align']) || $params['_align'] == 'center') { | |
92 | + $s_margin_align = ''; | |
93 | + } else { | |
94 | + $s_margin_align = ';margin-' . htmlsc($params['_align']) . ':0px'; | |
95 | + } | |
87 | 96 | $params['_body'] = <<<EOD |
88 | 97 | <table class="style_table" style="margin:$s_margin$s_margin_align"> |
89 | 98 | <tr> |
@@ -93,7 +102,7 @@ function plugin_ref_convert() | ||
93 | 102 | EOD; |
94 | 103 | } |
95 | 104 | |
96 | - if ($params['around']) { | |
105 | + if (isset($params['around'])) { | |
97 | 106 | $style = ($params['_align'] == 'right') ? 'float:right' : 'float:left'; |
98 | 107 | } else { |
99 | 108 | $style = 'text-align:' . $params['_align']; |
@@ -112,30 +121,27 @@ function plugin_ref_body($args) | ||
112 | 121 | $page = isset($vars['page']) ? $vars['page'] : ''; |
113 | 122 | |
114 | 123 | $params = array( |
115 | - // Align | |
116 | - 'left' => FALSE, | |
117 | - 'center' => FALSE, | |
118 | - 'right' => FALSE, | |
119 | - '_align' => PLUGIN_REF_DEFAULT_ALIGN, | |
120 | - | |
121 | - // Wrap with table or not | |
122 | - 'wrap' => FALSE, | |
123 | - 'nowrap' => FALSE, | |
124 | - | |
125 | - 'around' => FALSE, // wrap around | |
124 | + // Options | |
125 | + 'left' => FALSE, // Align | |
126 | + 'center' => FALSE, // Align | |
127 | + 'right' => FALSE, // Align | |
128 | + 'wrap' => FALSE, // Wrap the output with table ... | |
129 | + 'nowrap' => FALSE, // or not | |
130 | + 'around' => FALSE, // Text wrap around or not | |
126 | 131 | 'noicon' => FALSE, // Suppress showing icon |
127 | - 'nolink' => FALSE, // Suppress link to image itself | |
128 | 132 | 'noimg' => FALSE, // Suppress showing image |
133 | + 'nolink' => FALSE, // Suppress link to image itself | |
134 | + 'zoom' => FALSE, // Lock image width/height ratio as the original said | |
129 | 135 | |
130 | - 'zoom' => FALSE, // Lock image width/height ratio | |
131 | - '_%' => 0, // percentage | |
132 | - | |
136 | + // Flags and values | |
137 | + '_align' => PLUGIN_REF_DEFAULT_ALIGN, | |
133 | 138 | '_size' => FALSE, // Image size specified |
134 | - '_w' => 0, // width | |
135 | - '_h' => 0, // height | |
136 | - | |
137 | - '_title' => '', | |
138 | - '_error' => '' | |
139 | + '_w' => 0, // Width | |
140 | + '_h' => 0, // Height | |
141 | + '_%' => 0, // Percentage | |
142 | + //'_title' => '', // Reserved | |
143 | + //'_body => '', // Reserved | |
144 | + //'_error' => '' // Reserved | |
139 | 145 | ); |
140 | 146 | |
141 | 147 | // [Page_name/maybe-separated-with/slashes/]AttachedFileName.sfx or URI |
@@ -208,7 +214,7 @@ function plugin_ref_body($args) | ||
208 | 214 | |
209 | 215 | ref_check_args($args, $params); |
210 | 216 | |
211 | - $seems_image = (! $params['noimg'] && preg_match(PLUGIN_REF_IMAGE, $name)); | |
217 | + $seems_image = (! isset($params['noimg']) && preg_match(PLUGIN_REF_IMAGE, $name)); | |
212 | 218 | |
213 | 219 | $width = $height = 0; |
214 | 220 | $url = $url2 = ''; |
@@ -258,11 +264,12 @@ function plugin_ref_body($args) | ||
258 | 264 | } |
259 | 265 | |
260 | 266 | $s_url = htmlsc($url); |
261 | - $s_title = htmlsc($params['_title']); | |
267 | + $s_title = isset($params['_title']) ? htmlsc($params['_title']) : ''; | |
262 | 268 | $s_info = ''; |
263 | 269 | if ($seems_image) { |
264 | 270 | $s_title = make_line_rules($s_title); |
265 | - if (ref_check_size($width, $height, $params)) { | |
271 | + if (ref_check_size($width, $height, $params) && | |
272 | + isset($params['_w']) && isset($params['_h'])) { | |
266 | 273 | $s_info = 'width="' . htmlsc($params['_w']) . |
267 | 274 | '" height="' . htmlsc($params['_h']) . '" '; |
268 | 275 | } |
@@ -270,7 +277,7 @@ function plugin_ref_body($args) | ||
270 | 277 | 'alt="' . $s_title . '" ' . |
271 | 278 | 'title="' . $s_title . '" ' . |
272 | 279 | $s_info . '/>'; |
273 | - if (! $params['nolink'] && $url2) { | |
280 | + if (! isset($params['nolink']) && $url2) { | |
274 | 281 | $params['_body'] = |
275 | 282 | '<a href="' . htmlsc($url2) . '" title="' . $s_title . '">' . "\n" . |
276 | 283 | $body . "\n" . '</a>'; |
@@ -282,7 +289,7 @@ function plugin_ref_body($args) | ||
282 | 289 | $s_info = htmlsc(get_date('Y/m/d H:i:s', filemtime($file) - LOCALZONE) . |
283 | 290 | ' ' . sprintf('%01.1f', round(filesize($file) / 1024, 1)) . 'KB'); |
284 | 291 | } |
285 | - $icon = $params['noicon'] ? '' : FILE_ICON; | |
292 | + $icon = isset($params['noicon']) ? '' : FILE_ICON; | |
286 | 293 | $params['_body'] = '<a href="' . $s_url . '" title="' . $s_info . '">' . |
287 | 294 | $icon . $s_title . '</a>'; |
288 | 295 | } |
@@ -325,12 +332,16 @@ function ref_check_args($args, & $params) | ||
325 | 332 | } |
326 | 333 | } |
327 | 334 | unset($_args); |
328 | - | |
329 | 335 | $params['_title'] = join(',', $_title); |
330 | 336 | unset($_title); |
337 | + foreach(array_keys($params) as $key) { | |
338 | + if (! preg_match('/^_/', $key) && empty($params[$key])) { | |
339 | + unset($params[$key]); | |
340 | + } | |
341 | + } | |
331 | 342 | |
332 | 343 | foreach (array('right', 'left', 'center') as $align) { |
333 | - if (isset($params[$align]) && $params[$align]) { | |
344 | + if (isset($params[$align])) { | |
334 | 345 | $params['_align'] = $align; |
335 | 346 | unset($params[$align]); |
336 | 347 | break; |
@@ -347,11 +358,11 @@ function ref_check_size($width = 0, $height = 0, & $params) | ||
347 | 358 | $_width = isset($params['_w']) ? intval($params['_w']) : 0; |
348 | 359 | $_height = isset($params['_h']) ? intval($params['_h']) : 0; |
349 | 360 | |
350 | - if (isset($params['_size']) && $params['_size']) { | |
361 | + if (isset($params['_size'])) { | |
351 | 362 | if ($width == 0 && $height == 0) { |
352 | 363 | $width = $_width; |
353 | 364 | $height = $_height; |
354 | - } else if (isset($params['zoom']) && $params['zoom']) { | |
365 | + } else if (isset($params['zoom'])) { | |
355 | 366 | $_w = $_width ? $width / $_width : 0; |
356 | 367 | $_h = $_height ? $height / $_height : 0; |
357 | 368 | $zoom = max($_w, $_h); |
@@ -365,7 +376,7 @@ function ref_check_size($width = 0, $height = 0, & $params) | ||
365 | 376 | } |
366 | 377 | } |
367 | 378 | |
368 | - if (isset($params['_%']) && $params['_%']) { | |
379 | + if (isset($params['_%'])) { | |
369 | 380 | $width = $width * $params['_%'] / 100; |
370 | 381 | $height = $height * $params['_%'] / 100; |
371 | 382 | } |