cvs: pearweb /public_html/bugs bug.php /public_html/bugs/include functions.inc /sql bugs.sql
| From: | Pierre-Alain Joye | Date: | Tue, 21 Feb 2006 15:58:55 +0000 |
| Subject: | cvs: pearweb /public_html/bugs bug.php /public_html/bugs/include functions.inc /sql bugs.sql | ||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-cvs+get-38454@lists.php.net to get a copy of this message | ||
pajoye Tue Feb 21 15:58:55 2006 UTC
Modified files:
/pearweb/public_html/bugs bug.php
/pearweb/public_html/bugs/include functions.inc
/pearweb/sql bugs.sql
Log:
- #4655, allow users to subscribe to a bug
only for pear developers for now, testing
http://cvs.php.net/viewcvs.cgi/pearweb/public_html/bugs/bug.php?r1=1.97&r2=1.98&diff_format=u Index: pearweb/public_html/bugs/bug.php diff -u pearweb/public_html/bugs/bug.php:1.97 pearweb/public_html/bugs/bug.php:1.98 --- pearweb/public_html/bugs/bug.php:1.97 Mon Feb 20 21:40:14 2006 +++ pearweb/public_html/bugs/bug.php Tue Feb 21 15:58:55 2006 @@ -15,7 +15,7 @@ * @package Bugs * @copyright Copyright (c) 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License - * @version $Id: bug.php,v 1.97 2006/02/20 21:40:14 pajoye Exp $ + * @version $Id: bug.php,v 1.98 2006/02/21 15:58:55 pajoye Exp $ */ /* @@ -41,6 +41,7 @@ session_start(); error_reporting(E_ALL ^ E_NOTICE); + if (empty($_REQUEST['id']) || !(int)$_REQUEST['id']) { localRedirect('search.php'); exit; @@ -48,6 +49,20 @@ $id = (int)$_REQUEST['id']; } + +if (isset($_GET['unsubscribe'])) { + $unsubcribe = (int)$_GET['unsubscribe']; + $hash = isset($_GET['t']) ? $_GET['t'] : false; + $site == 'pear' ? $redirect = 'pecl' : $redirect = 'pear'; +print_r($hash); + if (!$hash) { + + localRedirect('http://' . $redirect . '.local/bugs/bug.php?id='.$id); + } + + unsubscribe($id, $hash); +} + if (empty($_REQUEST['edit']) || !(int)$_REQUEST['edit']) { $edit = 0; } else { @@ -85,6 +100,24 @@ $pw = ''; } +// Subscribtion +if (isset($_POST['subscribe_to_bug'])) { + $email = $_POST['subscribe_email']; + if (!preg_match("/[.\\w+-]+@[.\\w-]+\\.\\w{2,}/i", $email)) { + $errors[] = "You must provide a valid email address."; + } else { + $query = 'REPLACE INTO bugdb_subscribe SET bug_id=' . $id . + ", email='" . escapeSQL($email) . "'"; + $dbh->query($query); + + $site == 'pear' ? $redirect = 'pecl' : $redirect = 'pear'; + + localRedirect('http://' . $redirect . '.local/bugs/bug.php?id='.$id); + exit(); + } +} + + $trytoforce = isset($_POST['trytoforce']) ? (int)$_POST['trytoforce'] : false; // fetch info about the bug into $bug @@ -106,6 +139,23 @@ $bug =& $dbh->getRow($query, array(), DB_FETCHMODE_ASSOC); +// Unsubscribe +if (isset($_POST['unsubscribe_to_bug'])) { + $email = $_POST['subscribe_email']; + + if (!preg_match("/[.\\w+-]+@[.\\w-]+\\.\\w{2,}/i", $email)) { + $errors[] = "You must provide a valid email address."; + } else { + /* Generate the hash */ + unsubscribe_hash($id, $email, $bug); + + $site == 'pear' ? $redirect = 'pecl' : $redirect = 'pear'; + + localRedirect('http://' . $redirect . '.local/bugs/bug.php?id='.$id); + exit(); + } +} + if (!$bug) { response_header('No Such Bug'); display_bug_error('No such bug #' . $id); @@ -115,7 +165,7 @@ // Redirect to PECL if it's a PECL bug if (!empty($bug['package_type']) && $bug['package_type'] != $site) { - $site == 'pear' ? $redirect = 'pecl' : $redirect = 'pear'; + $site == 'pear' ? $redirect = 'pecl' : $redirect = 'pear'; localRedirect('http://'.$redirect.'.php.net/bugs/bug.php?id='.$id); exit(); } @@ -129,7 +179,7 @@ $addon = '&thanks=1'; } - localRedirect('/bugs/bug.php' . "?id=$id&edit=1$addon"); + localRedirect('http://pear.local/bugs/bug.php' . "?id=$id&edit=1$addon"); exit(); } @@ -143,10 +193,9 @@ $errors[] = 'Incorrect CAPTCHA'; } - $comment_name = isset($_POST['in']['comment_name']) ? htmlspecialchars(strip_tags($_POST['in']['comment_name'])) : ''; + $comment_name = isset($_POST['in']['comment_name']) ? htmlspecialchars(strip_tags($_POST['in']['comment_name'])) : ''; - if (!preg_match("/[.\\w+-]+@[.\\w-]+\\.\\w{2,}/i", - $_POST['in']['commentemail'])) { + if (!preg_match("/[.\\w+-]+@[.\\w-]+\\.\\w{2,}/i", $_POST['in']['commentemail'])) { $errors[] = "You must provide a valid email address."; } @@ -354,7 +403,7 @@ if ($_POST['in'] && !isset($_POST['preview'])) { if (!$errors) { - mail_bug_updates($bug, $_POST['in'], $from, $ncomment, $edit); + mail_bug_updates($bug, $_POST['in'], $from, $ncomment, $edit, $id); localRedirect(htmlspecialchars($_SERVER['PHP_SELF']) . "?id=$id&thanks=$edit"); exit; } @@ -475,8 +524,6 @@ ?> </div> - - <?php if (isset($_POST['preview']) && !empty($ncomment)) { @@ -745,12 +792,26 @@ <p style="margin-top: 0em"> <input type="submit" name="preview" value="Preview"> <input type="submit" value="Submit" /> </p> - </form> <?php } +if ($user_auth && $user_auth->registered) { +?> +<div class="explain"> + + <form name="subscribetobug" action="/bugs/bug.php?id=<?php echo $id; ?>" method="post"> + <table> + <th class="details" colspan="2">Subscribe to this entry?</th> + <th class="details">Your email</th><td><input type="text" name="subscribe_email" value="" /></td> + <th class="details" colspan="2"><input type="submit" name="subscribe_to_bug" value="Subscribe" /></th> + <th class="details" colspan="2"><input type="submit" name="unsubscribe_to_bug" value="Unsubscribe" /></th> + </table> + </form> +</div> +<?php +} if ($edit == 3) { ?> @@ -784,6 +845,7 @@ echo $preview; ?> + <table> <tr> <th class="details">Your <span class="accesskey">n</span>ame:</th> http://cvs.php.net/viewcvs.cgi/pearweb/public_html/bugs/include/functions.inc?r1=1.97&r2=1.98&diff_format=u Index: pearweb/public_html/bugs/include/functions.inc diff -u pearweb/public_html/bugs/include/functions.inc:1.97 pearweb/public_html/bugs/include/functions.inc:1.98 --- pearweb/public_html/bugs/include/functions.inc:1.97 Mon Jan 30 16:35:17 2006 +++ pearweb/public_html/bugs/include/functions.inc Tue Feb 21 15:58:55 2006 @@ -15,7 +15,7 @@ * @package Bugs * @copyright Copyright (c) 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License - * @version $Id: functions.inc,v 1.97 2006/01/30 16:35:17 cellog Exp $ + * @version $Id: functions.inc,v 1.98 2006/02/21 15:58:55 pajoye Exp $ */ @@ -459,7 +459,7 @@ if (!$use && $current) { echo '<option selected="selected">' . $current . "</option>\n"; } else { - echo '<option>CVS</option>' . "\n"; + echo '<option>CVS</option>' . "\n"; } echo '<option value="earlier">Earlier? Upgrade first!</option>' . "\n"; echo "</select>\n"; @@ -667,7 +667,7 @@ * * @return void */ -function mail_bug_updates($bug, $in, $from, $ncomment, $edit = 1) +function mail_bug_updates($bug, $in, $from, $ncomment, $edit = 1, $id) { global $tla, $types, $site, $siteBig; @@ -675,7 +675,7 @@ $headers = array(); /* Default addresses */ - list($mailto,$mailfrom) = get_package_mail(oneof($in['package_name'],$bug['package_name'])); + list($mailto,$mailfrom) = get_package_mail(oneof($in['package_name'],$bug['package_name']), $id); /* Get rid of slashes in bug status */ $bug['status'] = rinse($bug['status']); @@ -683,18 +683,18 @@ $headers[] = array(" ID", $bug['id']); switch ($edit) { - case 3: - $from = spam_protect(rinse($in['commentemail']), 'text'); - $headers[] = array(" Comment by", $from); - $from = "\"$from\" <$mailfrom>"; - break; - case 2: - $from = spam_protect(txfield('email'), 'text'); - $headers[] = array(" User updated by", $from); - $from = "\"$from\" <$mailfrom>"; - break; - default: - $headers[] = array(" Updated by", $from); + case 3: + $from = spam_protect(rinse($in['commentemail']), 'text'); + $headers[] = array(" Comment by", $from); + $from = "\"$from\" <$mailfrom>"; + break; + case 2: + $from = spam_protect(txfield('email'), 'text'); + $headers[] = array(" User updated by", $from); + $from = "\"$from\" <$mailfrom>"; + break; + default: + $headers[] = array(" Updated by", $from); } if (changed('sdesc')) { @@ -806,6 +806,7 @@ "In-Reply-To: <bug-$bug[id]@$site.php.net>", "-fbounces-ignored@php.net"); # but we go ahead and let the default sender get used for the list + @mail($mailto, "[$siteBig-BUG] " . rinse($subj) . txfield('sdesc'), $dev_text, @@ -1005,9 +1006,9 @@ * * @return array an array of eamil addresses */ -function get_package_mail($package_name) +function get_package_mail($package_name, $bug_id) { - global $site, $bugEmail; + global $site, $bugEmail, $dbh; // XXX Change to pear-bugs when it gets opened //$to[] = "pear-dev@lists.php.net"; @@ -1026,6 +1027,9 @@ foreach ($maintainers as $data) { $to[] = $data['email']; } + $mails = $dbh->getCol('SELECT email FROM bugdb_subscribe WHERE bug_id=' . $bug_id); + $to = array_merge($to, $mails); + $to = array_unique($to); return array(implode(', ', $to), $bugEmail); } @@ -1143,4 +1147,90 @@ echo "\n\n<!-- END BUG NAV -->\n\n"; } -?> +/** + * Send the confirmation mail to confirm a subscription removal + * + * @param integer bug ID + * @param string email to remove + * @param array bug data + * + * @return void + */ + function unsubscribe_hash($bug_id, $email, $bug) + { + global $dbh, $siteBig, $site; + + $now = time(); + $hash = crypt($email . $id, $now); + + $query = 'UPDATE bugdb_subscribe + SET unsubscribe_date=' . $now . ', + unsubscribe_hash=' . "'" . escapeSQL($hash) . "'" . + ' WHERE bug_id=' . $bug_id . ' AND email=' ."'" . escapeSQL($email) . "'"; + + $res = $dbh->query($query); + + $affected = $dbh->affectedRows($res); + + if ($affected > 0) { + $hash = urlencode($hash); + /* user text with attention, headers and previous messages */ + $user_text = "ATTENTION! Do NOT reply to this email!\n\n" . + "A request has been made to remove your subscription to\n" . + "$siteBig bug #$bug_id ($bug[sdesc])\n\n" . + "To confirm the removal please use this link:\n" . + "http://$site.php.net/bugs/bug.php?id=$bug[id]&unsubscribe=1&t=$hash\n\n\n"; + + @mail($email, + "[$siteBig-BUG-unsubscribe] " . rinse($bug['sdesc']), + $user_text, + "From: $siteBig Bug Database <$mailfrom>\n". + "X-PHP-Bug: $bug[id]\n". + "In-Reply-To: <bug-$bug[id]@$site.php.net>", + "-fbounces-ignored@php.net"); + } +} + + +/** + * Remove a subscribtion + * + * @param integer bug ID + * @param string hash + * + * @return void + */ + function unsubscribe($bug_id, $hash) + { + global $dbh; + + $hash = escapeSQL($hash); + $query = 'SELECT + bug_id, email, unsubscribe_date, unsubscribe_hash + FROM + bugdb_subscribe + WHERE + bug_id=' . $bug_id . ' + AND + unsubscribe_hash=' . "'" . $hash . "' + LIMIT 1"; + + $sub = $dbh->getRow($query, DB_FETCHMODE_ASSOC); + + if (!$sub) { + return false; + } + + $now = time(); + $requested_on = $sub['unsubscribe_date']; + /* 24hours delay to answer the mail */ + if (($now - $requested_on) > (24*60*60)) { + return false; + } + + $query = 'DELETE FROM bugdb_subscribe WHERE bug_id=' . $bug_id . ' + AND unsubscribe_hash=' . "'" . $hash . "' + AND email='" . $sub['email'] . "'"; + $dbh->query($query); + return true; + } http://cvs.php.net/viewcvs.cgi/pearweb/sql/bugs.sql?r1=1.5&r2=1.6&diff_format=u Index: pearweb/sql/bugs.sql diff -u pearweb/sql/bugs.sql:1.5 pearweb/sql/bugs.sql:1.6 --- pearweb/sql/bugs.sql:1.5 Mon Feb 20 02:41:55 2006 +++ pearweb/sql/bugs.sql Tue Feb 21 15:58:55 2006 @@ -49,3 +49,13 @@ sameos int(1) default NULL, samever int(1) default NULL ) TYPE=MyISAM; + +CREATE TABLE `bugdb_subscribe` ( + bug_id int(8) NOT NULL default '0', + email varchar(40) NOT NULL default '', + unsubcribe_date int(11) default '', + unsubcribe_hash varchar(80) default '', + PRIMARY KEY (bug_id, email), + KEY (unsubscribe_hash) +) TYPE=MyISAM; +
http://cvs.php.net/viewcvs.cgi/pearweb/public_html/bugs/bug.php?r1=1.97&r2=1.98&diff_format=u Index: pearweb/public_html/bugs/bug.php diff -u pearweb/public_html/bugs/bug.php:1.97 pearweb/public_html/bugs/bug.php:1.98 --- pearweb/public_html/bugs/bug.php:1.97 Mon Feb 20 21:40:14 2006 +++ pearweb/public_html/bugs/bug.php Tue Feb 21 15:58:55 2006 @@ -15,7 +15,7 @@ * @package Bugs * @copyright Copyright (c) 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License - * @version $Id: bug.php,v 1.97 2006/02/20 21:40:14 pajoye Exp $ + * @version $Id: bug.php,v 1.98 2006/02/21 15:58:55 pajoye Exp $ */ /* @@ -41,6 +41,7 @@ session_start(); error_reporting(E_ALL ^ E_NOTICE); + if (empty($_REQUEST['id']) || !(int)$_REQUEST['id']) { localRedirect('search.php'); exit; @@ -48,6 +49,20 @@ $id = (int)$_REQUEST['id']; } + +if (isset($_GET['unsubscribe'])) { + $unsubcribe = (int)$_GET['unsubscribe']; + $hash = isset($_GET['t']) ? $_GET['t'] : false; + $site == 'pear' ? $redirect = 'pecl' : $redirect = 'pear'; +print_r($hash); + if (!$hash) { + + localRedirect('http://' . $redirect . '.local/bugs/bug.php?id='.$id); + } + + unsubscribe($id, $hash); +} + if (empty($_REQUEST['edit']) || !(int)$_REQUEST['edit']) { $edit = 0; } else { @@ -85,6 +100,24 @@ $pw = ''; } +// Subscribtion +if (isset($_POST['subscribe_to_bug'])) { + $email = $_POST['subscribe_email']; + if (!preg_match("/[.\\w+-]+@[.\\w-]+\\.\\w{2,}/i", $email)) { + $errors[] = "You must provide a valid email address."; + } else { + $query = 'REPLACE INTO bugdb_subscribe SET bug_id=' . $id . + ", email='" . escapeSQL($email) . "'"; + $dbh->query($query); + + $site == 'pear' ? $redirect = 'pecl' : $redirect = 'pear'; + + localRedirect('http://' . $redirect . '.local/bugs/bug.php?id='.$id); + exit(); + } +} + + $trytoforce = isset($_POST['trytoforce']) ? (int)$_POST['trytoforce'] : false; // fetch info about the bug into $bug @@ -106,6 +139,23 @@ $bug =& $dbh->getRow($query, array(), DB_FETCHMODE_ASSOC); +// Unsubscribe +if (isset($_POST['unsubscribe_to_bug'])) { + $email = $_POST['subscribe_email']; + + if (!preg_match("/[.\\w+-]+@[.\\w-]+\\.\\w{2,}/i", $email)) { + $errors[] = "You must provide a valid email address."; + } else { + /* Generate the hash */ + unsubscribe_hash($id, $email, $bug); + + $site == 'pear' ? $redirect = 'pecl' : $redirect = 'pear'; + + localRedirect('http://' . $redirect . '.local/bugs/bug.php?id='.$id); + exit(); + } +} + if (!$bug) { response_header('No Such Bug'); display_bug_error('No such bug #' . $id); @@ -115,7 +165,7 @@ // Redirect to PECL if it's a PECL bug if (!empty($bug['package_type']) && $bug['package_type'] != $site) { - $site == 'pear' ? $redirect = 'pecl' : $redirect = 'pear'; + $site == 'pear' ? $redirect = 'pecl' : $redirect = 'pear'; localRedirect('http://'.$redirect.'.php.net/bugs/bug.php?id='.$id); exit(); } @@ -129,7 +179,7 @@ $addon = '&thanks=1'; } - localRedirect('/bugs/bug.php' . "?id=$id&edit=1$addon"); + localRedirect('http://pear.local/bugs/bug.php' . "?id=$id&edit=1$addon"); exit(); } @@ -143,10 +193,9 @@ $errors[] = 'Incorrect CAPTCHA'; } - $comment_name = isset($_POST['in']['comment_name']) ? htmlspecialchars(strip_tags($_POST['in']['comment_name'])) : ''; + $comment_name = isset($_POST['in']['comment_name']) ? htmlspecialchars(strip_tags($_POST['in']['comment_name'])) : ''; - if (!preg_match("/[.\\w+-]+@[.\\w-]+\\.\\w{2,}/i", - $_POST['in']['commentemail'])) { + if (!preg_match("/[.\\w+-]+@[.\\w-]+\\.\\w{2,}/i", $_POST['in']['commentemail'])) { $errors[] = "You must provide a valid email address."; } @@ -354,7 +403,7 @@ if ($_POST['in'] && !isset($_POST['preview'])) { if (!$errors) { - mail_bug_updates($bug, $_POST['in'], $from, $ncomment, $edit); + mail_bug_updates($bug, $_POST['in'], $from, $ncomment, $edit, $id); localRedirect(htmlspecialchars($_SERVER['PHP_SELF']) . "?id=$id&thanks=$edit"); exit; } @@ -475,8 +524,6 @@ ?> </div> - - <?php if (isset($_POST['preview']) && !empty($ncomment)) { @@ -745,12 +792,26 @@ <p style="margin-top: 0em"> <input type="submit" name="preview" value="Preview"> <input type="submit" value="Submit" /> </p> - </form> <?php } +if ($user_auth && $user_auth->registered) { +?> +<div class="explain"> + + <form name="subscribetobug" action="/bugs/bug.php?id=<?php echo $id; ?>" method="post"> + <table> + <th class="details" colspan="2">Subscribe to this entry?</th> + <th class="details">Your email</th><td><input type="text" name="subscribe_email" value="" /></td> + <th class="details" colspan="2"><input type="submit" name="subscribe_to_bug" value="Subscribe" /></th> + <th class="details" colspan="2"><input type="submit" name="unsubscribe_to_bug" value="Unsubscribe" /></th> + </table> + </form> +</div> +<?php +} if ($edit == 3) { ?> @@ -784,6 +845,7 @@ echo $preview; ?> + <table> <tr> <th class="details">Your <span class="accesskey">n</span>ame:</th> http://cvs.php.net/viewcvs.cgi/pearweb/public_html/bugs/include/functions.inc?r1=1.97&r2=1.98&diff_format=u Index: pearweb/public_html/bugs/include/functions.inc diff -u pearweb/public_html/bugs/include/functions.inc:1.97 pearweb/public_html/bugs/include/functions.inc:1.98 --- pearweb/public_html/bugs/include/functions.inc:1.97 Mon Jan 30 16:35:17 2006 +++ pearweb/public_html/bugs/include/functions.inc Tue Feb 21 15:58:55 2006 @@ -15,7 +15,7 @@ * @package Bugs * @copyright Copyright (c) 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License - * @version $Id: functions.inc,v 1.97 2006/01/30 16:35:17 cellog Exp $ + * @version $Id: functions.inc,v 1.98 2006/02/21 15:58:55 pajoye Exp $ */ @@ -459,7 +459,7 @@ if (!$use && $current) { echo '<option selected="selected">' . $current . "</option>\n"; } else { - echo '<option>CVS</option>' . "\n"; + echo '<option>CVS</option>' . "\n"; } echo '<option value="earlier">Earlier? Upgrade first!</option>' . "\n"; echo "</select>\n"; @@ -667,7 +667,7 @@ * * @return void */ -function mail_bug_updates($bug, $in, $from, $ncomment, $edit = 1) +function mail_bug_updates($bug, $in, $from, $ncomment, $edit = 1, $id) { global $tla, $types, $site, $siteBig; @@ -675,7 +675,7 @@ $headers = array(); /* Default addresses */ - list($mailto,$mailfrom) = get_package_mail(oneof($in['package_name'],$bug['package_name'])); + list($mailto,$mailfrom) = get_package_mail(oneof($in['package_name'],$bug['package_name']), $id); /* Get rid of slashes in bug status */ $bug['status'] = rinse($bug['status']); @@ -683,18 +683,18 @@ $headers[] = array(" ID", $bug['id']); switch ($edit) { - case 3: - $from = spam_protect(rinse($in['commentemail']), 'text'); - $headers[] = array(" Comment by", $from); - $from = "\"$from\" <$mailfrom>"; - break; - case 2: - $from = spam_protect(txfield('email'), 'text'); - $headers[] = array(" User updated by", $from); - $from = "\"$from\" <$mailfrom>"; - break; - default: - $headers[] = array(" Updated by", $from); + case 3: + $from = spam_protect(rinse($in['commentemail']), 'text'); + $headers[] = array(" Comment by", $from); + $from = "\"$from\" <$mailfrom>"; + break; + case 2: + $from = spam_protect(txfield('email'), 'text'); + $headers[] = array(" User updated by", $from); + $from = "\"$from\" <$mailfrom>"; + break; + default: + $headers[] = array(" Updated by", $from); } if (changed('sdesc')) { @@ -806,6 +806,7 @@ "In-Reply-To: <bug-$bug[id]@$site.php.net>", "-fbounces-ignored@php.net"); # but we go ahead and let the default sender get used for the list + @mail($mailto, "[$siteBig-BUG] " . rinse($subj) . txfield('sdesc'), $dev_text, @@ -1005,9 +1006,9 @@ * * @return array an array of eamil addresses */ -function get_package_mail($package_name) +function get_package_mail($package_name, $bug_id) { - global $site, $bugEmail; + global $site, $bugEmail, $dbh; // XXX Change to pear-bugs when it gets opened //$to[] = "pear-dev@lists.php.net"; @@ -1026,6 +1027,9 @@ foreach ($maintainers as $data) { $to[] = $data['email']; } + $mails = $dbh->getCol('SELECT email FROM bugdb_subscribe WHERE bug_id=' . $bug_id); + $to = array_merge($to, $mails); + $to = array_unique($to); return array(implode(', ', $to), $bugEmail); } @@ -1143,4 +1147,90 @@ echo "\n\n<!-- END BUG NAV -->\n\n"; } -?> +/** + * Send the confirmation mail to confirm a subscription removal + * + * @param integer bug ID + * @param string email to remove + * @param array bug data + * + * @return void + */ + function unsubscribe_hash($bug_id, $email, $bug) + { + global $dbh, $siteBig, $site; + + $now = time(); + $hash = crypt($email . $id, $now); + + $query = 'UPDATE bugdb_subscribe + SET unsubscribe_date=' . $now . ', + unsubscribe_hash=' . "'" . escapeSQL($hash) . "'" . + ' WHERE bug_id=' . $bug_id . ' AND email=' ."'" . escapeSQL($email) . "'"; + + $res = $dbh->query($query); + + $affected = $dbh->affectedRows($res); + + if ($affected > 0) { + $hash = urlencode($hash); + /* user text with attention, headers and previous messages */ + $user_text = "ATTENTION! Do NOT reply to this email!\n\n" . + "A request has been made to remove your subscription to\n" . + "$siteBig bug #$bug_id ($bug[sdesc])\n\n" . + "To confirm the removal please use this link:\n" . + "http://$site.php.net/bugs/bug.php?id=$bug[id]&unsubscribe=1&t=$hash\n\n\n"; + + @mail($email, + "[$siteBig-BUG-unsubscribe] " . rinse($bug['sdesc']), + $user_text, + "From: $siteBig Bug Database <$mailfrom>\n". + "X-PHP-Bug: $bug[id]\n". + "In-Reply-To: <bug-$bug[id]@$site.php.net>", + "-fbounces-ignored@php.net"); + } +} + + +/** + * Remove a subscribtion + * + * @param integer bug ID + * @param string hash + * + * @return void + */ + function unsubscribe($bug_id, $hash) + { + global $dbh; + + $hash = escapeSQL($hash); + $query = 'SELECT + bug_id, email, unsubscribe_date, unsubscribe_hash + FROM + bugdb_subscribe + WHERE + bug_id=' . $bug_id . ' + AND + unsubscribe_hash=' . "'" . $hash . "' + LIMIT 1"; + + $sub = $dbh->getRow($query, DB_FETCHMODE_ASSOC); + + if (!$sub) { + return false; + } + + $now = time(); + $requested_on = $sub['unsubscribe_date']; + /* 24hours delay to answer the mail */ + if (($now - $requested_on) > (24*60*60)) { + return false; + } + + $query = 'DELETE FROM bugdb_subscribe WHERE bug_id=' . $bug_id . ' + AND unsubscribe_hash=' . "'" . $hash . "' + AND email='" . $sub['email'] . "'"; + $dbh->query($query); + return true; + } http://cvs.php.net/viewcvs.cgi/pearweb/sql/bugs.sql?r1=1.5&r2=1.6&diff_format=u Index: pearweb/sql/bugs.sql diff -u pearweb/sql/bugs.sql:1.5 pearweb/sql/bugs.sql:1.6 --- pearweb/sql/bugs.sql:1.5 Mon Feb 20 02:41:55 2006 +++ pearweb/sql/bugs.sql Tue Feb 21 15:58:55 2006 @@ -49,3 +49,13 @@ sameos int(1) default NULL, samever int(1) default NULL ) TYPE=MyISAM; + +CREATE TABLE `bugdb_subscribe` ( + bug_id int(8) NOT NULL default '0', + email varchar(40) NOT NULL default '', + unsubcribe_date int(11) default '', + unsubcribe_hash varchar(80) default '', + PRIMARY KEY (bug_id, email), + KEY (unsubscribe_hash) +) TYPE=MyISAM; +