id = $pi ? $pi: (isset($_GET['id']) ? $_GET['id'] : 0); $this->id = (int) $this->id ; $this->loadIssue(); if (!$this->issue) { $this->jerr( "OPPS"); } $start = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0; $limit = isset($_REQUEST['limit']) ? (int) $_REQUEST['limit'] : 100; // fetch all the //DB_DataObject::debugLevel(1); $d = DB_DataObject::factory('mtrack_change'); $d->ontable = 'mtrack_ticket'; $d->onid = $this->id; $d->orderBy('changedate ASC'); // last first? $d->limit ($start, $limit); $d->audit = array(); $d->find(); $this->events = array(); while ($d->fetch()) { $this->events[$d->id] = clone($d); } /* $d = DB_DataObject::factory('mtrack_change_audit'); $d->whereAddIn('change_id', array_keys($this->events), 'int'); $d->find(); while ($d->fetch()) { $this->events[$d->change_id]->audit[] = clone($d); } */ foreach($this->events as $id=>$c) { echo $this->eventToHtml($c); } exit; //$this->renderEvents(); } function eventToHtml($e) { $preamble = 0; $cid = "comment:{$e->id}"; // tidied up by jquery.. $timestamp = $this->link->date($e->changedate, false); $comments = array(); // default is that something changed.. $type = 'Changed'; $comment_body = ''; $comment_title = ''; $comment_fields = array(); if (!empty($e->reason)) { $comments[] = $e->reason; $type = 'Comment added'; $comment_title = array_shift(explode("\n", $e->reason)); } $comment_fields = str_replace("\n", "
" , htmlspecialchars($e->cachedAuditToString()."\n")); //$comment_body .= "$label $citem[action]
\n"; $commit_info = array(); if ($comment_title && preg_match('/\(In \[changeset:([^,]+),([a-z0-9]+)\]\)(.*)$/i', $comment_title, $commit_info)) { $type = 'Commit'; $comment_title = '[' . $commit_info[2] . ']'.$commit_info[3]; } if ($this->id == $this->issue->created) { $type = 'Created'; $comment_title = 'Issue Created'; } $html = '
+ ' . $type.' #'.$e->id.' ' . (strlen($comment_title) ? $comment_title : $comment_fields) . ' ' . $this->link->username($e->person_id, array('no_image' => true, 'fullname' => true)) . ' - '.$timestamp.'
'; /* foreach ($this->effort as $eff) { $exp = (float)$eff['expended']; if ($eff['expended'] != 0) { $comment_body .= "spent $exp hours
\n"; $preamble++; } } */ if ($preamble) { $html .= "
\n"; $preamble = 0; } foreach ($comments as $cid => $text) { // look for changesets in the comments.. // and display them as expandable linsk.. $html .= '
' . htmlspecialchars($text) .
                "\n\n" .  $comment_fields . '
'; // MTrack_Wiki::format_to_html($text); } $html .= ''; if ($commit_info) { // list the files that where changed... //$html.= print_r($M, true); $rp = '/' . $commit_info[1] . '/' . $commit_info[2]; $fullrp = $rp; $repo = MTrackSCM::factory($rp); $cd = $repo->historyWithChangelog(null, 1, 'rev', $rp); //print_r($cd);exit; if (!is_array($cd->ent->files) || !count($cd->ent->files)) { return $html; } $num = count(array_keys($cd->ent->files)); $map = array( 'D' => 'DELETED', 'M' => 'MODIFIED', 'A' => 'ADDED' ); $file_summary = array(); foreach($map as $k=>$v) { $summary[$v] = 0; } foreach ($cd->ent->files as $id => $file) { $type = isset($map[$file->status]) ? $map[$file->status] : '??? '. $file->status; if ($num > 10) { // will bork on unknown... $summary[$type]++; continue; } $html .= '
+ ' . $type.' ' . $file->nameToHtml() . ' [View Diff] [View File] [View History]
'; } if ($num> 10) { $ar = array(); foreach($summary as $k=>$v) { if (empty($v)) { continue; } $ar[] = $v . ' ' . $k; } $html .= '
+ MULTIPLE FILES: ' . implode(', ', $ar) . ' [View Diff] [View File] [View History]
'; } //$html .= print_r($cd, true); } return $html ; } function collapse_diff($diff) { static $idnum = 1; require_once 'MTrackWeb/Changeset.php'; $cs = new MTrackWeb_Changeset(); $id = 'diff_' . $idnum++; return "
" . "". ""; } function diff_strings($before, $now) { $tempdir = sys_get_temp_dir(); $afile = tempnam($tempdir, "mtrack"); $bfile = tempnam($tempdir, "mtrack"); file_put_contents($afile, $before); file_put_contents($bfile, $now); static $diff = false; if (!$diff) { require_once 'System.php'; $diff= System::which('diff'); } if (PHP_OS == 'SunOS') { // TODO: make an option to allow use of gnu diff on solaris $diff = shell_exec("$diff -u $afile $bfile"); $diff = str_replace($afile, 'before', $diff); $diff = str_replace($bfile, 'now', $diff); } else { $diff = shell_exec("$diff --label before --label now -u $afile $bfile"); } unlink($afile); unlink($bfile); $diff = htmlentities($diff, ENT_COMPAT, 'utf-8'); return $diff; } }