Source for file comment_post.php
Documentation is available at comment_post.php
* This file posts a comment!
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
require_once( dirname(__FILE__
) .
'/../b2evocore/_main.php' );
// statuses allowed for acting on:
$show_statuses =
array( 'published', 'protected', 'private' );
// Only for 0.9.0.11, for users who will not update their conf! :/
if( !isset
($minimum_comment_interval) ) $minimum_comment_interval =
30;
// Getting GET or POST parameters:
param( 'comment_post_ID', 'integer', true ); // required
if( ! $commented_Item->can_comment( '', '', '', '' ) )
errors_add( T_('You cannot leave comments on this post!') );
param( 'author', 'string' );
param( 'email', 'string' );
param( 'url', 'string' );
param( 'comment' , 'html' );
param( 'comment_autobr', 'integer', ($comments_use_autobr ==
'always') ?
1 :
0 );
param( 'comment_cookies', 'integer', 0 );
{ // User is loggued in, we'll use his ID
$author_ID =
$current_User->ID;
{ // User is not logged in, we need some id info from him:
{ // Blog wants Name and EMail with comments
if( empty($author) ) errors_add( T_('Please fill in the name field') );
if( empty($email) ) errors_add( T_('Please fill in the email field') );
// add 'http://' if no protocol defined for URL
$url =
((!stristr($url, '://')) &&
($url !=
'')) ?
'http://' .
$url :
$url;
if( $error =
validate_url( $url, $comments_allowed_uri_scheme ) )
$user_ip =
$_SERVER['REMOTE_ADDR'];
$user_ip =
explode( ',', $user_ip );
$now =
date("Y-m-d H:i:s", $localtimenow );
// CHECK and FORMAT content
//echo 'allowed tags:',htmlspecialchars($comment_allowed_tags);
$original_comment =
strip_tags($comment, $comment_allowed_tags);
{ // comment should not be empty!
$query =
"SELECT max(comment_date)
WHERE comment_author_IP = '$user_ip'";
if( $then =
$DB->get_var( $query ) )
if( ($time_newcomment -
$time_lastcomment) <
$minimum_comment_interval )
errors_add( sprintf( T_('You can only post a new comment every %d seconds.'), $minimum_comment_interval ) );
/* end flood-protection */
'[<a href="javascript:history.go(-1)">'.
T_('Back to comment editing') .
'</a>]' ) )
$query =
"INSERT INTO $tablecomments( comment_post_ID, comment_type, comment_author_ID, comment_author,
comment_author_email, comment_author_url, comment_author_IP,
comment_date, comment_content)
VALUES( $comment_post_ID, 'comment', ".
$DB->null($author_ID).
",
".
$DB->quote($author).
", ".
$DB->quote($email).
",
".
$DB->quote($url).
",'".
$DB->escape($user_ip).
"','$now',
'".
$DB->escape($comment).
"' )";
* New comment notification:
$item_author_User =
& $commented_Item->Author;
if( $item_author_User->notify
&&
(!empty( $item_author_User->email ))
&&
$author_ID !=
$item_author_User->ID ) // don't send if original author comments (is logged in)
{ // Author wants to be notified and does not comment himself:
$recipient =
$item_author_User->email;
$subject =
sprintf( T_('New comment on your post #%d "%s"'), $comment_post_ID, $commented_Item->get('title') );
$notify_message =
sprintf( T_('New comment on your post #%d "%s"'), $comment_post_ID, $commented_Item->get('title') ).
"\n";
$notify_message .=
str_replace('&', '&', $commented_Item->gen_permalink( 'pid' )).
"\n\n"; // We use pid to get a short URL and avoid it to wrap on a new line in the mail which may prevent people from clicking
$notify_message .=
T_('Author').
': '.
$current_User->get('preferedname').
' ('.
$current_User->get('login').
")\n";
$notify_message .=
T_('Author').
": $author (IP: $user_ip, $user_domain)\n";
$notify_message .=
T_('Email').
": $email\n";
$notify_message .=
T_('Url').
": $url\n";
$notify_message .=
T_('Comment').
": \n".
$original_comment.
"\n\n";
$notify_message .=
T_('Edit/Delete').
': '.
$admin_url.
'/b2browse.php?blog='.
$commented_Item->blog_ID.
'&p='.
$comment_post_ID.
"&c=1\n";
// echo "Sending notification to $recipient :<pre>$notify_message</pre>";
$mail_from =
$current_User->get('email');
elseif( empty( $email ) )
$mail_from =
$notify_from;
$mail_from =
"\"$author\" <$email>";
send_mail( $recipient, $subject, $notify_message, $mail_from );
$email =
' '; // this to make sure a cookie is set for 'no email'
$url =
' '; // this to make sure a cookie is set for 'no url'
// fplanque: made cookies available for whole site
setcookie( $cookie_name, $author, $cookie_expires, $cookie_path, $cookie_domain);
setcookie( $cookie_email, $email, $cookie_expires, $cookie_path, $cookie_domain);
setcookie( $cookie_url, $url, $cookie_expires, $cookie_path, $cookie_domain);
if( !empty($_COOKIE[$cookie_name]) )
setcookie('comment_author', '', $cookie_expired, '/');
setcookie('comment_author', '', $cookie_expired, $cookie_path, $cookie_domain);
setcookie( $cookie_name, '', $cookie_expired, $cookie_path, $cookie_domain);
if( !empty($_COOKIE['comment_author_email']) )
setcookie('comment_author_email', '', $cookie_expired, '/');
setcookie('comment_author_email', '', $cookie_expired, $cookie_path, $cookie_domain);
setcookie( $cookie_email, '', $cookie_expired, $cookie_path, $cookie_domain);
if( !empty($_COOKIE['comment_author_url']) )
setcookie('comment_author_url', '', $cookie_expired, '/');
setcookie('comment_author_url', '', $cookie_expired, $cookie_path, $cookie_domain);
setcookie( $cookie_url, '', $cookie_expired, $cookie_path, $cookie_domain);
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');
param( 'redirect_to', 'string' );
$location =
(!empty($redirect_to)) ?
$redirect_to :
$_SERVER['HTTP_REFERER'];