Revision | bbd6b28ca8c2ac6b2f70663c44e930b6c61c85f0 (tree) |
---|---|
Time | 2007-10-20 19:46:42 |
Author | henoheno <henoheno> |
Commiter | henoheno |
Simplify
@@ -1,6 +1,6 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone |
3 | -// $Id: tracker.inc.php,v 1.117 2007/10/17 15:16:19 henoheno Exp $ | |
3 | +// $Id: tracker.inc.php,v 1.118 2007/10/20 10:46:42 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 | // |
@@ -41,6 +41,21 @@ define('PLUGIN_TRACKER_SORT_ORDER_ASC', 4); | ||
41 | 41 | define('PLUGIN_TRACKER_SORT_ORDER_DEFAULT', PLUGIN_TRACKER_SORT_ORDER_ASC); |
42 | 42 | |
43 | 43 | |
44 | +// ---- | |
45 | +// Basic interface and strategy | |
46 | + | |
47 | +// $refer : Where the plugin had been set / Where to return back to | |
48 | +// Compat: If ($base == '') $base = $refer; | |
49 | +// $base : "$base/nnn" will be added by plugin_tracker_action(), or will be shown by Tracker_list | |
50 | +// $config : ":config/plugin/tracker/$config" will be load to the Config | |
51 | +// $form : ":config/plugin/tracker/$config/$form" will be load as template for XHTML form by Tracker_form | |
52 | +// $page : ":config/plugin/tracker/$config/$page" will be load as template for a new page written by Tracker_form | |
53 | +// $list : ":config/plugin/tracker/$config/$list" will be load as template of Tracker_list | |
54 | +// $order : order command string for Tracker_list | |
55 | +// $limit : Show top N rows at a time | |
56 | + | |
57 | +// ---- | |
58 | + | |
44 | 59 | // Show a form |
45 | 60 | function plugin_tracker_convert() |
46 | 61 | { |
@@ -48,22 +63,23 @@ function plugin_tracker_convert() | ||
48 | 63 | |
49 | 64 | if (PKWK_READONLY) return ''; // Show nothing |
50 | 65 | |
51 | - $base = $refer = isset($vars['page']) ? $vars['page'] : ''; | |
52 | - $config = PLUGIN_TRACKER_DEFAULT_CONFIG; | |
53 | - $form = PLUGIN_TRACKER_DEFAULT_FORM; | |
54 | - | |
55 | - $args = func_get_args(); | |
56 | 66 | $argc = count($args); |
67 | + $args = func_get_args(); | |
57 | 68 | if ($argc > 2) { |
58 | 69 | return PLUGIN_TRACKER_USAGE . '<br />'; |
59 | 70 | } |
71 | + | |
72 | + $base = $refer = isset($vars['page']) ? $vars['page'] : ''; | |
73 | + $config = ''; | |
74 | + $form = ''; | |
60 | 75 | switch ($argc) { |
61 | 76 | case 2: |
77 | + // Set $base | |
62 | 78 | $arg = get_fullname($args[1], $base); |
63 | 79 | if (is_pagename($arg)) $base = $arg; |
64 | 80 | /*FALLTHROUGH*/ |
65 | 81 | case 1: |
66 | - // Config/form | |
82 | + // Set "$config/$form" | |
67 | 83 | if ($args[0] != '') { |
68 | 84 | $arg = explode('/', trim($args[0]), 2); |
69 | 85 | if ($arg[0] != '' ) $config = trim($arg[0]); |
@@ -73,19 +89,20 @@ function plugin_tracker_convert() | ||
73 | 89 | unset($args, $argc, $arg); |
74 | 90 | |
75 | 91 | $tracker_form = & new Tracker_form($base, $refer); |
76 | - if ($tracker_form->loadConfig($config) === FALSE) { | |
92 | + if (! $tracker_form->loadConfig($config)) { | |
77 | 93 | return '#tracker: ' . htmlspecialchars($tracker_form->error); |
78 | 94 | } |
79 | 95 | |
80 | 96 | // Load $template |
81 | - $form = $tracker_form->config->page . '/' . $form; | |
97 | + $form = ($form != '') ? $form : PLUGIN_TRACKER_DEFAULT_FORM; | |
98 | + $form = $tracker_form->config->page . '/' . $form; | |
82 | 99 | $template = plugin_tracker_get_source($form, TRUE); |
83 | 100 | if ($template === FALSE || empty($template)) { |
84 | 101 | return '#tracker: Form \'' . make_pagelink($form) . '\' not found<br />'; |
85 | 102 | } |
86 | 103 | |
87 | - if ($tracker_form->initFields(plugin_tracker_field_pickup($template)) === FALSE || | |
88 | - $tracker_form->initHiddenFields() === FALSE) { | |
104 | + if (! $tracker_form->initFields(plugin_tracker_field_pickup($template)) || | |
105 | + ! $tracker_form->initHiddenFields()) { | |
89 | 106 | return '#tracker: ' . htmlspecialchars($tracker_form->error); |
90 | 107 | } |
91 | 108 | $fields = $tracker_form->fields; |
@@ -125,6 +142,7 @@ function plugin_tracker_action() | ||
125 | 142 | if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing'); |
126 | 143 | |
127 | 144 | $base = isset($post['_base']) ? $post['_base'] : ''; |
145 | + | |
128 | 146 | $refer = isset($post['_refer']) ? $post['_refer'] : $base; |
129 | 147 | if (! is_pagename($refer)) { |
130 | 148 | return array( |
@@ -165,7 +183,7 @@ function plugin_tracker_action() | ||
165 | 183 | $from = $to = array(); |
166 | 184 | |
167 | 185 | $tracker_form = & new Tracker_form($base, $refer); |
168 | - if ($tracker_form->loadConfig($config) === FALSE) { | |
186 | + if (! $tracker_form->loadConfig($config)) { | |
169 | 187 | return array( |
170 | 188 | 'msg' => 'Cannot write', |
171 | 189 | 'body' => htmlspecialchars($tracker_form->error) |
@@ -182,7 +200,7 @@ function plugin_tracker_action() | ||
182 | 200 | ); |
183 | 201 | } |
184 | 202 | |
185 | - if ($tracker_form->initFields(plugin_tracker_field_pickup(implode('', $template))) === FALSE) { | |
203 | + if (! $tracker_form->initFields(plugin_tracker_field_pickup(implode('', $template)))) { | |
186 | 204 | return array( |
187 | 205 | 'msg' => 'Cannot write', |
188 | 206 | 'body' => htmlspecialchars($tracker_form->error) |
@@ -336,7 +354,7 @@ class Tracker_form | ||
336 | 354 | $field['default'] |
337 | 355 | ); |
338 | 356 | unset($raw_fields[$fieldname]); |
339 | - if ($err === FALSE) return FALSE; | |
357 | + if (! $err) return FALSE; | |
340 | 358 | } |
341 | 359 | } |
342 | 360 |
@@ -812,11 +830,12 @@ function plugin_tracker_list_convert() | ||
812 | 830 | { |
813 | 831 | global $vars; |
814 | 832 | |
815 | - $base = $refer = isset($vars['page']) ? $vars['page'] : ''; | |
833 | + $base = isset($vars['page']) ? $vars['page'] : ''; | |
834 | + $refer = $base; | |
816 | 835 | $config = ''; |
836 | + $order = ''; | |
817 | 837 | $list = ''; |
818 | 838 | $limit = NULL; |
819 | - $order = ''; | |
820 | 839 | |
821 | 840 | $args = func_get_args(); |
822 | 841 | $argc = count($args); |
@@ -827,11 +846,12 @@ function plugin_tracker_list_convert() | ||
827 | 846 | case 4: $limit = $args[3]; /*FALLTHROUGH*/ |
828 | 847 | case 3: $order = $args[2]; /*FALLTHROUGH*/ |
829 | 848 | case 2: |
849 | + // Set $base | |
830 | 850 | $arg = get_fullname($args[1], $base); |
831 | 851 | if (is_pagename($arg)) $base = $arg; |
832 | 852 | /*FALLTHROUGH*/ |
833 | 853 | case 1: |
834 | - // Config/list | |
854 | + // Set "$config/$list" | |
835 | 855 | if ($args[0] != '') { |
836 | 856 | $arg = explode('/', $args[0], 2); |
837 | 857 | if ($arg[0] != '' ) $config = $arg[0]; |
@@ -845,26 +865,23 @@ function plugin_tracker_list_convert() | ||
845 | 865 | |
846 | 866 | function plugin_tracker_list_action() |
847 | 867 | { |
848 | - global $get, $vars; | |
849 | - | |
850 | - $base = isset($get['base']) ? $get['base'] : ''; // Base directory to load | |
851 | - | |
852 | - if (isset($get['refer'])) { | |
853 | - $refer = $get['refer']; // Where to #tracker_list | |
854 | - if ($base == '') $base = $refer; | |
855 | - } else { | |
856 | - $refer = $base; | |
857 | - } | |
868 | + global $get; | |
858 | 869 | |
870 | + $base = isset($get['base']) ? $get['base'] : ''; | |
871 | + $refer = isset($get['refer']) ? $get['refer'] : $base; | |
859 | 872 | $config = isset($get['config']) ? $get['config'] : ''; |
860 | - $list = isset($get['list']) ? $get['list'] : ''; | |
861 | 873 | $order = isset($get['order']) ? $get['order'] : ''; |
874 | + $list = isset($get['list']) ? $get['list'] : ''; | |
862 | 875 | $limit = isset($get['limit']) ? $get['limit'] : NULL; |
863 | 876 | |
877 | + if ($base == '') $base = $refer; // Compat | |
878 | + | |
864 | 879 | $s_refer = make_pagelink($refer); |
880 | + | |
865 | 881 | return array( |
866 | 882 | 'msg' => plugin_tracker_message('msg_list'), |
867 | - 'body'=> str_replace('$1', $s_refer, plugin_tracker_message('msg_back')) . | |
883 | + 'body'=> | |
884 | + str_replace('$1', $s_refer, plugin_tracker_message('msg_back')) . | |
868 | 885 | plugin_tracker_list_render($base, $refer, $config, $order, $list, $limit) |
869 | 886 | ); |
870 | 887 | } |
@@ -877,16 +894,16 @@ function plugin_tracker_list_render($base, $refer, $config = '', $order = '', $l | ||
877 | 894 | $order = trim($order); |
878 | 895 | $list = trim($list); |
879 | 896 | if ($config == '' ) $config = PLUGIN_TRACKER_DEFAULT_CONFIG; |
880 | - if ($list == '' ) $list = PLUGIN_TRACKER_DEFAULT_LIST; | |
881 | 897 | if ($order == '' ) $order = PLUGIN_TRACKER_DEFAULT_ORDER; |
898 | + if ($list == '' ) $list = PLUGIN_TRACKER_DEFAULT_LIST; | |
882 | 899 | if ($limit == NULL) $limit = PLUGIN_TRACKER_DEFAULT_LIMIT; |
883 | 900 | |
884 | 901 | if ($base == '') return '#tracker_list: Base not specified' . '<br />'; |
885 | 902 | if (! is_page($refer)) return '#tracker_list: Refer page not found: ' . htmlspecialchars($refer) . '<br />'; |
886 | 903 | |
887 | 904 | $tracker_list = & new Tracker_list($base, $refer); |
888 | - if ($tracker_list->loadConfig($config) === FALSE || | |
889 | - $tracker_list->setSortOrder($order) === FALSE) { | |
905 | + if (! $tracker_list->loadConfig($config) || | |
906 | + ! $tracker_list->setSortOrder($order)) { | |
890 | 907 | return '#tracker_list: ' . htmlspecialchars($tracker_list->error) . '<br />'; |
891 | 908 | } |
892 | 909 |