File: utils_crossref.php

package info (click to toggle)
fusionforge 5.3.2%2B20141104-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 60,472 kB
  • sloc: php: 271,846; sql: 36,817; python: 14,575; perl: 6,406; sh: 5,980; xml: 4,294; pascal: 1,411; makefile: 911; cpp: 52; awk: 27
file content (116 lines) | stat: -rw-r--r-- 4,109 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
 * utils_crossref.php - Misc utils common to all aspects of the site
 *
 * Copyright 1999-2001 (c) Alcatel-Lucent
 * Copyright 2009, Roland Mas
 * Copyright 2014, Franck Villaume - TrivialDev
 *
 * This file is part of FusionForge. FusionForge is free software;
 * you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the Licence, or (at your option)
 * any later version.
 *
 * FusionForge is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

function util_gen_cross_ref ($text, $group_id) {

	// Some important information.
	$prj = group_getunixname ($group_id);

	// Handle URL in links, replace them with hyperlinks.
	$text = util_make_links($text);

	// Handle gforge [#nnn] Syntax => links to tracker.
	$text = preg_replace('/\[\#(\d+)\]/e', "_artifactid2url('\\1')", $text);

	// Handle gforge [Tnnn] Syntax => links to task.
	$text = preg_replace('/\[\T(\d+)\]/e', "_taskid2url('\\1','$group_id')", $text);

	// Handle [wiki:<pagename>] syntax
	$text = preg_replace('/\[wiki:(.*?)\]/e', "_page2url('$prj','\\1')", $text);

	// Handle [forum:<thread_id>] Syntax => links to forum.
	$text = preg_replace('/\[forum:(\d+)\]/e', "_forumid2url('\\1')", $text);

	return $text;
}

function _page2url($prj,$page) {
	return '<a href="/wiki/g/'.$prj.'/'.rawurlencode($page).'">'.$page.'</a>';
}

function _artifactid2url ($id, $mode='') {
	$text = '[#'.$id.']';
	$res = db_query_params ('SELECT group_id, artifact.group_artifact_id, summary, status_id
			FROM artifact, artifact_group_list
			WHERE artifact_id=$1
			AND artifact.group_artifact_id=artifact_group_list.group_artifact_id',
				array ($id)) ;
	if (db_numrows($res) == 1) {
		$row = db_fetch_array($res);
		$url = '/tracker/?func=detail&amp;aid='.$id.'&amp;group_id='.$row['group_id'].'&amp;atid='.$row['group_artifact_id'];
		$arg = 'title="'.util_html_secure($row['summary']).'"' ;
		if ($row['status_id'] == 2) {
			$arg .= 'class="artifact_closed"';
		}
		if ($mode == 'title') {
			return '<a href="'.$url.'" '.$arg.'>'.$text.'</a> <a href="'.$url.'">'.$row['summary'].'</a><br />';
		} else {
			return '<a href="'.$url.'" '.$arg.'>'.$text.'</a>';
		}
	}
	return $text;
}

/**
 * _taskid2url - transform text [T##] to clickable URL
 *
 * @param	int	$id		the Task ID
 * @param	int	$group_id	the group id owner of the task id
 * @return	string	the clickable link
 */
function _taskid2url($id, $group_id) {
	$text = '[T'.$id.']';
	$res = db_query_params('SELECT group_id, project_task.group_project_id, summary, status_id
			FROM project_task, project_group_list
			WHERE project_task_id=$1
			AND project_task.group_project_id=project_group_list.group_project_id
			AND group_id = $2',
				array ($id, $group_id));
	if (db_numrows($res) == 1) {
		$row = db_fetch_array($res);
		$url = '/pm/task.php?func=detailtask&amp;project_task_id='.$id.'&amp;group_id='.$row['group_id'].'&amp;group_project_id='.$row['group_project_id'];
		$arg = 'title="'.$row['summary'].'"' ;
		if ($row['status_id'] == 2) {
			$arg .= 'class="task_closed"';
		}
		return '<a href="'.$url.'" '.$arg.'>'.$text.'</a>';
	}
	return $text;
}

function _forumid2url ($id) {
	$text = '[forum:'.$id.']';
	$res = db_query_params ('SELECT group_id, forum.group_forum_id, subject
			FROM forum, forum_group_list
			WHERE msg_id=$1
			AND forum.group_forum_id=forum_group_list.group_forum_id',
				array ($id));
	if (db_numrows($res) == 1) {
		$row = db_fetch_array($res);
		$url = '/forum/message.php?msg_id='.$id.'&amp;group_id='.$row['group_id'];
		$arg = 'title="'.$row['subject'].'"' ;
		return '<a href="'.$url.'" '.$arg.'>'.$text.'</a>';
	}
	return $text;
}