OSDN Git Service

merged from v3.31sp1
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / COMMENTS.php
index 200c435..ec2ecc4 100755 (executable)
-<?php\r
-\r
-/**\r
-  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
-  * Copyright (C) 2002-2005 The Nucleus Group\r
-  *\r
-  * This program is free software; you can redistribute it and/or\r
-  * modify it under the terms of the GNU General Public License\r
-  * as published by the Free Software Foundation; either version 2\r
-  * of the License, or (at your option) any later version.\r
-  * (see nucleus/documentation/index.html#license for more info)\r
-  *\r
-  * A class representing the comments (all of them) for a certain post on a ceratin blog\r
-  *\r
-  * $Id: COMMENTS.php,v 1.5 2005-03-12 06:19:05 kimitake Exp $\r
-  * $NucleusJP$\r
-  */\r
-class COMMENTS {\r
-\r
-       // item for which comment are being displayed\r
-       var $itemid;\r
-\r
-       // reference to the itemActions object that is calling the showComments function\r
-       var $itemActions;\r
-\r
-       // total amount of comments displayed\r
-       var $commentcount;\r
-\r
-       /**\r
-        * Creates a new COMMENTS object for the given blog and item\r
-        *\r
-        * @param $itemid\r
-        *              id of the item\r
-        */\r
-       function COMMENTS($itemid) {\r
-               $this->itemid = intval($itemid);\r
-       }\r
-       /**\r
-        * Used when parsing comments\r
-        *\r
-        * @param $itemActions\r
-        *              itemActions object, that will take care of the parsing\r
-        */\r
-       function setItemActions(&$itemActions) {\r
-               $this->itemActions =& $itemActions;\r
-       }\r
-\r
-       /**\r
-        * Shows maximum $max comments to the given item using the given template\r
-        * returns the amount of shown comments (if maxToShow = -1, then there is no limit)\r
-        *\r
-        * @param template\r
-        *              template to use\r
-        * @param maxToShow\r
-        *              max. comments to show\r
-        * @param showNone\r
-        *              indicates if the 'no comments' thingie should be outputted when there are no comments\r
-        *              (useful for closed items)\r
-        * @param highlight\r
-        *              Highlight to use (if any)\r
-        */\r
-       function showComments($template, $maxToShow = -1, $showNone = 1, $highlight = '') {\r
-               global $CONF, $manager;\r
-\r
-               // create parser object & action handler\r
-               $actions =& new COMMENTACTIONS($this);\r
-               $parser =& new PARSER($actions->getDefinedActions(),$actions);\r
-               $actions->setTemplate($template);\r
-               $actions->setParser($parser);\r
-\r
-               if ($maxToShow == 0) {\r
-                       $this->commentcount = $this->amountComments();\r
-               } else {\r
-                       $query =  'SELECT c.cnumber as commentid, c.cbody as body, c.cuser as user, c.cmail as userid, c.cmember as memberid, c.ctime, c.chost as host, c.cip as ip, c.cblog as blogid'\r
-                                  . ' FROM '.sql_table('comment').' as c'\r
-                                  . ' WHERE c.citem=' . $this->itemid\r
-                                  . ' ORDER BY c.ctime';\r
-\r
-                       $comments = sql_query($query);\r
-                       $this->commentcount = mysql_num_rows($comments);\r
-               }\r
-\r
-               // if no result was found\r
-               if ($this->commentcount == 0) {\r
-                       // note: when no reactions, COMMENTS_HEADER and COMMENTS_FOOTER are _NOT_ used\r
-                       if ($showNone) $parser->parse($template['COMMENTS_NONE']);\r
-                       return 0;\r
-               }\r
-\r
-               // if too many comments to show\r
-               if (($maxToShow != -1) && ($this->commentcount > $maxToShow)) {\r
-                       $parser->parse($template['COMMENTS_TOOMUCH']);\r
-                       return 0;\r
-               }\r
-\r
-               $parser->parse($template['COMMENTS_HEADER']);\r
-\r
-               while ( $comment = mysql_fetch_assoc($comments) ) {\r
-                       $comment['timestamp'] = strtotime($comment['ctime']);\r
-                       $actions->setCurrentComment($comment);\r
-                       $actions->setHighlight($highlight);\r
-                       $manager->notify('PreComment', array('comment' => &$comment));\r
-                       $parser->parse($template['COMMENTS_BODY']);\r
-                       $manager->notify('PostComment', array('comment' => &$comment));\r
-               }\r
-\r
-               $parser->parse($template['COMMENTS_FOOTER']);\r
-\r
-               mysql_free_result($comments);\r
-\r
-               return $this->commentcount;\r
-       }\r
-\r
-       /**\r
-        * Returns the amount of comments for this itemid\r
-        */\r
-       function amountComments() {\r
-               $query =  'SELECT COUNT(*)'\r
-                          . ' FROM '.sql_table('comment').' as c'\r
-                          . ' WHERE c.citem='. $this->itemid;\r
-               $res = sql_query($query);\r
-               $arr = mysql_fetch_row($res);\r
-\r
-               return $arr[0];\r
-       }\r
-\r
-\r
-       function addComment($timestamp, $comment) {\r
-               global $CONF, $member, $manager;\r
-\r
-               $blogid = getBlogIDFromItemID($this->itemid);\r
-\r
-               $settings =& $manager->getBlog($blogid);\r
-               $settings->readSettings();\r
-\r
-               if (!$settings->commentsEnabled())\r
-                       return _ERROR_COMMENTS_DISABLED;\r
-\r
-               if (!$settings->isPublic() && !$member->isLoggedIn())\r
-                       return _ERROR_COMMENTS_NONPUBLIC;\r
-\r
-               // member name protection\r
-               if ($CONF['ProtectMemNames'] && !$member->isLoggedIn() && MEMBER::isNameProtected($comment['user']))\r
-                       return _ERROR_COMMENTS_MEMBERNICK;\r
-\r
-               // isValidComment returns either "1" or an error message\r
-               $isvalid = $this->isValidComment($comment);\r
-               if ($isvalid != 1)\r
-                       return $isvalid;\r
-\r
-               $comment['timestamp'] = $timestamp;\r
-               $comment['host'] = gethostbyaddr(serverVar('REMOTE_ADDR'));\r
-               $comment['ip'] = serverVar('REMOTE_ADDR');\r
-\r
-               // if member is logged in, use that data\r
-               if ($member->isLoggedIn()) {\r
-                       $comment['memberid'] = $member->getID();\r
-                       $comment['user'] = '';\r
-                       $comment['userid'] = '';\r
-               } else {\r
-                       $comment['memberid'] = 0;\r
-               }\r
-\r
-\r
-               // send email to notification address, if any\r
-               if ($settings->getNotifyAddress() && $settings->notifyOnComment()) {\r
-\r
-                       $mailto_msg = _NOTIFY_NC_MSG . ' ' . $this->itemid . "\n";\r
-                       $mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $this->itemid . "\n\n";\r
-                       if ($comment['memberid'] == 0) {\r
-                               $mailto_msg .= _NOTIFY_USER . ' ' . $comment['user'] . "\n";\r
-                               $mailto_msg .= _NOTIFY_USERID . ' ' . $comment['userid'] . "\n";\r
-                       } else {\r
-                               $mailto_msg .= _NOTIFY_MEMBER .' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n";\r
-                       }\r
-                       $mailto_msg .= _NOTIFY_HOST . ' ' . $comment['host'] . "\n";\r
-                       $mailto_msg .= _NOTIFY_COMMENT . "\n " . $comment['body'] . "\n";\r
-                       $mailto_msg .= getMailFooter();\r
-\r
-                       $item =& $manager->getItem($this->itemid, 0, 0);\r
-                       $mailto_title = _NOTIFY_NC_TITLE . ' ' . strip_tags($item['title']) . ' (' . $this->itemid . ')';\r
-\r
-                       $frommail = $member->getNotifyFromMailAddress($comment['userid']);\r
-\r
-                       $notify =& new NOTIFICATION($settings->getNotifyAddress());\r
-                       $notify->notify($mailto_title, $mailto_msg , $frommail);\r
-               }\r
-\r
-               $comment = COMMENT::prepare($comment);\r
-\r
-               $manager->notify('PreAddComment',array('comment' => &$comment));\r
-\r
-               $name           = addslashes($comment['user']);\r
-               $url            = addslashes($comment['userid']);\r
-               $body           = addslashes($comment['body']);\r
-               $host           = addslashes($comment['host']);\r
-               $ip                     = addslashes($comment['ip']);\r
-               $memberid       = intval($comment['memberid']);\r
-               $timestamp      = date('Y-m-d H:i:s', $comment['timestamp']);\r
-               $itemid         = $this->itemid;\r
-\r
-               $query = 'INSERT INTO '.sql_table('comment').' (CUSER, CMAIL, CMEMBER, CBODY, CITEM, CTIME, CHOST, CIP, CBLOG) '\r
-                          . "VALUES ('$name', '$url', $memberid, '$body', $itemid, '$timestamp', '$host', '$ip', '$blogid')";\r
-\r
-               sql_query($query);\r
-\r
-               // post add comment\r
-               $commentid = mysql_insert_id();\r
-               $manager->notify('PostAddComment',array('comment' => &$comment, 'commentid' => &$commentid));\r
-\r
-               // succeeded !\r
-               return true;\r
-       }\r
-\r
-\r
-       function isValidComment($comment) {\r
-               global $member, $manager;\r
-\r
-               // check if there exists a item for this date\r
-               $item =& $manager->getItem($this->itemid,0,0);\r
-\r
-               if (!$item)\r
-                       return _ERROR_NOSUCHITEM;\r
-\r
-               if ($item['closed'])\r
-                       return _ERROR_ITEMCLOSED;\r
-\r
-               // don't allow words that are too long\r
-               if (eregi('[a-zA-Z0-9|\.,;:!\?=\/\\]{90,90}',$comment['body']) != false)\r
-                       return _ERROR_COMMENT_LONGWORD;\r
-\r
-               // check lengths of comment\r
-               if (strlen($comment['body'])<3)\r
-                       return _ERROR_COMMENT_NOCOMMENT;\r
-\r
-               if (strlen($comment['body'])>5000)\r
-                       return _ERROR_COMMENT_TOOLONG;\r
-\r
-               // only check username if no member logged in\r
-               if (!$member->isLoggedIn())\r
-                       if (strlen($comment['user'])<2)\r
-                               return _ERROR_COMMENT_NOUSERNAME;\r
-\r
-               // let plugins do verification (any plugin which thinks the comment is invalid\r
-               // can change 'error' to something other than '1')\r
-               $result = 1;\r
-               $manager->notify('ValidateForm', array('type' => 'comment', 'comment' => &$comment, 'error' => &$result));\r
-\r
-               return $result;\r
-       }\r
-\r
-\r
-}\r
-\r
-/**\r
-  * This class is used when parsing comment templates\r
-  */\r
-class COMMENTACTIONS extends BaseActions {\r
-\r
-       // ref to COMMENTS object which is using this object to handle\r
-       // its templatevars\r
-       var $commentsObj;\r
-\r
-       // template to use to parse the comments\r
-       var $template;\r
-\r
-       // comment currenlty being handled (mysql result assoc array; see COMMENTS::showComments())\r
-       var $currentComment;\r
-\r
-       function COMMENTACTIONS(&$comments) {\r
-               // call constructor of superclass first\r
-               $this->BaseActions();\r
-\r
-               // reference to the comments object\r
-               $this->setCommentsObj($comments);\r
-       }\r
-\r
-       function getDefinedActions() {\r
-               return array(\r
-                       'commentcount',\r
-                       'commentword',\r
-                       'itemlink',\r
-                       'itemid',\r
-                       'itemtitle',\r
-                       'date',\r
-                       'time',\r
-                       'commentid',\r
-                       'body',\r
-                       'memberid',\r
-                       'timestamp',\r
-                       'host',\r
-                       'ip',\r
-                       'blogid',\r
-                       'authtext',\r
-                       'user',\r
-                       'userid',\r
-                       'userlinkraw',\r
-                       'userlink',\r
-                       'short',\r
-                       'skinfile',\r
-                       'set',\r
-                       'plugin',\r
-                       'include',\r
-                       'phpinclude',\r
-                       'parsedinclude'\r
-               );\r
-       }\r
-\r
-       function setParser(&$parser) {                  $this->parser =& $parser; }\r
-       function setCommentsObj(&$commentsObj) {$this->commentsObj =& $commentsObj; }\r
-       function setTemplate($template) {               $this->template =& $template; }\r
-       function setCurrentComment(&$comment) {\r
-               if ($comment['memberid'] != 0) {\r
-                       $comment['authtext'] = $template['COMMENTS_AUTH'];\r
-\r
-                       $mem = MEMBER::createFromID($comment['memberid']);\r
-                       $comment['user'] = $mem->getDisplayName();\r
-                       if ($mem->getURL())\r
-                               $comment['userid'] = $mem->getURL();\r
-                       else\r
-                               $comment['userid'] = $mem->getEmail();\r
-\r
-                       $comment['userlinkraw'] = createMemberLink(\r
-                                                                               $comment['memberid'],\r
-                                                                               $this->commentsObj->itemActions->linkparams\r
-                                                                         );\r
-\r
-               } else {\r
-\r
-                       // create smart links\r
-                       if (isValidMailAddress($comment['userid']))\r
-                               $comment['userlinkraw'] = 'mailto:'.$comment['userid'];\r
-                       elseif (strstr($comment['userid'],'http://') != false)\r
-                               $comment['userlinkraw'] = $comment['userid'];\r
-                       elseif (strstr($comment['userid'],'www') != false)\r
-                               $comment['userlinkraw'] = 'http://'.$comment['userid'];\r
-               }\r
-\r
-               $this->currentComment =& $comment;\r
-       }\r
-\r
-       function parse_commentcount() {                 echo $this->commentsObj->commentcount; }\r
-       function parse_commentword() {\r
-               if ($this->commentsObj->commentcount == 1)\r
-                       echo $this->template['COMMENTS_ONE'];\r
-               else\r
-                       echo $this->template['COMMENTS_MANY'];\r
-       }\r
-\r
-       function parse_itemlink() {                             echo createItemLink($this->commentsObj->itemid, $this->commentsObj->itemActions->linkparams); }\r
-       function parse_itemid() {                               echo $this->commentsObj->itemid; }\r
-       function parse_itemtitle($maxLength = 0) {\r
-               if ($maxLength == 0)\r
-                       $this->commentsObj->itemActions->parse_title();\r
-               else\r
-                       $this->commentsObj->itemActions->parse_syndicate_title($maxLength);\r
-       }\r
-\r
-       function parse_date($format = '') {\r
-               echo formatDate($format, $this->currentComment['timestamp'], $this->template['FORMAT_DATE']);\r
-       }\r
-       function parse_time($format = '') {\r
-               echo strftime(\r
-                               ($format == '') ? $this->template['FORMAT_TIME'] : $format,\r
-                               $this->currentComment['timestamp']\r
-                       );\r
-       }\r
-\r
-       function parse_commentid() {                    echo $this->currentComment['commentid']; }\r
-       function parse_body() {                                 echo $this->highlight($this->currentComment['body']); }\r
-       function parse_memberid() {                             echo $this->currentComment['memberid']; }\r
-       function parse_timestamp() {                    echo $this->currentComment['timestamp']; }\r
-       function parse_host() {                                 echo $this->currentComment['host']; }\r
-       function parse_ip() {                                   echo $this->currentComment['ip']; }\r
-       function parse_blogid() {                               echo $this->currentComment['blogid']; }\r
-\r
-       function parse_user() {                                 echo $this->currentComment['user']; }\r
-       function parse_userid() {                               echo $this->currentComment['userid']; }\r
-       function parse_userlinkraw() {                  echo $this->currentComment['userlinkraw']; }\r
-       function parse_userlink() {\r
-               if ($this->currentComment['userlinkraw']) {\r
-                       echo '<a href="'.$this->currentComment['userlinkraw'].'" rel="nofollow">'.$this->currentComment['user'].'</a>';\r
-               } else {\r
-                       echo $this->currentComment['user'];\r
-               }\r
-       }\r
-       function parse_short() {\r
-               $tmp = strtok($this->currentComment['body'],"\n");\r
-               $tmp = str_replace('<br />','',$tmp);\r
-               echo $tmp;\r
-               if ($tmp != $this->currentComment['body'])\r
-                       $this->parser->parse($this->template['COMMENTS_CONTINUED']);\r
-       }\r
-       function parse_authtext() {\r
-               if ($this->currentComment['memberid'] != 0)\r
-                       $this->parser->parse($this->template['COMMENTS_AUTH']);\r
-       }\r
-\r
-       /**\r
-         * Executes a plugin templatevar\r
-         *\r
-         * @param pluginName name of plugin (without the NP_)\r
-         *\r
-         * extra parameters can be added\r
-         */\r
-       function parse_plugin($pluginName) {\r
-               global $manager;\r
-\r
-               // only continue when the plugin is really installed\r
-               if (!$manager->pluginInstalled('NP_' . $pluginName))\r
-                       return;\r
-\r
-               $plugin =& $manager->getPlugin('NP_' . $pluginName);\r
-               if (!$plugin) return;\r
-\r
-               // get arguments\r
-               $params = func_get_args();\r
-\r
-               // remove plugin name\r
-               array_shift($params);\r
-\r
-               // pass info on current item and current comment as well\r
-               $params = array_merge(array(&$this->currentComment),$params);\r
-               $params = array_merge(array(&$this->commentsObj->itemActions->currentItem),$params);\r
-\r
-               call_user_func_array(array(&$plugin,'doTemplateCommentsVar'), $params);\r
-       }\r
-}\r
-\r
-?>\r
+<?php
+
+/*
+ * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
+ * Copyright (C) 2002-2007 The Nucleus Group
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * (see nucleus/documentation/index.html#license for more info)
+ */
+/**
+ * A class representing the comments (all of them) for a certain post on a ceratin blog
+ *
+ * @license http://nucleuscms.org/license.txt GNU General Public License
+ * @copyright Copyright (C) 2002-2007 The Nucleus Group
+ * @version $Id: COMMENTS.php,v 1.10 2008-02-08 09:31:22 kimitake Exp $
+ * $NucleusJP: COMMENTS.php,v 1.9.2.1 2007/08/08 05:32:21 kimitake Exp $
+ */
+
+if ( !function_exists('requestVar') ) exit;
+require_once dirname(__FILE__) . '/COMMENTACTIONS.php';
+
+class COMMENTS {
+
+       // item for which comment are being displayed
+       var $itemid;
+
+       // reference to the itemActions object that is calling the showComments function
+       var $itemActions;
+
+       // total amount of comments displayed
+       var $commentcount;
+
+       /**
+        * Creates a new COMMENTS object for the given blog and item
+        *
+        * @param $itemid
+        *              id of the item
+        */
+       function COMMENTS($itemid) {
+               $this->itemid = intval($itemid);
+       }
+       /**
+        * Used when parsing comments
+        *
+        * @param $itemActions
+        *              itemActions object, that will take care of the parsing
+        */
+       function setItemActions(&$itemActions) {
+               $this->itemActions =& $itemActions;
+       }
+
+       /**
+        * Shows maximum $max comments to the given item using the given template
+        * returns the amount of shown comments (if maxToShow = -1, then there is no limit)
+        *
+        * @param template
+        *              template to use
+        * @param maxToShow
+        *              max. comments to show
+        * @param showNone
+        *              indicates if the 'no comments' thingie should be outputted when there are no comments
+        *              (useful for closed items)
+        * @param highlight
+        *              Highlight to use (if any)
+        */
+       function showComments($template, $maxToShow = -1, $showNone = 1, $highlight = '') {
+               global $CONF, $manager;
+
+               // create parser object & action handler
+               $actions =& new COMMENTACTIONS($this);
+               $parser =& new PARSER($actions->getDefinedActions(),$actions);
+               $actions->setTemplate($template);
+               $actions->setParser($parser);
+
+               if ($maxToShow == 0) {
+                       $this->commentcount = $this->amountComments();
+               } else {
+                       $query =  'SELECT c.citem as itemid, c.cnumber as commentid, c.cbody as body, c.cuser as user, c.cmail as userid, c.cemail as email, c.cmember as memberid, c.ctime, c.chost as host, c.cip as ip, c.cblog as blogid'
+                                  . ' FROM '.sql_table('comment').' as c'
+                                  . ' WHERE c.citem=' . $this->itemid
+                                  . ' ORDER BY c.ctime';
+
+                       $comments = sql_query($query);
+                       $this->commentcount = mysql_num_rows($comments);
+               }
+
+               // if no result was found
+               if ($this->commentcount == 0) {
+                       // note: when no reactions, COMMENTS_HEADER and COMMENTS_FOOTER are _NOT_ used
+                       if ($showNone) $parser->parse($template['COMMENTS_NONE']);
+                       return 0;
+               }
+
+               // if too many comments to show
+               if (($maxToShow != -1) && ($this->commentcount > $maxToShow)) {
+                       $parser->parse($template['COMMENTS_TOOMUCH']);
+                       return 0;
+               }
+
+               $parser->parse($template['COMMENTS_HEADER']);
+
+               while ( $comment = mysql_fetch_assoc($comments) ) {
+                       $comment['timestamp'] = strtotime($comment['ctime']);
+                       $actions->setCurrentComment($comment);
+                       $actions->setHighlight($highlight);
+                       $manager->notify('PreComment', array('comment' => &$comment));
+                       $parser->parse($template['COMMENTS_BODY']);
+                       $manager->notify('PostComment', array('comment' => &$comment));
+               }
+
+               $parser->parse($template['COMMENTS_FOOTER']);
+
+               mysql_free_result($comments);
+
+               return $this->commentcount;
+       }
+
+       /**
+        * Returns the amount of comments for this itemid
+        */
+       function amountComments() {
+               $query =  'SELECT COUNT(*)'
+                          . ' FROM '.sql_table('comment').' as c'
+                          . ' WHERE c.citem='. $this->itemid;
+               $res = sql_query($query);
+               $arr = mysql_fetch_row($res);
+
+               return $arr[0];
+       }
+
+
+       function addComment($timestamp, $comment) {
+               global $CONF, $member, $manager;
+
+               $blogid = getBlogIDFromItemID($this->itemid);
+
+               $settings =& $manager->getBlog($blogid);
+               $settings->readSettings();
+
+               if (!$settings->commentsEnabled())
+                       return _ERROR_COMMENTS_DISABLED;
+
+               if (!$settings->isPublic() && !$member->isLoggedIn())
+                       return _ERROR_COMMENTS_NONPUBLIC;
+
+               // member name protection
+               if ($CONF['ProtectMemNames'] && !$member->isLoggedIn() && MEMBER::isNameProtected($comment['user']))
+                       return _ERROR_COMMENTS_MEMBERNICK;
+
+               // email required protection
+               if ($settings->emailRequired() && strlen($comment['email']) == 0 && !$member->isLoggedIn()) {
+                       return _ERROR_EMAIL_REQUIRED;
+               }
+
+               $comment['timestamp'] = $timestamp;
+               $comment['host'] = gethostbyaddr(serverVar('REMOTE_ADDR'));
+               $comment['ip'] = serverVar('REMOTE_ADDR');
+
+               // if member is logged in, use that data
+               if ($member->isLoggedIn()) {
+                       $comment['memberid'] = $member->getID();
+                       $comment['user'] = '';
+                       $comment['userid'] = '';
+                       $comment['email'] = '';
+               } else {
+                       $comment['memberid'] = 0;
+               }
+
+               // spam check
+               $continue = false;
+               $plugins = array();
+
+               if (isset($manager->subscriptions['ValidateForm']))
+                       $plugins = array_merge($plugins, $manager->subscriptions['ValidateForm']);
+
+               if (isset($manager->subscriptions['PreAddComment']))
+                       $plugins = array_merge($plugins, $manager->subscriptions['PreAddComment']);
+
+               if (isset($manager->subscriptions['PostAddComment']))
+                       $plugins = array_merge($plugins, $manager->subscriptions['PostAddComment']);
+
+               $plugins = array_unique($plugins);
+
+               while (list(,$plugin) = each($plugins)) {
+                       $p = $manager->getPlugin($plugin);
+                       $continue = $continue || $p->supportsFeature('handleSpam');
+               }
+
+               $spamcheck = array (
+                       'type'          => 'comment',
+                       'body'          => $comment['body'],
+                       'id'        => $comment['itemid'],
+                       'live'          => true,
+                       'return'        => $continue
+               );
+
+               if ($member->isLoggedIn()) {
+                       $spamcheck['author'] = $member->displayname;
+                       $spamcheck['email'] = $member->email;
+               } else {
+                       $spamcheck['author'] = $comment['user'];
+                       $spamcheck['email'] = $comment['email'];
+                       $spamcheck['url'] = $comment['userid'];
+               }
+
+               $manager->notify('SpamCheck', array ('spamcheck' => &$spamcheck));
+
+               if (!$continue && isset($spamcheck['result']) && $spamcheck['result'] == true)
+                       return _ERROR_COMMENTS_SPAM;
+
+
+               // isValidComment returns either "1" or an error message
+               $isvalid = $this->isValidComment($comment, $spamcheck);
+               if ($isvalid != 1)
+                       return $isvalid;
+
+               // send email to notification address, if any
+               if ($settings->getNotifyAddress() && $settings->notifyOnComment()) {
+
+                       $mailto_msg = _NOTIFY_NC_MSG . ' ' . $this->itemid . "\n";
+//                     $mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $this->itemid . "\n\n";
+                       $temp = parse_url($CONF['Self']);
+                       if ($temp['scheme']) {
+                               $mailto_msg .= createItemLink($this->itemid) . "\n\n";
+                       } else {
+                               $tempurl = $settings->getURL();
+                               if (substr($tempurl, -1) == '/' || substr($tempurl, -4) == '.php') {
+                                       $mailto_msg .= $tempurl . '?itemid=' . $this->itemid . "\n\n";
+                               } else {
+                                       $mailto_msg .= $tempurl . '/?itemid=' . $this->itemid . "\n\n";
+                               }
+                       }
+                       if ($comment['memberid'] == 0) {
+                               $mailto_msg .= _NOTIFY_USER . ' ' . $comment['user'] . "\n";
+                               $mailto_msg .= _NOTIFY_USERID . ' ' . $comment['userid'] . "\n";
+                       } else {
+                               $mailto_msg .= _NOTIFY_MEMBER .' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n";
+                       }
+                       $mailto_msg .= _NOTIFY_HOST . ' ' . $comment['host'] . "\n";
+                       $mailto_msg .= _NOTIFY_COMMENT . "\n " . $comment['body'] . "\n";
+                       $mailto_msg .= getMailFooter();
+
+                       $item =& $manager->getItem($this->itemid, 0, 0);
+                       $mailto_title = _NOTIFY_NC_TITLE . ' ' . strip_tags($item['title']) . ' (' . $this->itemid . ')';
+
+                       $frommail = $member->getNotifyFromMailAddress($comment['userid']);
+
+                       $notify =& new NOTIFICATION($settings->getNotifyAddress());
+                       $notify->notify($mailto_title, $mailto_msg , $frommail);
+               }
+
+               $comment = COMMENT::prepare($comment);
+
+               $manager->notify('PreAddComment',array('comment' => &$comment, 'spamcheck' => &$spamcheck));
+
+               $name           = addslashes($comment['user']);
+               $url            = addslashes($comment['userid']);
+               $email      = addslashes($comment['email']);
+               $body           = addslashes($comment['body']);
+               $host           = addslashes($comment['host']);
+               $ip                     = addslashes($comment['ip']);
+               $memberid       = intval($comment['memberid']);
+               $timestamp      = date('Y-m-d H:i:s', $comment['timestamp']);
+               $itemid         = $this->itemid;
+
+               $query = 'INSERT INTO '.sql_table('comment').' (CUSER, CMAIL, CEMAIL, CMEMBER, CBODY, CITEM, CTIME, CHOST, CIP, CBLOG) '
+                          . "VALUES ('$name', '$url', '$email', $memberid, '$body', $itemid, '$timestamp', '$host', '$ip', '$blogid')";
+
+               sql_query($query);
+
+               // post add comment
+               $commentid = mysql_insert_id();
+               $manager->notify('PostAddComment',array('comment' => &$comment, 'commentid' => &$commentid, 'spamcheck' => &$spamcheck));
+
+               // succeeded !
+               return true;
+       }
+
+
+       function isValidComment($comment, & $spamcheck) {
+               global $member, $manager;
+
+               // check if there exists a item for this date
+               $item =& $manager->getItem($this->itemid,0,0);
+
+               if (!$item)
+                       return _ERROR_NOSUCHITEM;
+
+               if ($item['closed'])
+                       return _ERROR_ITEMCLOSED;
+
+               // don't allow words that are too long
+               if (eregi('[a-zA-Z0-9|\.,;:!\?=\/\\]{90,90}',$comment['body']) != false)
+                       return _ERROR_COMMENT_LONGWORD;
+
+               // check lengths of comment
+               if (strlen($comment['body'])<3)
+                       return _ERROR_COMMENT_NOCOMMENT;
+
+               if (strlen($comment['body'])>5000)
+                       return _ERROR_COMMENT_TOOLONG;
+
+               // only check username if no member logged in
+               if (!$member->isLoggedIn())
+                       if (strlen($comment['user'])<2)
+                               return _ERROR_COMMENT_NOUSERNAME;
+
+               if ((strlen($comment['email']) != 0) && !(isValidMailAddress($comment['email']))) {
+                       return _ERROR_BADMAILADDRESS;
+               }
+
+               // let plugins do verification (any plugin which thinks the comment is invalid
+               // can change 'error' to something other than '1')
+               $result = 1;
+               $manager->notify('ValidateForm', array('type' => 'comment', 'comment' => &$comment, 'error' => &$result, 'spamcheck' => &$spamcheck));
+
+               return $result;
+       }
+
+}
+
+?>