修訂 | 859194b577b129f55c5ece61e36a5c09579ac141 (tree) |
---|---|
時間 | 2007-10-13 01:00:27 |
作者 | henoheno <henoheno> |
Commiter | henoheno |
Simplify:
* Tracker_form: Sort functions as functional order
* Tracker_list: $this->list seems to be just one of private resources of toString(). Speaking words of wisdom: let it be.
@@ -1,6 +1,6 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone |
3 | -// $Id: tracker.inc.php,v 1.107 2007/10/08 14:44:56 henoheno Exp $ | |
3 | +// $Id: tracker.inc.php,v 1.108 2007/10/12 16:00:27 henoheno Exp $ | |
4 | 4 | // Copyright (C) 2003-2005, 2007 PukiWiki Developers Team |
5 | 5 | // License: GPL v2 or (at your option) any later version |
6 | 6 | // |
@@ -249,33 +249,8 @@ class Tracker_form | ||
249 | 249 | $this->config = & $config; |
250 | 250 | } |
251 | 251 | |
252 | - function addField($fieldname, $displayname, $type = 'text', $options = '20', $default = '') | |
253 | - { | |
254 | - if (isset($this->fields[$fieldname])) { | |
255 | - $this->error = "No such field: " . $fieldname; | |
256 | - return FALSE; | |
257 | - } | |
258 | - | |
259 | - $class = 'Tracker_field_' . $type; | |
260 | - if (! class_exists($class)) { | |
261 | - $this->error = "No such type: " . $type; | |
262 | - return FALSE; | |
263 | - } | |
264 | - | |
265 | - $this->fields[$fieldname] = & new $class( | |
266 | - $this, // Reference | |
267 | - array( | |
268 | - $fieldname, | |
269 | - $displayname, | |
270 | - NULL, // $type | |
271 | - $options, | |
272 | - $default | |
273 | - ) | |
274 | - ); | |
275 | - | |
276 | - return TRUE; | |
277 | - } | |
278 | - | |
252 | + // Init $this->raw_fields and $this->fields | |
253 | + // TODO: Using func_get_args() to shrink the code? | |
279 | 254 | function initFields($requests = NULL) |
280 | 255 | { |
281 | 256 | if (! isset($this->raw_fields)) { |
@@ -362,6 +337,35 @@ class Tracker_form | ||
362 | 337 | |
363 | 338 | $this->initFields($fields); |
364 | 339 | } |
340 | + | |
341 | + // Called from InitFields() | |
342 | + function addField($fieldname, $displayname, $type = 'text', $options = '20', $default = '') | |
343 | + { | |
344 | + // Not Init | |
345 | + if (isset($this->fields[$fieldname])) { | |
346 | + $this->error = "No such field: " . $fieldname; | |
347 | + return FALSE; | |
348 | + } | |
349 | + | |
350 | + $class = 'Tracker_field_' . $type; | |
351 | + if (! class_exists($class)) { | |
352 | + $this->error = "No such type: " . $type; | |
353 | + return FALSE; | |
354 | + } | |
355 | + | |
356 | + $this->fields[$fieldname] = & new $class( | |
357 | + $this, // Reference | |
358 | + array( | |
359 | + $fieldname, | |
360 | + $displayname, | |
361 | + NULL, // $type | |
362 | + $options, | |
363 | + $default | |
364 | + ) | |
365 | + ); | |
366 | + | |
367 | + return TRUE; | |
368 | + } | |
365 | 369 | } |
366 | 370 | |
367 | 371 | // TODO: Why a filter sometimes created so many? |
@@ -870,15 +874,15 @@ function plugin_tracker_list_render($base, $refer, $config_name, $list, $order_c | ||
870 | 874 | return '#tracker_list: List not found: ' . make_pagelink($config->page . '/' . $list) . '<br />'; |
871 | 875 | } |
872 | 876 | |
873 | - $list = & new Tracker_list($base, $refer, $config, $list); | |
874 | - if ($list->setSortOrder($order_commands) === FALSE) { | |
877 | + $tracker_list = & new Tracker_list($base, $refer, $config); | |
878 | + if ($tracker_list->setSortOrder($order_commands) === FALSE) { | |
875 | 879 | return '#tracker_list: ' . htmlspecialchars($list->error) . '<br />'; |
876 | 880 | } |
877 | - $result = $list->toString($limit); | |
881 | + $result = $tracker_list->toString($list, $limit); | |
878 | 882 | if ($result === FALSE) { |
879 | 883 | return '#tracker_list: ' . htmlspecialchars($list->error) . '<br />'; |
880 | 884 | } |
881 | - unset($list); | |
885 | + unset($tracker_list); | |
882 | 886 | |
883 | 887 | return convert_html($result); |
884 | 888 | } |
@@ -888,29 +892,28 @@ class Tracker_list | ||
888 | 892 | { |
889 | 893 | var $form; // class Tracker_form |
890 | 894 | |
891 | - var $list; | |
892 | - | |
893 | - var $pattern; | |
894 | - var $pattern_fields; | |
895 | - | |
896 | 895 | var $rows = array(); |
897 | 896 | var $orders = array(); |
898 | 897 | var $error = ''; // Error message |
899 | 898 | |
899 | + // _generate_regex() | |
900 | + var $pattern; | |
901 | + var $pattern_fields; | |
902 | + | |
900 | 903 | // add() |
901 | 904 | var $_added = array(); |
902 | 905 | |
903 | 906 | // toString() |
907 | + var $_list; | |
904 | 908 | var $_row; |
905 | 909 | var $_the_first_character_of_the_line; |
906 | 910 | |
907 | - function Tracker_list($base, $refer, & $config, $list) | |
911 | + function Tracker_list($base, $refer, & $config) | |
908 | 912 | { |
909 | - $form = & new Tracker_form($base, $refer, $config); | |
910 | - $this->form = $form; | |
911 | - $this->list = $list; | |
913 | + $this->form = & new Tracker_form($base, $refer, $config); | |
912 | 914 | } |
913 | 915 | |
916 | + // Adding $this->rows | |
914 | 917 | // Add multiple pages at a time |
915 | 918 | function loadRows() |
916 | 919 | { |
@@ -918,7 +921,6 @@ class Tracker_list | ||
918 | 921 | $len = strlen($base); |
919 | 922 | $regex = '#^' . preg_quote($base, '#') . '#'; |
920 | 923 | |
921 | - // Adding $this->rows | |
922 | 924 | foreach (preg_grep($regex, array_values(get_existpages())) as $pagename) { |
923 | 925 | if (preg_match(PLUGIN_TRACKER_LIST_EXCLUDE_PATTERN, substr($pagename, $len))) { |
924 | 926 | continue; |
@@ -1195,8 +1197,8 @@ class Tracker_list | ||
1195 | 1197 | $fields = $form->fields; |
1196 | 1198 | $config_name = $form->config->config_name; |
1197 | 1199 | |
1198 | - $list = $this->list; | |
1199 | 1200 | $orders = $this->orders; |
1201 | + $list = $this->_list; | |
1200 | 1202 | |
1201 | 1203 | $fieldname = isset($matches[1]) ? $matches[1] : ''; |
1202 | 1204 | if (! isset($fields[$fieldname])) { |
@@ -1294,10 +1296,11 @@ class Tracker_list | ||
1294 | 1296 | } |
1295 | 1297 | |
1296 | 1298 | // Output a part of Wiki text |
1297 | - function toString($limit = 0) | |
1299 | + function toString($list, $limit = 0) | |
1298 | 1300 | { |
1299 | 1301 | $form = & $this->form; |
1300 | - $list = $form->config->page . '/' . $this->list; | |
1302 | + $list = $form->config->page . '/' . $list; | |
1303 | + | |
1301 | 1304 | $source = array(); |
1302 | 1305 | $regex = '/\[([^\[\]]+)\]/'; |
1303 | 1306 |
@@ -1308,22 +1311,26 @@ class Tracker_list | ||
1308 | 1311 | return FALSE; |
1309 | 1312 | } |
1310 | 1313 | |
1311 | - // Creating $form->fields just you need | |
1312 | - if ($form->initFields('_real') === FALSE || | |
1314 | + // Try to create $form->fields just you need | |
1315 | + if ($form->initFields('_real') === FALSE || | |
1313 | 1316 | $form->initFields(plugin_tracker_field_pickup($template)) === FALSE || |
1314 | 1317 | $form->initFields(array_keys($this->orders)) === FALSE) { |
1315 | 1318 | $this->error = $form->error; |
1316 | 1319 | return FALSE; |
1317 | 1320 | } |
1318 | 1321 | |
1322 | + // TODO: Check isset($this->rows) or something | |
1319 | 1323 | // Generate regex for $form->fields |
1320 | 1324 | if ($this->_generate_regex() === FALSE) return FALSE; |
1321 | 1325 | |
1326 | + // TODO: Check isset($this->rows) or something | |
1322 | 1327 | // Load and sort $this->rows |
1323 | 1328 | if ($this->loadRows() === FALSE || $this->sortRows() === FALSE) return FALSE; |
1324 | 1329 | $rows = $this->rows; |
1325 | 1330 | |
1331 | + | |
1326 | 1332 | // toString() |
1333 | + $this->_list = $list; // For _replace_title() only | |
1327 | 1334 | $count = count($this->rows); |
1328 | 1335 | $limit = intval($limit); |
1329 | 1336 | if ($limit != 0) $limit = max(1, $limit); |