project = $project;
$this->git = new IDF_Git(Pluf::f('git_repository'));
$text = wordwrap($text, 69, "\n", true);
$text = Pluf_esc($text);
$text = ereg_replace('[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]',
'\\0',
$text);
$text = preg_replace_callback('#(issues?|bugs?|tickets?)\s+(\d+)((\s+and|\s+or|,)\s+(\d+)){0,}#im',
array($this, 'callbackIssues'), $text);
$text = preg_replace_callback('#(commit\s+)([0-9a-f]{5,40})#im',
array($this, 'callbackCommit'), $text);
echo $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->git->testHash($m[2]) != 'commit') {
return $m[0];
}
$co = $this->git->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).'';
}
}