project = $request->project; $this->request = $request; $this->scm = IDF_Scm::get($request); if ($wordwrap) $text = wordwrap($text, 69, "\n", true); if ($esc) $text = Pluf_esc($text); $text = ereg_replace('[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]', '\\0', $text); if ($request->rights['hasIssuesAccess']) { $text = preg_replace_callback('#(issues?|bugs?|tickets?)\s+(\d+)((\s+and|\s+or|,)\s+(\d+)){0,}#im', array($this, 'callbackIssues'), $text); } if ($request->rights['hasSourceAccess']) { $text = preg_replace_callback('#(commit\s+)([0-9a-f]{1,40})#im', array($this, 'callbackCommit'), $text); } if ($echo) { echo $text; } else { return $text; } } /** * General call back for the issues. */ function callbackIssues($m) { if (count($m) == 3) { $issue = new IDF_Issue($m[2]); if ($issue->id > 0 and $issue->project == $this->project->id) { return $this->linkIssue($issue, $m[1].' '.$m[2]); } else { return $m[0]; // not existing issue. } } else { return preg_replace_callback('/(\d+)/', array($this, 'callbackIssue'), $m[0]); } } /** * Call back for the case of multiple issues like 'issues 1, 2 and 3'. * * Called from callbackIssues, it is linking only the number of * the issues. */ function callbackIssue($m) { $issue = new IDF_Issue($m[1]); if ($issue->id > 0 and $issue->project == $this->project->id) { return $this->linkIssue($issue, $m[1]); } else { return $m[0]; // not existing issue. } } function callbackCommit($m) { if ($this->scm->testHash($m[2]) != 'commit') { return $m[0]; } $co = $this->scm->getCommit($m[2]); return ''.$m[1].$m[2].''; } /** * Generate the link to an issue. * * @param IDF_Issue Issue. * @param string Name of the link. * @return string Linked issue. */ public function linkIssue($issue, $title) { $ic = (in_array($issue->status, $this->project->getTagIdsByStatus('closed'))) ? 'issue-c' : 'issue-o'; return ''.Pluf_esc($title).''; } }