1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved |
4
|
|
|
* |
5
|
|
|
* This file is a part of Codendi. |
6
|
|
|
* |
7
|
|
|
* Codendi is free software; you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* Codendi is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with Codendi. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
class URL { |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @see http://www.ietf.org/rfc/rfc2396.txt Annex B |
25
|
|
|
*/ |
26
|
|
|
/* static */ function parse($url) { |
27
|
|
|
$components = array(); |
28
|
|
|
preg_match('`^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?`i',$url, $components); |
29
|
|
|
return $components; |
30
|
|
|
} |
31
|
|
|
/* static */ function getHost($url) { |
32
|
|
|
$components = URL::parse($url); |
33
|
|
|
return $components[4]; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
static function getScheme($url) { |
37
|
|
|
$components = URL::parse($url); |
38
|
|
|
return $components[2]; |
39
|
|
|
} |
40
|
|
|
/** |
41
|
|
|
* |
42
|
|
|
* Retreives the project name from svn request uri |
43
|
|
|
* @param String $uri |
44
|
|
|
* |
45
|
|
|
* @return String |
46
|
|
|
*/ |
47
|
|
|
function getGroupNameFromSVNUrl($uri) { |
48
|
|
|
$pieces = explode('&', $uri); |
49
|
|
|
foreach($pieces as $piece) { |
50
|
|
|
if(strpos($piece, 'root=') !== false) { |
51
|
|
|
$parts = $piece; |
52
|
|
|
break; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
if (!isset($parts)) { |
56
|
|
|
return false; |
57
|
|
|
} |
58
|
|
|
$group = explode('=', $parts); |
59
|
|
|
return $group[1]; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Wrapper for Rule_ProjectName |
64
|
|
|
*/ |
65
|
|
|
function getProjectNameRule() { |
66
|
|
|
return new Rule_ProjectName(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
function getGroupIdFromUrl($url) { |
70
|
|
|
$req_uri='/'.trim($url, "/"); |
71
|
|
|
// /projects/ and /viewvc/ |
72
|
|
|
if ((strpos($req_uri,'/projects/') === 0) || (strpos($req_uri,'/viewvc.php/') !== false)) { |
73
|
|
|
if (strpos($req_uri,'/viewvc.php/') !== false) { |
74
|
|
|
$this_proj_name = $this->getGroupNameFromSVNUrl($req_uri); |
75
|
|
|
} else if (strpos($req_uri,'/projects/') !== false) { |
76
|
|
|
$pieces = explode("/", $url); |
77
|
|
|
$this_proj_name=$pieces[2]; |
78
|
|
|
} |
79
|
|
|
//Project short name validation |
80
|
|
|
$rule = $this->getProjectNameRule(); |
81
|
|
|
if ($rule->containsIllegalChars($this_proj_name)) { |
82
|
|
|
return false; |
83
|
|
|
} |
84
|
|
|
$dao = $this->getProjectDao(); |
85
|
|
|
$dao_results=$dao->searchByUnixGroupName($this_proj_name); |
86
|
|
|
if ($dao_results->rowCount() < 1) {# project does not exist |
87
|
|
|
return false; |
88
|
|
|
} |
89
|
|
|
$group_id=$dao_results->getRow(); |
90
|
|
|
$group_id=$group_id['group_id']; |
91
|
|
|
} |
92
|
|
|
// Forum and news. Each published news is a special forum of project 'news' |
93
|
|
|
if (strpos($req_uri,'/forum/') === 0) { |
94
|
|
|
if (array_key_exists('forum_id', $_REQUEST) && $_REQUEST['forum_id']) { |
95
|
|
|
// Get corresponding project |
96
|
|
|
$dao = $this->getForumDao(); |
97
|
|
|
$result = $dao->searchByGroupForumId($_REQUEST['forum_id']); |
98
|
|
|
$group_id=$result->getRow(); |
99
|
|
|
$group_id=$group_id['group_id']; |
100
|
|
|
|
101
|
|
|
// News |
102
|
|
|
if ($group_id==$GLOBALS['sys_news_group']) { |
103
|
|
|
// Otherwise, get group_id of corresponding news |
104
|
|
|
$dao = $this->getNewsBytesDao(); |
105
|
|
|
$result = $dao->searchByForumId($_REQUEST['forum_id']); |
106
|
|
|
$group_id = $result->getRow(); |
107
|
|
|
$group_id = $group_id['group_id']; |
108
|
|
|
|
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
// File downloads. It might be a good idea to restrict access to shownotes.php too... |
113
|
|
|
if (strpos($req_uri,'/file/download.php') === 0) { |
114
|
|
|
list(,$group_id, $file_id) = explode('/', $GLOBALS['PATH_INFO']); |
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
// Artifact attachment download... |
118
|
|
|
if (strpos($req_uri,'/tracker/download.php') === 0) { |
119
|
|
|
if (isset($_REQUEST['artifact_id'])) { |
120
|
|
|
$dao = $this->getArtifactDao(); |
121
|
|
|
$result = $dao->searchArtifactId($_REQUEST['artifact_id']); |
122
|
|
|
$group_id=$result->getRow(); |
123
|
|
|
$group_id=$group_id['group_id']; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
EventManager::instance()->processEvent( |
128
|
|
|
Event::GET_PROJECTID_FROM_URL, |
129
|
|
|
array( |
130
|
|
|
'url' => $req_uri, |
131
|
|
|
'project_id' => &$group_id, |
132
|
|
|
'project_dao' => $this->getProjectDao(), |
133
|
|
|
'request' => new Codendi_Request($_REQUEST) |
134
|
|
|
) |
135
|
|
|
); |
136
|
|
|
|
137
|
|
|
if ($group_id) { |
138
|
|
|
return $group_id; |
139
|
|
|
} elseif (isset($_REQUEST['group_id'])) { |
140
|
|
|
return $_REQUEST['group_id']; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
return null; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
function getProjectDao() { |
147
|
|
|
return new ProjectDao(CodendiDataAccess::instance()); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
function getForumDao() { |
151
|
|
|
return new ForumDao(CodendiDataAccess::instance()); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
function getNewsBytesDao() { |
155
|
|
|
return new NewsBytesDao(CodendiDataAccess::instance()); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
function getArtifactDao() { |
159
|
|
|
return new ArtifactDao(CodendiDataAccess::instance()); |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
?> |
163
|
|
|
|
This checks looks for assignemnts to variables using the
list(...)
function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$a
and$c
are used. There was no need to assign$b
.Instead, the list call could have been.