3 * utils_crossref.php - Misc utils common to all aspects of the site
5 * Copyright 1999-2001 (c) Alcatel-Lucent
6 * Copyright 2009, Roland Mas
8 * @version $Id: utils.php 5732 2006-09-30 21:04:41Z marcelo $
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 function util_gen_cross_ref ($text, $group_id) {
29 // Some important information.
30 $prj = group_getunixname ($group_id);
32 // Handle URL in links, replace them with hyperlinks.
33 $text = util_make_links($text);
35 // Handle gforge [#nnn] Syntax => links to tracker.
36 $text = preg_replace('/\[\#(\d+)\]/e', "_artifactid2url('\\1')", $text);
38 // Handle gforge [Tnnn] Syntax => links to task.
39 $text = preg_replace('/\[\T(\d+)\]/e', "_taskid2url('\\1')", $text);
41 // Handle [wiki:<pagename>] syntax
42 $text = preg_replace('/\[wiki:(.*?)\]/e', "_page2url('$prj','\\1')", $text);
44 // Handle [forum:<thread_id>] Syntax => links to forum.
45 $text = preg_replace('/\[forum:(\d+)\]/e', "_forumid2url('\\1')", $text);
50 function _page2url($prj,$page) {
51 return '<a href="/wiki/g/'.$prj.'/'.rawurlencode($page).'">'.$page.'</a>';
54 function _artifactid2url ($id, $mode='') {
56 $res = db_query_params ('SELECT group_id, artifact.group_artifact_id, summary, status_id
57 FROM artifact, artifact_group_list
59 AND artifact.group_artifact_id=artifact_group_list.group_artifact_id',
61 if (db_numrows($res) == 1) {
62 $row = db_fetch_array($res);
63 $url = '/tracker/?func=detail&aid='.$id.'&group_id='.$row['group_id'].'&atid='.$row['group_artifact_id'];
64 $arg = 'title="'.util_html_secure($row['summary']).'"' ;
65 if ($row['status_id'] == 2) {
66 $arg .= 'class="artifact_closed"';
68 if ($mode == 'title') {
69 return '<a href="'.$url.'" '.$arg.'>'.$text.'</a> <a href="'.$url.'">'.$row['summary'].'</a><br />';
71 return '<a href="'.$url.'" '.$arg.'>'.$text.'</a>';
77 function _taskid2url ($id) {
79 $res = db_query_params ('SELECT group_id, project_task.group_project_id, summary, status_id
80 FROM project_task, project_group_list
81 WHERE project_task_id=$1
82 AND project_task.group_project_id=project_group_list.group_project_id',
84 if (db_numrows($res) == 1) {
85 $row = db_fetch_array($res);
86 $url = '/pm/task.php?func=detailtask&project_task_id='.$id.'&group_id='.$row['group_id'].'&group_project_id='.$row['group_project_id'];
87 $arg = 'title="'.$row['summary'].'"' ;
88 if ($row['status_id'] == 2) {
89 $arg .= 'class="task_closed"';
91 return '<a href="'.$url.'" '.$arg.'>'.$text.'</a>';
96 function _forumid2url ($id) {
97 $text = '[forum:'.$id.']';
98 $res = db_query_params ('SELECT group_id, forum.group_forum_id, subject
99 FROM forum, forum_group_list
101 AND forum.group_forum_id=forum_group_list.group_forum_id',
103 if (db_numrows($res) == 1) {
104 $row = db_fetch_array($res);
105 $url = '/forum/message.php?msg_id='.$id.'&group_id='.$row['group_id'];
106 $arg = 'title="'.$row['subject'].'"' ;
107 return '<a href="'.$url.'" '.$arg.'>'.$text.'</a>';