• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

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

Commit MetaInfo

Revisãoa8119b2c38ae6b14d16581f0cf457e52b3f0047b (tree)
Hora2007-09-06 00:14:44
Autorhenoheno <henoheno>
Commiterhenoheno

Mensagem de Log

BugTrack2/243: Cleanup/Simplify/Todo

Mudança Sumário

Diff

--- 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.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 $
44 // Copyright (C) 2003-2005, 2007 PukiWiki Developers Team
55 // License: GPL v2 or (at your option) any later version
66 //
@@ -43,8 +43,8 @@ function plugin_tracker_convert()
4343 if ($argc > 0 && $args[0] != '') {
4444 // Configuration name AND form name
4545 $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];
4848 }
4949 }
5050
@@ -95,16 +95,16 @@ function plugin_tracker_action()
9595 $refer = isset($post['_refer']) ? $post['_refer'] : $base;
9696 if (! is_pagename($refer)) {
9797 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'
100100 );
101101 }
102102
103103 // $page name to add will be decided here
104- $name = isset($post['_name']) ? $post['_name'] : '';
105104 $num = 0;
105+ $name = isset($post['_name']) ? $post['_name'] : '';
106106 if (isset($post['_page'])) {
107- $page = $real = $post['_page'];
107+ $real = $page = $post['_page'];
108108 } else {
109109 $real = is_pagename($name) ? $name : ++$num;
110110 $page = get_fullname('./' . $real, $base);
@@ -125,8 +125,8 @@ function plugin_tracker_action()
125125 $template_page = $config->page . '/page';
126126 if (! is_page($template_page)) {
127127 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'
130130 );
131131 }
132132
@@ -472,7 +472,12 @@ class Tracker_field_radio extends Tracker_field_format
472472 {
473473 static $options = array();
474474 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+ );
476481 }
477482 return isset($options[$this->name][$value]) ? $options[$this->name][$value] : $value;
478483 }
@@ -595,17 +600,20 @@ class Tracker_field_past extends Tracker_field
595600 }
596601
597602 ///////////////////////////////////////////////////////////////////////////
603+// tracker_list plugin
598604
599605 function plugin_tracker_list_convert()
600606 {
601607 global $vars;
602608
603609 $config = PLUGIN_TRACKER_DEFAULT_CONFIG;
604- $page = $refer = $vars['page'];
610+ $page = $refer = isset($vars['page']) ? $vars['page'] : '';
605611 $field = '_page';
606612 $order = '';
607613 $list = 'list';
608614 $limit = NULL;
615+
616+ // TODO: SHOW USAGE OR ERROR CLEARLY
609617 if (func_num_args()) {
610618 $args = func_get_args();
611619 switch (count($args)) {
@@ -621,42 +629,39 @@ function plugin_tracker_list_convert()
621629 list($config, $list) = array_pad(explode('/', $config, 2), 2, $list);
622630 }
623631 }
624- return plugin_tracker_getlist($page, $refer, $config, $list, $order, $limit);
632+ return plugin_tracker_list_render($page, $refer, $config, $list, $order, $limit);
625633 }
626634
627635 function plugin_tracker_list_action()
628636 {
629637 global $script, $vars, $_tracker_messages;
630638
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';
636643
644+ $s_page = make_pagelink($page);
637645 return array(
638646 '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)
641649 );
642650 }
643651
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)
645653 {
646654 $config = new Config('plugin/tracker/' . $config_name);
647-
648655 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 />';
650657 }
651-
652658 $config->config_name = $config_name;
653-
654659 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 />';
656661 }
657662
658663 $list = & new Tracker_list($page, $refer, $config, $list);
659- $list->sort($order);
664+ $list->sort($order_commands);
660665 return $list->toString($limit);
661666 }
662667
@@ -684,6 +689,7 @@ class Tracker_list
684689 $this->order = array();
685690
686691 $pattern = plugin_tracker_get_source($config->page . '/page', TRUE);
692+ // TODO: if (is FALSE) OR file_exists()
687693
688694 // Convert block-plugins to fields
689695 // Incleasing and decreasing around #comment etc, will be covererd with [_block_xxx]
@@ -757,50 +763,66 @@ class Tracker_list
757763 }
758764 }
759765
760- function sort($order)
766+ // Sort $this->rows with $order_commands
767+ function sort($order_commands = '')
761768 {
762- if ($order == '') return;
769+ if ($order_commands == '') {
770+ $this->order = array();
771+ return TRUE;
772+ }
763773
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));
766777
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);
770782
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:
772791 case 'SORT_ASC':
773792 case 'ASC':
774- case SORT_ASC:
775- $dir = SORT_ASC;
793+ $order = SORT_ASC;
776794 break;
795+ case SORT_DESC:
777796 case 'SORT_DESC':
778797 case 'DESC':
779- case SORT_DESC:
780- $dir = SORT_DESC;
798+ $order = SORT_DESC;
781799 break;
782800 default:
783801 continue;
784802 }
785- $this->order[$key] = $dir;
803+
804+ $orders[$fieldname] = $order;
786805 }
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()
791807
808+ foreach ($orders as $fieldname => $order) {
809+ // One column set (one-dimensional array(), sort type, and order-by)
810+ $array = array();
792811 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]) :
795814 '';
796815 }
797- $params[] = $keys[$field];
798- $params[] = $this->fields[$field]->sort_type;
816+ $params[] = $array;
817+ $params[] = $this->fields[$fieldname]->sort_type;
799818 $params[] = $order;
800819 }
801820 $params[] = & $this->rows;
802821
803822 call_user_func_array('array_multisort', $params);
823+ $this->order = $orders;
824+
825+ return TRUE;
804826 }
805827
806828 // Used with preg_replace_callback() at toString()