1 | Index: includes/common.inc |
---|
2 | =================================================================== |
---|
3 | --- includes/common.inc (révision 111529) |
---|
4 | +++ includes/common.inc (copie de travail) |
---|
5 | @@ -71,12 +71,17 @@ |
---|
6 | |
---|
7 | # Connect to the portsdb and gather miscellaneous information: |
---|
8 | function portsdb_connect($portsdb_host, $portsdb_user, $portsdb_passwd) { |
---|
9 | + global $portsdb_name; |
---|
10 | |
---|
11 | $script = basename($_SERVER['PHP_SELF']); |
---|
12 | |
---|
13 | $portsdb_connection = FALSE; |
---|
14 | - if (function_exists('mysql_connect')) { |
---|
15 | - $portsdb_connection = mysql_connect($portsdb_host, $portsdb_user, $portsdb_passwd); |
---|
16 | + if (function_exists('pg_connect')) { |
---|
17 | + $h = str_replace(str_replace($portsdb_host, "\\" , "\\\\"), "'", "\\'"); |
---|
18 | + $u = str_replace(str_replace($portsdb_user, "'", "\\'"), "'", "\\'"); |
---|
19 | + $p = str_replace(str_replace($portsdb_password, "'", "\\'"), "'", "\\'"); |
---|
20 | + $db= str_replace(str_replace($portsdb_name, "'", "\\'"), "'", "\\'"); |
---|
21 | + $portsdb_connection = pg_connect("host='$h' dbname='$db' user='$u' password='$p'"); |
---|
22 | } |
---|
23 | if ($portsdb_connection === FALSE) { |
---|
24 | switch ($script) { |
---|
25 | @@ -120,11 +125,9 @@ |
---|
26 | |
---|
27 | # Total count of currently available ports: |
---|
28 | function ports_count() { |
---|
29 | - global $portsdb_name; |
---|
30 | - |
---|
31 | - $result = mysql_query("SELECT COUNT(DISTINCT name) FROM $portsdb_name.portfiles"); |
---|
32 | + $result = pg_query("SELECT COUNT(DISTINCT name) FROM portfiles"); |
---|
33 | if ($result) { |
---|
34 | - $row = mysql_fetch_array($result); |
---|
35 | + $row = pg_fetch_array($result); |
---|
36 | $count = $row[0]; |
---|
37 | } else { |
---|
38 | $count = 0; |
---|
39 | @@ -137,11 +140,9 @@ |
---|
40 | |
---|
41 | # Total count of port categories: |
---|
42 | function categories_count() { |
---|
43 | - global $portsdb_name; |
---|
44 | - |
---|
45 | - $result = mysql_query("SELECT COUNT(DISTINCT category) FROM $portsdb_name.categories"); |
---|
46 | + $result = pg_query("SELECT COUNT(DISTINCT category) FROM categories"); |
---|
47 | if ($result) { |
---|
48 | - $row = mysql_fetch_array($result); |
---|
49 | + $row = pg_fetch_array($result); |
---|
50 | $count = $row[0]; |
---|
51 | } else { |
---|
52 | $count = 0; |
---|
53 | Index: index.php |
---|
54 | =================================================================== |
---|
55 | --- index.php (révision 111529) |
---|
56 | +++ index.php (copie de travail) |
---|
57 | @@ -71,6 +71,6 @@ |
---|
58 | <?php |
---|
59 | print_footer(); |
---|
60 | if ($portsdb_info['connection_handler'] !== false) { |
---|
61 | - mysql_close($portsdb_info['connection_handler']); |
---|
62 | + pg_close($portsdb_info['connection_handler']); |
---|
63 | } |
---|
64 | ?> |
---|
65 | Index: ports.php |
---|
66 | =================================================================== |
---|
67 | --- ports.php (révision 111529) |
---|
68 | +++ ports.php (copie de travail) |
---|
69 | @@ -8,9 +8,9 @@ |
---|
70 | include_once("includes/common.inc"); |
---|
71 | |
---|
72 | $portsdb_info = portsdb_connect($portsdb_host, $portsdb_user, $portsdb_passwd); |
---|
73 | - $sql = "SELECT UNIX_TIMESTAMP(activity_time) FROM $portsdb_name.log ORDER BY UNIX_TIMESTAMP(activity_time) DESC"; |
---|
74 | - $result = mysql_query($sql); |
---|
75 | - if ($result && $row = mysql_fetch_row($result)) { |
---|
76 | + $sql = "SELECT ceil(extract( epoch from activity_time)) as tim FROM log ORDER BY tim DESC"; |
---|
77 | + $result = pg_query($sql); |
---|
78 | + if ($result && $row = pg_fetch_row($result)) { |
---|
79 | $date = date('Y-m-d', $row[0]); |
---|
80 | $time = date('H:i:s e', $row[0]); |
---|
81 | } else { |
---|
82 | @@ -64,8 +64,8 @@ |
---|
83 | /* If no valid search criteria is specified (by set and not equal to all and a valid substring) we output port categories |
---|
84 | as possible searches */ |
---|
85 | if (!$by || ($by != 'all' && !$substr)) { |
---|
86 | - $query = "SELECT DISTINCT category FROM $portsdb_name.categories ORDER BY category"; |
---|
87 | - $result = mysql_query($query); |
---|
88 | + $query = "SELECT DISTINCT category FROM categories ORDER BY category"; |
---|
89 | + $result = pg_query($query); |
---|
90 | if ($result) { |
---|
91 | $max_entries_per_column = floor($portsdb_info['num_categories']/4); |
---|
92 | $columns = 0; |
---|
93 | @@ -73,7 +73,7 @@ |
---|
94 | while ($columns < 4) { |
---|
95 | $entries_per_column = 0; |
---|
96 | print '<li><ul>'; |
---|
97 | - while ($row = mysql_fetch_assoc($result)) { |
---|
98 | + while ($row = pg_fetch_assoc($result)) { |
---|
99 | print "<li><a href=\"$phpself?by=category&substr=" . urlencode($row['category']) . '">' |
---|
100 | . htmlspecialchars($row['category']) . '</a></li>'; |
---|
101 | if ($entries_per_column == $max_entries_per_column) break; |
---|
102 | @@ -89,34 +89,35 @@ |
---|
103 | /* If valid criteria is specified (by set and a valid substring, or by set to all) we poll the db and display the results */ |
---|
104 | if ($by && ($substr || $by == 'all')) { |
---|
105 | $fields = 'name, path, version, description'; |
---|
106 | - $tables = "$portsdb_name.portfiles AS p"; |
---|
107 | + $tables = "portfiles AS p"; |
---|
108 | switch ($by) { |
---|
109 | case 'name': |
---|
110 | - $criteria = "p.name LIKE '%" . mysql_real_escape_string($substr) . "%'"; |
---|
111 | + #TODO: was pg_escape_string. Current charset taken into account ? |
---|
112 | + $criteria = "p.name LIKE '%" . pg_escape_string($substr) . "%'"; |
---|
113 | break; |
---|
114 | case 'category': |
---|
115 | - $tables .= ", $portsdb_name.categories AS c"; |
---|
116 | - $criteria = "c.portfile = p.name AND c.category = '" . mysql_real_escape_string($substr) . "'"; |
---|
117 | + $tables .= ", categories AS c"; |
---|
118 | + $criteria = "c.portfile = p.name AND c.category = '" . pg_escape_string($substr) . "'"; |
---|
119 | break; |
---|
120 | case 'maintainer': |
---|
121 | - $tables .= ", $portsdb_name.maintainers AS m"; |
---|
122 | - $criteria = "m.portfile = p.name AND m.maintainer LIKE '%" . mysql_real_escape_string($substr) . "%'"; |
---|
123 | + $tables .= ", maintainers AS m"; |
---|
124 | + $criteria = "m.portfile = p.name AND m.maintainer LIKE '%" . pg_escape_string($substr) . "%'"; |
---|
125 | break; |
---|
126 | case 'library': |
---|
127 | - $criteria = "p.name = '" . mysql_real_escape_string($substr) . "'"; |
---|
128 | + $criteria = "p.name = '" . pg_escape_string($substr) . "'"; |
---|
129 | break; |
---|
130 | case 'variant': |
---|
131 | - $tables .= ", $portsdb_name.variants AS v"; |
---|
132 | - $criteria = "v.portfile = p.name AND v.variant = '" . mysql_real_escape_string($substr) . "'"; |
---|
133 | + $tables .= ", variants AS v"; |
---|
134 | + $criteria = "v.portfile = p.name AND v.variant = '" . pg_escape_string($substr) . "'"; |
---|
135 | break; |
---|
136 | case 'platform': |
---|
137 | - $tables .= ", $portsdb_name.platforms AS pl"; |
---|
138 | - $criteria = "pl.portfile = p.name AND pl.platform = '" . mysql_real_escape_string($substr) . "'"; |
---|
139 | + $tables .= ", platforms AS pl"; |
---|
140 | + $criteria = "pl.portfile = p.name AND pl.platform = '" . pg_escape_string($substr) . "'"; |
---|
141 | break; |
---|
142 | /* |
---|
143 | case 'license': |
---|
144 | $tables .= ", $portsdb_name.licenses AS lc"; |
---|
145 | - $criteria = "lc.portfile = p.name AND lc.license = '" . mysql_real_escape_string($substr) . "'"; |
---|
146 | + $criteria = "lc.portfile = p.name AND lc.license = '" . pg_escape_string($substr) . "'"; |
---|
147 | break; |
---|
148 | */ |
---|
149 | case 'all': |
---|
150 | @@ -128,12 +129,12 @@ |
---|
151 | } |
---|
152 | $where = ($criteria == '' ? '' : "WHERE $criteria"); |
---|
153 | $query = "SELECT DISTINCT $fields FROM $tables $where ORDER BY name"; |
---|
154 | - $result = mysql_query($query); |
---|
155 | + $result = pg_query($query); |
---|
156 | |
---|
157 | /* Main query sent to the DB */ |
---|
158 | if ($result) { |
---|
159 | $paging = false; |
---|
160 | - $numrows = mysql_num_rows($result); |
---|
161 | + $numrows = pg_num_rows($result); |
---|
162 | if ($numrows > $pagesize) { |
---|
163 | $paging = true; |
---|
164 | $pagecount = ceil($numrows / $pagesize); |
---|
165 | @@ -154,8 +155,11 @@ |
---|
166 | } |
---|
167 | $pagecontrol .= "</p>"; |
---|
168 | |
---|
169 | - # seek the data pointer |
---|
170 | - mysql_data_seek($result, $offset); |
---|
171 | + # seek the data pointer by fetching the row before the interesting one |
---|
172 | + # FIXME: maybe should be offset - 1 |
---|
173 | + if($offset > 0){ |
---|
174 | + pg_fetch_row($result, $offset); |
---|
175 | + } |
---|
176 | } |
---|
177 | |
---|
178 | print '<h3>Query Results</h3>'; |
---|
179 | @@ -169,9 +173,9 @@ |
---|
180 | |
---|
181 | print '<dl>'; |
---|
182 | /* Iterate over the entire set of returned ports */ |
---|
183 | - for ($row = mysql_fetch_assoc($result), $i = 0; |
---|
184 | + for ($row = pg_fetch_assoc($result), $i = 0; |
---|
185 | $row && (!$paging || $i < $curpagesize); |
---|
186 | - $row = mysql_fetch_assoc($result), $i++) { |
---|
187 | + $row = pg_fetch_assoc($result), $i++) { |
---|
188 | |
---|
189 | /* Port name and Portfile URL */ |
---|
190 | print "<dt><b><a href=\"${trac_url}browser/trunk/dports/" . $row['path'] . "/Portfile\">" . htmlspecialchars($row['name']) |
---|
191 | @@ -182,12 +186,12 @@ |
---|
192 | print htmlspecialchars($row['description']) . '<br />'; |
---|
193 | |
---|
194 | /* Licenses */ |
---|
195 | - $nquery = "SELECT license FROM $portsdb_name.licenses WHERE portfile='" . mysql_real_escape_string($row['name']) . |
---|
196 | + $nquery = "SELECT license FROM licenses WHERE portfile='" . pg_escape_string($row['name']) . |
---|
197 | "' ORDER BY license"; |
---|
198 | - $nresult = mysql_query($nquery); |
---|
199 | - if ($nresult && mysql_num_rows($nresult) > 0) { |
---|
200 | + $nresult = pg_query($nquery); |
---|
201 | + if ($nresult && pg_num_rows($nresult) > 0) { |
---|
202 | print '<i>Licenses:</i> '; |
---|
203 | - while ($nrow = mysql_fetch_row($nresult)) { |
---|
204 | + while ($nrow = pg_fetch_row($nresult)) { |
---|
205 | print "<a href=\"$phpself?by=license&substr=" . urlencode($nrow[0]) . '">' |
---|
206 | . htmlspecialchars($nrow[0]) . '</a> '; |
---|
207 | } |
---|
208 | @@ -195,13 +199,13 @@ |
---|
209 | } |
---|
210 | |
---|
211 | /* Maintainers */ |
---|
212 | - $nquery = "SELECT maintainer FROM $portsdb_name.maintainers WHERE portfile='" . mysql_real_escape_string($row['name']) . |
---|
213 | + $nquery = "SELECT maintainer FROM maintainers WHERE portfile='" . pg_escape_string($row['name']) . |
---|
214 | "' ORDER BY is_primary DESC, maintainer"; |
---|
215 | - $nresult = mysql_query($nquery); |
---|
216 | + $nresult = pg_query($nquery); |
---|
217 | if ($nresult) { |
---|
218 | $primary = 1; |
---|
219 | print '<i>Maintained by:</i>'; |
---|
220 | - while ($nrow = mysql_fetch_row($nresult)) { |
---|
221 | + while ($nrow = pg_fetch_row($nresult)) { |
---|
222 | if ($primary) { print ' <b>'; } |
---|
223 | else { print ' '; } |
---|
224 | print obfuscate_email($nrow[0]); |
---|
225 | @@ -211,13 +215,13 @@ |
---|
226 | } |
---|
227 | |
---|
228 | /* Categories */ |
---|
229 | - $nquery = "SELECT category FROM $portsdb_name.categories WHERE portfile='" . mysql_real_escape_string($row['name']) . |
---|
230 | + $nquery = "SELECT category FROM categories WHERE portfile='" . pg_escape_string($row['name']) . |
---|
231 | "' ORDER BY is_primary DESC, category"; |
---|
232 | - $nresult = mysql_query($nquery); |
---|
233 | + $nresult = pg_query($nquery); |
---|
234 | if ($nresult) { |
---|
235 | $primary = 1; |
---|
236 | print '<br /><i>Categories:</i>'; |
---|
237 | - while ($nrow = mysql_fetch_row($nresult)) { |
---|
238 | + while ($nrow = pg_fetch_row($nresult)) { |
---|
239 | if ($primary) { print ' <b>'; } |
---|
240 | else { print ' '; } |
---|
241 | print "<a href=\"$phpself?by=category&substr=" . urlencode($nrow[0]) . '">' |
---|
242 | @@ -228,12 +232,12 @@ |
---|
243 | } |
---|
244 | |
---|
245 | /* Platforms */ |
---|
246 | - $nquery = "SELECT platform FROM $portsdb_name.platforms WHERE portfile='" . mysql_real_escape_string($row['name']) . |
---|
247 | + $nquery = "SELECT platform FROM platforms WHERE portfile='" . pg_escape_string($row['name']) . |
---|
248 | "' ORDER BY platform"; |
---|
249 | - $nresult = mysql_query($nquery); |
---|
250 | + $nresult = pg_query($nquery); |
---|
251 | if ($nresult) { |
---|
252 | print '<br /><i>Platforms:</i> '; |
---|
253 | - while ($nrow = mysql_fetch_row($nresult)) { |
---|
254 | + while ($nrow = pg_fetch_row($nresult)) { |
---|
255 | print "<a href=\"$phpself?by=platform&substr=" . urlencode($nrow[0]) . '">' |
---|
256 | . htmlspecialchars($nrow[0]) . '</a> '; |
---|
257 | } |
---|
258 | @@ -240,12 +244,12 @@ |
---|
259 | } |
---|
260 | |
---|
261 | /* Dependencies */ |
---|
262 | - $nquery = "SELECT library FROM $portsdb_name.dependencies WHERE portfile='" . mysql_real_escape_string($row['name']) . |
---|
263 | + $nquery = "SELECT library FROM dependencies WHERE portfile='" . pg_escape_string($row['name']) . |
---|
264 | "' ORDER BY library"; |
---|
265 | - $nresult = mysql_query($nquery); |
---|
266 | - if ($nresult && mysql_num_rows($nresult) > 0) { |
---|
267 | + $nresult = pg_query($nquery); |
---|
268 | + if ($nresult && pg_num_rows($nresult) > 0) { |
---|
269 | print '<br /><i>Dependencies:</i> '; |
---|
270 | - while ($nrow = mysql_fetch_row($nresult)) { |
---|
271 | + while ($nrow = pg_fetch_row($nresult)) { |
---|
272 | $library = preg_replace('/^(?:[^:]*:){1,2}/', '', $nrow[0]); |
---|
273 | print "<a href=\"$phpself?by=library&substr=" . urlencode($library) . '">' |
---|
274 | . htmlspecialchars($library) . '</a> '; |
---|
275 | @@ -253,12 +257,12 @@ |
---|
276 | } |
---|
277 | |
---|
278 | /* Variants */ |
---|
279 | - $nquery = "SELECT variant FROM $portsdb_name.variants WHERE portfile='" . mysql_real_escape_string($row['name']) . |
---|
280 | + $nquery = "SELECT variant FROM variants WHERE portfile='" . pg_escape_string($row['name']) . |
---|
281 | "' ORDER BY variant"; |
---|
282 | - $nresult = mysql_query($nquery); |
---|
283 | - if ($nresult && mysql_num_rows($nresult) > 0) { |
---|
284 | + $nresult = pg_query($nquery); |
---|
285 | + if ($nresult && pg_num_rows($nresult) > 0) { |
---|
286 | print '<br /><i>Variants:</i> '; |
---|
287 | - while ($nrow = mysql_fetch_row($nresult)) { |
---|
288 | + while ($nrow = pg_fetch_row($nresult)) { |
---|
289 | print "<a href=\"$phpself?by=variant&substr=" . urlencode($nrow[0]) . '">' |
---|
290 | . htmlspecialchars($nrow[0]) . '</a> '; |
---|
291 | } |
---|
292 | @@ -274,7 +278,7 @@ |
---|
293 | |
---|
294 | /* When we hit this else, the query failed for some reason */ |
---|
295 | } else { |
---|
296 | - print '<p>An Error Occurred: '. mysql_error($portsdb_info['connection_handler']) . '</p>'; |
---|
297 | + print '<p>An Error Occurred: '. pg_last_error($portsdb_info['connection_handler']) . '</p>'; |
---|
298 | } |
---|
299 | |
---|
300 | } /* if (main query sent to the DB) */ |
---|
301 | @@ -285,5 +289,5 @@ |
---|
302 | |
---|
303 | <?php |
---|
304 | print_footer(); |
---|
305 | - mysql_close($portsdb_info['connection_handler']); |
---|
306 | + pg_close($portsdb_info['connection_handler']); |
---|
307 | ?> |
---|