InDefero

Sign in or create your account | Project List | Help

InDefero Git Source Tree

Root/src/IDF/Template/IssueComment.php

Source at commit 7383e18dff19e7e6a1e56d55cdfbfa109e91bfb3 created 2 years 1 month ago.
By Loic d'Anterroches, Fixed issue 4, with fine control over the tabs access.
1<?php
2/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3/*
4# ***** BEGIN LICENSE BLOCK *****
5# This file is part of InDefero, an open source project management application.
6# Copyright (C) 2008 Céondo Ltd and contributors.
7#
8# InDefero is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# InDefero is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21#
22# ***** END LICENSE BLOCK ***** */
23
24Pluf::loadFunction('Pluf_HTTP_URL_urlForView');
25
26/**
27 * Make the links to issues and commits.
28 */
29class IDF_Template_IssueComment extends Pluf_Template_Tag
30{
31    private $project = null;
32    private $request = null;
33    private $git = null;
34
35    function start($text, $request)
36    {
37        $this->project = $request->project;
38        $this->request = $request;
39        $this->git = new IDF_Git($this->project->getGitRepository());
40        $text = wordwrap($text, 69, "\n", true);
41        $text = Pluf_esc($text);
42        $text = ereg_replace('[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]',
43                             '<a href="\\0" rel="nofollow">\\0</a>',
44                             $text);
45        if ($request->rights['hasIssuesAccess']) {
46            $text = preg_replace_callback('#(issues?|bugs?|tickets?)\s+(\d+)((\s+and|\s+or|,)\s+(\d+)){0,}#im',
47                                          array($this, 'callbackIssues'), $text);
48        }
49        if ($request->rights['hasSourceAccess']) {
50            $text = preg_replace_callback('#(commit\s+)([0-9a-f]{5,40})#im',
51                                          array($this, 'callbackCommit'), $text);
52        }
53        echo $text;
54    }
55
56    /**
57     * General call back for the issues.
58     */
59    function callbackIssues($m)
60    {
61        if (count($m) == 3) {
62            $issue = new IDF_Issue($m[2]);
63            if ($issue->id > 0 and $issue->project == $this->project->id) {
64                return $this->linkIssue($issue, $m[1].' '.$m[2]);
65            } else {
66                return $m[0]; // not existing issue.
67            }
68        } else {
69            return preg_replace_callback('/(\d+)/',
70                                         array($this, 'callbackIssue'),
71                                         $m[0]);
72        }
73    }
74
75    /**
76     * Call back for the case of multiple issues like 'issues 1, 2 and 3'.
77     *
78     * Called from callbackIssues, it is linking only the number of
79     * the issues.
80     */
81    function callbackIssue($m)
82    {
83        $issue = new IDF_Issue($m[1]);
84        if ($issue->id > 0 and $issue->project == $this->project->id) {
85            return $this->linkIssue($issue, $m[1]);
86        } else {
87            return $m[0]; // not existing issue.
88        }
89    }
90
91    function callbackCommit($m)
92    {
93        if ($this->git->testHash($m[2]) != 'commit') {
94            return $m[0];
95        }
96        $co = $this->git->getCommit($m[2]);
97        return '<a href="'.Pluf_HTTP_URL_urlForView('IDF_Views_Source::commit', array($this->project->shortname, $co->commit)).'">'.$m[1].$m[2].'</a>';
98    }
99
100    /**
101     * Generate the link to an issue.
102     *
103     * @param IDF_Issue Issue.
104     * @param string Name of the link.
105     * @return string Linked issue.
106     */
107    public function linkIssue($issue, $title)
108    {
109        $ic = (in_array($issue->status, $this->project->getTagIdsByStatus('closed'))) ? 'issue-c' : 'issue-o';
110        return '<a href="'.Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view',
111                                                    array($this->project->shortname, $issue->id)).'" class="'.$ic.'" title="'.Pluf_esc($issue->summary).'">'.Pluf_esc($title).'</a>';
112    }
113}
114

Archive Download this file

Branches:
dev
develop
master
newdiff
svn

Tags:
v1.0