mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
rss.php: Pull out DB code
* Move DB code in rss.php to new function in aur.inc.php * Centralization of DB code important in a future transition to PDO interface Signed-off-by: canyonknight <canyonknight@gmail.com> Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
parent
c15441762c
commit
41986bbc78
2 changed files with 21 additions and 6 deletions
|
@ -37,13 +37,9 @@ $image->description = "AUR Newest Packages Feed";
|
||||||
$rss->image = $image;
|
$rss->image = $image;
|
||||||
|
|
||||||
#Get the latest packages and add items for them
|
#Get the latest packages and add items for them
|
||||||
$dbh = db_connect();
|
$packages = latest_pkgs(20);
|
||||||
$q = "SELECT * FROM Packages ";
|
|
||||||
$q.= "ORDER BY SubmittedTS DESC ";
|
|
||||||
$q.= "LIMIT 20";
|
|
||||||
$result = db_query($q, $dbh);
|
|
||||||
|
|
||||||
while ($row = mysql_fetch_assoc($result)) {
|
while (list($indx, $row) = each($packages)) {
|
||||||
$item = new FeedItem();
|
$item = new FeedItem();
|
||||||
$item->title = $row["Name"];
|
$item->title = $row["Name"];
|
||||||
$item->link = "{$protocol}://{$host}/packages.php?ID={$row["ID"]}";
|
$item->link = "{$protocol}://{$host}/packages.php?ID={$row["ID"]}";
|
||||||
|
|
|
@ -533,3 +533,22 @@ function last_insert_id($dbh=NULL) {
|
||||||
}
|
}
|
||||||
return mysql_insert_id($dbh);
|
return mysql_insert_id($dbh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function latest_pkgs($numpkgs, $dbh=NULL) {
|
||||||
|
if(!$dbh) {
|
||||||
|
$dbh = db_connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
$q = "SELECT * FROM Packages ";
|
||||||
|
$q.= "ORDER BY SubmittedTS DESC ";
|
||||||
|
$q.= "LIMIT " .intval($numpkgs);
|
||||||
|
$result = db_query($q, $dbh);
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
while ($row = mysql_fetch_assoc($result)) {
|
||||||
|
$packages[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $packages;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue