function reportComment() { if (JCommentsSecurity::badRequest() == 1) { JCommentsSecurity::notAuth(); } $acl =& JCommentsFactory::getACL(); $db =& JCommentsFactory::getDBO(); $config =& JCommentsFactory::getConfig(); $response =& JCommentsFactory::getAjaxResponse(); $values = JCommentsAJAX::prepareValues($_POST); $id = (int) $values['commentid']; $reason = trim(strip_tags($values['reason'])); $name = trim(strip_tags($values['name'])); $ip = $acl->getUserIP(); if ($reason == '') { JCommentsAJAX::showErrorMessage(JText::_('Please enter the reason for your report!'), '', 'comments-report-form'); return $response; } $query = 'SELECT COUNT(*) FROM `#__jcomments_reports` WHERE commentid = ' . $id; if ($acl->getUserId()) { $query .= ' AND userid = ' . $acl->getUserId(); } else { $query .= ' AND ip = "' . $ip . '"'; } $db->setQuery($query); $reported = $db->loadResult(); if (!$reported) { $query = 'SELECT COUNT(*) FROM `#__jcomments_reports` WHERE commentid = ' . $id; $db->setQuery($query); $reported = $db->loadResult(); if (!$reported) { $comment = new JCommentsDB($db); if ($comment->load($id)) { if ($acl->canReport($comment)) { $allowed = true; if ($config->getInt('enable_mambots') == 1) { require_once JCOMMENTS_HELPERS . DS . 'plugin.php'; JCommentsPluginHelper::importPlugin('jcomments'); JCommentsPluginHelper::trigger('onReportComment', array(&$comment, &$response, &$allowed, &$value)); } if ($allowed !== false) { if ($acl->getUserId()) { $user = JCommentsFactory::getUser(); $name = $user->name; } else { if ($name == '') { $name = JText::_('Guest'); } } $query = "INSERT INTO `#__jcomments_reports`(`commentid`,`userid`, `name`,`ip`,`date`,`reason`)" . "VALUES('" . $comment->id . "', '" . $acl->getUserId() . "', '" . $db->getEscaped($name) . "', '" . $db->getEscaped($ip) . "', now(), '" . $db->getEscaped($reason) . "')"; $db->setQuery($query); $db->query(); if ($config->getInt('enable_notification') == 1) { if ($config->check('notification_type', 2)) { $comment->datetime = $comment->date; if (is_string($comment->datetime)) { $comment->datetime = strtotime($comment->datetime); } JComments::sendReport($comment, $name, $reason); } } $html = JText::_('Report successfully sent!'); $html = str_replace("\n", '\\n', $html); $html = str_replace('\\n', '<br />', $html); $html = JCommentsText::jsEscape($html); $response->addScript("jcomments.closeReport('{$html}');"); } } else { JCommentsAJAX::showErrorMessage(JText::_('You have no rights to report comment!'), '', 'comments-report-form'); } } else { $response->addAlert(JText::_('ERROR_NOT_FOUND')); } unset($comment); } else { JCommentsAJAX::showErrorMessage(JText::_('Comment already reported to the site administrator'), '', 'comments-report-form'); } } else { JCommentsAJAX::showErrorMessage(JText::_('You can\'t report the same comment more than once!'), '', 'comments-report-form'); } return $response; }
public static function reportComment() { if (JCommentsSecurity::badRequest() == 1) { JCommentsSecurity::notAuth(); } $acl = JCommentsFactory::getACL(); $db = JCommentsFactory::getDBO(); $config = JCommentsFactory::getConfig(); $response = JCommentsFactory::getAjaxResponse(); $values = self::prepareValues($_POST); $id = (int) $values['commentid']; $reason = trim(strip_tags($values['reason'])); $name = trim(strip_tags($values['name'])); $ip = $acl->getUserIP(); if (empty($reason)) { if ($config->getInt('report_reason_required') == 1) { self::showErrorMessage(JText::_('ERROR_NO_REASON_FOR_REPORT'), '', 'comments-report-form'); return $response; } else { $reason = JText::_('REPORT_REASON_UNKNOWN_REASON'); } } $query = 'SELECT COUNT(*) FROM `#__jcomments_reports` WHERE commentid = ' . $id; if ($acl->getUserId()) { $query .= ' AND userid = ' . $acl->getUserId(); } else { $query .= ' AND userid = 0 AND ip = "' . $ip . '"'; } $db->setQuery($query); $reported = $db->loadResult(); if (!$reported) { $maxReportsPerComment = $config->getInt('reports_per_comment', 1); $maxReportsBeforeUnpublish = $config->getInt('reports_before_unpublish', 0); $db->setQuery('SELECT COUNT(*) FROM `#__jcomments_reports` WHERE commentid = ' . $id); $reported = $db->loadResult(); if ($reported < $maxReportsPerComment || $maxReportsPerComment == 0) { $comment = new JCommentsTableComment($db); if ($comment->load($id)) { if ($acl->canReport($comment)) { if ($acl->getUserId()) { $user = JCommentsFactory::getUser(); $name = $user->name; } else { if (empty($name)) { $name = 'Guest'; // JText::_('Guest'); } } require_once JCOMMENTS_TABLES . '/report.php'; $report = new JCommentsTableReport($db); $report->commentid = $comment->id; $report->date = JCommentsFactory::getDate(); $report->userid = $acl->getUserId(); $report->ip = $ip; $report->name = $name; $report->reason = $reason; $html = ''; $result = JCommentsEvent::trigger('onJCommentsCommentBeforeReport', array(&$comment, &$report)); if (!in_array(false, $result, true)) { if ($report->store()) { JCommentsEvent::trigger('onJCommentsCommentAfterReport', array(&$comment, $report)); if ($config->getInt('enable_notification') == 1) { if ($config->check('notification_type', 2)) { JComments::sendReport($comment, $name, $reason); } } // unpublish comment if reports count is enough if ($maxReportsBeforeUnpublish > 0 && $reported >= $maxReportsBeforeUnpublish) { $comment->published = 0; $comment->store(); } $html = JText::_('REPORT_SUCCESSFULLY_SENT'); $html = str_replace("\n", '\\n', $html); $html = str_replace('\\n', '<br />', $html); $html = JCommentsText::jsEscape($html); } } $response->addScript("jcomments.closeReport('{$html}');"); } else { self::showErrorMessage(JText::_('ERROR_YOU_HAVE_NO_RIGHTS_TO_REPORT'), '', 'comments-report-form'); } } else { $response->addAlert(JText::_('ERROR_NOT_FOUND')); } } else { self::showErrorMessage(JText::_('ERROR_COMMENT_ALREADY_REPORTED'), '', 'comments-report-form'); } } else { self::showErrorMessage(JText::_('ERROR_YOU_CAN_NOT_REPORT_THE_SAME_COMMENT_MORE_THAN_ONCE'), '', 'comments-report-form'); } return $response; }