summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorcanyonknight <canyonknight@gmail.com>2012-05-23 21:28:20 +0200
committerLukas Fleischer <archlinux@cryptocrack.de>2012-07-06 11:26:57 +0200
commitd3de6679010a1d140794305e747f1af0e7f21834 (patch)
tree9d0352f32efe141cff5c9597bd9065de3d9afa2c /web
parent84d21e6f30a2f0219f27942998d295d716751bf6 (diff)
downloadaur-d3de6679010a1d140794305e747f1af0e7f21834.tar.gz
aur-d3de6679010a1d140794305e747f1af0e7f21834.tar.xz
pkg_comment_form.php: Pull out DB code
* Move DB code and e-mail code from pkg_comment_form.php to new function in pkgfuncs.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>
Diffstat (limited to 'web')
-rw-r--r--web/lib/pkgfuncs.inc.php54
-rw-r--r--web/template/pkg_comment_form.php51
2 files changed, 54 insertions, 51 deletions
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
index 979d74b5..40fccbcf 100644
--- a/web/lib/pkgfuncs.inc.php
+++ b/web/lib/pkgfuncs.inc.php
@@ -200,6 +200,56 @@ function package_comments($pkgid, $dbh=NULL) {
return $comments;
}
+# Add a comment to a package page and send out appropriate notifications
+# TODO: Move notification logic to separate function where it belongs
+function add_package_comment($pkgid, $uid, $comment, $dbh=NULL) {
+ if(!$dbh) {
+ $dbh = db_connect();
+ }
+
+ $q = 'INSERT INTO PackageComments ';
+ $q.= '(PackageID, UsersID, Comments, CommentTS) VALUES (';
+ $q.= intval($pkgid) . ', ' . $uid . ', ';
+ $q.= "'" . db_escape_string($comment) . "', ";
+ $q.= 'UNIX_TIMESTAMP())';
+ db_query($q, $dbh);
+
+ # Send email notifications
+ $q = 'SELECT CommentNotify.*, Users.Email ';
+ $q.= 'FROM CommentNotify, Users ';
+ $q.= 'WHERE Users.ID = CommentNotify.UserID ';
+ $q.= 'AND CommentNotify.UserID != ' . $uid . ' ';
+ $q.= 'AND CommentNotify.PkgID = ' . intval($pkgid);
+ $result = db_query($q, $dbh);
+ $bcc = array();
+
+ if (mysql_num_rows($result)) {
+ while ($row = mysql_fetch_assoc($result)) {
+ array_push($bcc, $row['Email']);
+ }
+
+ $q = 'SELECT Packages.* ';
+ $q.= 'FROM Packages ';
+ $q.= 'WHERE Packages.ID = ' . intval($pkgid);
+ $result = db_query($q, $dbh);
+ $row = mysql_fetch_assoc($result);
+
+ # TODO: native language emails for users, based on their prefs
+ # 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 =
+ 'from ' . $AUR_LOCATION . '/packages.php?ID='
+ . $pkgid . "\n"
+ . username_from_sid($_COOKIE['AURSID'], $dbh) . " wrote:\n\n"
+ . $comment
+ . "\n\n---\nIf you no longer wish to receive notifications about this package, please go the the above package page and click the UnNotify button.";
+ $body = wordwrap($body, 70);
+ $bcc = implode(', ', $bcc);
+ $headers = "Bcc: $bcc\nReply-to: nobody@archlinux.org\nFrom: aur-notify@archlinux.org\nX-Mailer: AUR\n";
+ @mail('undisclosed-recipients: ;', "AUR Comment for " . $row['Name'], $body, $headers);
+ }
+}
+
# grab package sources
#
function package_sources($pkgid, $dbh=NULL) {
@@ -345,6 +395,10 @@ function package_details($id=0, $SID="", $dbh=NULL) {
# Actions Bar
if ($SID) {
include('actions_form.php');
+ if (isset($_REQUEST['comment'])) {
+ $uid = uid_from_sid($SID, $dbh);
+ add_package_comment($id, $uid, $_REQUEST['comment'], $dbh);
+ }
include('pkg_comment_form.php');
}
diff --git a/web/template/pkg_comment_form.php b/web/template/pkg_comment_form.php
index 0fcfa7c0..8430a89c 100644
--- a/web/template/pkg_comment_form.php
+++ b/web/template/pkg_comment_form.php
@@ -1,54 +1,3 @@
-<?php
-# Add a comment to this package
-if (isset($_REQUEST['comment'])) {
-
- # Insert the comment
- $dbh = db_connect();
- $q = 'INSERT INTO PackageComments ';
- $q.= '(PackageID, UsersID, Comments, CommentTS) VALUES (';
- $q.= intval($_REQUEST['ID']) . ', ' . uid_from_sid($_COOKIE['AURSID']) . ', ';
- $q.= "'" . db_escape_string($_REQUEST['comment']) . "', ";
- $q.= 'UNIX_TIMESTAMP())';
- db_query($q, $dbh);
-
- # Send email notifications
- $q = 'SELECT CommentNotify.*, Users.Email ';
- $q.= 'FROM CommentNotify, Users ';
- $q.= 'WHERE Users.ID = CommentNotify.UserID ';
- $q.= 'AND CommentNotify.UserID != ' . uid_from_sid($_COOKIE['AURSID']) . ' ';
- $q.= 'AND CommentNotify.PkgID = ' . intval($_REQUEST['ID']);
- $result = db_query($q, $dbh);
- $bcc = array();
-
- if (mysql_num_rows($result)) {
- while ($row = mysql_fetch_assoc($result)) {
- array_push($bcc, $row['Email']);
- }
-
- $q = 'SELECT Packages.* ';
- $q.= 'FROM Packages ';
- $q.= 'WHERE Packages.ID = ' . intval($_REQUEST['ID']);
- $result = db_query($q, $dbh);
- $row = mysql_fetch_assoc($result);
-
- # TODO: native language emails for users, based on their prefs
- # 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 =
- 'from ' . $AUR_LOCATION . '/packages.php?ID='
- . $_REQUEST['ID'] . "\n"
- . username_from_sid($_COOKIE['AURSID'], $dbh) . " wrote:\n\n"
- . $_POST['comment']
- . "\n\n---\nIf you no longer wish to receive notifications about this package, please go the the above package page and click the UnNotify button.";
- $body = wordwrap($body, 70);
- $bcc = implode(', ', $bcc);
- $headers = "Bcc: $bcc\nReply-to: nobody@archlinux.org\nFrom: aur-notify@archlinux.org\nX-Mailer: AUR\n";
- @mail('undisclosed-recipients: ;', "AUR Comment for " . $row['Name'], $body, $headers);
- }
-}
-
- # Prompt visitor for comment
-?>
<div id="generic-form" class="box">
<h2><?php echo __("Add Comment"); ?></h2>
<form call="general-form" action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="post">