Revisão | 862d2c905f0252cc24a66b6bdaf5aa78cb0dbafe (tree) |
---|---|
Hora | 2007-09-18 01:05:28 |
Autor | henoheno <henoheno> |
Commiter | henoheno |
KISS
* Do one thing best: Tracker_list::toString() now returns a wiki text, not a xhtml.
* Correct / Clear tracker_list not-sorting bug inserted these days.
@@ -1,6 +1,6 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone |
3 | -// $Id: tracker.inc.php,v 1.53 2007/09/16 04:06:39 henoheno Exp $ | |
3 | +// $Id: tracker.inc.php,v 1.54 2007/09/17 16:05:28 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 | // |
@@ -707,9 +707,9 @@ function plugin_tracker_list_render($base, $refer, $config_name, $list, $order_c | ||
707 | 707 | $result = $list->toString($limit); |
708 | 708 | if ($result === FALSE) { |
709 | 709 | return '#tracker_list: ' . htmlspecialchars($list->error) . '<br />'; |
710 | + } else { | |
711 | + return convert_html($result); | |
710 | 712 | } |
711 | - | |
712 | - return $result; | |
713 | 713 | } |
714 | 714 | |
715 | 715 | // Listing class |
@@ -728,6 +728,10 @@ class Tracker_list | ||
728 | 728 | |
729 | 729 | var $error = ''; // Error message |
730 | 730 | |
731 | + // Used by toString() only | |
732 | + var $_itmes; | |
733 | + var $_escape; | |
734 | + | |
731 | 735 | // TODO: Why list here |
732 | 736 | function Tracker_list($base, $refer, & $config, $list) |
733 | 737 | { |
@@ -832,9 +836,10 @@ class Tracker_list | ||
832 | 836 | return TRUE; |
833 | 837 | } |
834 | 838 | |
839 | + $fields = $this->fields; | |
835 | 840 | $orders = array(); |
836 | 841 | $params = array(); // Arguments for array_multisort() |
837 | - $names = array_flip(array_keys($this->fields)); | |
842 | + $names = array_flip(array_keys($fields)); | |
838 | 843 | |
839 | 844 | foreach (explode(';', $order_commands) as $command) { |
840 | 845 | // TODO: ??? |
@@ -847,21 +852,26 @@ class Tracker_list | ||
847 | 852 | } |
848 | 853 | |
849 | 854 | $order = $this->_sortkey_string2define($order); |
850 | - if ($order === FALSE) return FALSE; | |
851 | - if ($order !== NULL) $orders[$fieldname] = $order; | |
855 | + if ($order === NULL) continue; | |
856 | + if ($order === FALSE) { | |
857 | + $this->error = 'Invalid sortkey: ' . $order; | |
858 | + return FALSE; | |
859 | + } | |
860 | + | |
861 | + $orders[$fieldname] = $order; // Set or override | |
852 | 862 | } |
853 | - // TODO: LIMIT (count($orders) < N < count(fields)) TO LIMIT array_multisort() | |
863 | + // TODO: LIMIT (count($orders) < N < count(fields_effective)) TO LIMIT array_multisort() | |
854 | 864 | |
855 | 865 | foreach ($orders as $fieldname => $order) { |
856 | 866 | // One column set (one-dimensional array(), sort type, and order-by) |
857 | 867 | $array = array(); |
858 | 868 | foreach ($this->rows as $row) { |
859 | 869 | $array[] = isset($row[$fieldname]) ? |
860 | - $this->fields[$fieldname]->get_value($row[$fieldname]) : | |
870 | + $fields[$fieldname]->get_value($row[$fieldname]) : | |
861 | 871 | ''; |
862 | 872 | } |
863 | 873 | $params[] = $array; |
864 | - $params[] = $this->fields[$fieldname]->sort_type; | |
874 | + $params[] = $fields[$fieldname]->sort_type; | |
865 | 875 | $params[] = $order; |
866 | 876 | } |
867 | 877 | $params[] = & $this->rows; |
@@ -910,7 +920,7 @@ class Tracker_list | ||
910 | 920 | function _replace_item($matches = array()) |
911 | 921 | { |
912 | 922 | $fields = $this->fields; |
913 | - $items = $this->items; | |
923 | + $items = $this->_items; | |
914 | 924 | $escape = isset($this->_escape) ? (bool)$this->_escape : FALSE; |
915 | 925 | |
916 | 926 | $params = isset($matches[1]) ? explode(',', $matches[1]) : array(); |
@@ -948,34 +958,36 @@ class Tracker_list | ||
948 | 958 | |
949 | 959 | $fieldname = isset($matches[1]) ? $matches[1] : ''; |
950 | 960 | if (! isset($fields[$fieldname])) { |
951 | - return isset($matches[0]) ? $matches[0] : ''; // Nothing to do | |
961 | + // Invalid sortkey or user's own string or something. Nothing to do | |
962 | + return isset($matches[0]) ? $matches[0] : ''; | |
952 | 963 | } |
953 | 964 | |
954 | - $sort = $fieldname; | |
955 | - if ($sort == '_name' || $sort == '_page') $sort = '_real'; | |
965 | + if ($fieldname == '_name' || $fieldname == '_page') { | |
966 | + $sort = '_real'; | |
967 | + } else { | |
968 | + $sort = $fieldname; | |
969 | + } | |
956 | 970 | |
957 | 971 | $arrow = ''; |
958 | - $order = PLUGIN_TRACKER_LIST_SORT_ASC; | |
959 | - $_order = array(); | |
960 | 972 | if (isset($orders[$sort])) { |
961 | - // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5 | |
962 | - $order_keys = array_keys($orders); // with array_shift(); | |
963 | - | |
973 | + // Sorted | |
974 | + $order_keys = array_keys($orders); | |
964 | 975 | $index = array_flip($order_keys); |
965 | 976 | $pos = 1 + $index[$sort]; |
966 | - $b_end = ($sort == $order_keys[0]); | |
977 | + $b_end = ($sort == isset($order_keys[0]) ? $order_keys[0] : ''); | |
967 | 978 | $b_order = ($orders[$sort] === PLUGIN_TRACKER_LIST_SORT_ASC); |
968 | 979 | $order = ($b_end xor $b_order) |
969 | 980 | ? PLUGIN_TRACKER_LIST_SORT_ASC |
970 | 981 | : PLUGIN_TRACKER_LIST_SORT_DESC; |
971 | 982 | $arrow = '&br;' . ($b_order ? '↑' : '↓') . '(' . $pos . ')'; |
972 | - | |
973 | 983 | unset($order_keys, $index); |
974 | - | |
975 | - // $sort become the first | |
976 | - unset($orders[$sort]); | |
977 | - $_order[] = $sort . ':' . $this->_sortkey_define2string($order); | |
984 | + unset($orders[$sort]); // $sort become the first if you click this | |
985 | + } else { | |
986 | + // Not sorted yet, but $sort become the first if you click this | |
987 | + $order = PLUGIN_TRACKER_LIST_SORT_ASC; | |
978 | 988 | } |
989 | + | |
990 | + $_order = array($sort . ':' . $this->_sortkey_define2string($order)); | |
979 | 991 | foreach ($orders as $key => $value) { |
980 | 992 | $_order[] = $key . ':' . $this->_sortkey_define2string($value); |
981 | 993 | } |
@@ -991,7 +1003,7 @@ class Tracker_list | ||
991 | 1003 | ']]'; |
992 | 1004 | } |
993 | 1005 | |
994 | - // Output part of XHTML | |
1006 | + // Output a part of Wiki text | |
995 | 1007 | function toString($limit = 0) |
996 | 1008 | { |
997 | 1009 | if (empty($this->rows)) { |
@@ -999,8 +1011,8 @@ class Tracker_list | ||
999 | 1011 | return FALSE; |
1000 | 1012 | } |
1001 | 1013 | |
1002 | - $source = array(); | |
1003 | 1014 | $rows = $this->rows; |
1015 | + $source = array(); | |
1004 | 1016 | |
1005 | 1017 | $count = count($this->rows); |
1006 | 1018 | $limit = intval($limit); |
@@ -1014,19 +1026,23 @@ class Tracker_list | ||
1014 | 1026 | $rows = array_slice($this->rows, 0, $limit); |
1015 | 1027 | } |
1016 | 1028 | |
1017 | - $body = array(); | |
1029 | + // Loading template | |
1030 | + $header = $body = array(); | |
1018 | 1031 | foreach (plugin_tracker_get_source($this->config->page . '/' . $this->list) as $line) { |
1019 | 1032 | if (preg_match('/^\|(.+)\|[hfc]$/i', $line)) { |
1020 | - // Table decolations | |
1021 | - $source[] = preg_replace_callback('/\[([^\[\]]+)\]/', array(& $this, '_replace_title'), $line); | |
1033 | + // TODO: Why c and f here | |
1034 | + $header[] = $line; // Table header, footer, and decoration | |
1022 | 1035 | } else { |
1023 | - $body[] = $line; | |
1036 | + $body[] = $line; // The others | |
1024 | 1037 | } |
1025 | 1038 | } |
1039 | + | |
1040 | + foreach($header as $line) { | |
1041 | + $source[] = preg_replace_callback('/\[([^\[\]]+)\]/', array(& $this, '_replace_title'), $line); | |
1042 | + } | |
1026 | 1043 | foreach ($rows as $row) { |
1027 | 1044 | if (! PLUGIN_TRACKER_LIST_SHOW_ERROR_PAGE && ! $row['_match']) continue; |
1028 | - | |
1029 | - $this->items = $row; | |
1045 | + $this->_items = $row; | |
1030 | 1046 | foreach ($body as $line) { |
1031 | 1047 | if (ltrim($line) != '') { |
1032 | 1048 | $this->_escape = ($line[0] == '|' || $line[0] == ':'); // The first letter |
@@ -1036,7 +1052,7 @@ class Tracker_list | ||
1036 | 1052 | } |
1037 | 1053 | } |
1038 | 1054 | |
1039 | - return convert_html(implode('', $source)); | |
1055 | + return implode('', $source); | |
1040 | 1056 | } |
1041 | 1057 | } |
1042 | 1058 |