Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 260 lines (228 sloc) 8.694 kb
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
1 <?php
2
3 $errors = array();
4 $warnings = array();
5 $order_options = array(
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
6 '' => 'relevance',
7 'id' => 'ID',
8 'ts1' => 'date',
9 'ts2' => 'last modified',
10 'package_name' => 'package',
11 'bug_type' => 'bug_type',
12 'status' => 'status',
13 'php_version' => 'php_version',
14 'php_os' => 'os',
15 'sdesc' => 'summary',
16 'assign' => 'assignment',
31662ab @felipensp - Added order by number of votes
felipensp authored
17 'avg_score' => 'avg. vote score',
18 'votes_count' => 'number of votes'
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
19 );
20
21 // Fetch pseudo packages
17cd250 @felipensp - Missing project type information
felipensp authored
22 $pseudo_pkgs = get_pseudo_packages(false);
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
23
24 // Setup input variables..
25 $boolean_search = isset($_GET['boolean']) ? (int) $_GET['boolean'] : 0;
26 $status = !empty($_GET['status']) ? $_GET['status'] : 'Open';
27 $search_for = !empty($_GET['search_for']) ? $_GET['search_for'] : '';
28 $bug_type = (!empty($_GET['bug_type']) && $_GET['bug_type'] != 'All') ? $_GET['bug_type'] : '';
99ced3c - Fixed bug #51722.
Derick Rethans authored
29 $bug_age = (int) (isset($_GET['bug_age']) ? $_GET['bug_age'] : 0);
30 $bug_updated = (int) (isset($_GET['bug_updated']) ? $_GET['bug_updated'] : 0);
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
31 $php_os = !empty($_GET['php_os']) ? $_GET['php_os'] : '';
32 $php_os_not = !empty($_GET['php_os_not']) ? 'not' : '';
33 $phpver = !empty($_GET['phpver']) ? $_GET['phpver'] : '';
3f640e5 @felipensp - Added field to CVE-ID
felipensp authored
34 $cve_id = !empty($_GET['cve_id']) ? $_GET['cve_id'] : '';
15bd8e4 @felipensp - Added NOT option to CVE-ID bug search
felipensp authored
35 $cve_id_not = !empty($_GET['cve_id_not']) ? 'not' : '';
beffeed @felipensp - Added possibility to search only for bugs with patch attached
felipensp authored
36 $patch = !empty($_GET['patch']) ? $_GET['patch'] : '';
6ab9545 @felipensp - Added option to search for bugs marked as private
felipensp authored
37 $private = !empty($_GET['private']) ? $_GET['private'] : '';
99ced3c - Fixed bug #51722.
Derick Rethans authored
38 $begin = (int) (!empty($_GET['begin']) ? $_GET['begin'] : 0);
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
39 $limit = (defined('MAX_BUGS_RETURN')) ? MAX_BUGS_RETURN : 30;
cc16c49 @felipensp - Added option to search for project (php, pecl)
felipensp authored
40 $project = (!empty($_GET['project']) && $_GET['project'] != 'All') ? $_GET['project'] : '';
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
41 if (!empty($_GET['limit'])) {
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
42 $limit = ($_GET['limit'] == 'All') ? 'All' : (($_GET['limit'] > 0) ? (int) $_GET['limit'] : $limit);
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
43 }
44 $direction = (!empty($_GET['direction']) && $_GET['direction'] != 'DESC') ? 'ASC' : 'DESC';
47b5807 @LawnGnome Fix bug #52472 (Bug tracker relevance sort doesn't work). Based (loosely...
LawnGnome authored
45 $order_by = (!empty($_GET['order_by']) && array_key_exists($_GET['order_by'], $order_options)) ? $_GET['order_by'] : '';
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
46 $reorder_by = (!empty($_GET['reorder_by']) && array_key_exists($_GET['reorder_by'], $order_options)) ? $_GET['reorder_by'] : '';
47 $assign = !empty($_GET['assign']) ? $_GET['assign'] : '';
4e4fb08 @vrana Allow ' at ' in author e-mail, return empty result for invalid e-mails
vrana authored
48 $author_email = !empty($_GET['author_email']) ? spam_protect($_GET['author_email'], 'reverse') : '';
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
49 $package_name = (isset($_GET['package_name']) && is_array($_GET['package_name'])) ? $_GET['package_name'] : array();
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
50 $package_nname = (isset($_GET['package_nname']) && is_array($_GET['package_nname'])) ? $_GET['package_nname'] : array();
51
52 if (isset($_GET['cmd']) && $_GET['cmd'] == 'display')
53 {
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
54 $query = '
55 SELECT SQL_CALC_FOUND_ROWS
56 bugdb.*,
57 TO_DAYS(NOW())-TO_DAYS(bugdb.ts2) AS unchanged,
9926d38 - Fix some RSS/RDF issues (rss feeds actually validate now, search feeds...
Jani Taskinen authored
58 UNIX_TIMESTAMP(ts1) AS submitted,
59 UNIX_TIMESTAMP(ts2) AS modified
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
60 FROM bugdb
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
61 ';
dc4f1bb @felipensp - Added order by avg. vote scores
felipensp authored
62
31662ab @felipensp - Added order by number of votes
felipensp authored
63 if (in_array($order_by, array('votes_count', 'avg_score'))) {
dc4f1bb @felipensp - Added order by avg. vote scores
felipensp authored
64 $query .= 'LEFT JOIN bugdb_votes v ON bugdb.id = v.bug';
65 }
3f640e5 @felipensp - Added field to CVE-ID
felipensp authored
66
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
67 $where_clause = ' WHERE 1 = 1 ';
3f640e5 @felipensp - Added field to CVE-ID
felipensp authored
68
88a4cb9 @felipensp - Fix warning
felipensp authored
69 if (isset($user_flags) && ($user_flags & (BUGS_SECURITY_DEV | BUGS_TRUSTED_DEV))) {
6ab9545 @felipensp - Added option to search for bugs marked as private
felipensp authored
70 if ($private != '') {
71 $where_clause .= ' AND bugdb.private = "Y" ';
72 }
73 } else {
3f640e5 @felipensp - Added field to CVE-ID
felipensp authored
74 /* Non trusted developer should see the Security related bug report just when it is public */
e073c2d @felipensp - Updated the search part
felipensp authored
75 $where_clause .= ' AND (bugdb.bug_type <> "Security" OR private = "N") ';
3f640e5 @felipensp - Added field to CVE-ID
felipensp authored
76 }
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
77
78 if (!empty($package_name)) {
79 $where_clause .= ' AND bugdb.package_name';
80 if (count($package_name) > 1) {
81 $where_clause .= " IN ('" . join("', '", escapeSQL($package_name)) . "')";
82 } else {
83 $where_clause .= ' = ' . $dbh->quote($package_name[0]);
84 }
85 }
86
87 if (!empty($package_nname)) {
88 $where_clause .= ' AND bugdb.package_name';
89 if (count($package_nname) > 1) {
90 $where_clause .= " NOT IN ('" . join("', '", escapeSQL($package_nname)) . "')";
91 } else {
92 $where_clause .= ' <> ' . $dbh->quote($package_nname[0]);
93 }
94 }
95
96 // Ensure status is valid and tweak search clause to treat assigned, analyzed, critical and verified bugs as open
97 switch ($status) {
98 case 'All':
99 break;
100 case 'Closed':
101 case 'Re-Opened':
102 case 'Duplicate':
103 case 'Critical':
104 case 'Assigned':
105 case 'Analyzed':
106 case 'Verified':
107 case 'Suspended':
108 case 'Wont fix':
109 case 'No Feedback':
110 case 'Feedback':
c3110c3 @rlerdorf - The end of an era - switch "Bogus" to "Not a bug" by popular demand
rlerdorf authored
111 case 'Not a bug':
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
112 $where_clause .= " AND bugdb.status='$status'";
113 break;
114 case 'Old Feedback':
115 $where_clause .= " AND bugdb.status='Feedback'
116 AND TO_DAYS(NOW())-TO_DAYS(bugdb.ts2) > 60";
117 break;
118 case 'Fresh':
c3110c3 @rlerdorf - The end of an era - switch "Bogus" to "Not a bug" by popular demand
rlerdorf authored
119 $where_clause .= " AND bugdb.status NOT IN ('Closed', 'Duplicate', 'Not a bug')
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
120 AND TO_DAYS(NOW())-TO_DAYS(bugdb.ts2) < 30";
121 break;
122 case 'Stale':
c3110c3 @rlerdorf - The end of an era - switch "Bogus" to "Not a bug" by popular demand
rlerdorf authored
123 $where_clause .= " AND bugdb.status NOT IN ('Closed', 'Duplicate', 'Not a bug')
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
124 AND TO_DAYS(NOW())-TO_DAYS(bugdb.ts2) > 30";
125 break;
126 case 'Not Assigned':
c3110c3 @rlerdorf - The end of an era - switch "Bogus" to "Not a bug" by popular demand
rlerdorf authored
127 $where_clause .= " AND bugdb.status NOT IN ('Closed', 'Duplicate', 'Not a bug', 'Assigned', 'Wont Fix', 'Suspended')";
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
128 break;
129 case 'OpenFeedback':
130 $where_clause .= " AND bugdb.status IN ('Open', 'Re-Opened', 'Assigned','Analyzed', 'Critical', 'Verified', 'Feedback')";
131 break;
132 default:
133 case 'Open':
9e3082d @bjori There is no such status anymore, its a bug type
bjori authored
134 $where_clause .= " AND bugdb.status IN ('Open', 'Re-Opened', 'Assigned', 'Analyzed', 'Critical', 'Verified')";
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
135 }
136
137 if ($search_for != '') {
138 list($sql_search, $ignored) = format_search_string($search_for, $boolean_search);
139 $where_clause .= $sql_search;
140 if (count($ignored) > 0 ) {
141 $warnings[] = 'The following words were ignored: ' . implode(', ', array_unique($ignored));
142 }
143 }
144
145 if ($bug_type != '') {
146 if ($bug_type == 'Bugs') {
147 $where_clause .= ' AND (bugdb.bug_type = "Bug" OR bugdb.bug_type="Documentation Problem")';
148 } else {
149 $where_clause .= ' AND bugdb.bug_type = ' . $dbh->quote($bug_type);
150 }
151 }
152
153 if ($bug_age > 0) {
154 $where_clause .= " AND bugdb.ts1 >= DATE_SUB(NOW(), INTERVAL $bug_age DAY)";
155 }
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
156
157 if ($bug_updated > 0) {
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
158 $where_clause .= " AND bugdb.ts2 >= DATE_SUB(NOW(), INTERVAL $bug_updated DAY)";
159 }
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
160
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
161 if ($php_os != '') {
162 $where_clause .= " AND bugdb.php_os {$php_os_not} LIKE '%" . $dbh->escape($php_os) . "%'";
163 }
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
164
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
165 if ($phpver != '') {
166 $where_clause .= " AND bugdb.php_version LIKE '" . $dbh->escape($phpver) . "%'";
167 }
beffeed @felipensp - Added possibility to search only for bugs with patch attached
felipensp authored
168
cc16c49 @felipensp - Added option to search for project (php, pecl)
felipensp authored
169 if ($project != '') {
170 $where_clause .= " AND EXISTS (SELECT 1 FROM bugdb_pseudo_packages b WHERE b.name = bugdb.package_name AND b.project = '". $dbh->escape($project) ."' LIMIT 1)";
171 }
172
3f640e5 @felipensp - Added field to CVE-ID
felipensp authored
173 if ($cve_id != '') {
15bd8e4 @felipensp - Added NOT option to CVE-ID bug search
felipensp authored
174 $where_clause .= " AND bugdb.cve_id {$cve_id_not} LIKE '" . $dbh->escape($cve_id) . "%'";
3f640e5 @felipensp - Added field to CVE-ID
felipensp authored
175 }
176
beffeed @felipensp - Added possibility to search only for bugs with patch attached
felipensp authored
177 if ($patch != '') {
178 $where_clause .= " AND EXISTS (SELECT 1 FROM bugdb_patchtracker WHERE bugdb_id = bugdb.id LIMIT 1)";
179 }
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
180
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
181 if ($assign != '') {
182 $where_clause .= ' AND bugdb.assign = ' . $dbh->quote($assign);
183 }
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
184
185 if ($author_email != '') {
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
186 $where_clause .= ' AND bugdb.email = ' . $dbh->quote($author_email);
187 }
188
189 $where_clause .= ' AND (1=1';
190
191 if ($pseudo = array_intersect(array_keys($pseudo_pkgs), $package_name)) {
192 $where_clause .= " OR bugdb.package_name";
193 if (count($pseudo) > 1) {
194 $where_clause .= " IN ('" . join("', '", escapeSQL($pseudo)) . "')";
195 } else {
196 $where_clause .= " = '" . implode('', escapeSQL($pseudo)) . "'";
197 }
198 } else {
199 $where_clause .= " OR bugdb.package_name IN ('" . join("', '", escapeSQL(array_keys($pseudo_pkgs))) . "')";
200 }
201
202 $query .= "$where_clause )";
203
204 if ($reorder_by != '') {
205 if ($order_by == $reorder_by) {
206 $direction = $direction == 'ASC' ? 'DESC' : 'ASC';
207 } else {
7df4a0d - When sorting by "last modified", show results in descenting order by d...
Jani Taskinen authored
208 $direction = $reorder_by == 'ts2' ? 'DESC' : 'ASC';
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
209 $order_by = $reorder_by;
210 }
211 }
dc4f1bb @felipensp - Added order by avg. vote scores
felipensp authored
212
47b5807 @LawnGnome Fix bug #52472 (Bug tracker relevance sort doesn't work). Based (loosely...
LawnGnome authored
213 $order_by_clauses = array();
31662ab @felipensp - Added order by number of votes
felipensp authored
214 if (in_array($order_by, array('votes_count', 'avg_score'))) {
adf592b @felipensp - Fix GROUP BY
felipensp authored
215 $query .= ' GROUP BY bugdb.id';
31662ab @felipensp - Added order by number of votes
felipensp authored
216
217 switch ($order_by) {
218 case 'avg_score':
47b5807 @LawnGnome Fix bug #52472 (Bug tracker relevance sort doesn't work). Based (loosely...
LawnGnome authored
219 $order_by_clauses = array(
220 "IFNULL(AVG(v.score), 0)+3 $direction",
221 "COUNT(v.bug) DESC"
222 );
31662ab @felipensp - Added order by number of votes
felipensp authored
223 break;
224 case 'votes_count':
47b5807 @LawnGnome Fix bug #52472 (Bug tracker relevance sort doesn't work). Based (loosely...
LawnGnome authored
225 $order_by_clauses = array("COUNT(v.bug) $direction");
31662ab @felipensp - Added order by number of votes
felipensp authored
226 break;
227 }
47b5807 @LawnGnome Fix bug #52472 (Bug tracker relevance sort doesn't work). Based (loosely...
LawnGnome authored
228 } elseif ($order_by != '') {
229 $order_by_clauses = array("$order_by $direction");
dc4f1bb @felipensp - Added order by avg. vote scores
felipensp authored
230 }
47b5807 @LawnGnome Fix bug #52472 (Bug tracker relevance sort doesn't work). Based (loosely...
LawnGnome authored
231
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
232 if ($status == 'Feedback') {
47b5807 @LawnGnome Fix bug #52472 (Bug tracker relevance sort doesn't work). Based (loosely...
LawnGnome authored
233 $order_by_clauses[] = "bugdb.ts2 $direction";
234 }
235
236 if (count($order_by_clauses)) {
237 $query .= ' ORDER BY ' . implode(', ', $order_by_clauses);
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
238 }
239
240 if ($limit != 'All' && $limit > 0) {
241 $query .= " LIMIT $begin, $limit";
242 }
243
244 if (stristr($query, ';')) {
245 $errors[] = 'BAD HACKER!! No database cracking for you today!';
246 } else {
247 $res = $dbh->prepare($query)->execute();
248 if (!PEAR::isError($res)) {
249 $rows = $res->numRows();
250 $total_rows = $dbh->prepare('SELECT FOUND_ROWS()')->execute()->fetchOne();
b236d21 - Merge some more php-bugs-web stuff into this codebase
Jani Taskinen authored
251 } else {
252 $error = MDB2::errorMessage($res);
253 $errors[] = $error;
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
254 }
255 if (defined('MAX_BUGS_RETURN') && $total_rows > $rows) {
256 $warnings[] = 'The search was too general, only ' . MAX_BUGS_RETURN . ' bugs will be returned';
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
257 }
bab4791 - More totally unnecessary whitespace changes.
Jani Taskinen authored
258 }
feb6a80 - Separated the search query from search.php so it can be easily reused ...
Jani Taskinen authored
259 }
Something went wrong with that request. Please try again.