Revisão | a8119b2c38ae6b14d16581f0cf457e52b3f0047b (tree) |
---|---|
Hora | 2007-09-06 00:14:44 |
Autor | henoheno <henoheno> |
Commiter | henoheno |
BugTrack2/243: Cleanup/Simplify/Todo
@@ -1,6 +1,6 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone |
3 | -// $Id: tracker.inc.php,v 1.42 2007/09/04 14:09:43 henoheno Exp $ | |
3 | +// $Id: tracker.inc.php,v 1.43 2007/09/05 15:14:44 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 | // |
@@ -43,8 +43,8 @@ function plugin_tracker_convert() | ||
43 | 43 | if ($argc > 0 && $args[0] != '') { |
44 | 44 | // Configuration name AND form name |
45 | 45 | $arg = explode('/', $args[0], 2); |
46 | - $config_name = ($arg[0] != '') ? $arg[0] : PLUGIN_TRACKER_DEFAULT_CONFIG; | |
47 | - $form = (count($arg) > 1) ? $arg[1] : PLUGIN_TRACKER_DEFAULT_FORM; | |
46 | + if ($arg[0] != '' ) $config_name = $arg[0]; | |
47 | + if (isset($arg[1])) $form = $arg[1]; | |
48 | 48 | } |
49 | 49 | } |
50 | 50 |
@@ -95,16 +95,16 @@ function plugin_tracker_action() | ||
95 | 95 | $refer = isset($post['_refer']) ? $post['_refer'] : $base; |
96 | 96 | if (! is_pagename($refer)) { |
97 | 97 | return array( |
98 | - 'msg' => 'cannot write', | |
99 | - 'body' => 'page name (' . htmlspecialchars($refer) . ') is not valid.' | |
98 | + 'msg' => 'Cannot write', | |
99 | + 'body' => 'Page name (' . htmlspecialchars($refer) . ') invalid' | |
100 | 100 | ); |
101 | 101 | } |
102 | 102 | |
103 | 103 | // $page name to add will be decided here |
104 | - $name = isset($post['_name']) ? $post['_name'] : ''; | |
105 | 104 | $num = 0; |
105 | + $name = isset($post['_name']) ? $post['_name'] : ''; | |
106 | 106 | if (isset($post['_page'])) { |
107 | - $page = $real = $post['_page']; | |
107 | + $real = $page = $post['_page']; | |
108 | 108 | } else { |
109 | 109 | $real = is_pagename($name) ? $name : ++$num; |
110 | 110 | $page = get_fullname('./' . $real, $base); |
@@ -125,8 +125,8 @@ function plugin_tracker_action() | ||
125 | 125 | $template_page = $config->page . '/page'; |
126 | 126 | if (! is_page($template_page)) { |
127 | 127 | return array( |
128 | - 'msg' => 'cannot write', | |
129 | - 'body' => 'page template (' . htmlspecialchars($template_page) . ') is not exist.' | |
128 | + 'msg' => 'Cannot write', | |
129 | + 'body' => 'Page template (' . htmlspecialchars($template_page) . ') not exists' | |
130 | 130 | ); |
131 | 131 | } |
132 | 132 |
@@ -472,7 +472,12 @@ class Tracker_field_radio extends Tracker_field_format | ||
472 | 472 | { |
473 | 473 | static $options = array(); |
474 | 474 | if (! isset($options[$this->name])) { |
475 | - $options[$this->name] = array_flip(array_map(create_function('$arr', 'return $arr[0];'), $this->config->get($this->name))); | |
475 | + $options[$this->name] = | |
476 | + array_flip( | |
477 | + array_map(create_function('$arr', 'return $arr[0];'), | |
478 | + $this->config->get($this->name) | |
479 | + ) | |
480 | + ); | |
476 | 481 | } |
477 | 482 | return isset($options[$this->name][$value]) ? $options[$this->name][$value] : $value; |
478 | 483 | } |
@@ -595,17 +600,20 @@ class Tracker_field_past extends Tracker_field | ||
595 | 600 | } |
596 | 601 | |
597 | 602 | /////////////////////////////////////////////////////////////////////////// |
603 | +// tracker_list plugin | |
598 | 604 | |
599 | 605 | function plugin_tracker_list_convert() |
600 | 606 | { |
601 | 607 | global $vars; |
602 | 608 | |
603 | 609 | $config = PLUGIN_TRACKER_DEFAULT_CONFIG; |
604 | - $page = $refer = $vars['page']; | |
610 | + $page = $refer = isset($vars['page']) ? $vars['page'] : ''; | |
605 | 611 | $field = '_page'; |
606 | 612 | $order = ''; |
607 | 613 | $list = 'list'; |
608 | 614 | $limit = NULL; |
615 | + | |
616 | + // TODO: SHOW USAGE OR ERROR CLEARLY | |
609 | 617 | if (func_num_args()) { |
610 | 618 | $args = func_get_args(); |
611 | 619 | switch (count($args)) { |
@@ -621,42 +629,39 @@ function plugin_tracker_list_convert() | ||
621 | 629 | list($config, $list) = array_pad(explode('/', $config, 2), 2, $list); |
622 | 630 | } |
623 | 631 | } |
624 | - return plugin_tracker_getlist($page, $refer, $config, $list, $order, $limit); | |
632 | + return plugin_tracker_list_render($page, $refer, $config, $list, $order, $limit); | |
625 | 633 | } |
626 | 634 | |
627 | 635 | function plugin_tracker_list_action() |
628 | 636 | { |
629 | 637 | global $script, $vars, $_tracker_messages; |
630 | 638 | |
631 | - $page = $refer = $vars['refer']; | |
632 | - $s_page = make_pagelink($page); | |
633 | - $config = $vars['config']; | |
634 | - $list = isset($vars['list']) ? $vars['list'] : 'list'; | |
635 | - $order = isset($vars['order']) ? $vars['order'] : '_real:SORT_DESC'; | |
639 | + $page = $refer = isset($vars['refer']) ? $vars['refer'] : ''; | |
640 | + $config = isset($vars['config']) ? $vars['config'] : ''; | |
641 | + $list = isset($vars['list']) ? $vars['list'] : 'list'; | |
642 | + $order = isset($vars['order']) ? $vars['order'] : '_real:SORT_DESC'; | |
636 | 643 | |
644 | + $s_page = make_pagelink($page); | |
637 | 645 | return array( |
638 | 646 | 'msg' => $_tracker_messages['msg_list'], |
639 | - 'body'=> str_replace('$1', $s_page, $_tracker_messages['msg_back']). | |
640 | - plugin_tracker_getlist($page, $refer, $config, $list, $order) | |
647 | + 'body'=> str_replace('$1', $s_page, $_tracker_messages['msg_back']) . | |
648 | + plugin_tracker_list_render($page, $refer, $config, $list, $order) | |
641 | 649 | ); |
642 | 650 | } |
643 | 651 | |
644 | -function plugin_tracker_getlist($page, $refer, $config_name, $list, $order = '', $limit = NULL) | |
652 | +function plugin_tracker_list_render($page, $refer, $config_name, $list, $order_commands = '', $limit = NULL) | |
645 | 653 | { |
646 | 654 | $config = new Config('plugin/tracker/' . $config_name); |
647 | - | |
648 | 655 | if (! $config->read()) { |
649 | - return '<p>config file \'' . htmlspecialchars($config_name) . '\' is not exist.</p>'; | |
656 | + return '#tracker_list: Config \'' . htmlspecialchars($config_name) . '\' not found<br />'; | |
650 | 657 | } |
651 | - | |
652 | 658 | $config->config_name = $config_name; |
653 | - | |
654 | 659 | if (! is_page($config->page . '/' . $list)) { |
655 | - return '<p>config file \'' . make_pagelink($config->page . '/' . $list) . '\' not found.</p>'; | |
660 | + return '#tracker_list: List \'' . make_pagelink($config->page . '/' . $list) . '\' not found<br />'; | |
656 | 661 | } |
657 | 662 | |
658 | 663 | $list = & new Tracker_list($page, $refer, $config, $list); |
659 | - $list->sort($order); | |
664 | + $list->sort($order_commands); | |
660 | 665 | return $list->toString($limit); |
661 | 666 | } |
662 | 667 |
@@ -684,6 +689,7 @@ class Tracker_list | ||
684 | 689 | $this->order = array(); |
685 | 690 | |
686 | 691 | $pattern = plugin_tracker_get_source($config->page . '/page', TRUE); |
692 | + // TODO: if (is FALSE) OR file_exists() | |
687 | 693 | |
688 | 694 | // Convert block-plugins to fields |
689 | 695 | // Incleasing and decreasing around #comment etc, will be covererd with [_block_xxx] |
@@ -757,50 +763,66 @@ class Tracker_list | ||
757 | 763 | } |
758 | 764 | } |
759 | 765 | |
760 | - function sort($order) | |
766 | + // Sort $this->rows with $order_commands | |
767 | + function sort($order_commands = '') | |
761 | 768 | { |
762 | - if ($order == '') return; | |
769 | + if ($order_commands == '') { | |
770 | + $this->order = array(); | |
771 | + return TRUE; | |
772 | + } | |
763 | 773 | |
764 | - $names = array_flip(array_keys($this->fields)); | |
765 | - $this->order = array(); | |
774 | + $orders = array(); | |
775 | + $params = array(); // Arguments for array_multisort() | |
776 | + $names = array_flip(array_keys($this->fields)); | |
766 | 777 | |
767 | - foreach (explode(';', $order) as $item) { | |
768 | - list($key, $dir) = array_pad(explode(':', $item), 1, 'ASC'); | |
769 | - if (! isset($names[$key])) continue; | |
778 | + foreach (explode(';', $order_commands) as $command) { | |
779 | + // TODO: ??? | |
780 | + list($fieldname, $order) = array_pad(explode(':', $command), 1, 'SORT_ASC'); | |
781 | + $fieldname = trim($fieldname); | |
770 | 782 | |
771 | - switch (strtoupper($dir)) { | |
783 | + if (! isset($names[$fieldname])) { | |
784 | + // TODO: SHOW INVALID FIELDNAME CLEARLY | |
785 | + return FALSE; | |
786 | + } | |
787 | + | |
788 | + // TODO: SHOULD NOT TO USE DEFINES AT THIS string WORLD | |
789 | + switch (strtoupper(trim($order))) { | |
790 | + case SORT_ASC: | |
772 | 791 | case 'SORT_ASC': |
773 | 792 | case 'ASC': |
774 | - case SORT_ASC: | |
775 | - $dir = SORT_ASC; | |
793 | + $order = SORT_ASC; | |
776 | 794 | break; |
795 | + case SORT_DESC: | |
777 | 796 | case 'SORT_DESC': |
778 | 797 | case 'DESC': |
779 | - case SORT_DESC: | |
780 | - $dir = SORT_DESC; | |
798 | + $order = SORT_DESC; | |
781 | 799 | break; |
782 | 800 | default: |
783 | 801 | continue; |
784 | 802 | } |
785 | - $this->order[$key] = $dir; | |
803 | + | |
804 | + $orders[$fieldname] = $order; | |
786 | 805 | } |
787 | - $keys = array(); | |
788 | - $params = array(); | |
789 | - foreach ($this->order as $field => $order) { | |
790 | - if (! isset($names[$field])) continue; | |
806 | + // TODO: LIMIT (count($order) < N < count(fields)) TO LIMIT array_multisort() | |
791 | 807 | |
808 | + foreach ($orders as $fieldname => $order) { | |
809 | + // One column set (one-dimensional array(), sort type, and order-by) | |
810 | + $array = array(); | |
792 | 811 | foreach ($this->rows as $row) { |
793 | - $keys[$field][] = isset($row[$field])? | |
794 | - $this->fields[$field]->get_value($row[$field]) : | |
812 | + $array[] = isset($row[$fieldname]) ? | |
813 | + $this->fields[$fieldname]->get_value($row[$fieldname]) : | |
795 | 814 | ''; |
796 | 815 | } |
797 | - $params[] = $keys[$field]; | |
798 | - $params[] = $this->fields[$field]->sort_type; | |
816 | + $params[] = $array; | |
817 | + $params[] = $this->fields[$fieldname]->sort_type; | |
799 | 818 | $params[] = $order; |
800 | 819 | } |
801 | 820 | $params[] = & $this->rows; |
802 | 821 | |
803 | 822 | call_user_func_array('array_multisort', $params); |
823 | + $this->order = $orders; | |
824 | + | |
825 | + return TRUE; | |
804 | 826 | } |
805 | 827 | |
806 | 828 | // Used with preg_replace_callback() at toString() |