Revisão | 7515b16fd3e09dfb552f13a0cf2dbb48f407d61e (tree) |
---|---|
Hora | 2007-09-16 01:50:23 |
Autor | henoheno <henoheno> |
Commiter | henoheno |
* PLUGIN_TRACKER_DEFAULT_ORDER: SORT_DESC => SORT_ASC, as 1.4.7_notb does
* TODO: SHOULD NOT TO USE DEFINES AT THIS string WORLD
* Rename internal methods() => _methods()
* Rename variables
@@ -1,6 +1,6 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone |
3 | -// $Id: tracker.inc.php,v 1.51 2007-09-11 13:43:56 henoheno Exp $ | |
3 | +// $Id: tracker.inc.php,v 1.52 2007-09-15 16:50:23 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 | // |
@@ -13,15 +13,18 @@ define('PLUGIN_TRACKER_DEFAULT_CONFIG', 'default'); | ||
13 | 13 | define('PLUGIN_TRACKER_DEFAULT_FORM', 'form'); |
14 | 14 | define('PLUGIN_TRACKER_DEFAULT_LIST', 'list'); |
15 | 15 | define('PLUGIN_TRACKER_DEFAULT_LIMIT', 0); // 0 = Unlimited |
16 | -define('PLUGIN_TRACKER_DEFAULT_ORDER', '_real:SORT_DESC'); | |
16 | +define('PLUGIN_TRACKER_DEFAULT_ORDER', '_real:SORT_ASC'); | |
17 | 17 | |
18 | -// #tracker_list: Excluding pattern | |
18 | +// Excluding pattern | |
19 | 19 | define('PLUGIN_TRACKER_LIST_EXCLUDE_PATTERN','#^SubMenu$|/#'); // 'SubMenu' and using '/' |
20 | 20 | //define('PLUGIN_TRACKER_LIST_EXCLUDE_PATTERN','#(?!)#'); // Nothing excluded |
21 | 21 | |
22 | -// #tracker_list: Show error rows (can't capture columns properly) | |
22 | +// Show error rows (can't capture columns properly) | |
23 | 23 | define('PLUGIN_TRACKER_LIST_SHOW_ERROR_PAGE', 1); |
24 | 24 | |
25 | +// Sort options | |
26 | +define('PLUGIN_TRACKER_LIST_SORT_DESC', 3); | |
27 | +define('PLUGIN_TRACKER_LIST_SORT_ASC', 4); | |
25 | 28 | |
26 | 29 | // Show a form |
27 | 30 | function plugin_tracker_convert() |
@@ -841,25 +844,9 @@ class Tracker_list | ||
841 | 844 | return FALSE; |
842 | 845 | } |
843 | 846 | |
844 | - // TODO: SHOULD NOT TO USE DEFINES AT THIS string WORLD | |
845 | - $order = trim($order); | |
846 | - switch (strtoupper($order)) { | |
847 | - case '': | |
848 | - break; | |
849 | - case SORT_ASC: /*FALLTHROUGH*/ | |
850 | - case 'SORT_ASC': /*FALLTHROUGH*/ | |
851 | - case 'ASC': | |
852 | - $orders[$fieldname] = SORT_ASC; | |
853 | - break; | |
854 | - case SORT_DESC: /*FALLTHROUGH*/ | |
855 | - case 'SORT_DESC': /*FALLTHROUGH*/ | |
856 | - case 'DESC': | |
857 | - $orders[$fieldname] = SORT_DESC; | |
858 | - break; | |
859 | - default: | |
860 | - $this->error = 'Invalid sort key: ' . $order; | |
861 | - return FALSE; | |
862 | - } | |
847 | + $order = $this->_sortkey_string2define($order); | |
848 | + if ($order === FALSE) return FALSE; | |
849 | + if ($order !== NULL) $orders[$fieldname] = $order; | |
863 | 850 | } |
864 | 851 | // TODO: LIMIT (count($orders) < N < count(fields)) TO LIMIT array_multisort() |
865 | 852 |
@@ -883,8 +870,42 @@ class Tracker_list | ||
883 | 870 | return TRUE; |
884 | 871 | } |
885 | 872 | |
886 | - // Used with preg_replace_callback() at toString() | |
887 | - function replace_item($arr) | |
873 | + // toString(): Sort key: Define to string (internal var => string) | |
874 | + function _sortkey_define2string($sortkey) | |
875 | + { | |
876 | + switch ($sortkey) { | |
877 | + case PLUGIN_TRACKER_LIST_SORT_ASC: $sortkey = 'SORT_ASC'; break; | |
878 | + case PLUGIN_TRACKER_LIST_SORT_DESC: $sortkey = 'SORT_DESC'; break; | |
879 | + default: | |
880 | + $this->error = 'No such define: ' . $sortkey; | |
881 | + $sortkey = FALSE; | |
882 | + } | |
883 | + return $sortkey; | |
884 | + } | |
885 | + | |
886 | + // toString(): Sort key: String to define (string => internal var) | |
887 | + function _sortkey_string2define($sortkey) | |
888 | + { | |
889 | + switch (strtoupper(trim($sortkey))) { | |
890 | + case '': $sortkey = NULL; break; | |
891 | + | |
892 | + case SORT_ASC: /*FALLTHROUGH*/ // Compat, will be removed at 1.4.9 or later | |
893 | + case 'SORT_ASC': /*FALLTHROUGH*/ | |
894 | + case 'ASC': $sortkey = PLUGIN_TRACKER_LIST_SORT_ASC; break; | |
895 | + | |
896 | + case SORT_DESC: /*FALLTHROUGH*/ // Compat, will be removed at 1.4.9 or later | |
897 | + case 'SORT_DESC': /*FALLTHROUGH*/ | |
898 | + case 'DESC': $sortkey = PLUGIN_TRACKER_LIST_SORT_DESC; break; | |
899 | + | |
900 | + default: | |
901 | + $this->error = 'Invalid sort key: ' . $sortkey; | |
902 | + $sortkey = FALSE; | |
903 | + } | |
904 | + return $sortkey; | |
905 | + } | |
906 | + | |
907 | + // toString(): Used with preg_replace_callback() | |
908 | + function _replace_item($arr) | |
888 | 909 | { |
889 | 910 | $params = explode(',', $arr[1]); |
890 | 911 | $name = array_shift($params); |
@@ -907,47 +928,54 @@ class Tracker_list | ||
907 | 928 | return $this->pipe ? str_replace('|', '|', $str) : $str; |
908 | 929 | } |
909 | 930 | |
910 | - // Used with preg_replace_callback() at toString() | |
911 | - function replace_title($arr) | |
931 | + // toString(): Used with preg_replace_callback() | |
932 | + function _replace_title($arr) | |
912 | 933 | { |
913 | - $field = $sort = $arr[1]; | |
934 | + $field = $arr[1]; | |
914 | 935 | if (! isset($this->fields[$field])) return $arr[0]; |
915 | 936 | |
937 | + $sort = $field; | |
916 | 938 | if ($sort == '_name' || $sort == '_page') $sort = '_real'; |
917 | 939 | |
918 | - $dir = SORT_ASC; | |
919 | 940 | $arrow = ''; |
920 | - $order = $this->order; | |
921 | - if (is_array($order) && isset($order[$sort])) { | |
941 | + $order = PLUGIN_TRACKER_LIST_SORT_ASC; | |
942 | + | |
943 | + $orders = $this->order; | |
944 | + | |
945 | + if (isset($orders[$sort])) { | |
922 | 946 | // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5 |
923 | - $order_keys = array_keys($order); // with array_shift(); | |
947 | + $order_keys = array_keys($orders); // with array_shift(); | |
924 | 948 | |
925 | 949 | $index = array_flip($order_keys); |
926 | 950 | $pos = 1 + $index[$sort]; |
927 | 951 | $b_end = ($sort == array_shift($order_keys)); |
928 | - $b_order = ($order[$sort] == SORT_ASC); | |
929 | - $dir = ($b_end xor $b_order) ? SORT_ASC : SORT_DESC; | |
952 | + $b_order = ($orders[$sort] == PLUGIN_TRACKER_LIST_SORT_ASC); | |
953 | + $order = ($b_end xor $b_order) | |
954 | + ? PLUGIN_TRACKER_LIST_SORT_ASC | |
955 | + : PLUGIN_TRACKER_LIST_SORT_DESC; | |
930 | 956 | $arrow = '&br;' . ($b_order ? '↑' : '↓') . '(' . $pos . ')'; |
931 | 957 | |
932 | - unset($order[$sort], $order_keys); | |
958 | + unset($order_keys); | |
933 | 959 | } |
934 | 960 | $title = $this->fields[$field]->title; |
935 | 961 | $r_base = rawurlencode($this->base); |
936 | 962 | $r_config = rawurlencode($this->config->config_name); |
937 | 963 | $r_list = rawurlencode($this->list); |
938 | - $_order = array($sort . ':' . $dir); | |
939 | - if (is_array($order)) { | |
940 | - foreach ($order as $key => $value) { | |
941 | - $_order[] = $key . ':' . $value; | |
942 | - } | |
964 | + | |
965 | + $_order = array($sort . ':' . $order); | |
966 | + foreach ($orders as $key => $value) { | |
967 | + $_order[] = $key . ':' . $this->_sortkey_define2string($value); | |
943 | 968 | } |
944 | - $r_order = rawurlencode(join(';', $_order)); | |
945 | 969 | |
946 | 970 | $script = get_script_uri(); |
947 | - return '[[' . $title . $arrow . '>' . | |
971 | + return '[[' . | |
972 | + $title . $arrow . | |
973 | + '>' . | |
948 | 974 | $script . '?plugin=tracker_list&base=' . $r_base . |
949 | 975 | '&config=' . $r_config . |
950 | - '&list=' . $r_list . '&order=' . $r_order . ']]'; | |
976 | + '&list=' . $r_list . | |
977 | + '&order=' . rawurlencode(join(';', $_order)) . | |
978 | + ']]'; | |
951 | 979 | } |
952 | 980 | |
953 | 981 | function toString($limit = 0) |
@@ -986,7 +1014,7 @@ class Tracker_list | ||
986 | 1014 | foreach (plugin_tracker_get_source($this->config->page . '/' . $this->list) as $line) { |
987 | 1015 | if (preg_match('/^\|(.+)\|[hfc]$/i', $line)) { |
988 | 1016 | // Table decolations |
989 | - $source[] = preg_replace_callback('/\[([^\[\]]+)\]/', array(& $this, 'replace_title'), $line); | |
1017 | + $source[] = preg_replace_callback('/\[([^\[\]]+)\]/', array(& $this, '_replace_title'), $line); | |
990 | 1018 | } else { |
991 | 1019 | $body[] = $line; |
992 | 1020 | } |
@@ -1000,7 +1028,7 @@ class Tracker_list | ||
1000 | 1028 | $source[] = $line; |
1001 | 1029 | } else { |
1002 | 1030 | $this->pipe = ($line{0} == '|' || $line{0} == ':'); |
1003 | - $source[] = preg_replace_callback('/\[([^\[\]]+)\]/', array(& $this, 'replace_item'), $line); | |
1031 | + $source[] = preg_replace_callback('/\[([^\[\]]+)\]/', array(& $this, '_replace_item'), $line); | |
1004 | 1032 | } |
1005 | 1033 | } |
1006 | 1034 | } |