PukiWiki PHP Cross Reference Collaborative Wikis

Source: /plugin/tracker.inc.php - 922 lines - 22982 bytes - Summary - Text - Print

   1  <?php
   2  // PukiWiki - Yet another WikiWikiWeb clone
   3  // $Id: tracker.inc.php,v 1.34 2005/11/28 17:48:30 teanan Exp $
   4  //
   5  // Issue tracker plugin (See Also bugtrack plugin)
   6  
   7  // tracker_listで表示しないページ名(正規表現で)
   8  // 'SubMenu'ページ および '/'を含むページを除外する
   9  define('TRACKER_LIST_EXCLUDE_PATTERN','#^SubMenu$|/#');
  10  // 制限しない場合はこちら
  11  //define('TRACKER_LIST_EXCLUDE_PATTERN','#(?!)#');
  12  
  13  // 項目の取り出しに失敗したページを一覧に表示する
  14  define('TRACKER_LIST_SHOW_ERROR_PAGE',TRUE);
  15  
  16  function plugin_tracker_convert()
  17  {
  18      global $script,$vars;
  19  
  20      if (PKWK_READONLY) return ''; // Show nothing
  21  
  22      $base = $refer = $vars['page'];
  23  
  24      $config_name = 'default';
  25      $form = 'form';
  26      $options = array();
  27      if (func_num_args())
  28      {
  29          $args = func_get_args();
  30          switch (count($args))
  31          {
  32              case 3:
  33                  $options = array_splice($args,2);
  34              case 2:
  35                  $args[1] = get_fullname($args[1],$base);
  36                  $base = is_pagename($args[1]) ? $args[1] : $base;
  37              case 1:
  38                  $config_name = ($args[0] != '') ? $args[0] : $config_name;
  39                  list($config_name,$form) = array_pad(explode('/',$config_name,2),2,$form);
  40          }
  41      }
  42  
  43      $config = new Config('plugin/tracker/'.$config_name);
  44  
  45      if (!$config->read())
  46      {
  47          return "<p>config file '".htmlspecialchars($config_name)."' not found.</p>";
  48      }
  49  
  50      $config->config_name = $config_name;
  51  
  52      $fields = plugin_tracker_get_fields($base,$refer,$config);
  53  
  54      $form = $config->page.'/'.$form;
  55      if (!is_page($form))
  56      {
  57          return "<p>config file '".make_pagelink($form)."' not found.</p>";
  58      }
  59      $retval = convert_html(plugin_tracker_get_source($form));
  60      $hiddens = '';
  61  
  62      foreach (array_keys($fields) as $name)
  63      {
  64          $replace = $fields[$name]->get_tag();
  65          if (is_a($fields[$name],'Tracker_field_hidden'))
  66          {
  67              $hiddens .= $replace;
  68              $replace = '';
  69          }
  70          $retval = str_replace("[$name]",$replace,$retval);
  71      }
  72      return <<<EOD
  73  <form enctype="multipart/form-data" action="$script" method="post">
  74  <div>
  75  $retval
  76  $hiddens
  77  </div>
  78  </form>
  79  EOD;
  80  }
  81  function plugin_tracker_action()
  82  {
  83      global $post, $vars, $now;
  84  
  85      if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
  86  
  87      $config_name = array_key_exists('_config',$post) ? $post['_config'] : '';
  88  
  89      $config = new Config('plugin/tracker/'.$config_name);
  90      if (!$config->read())
  91      {
  92          return "<p>config file '".htmlspecialchars($config_name)."' not found.</p>";
  93      }
  94      $config->config_name = $config_name;
  95      $source = $config->page.'/page';
  96  
  97      $refer = array_key_exists('_refer',$post) ? $post['_refer'] : $post['_base'];
  98  
  99      if (!is_pagename($refer))
 100      {
 101          return array(
 102              'msg'=>'cannot write',
 103              'body'=>'page name ('.htmlspecialchars($refer).') is not valid.'
 104          );
 105      }
 106      if (!is_page($source))
 107      {
 108          return array(
 109              'msg'=>'cannot write',
 110              'body'=>'page template ('.htmlspecialchars($source).') is not exist.'
 111          );
 112      }
 113      // ページ名を決定
 114      $base = $post['_base'];
 115      $num = 0;
 116      $name = (array_key_exists('_name',$post)) ? $post['_name'] : '';
 117      if (array_key_exists('_page',$post))
 118      {
 119          $page = $real = $post['_page'];
 120      }
 121      else
 122      {
 123          $real = is_pagename($name) ? $name : ++$num;
 124          $page = get_fullname('./'.$real,$base);
 125      }
 126      if (!is_pagename($page))
 127      {
 128          $page = $base;
 129      }
 130  
 131      while (is_page($page))
 132      {
 133          $real = ++$num;
 134          $page = "$base/$real";
 135      }
 136      // ページデータを生成
 137      $postdata = plugin_tracker_get_source($source);
 138  
 139      // 規定のデータ
 140      $_post = array_merge($post,$_FILES);
 141      $_post['_date'] = $now;
 142      $_post['_page'] = $page;
 143      $_post['_name'] = $name;
 144      $_post['_real'] = $real;
 145      // $_post['_refer'] = $_post['refer'];
 146  
 147      $fields = plugin_tracker_get_fields($page,$refer,$config);
 148  
 149      // Creating an empty page, before attaching files
 150      touch(get_filename($page));
 151  
 152      foreach (array_keys($fields) as $key)
 153      {
 154          $value = array_key_exists($key,$_post) ?
 155              $fields[$key]->format_value($_post[$key]) : '';
 156  
 157          foreach (array_keys($postdata) as $num)
 158          {
 159              if (trim($postdata[$num]) == '')
 160              {
 161                  continue;
 162              }
 163              $postdata[$num] = str_replace(
 164                  "[$key]",
 165                  ($postdata[$num]{0} == '|' or $postdata[$num]{0} == ':') ?
 166                      str_replace('|','&#x7c;',$value) : $value,
 167                  $postdata[$num]
 168              );
 169          }
 170      }
 171  
 172      // Writing page data, without touch
 173      page_write($page, join('', $postdata));
 174  
 175      $r_page = rawurlencode($page);
 176  
 177      pkwk_headers_sent();
 178      header('Location: ' . get_script_uri() . '?' . $r_page);
 179      exit;
 180  }
 181  /*
 182  function plugin_tracker_inline()
 183  {
 184      global $vars;
 185  
 186      if (PKWK_READONLY) return ''; // Show nothing
 187  
 188      $args = func_get_args();
 189      if (count($args) < 3)
 190      {
 191          return FALSE;
 192      }
 193      $body = array_pop($args);
 194      list($config_name,$field) = $args;
 195  
 196      $config = new Config('plugin/tracker/'.$config_name);
 197  
 198      if (!$config->read())
 199      {
 200          return "config file '".htmlspecialchars($config_name)."' not found.";
 201      }
 202  
 203      $config->config_name = $config_name;
 204  
 205      $fields = plugin_tracker_get_fields($vars['page'],$vars['page'],$config);
 206      $fields[$field]->default_value = $body;
 207      return $fields[$field]->get_tag();
 208  }
 209  */
 210  // フィールドオブジェクトを構築する
 211  function plugin_tracker_get_fields($base,$refer,&$config)
 212  {
 213      global $now,$_tracker_messages;
 214  
 215      $fields = array();
 216      // 予約語
 217      foreach (array(
 218          '_date'=>'text',    // 投稿日時
 219          '_update'=>'date',  // 最終更新
 220          '_past'=>'past',    // 経過(passage)
 221          '_page'=>'page',    // ページ名
 222          '_name'=>'text',    // 指定されたページ名
 223          '_real'=>'real',    // 実際のページ名
 224          '_refer'=>'page',   // 参照元(フォームのあるページ)
 225          '_base'=>'page',    // 基準ページ
 226          '_submit'=>'submit' // 追加ボタン
 227          ) as $field=>$class)
 228      {
 229          $class = 'Tracker_field_'.$class;
 230          $fields[$field] = &new $class(array($field,$_tracker_messages["btn$field"],'','20',''),$base,$refer,$config);
 231      }
 232  
 233      foreach ($config->get('fields') as $field)
 234      {
 235          // 0=>項目名 1=>見出し 2=>形式 3=>オプション 4=>デフォルト値
 236          $class = 'Tracker_field_'.$field[2];
 237          if (!class_exists($class))
 238          { // デフォルト
 239              $class = 'Tracker_field_text';
 240              $field[2] = 'text';
 241              $field[3] = '20';
 242          }
 243          $fields[$field[0]] = &new $class($field,$base,$refer,$config);
 244      }
 245      return $fields;
 246  }
 247  // フィールドクラス
 248  class Tracker_field
 249  {
 250      var $name;
 251      var $title;
 252      var $values;
 253      var $default_value;
 254      var $page;
 255      var $refer;
 256      var $config;
 257      var $data;
 258      var $sort_type = SORT_REGULAR;
 259      var $id = 0;
 260  
 261  	function Tracker_field($field,$page,$refer,&$config)
 262      {
 263          global $post;
 264          static $id = 0;
 265  
 266          $this->id = ++$id;
 267          $this->name = $field[0];
 268          $this->title = $field[1];
 269          $this->values = explode(',',$field[3]);
 270          $this->default_value = $field[4];
 271          $this->page = $page;
 272          $this->refer = $refer;
 273          $this->config = &$config;
 274          $this->data = array_key_exists($this->name,$post) ? $post[$this->name] : '';
 275      }
 276  	function get_tag()
 277      {
 278      }
 279  	function get_style($str)
 280      {
 281          return '%s';
 282      }
 283  	function format_value($value)
 284      {
 285          return $value;
 286      }
 287  	function format_cell($str)
 288      {
 289          return $str;
 290      }
 291  	function get_value($value)
 292      {
 293          return $value;
 294      }
 295  }
 296  class Tracker_field_text extends Tracker_field
 297  {
 298      var $sort_type = SORT_STRING;
 299  
 300  	function get_tag()
 301      {
 302          $s_name = htmlspecialchars($this->name);
 303          $s_size = htmlspecialchars($this->values[0]);
 304          $s_value = htmlspecialchars($this->default_value);
 305          return "<input type=\"text\" name=\"$s_name\" size=\"$s_size\" value=\"$s_value\" />";
 306      }
 307  }
 308  class Tracker_field_page extends Tracker_field_text
 309  {
 310      var $sort_type = SORT_STRING;
 311  
 312  	function format_value($value)
 313      {
 314          global $WikiName;
 315  
 316          $value = strip_bracket($value);
 317          if (is_pagename($value))
 318          {
 319              $value = "[[$value]]";
 320          }
 321          return parent::format_value($value);
 322      }
 323  }
 324  class Tracker_field_real extends Tracker_field_text
 325  {
 326      var $sort_type = SORT_REGULAR;
 327  }
 328  class Tracker_field_title extends Tracker_field_text
 329  {
 330      var $sort_type = SORT_STRING;
 331  
 332  	function format_cell($str)
 333      {
 334          make_heading($str);
 335          return $str;
 336      }
 337  }
 338  class Tracker_field_textarea extends Tracker_field
 339  {
 340      var $sort_type = SORT_STRING;
 341  
 342  	function get_tag()
 343      {
 344          $s_name = htmlspecialchars($this->name);
 345          $s_cols = htmlspecialchars($this->values[0]);
 346          $s_rows = htmlspecialchars($this->values[1]);
 347          $s_value = htmlspecialchars($this->default_value);
 348          return "<textarea name=\"$s_name\" cols=\"$s_cols\" rows=\"$s_rows\">$s_value</textarea>";
 349      }
 350  	function format_cell($str)
 351      {
 352          $str = preg_replace('/[\r\n]+/','',$str);
 353          if (!empty($this->values[2]) and strlen($str) > ($this->values[2] + 3))
 354          {
 355              $str = mb_substr($str,0,$this->values[2]).'...';
 356          }
 357          return $str;
 358      }
 359  }
 360  class Tracker_field_format extends Tracker_field
 361  {
 362      var $sort_type = SORT_STRING;
 363  
 364      var $styles = array();
 365      var $formats = array();
 366  
 367  	function Tracker_field_format($field,$page,$refer,&$config)
 368      {
 369          parent::Tracker_field($field,$page,$refer,$config);
 370  
 371          foreach ($this->config->get($this->name) as $option)
 372          {
 373              list($key,$style,$format) = array_pad(array_map(create_function('$a','return trim($a);'),$option),3,'');
 374              if ($style != '')
 375              {
 376                  $this->styles[$key] = $style;
 377              }
 378              if ($format != '')
 379              {
 380                  $this->formats[$key] = $format;
 381              }
 382          }
 383      }
 384  	function get_tag()
 385      {
 386          $s_name = htmlspecialchars($this->name);
 387          $s_size = htmlspecialchars($this->values[0]);
 388          return "<input type=\"text\" name=\"$s_name\" size=\"$s_size\" />";
 389      }
 390  	function get_key($str)
 391      {
 392          return ($str == '') ? 'IS NULL' : 'IS NOT NULL';
 393      }
 394  	function format_value($str)
 395      {
 396          if (is_array($str))
 397          {
 398              return join(', ',array_map(array($this,'format_value'),$str));
 399          }
 400          $key = $this->get_key($str);
 401          return array_key_exists($key,$this->formats) ? str_replace('%s',$str,$this->formats[$key]) : $str;
 402      }
 403  	function get_style($str)
 404      {
 405          $key = $this->get_key($str);
 406          return array_key_exists($key,$this->styles) ? $this->styles[$key] : '%s';
 407      }
 408  }
 409  class Tracker_field_file extends Tracker_field_format
 410  {
 411      var $sort_type = SORT_STRING;
 412  
 413  	function get_tag()
 414      {
 415          $s_name = htmlspecialchars($this->name);
 416          $s_size = htmlspecialchars($this->values[0]);
 417          return "<input type=\"file\" name=\"$s_name\" size=\"$s_size\" />";
 418      }
 419  	function format_value($str)
 420      {
 421          if (array_key_exists($this->name,$_FILES))
 422          {
 423              require_once (PLUGIN_DIR.'attach.inc.php');
 424              $result = attach_upload($_FILES[$this->name],$this->page);
 425              if ($result['result']) // アップロード成功
 426              {
 427                  return parent::format_value($this->page.'/'.$_FILES[$this->name]['name']);
 428              }
 429          }
 430          // ファイルが指定されていないか、アップロードに失敗
 431          return parent::format_value('');
 432      }
 433  }
 434  class Tracker_field_radio extends Tracker_field_format
 435  {
 436      var $sort_type = SORT_NUMERIC;
 437  
 438  	function get_tag()
 439      {
 440          $s_name = htmlspecialchars($this->name);
 441          $retval = '';
 442          $id = 0;
 443          foreach ($this->config->get($this->name) as $option)
 444          {
 445              $s_option = htmlspecialchars($option[0]);
 446              $checked = trim($option[0]) == trim($this->default_value) ? ' checked="checked"' : '';
 447              ++$id;
 448              $s_id = '_p_tracker_' . $s_name . '_' . $this->id . '_' . $id;
 449              $retval .= '<input type="radio" name="' .  $s_name . '" id="' . $s_id .
 450                  '" value="' . $s_option . '"' . $checked . ' />' .
 451                  '<label for="' . $s_id . '">' . $s_option . '</label>' . "\n";
 452          }
 453  
 454          return $retval;
 455      }
 456  	function get_key($str)
 457      {
 458          return $str;
 459      }
 460  	function get_value($value)
 461      {
 462          static $options = array();
 463          if (!array_key_exists($this->name,$options))
 464          {
 465              $options[$this->name] = array_flip(array_map(create_function('$arr','return $arr[0];'),$this->config->get($this->name)));
 466          }
 467          return array_key_exists($value,$options[$this->name]) ? $options[$this->name][$value] : $value;
 468      }
 469  }
 470  class Tracker_field_select extends Tracker_field_radio
 471  {
 472      var $sort_type = SORT_NUMERIC;
 473  
 474  	function get_tag($empty=FALSE)
 475      {
 476          $s_name = htmlspecialchars($this->name);
 477          $s_size = (array_key_exists(0,$this->values) and is_numeric($this->values[0])) ?
 478              ' size="'.htmlspecialchars($this->values[0]).'"' : '';
 479          $s_multiple = (array_key_exists(1,$this->values) and strtolower($this->values[1]) == 'multiple') ?
 480              ' multiple="multiple"' : '';
 481          $retval = "<select name=\"{$s_name}[]\"$s_size$s_multiple>\n";
 482          if ($empty)
 483          {
 484              $retval .= " <option value=\"\"></option>\n";
 485          }
 486          $defaults = array_flip(preg_split('/\s*,\s*/',$this->default_value,-1,PREG_SPLIT_NO_EMPTY));
 487          foreach ($this->config->get($this->name) as $option)
 488          {
 489              $s_option = htmlspecialchars($option[0]);
 490              $selected = array_key_exists(trim($option[0]),$defaults) ? ' selected="selected"' : '';
 491              $retval .= " <option value=\"$s_option\"$selected>$s_option</option>\n";
 492          }
 493          $retval .= "</select>";
 494  
 495          return $retval;
 496      }
 497  }
 498  class Tracker_field_checkbox extends Tracker_field_radio
 499  {
 500      var $sort_type = SORT_NUMERIC;
 501  
 502  	function get_tag($empty=FALSE)
 503      {
 504          $s_name = htmlspecialchars($this->name);
 505          $defaults = array_flip(preg_split('/\s*,\s*/',$this->default_value,-1,PREG_SPLIT_NO_EMPTY));
 506          $retval = '';
 507          $id = 0;
 508          foreach ($this->config->get($this->name) as $option)
 509          {
 510              $s_option = htmlspecialchars($option[0]);
 511              $checked = array_key_exists(trim($option[0]),$defaults) ?
 512                  ' checked="checked"' : '';
 513              ++$id;
 514              $s_id = '_p_tracker_' . $s_name . '_' . $this->id . '_' . $id;
 515              $retval .= '<input type="checkbox" name="' . $s_name .
 516                  '[]" id="' . $s_id . '" value="' . $s_option . '"' . $checked . ' />' .
 517                  '<label for="' . $s_id . '">' . $s_option . '</label>' . "\n";
 518          }
 519  
 520          return $retval;
 521      }
 522  }
 523  class Tracker_field_hidden extends Tracker_field_radio
 524  {
 525      var $sort_type = SORT_NUMERIC;
 526  
 527  	function get_tag($empty=FALSE)
 528      {
 529          $s_name = htmlspecialchars($this->name);
 530          $s_default = htmlspecialchars($this->default_value);
 531          $retval = "<input type=\"hidden\" name=\"$s_name\" value=\"$s_default\" />\n";
 532  
 533          return $retval;
 534      }
 535  }
 536  class Tracker_field_submit extends Tracker_field
 537  {
 538  	function get_tag()
 539      {
 540          $s_title = htmlspecialchars($this->title);
 541          $s_page = htmlspecialchars($this->page);
 542          $s_refer = htmlspecialchars($this->refer);
 543          $s_config = htmlspecialchars($this->config->config_name);
 544  
 545          return <<<EOD
 546  <input type="submit" value="$s_title" />
 547  <input type="hidden" name="plugin" value="tracker" />
 548  <input type="hidden" name="_refer" value="$s_refer" />
 549  <input type="hidden" name="_base" value="$s_page" />
 550  <input type="hidden" name="_config" value="$s_config" />
 551  EOD;
 552      }
 553  }
 554  class Tracker_field_date extends Tracker_field
 555  {
 556      var $sort_type = SORT_NUMERIC;
 557  
 558  	function format_cell($timestamp)
 559      {
 560          return format_date($timestamp);
 561      }
 562  }
 563  class Tracker_field_past extends Tracker_field
 564  {
 565      var $sort_type = SORT_NUMERIC;
 566  
 567  	function format_cell($timestamp)
 568      {
 569          return get_passage($timestamp,FALSE);
 570      }
 571  	function get_value($value)
 572      {
 573          return UTIME - $value;
 574      }
 575  }
 576  ///////////////////////////////////////////////////////////////////////////
 577  // 一覧表示
 578  function plugin_tracker_list_convert()
 579  {
 580      global $vars;
 581  
 582      $config = 'default';
 583      $page = $refer = $vars['page'];
 584      $field = '_page';
 585      $order = '';
 586      $list = 'list';
 587      $limit = NULL;
 588      if (func_num_args())
 589      {
 590          $args = func_get_args();
 591          switch (count($args))
 592          {
 593              case 4:
 594                  $limit = is_numeric($args[3]) ? $args[3] : $limit;
 595              case 3:
 596                  $order = $args[2];
 597              case 2:
 598                  $args[1] = get_fullname($args[1],$page);
 599                  $page = is_pagename($args[1]) ? $args[1] : $page;
 600              case 1:
 601                  $config = ($args[0] != '') ? $args[0] : $config;
 602                  list($config,$list) = array_pad(explode('/',$config,2),2,$list);
 603          }
 604      }
 605      return plugin_tracker_getlist($page,$refer,$config,$list,$order,$limit);
 606  }
 607  function plugin_tracker_list_action()
 608  {
 609      global $script,$vars,$_tracker_messages;
 610  
 611      $page = $refer = $vars['refer'];
 612      $s_page = make_pagelink($page);
 613      $config = $vars['config'];
 614      $list = array_key_exists('list',$vars) ? $vars['list'] : 'list';
 615      $order = array_key_exists('order',$vars) ? $vars['order'] : '_real:SORT_DESC';
 616  
 617      return array(
 618          'msg' => $_tracker_messages['msg_list'],
 619          'body'=> str_replace('$1',$s_page,$_tracker_messages['msg_back']).
 620              plugin_tracker_getlist($page,$refer,$config,$list,$order)
 621      );
 622  }
 623  function plugin_tracker_getlist($page,$refer,$config_name,$list,$order='',$limit=NULL)
 624  {
 625      $config = new Config('plugin/tracker/'.$config_name);
 626  
 627      if (!$config->read())
 628      {
 629          return "<p>config file '".htmlspecialchars($config_name)."' is not exist.";
 630      }
 631  
 632      $config->config_name = $config_name;
 633  
 634      if (!is_page($config->page.'/'.$list))
 635      {
 636          return "<p>config file '".make_pagelink($config->page.'/'.$list)."' not found.</p>";
 637      }
 638  
 639      $list = &new Tracker_list($page,$refer,$config,$list);
 640      $list->sort($order);
 641      return $list->toString($limit);
 642  }
 643  
 644  // 一覧クラス
 645  class Tracker_list
 646  {
 647      var $page;
 648      var $config;
 649      var $list;
 650      var $fields;
 651      var $pattern;
 652      var $pattern_fields;
 653      var $rows;
 654      var $order;
 655  
 656  	function Tracker_list($page,$refer,&$config,$list)
 657      {
 658          $this->page = $page;
 659          $this->config = &$config;
 660          $this->list = $list;
 661          $this->fields = plugin_tracker_get_fields($page,$refer,$config);
 662  
 663          $pattern = join('',plugin_tracker_get_source($config->page.'/page'));
 664          // ブロックプラグインをフィールドに置換
 665          // #commentなどで前後に文字列の増減があった場合に、[_block_xxx]に吸い込ませるようにする
 666          $pattern = preg_replace('/^\#([^\(\s]+)(?:\((.*)\))?\s*$/m','[_block_$1]',$pattern);
 667  
 668          // パターンを生成
 669          $this->pattern = '';
 670          $this->pattern_fields = array();
 671          $pattern = preg_split('/\\\\\[(\w+)\\\\\]/',preg_quote($pattern,'/'),-1,PREG_SPLIT_DELIM_CAPTURE);
 672          while (count($pattern))
 673          {
 674              $this->pattern .= preg_replace('/\s+/','\\s*','(?>\\s*'.trim(array_shift($pattern)).'\\s*)');
 675              if (count($pattern))
 676              {
 677                  $field = array_shift($pattern);
 678                  $this->pattern_fields[] = $field;
 679                  $this->pattern .= '(.*)';
 680              }
 681          }
 682          // ページの列挙と取り込み
 683          $this->rows = array();
 684          $pattern = "$page/";
 685          $pattern_len = strlen($pattern);
 686          foreach (get_existpages() as $_page)
 687          {
 688              if (strpos($_page,$pattern) === 0)
 689              {
 690                  $name = substr($_page,$pattern_len);
 691                  if (preg_match(TRACKER_LIST_EXCLUDE_PATTERN,$name))
 692                  {
 693                      continue;
 694                  }
 695                  $this->add($_page,$name);
 696              }
 697          }
 698      }
 699  	function add($page,$name)
 700      {
 701          static $moved = array();
 702  
 703          // 無限ループ防止
 704          if (array_key_exists($name,$this->rows))
 705          {
 706              return;
 707          }
 708  
 709          $source = plugin_tracker_get_source($page);
 710          if (preg_match('/move\sto\s(.+)/',$source[0],$matches))
 711          {
 712              $page = strip_bracket(trim($matches[1]));
 713              if (array_key_exists($page,$moved) or !is_page($page))
 714              {
 715                  return;
 716              }
 717              $moved[$page] = TRUE;
 718              return $this->add($page,$name);
 719          }
 720          $source = join('',preg_replace('/^(\*{1,3}.*)\[#[A-Za-z][\w-]+\](.*)$/','$1$2',$source));
 721  
 722          // デフォルト値
 723          $this->rows[$name] = array(
 724              '_page'  => "[[$page]]",
 725              '_refer' => $this->page,
 726              '_real'  => $name,
 727              '_update'=> get_filetime($page),
 728              '_past'  => get_filetime($page)
 729          );
 730          if ($this->rows[$name]['_match'] = preg_match("/{$this->pattern}/s",$source,$matches))
 731          {
 732              array_shift($matches);
 733              foreach ($this->pattern_fields as $key=>$field)
 734              {
 735                  $this->rows[$name][$field] = trim($matches[$key]);
 736              }
 737          }
 738      }
 739  	function sort($order)
 740      {
 741          if ($order == '')
 742          {
 743              return;
 744          }
 745          $names = array_flip(array_keys($this->fields));
 746          $this->order = array();
 747          foreach (explode(';',$order) as $item)
 748          {
 749              list($key,$dir) = array_pad(explode(':',$item),1,'ASC');
 750              if (!array_key_exists($key,$names))
 751              {
 752                  continue;
 753              }
 754              switch (strtoupper($dir))
 755              {
 756                  case 'SORT_ASC':
 757                  case 'ASC':
 758                  case SORT_ASC:
 759                      $dir = SORT_ASC;
 760                      break;
 761                  case 'SORT_DESC':
 762                  case 'DESC':
 763                  case SORT_DESC:
 764                      $dir = SORT_DESC;
 765                      break;
 766                  default:
 767                      continue;
 768              }
 769              $this->order[$key] = $dir;
 770          }
 771          $keys = array();
 772          $params = array();
 773          foreach ($this->order as $field=>$order)
 774          {
 775              if (!array_key_exists($field,$names))
 776              {
 777                  continue;
 778              }
 779              foreach ($this->rows as $row)
 780              {
 781                  $keys[$field][] = isset($row[$field])? $this->fields[$field]->get_value($row[$field]) : '';
 782              }
 783              $params[] = $keys[$field];
 784              $params[] = $this->fields[$field]->sort_type;
 785              $params[] = $order;
 786  
 787          }
 788          $params[] = &$this->rows;
 789  
 790          call_user_func_array('array_multisort',$params);
 791      }
 792  	function replace_item($arr)
 793      {
 794          $params = explode(',',$arr[1]);
 795          $name = array_shift($params);
 796          if ($name == '')
 797          {
 798              $str = '';
 799          }
 800          else if (array_key_exists($name,$this->items))
 801          {
 802              $str = $this->items[$name];
 803              if (array_key_exists($name,$this->fields))
 804              {
 805                  $str = $this->fields[$name]->format_cell($str);
 806              }
 807          }
 808          else
 809          {
 810              return $this->pipe ? str_replace('|','&#x7c;',$arr[0]) : $arr[0];
 811          }
 812          $style = count($params) ? $params[0] : $name;
 813          if (array_key_exists($style,$this->items)
 814              and array_key_exists($style,$this->fields))
 815          {
 816              $str = sprintf($this->fields[$style]->get_style($this->items[$style]),$str);
 817          }
 818          return $this->pipe ? str_replace('|','&#x7c;',$str) : $str;
 819      }
 820  	function replace_title($arr)
 821      {
 822          global $script;
 823  
 824          $field = $sort = $arr[1];
 825          if ($sort == '_name' or $sort == '_page')
 826          {
 827              $sort = '_real';
 828          }
 829          if (!array_key_exists($field,$this->fields))
 830          {
 831              return $arr[0];
 832          }
 833          $dir = SORT_ASC;
 834          $arrow = '';
 835          $order = $this->order;
 836  
 837          if (is_array($order) && isset($order[$sort]))
 838          {
 839              // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5
 840              $order_keys = array_keys($order); // with array_shift();
 841  
 842              $index = array_flip($order_keys);
 843              $pos = 1 + $index[$sort];
 844              $b_end = ($sort == array_shift($order_keys));
 845              $b_order = ($order[$sort] == SORT_ASC);
 846              $dir = ($b_end xor $b_order) ? SORT_ASC : SORT_DESC;
 847              $arrow = '&br;'.($b_order ? '&uarr;' : '&darr;')."($pos)";
 848  
 849              unset($order[$sort], $order_keys);
 850          }
 851          $title = $this->fields[$field]->title;
 852          $r_page = rawurlencode($this->page);
 853          $r_config = rawurlencode($this->config->config_name);
 854          $r_list = rawurlencode($this->list);
 855          $_order = array("$sort:$dir");
 856          if (is_array($order))
 857              foreach ($order as $key=>$value)
 858                  $_order[] = "$key:$value";
 859          $r_order = rawurlencode(join(';',$_order));
 860  
 861          return "[[$title$arrow>$script?plugin=tracker_list&refer=$r_page&config=$r_config&list=$r_list&order=$r_order]]";
 862      }
 863  	function toString($limit=NULL)
 864      {
 865          global $_tracker_messages;
 866  
 867          $source = '';
 868          $body = array();
 869  
 870          if ($limit !== NULL and count($this->rows) > $limit)
 871          {
 872              $source = str_replace(
 873                  array('$1','$2'),
 874                  array(count($this->rows),$limit),
 875                  $_tracker_messages['msg_limit'])."\n";
 876              $this->rows = array_splice($this->rows,0,$limit);
 877          }
 878          if (count($this->rows) == 0)
 879          {
 880              return '';
 881          }
 882          foreach (plugin_tracker_get_source($this->config->page.'/'.$this->list) as $line)
 883          {
 884              if (preg_match('/^\|(.+)\|[hHfFcC]$/',$line))
 885              {
 886                  $source .= preg_replace_callback('/\[([^\[\]]+)\]/',array(&$this,'replace_title'),$line);
 887              }
 888              else
 889              {
 890                  $body[] = $line;
 891              }
 892          }
 893          foreach ($this->rows as $key=>$row)
 894          {
 895              if (!TRACKER_LIST_SHOW_ERROR_PAGE and !$row['_match'])
 896              {
 897                  continue;
 898              }
 899              $this->items = $row;
 900              foreach ($body as $line)
 901              {
 902                  if (trim($line) == '')
 903                  {
 904                      $source .= $line;
 905                      continue;
 906                  }
 907                  $this->pipe = ($line{0} == '|' or $line{0} == ':');
 908                  $source .= preg_replace_callback('/\[([^\[\]]+)\]/',array(&$this,'replace_item'),$line);
 909              }
 910          }
 911          return convert_html($source);
 912      }
 913  }
 914  function plugin_tracker_get_source($page)
 915  {
 916      $source = get_source($page);
 917      // 見出しの固有ID部を削除
 918      $source = preg_replace('/^(\*{1,3}.*)\[#[A-Za-z][\w-]+\](.*)$/m','$1$2',$source);
 919      // #freezeを削除
 920      return preg_replace('/^#freeze\s*$/im', '', $source);
 921  }
 922  ?>

title

Description

title

Description

title

Description

title

title

Body