修訂 | 9419fe8e5837c31e1ef58cd08b4a8fd2297f4806 (tree) |
---|---|
時間 | 2007-09-09 09:57:57 |
作者 | henoheno <henoheno> |
Commiter | henoheno |
* BugTrack/779: Static variables within class methods cause side effect if the class is not singleton => private class variables
* Corrected $limit default bug (1 => 0(unlimited))
* tracker_list_action(): enable $limit
@@ -1,6 +1,6 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone |
3 | -// $Id: tracker.inc.php,v 1.46 2007-09-08 16:37:16 henoheno Exp $ | |
3 | +// $Id: tracker.inc.php,v 1.47 2007-09-09 00:57:57 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 | // |
@@ -70,7 +70,6 @@ function plugin_tracker_convert() | ||
70 | 70 | } else { |
71 | 71 | $to[] = $_to; |
72 | 72 | } |
73 | - $fields[$field]->dispose(); | |
74 | 73 | unset($fields[$field]); |
75 | 74 | } |
76 | 75 |
@@ -149,7 +148,6 @@ function plugin_tracker_action() | ||
149 | 148 | foreach (array_keys($fields) as $field) { |
150 | 149 | $from[] = '[' . $field . ']'; |
151 | 150 | $to[] = isset($_post[$field]) ? $fields[$field]->format_value($_post[$field]) : ''; |
152 | - $fields[$field]->dispose(); | |
153 | 151 | unset($fields[$field]); |
154 | 152 | } |
155 | 153 |
@@ -299,11 +297,6 @@ class Tracker_field | ||
299 | 297 | { |
300 | 298 | return $value; // Default: $value itself |
301 | 299 | } |
302 | - | |
303 | - // Release the resources | |
304 | - function dispose() | |
305 | - { | |
306 | - } | |
307 | 300 | } |
308 | 301 | |
309 | 302 | class Tracker_field_text extends Tracker_field |
@@ -450,6 +443,7 @@ class Tracker_field_file extends Tracker_field_format | ||
450 | 443 | class Tracker_field_radio extends Tracker_field_format |
451 | 444 | { |
452 | 445 | var $sort_type = SORT_NUMERIC; |
446 | + var $_options = array(); | |
453 | 447 | |
454 | 448 | function get_tag() |
455 | 449 | { |
@@ -481,29 +475,18 @@ class Tracker_field_radio extends Tracker_field_format | ||
481 | 475 | |
482 | 476 | function get_value($value) |
483 | 477 | { |
484 | - static $options = array(); | |
485 | - | |
486 | - if ($value === NULL) { | |
487 | - $options = array(); | |
488 | - return NULL; | |
489 | - } | |
478 | + $options = & $this->_options; | |
479 | + $name = $this->name; | |
490 | 480 | |
491 | - if (! isset($options[$this->name])) { | |
492 | - $options[$this->name] = array_flip( | |
493 | - array_map( | |
494 | - create_function('$arr', 'return $arr[0];'), | |
495 | - $this->config->get($this->name) | |
496 | - ) | |
481 | + if (! isset($options[$name])) { | |
482 | + $values = array_map( | |
483 | + create_function('$array', 'return $array[0];'), | |
484 | + $this->config->get($name) | |
497 | 485 | ); |
486 | + $options[$name] = array_flip($values); // array('value0' => 0, 'value1' => 1, ...) | |
498 | 487 | } |
499 | 488 | |
500 | - // Int or $value | |
501 | - return isset($options[$this->name][$value]) ? $options[$this->name][$value] : $value; | |
502 | - } | |
503 | - | |
504 | - function dispose() | |
505 | - { | |
506 | - $this->get_value(NULL); | |
489 | + return isset($options[$name][$value]) ? $options[$name][$value] : $value; | |
507 | 490 | } |
508 | 491 | } |
509 | 492 |
@@ -632,7 +615,7 @@ function plugin_tracker_list_convert() | ||
632 | 615 | $page = $refer = isset($vars['page']) ? $vars['page'] : ''; |
633 | 616 | $order = ''; |
634 | 617 | $list = 'list'; |
635 | - $limit = NULL; | |
618 | + $limit = 0; | |
636 | 619 | |
637 | 620 | // TODO: SHOW USAGE OR ERROR CLEARLY |
638 | 621 | if (func_num_args()) { |
@@ -662,16 +645,17 @@ function plugin_tracker_list_action() | ||
662 | 645 | $config = isset($vars['config']) ? $vars['config'] : ''; |
663 | 646 | $list = isset($vars['list']) ? $vars['list'] : 'list'; |
664 | 647 | $order = isset($vars['order']) ? $vars['order'] : '_real:SORT_DESC'; |
648 | + $limit = isset($vars['limit']) ? intval($vars['limit']) : 0; | |
665 | 649 | |
666 | 650 | $s_page = make_pagelink($page); |
667 | 651 | return array( |
668 | 652 | 'msg' => plugin_tracker_message('msg_list'), |
669 | 653 | 'body'=> str_replace('$1', $s_page, plugin_tracker_message('msg_back')) . |
670 | - plugin_tracker_list_render($page, $refer, $config, $list, $order) | |
654 | + plugin_tracker_list_render($page, $refer, $config, $list, $order, $limit) | |
671 | 655 | ); |
672 | 656 | } |
673 | 657 | |
674 | -function plugin_tracker_list_render($page, $refer, $config_name, $list, $order_commands = '', $limit = NULL) | |
658 | +function plugin_tracker_list_render($page, $refer, $config_name, $list, $order_commands = '', $limit = 0) | |
675 | 659 | { |
676 | 660 | $config = new Config('plugin/tracker/' . $config_name); |
677 | 661 | if (! $config->read()) { |
@@ -688,7 +672,6 @@ function plugin_tracker_list_render($page, $refer, $config_name, $list, $order_c | ||
688 | 672 | if ($result == FALSE) { |
689 | 673 | $result = '#tracker_list: Pages under \'' . htmlspecialchars($page) . '/\' not found' . '<br />'; |
690 | 674 | } |
691 | - $list->dispose(); | |
692 | 675 | |
693 | 676 | return $result; |
694 | 677 | } |
@@ -705,6 +688,7 @@ class Tracker_list | ||
705 | 688 | var $pattern_fields; |
706 | 689 | var $rows; |
707 | 690 | var $order; |
691 | + var $_added; | |
708 | 692 | |
709 | 693 | function Tracker_list($page, $refer, & $config, $list) |
710 | 694 | { |
@@ -716,6 +700,7 @@ class Tracker_list | ||
716 | 700 | $this->pattern_fields = array(); |
717 | 701 | $this->rows = array(); |
718 | 702 | $this->order = array(); |
703 | + $this->_added = array(); | |
719 | 704 | |
720 | 705 | $pattern = plugin_tracker_get_source($config->page . '/page', TRUE); |
721 | 706 | // TODO: if (is FALSE) OR file_exists() |
@@ -749,16 +734,10 @@ class Tracker_list | ||
749 | 734 | |
750 | 735 | function add($page, $name) |
751 | 736 | { |
752 | - static $done = array(); | |
753 | - | |
754 | - if (isset($done[$page])) return; | |
755 | 737 | |
756 | - if ($page === NULL) { | |
757 | - $done = array(); | |
758 | - return; | |
759 | - } | |
738 | + if (isset($this->_added[$page])) return; | |
760 | 739 | |
761 | - $done[$page] = TRUE; | |
740 | + $this->_added[$page] = TRUE; | |
762 | 741 | |
763 | 742 | $source = plugin_tracker_get_source($page); |
764 | 743 |
@@ -929,18 +908,22 @@ class Tracker_list | ||
929 | 908 | '&list=' . $r_list . '&order=' . $r_order . ']]'; |
930 | 909 | } |
931 | 910 | |
932 | - function toString($limit = 10) | |
911 | + function toString($limit = 0) | |
933 | 912 | { |
934 | 913 | if (empty($this->rows)) return FALSE; |
935 | 914 | |
936 | - $limit = max(1, intval($limit)); | |
937 | - | |
938 | 915 | $count = $_count = count($this->rows); |
939 | - if ($limit != 0 && $count > $limit) { | |
940 | - $rows = array_slice($this->rows, 0, $limit); | |
941 | - $_count = count($rows); | |
916 | + | |
917 | + if ($limit != 0) { | |
918 | + $limit = max(1, intval($limit)); | |
919 | + if ($count > $limit) { | |
920 | + $rows = array_slice($this->rows, 0, $limit); | |
921 | + $_count = count($rows); | |
922 | + } else { | |
923 | + $rows = $this->rows; | |
924 | + } | |
942 | 925 | } else { |
943 | - $rows = $this->rows; | |
926 | + $rows = $this->rows; | |
944 | 927 | } |
945 | 928 | |
946 | 929 | $source = array(); |
@@ -979,12 +962,6 @@ class Tracker_list | ||
979 | 962 | |
980 | 963 | return convert_html(implode('', $source)); |
981 | 964 | } |
982 | - | |
983 | - function dispose() | |
984 | - { | |
985 | - $this->add(NULL, NULL); | |
986 | - return; | |
987 | - } | |
988 | 965 | } |
989 | 966 | |
990 | 967 | function plugin_tracker_get_source($page, $join = FALSE) |