// This hack by Michael H. Park
// http://www.MichaelPark.net
The first thing is to add the new field to the table. Login to your control panel of your host and enter phpMyAdmin;
then, select your b2 database if necessary and click "SQL" on the top of the main page. In the textarea box, enter the
following and click "Go".
[code]
ALTER TABLE `b2comments` ADD `comment_notify` INT(1) DEFAULT '0' NOT NULL
[/code]
Now, go to the b2comments table and verify the addition.
Ok, then. You can logout from there. Now, open up "b2comments.php" or "b2commentspopup.php" depending on which one you
use. I recommend modifying both if you use the latter.
Place the following in the commentts form with other hidden fields:
Place the following where you want the option for the commenter to appear (optional):
[code]
notify me of new comments on this post (your e-mail has to be valid)
[/code]
If you choose not to show the above checkbox, put the following instead along with other hidden input form tags:
[code]
[/code]
This will turn the "notify me" option on by default. If you don't want this, set the value to 0. Also, make sure the
variable $wxcvbn_c is defined in the loop to count the number of comments.
Now, open "b2comments.post.php" file and locate:
[code]
$comment_post_ID = $HTTP_POST_VARS["comment_post_ID"];
[/code]
Add the following on the next line:
[code]
$notify = $HTTP_POST_VARS["notifyme"];
$wxcvbn_c = $HTTP_POST_VARS["wxcvbn_c"];
[/code]
Now locate:
[code]
$query = "INSERT INTO $tablecomments VALUES ('0','$comment_post_ID','$author','$email','$url','$user_ip','$now','$comment','0')";
[/code]
And replace it with:
[code]
$query = "INSERT INTO $tablecomments VALUES ('0','$comment_post_ID','$author','$email','$url','$user_ip','$now','$comment','0','$notify')";
[/code]
Locate the following:
[code]
@mail($recipient, $subject, $notify_message, "From: b2@".$HTTP_SERVER_VARS['SERVER_NAME']."\r\n"."X-Mailer: b2 $b2_version - PHP/" . phpversion());
[/code]
Lastly, add the following on the next line:
[code]
// "Notify Me" hack by Michael H. Park (http://www.MichaelPark.net)
if ($wxcvbn_c > 0) {
$notify_comment = "There's a new comment on post #$comment_post_ID.\r\n\r\n";
$notify_comment .= "author : $comment_author\r\n";
$notify_comment .= "url : $comment_author_url\r\n";
$notify_comment .= "comment: \n".stripslashes($original_comment)."\r\n\r\n";
$notify_comment .= "You can reply via here: \r\n";
$notify_comment .= $siteurl.'/'.$blogfilename.$querystring_start.'p'.$querystring_equal.$comment_post_ID.'&c'.$querystring_equal.'1&blogonly=1#comments';
// get e-mails of all commenters with "notify me" turned on for a particular post
$nquery = " SELECT DISTINCT comment_author_email, comment_notify " .
" FROM $tableposts LEFT JOIN $tablecomments ON ID = comment_post_id " .
" WHERE ID = '$comment_post_ID' AND comment_notify = 1 " .
" ORDER BY comment_ID DESC";
$nresult = mysql_query($nquery) or die(mysql_error());
while ($row = mysql_fetch_array($nresult)) {
$commenter_email = $row["comment_author_email"];
$comment_notify = $row["comment_notify"];
// e-mail out the new comment except to the current commenter
if ($commenter_email <> $email) {
@mail($commenter_email, $subject, $notify_comment, "From: b2@".$HTTP_SERVER_VARS['SERVER_NAME']."\r\n"."X-Mailer: b2 $b2_version - PHP/" . phpversion());
}
// update the "notify me" status if it's been changed since the last comment by the same commenter
if ($commenter_email == $email && $comment_notify <> $notify) {
$nupdate = mysql_query("UPDATE $tablecomments " .
" SET comment_notify = '$notify' " .
" WHERE comment_post_id = '$comment_post_ID' AND comment_author_email = '$email' ")
or die(mysql_error());
$stat_message = "Your notification status has been changed.\r\n";
$stat_subject = "Your notification status for post #$comment_post_ID \"".$postdata["Title"]."\"";
@mail($commenter_email, $stat_subject, $stat_message, "From: b2@".$HTTP_SERVER_VARS['SERVER_NAME']."\r\n"."X-Mailer: b2 $b2_version - PHP/" . phpversion());
}
}
} // end hack
[/code]
Also, because trackbacks and pingbacks are stored in the same table, a little modification to their INSERT statements is
needed; therefore, locate the following in b2trackback.php file:
[code]
$query = "INSERT INTO $tablecomments VALUES ('0','$comment_post_ID','$author','$email','$url','$user_ip','$now','$comment','0')";
[/code]
And replace it with:
[code]
$query = "INSERT INTO $tablecomments VALUES ('0','$comment_post_ID','$author','$email','$url','$user_ip','$now','$comment','0','0')";
[/code]
Then in xmlprc.php file, locate:
[code]
$sql = "INSERT INTO $tablecomments (comment_post_ID, comment_author, comment_author_url, comment_date, comment_content) VALUES ($post_ID, '$title', '$pagelinkedfrom', NOW(), '$context')";
And replace it with:
[code]
$sql = "INSERT INTO $tablecomments (comment_post_ID, comment_author, comment_author_url, comment_date, comment_content, comment_notify) VALUES ($post_ID, '$title', '$pagelinkedfrom', NOW(), '$context','0')";
[/code]
UPGRADE
-------
If you want a separate form that a visitor use to subscribe or unsubscribe to a post without entering a comment,
implement the following instructions.
Create a new file and name it b2comments.notify.php with the following codes:
[code]
$v) {
if (is_array($v)) {
$array[$k] = add_magic_quotes($v);
} else {
$array[$k] = addslashes($v);
}
}
return $array;
}
if (!get_magic_quotes_gpc()) {
$HTTP_GET_VARS = add_magic_quotes($HTTP_GET_VARS);
$HTTP_POST_VARS = add_magic_quotes($HTTP_POST_VARS);
$HTTP_COOKIE_VARS = add_magic_quotes($HTTP_COOKIE_VARS);
}
//end original
$email = trim($HTTP_POST_VARS["email"]);
$comment_post_ID = $HTTP_POST_VARS["comment_post_ID"];
$sub = $HTTP_POST_VARS["sub"];
$unsub = $HTTP_POST_VARS["unsub"];
if (empty($email) || $email == "@") {
echo "Error: please type in your e-mail address.";
echo "\n
\ngo back\n\n";
exit;
}
//by Michael E. (marshack)
elseif ((!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))) {
echo "Error: e-mail address is mal-formed.";
echo "\n
\ngo back\n\n";
exit;
}
elseif (!$sub && !$unsub) {
echo "Error: please select either subscribe or unsubscribe option.";
echo "\n
\ngo back\n\n";
exit;
}
//original
$user_ip = $REMOTE_ADDR;
$user_domain = gethostbyaddr($user_ip);
$time_difference = get_settings("time_difference");
$now = date("Y-m-d H:i:s",(time() + ($time_difference * 3600)));
$email = strip_tags($email);
if (strlen($email) < 6) {
$email = '';
}
$comment_author_email = $email;
$email = addslashes($email);
/* flood-protection */
$query = "SELECT comment_date FROM $tablecomments WHERE comment_author_IP='$user_ip' ORDER BY comment_date DESC LIMIT 1";
$result = mysql_query($query);
$ok=1;
if (!empty($result)) {
while($row = mysql_fetch_object($result)) {
$then=$row->comment_date;
}
$time_lastcomment=mysql2date("U","$then");
$time_newcomment=mysql2date("U","$now");
if (($time_newcomment - $time_lastcomment) < 30)
$ok=0;
}
/* end flood-protection */
//end original
if ($ok) {
$postdata = get_postdata($comment_post_ID);
$stat_subject = "Your subscription status for post #$comment_post_ID \"".$postdata["Title"]."\"";
if ($sub) {
$checksub = mysql_query("SELECT DISTINCT comment_author_email FROM $tablecomments " .
" WHERE comment_post_id = '$comment_post_ID' AND comment_author_email = '$email' AND comment_notify = 1 " .
" ORDER BY comment_date DESC")
or die(mysql_error());
$numrows = mysql_num_rows($checksub);
if ($numrows > 0) {
echo "You are already subscribed to this post.\n\n";
echo "\n
\ngo back\n\n";
exit;
}
else {
$query = "INSERT INTO $tablecomments (comment_post_ID,comment_author_email,comment_author_ip,comment_date,comment_notify) VALUES ('$comment_post_ID','$email','$user_ip','$now','$sub')";
$result = mysql_query($query) or die(mysql_error());
$stat_message = "You are now subscribed to post #$comment_post_ID.\r\n";
@mail($email, $stat_subject, $stat_message, "From: b2@".$HTTP_SERVER_VARS['SERVER_NAME']."\r\n"."X-Mailer: b2 $b2_version - PHP/" . phpversion());
}
}
elseif ($unsub) {
$checkunsub = mysql_query("SELECT DISTINCT comment_author_email FROM $tablecomments " .
" WHERE comment_post_id = '$comment_post_ID' AND comment_author_email = '$email' AND comment_notify = 1 " .
" ORDER BY comment_date DESC")
or die(mysql_error());
$numrows = mysql_num_rows($checkunsub);
if ($numrows == 0) {
echo "You have not subscribed to this post.\n\n";
echo "\n
\ngo back\n\n";
exit;
}
else {
$nupdate = mysql_query("UPDATE $tablecomments " .
" SET comment_notify = 0 " .
" WHERE comment_post_id = '$comment_post_ID' AND comment_author_email = '$email' AND comment_notify = 1")
or die(mysql_error());
$stat_message = "Your subscription on post #$comment_post_ID has been cancelled.\r\n";
@mail($email, $stat_subject, $stat_message, "From: b2@".$HTTP_SERVER_VARS['SERVER_NAME']."\r\n"."X-Mailer: b2 $b2_version - PHP/" . phpversion());
}
}
//original
if ($email == "") {
$email = " "; // this to make sure a cookie is set for 'no email'
}
setcookie("comment_author_email",$email, time()+30000000, "/", ".michaelpark.net");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
$location = (!empty($HTTP_POST_VARS['redirect_to'])) ? $HTTP_POST_VARS['redirect_to'] : $HTTP_SERVER_VARS["HTTP_REFERER"];
if ($is_IIS) {
header("Refresh: 0;url=$location");
} else {
header("Location: $location");
}
//end original
} else {
echo "Sorry, you can only use this every 30 second";
echo "\n
go back\n\n";
die();
}
?>
[/code]
Then in b2comments.php and/or b2commentspopup.php, put the following where you want the form to appear:
[code]