From 0a66f48aa1293f93579b7de9bc5d080cf5f3105e Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Thu, 5 Jun 2014 14:47:38 +0200 Subject: Do not return "None" in user functions Return null instead of the string "None" in username_from_id(), uid_from_email() and uid_from_username(). Signed-off-by: Lukas Fleischer --- web/html/passreset.php | 2 +- web/lib/acctfuncs.inc.php | 2 +- web/lib/aur.inc.php | 44 ++++++++++++++++++++----------------- web/template/pkg_details.php | 18 +++++++-------- web/template/pkgbase_details.php | 18 +++++++-------- web/template/tu_details.php | 2 +- web/template/tu_last_votes_list.php | 4 ++-- 7 files changed, 47 insertions(+), 43 deletions(-) (limited to 'web') diff --git a/web/html/passreset.php b/web/html/passreset.php index 9541021c..9d8e1aee 100644 --- a/web/html/passreset.php +++ b/web/html/passreset.php @@ -25,7 +25,7 @@ if (isset($_GET['resetkey'], $_POST['email'], $_POST['password'], $_POST['confir $error = __('Missing a required field.'); } elseif ($password != $confirm) { $error = __('Password fields do not match.'); - } elseif ($uid == NULL || $uid == 'None') { + } elseif ($uid == null) { $error = __('Invalid e-mail.'); } diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index 51ffec63..a9965619 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -642,7 +642,7 @@ function send_resetkey($email, $subject, $body) { global $AUR_LOCATION; $uid = uid_from_email($email); - if ($uid != NULL && $uid != 'None') { + if ($uid != null) { /* * We (ab)use new_sid() to get a random 32 characters long * string. diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 99f5ae4a..33686968 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -135,20 +135,19 @@ function new_sid() { * * @param string $id User's ID * - * @return string Username if it exists, otherwise "None" + * @return string Username if it exists, otherwise null */ -function username_from_id($id="") { - if (!$id) { - return ""; - } +function username_from_id($id) { + $id = intval($id); + $dbh = DB::connect(); $q = "SELECT Username FROM Users WHERE ID = " . $dbh->quote($id); $result = $dbh->query($q); if (!$result) { - return "None"; + return null; } - $row = $result->fetch(PDO::FETCH_NUM); + $row = $result->fetch(PDO::FETCH_NUM); return $row[0]; } @@ -177,6 +176,17 @@ function username_from_sid($sid="") { return $row[0]; } +/** + * Format a user name for inclusion in HTML data + * + * @param string $username The user name to format + * + * @return void + */ +function html_format_username($username) { + return $username ? htmlspecialchars($username) : __("None"); +} + /** * Determine the user's e-mail address in the database using a session ID * @@ -363,20 +373,17 @@ function rm_tree($dirname) { * * @param string $username The username of an account * - * @return string Return user ID if exists for username, otherwise "None" + * @return string Return user ID if exists for username, otherwise null */ -function uid_from_username($username="") { - if (!$username) { - return ""; - } +function uid_from_username($username) { $dbh = DB::connect(); $q = "SELECT ID FROM Users WHERE Username = " . $dbh->quote($username); $result = $dbh->query($q); if (!$result) { - return "None"; + return null; } - $row = $result->fetch(PDO::FETCH_NUM); + $row = $result->fetch(PDO::FETCH_NUM); return $row[0]; } @@ -387,18 +394,15 @@ function uid_from_username($username="") { * * @return string The user's ID */ -function uid_from_email($email="") { - if (!$email) { - return ""; - } +function uid_from_email($email) { $dbh = DB::connect(); $q = "SELECT ID FROM Users WHERE Email = " . $dbh->quote($email); $result = $dbh->query($q); if (!$result) { - return "None"; + return null; } - $row = $result->fetch(PDO::FETCH_NUM); + $row = $result->fetch(PDO::FETCH_NUM); return $row[0]; } diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index c813e35a..6326d4e3 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -261,12 +261,12 @@ if ($row["SubmitterUID"]): if ($SID): if (!$USE_VIRTUAL_URLS): ?> - + - + - + @@ -279,12 +279,12 @@ if ($row["MaintainerUID"]): if ($SID): if (!$USE_VIRTUAL_URLS): ?> - + - + - + @@ -297,12 +297,12 @@ if ($row["PackagerUID"]): if ($SID): if (!$USE_VIRTUAL_URLS): ?> - + - + - + diff --git a/web/template/pkgbase_details.php b/web/template/pkgbase_details.php index da9a9629..6c617bf5 100644 --- a/web/template/pkgbase_details.php +++ b/web/template/pkgbase_details.php @@ -144,12 +144,12 @@ if ($row["SubmitterUID"]): if ($SID): if (!$USE_VIRTUAL_URLS): ?> - + - + - + @@ -162,12 +162,12 @@ if ($row["MaintainerUID"]): if ($SID): if (!$USE_VIRTUAL_URLS): ?> - + - + - + @@ -180,12 +180,12 @@ if ($row["PackagerUID"]): if ($SID): if (!$USE_VIRTUAL_URLS): ?> - + - + - + diff --git a/web/template/tu_details.php b/web/template/tu_details.php index fca18151..38f6c0d0 100644 --- a/web/template/tu_details.php +++ b/web/template/tu_details.php @@ -39,7 +39,7 @@ if ($yes > $active_tus / 2) {
- +
: diff --git a/web/template/tu_last_votes_list.php b/web/template/tu_last_votes_list.php index 090ce8d0..e897a6a1 100644 --- a/web/template/tu_last_votes_list.php +++ b/web/template/tu_last_votes_list.php @@ -22,9 +22,9 @@ - + - + -- cgit v1.2.3-24-g4f1b