summaryrefslogtreecommitdiffstats
path: root/web/lib
diff options
context:
space:
mode:
Diffstat (limited to 'web/lib')
-rw-r--r--web/lib/acctfuncs.inc.php97
-rw-r--r--web/lib/aur.inc.php60
-rw-r--r--web/lib/pkgfuncs.inc.php144
3 files changed, 75 insertions, 226 deletions
diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php
index e982849f..9c0998a5 100644
--- a/web/lib/acctfuncs.inc.php
+++ b/web/lib/acctfuncs.inc.php
@@ -93,9 +93,7 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
# error check and process request for a new/modified account
global $SUPPORTED_LANGS;
- if (!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
if(isset($_COOKIE['AURSID'])) {
$editor_user = uid_from_sid($_COOKIE['AURSID']);
@@ -298,9 +296,7 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="",
}
$search_vars = array();
- if (!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT Users.*, AccountTypes.AccountType ";
$q.= "FROM Users, AccountTypes ";
@@ -364,9 +360,7 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="",
$search_vars[] = "SB";
$q.= "LIMIT " . $HITS_PER_PAGE . " OFFSET " . $OFFSET;
- if (!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$result = $dbh->query($q);
@@ -394,9 +388,7 @@ function try_login() {
$userID = null;
if ( isset($_REQUEST['user']) || isset($_REQUEST['passwd']) ) {
- if (!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$userID = valid_user($_REQUEST['user']);
if ( user_suspended($userID) ) {
@@ -517,9 +509,7 @@ function valid_username($user) {
function valid_user($user) {
/* if ( $user = valid_username($user) ) { */
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
if ( $user ) {
$q = "SELECT ID FROM Users ";
@@ -543,9 +533,7 @@ function valid_user($user) {
* @return bool True if there is an open proposal about the user, otherwise false
*/
function open_user_proposals($user) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT * FROM TU_VoteInfo WHERE User = " . $dbh->quote($user) . " ";
$q.= "AND End > UNIX_TIMESTAMP()";
$result = $dbh->query($q);
@@ -568,9 +556,7 @@ function open_user_proposals($user) {
* @return void
*/
function add_tu_proposal($agenda, $user, $votelength, $submitteruid) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End, SubmitterID) VALUES ";
$q.= "(" . $dbh->quote($agenda) . ", " . $dbh->quote($user) . ", ";
@@ -588,9 +574,7 @@ function add_tu_proposal($agenda, $user, $votelength, $submitteruid) {
* @return void
*/
function create_resetkey($resetkey, $uid) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "UPDATE Users ";
$q.= "SET ResetKey = '" . $resetkey . "' ";
$q.= "WHERE ID = " . $uid;
@@ -608,9 +592,7 @@ function create_resetkey($resetkey, $uid) {
* @return string|void Redirect page if successful, otherwise return error message
*/
function password_reset($hash, $salt, $resetkey, $email) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "UPDATE Users ";
$q.= "SET Passwd = '$hash', ";
$q.= "Salt = '$salt', ";
@@ -652,9 +634,7 @@ function good_passwd($passwd) {
* @return bool True if password was correct and properly salted, otherwise false
*/
function valid_passwd($userID, $passwd) {
- if (!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
if ( strlen($passwd) > 0 ) {
# get salt for this user
$salt = get_salt($userID);
@@ -713,9 +693,7 @@ function valid_pgp_fingerprint($fingerprint) {
* @return bool True if the user is suspended, otherwise false
*/
function user_suspended($id) {
- if (!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
if (!$id) {
return false;
}
@@ -738,9 +716,7 @@ function user_suspended($id) {
* @return void
*/
function user_delete($id) {
- if (!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "DELETE FROM Users WHERE ID = " . $id;
$dbh->query($q);
return;
@@ -754,9 +730,7 @@ function user_delete($id) {
* @return int|string Return 0 if un-privileged, "2" if Trusted User, "3" if Developer
*/
function user_is_privileged($id) {
- if (!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT AccountTypeID FROM Users WHERE ID = " . $id;
$result = $dbh->query($q);
if ($result) {
@@ -777,9 +751,7 @@ function user_is_privileged($id) {
* @return void
*/
function delete_session_id($sid) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "DELETE FROM Sessions WHERE SessionID = " . $dbh->quote($sid);
$dbh->query($q);
@@ -793,9 +765,7 @@ function delete_session_id($sid) {
* @return void
*/
function delete_user_sessions($uid) {
- if (!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "DELETE FROM Sessions WHERE UsersID = " . intval($uid);
$dbh->exec($q);
@@ -811,9 +781,7 @@ function delete_user_sessions($uid) {
function clear_expired_sessions() {
global $LOGIN_TIMEOUT;
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "DELETE FROM Sessions WHERE LastUpdateTS < (UNIX_TIMESTAMP() - $LOGIN_TIMEOUT)";
$dbh->query($q);
@@ -830,9 +798,7 @@ function clear_expired_sessions() {
* @return array Account details for the specified user
*/
function account_details($uid, $username) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT Users.*, AccountTypes.AccountType ";
$q.= "FROM Users, AccountTypes ";
$q.= "WHERE AccountTypes.ID = Users.AccountTypeID ";
@@ -859,9 +825,7 @@ function account_details($uid, $username) {
* @return bool True if the user has already voted, otherwise false
*/
function tu_voted($voteid, $uid) {
- if (!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT COUNT(*) FROM TU_Votes ";
$q.= "WHERE VoteID = " . intval($voteid) . " AND UserID = " . intval($uid);
@@ -882,9 +846,7 @@ function tu_voted($voteid, $uid) {
* @return array The details for all current Trusted User proposals
*/
function current_proposal_list($order) {
- if (!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT * FROM TU_VoteInfo WHERE End > " . time() . " ORDER BY Submitted " . $order;
$result = $dbh->query($q);
@@ -906,9 +868,7 @@ function current_proposal_list($order) {
* @return array The details for the subset of past Trusted User proposals
*/
function past_proposal_list($order, $lim) {
- if (!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT * FROM TU_VoteInfo WHERE End < " . time() . " ORDER BY Submitted " . $order . $lim;
$result = $dbh->query($q);
@@ -927,10 +887,7 @@ function past_proposal_list($order, $lim) {
* @return string The total number of Trusted User proposals
*/
function proposal_count() {
- if (!$dbh) {
- $dbh = DB::connect();
- }
-
+ $dbh = DB::connect();
$q = "SELECT COUNT(*) FROM TU_VoteInfo";
$result = $dbh->query($q);
$row = $result->fetch(PDO::FETCH_NUM);
@@ -946,9 +903,7 @@ function proposal_count() {
* @return array All stored details for a specific vote
*/
function vote_details($voteid) {
- if (!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT * FROM TU_VoteInfo ";
$q.= "WHERE ID = " . intval($voteid);
@@ -967,9 +922,7 @@ function vote_details($voteid) {
* @return array All users who voted for a specific proposal
*/
function voter_list($voteid) {
- if (!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$whovoted = array();
@@ -999,9 +952,7 @@ function voter_list($voteid) {
* @return void
*/
function cast_proposal_vote($voteid, $uid, $vote, $newtotal) {
- if (!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "UPDATE TU_VoteInfo SET " . $vote . " = (" . $newtotal . ") WHERE ID = " . $voteid;
$result = $dbh->exec($q);
diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php
index 3182dc92..b3a800c5 100644
--- a/web/lib/aur.inc.php
+++ b/web/lib/aur.inc.php
@@ -37,9 +37,7 @@ function check_sid() {
$failed = 0;
# the visitor is logged in, try and update the session
#
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT LastUpdateTS, UNIX_TIMESTAMP() FROM Sessions ";
$q.= "WHERE SessionID = " . $dbh->quote($_COOKIE["AURSID"]);
$result = $dbh->query($q);
@@ -143,9 +141,7 @@ function username_from_id($id="") {
if (!$id) {
return "";
}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT Username FROM Users WHERE ID = " . $dbh->quote($id);
$result = $dbh->query($q);
if (!$result) {
@@ -167,9 +163,7 @@ function username_from_sid($sid="") {
if (!$sid) {
return "";
}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT Username ";
$q.= "FROM Users, Sessions ";
$q.= "WHERE Users.ID = Sessions.UsersID ";
@@ -194,9 +188,7 @@ function email_from_sid($sid="") {
if (!$sid) {
return "";
}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT Email ";
$q.= "FROM Users, Sessions ";
$q.= "WHERE Users.ID = Sessions.UsersID ";
@@ -221,9 +213,7 @@ function account_from_sid($sid="") {
if (!$sid) {
return "";
}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT AccountType ";
$q.= "FROM Users, AccountTypes, Sessions ";
$q.= "WHERE Users.ID = Sessions.UsersID ";
@@ -249,9 +239,7 @@ function uid_from_sid($sid="") {
if (!$sid) {
return "";
}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT Users.ID ";
$q.= "FROM Users, Sessions ";
$q.= "WHERE Users.ID = Sessions.UsersID ";
@@ -306,9 +294,7 @@ function html_footer($ver="") {
*/
function can_submit_pkg($name="", $sid="") {
if (!$name || !$sid) {return 0;}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT MaintainerUID ";
$q.= "FROM Packages WHERE Name = " . $dbh->quote($name);
$result = $dbh->query($q);
@@ -364,9 +350,7 @@ function uid_from_username($username="") {
if (!$username) {
return "";
}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT ID FROM Users WHERE Username = " . $dbh->quote($username);
$result = $dbh->query($q);
if (!$result) {
@@ -388,9 +372,7 @@ function uid_from_email($email="") {
if (!$email) {
return "";
}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT ID FROM Users WHERE Email = " . $dbh->quote($email);
$result = $dbh->query($q);
if (!$result) {
@@ -453,9 +435,7 @@ function mkurl($append) {
* @return string|void Return the salt for the requested user, otherwise void
*/
function get_salt($user_id) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT Salt FROM Users WHERE ID = " . $user_id;
$result = $dbh->query($q);
if ($result) {
@@ -472,9 +452,7 @@ function get_salt($user_id) {
* @param string $passwd The password of the user logging in
*/
function save_salt($user_id, $passwd) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$salt = generate_salt();
$hash = salted_hash($passwd, $salt);
$q = "UPDATE Users SET Salt = " . $dbh->quote($salt) . ", ";
@@ -540,9 +518,7 @@ function parse_comment($comment) {
* Wrapper for beginning a database transaction
*/
function begin_atomic_commit() {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$dbh->beginTransaction();
}
@@ -550,9 +526,7 @@ function begin_atomic_commit() {
* Wrapper for committing a database transaction
*/
function end_atomic_commit() {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$dbh->commit();
}
@@ -563,9 +537,7 @@ function end_atomic_commit() {
* @return string The ID of the last inserted row
*/
function last_insert_id() {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
return $dbh->lastInsertId();
}
@@ -577,9 +549,7 @@ function last_insert_id() {
* @return array $packages Package info for the specified number of recent packages
*/
function latest_pkgs($numpkgs) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT * FROM Packages ";
$q.= "ORDER BY SubmittedTS DESC ";
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
index acaa218b..5ad53b22 100644
--- a/web/lib/pkgfuncs.inc.php
+++ b/web/lib/pkgfuncs.inc.php
@@ -18,9 +18,7 @@ function canDeleteComment($comment_id=0, $atype="", $uid=0) {
# A TU/Dev can delete any comment
return TRUE;
}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT COUNT(ID) AS CNT ";
$q.= "FROM PackageComments ";
$q.= "WHERE ID = " . intval($comment_id);
@@ -87,9 +85,7 @@ function canSubmitBlacklisted($atype = "") {
*/
function pkgCategories() {
$cats = array();
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT * FROM PackageCategories WHERE ID != 1 ";
$q.= "ORDER BY Category ASC";
$result = $dbh->query($q);
@@ -110,9 +106,7 @@ function pkgCategories() {
*/
function pkgid_from_name($name="") {
if (!$name) {return NULL;}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT ID FROM Packages ";
$q.= "WHERE Name = " . $dbh->quote($name);
$result = $dbh->query($q);
@@ -134,9 +128,7 @@ function package_dependencies($pkgid) {
$deps = array();
$pkgid = intval($pkgid);
if ($pkgid > 0) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT pd.DepName, pd.DepCondition, p.ID FROM PackageDepends pd ";
$q.= "LEFT JOIN Packages p ON pd.DepName = p.Name ";
$q.= "WHERE pd.PackageID = ". $pkgid . " ";
@@ -162,9 +154,7 @@ function package_dependencies($pkgid) {
function package_required($name="") {
$deps = array();
if ($name != "") {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT DISTINCT p.Name, PackageID FROM PackageDepends pd ";
$q.= "JOIN Packages p ON pd.PackageID = p.ID ";
$q.= "WHERE DepName = " . $dbh->quote($name) . " ";
@@ -186,15 +176,11 @@ function package_required($name="") {
* @return string The number of comments left for a specific package
*/
function package_comments_count($pkgid) {
- if (!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$pkgid = intval($pkgid);
if ($pkgid > 0) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT COUNT(*) FROM PackageComments ";
$q.= "WHERE PackageID = " . $pkgid;
$q.= " AND DelUsersID IS NULL";
@@ -220,9 +206,7 @@ function package_comments($pkgid) {
$comments = array();
$pkgid = intval($pkgid);
if ($pkgid > 0) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT PackageComments.ID, UserName, UsersID, Comments, CommentTS ";
$q.= "FROM PackageComments, Users ";
$q.= "WHERE PackageComments.UsersID = Users.ID";
@@ -260,9 +244,7 @@ function package_comments($pkgid) {
function add_package_comment($pkgid, $uid, $comment) {
global $AUR_LOCATION;
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "INSERT INTO PackageComments ";
$q.= "(PackageID, UsersID, Comments, CommentTS) VALUES (";
@@ -317,9 +299,7 @@ function package_sources($pkgid) {
$sources = array();
$pkgid = intval($pkgid);
if ($pkgid > 0) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT Source FROM PackageSources ";
$q.= "WHERE PackageID = " . $pkgid;
$q.= " ORDER BY Source";
@@ -344,9 +324,7 @@ function package_sources($pkgid) {
function pkgvotes_from_sid($sid="") {
$pkgs = array();
if (!$sid) {return $pkgs;}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT PackageID ";
$q.= "FROM PackageVotes, Users, Sessions ";
$q.= "WHERE Users.ID = Sessions.UsersID ";
@@ -372,9 +350,7 @@ function pkgname_from_id($pkgids) {
if (is_array($pkgids)) {
$pkgids = sanitize_ids($pkgids);
$names = array();
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT Name FROM Packages WHERE ID IN (";
$q.= implode(",", $pkgids) . ")";
$result = $dbh->query($q);
@@ -386,9 +362,7 @@ function pkgname_from_id($pkgids) {
return $names;
}
elseif ($pkgids > 0) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT Name FROM Packages WHERE ID = " . $pkgids;
$result = $dbh->query($q);
if ($result) {
@@ -409,9 +383,7 @@ function pkgname_from_id($pkgids) {
* @return bool True if the name is blacklisted, otherwise false
*/
function pkgname_is_blacklisted($name) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT COUNT(*) FROM PackageBlacklist ";
$q.= "WHERE Name = " . $dbh->quote($name);
$result = $dbh->query($q);
@@ -428,9 +400,7 @@ function pkgname_is_blacklisted($name) {
* @return array The package's details OR error message
**/
function get_package_details($id=0) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT Packages.*,Category ";
$q.= "FROM Packages,PackageCategories ";
@@ -468,9 +438,7 @@ function display_package_details($id=0, $row, $SID="") {
global $AUR_LOCATION;
global $USE_VIRTUAL_URLS;
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
if (isset($row['error'])) {
print "<p>" . $row['error'] . "</p>\n";
@@ -542,9 +510,7 @@ function display_package_details($id=0, $row, $SID="") {
* do_UnNotify - Disable notification
*/
function pkg_search_page($SID="") {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
// get commonly used variables...
// TODO: REDUCE DB HITS.
@@ -800,9 +766,7 @@ function pkg_flag($atype, $ids) {
return __("You did not select any packages to flag.");
}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "UPDATE Packages SET";
$q.= " OutOfDateTS = UNIX_TIMESTAMP()";
@@ -854,9 +818,7 @@ function pkg_unflag($atype, $ids) {
return __("You did not select any packages to unflag.");
}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "UPDATE Packages SET ";
$q.= "OutOfDateTS = NULL ";
@@ -897,9 +859,7 @@ function pkg_delete ($atype, $ids, $mergepkgid) {
return __("You did not select any packages to delete.");
}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
if ($mergepkgid) {
$mergepkgname = pkgname_from_id($mergepkgid);
@@ -999,9 +959,7 @@ function pkg_adopt ($atype, $ids, $action=true) {
}
}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$field = "MaintainerUID";
$q = "UPDATE Packages ";
@@ -1059,9 +1017,7 @@ function pkg_vote ($atype, $ids, $action=true) {
}
}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$my_votes = pkgvotes_from_sid($_COOKIE["AURSID"]);
$uid = uid_from_sid($_COOKIE["AURSID"]);
@@ -1128,9 +1084,7 @@ function pkg_vote ($atype, $ids, $action=true) {
* @return array User IDs and usernames that voted for a specific package
*/
function getvotes($pkgid) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT UsersID,Username FROM PackageVotes ";
$q.= "LEFT JOIN Users on (UsersID = ID) ";
@@ -1159,9 +1113,7 @@ function getvotes($pkgid) {
* @return bool True if the user has already voted, otherwise false
*/
function user_voted($uid, $pkgid) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT * FROM PackageVotes WHERE UsersID = ". $dbh->quote($uid);
$q.= " AND PackageID = " . $dbh->quote($pkgid);
@@ -1184,9 +1136,7 @@ function user_voted($uid, $pkgid) {
* @return bool True if the user wants notifications, otherwise false
*/
function user_notify($uid, $pkgid) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT * FROM CommentNotify WHERE UserID = " . $dbh->quote($uid);
$q.= " AND PkgID = " . $dbh->quote($pkgid);
@@ -1219,9 +1169,7 @@ function pkg_notify ($atype, $ids, $action=true) {
return __("Couldn't add to notification list.");
}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$uid = uid_from_sid($_COOKIE["AURSID"]);
$output = "";
@@ -1298,9 +1246,7 @@ function pkg_delete_comment($atype) {
return __("Missing comment ID.");
}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$uid = uid_from_sid($_COOKIE["AURSID"]);
if (canDeleteComment($comment_id, $atype, $uid)) {
$q = "UPDATE PackageComments ";
@@ -1332,9 +1278,7 @@ function pkg_change_category($pid, $atype) {
return __("Missing category ID.");
}
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$catArray = pkgCategories($dbh);
if (!array_key_exists($category_id, $catArray)) {
return __("Invalid category ID.");
@@ -1373,9 +1317,7 @@ function pkg_change_category($pid, $atype) {
* @return array All package details for a specific package
*/
function pkgdetails_by_pkgname($pkgname) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "SELECT * FROM Packages WHERE Name = " . $dbh->quote($pkgname);
$result = $dbh->query($q);
if ($result) {
@@ -1398,9 +1340,7 @@ function pkgdetails_by_pkgname($pkgname) {
* @return void
*/
function new_pkgdetails($pkgname, $license, $pkgver, $category_id, $pkgdesc, $pkgurl, $uid) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = sprintf("INSERT INTO Packages (Name, License, Version, CategoryID, Description, URL, SubmittedTS, ModifiedTS, SubmitterUID, MaintainerUID) VALUES (%s, %s, %s, %d, %s, %s, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), %d, %d)",
$dbh->quote($pkgname),
$dbh->quote($license),
@@ -1428,9 +1368,7 @@ function new_pkgdetails($pkgname, $license, $pkgver, $category_id, $pkgdesc, $pk
* @return void
*/
function update_pkgdetails($pkgname, $license, $pkgver, $pkgdesc, $pkgurl, $uid, $pkgid) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
# This is an overwrite of an existing package
$q = sprintf("UPDATE Packages SET ModifiedTS = UNIX_TIMESTAMP(), Name = %s, Version = %s, License = %s, Description = %s, URL = %s, OutOfDateTS = NULL, MaintainerUID = %d WHERE ID = %d",
$dbh->quote($pkgname),
@@ -1454,9 +1392,7 @@ function update_pkgdetails($pkgname, $license, $pkgver, $pkgdesc, $pkgurl, $uid,
* @return void
*/
function add_pkg_dep($pkgid, $depname, $depcondition) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = sprintf("INSERT INTO PackageDepends (PackageID, DepName, DepCondition) VALUES (%d, %s, %s)",
$pkgid,
$dbh->quote($depname),
@@ -1474,9 +1410,7 @@ function add_pkg_dep($pkgid, $depname, $depcondition) {
* @return void
*/
function add_pkg_src($pkgid, $pkgsrc) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "INSERT INTO PackageSources (PackageID, Source) VALUES (";
$q .= $pkgid . ", " . $dbh->quote($pkgsrc) . ")";
@@ -1492,9 +1426,7 @@ function add_pkg_src($pkgid, $pkgsrc) {
* @return void
*/
function update_pkg_category($pkgid, $category_id) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = sprintf( "UPDATE Packages SET CategoryID = %d WHERE ID = %d",
$category_id,
$pkgid);
@@ -1510,9 +1442,7 @@ function update_pkg_category($pkgid, $category_id) {
* @return void
*/
function remove_pkg_deps($pkgid) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "DELETE FROM PackageDepends WHERE PackageID = " . $pkgid;
$dbh->exec($q);
@@ -1526,9 +1456,7 @@ function remove_pkg_deps($pkgid) {
* @return void
*/
function remove_pkg_sources($pkgid) {
- if(!$dbh) {
- $dbh = DB::connect();
- }
+ $dbh = DB::connect();
$q = "DELETE FROM PackageSources WHERE PackageID = " . $pkgid;
$dbh->exec($q);