function post_new_comment($objectId, $parentId, $userName, $title, $data, &$message_id, $in_reply_to = '', $type = 'n', $summary = '', $smiley = '') { if (!$userName) { $_SESSION["lastPost"] = date("U"); } if (!isset($_SERVER['REMOTE_ADDR'])) { $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; } // Check for banned userName or banned IP or IP in banned range // Check for duplicates. $title = strip_tags($title); if (!$userName) { $userName = tra('Anonymous'); } else { $now = (int) date("U"); if ($this->getOne("select count(*) from \n\t\t\t`tiki_user_postings` where `user`=?", array($userName), false)) { $query = "update `tiki_user_postings` " . "set `last`=?, `posts` = `posts` + 1 where `user`=?"; $this->query($query, array($now, $userName)); } else { $posts = $this->getOne("select count(*) " . "from `tiki_comments` where `userName`=?", array($userName), false); if (!$posts) { $posts = 1; } $query = "insert into \n\t\t `tiki_user_postings`(`user`,`first`,`last`,`posts`) \n\t\t values( ?, ?, ?, ? )"; $this->query($query, array($userName, (int) $now, (int) $now, (int) $posts)); } // Calculate max $max = $this->getOne("select max(`posts`) from `tiki_user_postings`", array()); $min = $this->getOne("select min(`posts`) from `tiki_user_postings`", array()); if ($min == 0) { $min = 1; } $ids = $this->getOne("select count(*) from `tiki_user_postings`", array()); $tot = $this->getOne("select sum(`posts`) from `tiki_user_postings`", array()); $average = $tot / $ids; $range1 = ($min + $average) / 2; $range2 = ($max + $average) / 2; $posts = $this->getOne("select `posts` " . "from `tiki_user_postings` where `user`=?", array($userName), false); if ($posts == $max) { $level = 5; } elseif ($posts > $range2) { $level = 4; } elseif ($posts > $average) { $level = 3; } elseif ($posts > $range1) { $level = 2; } else { $level = 1; } $query = "update `tiki_user_postings` " . "set `level`=? where `user`=?"; $this->query($query, array($level, $userName)); } $hash = md5($title . $data); $query = "select `threadId` from `tiki_comments` where `hash`=?"; $result = $this->query($query, array($hash)); // print( "<pre>result:" ); // print_r( $result ); // print( "</pre>" ); // Check if we were passed a message-id. if (!$message_id) { // Construct a message id via proctological // extraction. -rlpowell $message_id = $userName . "-" . $parentId . "-" . substr($hash, 0, 10) . "@" . $_SERVER["SERVER_NAME"]; } // If this post was not already found. if (!$result->numRows()) { $now = (int) date("U"); // Break out the type and object parameters. $object = explode(":", $objectId, 2); $query = "insert into\n\t\t`tiki_comments`(`objectType`, `object`,\n\t\t\t`commentDate`, `userName`, `title`, `data`, `votes`,\n\t\t\t`points`, `hash`, `parentId`, `average`, `hits`,\n\t\t\t`type`, `summary`, `smiley`, `user_ip`,\n\t\t\t`message_id`, `in_reply_to`)\n\t\tvalues ( ?, ?, ?, ?, ?, ?,\n\t\t\t0, 0, ?, ?, 0, 0, ?, ?, \n\t\t\t?, ?, ?, ?)"; $result = $this->query($query, array($object[0], (string) $object[1], (int) $now, $userName, $title, $data, $hash, (int) $parentId, $type, $summary, $smiley, $_SERVER["REMOTE_ADDR"], $message_id, $in_reply_to)); } $threadId = $this->getOne("select `threadId` from\n\t\t`tiki_comments` where `hash`=?", array($hash)); /* Force an index refresh of the data */ include_once "lib/search/refresh-functions.php"; refresh_index_comments($threadId); return $threadId; //return $return_result; }
function post_new_comment($objectId, $parentId, $userName, $title, $data, &$message_id, $in_reply_to = '', $type = 'n', $summary = '', $smiley = '', $contributions = '', $anonymous_name = '') { if (!$userName) { $_SESSION["lastPost"] = $this->now; } if (!isset($_SERVER['REMOTE_ADDR'])) { $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; } // Check for banned userName or banned IP or IP in banned range // Check for duplicates. $title = strip_tags($title); if (!$userName) { if ($anonymous_name) { $userName = $anonymous_name . ' ' . tra('(not registered)'); } else { $userName = tra('Anonymous'); } } else { if ($this->getOne("select count(*) from \n\t\t\t`tiki_user_postings` where `user`=?", array($userName), false)) { $query = "update `tiki_user_postings` " . "set `last`=?, `posts` = `posts` + 1 where `user`=?"; $this->query($query, array((int) $this->now, $userName)); } else { $posts = $this->getOne("select count(*) " . "from `tiki_comments` where `userName`=?", array($userName), false); if (!$posts) { $posts = 1; } $query = "insert into \n\t\t `tiki_user_postings`(`user`,`first`,`last`,`posts`) \n\t\t values( ?, ?, ?, ? )"; $this->query($query, array($userName, (int) $this->now, (int) $this->now, (int) $posts)); } // Calculate max $max = $this->getOne("select max(`posts`) from `tiki_user_postings`", array()); $min = $this->getOne("select min(`posts`) from `tiki_user_postings`", array()); if ($min == 0) { $min = 1; } $ids = $this->getOne("select count(*) from `tiki_user_postings`", array()); $tot = $this->getOne("select sum(`posts`) from `tiki_user_postings`", array()); $average = $tot / $ids; $range1 = ($min + $average) / 2; $range2 = ($max + $average) / 2; $posts = $this->getOne("select `posts` " . "from `tiki_user_postings` where `user`=?", array($userName), false); if ($posts == $max) { $level = 5; } elseif ($posts > $range2) { $level = 4; } elseif ($posts > $average) { $level = 3; } elseif ($posts > $range1) { $level = 2; } else { $level = 1; } $query = "update `tiki_user_postings` " . "set `level`=? where `user`=?"; $this->query($query, array($level, $userName)); } $hash = md5($title . $data); $query = "select `threadId` from `tiki_comments` where `hash`=?"; $result = $this->query($query, array($hash)); // print( "<pre>result:" ); // print_r( $result ); // print( "</pre>" ); // Check if we were passed a message-id. if (!$message_id) { // Construct a message id via proctological // extraction. -rlpowell $message_id = $userName . "-" . $parentId . "-" . substr($hash, 0, 10) . "@" . $_SERVER["SERVER_NAME"]; } // Break out the type and object parameters. $object = explode(":", $objectId, 2); // If this post was not already found. if (!$result->numRows()) { $query = "insert into\n\t\t`tiki_comments`(`objectType`, `object`,\n\t\t\t`commentDate`, `userName`, `title`, `data`, `votes`,\n\t\t\t`points`, `hash`, `parentId`, `average`, `hits`,\n\t\t\t`type`, `summary`, `smiley`, `user_ip`,\n\t\t\t`message_id`, `in_reply_to`)\n\t\tvalues ( ?, ?, ?, ?, ?, ?,\n\t\t\t0, 0, ?, ?, 0, 0, ?, ?, \n\t\t\t?, ?, ?, ?)"; $result = $this->query($query, array($object[0], (string) $object[1], (int) $this->now, $userName, $title, $data, $hash, (int) $parentId, $type, $summary, $smiley, $_SERVER["REMOTE_ADDR"], $message_id, (string) $in_reply_to)); } $threadId = $this->getOne("select `threadId` from\n\t\t`tiki_comments` where `hash`=?", array($hash)); /* Force an index refresh of the data */ include_once "lib/search/refresh-functions.php"; refresh_index_comments($threadId); global $prefs; if ($prefs['feature_actionlog'] == 'y') { global $logslib; include_once 'lib/logs/logslib.php'; global $tikilib; if ($parentId == 0) { $l = strlen($data); } else { $l = $tikilib->strlen_quoted($data); } if ($object[0] == 'forum') { $logslib->add_action($parentId == 0 ? 'Posted' : 'Replied', $object[1], $object[0], 'comments_parentId=' . $threadId . '&add=' . $l, '', '', '', '', $contributions); } else { $logslib->add_action($parentId == 0 ? 'Posted' : 'Replied', $object[1], 'comment', 'type=' . $object[0] . '&add=' . $l . '#threadId' . $threadId, '', '', '', '', $contributions); } } if ($prefs['feature_contribution'] == 'y') { global $contributionlib; include_once 'lib/contribution/contributionlib.php'; $contributionlib->assign_contributions($contributions, $threadId, 'comment', $title, '', ''); } if ($prefs['feature_search'] == 'y' && $prefs['feature_search_fulltext'] != 'y' && $prefs['search_refresh_index_mode'] == 'normal') { require_once 'lib/search/refresh-functions.php'; refresh_index('comments', $threadId); } $this->update_comment_links($data, $object[0], $threadId); return $threadId; //return $return_result; }