• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修订版7515b16fd3e09dfb552f13a0cf2dbb48f407d61e (tree)
时间2007-09-16 01:50:23
作者henoheno <henoheno>
Commiterhenoheno

Log Message

* 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

更改概述

差异

--- a/plugin/tracker.inc.php
+++ b/plugin/tracker.inc.php
@@ -1,6 +1,6 @@
11 <?php
22 // 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 $
44 // Copyright (C) 2003-2005, 2007 PukiWiki Developers Team
55 // License: GPL v2 or (at your option) any later version
66 //
@@ -13,15 +13,18 @@ define('PLUGIN_TRACKER_DEFAULT_CONFIG', 'default');
1313 define('PLUGIN_TRACKER_DEFAULT_FORM', 'form');
1414 define('PLUGIN_TRACKER_DEFAULT_LIST', 'list');
1515 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');
1717
18-// #tracker_list: Excluding pattern
18+// Excluding pattern
1919 define('PLUGIN_TRACKER_LIST_EXCLUDE_PATTERN','#^SubMenu$|/#'); // 'SubMenu' and using '/'
2020 //define('PLUGIN_TRACKER_LIST_EXCLUDE_PATTERN','#(?!)#'); // Nothing excluded
2121
22-// #tracker_list: Show error rows (can't capture columns properly)
22+// Show error rows (can't capture columns properly)
2323 define('PLUGIN_TRACKER_LIST_SHOW_ERROR_PAGE', 1);
2424
25+// Sort options
26+define('PLUGIN_TRACKER_LIST_SORT_DESC', 3);
27+define('PLUGIN_TRACKER_LIST_SORT_ASC', 4);
2528
2629 // Show a form
2730 function plugin_tracker_convert()
@@ -841,25 +844,9 @@ class Tracker_list
841844 return FALSE;
842845 }
843846
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;
863850 }
864851 // TODO: LIMIT (count($orders) < N < count(fields)) TO LIMIT array_multisort()
865852
@@ -883,8 +870,42 @@ class Tracker_list
883870 return TRUE;
884871 }
885872
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)
888909 {
889910 $params = explode(',', $arr[1]);
890911 $name = array_shift($params);
@@ -907,47 +928,54 @@ class Tracker_list
907928 return $this->pipe ? str_replace('|', '&#x7c;', $str) : $str;
908929 }
909930
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)
912933 {
913- $field = $sort = $arr[1];
934+ $field = $arr[1];
914935 if (! isset($this->fields[$field])) return $arr[0];
915936
937+ $sort = $field;
916938 if ($sort == '_name' || $sort == '_page') $sort = '_real';
917939
918- $dir = SORT_ASC;
919940 $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])) {
922946 // 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();
924948
925949 $index = array_flip($order_keys);
926950 $pos = 1 + $index[$sort];
927951 $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;
930956 $arrow = '&br;' . ($b_order ? '&uarr;' : '&darr;') . '(' . $pos . ')';
931957
932- unset($order[$sort], $order_keys);
958+ unset($order_keys);
933959 }
934960 $title = $this->fields[$field]->title;
935961 $r_base = rawurlencode($this->base);
936962 $r_config = rawurlencode($this->config->config_name);
937963 $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);
943968 }
944- $r_order = rawurlencode(join(';', $_order));
945969
946970 $script = get_script_uri();
947- return '[[' . $title . $arrow . '>' .
971+ return '[[' .
972+ $title . $arrow .
973+ '>' .
948974 $script . '?plugin=tracker_list&base=' . $r_base .
949975 '&config=' . $r_config .
950- '&list=' . $r_list . '&order=' . $r_order . ']]';
976+ '&list=' . $r_list .
977+ '&order=' . rawurlencode(join(';', $_order)) .
978+ ']]';
951979 }
952980
953981 function toString($limit = 0)
@@ -986,7 +1014,7 @@ class Tracker_list
9861014 foreach (plugin_tracker_get_source($this->config->page . '/' . $this->list) as $line) {
9871015 if (preg_match('/^\|(.+)\|[hfc]$/i', $line)) {
9881016 // Table decolations
989- $source[] = preg_replace_callback('/\[([^\[\]]+)\]/', array(& $this, 'replace_title'), $line);
1017+ $source[] = preg_replace_callback('/\[([^\[\]]+)\]/', array(& $this, '_replace_title'), $line);
9901018 } else {
9911019 $body[] = $line;
9921020 }
@@ -1000,7 +1028,7 @@ class Tracker_list
10001028 $source[] = $line;
10011029 } else {
10021030 $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);
10041032 }
10051033 }
10061034 }