• 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

Revision0627c005f6071de8b788ac8f85a862b2c6d1e3ae (tree)
Zeit2007-09-30 21:28:14
Autorhenoheno <henoheno>
Commiterhenoheno

Log Message

Simplify: Creating $this->form->fields only just you need

Ä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.92 2007/09/30 08:32:58 henoheno Exp $
3+// $Id: tracker.inc.php,v 1.93 2007/09/30 12:28:14 henoheno Exp $
44 // Copyright (C) 2003-2005, 2007 PukiWiki Developers Team
55 // License: GPL v2 or (at your option) any later version
66 //
@@ -237,6 +237,8 @@ class Tracker_form
237237 var $raw_fields;
238238 var $fields = array();
239239
240+ var $error = ''; // Error message
241+
240242 function Tracker_form($base, $refer, $config)
241243 {
242244 static $id = 0; // Unique id per instance
@@ -276,11 +278,9 @@ class Tracker_form
276278 return TRUE;
277279 }
278280
279- function initFields($requests = array())
281+ function initFields($requests = NULL)
280282 {
281- if (isset($this->raw_fields)) {
282- $raw_fields = $this->raw_fields;
283- } else {
283+ if (! isset($this->raw_fields)) {
284284 $raw_fields = array();
285285 // From config
286286 foreach ($this->config->get('fields') as $field) {
@@ -312,11 +312,24 @@ class Tracker_form
312312 ) + $default;
313313 }
314314 $this->raw_fields = $raw_fields;
315+ } else {
316+ $raw_fields = $this->raw_fields;
315317 }
316318
317- if (! is_array($requests)) $requests = array($requests);
318- if ($requests) {
319- // A part of
319+ if ($requests === NULL) {
320+ // All
321+ foreach ($raw_fields as $fieldname => $field) {
322+ $this->addField(
323+ $fieldname,
324+ $field['display'],
325+ $field['type'],
326+ $field['options'],
327+ $field['default']
328+ );
329+ }
330+ } else {
331+ if (! is_array($requests)) $requests = array($requests);
332+ // A part of, specific order
320333 foreach ($requests as $fieldname) {
321334 if (isset($raw_fields[$fieldname])) {
322335 $field = $raw_fields[$fieldname];
@@ -328,21 +341,10 @@ class Tracker_form
328341 $field['default']
329342 );
330343 } else{
331- // TODO: Return an error: Invalid fieldname
332- // return FALSE;
344+ $this->error = 'Invalid fieldname: ' . $fieldname;
345+ return FALSE;
333346 }
334347 }
335- } else {
336- // All
337- foreach ($raw_fields as $fieldname => $field) {
338- $this->addField(
339- $fieldname,
340- $field['display'],
341- $field['type'],
342- $field['options'],
343- $field['default']
344- );
345- }
346348 }
347349
348350 return TRUE;
@@ -847,9 +849,6 @@ class Tracker_list
847849 $form = & new Tracker_form($base, $refer, $config);
848850 $this->form = $form;
849851 $this->list = $list;
850-
851- // TODO: Call with sort() and toString()
852- $this->form->initFields();
853852 }
854853
855854 // Add multiple pages at a time
@@ -1231,6 +1230,27 @@ class Tracker_list
12311230 return plugin_tracker_escape($str, $tfc);
12321231 }
12331232
1233+ // Loading template: Roughly checking listed fields from template
1234+ function fieldPickup($string = '')
1235+ {
1236+ if (! is_string($string) || empty($string)) return array();
1237+
1238+ $fieldnames = array();
1239+
1240+ $matches = array();
1241+ preg_match_all('/\[([^\[\]]+)\]/', $string, $matches);
1242+ unset($matches[0]);
1243+
1244+ foreach ($matches[1] as $match) {
1245+ $params = explode(',', $match, 2);
1246+ if (isset($params[0])) {
1247+ $fieldnames[$params[0]] = TRUE;
1248+ }
1249+ }
1250+
1251+ return array_keys($fieldnames);
1252+ }
1253+
12341254 // Output a part of Wiki text
12351255 function toString($limit = 0)
12361256 {
@@ -1238,38 +1258,24 @@ class Tracker_list
12381258 $source = array();
12391259 $regex = '/\[([^\[\]]+)\]/';
12401260
1241- // Loading template: Roughly checking listed fields
1242- $matches = array();
1243- $used_fieldname = array('_real' => TRUE);
1244- $template = plugin_tracker_get_source($list, TRUE);
1261+ // Loading template
1262+ $template = plugin_tracker_get_source($list, TRUE);
12451263 if ($template === FALSE || empty($template)) {
12461264 $this->error = 'Page not found or seems empty: ' . $template;
12471265 return FALSE;
12481266 }
1249- preg_match_all($regex, $template, $matches);
1250- unset($matches[0]);
1251- foreach ($matches[1] as $match) {
1252- $params = explode(',', $match);
1253- if (isset($params[0]) && ! isset($used_fieldname[$params[0]])) {
1254- $used_fieldname[$params[0]] = TRUE;
1255- }
1256- }
1257- unset($matches[1]);
1258- foreach (array_keys($this->orders) as $fieldname) {
1259- if (! isset($used_fieldname[$fieldname])) {
1260- $used_fieldname[$fieldname] = TRUE;
1261- }
1262- }
12631267
1264- // Remove unused $this->form->fields
1265- $fields = & $this->form->fields; // Modify
1266- $new_filds = array();
1267- foreach (array_keys($fields) as $fieldname) {
1268- if (isset($used_fieldname[$fieldname])) {
1269- $new_filds[$fieldname] = & $fields[$fieldname];
1270- }
1268+ // Creating $this->form->fields just you need
1269+ if ($this->form->initFields('_real') === FALSE) {
1270+ $this->error = $this->form->error;
1271+ return FALSE;
1272+ } else if ($this->form->initFields($this->fieldPickup($template)) === FALSE) {
1273+ $this->error = $this->form->error . ' at ' . $list;
1274+ return FALSE;
1275+ } else if ($this->form->initFields(array_keys($this->orders)) === FALSE) {
1276+ $this->error = $this->form->error . ' at sort setting';
1277+ return FALSE;
12711278 }
1272- $fields = $new_filds;
12731279
12741280 // Generate regex for $this->form->fields
12751281 if ($this->_generate_regex() === FALSE) return FALSE;
@@ -1279,7 +1285,10 @@ class Tracker_list
12791285
12801286 // Sort $this->rows
12811287 if ($this->sortRows() === FALSE) return FALSE;
1282- $rows = $this->rows;
1288+ $rows = $this->rows;
1289+
1290+
1291+
12831292
12841293 // toString()
12851294 $count = count($this->rows);