Revisão | f1bf06fc8d706e09c40d5d9f6f0189b7b03602dd (tree) |
---|---|
Hora | 2007-09-11 01:07:21 |
Autor | henoheno <henoheno> |
Commiter | henoheno |
Cleanup/Simplify/Todo
* $page => $base
* plugin_tracker_list_render(): Added some validations except $refer
* Tracker_list: Hidden column '_refer' seems to be the same ($this->base), and seems not used.
@@ -1,6 +1,6 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone |
3 | -// $Id: tracker.inc.php,v 1.49 2007/09/09 13:41:52 henoheno Exp $ | |
3 | +// $Id: tracker.inc.php,v 1.50 2007/09/10 16:07:21 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 | // |
@@ -241,21 +241,20 @@ function plugin_tracker_get_fields($base, $refer, & $config) | ||
241 | 241 | } |
242 | 242 | |
243 | 243 | // Field classes |
244 | -// TODO: Not to use static variables (except $id) | |
245 | 244 | class Tracker_field |
246 | 245 | { |
247 | 246 | var $name; |
248 | 247 | var $title; |
249 | 248 | var $values; |
250 | 249 | var $default_value; |
251 | - var $page; | |
250 | + var $base; | |
252 | 251 | var $refer; |
253 | 252 | var $config; |
254 | 253 | var $data; |
255 | 254 | var $sort_type = SORT_REGULAR; |
256 | 255 | var $id = 0; |
257 | 256 | |
258 | - function Tracker_field($field, $page, $refer, & $config) | |
257 | + function Tracker_field($field, $base, $refer, & $config) | |
259 | 258 | { |
260 | 259 | global $post; |
261 | 260 | static $id = 0; // Unique id per instance |
@@ -265,7 +264,7 @@ class Tracker_field | ||
265 | 264 | $this->title = $field[1]; |
266 | 265 | $this->values = explode(',', $field[3]); |
267 | 266 | $this->default_value = $field[4]; |
268 | - $this->page = $page; | |
267 | + $this->base = $base; | |
269 | 268 | $this->refer = $refer; |
270 | 269 | $this->config = & $config; |
271 | 270 | $this->data = isset($post[$this->name]) ? $post[$this->name] : ''; |
@@ -370,9 +369,9 @@ class Tracker_field_format extends Tracker_field | ||
370 | 369 | var $styles = array(); |
371 | 370 | var $formats = array(); |
372 | 371 | |
373 | - function Tracker_field_format($field, $page, $refer, & $config) | |
372 | + function Tracker_field_format($field, $base, $refer, & $config) | |
374 | 373 | { |
375 | - parent::Tracker_field($field, $page, $refer, $config); | |
374 | + parent::Tracker_field($field, $base, $refer, $config); | |
376 | 375 | |
377 | 376 | foreach ($this->config->get($this->name) as $option) { |
378 | 377 | list($key, $style, $format) = |
@@ -428,10 +427,10 @@ class Tracker_field_file extends Tracker_field_format | ||
428 | 427 | |
429 | 428 | require_once(PLUGIN_DIR . 'attach.inc.php'); |
430 | 429 | |
431 | - $result = attach_upload($_FILES[$this->name], $this->page); | |
432 | - if ($result['result']) { | |
430 | + $result = attach_upload($_FILES[$this->name], $this->base); | |
431 | + if (isset($result['result']) && $result['result']) { | |
433 | 432 | // Upload success |
434 | - return parent::format_value($this->page . '/' . $_FILES[$this->name]['name']); | |
433 | + return parent::format_value($this->base . '/' . $_FILES[$this->name]['name']); | |
435 | 434 | } |
436 | 435 | } |
437 | 436 |
@@ -565,15 +564,15 @@ class Tracker_field_submit extends Tracker_field | ||
565 | 564 | function get_tag() |
566 | 565 | { |
567 | 566 | $s_title = htmlspecialchars($this->title); |
568 | - $s_page = htmlspecialchars($this->page); | |
567 | + $s_base = htmlspecialchars($this->base); | |
569 | 568 | $s_refer = htmlspecialchars($this->refer); |
570 | 569 | $s_config = htmlspecialchars($this->config->config_name); |
571 | 570 | |
572 | 571 | return <<<EOD |
573 | 572 | <input type="submit" value="$s_title" /> |
574 | -<input type="hidden" name="plugin" value="tracker" /> | |
575 | -<input type="hidden" name="_refer" value="$s_refer" /> | |
576 | -<input type="hidden" name="_base" value="$s_page" /> | |
573 | +<input type="hidden" name="plugin" value="tracker" /> | |
574 | +<input type="hidden" name="_refer" value="$s_refer" /> | |
575 | +<input type="hidden" name="_base" value="$s_base" /> | |
577 | 576 | <input type="hidden" name="_config" value="$s_config" /> |
578 | 577 | EOD; |
579 | 578 | } |
@@ -612,7 +611,7 @@ function plugin_tracker_list_convert() | ||
612 | 611 | global $vars; |
613 | 612 | |
614 | 613 | $config = PLUGIN_TRACKER_DEFAULT_CONFIG; |
615 | - $page = $refer = isset($vars['page']) ? $vars['page'] : ''; | |
614 | + $base = $refer = isset($vars['page']) ? $vars['page'] : ''; | |
616 | 615 | $order = ''; |
617 | 616 | $list = 'list'; |
618 | 617 | $limit = 0; |
@@ -621,42 +620,57 @@ function plugin_tracker_list_convert() | ||
621 | 620 | if (func_num_args()) { |
622 | 621 | $args = func_get_args(); |
623 | 622 | switch (count($args)) { |
624 | - case 4: | |
625 | - if (! is_numeric($args[3])) return PLUGIN_TRACKER_LIST_USAGE . '<br />'; | |
626 | - $limit = intval($args[3]); | |
627 | - case 3: | |
628 | - $order = $args[2]; | |
629 | - case 2: | |
630 | - $arg = get_fullname($args[1], $page); | |
631 | - if (is_pagename($arg)) $page = $arg; | |
623 | + case 4: $limit = $args[3]; /*FALLTHROUGH*/ | |
624 | + case 3: $order = $args[2]; /*FALLTHROUGH*/ | |
625 | + case 2: /*FALLTHROUGH*/ | |
626 | + $arg = get_fullname($args[1], $base); | |
627 | + if (is_pagename($arg)) $base = $arg; | |
632 | 628 | case 1: |
633 | 629 | if ($args[0] != '') $config = $args[0]; |
634 | 630 | list($config, $list) = array_pad(explode('/', $config, 2), 2, $list); |
635 | 631 | } |
636 | 632 | } |
637 | - return plugin_tracker_list_render($page, $refer, $config, $list, $order, $limit); | |
633 | + | |
634 | + return plugin_tracker_list_render($base, $refer, $config, $list, $order, $limit); | |
638 | 635 | } |
639 | 636 | |
640 | 637 | function plugin_tracker_list_action() |
641 | 638 | { |
642 | 639 | global $vars; |
643 | 640 | |
644 | - $page = $refer = isset($vars['refer']) ? $vars['refer'] : ''; | |
641 | + $base = isset($vars['base']) ? $vars['base'] : ''; | |
645 | 642 | $config = isset($vars['config']) ? $vars['config'] : ''; |
646 | 643 | $list = isset($vars['list']) ? $vars['list'] : 'list'; |
647 | 644 | $order = isset($vars['order']) ? $vars['order'] : '_real:SORT_DESC'; |
648 | - $limit = isset($vars['limit']) ? intval($vars['limit']) : 0; | |
645 | + $limit = isset($vars['limit']) ? $vars['limit'] : 0; | |
649 | 646 | |
650 | - $s_page = make_pagelink($page); | |
647 | + $s_base = make_pagelink(trim($base)); | |
651 | 648 | return array( |
652 | 649 | 'msg' => plugin_tracker_message('msg_list'), |
653 | - 'body'=> str_replace('$1', $s_page, plugin_tracker_message('msg_back')) . | |
654 | - plugin_tracker_list_render($page, $refer, $config, $list, $order, $limit) | |
650 | + 'body'=> str_replace('$1', $s_base, plugin_tracker_message('msg_back')) . | |
651 | + plugin_tracker_list_render($base, $base, $config, $list, $order, $limit) | |
655 | 652 | ); |
656 | 653 | } |
657 | 654 | |
658 | -function plugin_tracker_list_render($page, $refer, $config_name, $list, $order_commands = '', $limit = 0) | |
655 | +function plugin_tracker_list_render($base, $refer, $config_name, $list, $order_commands = '', $limit = 0) | |
659 | 656 | { |
657 | + $base = trim($base); | |
658 | + $refer = trim($refer); | |
659 | + $list = trim($list); | |
660 | + $config_name = trim($config_name); | |
661 | + $order_commands = trim($order_commands); | |
662 | + | |
663 | + if ($base == '') { | |
664 | + return '#tracker_list: Base not specified' . '<br />'; | |
665 | + } | |
666 | + if (! is_numeric($limit)) { | |
667 | + return PLUGIN_TRACKER_LIST_USAGE . '<br />'; | |
668 | + } | |
669 | + $limit = intval($limit); | |
670 | + | |
671 | + if ($config_name == '') { | |
672 | + return '#tracker_list: Config not specified<br />'; | |
673 | + } | |
660 | 674 | $config = new Config('plugin/tracker/' . $config_name); |
661 | 675 | if (! $config->read()) { |
662 | 676 | return '#tracker_list: Config \'' . htmlspecialchars($config_name) . '\' not found<br />'; |
@@ -666,21 +680,20 @@ function plugin_tracker_list_render($page, $refer, $config_name, $list, $order_c | ||
666 | 680 | return '#tracker_list: List \'' . make_pagelink($config->page . '/' . $list) . '\' not found<br />'; |
667 | 681 | } |
668 | 682 | |
669 | - $list = & new Tracker_list($page, $refer, $config, $list); | |
683 | + $list = & new Tracker_list($base, $refer, $config, $list); | |
670 | 684 | $list->sort($order_commands); |
671 | 685 | $result = $list->toString($limit); |
672 | 686 | if ($result == FALSE) { |
673 | - $result = '#tracker_list: Pages under \'' . htmlspecialchars($page) . '/\' not found' . '<br />'; | |
687 | + $result = '#tracker_list: Pages under \'' . htmlspecialchars($base) . '/\' not found' . '<br />'; | |
674 | 688 | } |
675 | 689 | |
676 | 690 | return $result; |
677 | 691 | } |
678 | 692 | |
679 | 693 | // Listing class |
680 | -// TODO: Not to use static variable | |
681 | 694 | class Tracker_list |
682 | 695 | { |
683 | - var $page; | |
696 | + var $base; | |
684 | 697 | var $config; |
685 | 698 | var $list; |
686 | 699 | var $fields; |
@@ -691,13 +704,14 @@ class Tracker_list | ||
691 | 704 | var $order = array(); |
692 | 705 | var $_added = array(); |
693 | 706 | |
694 | - function Tracker_list($page, $refer, & $config, $list) | |
707 | + // TODO: Why list here | |
708 | + function Tracker_list($base, $refer, & $config, $list) | |
695 | 709 | { |
696 | - $this->page = $page; | |
710 | + $this->base = $base; | |
697 | 711 | $this->config = & $config; |
698 | 712 | $this->list = $list; |
699 | 713 | |
700 | - $fields = plugin_tracker_get_fields($page, $refer, $config); | |
714 | + $fields = plugin_tracker_get_fields($base, $refer, $config); | |
701 | 715 | $pattern = array(); |
702 | 716 | $pattern_fields = array(); |
703 | 717 |
@@ -730,7 +744,7 @@ class Tracker_list | ||
730 | 744 | $this->pattern_fields = $pattern_fields; |
731 | 745 | |
732 | 746 | // Listing |
733 | - $pattern = $page . '/'; | |
747 | + $pattern = $base . '/'; | |
734 | 748 | $pattern_len = strlen($pattern); |
735 | 749 | foreach (get_existpages() as $_page) { |
736 | 750 | if (strpos($_page, $pattern) === 0) { |
@@ -766,7 +780,6 @@ class Tracker_list | ||
766 | 780 | $row = array( |
767 | 781 | // column => default data of the cell |
768 | 782 | '_page' => '[[' . $page . ']]', |
769 | - '_refer' => $this->page, | |
770 | 783 | '_real' => $name, |
771 | 784 | '_update' => $filetime, |
772 | 785 | '_past' => $filetime, |
@@ -813,13 +826,13 @@ class Tracker_list | ||
813 | 826 | switch (strtoupper(trim($order))) { |
814 | 827 | case '': |
815 | 828 | break; |
816 | - case SORT_ASC: | |
817 | - case 'SORT_ASC': | |
829 | + case SORT_ASC: /*FALLTHROUGH*/ | |
830 | + case 'SORT_ASC': /*FALLTHROUGH*/ | |
818 | 831 | case 'ASC': |
819 | 832 | $orders[$fieldname] = SORT_ASC; |
820 | 833 | break; |
821 | - case SORT_DESC: | |
822 | - case 'SORT_DESC': | |
834 | + case SORT_DESC: /*FALLTHROUGH*/ | |
835 | + case 'SORT_DESC': /*FALLTHROUGH*/ | |
823 | 836 | case 'DESC': |
824 | 837 | $orders[$fieldname] = SORT_DESC; |
825 | 838 | break; |
@@ -899,7 +912,7 @@ class Tracker_list | ||
899 | 912 | unset($order[$sort], $order_keys); |
900 | 913 | } |
901 | 914 | $title = $this->fields[$field]->title; |
902 | - $r_page = rawurlencode($this->page); | |
915 | + $r_base = rawurlencode($this->base); | |
903 | 916 | $r_config = rawurlencode($this->config->config_name); |
904 | 917 | $r_list = rawurlencode($this->list); |
905 | 918 | $_order = array($sort . ':' . $dir); |
@@ -912,7 +925,7 @@ class Tracker_list | ||
912 | 925 | |
913 | 926 | $script = get_script_uri(); |
914 | 927 | return '[[' . $title . $arrow . '>' . |
915 | - $script . '?plugin=tracker_list&refer=' . $r_page . | |
928 | + $script . '?plugin=tracker_list&base=' . $r_base . | |
916 | 929 | '&config=' . $r_config . |
917 | 930 | '&list=' . $r_list . '&order=' . $r_order . ']]'; |
918 | 931 | } |
@@ -946,7 +959,7 @@ class Tracker_list | ||
946 | 959 | ) . "\n"; |
947 | 960 | } |
948 | 961 | |
949 | - $body = array(); | |
962 | + $body = array(); | |
950 | 963 | foreach (plugin_tracker_get_source($this->config->page . '/' . $this->list) as $line) { |
951 | 964 | if (preg_match('/^\|(.+)\|[hfc]$/i', $line)) { |
952 | 965 | // Table decolations |