pkgfuncs.inc.php: Fix comment style

* Use C-style comments (/* */) instead of # or //.
* Remove some superfluous comments and slightly reword others.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2014-02-06 18:58:59 +01:00
parent 34447e7233
commit 3f0a1a827a

View file

@ -19,7 +19,7 @@ function canDeleteComment($comment_id=0, $atype="", $uid=0) {
return false; return false;
} }
if ($atype == "Trusted User" || $atype == "Developer") { if ($atype == "Trusted User" || $atype == "Developer") {
# A TU/Dev can delete any comment /* TUs and developers can delete any comment. */
return true; return true;
} }
$dbh = DB::connect(); $dbh = DB::connect();
@ -54,10 +54,10 @@ function canDeleteCommentArray($comment, $atype="", $uid=0) {
/* Unauthenticated users cannot delete anything. */ /* Unauthenticated users cannot delete anything. */
return false; return false;
} elseif ($atype == "Trusted User" || $atype == "Developer") { } elseif ($atype == "Trusted User" || $atype == "Developer") {
# A TU/Dev can delete any comment /* TUs and developers can delete any comment. */
return true; return true;
} else if ($comment['UsersID'] == $uid) { } else if ($comment['UsersID'] == $uid) {
# User's own comment /* Users can delete their own comments. */
return true; return true;
} }
return false; return false;
@ -75,7 +75,7 @@ function canDeleteCommentArray($comment, $atype="", $uid=0) {
*/ */
function canSubmitBlacklisted($atype = "") { function canSubmitBlacklisted($atype = "") {
if ($atype == "Trusted User" || $atype == "Developer") { if ($atype == "Trusted User" || $atype == "Developer") {
# Only TUs/Devs can submit blacklisted packages. /* Only TUs and developers can submit blacklisted packages. */
return true; return true;
} }
else { else {
@ -218,7 +218,7 @@ function package_comments($pkgid) {
$q.= "FROM PackageComments LEFT JOIN Users "; $q.= "FROM PackageComments LEFT JOIN Users ";
$q.= "ON PackageComments.UsersID = Users.ID "; $q.= "ON PackageComments.UsersID = Users.ID ";
$q.= "WHERE PackageID = " . $pkgid . " "; $q.= "WHERE PackageID = " . $pkgid . " ";
$q.= "AND DelUsersID IS NULL "; # only display non-deleted comments $q.= "AND DelUsersID IS NULL ";
$q.= "ORDER BY CommentTS DESC"; $q.= "ORDER BY CommentTS DESC";
if (!isset($_GET['comments'])) { if (!isset($_GET['comments'])) {
@ -259,8 +259,10 @@ function add_package_comment($pkgid, $uid, $comment) {
$q.= $dbh->quote($comment) . ", UNIX_TIMESTAMP())"; $q.= $dbh->quote($comment) . ", UNIX_TIMESTAMP())";
$dbh->exec($q); $dbh->exec($q);
# TODO: Move notification logic to separate function where it belongs /*
# Send email notifications * Send e-mail notifications.
* TODO: Move notification logic to separate function where it belongs.
*/
$q = "SELECT CommentNotify.*, Users.Email "; $q = "SELECT CommentNotify.*, Users.Email ";
$q.= "FROM CommentNotify, Users "; $q.= "FROM CommentNotify, Users ";
$q.= "WHERE Users.ID = CommentNotify.UserID "; $q.= "WHERE Users.ID = CommentNotify.UserID ";
@ -280,9 +282,12 @@ function add_package_comment($pkgid, $uid, $comment) {
$result = $dbh->query($q); $result = $dbh->query($q);
$row = $result->fetch(PDO::FETCH_ASSOC); $row = $result->fetch(PDO::FETCH_ASSOC);
# TODO: native language emails for users, based on their prefs /*
# Simply making these strings translatable won't work, users would be * TODO: Add native language emails for users, based on their
# getting emails in the language that the user who posted the comment was in * preferences. Simply making these strings translatable won't
* work, users would be getting emails in the language that the
* user who posted the comment was in.
*/
$body = $body =
'from ' . $AUR_LOCATION . get_pkg_uri($row['Name']) . "\n" 'from ' . $AUR_LOCATION . get_pkg_uri($row['Name']) . "\n"
. username_from_sid($_COOKIE['AURSID']) . " wrote:\n\n" . username_from_sid($_COOKIE['AURSID']) . " wrote:\n\n"
@ -453,13 +458,11 @@ function display_package_details($id=0, $row, $SID="") {
else { else {
include('pkg_details.php'); include('pkg_details.php');
# Actions Bar
if ($SID) { if ($SID) {
include('actions_form.php'); include('actions_form.php');
include('pkg_comment_form.php'); include('pkg_comment_form.php');
} }
# Print Comments
$comments = package_comments($id); $comments = package_comments($id);
if (!empty($comments)) { if (!empty($comments)) {
include('pkg_comments.php'); include('pkg_comments.php');
@ -515,16 +518,15 @@ function display_package_details($id=0, $row, $SID="") {
function pkg_search_page($SID="") { function pkg_search_page($SID="") {
$dbh = DB::connect(); $dbh = DB::connect();
// get commonly used variables... /*
// TODO: REDUCE DB HITS. * Get commonly used variables.
// grab info for user if they're logged in * TODO: Reduce the number of database queries!
*/
if ($SID) if ($SID)
$myuid = uid_from_sid($SID); $myuid = uid_from_sid($SID);
// get a list of package categories $cats = pkgCategories($dbh);
$cats = pkgCategories($dbh); //meow
// sanitize paging variables /* Sanitize paging variables. */
//
if (isset($_GET['O'])) { if (isset($_GET['O'])) {
$_GET['O'] = intval($_GET['O']); $_GET['O'] = intval($_GET['O']);
if ($_GET['O'] < 0) if ($_GET['O'] < 0)
@ -545,12 +547,12 @@ function pkg_search_page($SID="") {
$_GET["PP"] = 50; $_GET["PP"] = 50;
} }
// FIXME: pull out DB-related code. all of it. /*
// this one's worth a choco-chip cookie, * FIXME: Pull out DB-related code. All of it! This one's worth a
// one of those nice big soft ones * choco-chip cookie, one of those nice big soft ones.
*/
// build the package search query /* Build the package search query. */
//
$q_select = "SELECT "; $q_select = "SELECT ";
if ($SID) { if ($SID) {
$q_select .= "CommentNotify.UserID AS Notify, $q_select .= "CommentNotify.UserID AS Notify,
@ -566,7 +568,7 @@ function pkg_search_page($SID="") {
LEFT JOIN PackageCategories LEFT JOIN PackageCategories
ON (Packages.CategoryID = PackageCategories.ID) "; ON (Packages.CategoryID = PackageCategories.ID) ";
if ($SID) { if ($SID) {
# this portion is not needed for the total row count query /* This is not needed for the total row count query. */
$q_from_extra = "LEFT JOIN PackageVotes $q_from_extra = "LEFT JOIN PackageVotes
ON (Packages.ID = PackageVotes.PackageID AND PackageVotes.UsersID = $myuid) ON (Packages.ID = PackageVotes.PackageID AND PackageVotes.UsersID = $myuid)
LEFT JOIN CommentNotify LEFT JOIN CommentNotify
@ -576,32 +578,34 @@ function pkg_search_page($SID="") {
} }
$q_where = "WHERE 1 = 1 "; $q_where = "WHERE 1 = 1 ";
// TODO: possibly do string matching on category /*
// to make request variable values more sensible * TODO: Possibly do string matching on category to make request
* variable values more sensible.
*/
if (isset($_GET["C"]) && intval($_GET["C"])) { if (isset($_GET["C"]) && intval($_GET["C"])) {
$q_where .= "AND Packages.CategoryID = ".intval($_GET["C"])." "; $q_where .= "AND Packages.CategoryID = ".intval($_GET["C"])." ";
} }
if (isset($_GET['K'])) { if (isset($_GET['K'])) {
# Search by maintainer
if (isset($_GET["SeB"]) && $_GET["SeB"] == "m") { if (isset($_GET["SeB"]) && $_GET["SeB"] == "m") {
/* Search by maintainer. */
$q_where .= "AND Users.Username = " . $dbh->quote($_GET['K']) . " "; $q_where .= "AND Users.Username = " . $dbh->quote($_GET['K']) . " ";
} }
# Search by submitter
elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "s") { elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "s") {
/* Search by submitter. */
$q_where .= "AND SubmitterUID = ".uid_from_username($_GET['K'])." "; $q_where .= "AND SubmitterUID = ".uid_from_username($_GET['K'])." ";
} }
# Search by name
elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "n") { elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "n") {
/* Search by name. */
$K = "%" . addcslashes($_GET['K'], '%_') . "%"; $K = "%" . addcslashes($_GET['K'], '%_') . "%";
$q_where .= "AND (Name LIKE " . $dbh->quote($K) . ") "; $q_where .= "AND (Name LIKE " . $dbh->quote($K) . ") ";
} }
# Search by name (exact match)
elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "x") { elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "x") {
/* Search by name (exact match). */
$q_where .= "AND (Name = " . $dbh->quote($_GET['K']) . ") "; $q_where .= "AND (Name = " . $dbh->quote($_GET['K']) . ") ";
} }
# Search by name and description (Default)
else { else {
/* Search by name and description (default). */
$K = "%" . addcslashes($_GET['K'], '%_') . "%"; $K = "%" . addcslashes($_GET['K'], '%_') . "%";
$q_where .= "AND (Name LIKE " . $dbh->quote($K) . " OR "; $q_where .= "AND (Name LIKE " . $dbh->quote($K) . " OR ";
$q_where .= "Description LIKE " . $dbh->quote($K) . ") "; $q_where .= "Description LIKE " . $dbh->quote($K) . ") ";
@ -676,10 +680,10 @@ function pkg_search_page($SID="") {
} }
} }
// figure out the results to use /* Calculate the results to use. */
$first = $_GET['O'] + 1; $first = $_GET['O'] + 1;
# calculation of pagination links /* Calculation of pagination links. */
$per_page = ($_GET['PP'] > 0) ? $_GET['PP'] : 50; $per_page = ($_GET['PP'] > 0) ? $_GET['PP'] : 50;
$current = ceil($first / $per_page); $current = ceil($first / $per_page);
$pages = ceil($total / $per_page); $pages = ceil($total / $per_page);
@ -779,7 +783,7 @@ function pkg_flag($atype, $ids) {
$affected_pkgs = $dbh->exec($q); $affected_pkgs = $dbh->exec($q);
if ($affected_pkgs > 0) { if ($affected_pkgs > 0) {
# Notify of flagging by email /* Notify of flagging by e-mail. */
$f_name = username_from_sid($_COOKIE['AURSID']); $f_name = username_from_sid($_COOKIE['AURSID']);
$f_email = email_from_sid($_COOKIE['AURSID']); $f_email = email_from_sid($_COOKIE['AURSID']);
$f_uid = uid_from_sid($_COOKIE['AURSID']); $f_uid = uid_from_sid($_COOKIE['AURSID']);
@ -791,7 +795,6 @@ function pkg_flag($atype, $ids) {
$result = $dbh->query($q); $result = $dbh->query($q);
if ($result) { if ($result) {
while ($row = $result->fetch(PDO::FETCH_ASSOC)) { while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
# construct email
$body = "Your package " . $row['Name'] . " has been flagged out of date by " . $f_name . " [1]. You may view your package at:\n" . $AUR_LOCATION . get_pkg_uri($row['Name']) . "\n\n[1] - " . $AUR_LOCATION . get_user_uri($f_name); $body = "Your package " . $row['Name'] . " has been flagged out of date by " . $f_name . " [1]. You may view your package at:\n" . $AUR_LOCATION . get_pkg_uri($row['Name']) . "\n\n[1] - " . $AUR_LOCATION . get_user_uri($f_name);
$body = wordwrap($body, 70); $body = wordwrap($body, 70);
$headers = "Reply-to: nobody@archlinux.org\nFrom:aur-notify@archlinux.org\nX-Mailer: PHP\nX-MimeOLE: Produced By AUR\n"; $headers = "Reply-to: nobody@archlinux.org\nFrom:aur-notify@archlinux.org\nX-Mailer: PHP\nX-MimeOLE: Produced By AUR\n";
@ -852,7 +855,6 @@ function pkg_delete ($atype, $ids, $mergepkgid) {
return array(false, __("You must be logged in before you can delete packages.")); return array(false, __("You must be logged in before you can delete packages."));
} }
# If they're a TU or dev, can delete
if ($atype != "Trusted User" && $atype != "Developer") { if ($atype != "Trusted User" && $atype != "Developer") {
return array(false, __("You do not have permission to delete packages.")); return array(false, __("You do not have permission to delete packages."));
} }
@ -868,7 +870,7 @@ function pkg_delete ($atype, $ids, $mergepkgid) {
$mergepkgname = pkgname_from_id($mergepkgid); $mergepkgname = pkgname_from_id($mergepkgid);
} }
# Send email notifications /* Send e-mail notifications. */
foreach ($ids as $pkgid) { foreach ($ids as $pkgid) {
$q = "SELECT CommentNotify.*, Users.Email "; $q = "SELECT CommentNotify.*, Users.Email ";
$q.= "FROM CommentNotify, Users "; $q.= "FROM CommentNotify, Users ";
@ -884,9 +886,13 @@ function pkg_delete ($atype, $ids, $mergepkgid) {
if (!empty($bcc)) { if (!empty($bcc)) {
$pkgname = pkgname_from_id($pkgid); $pkgname = pkgname_from_id($pkgid);
# TODO: native language emails for users, based on their prefs /*
# Simply making these strings translatable won't work, users would be * TODO: Add native language emails for users, based on
# getting emails in the language that the user who posted the comment was in * their preferences. Simply making these strings
* translatable won't work, users would be getting
* emails in the language that the user who posted the
* comment was in.
*/
$body = ""; $body = "";
if ($mergepkgid) { if ($mergepkgid) {
$body .= username_from_sid($_COOKIE['AURSID']) . " merged \"".$pkgname."\" into \"$mergepkgname\".\n\n"; $body .= username_from_sid($_COOKIE['AURSID']) . " merged \"".$pkgname."\" into \"$mergepkgname\".\n\n";
@ -977,7 +983,7 @@ function pkg_adopt ($atype, $ids, $action=true) {
$q.= "WHERE ID IN (" . implode(",", $ids) . ") "; $q.= "WHERE ID IN (" . implode(",", $ids) . ") ";
if ($action && $atype == "User") { if ($action && $atype == "User") {
# Regular users may only adopt orphan packages from unsupported /* Regular users may only adopt orphan packages. */
$q.= "AND $field IS NULL "; $q.= "AND $field IS NULL ";
} else if ($atype == "User") { } else if ($atype == "User") {
$q.= "AND $field = " . uid_from_sid($_COOKIE["AURSID"]); $q.= "AND $field = " . uid_from_sid($_COOKIE["AURSID"]);
@ -1048,8 +1054,7 @@ function pkg_vote ($atype, $ids, $action=true) {
} }
} }
# only vote for packages the user hasn't already voted for /* Only add votes for packages the user hasn't already voted for. */
#
$op = $action ? "+" : "-"; $op = $action ? "+" : "-";
$q = "UPDATE Packages SET NumVotes = NumVotes $op 1 "; $q = "UPDATE Packages SET NumVotes = NumVotes $op 1 ";
$q.= "WHERE ID IN ($vote_ids)"; $q.= "WHERE ID IN ($vote_ids)";
@ -1164,7 +1169,6 @@ function user_notify($uid, $pkgid) {
*/ */
function pkg_notify ($atype, $ids, $action=true) { function pkg_notify ($atype, $ids, $action=true) {
if (!$atype) { if (!$atype) {
# return __("You must be logged in before you can get notifications on comments.");
return; return;
} }
@ -1180,8 +1184,10 @@ function pkg_notify ($atype, $ids, $action=true) {
$first = true; $first = true;
# There currently shouldn't be multiple requests here, but the /*
# format in which it's sent requires this. * There currently shouldn't be multiple requests here, but the format
* in which it's sent requires this.
*/
foreach ($ids as $pid) { foreach ($ids as $pid) {
$q = "SELECT Name FROM Packages WHERE ID = $pid"; $q = "SELECT Name FROM Packages WHERE ID = $pid";
$result = $dbh->query($q); $result = $dbh->query($q);
@ -1203,7 +1209,7 @@ function pkg_notify ($atype, $ids, $action=true) {
$q = "SELECT COUNT(*) FROM CommentNotify WHERE "; $q = "SELECT COUNT(*) FROM CommentNotify WHERE ";
$q .= "UserID = $uid AND PkgID = $pid"; $q .= "UserID = $uid AND PkgID = $pid";
# Notification already added. Don't add again. /* Notification already added. Don't add again. */
$result = $dbh->query($q); $result = $dbh->query($q);
if ($result->fetchColumn() == 0) { if ($result->fetchColumn() == 0) {
$q = "INSERT INTO CommentNotify (PkgID, UserID) VALUES ($pid, $uid)"; $q = "INSERT INTO CommentNotify (PkgID, UserID) VALUES ($pid, $uid)";
@ -1243,7 +1249,6 @@ function pkg_delete_comment($atype) {
return array(false, __("You must be logged in before you can edit package information.")); return array(false, __("You must be logged in before you can edit package information."));
} }
# Get ID of comment to be removed
if (isset($_POST["comment_id"])) { if (isset($_POST["comment_id"])) {
$comment_id = $_POST["comment_id"]; $comment_id = $_POST["comment_id"];
} else { } else {
@ -1275,7 +1280,6 @@ function pkg_change_category($pid, $atype) {
return array(false, __("You must be logged in before you can edit package information.")); return array(false, __("You must be logged in before you can edit package information."));
} }
# Get ID of the new category
if (isset($_POST["category_id"])) { if (isset($_POST["category_id"])) {
$category_id = $_POST["category_id"]; $category_id = $_POST["category_id"];
} else { } else {
@ -1288,7 +1292,7 @@ function pkg_change_category($pid, $atype) {
return array(false, __("Invalid category ID.")); return array(false, __("Invalid category ID."));
} }
# Verify package ownership /* Verify package ownership. */
$q = "SELECT Packages.MaintainerUID "; $q = "SELECT Packages.MaintainerUID ";
$q.= "FROM Packages "; $q.= "FROM Packages ";
$q.= "WHERE Packages.ID = ".$pid; $q.= "WHERE Packages.ID = ".$pid;
@ -1373,7 +1377,7 @@ function new_pkgdetails($pkgname, $license, $pkgver, $category_id, $pkgdesc, $pk
*/ */
function update_pkgdetails($pkgname, $license, $pkgver, $pkgdesc, $pkgurl, $uid, $pkgid) { function update_pkgdetails($pkgname, $license, $pkgver, $pkgdesc, $pkgurl, $uid, $pkgid) {
$dbh = DB::connect(); $dbh = DB::connect();
# This is an overwrite of an existing package /* 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", $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), $dbh->quote($pkgname),
$dbh->quote($pkgver), $dbh->quote($pkgver),