5 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
6 * Copyright (C) 2002-2012 The Nucleus Group
\r
8 * This program is free software; you can redistribute it and/or
\r
9 * modify it under the terms of the GNU General Public License
\r
10 * as published by the Free Software Foundation; either version 2
\r
11 * of the License, or (at your option) any later version.
\r
12 * (see nucleus/documentation/index.html#license for more info)
\r
15 * A class representing the comments (all of them) for a certain post on a ceratin blog
\r
17 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
18 * @copyright Copyright (C) 2002-2012 The Nucleus Group
\r
19 * @version $Id: COMMENTS.php 1527 2011-06-21 10:43:44Z sakamocchi $
\r
22 if ( !function_exists('requestVar') ) exit;
\r
23 require_once dirname(__FILE__) . '/COMMENTACTIONS.php';
\r
27 // reference to the itemActions object that is calling the showComments function
\r
28 public $itemActions;
\r
30 // item for which comment are being displayed
\r
33 // total amount of comments displayed
\r
34 public $commentcount;
\r
37 * Comments::__construct()
\r
38 * Creates a new Comments object for the given blog and item
\r
40 * @param integer $itemid id of the item
\r
43 public function __construct($itemid)
\r
45 $this->itemid = (integer) $itemid;
\r
50 * Comments::setItemActions()
\r
51 * Used when parsing comments
\r
53 * @param object $itemActions itemActions object, that will take care of the parsing
\r
56 public function setItemActions(&$itemActions)
\r
58 $this->itemActions =& $itemActions;
\r
63 * Comments::showComments()
\r
64 * Shows maximum $max comments to the given item using the given template
\r
65 * returns the amount of shown comments (if maxToShow = -1, then there is no limit)
\r
67 * @param array template template to use
\r
68 * @param integer maxToShow max. comments to show
\r
69 * @param integer showNone indicates if the 'no comments' thingie should be outputted
\r
70 * when there are no comments (useful for closed items)
\r
71 * @param string highlight Highlight to use (if any)
\r
72 * @return integer number of comments
\r
74 public function showComments($template, $maxToShow = -1, $showNone = 1, $highlight = '')
\r
76 global $CONF, $manager;
\r
78 if ( $maxToShow == 0 )
\r
80 $this->commentcount = $this->amountComments();
\r
84 $query = 'SELECT citem as itemid, cnumber as commentid, cbody as body, cuser as user, cmail as userid, '
\r
85 . 'cemail as email, cmember as memberid, ctime, chost as host, cip as ip, cblog as blogid '
\r
86 . 'FROM %s as c WHERE citem=%d ORDER BY ctime';
\r
88 $query = sprintf($query, sql_table('comment'), (integer) $this->itemid);
\r
89 $comments = DB::getResult($query);
\r
90 $this->commentcount = $comments->rowCount();
\r
93 // create parser object & action handler
\r
94 $handler = new CommentActions($this);
\r
95 $handler->setTemplate($template);
\r
97 $parser = new Parser($handler);
\r
99 // if no result was found
\r
100 if ( $this->commentcount == 0 )
\r
102 // note: when no reactions, COMMENTS_HEADER and COMMENTS_FOOTER are _NOT_ used
\r
105 $parser->parse($template['COMMENTS_NONE']);
\r
110 // if too many comments to show
\r
111 if ( ($maxToShow != -1) && ($this->commentcount > $maxToShow) )
\r
113 $parser->parse($template['COMMENTS_TOOMUCH']);
\r
117 $parser->parse($template['COMMENTS_HEADER']);
\r
119 foreach ( $comments as $comment )
\r
121 $comment['timestamp'] = strtotime($comment['ctime']);
\r
122 $handler->setCurrentComment($comment);
\r
123 $handler->setHighlight($highlight);
\r
125 $manager->notify('PreComment', array('comment' => &$comment));
\r
126 $parser->parse($template['COMMENTS_BODY']);
\r
127 $manager->notify('PostComment', array('comment' => &$comment));
\r
130 $parser->parse($template['COMMENTS_FOOTER']);
\r
132 $comments->closeCursor();
\r
134 return $this->commentcount;
\r
138 * Comments::amountComments()
\r
139 * Returns the amount of comments for this itemid
\r
142 * @return integer number of comments
\r
144 public function amountComments()
\r
146 $query = 'SELECT COUNT(*) FROM %s WHERE citem=%d;';
\r
147 $query = sprintf($query, sql_table('comment'), (integer) $this->itemid);
\r
148 $res = DB::getValue($query);
\r
154 * Comments::addComment()
\r
155 * Adds a new comment to the database
\r
157 * @param string $timestamp
\r
158 * @param array $comment
\r
161 public function addComment($timestamp, $comment)
\r
163 global $CONF, $member, $manager;
\r
165 $blogid = getBlogIDFromItemID($this->itemid);
\r
167 $settings =& $manager->getBlog($blogid);
\r
168 $settings->readSettings();
\r
170 // begin if: comments disabled
\r
171 if ( !$settings->commentsEnabled() )
\r
173 return _ERROR_COMMENTS_DISABLED;
\r
176 // begin if: public cannot comment
\r
177 if ( !$settings->isPublic() && !$member->isLoggedIn() )
\r
179 return _ERROR_COMMENTS_NONPUBLIC;
\r
182 // begin if: comment uses a protected member name
\r
183 if ( $CONF['ProtectMemNames'] && !$member->isLoggedIn() && Member::isNameProtected($comment['user']) )
\r
185 return _ERROR_COMMENTS_MEMBERNICK;
\r
188 // begin if: email required, but missing (doesn't apply to members)
\r
189 if ( $settings->emailRequired() && i18n::strlen($comment['email']) == 0 && !$member->isLoggedIn() )
\r
191 return _ERROR_EMAIL_REQUIRED;
\r
194 // begin if: commenter's name is too long
\r
195 if ( i18n::strlen($comment['user']) > 40 )
\r
197 return _ERROR_USER_TOO_LONG;
\r
200 // begin if: commenter's email is too long
\r
201 if ( i18n::strlen($comment['email']) > 100 )
\r
203 return _ERROR_EMAIL_TOO_LONG;
\r
206 // begin if: commenter's url is too long
\r
207 if ( i18n::strlen($comment['userid']) > 100 )
\r
209 return _ERROR_URL_TOO_LONG;
\r
212 $comment['timestamp'] = $timestamp;
\r
213 $comment['host'] = gethostbyaddr(serverVar('REMOTE_ADDR') );
\r
214 $comment['ip'] = serverVar('REMOTE_ADDR');
\r
216 // begin if: member is logged in, use that data
\r
217 if ( $member->isLoggedIn() )
\r
219 $comment['memberid'] = $member->getID();
\r
220 $comment['user'] = '';
\r
221 $comment['userid'] = '';
\r
222 $comment['email'] = '';
\r
226 $comment['memberid'] = 0;
\r
231 $plugins = array();
\r
233 if ( isset($manager->subscriptions['ValidateForm']) )
\r
235 $plugins = array_merge($plugins, $manager->subscriptions['ValidateForm']);
\r
238 if ( isset($manager->subscriptions['PreAddComment']) )
\r
240 $plugins = array_merge($plugins, $manager->subscriptions['PreAddComment']);
\r
243 if ( isset($manager->subscriptions['PostAddComment']) )
\r
245 $plugins = array_merge($plugins, $manager->subscriptions['PostAddComment']);
\r
248 $plugins = array_unique($plugins);
\r
250 while ( list(, $plugin) = each($plugins) )
\r
252 $p = $manager->getPlugin($plugin);
\r
253 $continue = $continue || $p->supportsFeature('handleSpam');
\r
256 $spamcheck = array(
\r
257 'type' => 'comment',
\r
258 'body' => $comment['body'],
\r
259 'id' => $comment['itemid'],
\r
261 'return' => $continue
\r
264 // begin if: member logged in
\r
265 if ( $member->isLoggedIn() )
\r
267 $spamcheck['author'] = $member->displayname;
\r
268 $spamcheck['email'] = $member->email;
\r
273 $spamcheck['author'] = $comment['user'];
\r
274 $spamcheck['email'] = $comment['email'];
\r
275 $spamcheck['url'] = $comment['userid'];
\r
278 $manager->notify('SpamCheck', array('spamcheck' => &$spamcheck) );
\r
280 if ( !$continue && isset($spamcheck['result']) && $spamcheck['result'] == TRUE )
\r
282 return _ERROR_COMMENTS_SPAM;
\r
285 // isValidComment returns either "1" or an error message
\r
286 $isvalid = $this->isValidComment($comment, $spamcheck);
\r
287 if ( $isvalid != 1 )
\r
292 // begin if: send email to notification address
\r
293 if ( $settings->getNotifyAddress() && $settings->notifyOnComment() )
\r
296 $message = _NOTIFY_NC_MSG . ' ' . $this->itemid . "\n";
\r
297 $temp = parse_url($CONF['Self']);
\r
299 if ( $temp['scheme'] )
\r
301 $message .= Link::create_item_link($this->itemid) . "\n\n";
\r
305 $tempurl = $settings->getURL();
\r
307 if ( i18n::substr($tempurl, -1) == '/' || i18n::substr($tempurl, -4) == '.php' )
\r
309 $message .= $tempurl . '?itemid=' . $this->itemid . "\n\n";
\r
313 $message .= $tempurl . '/?itemid=' . $this->itemid . "\n\n";
\r
317 if ( $comment['memberid'] == 0 )
\r
319 $message .= _NOTIFY_USER . ' ' . $comment['user'] . "\n";
\r
320 $message .= _NOTIFY_USERID . ' ' . $comment['userid'] . "\n";
\r
324 $message .= _NOTIFY_MEMBER .' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n";
\r
327 $message .= _NOTIFY_HOST . ' ' . $comment['host'] . "\n";
\r
328 $message .= _NOTIFY_COMMENT . "\n " . $comment['body'] . "\n";
\r
329 $message .= NOTIFICATION::get_mail_footer();
\r
331 $item =& $manager->getItem($this->itemid, 0, 0);
\r
332 $subject = _NOTIFY_NC_TITLE . ' ' . strip_tags($item['title']) . ' (' . $this->itemid . ')';
\r
334 $from = $member->getNotifyFromMailAddress($comment['email']);
\r
336 NOTIFICATION::mail($settings->getNotifyAddress(), $subject, $message, $from, i18n::get_current_charset());
\r
339 $comment = Comment::prepare($comment);
\r
341 $manager->notify('PreAddComment', array('comment' => &$comment, 'spamcheck' => &$spamcheck) );
\r
343 $name = DB::quoteValue($comment['user']);
\r
344 $url = DB::quoteValue($comment['userid']);
\r
345 $email = DB::quoteValue($comment['email']);
\r
346 $body = DB::quoteValue($comment['body']);
\r
347 $host = DB::quoteValue($comment['host']);
\r
348 $ip = DB::quoteValue($comment['ip']);
\r
349 $memberid = intval($comment['memberid']);
\r
350 $timestamp = DB::formatDateTime($comment['timestamp']);
\r
351 $itemid = $this->itemid;
\r
353 $qSql = 'SELECT COUNT(*) AS result '
\r
354 . 'FROM ' . sql_table('comment')
\r
356 . 'cmail = ' . $url
\r
357 . ' AND cmember = ' . $memberid
\r
358 . ' AND cbody = ' . $body
\r
359 . ' AND citem = ' . $itemid
\r
360 . ' AND cblog = ' . $blogid;
\r
361 $result = (integer) DB::getValue($qSql);
\r
365 return _ERROR_BADACTION;
\r
368 $query = sprintf('INSERT INTO %s (cuser, cmail, cemail, cmember, cbody, citem, ctime, chost, cip, cblog) '
\r
369 . 'VALUES (%s, %s, %s, %d, %s, %d, %s, %s, %s, %d)'
\r
370 , sql_table('comment'), $name, $url, $email, $memberid, $body, $itemid, $timestamp, $host, $ip, $blogid);
\r
372 DB::execute($query);
\r
374 // post add comment
\r
375 $commentid = DB::getInsertId();
\r
376 $manager->notify('PostAddComment', array('comment' => &$comment, 'commentid' => &$commentid, 'spamcheck' => &$spamcheck) );
\r
383 * Comments::isValidComment()
\r
384 * Checks if a comment is valid and call plugins
\r
385 * that can check if the comment is a spam comment
\r
387 * @param array $comment array with comment elements
\r
388 * @param array $spamcheck array with spamcheck elements
\r
389 * @return boolean valid or not
\r
391 private function isValidComment(&$comment, &$spamcheck)
\r
393 global $member, $manager;
\r
395 // check if there exists a item for this date
\r
396 $item =& $manager->getItem($this->itemid, 0, 0);
\r
400 return _ERROR_NOSUCHITEM;
\r
403 if ( $item['closed'] )
\r
405 return _ERROR_ITEMCLOSED;
\r
408 // don't allow words that are too long
\r
409 if ( preg_match('/[a-zA-Z0-9|\.,;:!\?=\/\\\\]{90,90}/', $comment['body']) != 0 )
\r
411 return _ERROR_COMMENT_LONGWORD;
\r
414 // check lengths of comment
\r
415 if ( i18n::strlen($comment['body']) < 3 )
\r
417 return _ERROR_COMMENT_NOCOMMENT;
\r
420 if ( i18n::strlen($comment['body']) > 5000 )
\r
422 return _ERROR_COMMENT_TOOLONG;
\r
425 // only check username if no member logged in
\r
426 if ( !$member->isLoggedIn() && (i18n::strlen($comment['user']) < 2) )
\r
428 return _ERROR_COMMENT_NOUSERNAME;
\r
431 if ( (i18n::strlen($comment['email']) != 0) && !NOTIFICATION::address_validation(trim($comment['email'])) )
\r
433 return _ERROR_BADMAILADDRESS;
\r
436 // let plugins do verification (any plugin which thinks the comment is invalid
\r
437 // can change 'error' to something other than '1')
\r
439 $manager->notify('ValidateForm', array('type' => 'comment', 'comment' => &$comment, 'error' => &$result, 'spamcheck' => &$spamcheck) );
\r
448 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
449 * Copyright (C) 2002-2009 The Nucleus Group
451 * This program is free software; you can redistribute it and/or
452 * modify it under the terms of the GNU General Public License
453 * as published by the Free Software Foundation; either version 2
454 * of the License, or (at your option) any later version.
455 * (see nucleus/documentation/index.html#license for more info)
458 * A class representing the comments (all of them) for a certain post on a ceratin blog
460 * @license http://nucleuscms.org/license.txt GNU General Public License
461 * @copyright Copyright (C) 2002-2009 The Nucleus Group
462 * @version $Id: COMMENTS.php 1527 2011-06-21 10:43:44Z sakamocchi $
465 if ( !function_exists('requestVar') ) exit;
466 require_once dirname(__FILE__) . '/COMMENTACTIONS.php';
470 // reference to the itemActions object that is calling the showComments function
473 // item for which comment are being displayed
476 // total amount of comments displayed
477 public $commentcount;
480 * Comments::__construct()
481 * Creates a new Comments object for the given blog and item
483 * @param integer $itemid id of the item
486 public function __construct($itemid)
488 $this->itemid = (integer) $itemid;
493 * Comments::setItemActions()
494 * Used when parsing comments
496 * @param object $itemActions itemActions object, that will take care of the parsing
499 public function setItemActions(&$itemActions)
501 $this->itemActions =& $itemActions;
506 * Comments::showComments()
507 * Shows maximum $max comments to the given item using the given template
508 * returns the amount of shown comments (if maxToShow = -1, then there is no limit)
510 * @param array template template to use
511 * @param integer maxToShow max. comments to show
512 * @param integer showNone indicates if the 'no comments' thingie should be outputted
513 * when there are no comments (useful for closed items)
514 * @param string highlight Highlight to use (if any)
515 * @return integer number of comments
517 public function showComments($template, $maxToShow = -1, $showNone = 1, $highlight = '')
519 global $CONF, $manager;
521 if ( $maxToShow == 0 )
523 $this->commentcount = $this->amountComments();
527 $query = 'SELECT citem as itemid, cnumber as commentid, cbody as body, cuser as user, cmail as userid, '
528 . 'cemail as email, cmember as memberid, ctime, chost as host, cip as ip, cblog as blogid '
529 . 'FROM %s as c WHERE citem=%d ORDER BY ctime';
531 $query = sprintf($query, sql_table('comment'), (integer) $this->itemid);
532 $comments = DB::getResult($query);
533 $this->commentcount = $comments->rowCount();
536 // create parser object & action handler
537 $handler = new CommentActions($this);
538 $handler->setTemplate($template);
540 $parser = new Parser($handler);
542 // if no result was found
543 if ( $this->commentcount == 0 )
545 // note: when no reactions, COMMENTS_HEADER and COMMENTS_FOOTER are _NOT_ used
548 $parser->parse($template['COMMENTS_NONE']);
553 // if too many comments to show
554 if ( ($maxToShow != -1) && ($this->commentcount > $maxToShow) )
556 $parser->parse($template['COMMENTS_TOOMUCH']);
560 $parser->parse($template['COMMENTS_HEADER']);
562 foreach ( $comments as $comment )
564 $comment['timestamp'] = strtotime($comment['ctime']);
565 $handler->setCurrentComment($comment);
566 $handler->setHighlight($highlight);
568 $data = array('comment' => &$comment);
569 $manager->notify('PreComment', $data);
570 $parser->parse($template['COMMENTS_BODY']);
571 $manager->notify('PostComment', $data);
574 $parser->parse($template['COMMENTS_FOOTER']);
576 $comments->closeCursor();
578 return $this->commentcount;
582 * Comments::amountComments()
583 * Returns the amount of comments for this itemid
586 * @return integer number of comments
588 public function amountComments()
590 $query = 'SELECT COUNT(*) FROM %s WHERE citem=%d;';
591 $query = sprintf($query, sql_table('comment'), (integer) $this->itemid);
592 $res = DB::getValue($query);
598 * Comments::addComment()
599 * Adds a new comment to the database
601 * @param string $timestamp
602 * @param array $comment
605 public function addComment($timestamp, $comment)
607 global $CONF, $member, $manager;
609 $blogid = getBlogIDFromItemID($this->itemid);
611 $settings =& $manager->getBlog($blogid);
612 $settings->readSettings();
614 // begin if: comments disabled
615 if ( !$settings->commentsEnabled() )
617 return _ERROR_COMMENTS_DISABLED;
620 // begin if: public cannot comment
621 if ( !$settings->isPublic() && !$member->isLoggedIn() )
623 return _ERROR_COMMENTS_NONPUBLIC;
626 // begin if: comment uses a protected member name
627 if ( $CONF['ProtectMemNames'] && !$member->isLoggedIn() && Member::isNameProtected($comment['user']) )
629 return _ERROR_COMMENTS_MEMBERNICK;
632 // begin if: email required, but missing (doesn't apply to members)
633 if ( $settings->emailRequired() && i18n::strlen($comment['email']) == 0 && !$member->isLoggedIn() )
635 return _ERROR_EMAIL_REQUIRED;
638 // begin if: commenter's name is too long
639 if ( i18n::strlen($comment['user']) > 40 )
641 return _ERROR_USER_TOO_LONG;
644 // begin if: commenter's email is too long
645 if ( i18n::strlen($comment['email']) > 100 )
647 return _ERROR_EMAIL_TOO_LONG;
650 // begin if: commenter's url is too long
651 if ( i18n::strlen($comment['userid']) > 100 )
653 return _ERROR_URL_TOO_LONG;
656 $comment['timestamp'] = $timestamp;
657 $comment['host'] = gethostbyaddr(serverVar('REMOTE_ADDR') );
658 $comment['ip'] = serverVar('REMOTE_ADDR');
660 // begin if: member is logged in, use that data
661 if ( $member->isLoggedIn() )
663 $comment['memberid'] = $member->getID();
664 $comment['user'] = '';
665 $comment['userid'] = '';
666 $comment['email'] = '';
670 $comment['memberid'] = 0;
677 if ( isset($manager->subscriptions['ValidateForm']) )
679 $plugins = array_merge($plugins, $manager->subscriptions['ValidateForm']);
682 if ( isset($manager->subscriptions['PreAddComment']) )
684 $plugins = array_merge($plugins, $manager->subscriptions['PreAddComment']);
687 if ( isset($manager->subscriptions['PostAddComment']) )
689 $plugins = array_merge($plugins, $manager->subscriptions['PostAddComment']);
692 $plugins = array_unique($plugins);
694 while ( list(, $plugin) = each($plugins) )
696 $p = $manager->getPlugin($plugin);
697 $continue = $continue || $p->supportsFeature('handleSpam');
702 'body' => $comment['body'],
703 'id' => $comment['itemid'],
705 'return' => $continue
708 // begin if: member logged in
709 if ( $member->isLoggedIn() )
711 $spamcheck['author'] = $member->displayname;
712 $spamcheck['email'] = $member->email;
717 $spamcheck['author'] = $comment['user'];
718 $spamcheck['email'] = $comment['email'];
719 $spamcheck['url'] = $comment['userid'];
722 $data = array('spamcheck' => &$spamcheck);
723 $manager->notify('SpamCheck', $data);
725 if ( !$continue && isset($spamcheck['result']) && $spamcheck['result'] == TRUE )
727 return _ERROR_COMMENTS_SPAM;
730 // isValidComment returns either "1" or an error message
731 $isvalid = $this->isValidComment($comment, $spamcheck);
737 // begin if: send email to notification address
738 if ( $settings->getNotifyAddress() && $settings->notifyOnComment() )
741 $message = _NOTIFY_NC_MSG . ' ' . $this->itemid . "\n";
742 $temp = parse_url($CONF['Self']);
744 if ( $temp['scheme'] )
746 $message .= Link::create_item_link($this->itemid) . "\n\n";
750 $tempurl = $settings->getURL();
752 if ( i18n::substr($tempurl, -1) == '/' || i18n::substr($tempurl, -4) == '.php' )
754 $message .= $tempurl . '?itemid=' . $this->itemid . "\n\n";
758 $message .= $tempurl . '/?itemid=' . $this->itemid . "\n\n";
762 if ( $comment['memberid'] == 0 )
764 $message .= _NOTIFY_USER . ' ' . $comment['user'] . "\n";
765 $message .= _NOTIFY_USERID . ' ' . $comment['userid'] . "\n";
769 $message .= _NOTIFY_MEMBER .' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n";
772 $message .= _NOTIFY_HOST . ' ' . $comment['host'] . "\n";
773 $message .= _NOTIFY_COMMENT . "\n " . $comment['body'] . "\n";
774 $message .= NOTIFICATION::get_mail_footer();
776 $item =& $manager->getItem($this->itemid, 0, 0);
777 $subject = _NOTIFY_NC_TITLE . ' ' . strip_tags($item['title']) . ' (' . $this->itemid . ')';
779 $from = $member->getNotifyFromMailAddress($comment['email']);
781 NOTIFICATION::mail($settings->getNotifyAddress(), $subject, $message, $from, i18n::get_current_charset());
784 $comment = Comment::prepare($comment);
786 $data = array('comment' => &$comment, 'spamcheck' => &$spamcheck);
787 $manager->notify('PreAddComment', $data);
789 $name = DB::quoteValue($comment['user']);
790 $url = DB::quoteValue($comment['userid']);
791 $email = DB::quoteValue($comment['email']);
792 $body = DB::quoteValue($comment['body']);
793 $host = DB::quoteValue($comment['host']);
794 $ip = DB::quoteValue($comment['ip']);
795 $memberid = intval($comment['memberid']);
796 $timestamp = DB::formatDateTime($comment['timestamp']);
797 $itemid = $this->itemid;
799 $qSql = 'SELECT COUNT(*) AS result '
800 . 'FROM ' . sql_table('comment')
803 . ' AND cmember = ' . $memberid
804 . ' AND cbody = ' . $body
805 . ' AND citem = ' . $itemid
806 . ' AND cblog = ' . $blogid;
807 $result = (integer) DB::getValue($qSql);
811 return _ERROR_BADACTION;
814 $query = sprintf('INSERT INTO %s (cuser, cmail, cemail, cmember, cbody, citem, ctime, chost, cip, cblog) '
815 . 'VALUES (%s, %s, %s, %d, %s, %d, %s, %s, %s, %d)'
816 , sql_table('comment'), $name, $url, $email, $memberid, $body, $itemid, $timestamp, $host, $ip, $blogid);
821 $commentid = DB::getInsertId();
822 $data = array('comment' => &$comment, 'commentid' => &$commentid, 'spamcheck' => &$spamcheck);
823 $manager->notify('PostAddComment', $data);
830 * Comments::isValidComment()
831 * Checks if a comment is valid and call plugins
832 * that can check if the comment is a spam comment
834 * @param array $comment array with comment elements
835 * @param array $spamcheck array with spamcheck elements
836 * @return boolean valid or not
838 private function isValidComment(&$comment, &$spamcheck)
840 global $member, $manager;
842 // check if there exists a item for this date
843 $item =& $manager->getItem($this->itemid, 0, 0);
847 return _ERROR_NOSUCHITEM;
850 if ( $item['closed'] )
852 return _ERROR_ITEMCLOSED;
855 // don't allow words that are too long
856 if ( preg_match('/[a-zA-Z0-9|\.,;:!\?=\/\\\\]{90,90}/', $comment['body']) != 0 )
858 return _ERROR_COMMENT_LONGWORD;
861 // check lengths of comment
862 if ( i18n::strlen($comment['body']) < 3 )
864 return _ERROR_COMMENT_NOCOMMENT;
867 if ( i18n::strlen($comment['body']) > 5000 )
869 return _ERROR_COMMENT_TOOLONG;
872 // only check username if no member logged in
873 if ( !$member->isLoggedIn() && (i18n::strlen($comment['user']) < 2) )
875 return _ERROR_COMMENT_NOUSERNAME;
878 if ( (i18n::strlen($comment['email']) != 0) && !NOTIFICATION::address_validation(trim($comment['email'])) )
880 return _ERROR_BADMAILADDRESS;
883 // let plugins do verification (any plugin which thinks the comment is invalid
884 // can change 'error' to something other than '1')
886 $data = array('type' => 'comment', 'comment' => &$comment, 'error' => &$result, 'spamcheck' => &$spamcheck);
887 $manager->notify('ValidateForm', $data);
892 >>>>>>> skinnable-master