• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

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

Commit MetaInfo

Revisionc0dd212d4150eed589944d7a8bc2b33d0626863e (tree)
Zeit2007-10-16 22:09:29
Autorhenoheno <henoheno>
Commiterhenoheno

Log Message

Simplify:
* Rename variables
* Remove redundant errors
* unset() to rebuild (to be continued)

Ändern Zusammenfassung

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.113 2007/10/13 14:47:14 henoheno Exp $
3+// $Id: tracker.inc.php,v 1.114 2007/10/16 13:09:29 henoheno Exp $
44 // Copyright (C) 2003-2005, 2007 PukiWiki Developers Team
55 // License: GPL v2 or (at your option) any later version
66 //
@@ -48,9 +48,9 @@ function plugin_tracker_convert()
4848
4949 if (PKWK_READONLY) return ''; // Show nothing
5050
51- $base = $refer = isset($vars['page']) ? $vars['page'] : '';
52- $config_name = PLUGIN_TRACKER_DEFAULT_CONFIG;
53- $form = PLUGIN_TRACKER_DEFAULT_FORM;
51+ $base = $refer = isset($vars['page']) ? $vars['page'] : '';
52+ $config = PLUGIN_TRACKER_DEFAULT_CONFIG;
53+ $form = PLUGIN_TRACKER_DEFAULT_FORM;
5454
5555 $args = func_get_args();
5656 $argc = count($args);
@@ -66,28 +66,31 @@ function plugin_tracker_convert()
6666 // Config/form
6767 if ($args[0] != '') {
6868 $arg = explode('/', trim($args[0]), 2);
69- if ($arg[0] != '' ) $config_name = trim($arg[0]);
70- if (isset($arg[1])) $form = trim($arg[1]);
69+ if ($arg[0] != '' ) $config = trim($arg[0]);
70+ if (isset($arg[1])) $form = trim($arg[1]);
7171 }
7272 }
7373 unset($args, $argc, $arg);
7474
75- $config = new Config('plugin/tracker/' . $config_name);
76- if (! $config->read()) {
77- return '#tracker: Config \'' . htmlspecialchars($config_name) . '\' not found<br />';
75+ $obj_config = new Config('plugin/tracker/' . $config);
76+ if (! $obj_config->read()) {
77+ return '#tracker: Config \'' . htmlspecialchars($config) . '\' not found<br />';
7878 }
79- $config->config_name = $config_name;
79+ $obj_config->_local_name = $config;
8080
81- $form = $config->page . '/' . $form;
81+ $form = $obj_config->page . '/' . $form;
8282 $template = plugin_tracker_get_source($form, TRUE);
8383 if ($template === FALSE || empty($template)) {
8484 return '#tracker: Form \'' . make_pagelink($form) . '\' not found or seems empty<br />';
8585 }
8686
87- $_form = & new Tracker_form($base, $refer, $config);
88- $_form->initFields(plugin_tracker_field_pickup($template));
89- $_form->initHiddenFields();
90- $fields = $_form->fields;
87+ $tracker_form = & new Tracker_form($base, $refer, $obj_config);
88+ if ($tracker_form->initFields(plugin_tracker_field_pickup($template)) === FALSE ||
89+ $tracker_form->initHiddenFields() === FALSE) {
90+ return '#tracker: ' . htmlspecialchars($tracker_form->error);
91+ }
92+ $fields = $tracker_form->fields;
93+ unset($tracker_form);
9194
9295 $from = $to = $hidden = array();
9396 foreach (array_keys($fields) as $fieldname) {
@@ -147,12 +150,15 @@ function plugin_tracker_action()
147150 }
148151
149152 // Loading configuration
150- $config_name = isset($post['_config']) ? $post['_config'] : '';
151- $config = new Config('plugin/tracker/' . $config_name);
152- if (! $config->read()) {
153- return '<p>config file \'' . htmlspecialchars($config_name) . '\' not found.</p>';
153+ $config = isset($post['_config']) ? $post['_config'] : '';
154+ $obj_config = new Config('plugin/tracker/' . $config);
155+ if (! $obj_config->read()) {
156+ return array(
157+ 'msg' => 'Cannot write',
158+ 'body' => 'Config file \'' . htmlspecialchars($config) . '\' not found'
159+ );
154160 }
155- $config->config_name = $config_name;
161+ $obj_config->_local_name = $config;
156162
157163 // Default
158164 $_post = array_merge($post, $_FILES);
@@ -168,7 +174,7 @@ function plugin_tracker_action()
168174 $from = $to = array();
169175
170176 // Load $template
171- $template_page = $config->page . '/page';
177+ $template_page = $obj_config->page . '/page';
172178 $template = plugin_tracker_get_source($template_page);
173179 if ($template === FALSE || empty($template)) {
174180 return array(
@@ -177,9 +183,16 @@ function plugin_tracker_action()
177183 );
178184 }
179185
180- $form = & new Tracker_form($base, $refer, $config);
181- $form->initFields(plugin_tracker_field_pickup(implode('', $template)));
182- $fields = & $form->fields; // unset()
186+ $tracker_form = & new Tracker_form($base, $refer, $obj_config);
187+ if ($tracker_form->initFields(plugin_tracker_field_pickup(implode('', $template))) === FALSE) {
188+ return array(
189+ 'msg' => 'Cannot write',
190+ 'body' => htmlspecialchars($tracker_form->error)
191+ );
192+ }
193+ $fields = $tracker_form->fields;
194+ unset($tracker_form);
195+
183196 foreach (array_keys($fields) as $field) {
184197 $from[] = '[' . $field . ']';
185198 $to[] = isset($_post[$field]) ? $fields[$field]->format_value($_post[$field]) : '';
@@ -475,7 +488,8 @@ class Tracker_field_real extends Tracker_field_text
475488
476489 function format_cell($value)
477490 {
478- // basename(): Rough but work with this(PLUGIN_TRACKER_LIST_EXCLUDE_PATTERN prohibits '/') situation
491+ // basename(): Rough but work with this
492+ // (PLUGIN_TRACKER_LIST_EXCLUDE_PATTERN prohibits '/') situation
479493 return basename($value);
480494 }
481495 }
@@ -538,6 +552,7 @@ class Tracker_field_format extends Tracker_field
538552 function Tracker_field_format(& $tracker_form, $field)
539553 {
540554 parent::Tracker_field($tracker_form, $field);
555+
541556 foreach ($this->form->config->get($this->name) as $option) {
542557 list($key, $style, $format) = array_pad(array_map('trim', $option), 3, '');
543558 if ($style != '') $this->styles[$key] = $style;
@@ -590,7 +605,6 @@ class Tracker_field_file extends Tracker_field_format
590605 function format_value()
591606 {
592607 if (isset($_FILES[$this->name])) {
593-
594608 require_once(PLUGIN_DIR . 'attach.inc.php');
595609
596610 $base = $this->form->base;
@@ -739,7 +753,7 @@ class Tracker_field_submit extends Tracker_field
739753 $s_title = htmlspecialchars($this->title);
740754 $s_base = htmlspecialchars($form->base);
741755 $s_refer = htmlspecialchars($form->refer);
742- $s_config = htmlspecialchars($form->config->config_name);
756+ $s_config = htmlspecialchars($form->config->_local_name);
743757
744758 return <<<EOD
745759 <input type="submit" value="$s_title" />
@@ -783,11 +797,11 @@ function plugin_tracker_list_convert()
783797 {
784798 global $vars;
785799
786- $base = $refer = isset($vars['page']) ? $vars['page'] : '';
787- $config_name = PLUGIN_TRACKER_DEFAULT_CONFIG;
788- $list = PLUGIN_TRACKER_DEFAULT_LIST;
789- $limit = PLUGIN_TRACKER_DEFAULT_LIMIT;
790- $order = PLUGIN_TRACKER_DEFAULT_ORDER;
800+ $base = $refer = isset($vars['page']) ? $vars['page'] : '';
801+ $config = '';
802+ $list = '';
803+ $limit = NULL;
804+ $order = '';
791805
792806 $args = func_get_args();
793807 $argc = count($args);
@@ -805,13 +819,13 @@ function plugin_tracker_list_convert()
805819 // Config/list
806820 if ($args[0] != '') {
807821 $arg = explode('/', $args[0], 2);
808- if ($arg[0] != '' ) $config_name = $arg[0];
809- if (isset($arg[1])) $list = $arg[1];
822+ if ($arg[0] != '' ) $config = $arg[0];
823+ if (isset($arg[1])) $list = $arg[1];
810824 }
811825 }
812826 unset($args, $argc, $arg);
813827
814- return plugin_tracker_list_render($base, $refer, $config_name, $list, $order, $limit);
828+ return plugin_tracker_list_render($base, $refer, $config, $order, $list, $limit);
815829 }
816830
817831 function plugin_tracker_list_action()
@@ -828,48 +842,44 @@ function plugin_tracker_list_action()
828842 }
829843
830844 $config = isset($get['config']) ? $get['config'] : '';
831- $list = isset($get['list']) ? $get['list'] : 'list';
832- $order = isset($get['order']) ? $get['order'] : PLUGIN_TRACKER_DEFAULT_ORDER;
833- $limit = isset($get['limit']) ? $get['limit'] : 0;
845+ $list = isset($get['list']) ? $get['list'] : '';
846+ $order = isset($get['order']) ? $get['order'] : '';
847+ $limit = isset($get['limit']) ? $get['limit'] : NULL;
834848
835849 $s_refer = make_pagelink($refer);
836850 return array(
837851 'msg' => plugin_tracker_message('msg_list'),
838852 'body'=> str_replace('$1', $s_refer, plugin_tracker_message('msg_back')) .
839- plugin_tracker_list_render($base, $refer, $config, $list, $order, $limit)
853+ plugin_tracker_list_render($base, $refer, $config, $order, $list, $limit)
840854 );
841855 }
842856
843-function plugin_tracker_list_render($base, $refer, $config_name, $list, $order_commands = '', $limit = 0)
857+function plugin_tracker_list_render($base, $refer, $config = '', $order_commands = '', $list = '', $limit = NULL)
844858 {
845- $base = trim($base);
846- if ($base == '') return '#tracker_list: Base not specified' . '<br />';
847-
848- $refer = trim($refer);
849- if (! is_page($refer)) {
850- return '#tracker_list: Refer page not found: ' . htmlspecialchars($refer) . '<br />';
851- }
859+ $base = trim($base);
860+ $refer = trim($refer);
861+ $config = trim($config);
862+ $list = trim($list);
863+ if ($config == '' ) $config = PLUGIN_TRACKER_DEFAULT_CONFIG;
864+ if ($list == '' ) $list = PLUGIN_TRACKER_DEFAULT_LIST;
865+ if ($order_commands == '') $order_commands = PLUGIN_TRACKER_DEFAULT_ORDER;
866+ if ($limit == NULL ) $limit = PLUGIN_TRACKER_DEFAULT_LIMIT;
852867
853- $config_name = trim($config_name);
854- if ($config_name == '') $config_name = PLUGIN_TRACKER_DEFAULT_CONFIG;
868+ if ($base == '') return '#tracker_list: Base not specified' . '<br />';
869+ if (! is_page($refer)) return '#tracker_list: Refer page not found: ' . htmlspecialchars($refer) . '<br />';
855870
856- $list = trim($list);
857871 if (! is_numeric($limit)) return PLUGIN_TRACKER_LIST_USAGE . '<br />';
858872 $limit = intval($limit);
859873
860- $config = new Config('plugin/tracker/' . $config_name);
861- if (! $config->read()) {
862- return '#tracker_list: Config not found: ' . htmlspecialchars($config_name) . '<br />';
863- }
864- $config->config_name = $config_name;
865- if (! is_page($config->page . '/' . $list)) {
866- return '#tracker_list: List not found: ' . make_pagelink($config->page . '/' . $list) . '<br />';
867- }
874+ $obj_config = new Config('plugin/tracker/' . $config);
875+ if (! $obj_config->read()) return '#tracker_list: Config not found: ' . htmlspecialchars($config) . '<br />';
876+ $obj_config->_local_name = $config;
868877
869- $tracker_list = & new Tracker_list($base, $refer, $config);
878+ $tracker_list = & new Tracker_list($base, $refer, $obj_config);
870879 if ($tracker_list->setSortOrder($order_commands) === FALSE) {
871880 return '#tracker_list: ' . htmlspecialchars($tracker_list->error) . '<br />';
872881 }
882+
873883 $result = $tracker_list->toString($list, $limit);
874884 if ($result === FALSE) {
875885 return '#tracker_list: ' . htmlspecialchars($tracker_list->error) . '<br />';
@@ -885,7 +895,7 @@ class Tracker_list
885895 var $form; // class Tracker_form
886896
887897 var $rows = array();
888- var $orders = array();
898+ var $orders;
889899 var $error = ''; // Error message
890900
891901 // _generate_regex()
@@ -905,7 +915,7 @@ class Tracker_list
905915 $this->form = & new Tracker_form($base, $refer, $config);
906916 }
907917
908- // Generate regex to load a page
918+ // Generate/Regenerate regex to load one page
909919 function _generate_regex()
910920 {
911921 if (isset($this->pattern) && isset($this->pattern_fields)) return TRUE;
@@ -1059,11 +1069,12 @@ class Tracker_list
10591069 {
10601070 $orders = $this->_order_commands2orders($order_commands);
10611071 if ($orders === FALSE) {
1062- $this->orders = array();
1072+ unset($this->orders);
10631073 return FALSE;
1074+ } else {
1075+ $this->orders = $orders;
1076+ return TRUE;
10641077 }
1065- $this->orders = $orders;
1066- return TRUE;
10671078 }
10681079
10691080 // sortRows(): Internal sort type => PHP sort define
@@ -1095,6 +1106,11 @@ class Tracker_list
10951106 // Sort $this->rows by $this->orders
10961107 function sortRows()
10971108 {
1109+ if (! isset($this->orders)) {
1110+ $this->error = "Sort order seems not set";
1111+ return FALSE;
1112+ }
1113+
10981114 $fields = $this->form->fields;
10991115 $orders = $this->orders;
11001116 $types = array();
@@ -1189,14 +1205,14 @@ class Tracker_list
11891205 // toString(): Called within preg_replace_callback()
11901206 function _replace_title($matches = array())
11911207 {
1192- $form = $this->form;
1193- $base = $form->base;
1194- $refer = $form->refer;
1195- $fields = $form->fields;
1196- $config_name = $form->config->config_name;
1208+ $form = $this->form;
1209+ $base = $form->base;
1210+ $refer = $form->refer;
1211+ $fields = $form->fields;
1212+ $config = $form->config->_local_name;
11971213
1198- $orders = $this->orders;
1199- $list = $this->_list;
1214+ $orders = $this->orders;
1215+ $list = $this->_list;
12001216
12011217 $fieldname = isset($matches[1]) ? $matches[1] : '';
12021218 if (! isset($fields[$fieldname])) {
@@ -1239,8 +1255,8 @@ class Tracker_list
12391255 $script = get_script_uri();
12401256 $r_base = ($refer != $base) ?
12411257 '&base=' . rawurlencode($base) : '';
1242- $r_config = ($config_name != PLUGIN_TRACKER_DEFAULT_CONFIG) ?
1243- '&config=' . rawurlencode($config_name) : '';
1258+ $r_config = ($config != PLUGIN_TRACKER_DEFAULT_CONFIG) ?
1259+ '&config=' . rawurlencode($config) : '';
12441260 $r_list = ($list != PLUGIN_TRACKER_DEFAULT_LIST) ?
12451261 '&list=' . rawurlencode($list) : '';
12461262 $r_order = ! empty($_orders) ?
@@ -1294,7 +1310,7 @@ class Tracker_list
12941310 }
12951311
12961312 // Output a part of Wiki text
1297- function toString($list, $limit = 0)
1313+ function toString($list = PLUGIN_TRACKER_DEFAULT_LIST, $limit = 0)
12981314 {
12991315 $form = & $this->form;
13001316
@@ -1307,7 +1323,7 @@ class Tracker_list
13071323 // Loading template
13081324 $template = plugin_tracker_get_source($list, TRUE);
13091325 if ($template === FALSE || empty($template)) {
1310- $this->error = 'Page not found or seems empty: ' . $list;
1326+ $this->error = 'List not found: ' . $list;
13111327 return FALSE;
13121328 }
13131329
@@ -1318,12 +1334,10 @@ class Tracker_list
13181334 return FALSE;
13191335 }
13201336
1321- // TODO: Check isset($this->rows) or something
13221337 // Load and sort $this->rows
13231338 if ($this->loadRows() === FALSE || $this->sortRows() === FALSE) return FALSE;
13241339 $rows = $this->rows;
13251340
1326-
13271341 // toString()
13281342 $count = count($this->rows);
13291343 $limit = intval($limit);