summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to 'web')
-rw-r--r--web/html/account.php2
-rw-r--r--web/html/home.php2
-rw-r--r--web/html/logout.php2
-rw-r--r--web/html/pkgsubmit.php2
-rw-r--r--web/lib/DB.class.php28
-rw-r--r--web/lib/acctfuncs.inc.php48
-rw-r--r--web/lib/aur.inc.php49
-rw-r--r--web/lib/aurjson.class.php2
-rw-r--r--web/lib/pkgfuncs.inc.php72
-rw-r--r--web/lib/translator.inc.php7
10 files changed, 112 insertions, 102 deletions
diff --git a/web/html/account.php b/web/html/account.php
index 2133734..7cd0263 100644
--- a/web/html/account.php
+++ b/web/html/account.php
@@ -20,7 +20,7 @@ $action = in_request("Action");
if (isset($_COOKIE["AURSID"])) {
# visitor is logged in
#
- $dbh = db_connect();
+ $dbh = DB::connect();
$atype = account_from_sid($_COOKIE["AURSID"]);
if ($action == "SearchAccounts") {
diff --git a/web/html/home.php b/web/html/home.php
index 0b51d55..a10ebf0 100644
--- a/web/html/home.php
+++ b/web/html/home.php
@@ -10,7 +10,7 @@ include_once('stats.inc.php');
html_header( __("Home") );
-$dbh = db_connect();
+$dbh = DB::connect();
?>
diff --git a/web/html/logout.php b/web/html/logout.php
index 3d059e7..2d8bebc 100644
--- a/web/html/logout.php
+++ b/web/html/logout.php
@@ -11,7 +11,7 @@ include_once("acctfuncs.inc.php"); # access AUR common functions
#
if (isset($_COOKIE["AURSID"])) {
if (!isset($dbh)) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
delete_session_id($_COOKIE["AURSID"], $dbh);
# setting expiration to 1 means '1 second after midnight January 1, 1970'
diff --git a/web/html/pkgsubmit.php b/web/html/pkgsubmit.php
index 5dd58af..78fceac 100644
--- a/web/html/pkgsubmit.php
+++ b/web/html/pkgsubmit.php
@@ -356,7 +356,7 @@ if ($uid):
# Update the backend database
if (!$error) {
- $dbh = db_connect();
+ $dbh = DB::connect();
begin_atomic_commit($dbh);
$pdata = pkgdetails_by_pkgname($new_pkgbuild['pkgname'], $dbh);
diff --git a/web/lib/DB.class.php b/web/lib/DB.class.php
new file mode 100644
index 0000000..0975989
--- /dev/null
+++ b/web/lib/DB.class.php
@@ -0,0 +1,28 @@
+<?php
+
+class DB {
+
+ /**
+ * A database object
+ */
+ private static $dbh = null;
+
+ /**
+ * Return an already existing database object or newly instantiated object
+ *
+ * @return \PDO A database connection using PDO
+ */
+ public static function connect() {
+ if (self::$dbh === null) {
+ try {
+ self::$dbh = new PDO(AUR_db_DSN_prefix . ":" . AUR_db_host
+ . ";dbname=" . AUR_db_name, AUR_db_user, AUR_db_pass);
+ self::$dbh->exec("SET NAMES 'utf8' COLLATE 'utf8_general_ci';");
+ } catch (PDOException $e) {
+ die('Error - Could not connect to AUR database');
+ }
+ }
+
+ return self::$dbh;
+ }
+}
diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php
index 3759c63..1e25f62 100644
--- a/web/lib/acctfuncs.inc.php
+++ b/web/lib/acctfuncs.inc.php
@@ -95,7 +95,7 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
global $SUPPORTED_LANGS;
if (!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
if(isset($_COOKIE['AURSID'])) {
@@ -301,7 +301,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 ";
@@ -367,7 +367,7 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="",
$q.= "LIMIT " . $HITS_PER_PAGE . " OFFSET " . $OFFSET;
if (!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$result = $dbh->query($q);
@@ -398,7 +398,7 @@ function try_login($dbh=NULL) {
if ( isset($_REQUEST['user']) || isset($_REQUEST['passwd']) ) {
if (!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$userID = valid_user($_REQUEST['user'], $dbh);
@@ -522,7 +522,7 @@ function valid_user($user, $dbh=NULL) {
/* if ( $user = valid_username($user) ) { */
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
if ( $user ) {
@@ -549,7 +549,7 @@ function valid_user($user, $dbh=NULL) {
*/
function open_user_proposals($user, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT * FROM TU_VoteInfo WHERE User = " . $dbh->quote($user) . " ";
$q.= "AND End > UNIX_TIMESTAMP()";
@@ -575,7 +575,7 @@ function open_user_proposals($user, $dbh=NULL) {
*/
function add_tu_proposal($agenda, $user, $votelength, $submitteruid, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End, SubmitterID) VALUES ";
@@ -596,7 +596,7 @@ function add_tu_proposal($agenda, $user, $votelength, $submitteruid, $dbh=NULL)
*/
function create_resetkey($resetkey, $uid, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "UPDATE Users ";
$q.= "SET ResetKey = '" . $resetkey . "' ";
@@ -617,7 +617,7 @@ function create_resetkey($resetkey, $uid, $dbh=NULL) {
*/
function password_reset($hash, $salt, $resetkey, $email, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "UPDATE Users ";
$q.= "SET Passwd = '$hash', ";
@@ -662,7 +662,7 @@ function good_passwd($passwd) {
*/
function valid_passwd($userID, $passwd, $dbh=NULL) {
if (!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
if ( strlen($passwd) > 0 ) {
# get salt for this user
@@ -724,7 +724,7 @@ function valid_pgp_fingerprint($fingerprint) {
*/
function user_suspended($id, $dbh=NULL) {
if (!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
if (!$id) {
return false;
@@ -750,7 +750,7 @@ function user_suspended($id, $dbh=NULL) {
*/
function user_delete($id, $dbh=NULL) {
if (!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "DELETE FROM Users WHERE ID = " . $id;
$dbh->query($q);
@@ -767,7 +767,7 @@ function user_delete($id, $dbh=NULL) {
*/
function user_is_privileged($id, $dbh=NULL) {
if (!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT AccountTypeID FROM Users WHERE ID = " . $id;
$result = $dbh->query($q);
@@ -791,7 +791,7 @@ function user_is_privileged($id, $dbh=NULL) {
*/
function delete_session_id($sid, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "DELETE FROM Sessions WHERE SessionID = " . $dbh->quote($sid);
@@ -808,7 +808,7 @@ function delete_session_id($sid, $dbh=NULL) {
*/
function delete_user_sessions($uid, $dbh=NULL) {
if (!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "DELETE FROM Sessions WHERE UsersID = " . intval($uid);
@@ -827,7 +827,7 @@ function clear_expired_sessions($dbh=NULL) {
global $LOGIN_TIMEOUT;
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "DELETE FROM Sessions WHERE LastUpdateTS < (UNIX_TIMESTAMP() - $LOGIN_TIMEOUT)";
@@ -847,7 +847,7 @@ function clear_expired_sessions($dbh=NULL) {
*/
function account_details($uid, $username, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT Users.*, AccountTypes.AccountType ";
$q.= "FROM Users, AccountTypes ";
@@ -877,7 +877,7 @@ function account_details($uid, $username, $dbh=NULL) {
*/
function tu_voted($voteid, $uid, $dbh=NULL) {
if (!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT COUNT(*) FROM TU_Votes ";
@@ -901,7 +901,7 @@ function tu_voted($voteid, $uid, $dbh=NULL) {
*/
function current_proposal_list($order, $dbh=NULL) {
if (!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT * FROM TU_VoteInfo WHERE End > " . time() . " ORDER BY Submitted " . $order;
@@ -926,7 +926,7 @@ function current_proposal_list($order, $dbh=NULL) {
*/
function past_proposal_list($order, $lim, $dbh=NULL) {
if (!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT * FROM TU_VoteInfo WHERE End < " . time() . " ORDER BY Submitted " . $order . $lim;
@@ -949,7 +949,7 @@ function past_proposal_list($order, $lim, $dbh=NULL) {
*/
function proposal_count($dbh=NULL) {
if (!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT COUNT(*) FROM TU_VoteInfo";
@@ -969,7 +969,7 @@ function proposal_count($dbh=NULL) {
*/
function vote_details($voteid, $dbh=NULL) {
if (!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT * FROM TU_VoteInfo ";
@@ -991,7 +991,7 @@ function vote_details($voteid, $dbh=NULL) {
*/
function voter_list($voteid, $dbh=NULL) {
if (!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$whovoted = array();
@@ -1024,7 +1024,7 @@ function voter_list($voteid, $dbh=NULL) {
*/
function cast_proposal_vote($voteid, $uid, $vote, $newtotal, $dbh=NULL) {
if (!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "UPDATE TU_VoteInfo SET " . $vote . " = (" . $newtotal . ") WHERE ID = " . $voteid;
diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php
index d8c5cb4..9a84ec7 100644
--- a/web/lib/aur.inc.php
+++ b/web/lib/aur.inc.php
@@ -11,6 +11,7 @@ include_once('translator.inc.php');
set_lang();
include_once("config.inc.php");
+include_once("DB.class.php");
include_once("routing.inc.php");
include_once("version.inc.php");
include_once("acctfuncs.inc.php");
@@ -38,7 +39,7 @@ function check_sid($dbh=NULL) {
# 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"]);
@@ -145,7 +146,7 @@ function username_from_id($id="", $dbh=NULL) {
return "";
}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT Username FROM Users WHERE ID = " . $dbh->quote($id);
$result = $dbh->query($q);
@@ -170,7 +171,7 @@ function username_from_sid($sid="", $dbh=NULL) {
return "";
}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT Username ";
$q.= "FROM Users, Sessions ";
@@ -198,7 +199,7 @@ function email_from_sid($sid="", $dbh=NULL) {
return "";
}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT Email ";
$q.= "FROM Users, Sessions ";
@@ -226,7 +227,7 @@ function account_from_sid($sid="", $dbh=NULL) {
return "";
}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT AccountType ";
$q.= "FROM Users, AccountTypes, Sessions ";
@@ -255,7 +256,7 @@ function uid_from_sid($sid="", $dbh=NULL) {
return "";
}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT Users.ID ";
$q.= "FROM Users, Sessions ";
@@ -271,24 +272,6 @@ function uid_from_sid($sid="", $dbh=NULL) {
}
/**
- * Establish a connection with a database using PDO
- *
- * @return \PDO A database connection
- */
-function db_connect() {
- try {
- $dbh = new PDO(AUR_db_DSN_prefix . ":" . AUR_db_host . ";dbname=" . AUR_db_name, AUR_db_user, AUR_db_pass);
- }
- catch (PDOException $e) {
- echo "Error - Could not connect to AUR database: " . $e->getMessage();
- }
-
- $dbh->exec("SET NAMES 'utf8' COLLATE 'utf8_general_ci';");
-
- return $dbh;
-}
-
-/**
* Common AUR header displayed on all pages
*
* @global string $LANG Language selected by the visitor
@@ -331,7 +314,7 @@ function html_footer($ver="") {
function can_submit_pkg($name="", $sid="", $dbh=NULL) {
if (!$name || !$sid) {return 0;}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT MaintainerUID ";
$q.= "FROM Packages WHERE Name = " . $dbh->quote($name);
@@ -390,7 +373,7 @@ function uid_from_username($username="", $dbh=NULL) {
return "";
}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT ID FROM Users WHERE Username = " . $dbh->quote($username);
$result = $dbh->query($q);
@@ -415,7 +398,7 @@ function uid_from_email($email="", $dbh=NULL) {
return "";
}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT ID FROM Users WHERE Email = " . $dbh->quote($email);
$result = $dbh->query($q);
@@ -481,7 +464,7 @@ function mkurl($append) {
*/
function get_salt($user_id, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT Salt FROM Users WHERE ID = " . $user_id;
$result = $dbh->query($q);
@@ -501,7 +484,7 @@ function get_salt($user_id, $dbh=NULL) {
*/
function save_salt($user_id, $passwd, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$salt = generate_salt();
$hash = salted_hash($passwd, $salt);
@@ -571,7 +554,7 @@ function parse_comment($comment) {
*/
function begin_atomic_commit($dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$dbh->beginTransaction();
}
@@ -583,7 +566,7 @@ function begin_atomic_commit($dbh=NULL) {
*/
function end_atomic_commit($dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$dbh->commit();
}
@@ -598,7 +581,7 @@ function end_atomic_commit($dbh=NULL) {
*/
function last_insert_id($dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
return $dbh->lastInsertId();
}
@@ -613,7 +596,7 @@ function last_insert_id($dbh=NULL) {
*/
function latest_pkgs($numpkgs, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT * FROM Packages ";
diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index 616b783..b905275 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -52,7 +52,7 @@ class AurJSON {
// do the routing
if ( in_array($http_data['type'], self::$exposed_methods) ) {
// set up db connection.
- $this->dbh = db_connect();
+ $this->dbh = DB::connect();
// ugh. this works. I hate you php.
$json = call_user_func(array(&$this, $http_data['type']),
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
index 568ca3d..b29acb3 100644
--- a/web/lib/pkgfuncs.inc.php
+++ b/web/lib/pkgfuncs.inc.php
@@ -20,7 +20,7 @@ function canDeleteComment($comment_id=0, $atype="", $uid=0, $dbh=NULL) {
return TRUE;
}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT COUNT(ID) AS CNT ";
$q.= "FROM PackageComments ";
@@ -89,7 +89,7 @@ function canSubmitBlacklisted($atype = "") {
function pkgCategories($dbh=NULL) {
$cats = array();
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT * FROM PackageCategories WHERE ID != 1 ";
$q.= "ORDER BY Category ASC";
@@ -113,7 +113,7 @@ function pkgCategories($dbh=NULL) {
function pkgid_from_name($name="", $dbh=NULL) {
if (!$name) {return NULL;}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT ID FROM Packages ";
$q.= "WHERE Name = " . $dbh->quote($name);
@@ -138,7 +138,7 @@ function package_dependencies($pkgid, $dbh=NULL) {
$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 ";
@@ -167,7 +167,7 @@ function package_required($name="", $dbh=NULL) {
$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 ";
@@ -192,13 +192,13 @@ function package_required($name="", $dbh=NULL) {
*/
function package_comments_count($pkgid, $dbh=NULL) {
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;
@@ -227,7 +227,7 @@ function package_comments($pkgid, $dbh=NULL) {
$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 ";
@@ -268,7 +268,7 @@ function add_package_comment($pkgid, $uid, $comment, $dbh=NULL) {
global $AUR_LOCATION;
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "INSERT INTO PackageComments ";
@@ -326,7 +326,7 @@ function package_sources($pkgid, $dbh=NULL) {
$pkgid = intval($pkgid);
if ($pkgid > 0) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT Source FROM PackageSources ";
$q.= "WHERE PackageID = " . $pkgid;
@@ -354,7 +354,7 @@ function pkgvotes_from_sid($sid="", $dbh=NULL) {
$pkgs = array();
if (!$sid) {return $pkgs;}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT PackageID ";
$q.= "FROM PackageVotes, Users, Sessions ";
@@ -383,7 +383,7 @@ function pkgname_from_id($pkgids, $dbh=NULL) {
$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) . ")";
@@ -397,7 +397,7 @@ function pkgname_from_id($pkgids, $dbh=NULL) {
}
elseif ($pkgids > 0) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT Name FROM Packages WHERE ID = " . $pkgids;
$result = $dbh->query($q);
@@ -421,7 +421,7 @@ function pkgname_from_id($pkgids, $dbh=NULL) {
*/
function pkgname_is_blacklisted($name, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT COUNT(*) FROM PackageBlacklist ";
$q.= "WHERE Name = " . $dbh->quote($name);
@@ -441,7 +441,7 @@ function pkgname_is_blacklisted($name, $dbh=NULL) {
**/
function get_package_details($id=0, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT Packages.*,Category ";
@@ -482,7 +482,7 @@ function display_package_details($id=0, $row, $SID="", $dbh=NULL) {
global $USE_VIRTUAL_URLS;
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
if (isset($row['error'])) {
@@ -556,7 +556,7 @@ function display_package_details($id=0, $row, $SID="", $dbh=NULL) {
*/
function pkg_search_page($SID="", $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
// get commonly used variables...
@@ -814,7 +814,7 @@ function pkg_flag($atype, $ids, $dbh=NULL) {
}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "UPDATE Packages SET";
@@ -868,7 +868,7 @@ function pkg_unflag($atype, $ids, $dbh=NULL) {
}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "UPDATE Packages SET ";
@@ -911,7 +911,7 @@ function pkg_delete ($atype, $ids, $mergepkgid, $dbh=NULL) {
}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
if ($mergepkgid) {
@@ -1013,7 +1013,7 @@ function pkg_adopt ($atype, $ids, $action=true, $dbh=NULL) {
}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$field = "MaintainerUID";
@@ -1073,7 +1073,7 @@ function pkg_vote ($atype, $ids, $action=true, $dbh=NULL) {
}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$my_votes = pkgvotes_from_sid($_COOKIE["AURSID"], $dbh);
$uid = uid_from_sid($_COOKIE["AURSID"], $dbh);
@@ -1143,7 +1143,7 @@ function pkg_vote ($atype, $ids, $action=true, $dbh=NULL) {
*/
function getvotes($pkgid, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT UsersID,Username FROM PackageVotes ";
@@ -1175,7 +1175,7 @@ function getvotes($pkgid, $dbh=NULL) {
*/
function user_voted($uid, $pkgid, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT * FROM PackageVotes WHERE UsersID = ". $dbh->quote($uid);
@@ -1201,7 +1201,7 @@ function user_voted($uid, $pkgid, $dbh=NULL) {
*/
function user_notify($uid, $pkgid, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT * FROM CommentNotify WHERE UserID = " . $dbh->quote($uid);
@@ -1236,7 +1236,7 @@ function pkg_notify ($atype, $ids, $action=true, $dbh=NULL) {
}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$uid = uid_from_sid($_COOKIE["AURSID"], $dbh);
@@ -1315,7 +1315,7 @@ function pkg_delete_comment($atype, $dbh=NULL) {
}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$uid = uid_from_sid($_COOKIE["AURSID"], $dbh);
if (canDeleteComment($comment_id, $atype, $uid, $dbh)) {
@@ -1349,7 +1349,7 @@ function pkg_change_category($pid, $atype, $dbh=NULL) {
}
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$catArray = pkgCategories($dbh);
if (!array_key_exists($category_id, $catArray)) {
@@ -1391,7 +1391,7 @@ function pkg_change_category($pid, $atype, $dbh=NULL) {
*/
function pkgdetails_by_pkgname($pkgname, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "SELECT * FROM Packages WHERE Name = " . $dbh->quote($pkgname);
$result = $dbh->query($q);
@@ -1417,7 +1417,7 @@ function pkgdetails_by_pkgname($pkgname, $dbh=NULL) {
*/
function new_pkgdetails($pkgname, $license, $pkgver, $category_id, $pkgdesc, $pkgurl, $uid, $dbh=NULL) {
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),
@@ -1448,7 +1448,7 @@ function new_pkgdetails($pkgname, $license, $pkgver, $category_id, $pkgdesc, $pk
*/
function update_pkgdetails($pkgname, $license, $pkgver, $pkgdesc, $pkgurl, $uid, $pkgid, $dbh=NULL) {
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",
@@ -1475,7 +1475,7 @@ function update_pkgdetails($pkgname, $license, $pkgver, $pkgdesc, $pkgurl, $uid,
*/
function add_pkg_dep($pkgid, $depname, $depcondition, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = sprintf("INSERT INTO PackageDepends (PackageID, DepName, DepCondition) VALUES (%d, %s, %s)",
$pkgid,
@@ -1496,7 +1496,7 @@ function add_pkg_dep($pkgid, $depname, $depcondition, $dbh=NULL) {
*/
function add_pkg_src($pkgid, $pkgsrc, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "INSERT INTO PackageSources (PackageID, Source) VALUES (";
$q .= $pkgid . ", " . $dbh->quote($pkgsrc) . ")";
@@ -1515,7 +1515,7 @@ function add_pkg_src($pkgid, $pkgsrc, $dbh=NULL) {
*/
function update_pkg_category($pkgid, $category_id, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = sprintf( "UPDATE Packages SET CategoryID = %d WHERE ID = %d",
$category_id,
@@ -1534,7 +1534,7 @@ function update_pkg_category($pkgid, $category_id, $dbh=NULL) {
*/
function remove_pkg_deps($pkgid, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "DELETE FROM PackageDepends WHERE PackageID = " . $pkgid;
@@ -1551,7 +1551,7 @@ function remove_pkg_deps($pkgid, $dbh=NULL) {
*/
function remove_pkg_sources($pkgid, $dbh=NULL) {
if(!$dbh) {
- $dbh = db_connect();
+ $dbh = DB::connect();
}
$q = "DELETE FROM PackageSources WHERE PackageID = " . $pkgid;
diff --git a/web/lib/translator.inc.php b/web/lib/translator.inc.php
index 1477b17..67693e0 100644
--- a/web/lib/translator.inc.php
+++ b/web/lib/translator.inc.php
@@ -12,6 +12,7 @@ set_include_path(get_include_path() . PATH_SEPARATOR . '../lib' . PATH_SEPARATOR
# print __("This is a %smajor%s problem!", "<strong>", "</strong>");
include_once('config.inc.php');
+include_once('DB.class.php');
include_once('gettext.php');
include_once('streams.php');
@@ -69,7 +70,7 @@ function __() {
# set up the visitor's language
#
-function set_lang($dbh=NULL) {
+function set_lang() {
global $LANG;
global $SUPPORTED_LANGS;
global $PERSISTENT_COOKIE_TIMEOUT;
@@ -90,9 +91,7 @@ function set_lang($dbh=NULL) {
} elseif (isset($_COOKIE["AURSID"])) {
# No language but a session; use default lang preference
#
- if(!$dbh) {
- $dbh = db_connect();
- }
+ $dbh = DB::connect();
$q = "SELECT LangPreference FROM Users, Sessions ";
$q.= "WHERE Users.ID = Sessions.UsersID ";
$q.= "AND Sessions.SessionID = '";