public function onQuestionPost(iUmiEventPoint $event)
 {
     if ($event->getMode() == 'after') {
         $questionId = $event->getParam('element_id');
         antiSpamHelper::checkForSpam($questionId, 'question');
     }
 }
 /**
  *
  */
 public function onCommentAdded(iUmiEventPoint $event)
 {
     $commentId = $event->getParam('id');
     antiSpamHelper::checkForSpam($commentId);
 }
Example #3
0
 public function message_post_do()
 {
     if ($users_inst = cmsController::getInstance()->getModule("users")) {
         if (!$users_inst->is_auth()) {
             if (!regedit::getInstance()->getVal("//modules/forum/allow_guest")) {
                 return "%forum_not_allowed_post%";
             }
         }
     }
     $title = getRequest('title');
     $body = getRequest('body');
     $title = htmlspecialchars($title);
     $body = htmlspecialchars($body);
     $nickname = htmlspecialchars(getRequest('nickname'));
     $email = htmlspecialchars(getRequest('email'));
     $ip = getServer('REMOTE_ADDR');
     $publish_time = new umiDate(time());
     $parent_id = (int) getRequest('param0');
     $parent_element = umiHierarchy::getInstance()->getElement($parent_id, true);
     if (!strlen(trim($title)) && $parent_element instanceof umiHierarchyElement) {
         $title = "Re: " . $parent_element->getName();
     }
     // check captcha
     $referer_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/';
     if (isset($_REQUEST['captcha'])) {
         $_SESSION['user_captcha'] = md5((int) getRequest('captcha'));
     }
     if (!umiCaptcha::checkCaptcha() || !$parent_element) {
         $this->errorNewMessage('%errors_wrong_captcha%', false);
         $this->errorPanic();
     }
     if (!strlen(trim($body))) {
         $this->errorNewMessage('%error_message_empty%', false);
         $this->errorPanic();
     }
     $lang_id = cmsController::getInstance()->getCurrentLang()->getId();
     $domain_id = cmsController::getInstance()->getCurrentDomain()->getId();
     $tpl_id = $parent_element->getTplId();
     $hierarchy_type_id = umiHierarchyTypesCollection::getInstance()->getTypeByName("forum", "message")->getId();
     $object_type_id = umiObjectTypesCollection::getInstance()->getBaseType("forum", "message");
     $is_supervisor = false;
     if ($users_inst = cmsController::getInstance()->getModule("users")) {
         if ($users_inst->is_auth()) {
             $user_id = $users_inst->user_id;
             $author_id = $users_inst->createAuthorUser($user_id);
             $is_supervisor = $users_inst->isSv($user_id);
         } else {
             $author_id = $users_inst->createAuthorGuest($nickname, $email, $ip);
         }
         $author = umiObjectsCollection::getInstance()->getObject($author_id);
         $author->commit();
     }
     $element_id = umiHierarchy::getInstance()->addElement($parent_id, $hierarchy_type_id, $title, $title, $object_type_id, $domain_id, $lang_id, $tpl_id);
     permissionsCollection::getInstance()->setDefaultPermissions($element_id);
     $element = umiHierarchy::getInstance()->getElement($element_id, true);
     $element->setIsVisible(false);
     $bNeedModerate = !$is_supervisor && regedit::getInstance()->getVal("//modules/forum/need_moder");
     if (!$bNeedModerate) {
         $bNeedModerate = !antiSpamHelper::checkContent($body . $title . $nickname . $email);
     }
     $element->setIsActive(!$bNeedModerate);
     $element->setAltName($title);
     $element->getObject()->setName($title);
     $element->setValue("meta_descriptions", "");
     $element->setValue("meta_keywords", "");
     $element->setValue("h1", $title);
     $element->setValue("title", $title);
     $element->setValue("is_expanded", false);
     $element->setValue("show_submenu", false);
     $element->setValue("message", $body);
     $element->setValue("author_id", $author_id);
     $element->setValue("publish_time", $publish_time);
     if ($headers = umiFile::upload("pics", "headers", "./images/cms/headers/")) {
         $element->setValue("header_pic", $headers);
     }
     $object_id = $element->getObject()->getId();
     $data_module = cmsController::getInstance()->getModule('data');
     $data_module->saveEditedObject($object_id, true);
     $element->commit();
     if (!defined("DISABLE_SEARCH_REINDEX")) {
         define("DISABLE_SEARCH_REINDEX", 1);
     }
     if ($parent_id) {
         $parentElement = umiHierarchy::getInstance()->getElement($element->getRel());
         if ($parentElement instanceof umiHierarchyElement) {
             $parentElement->setValue("last_message", $element_id);
             $parentElement->setValue("last_post_time", time());
             $parentElement->commit();
         }
         $parentElement = umiHierarchy::getInstance()->getElement($parentElement->getRel());
         if ($parentElement instanceof umiHierarchyElement) {
             $parentElement->setValue("last_message", $element_id);
             $parentElement->commit();
         }
     }
     if (!$bNeedModerate) {
         $this->recalcCounts($element);
     }
     $oEventPoint = new umiEventPoint("forum_message_post_do");
     $oEventPoint->setMode("after");
     $oEventPoint->setParam("topic_id", $parent_id);
     $oEventPoint->setParam("message_id", $element_id);
     $this->setEventPoint($oEventPoint);
     $path = $bNeedModerate ? $referer_url : $this->getMessageLink($element_id);
     $this->redirect($path);
 }
Example #4
0
 public function onModifyElementAntispam(iUmiEventPoint $event)
 {
     static $cache = array();
     $element = $event->getRef("element");
     if (!$element) {
         return;
     }
     if ($event->getMode() == "before") {
         $data = getRequest("data");
         if (isset($data[$element->getId()])) {
             $oldValue = getArrayKey($data[$element->getId()], 'is_spam');
             if ($oldValue != $element->getValue("is_spam")) {
                 $cache[$element->getId()] = true;
             }
         }
     } else {
         if (isset($cache[$element->getId()])) {
             $type = umiHierarchyTypesCollection::getInstance()->getTypeByName("faq", "question");
             $contentField = $type->getId() == $element->getTypeId() ? 'question' : 'content';
             antiSpamHelper::report($element->getId(), $contentField);
         }
     }
 }
Example #5
0
 /**
  * @desc Выводит форму для добавления комментария и выполняет все действия по сохранению
  * @param int $postId Идентификатор публикации или комментария
  * @param string $template имя файла шаблона
  * @return string|array
  */
 public function commentAdd($postId = false, $template = 'default')
 {
     $bNeedFinalPanic = false;
     if (!($oUsersModule = cmsController::getInstance()->getModule("users"))) {
         throw new publicException("Can't find users module");
     }
     if (!($oUsersModule->is_auth() || regedit::getInstance()->getVal("//modules/blogs20/allow_guest_comments"))) {
         return;
     }
     if ($postId === false) {
         $iTmp = getRequest('param0');
         if ($iTmp) {
             $postId = $iTmp;
         } else {
             $postId = cmsController::getInstance()->getCurrentElementId();
         }
     }
     $postId = (int) $postId;
     $oHierarchy = umiHierarchy::getInstance();
     $oHTypesCollection = umiHierarchyTypesCollection::getInstance();
     if (!($oPost = $oHierarchy->getElement($postId))) {
         throw new publicException(getLabel('error-page-does-not-exist', null, $postId));
     }
     if ($oPost->getTypeId() != $oHTypesCollection->getTypeByName("blogs20", "post")->getId() && $oPost->getTypeId() != $oHTypesCollection->getTypeByName("blogs20", "comment")->getId()) {
         throw new publicException("The id(#{$postId}) given is not an id of the blog's post");
     }
     $sTitle = ($tmp = getRequest('title')) ? $tmp : 'Re: ' . $oPost->getName();
     $sContent = htmlspecialchars(trim(getRequest('content')));
     if ($postId !== false && strlen($sContent) > 0) {
         if (!umiCaptcha::checkCaptcha()) {
             $this->errorNewMessage("%errors_wrong_captcha%");
             $this->errorPanic();
         }
         $hierarchy_type_id = umiHierarchyTypesCollection::getInstance()->getTypeByName("blogs20", "comment")->getId();
         $iCommentId = $oHierarchy->addElement($postId, $hierarchy_type_id, $sTitle, $sTitle);
         permissionsCollection::getInstance()->setDefaultPermissions($iCommentId);
         if ($oUsersModule->is_auth()) {
             $userId = $oUsersModule->user_id;
             $authorId = $oUsersModule->createAuthorUser($userId);
             $oActivity = antiSpamHelper::checkContent($sContent . $sTitle);
         } else {
             $nick = getRequest('nick');
             $email = getRequest('email');
             $ip = getServer('REMOTE_ADDR');
             $authorId = $oUsersModule->createAuthorGuest($nick, $email, $ip);
             $oActivity = antiSpamHelper::checkContent($sContent . $sTitle . $nick . $email);
         }
         $oComment = $oHierarchy->getElement($iCommentId, true);
         $is_active = $this->moderate ? 0 : 1;
         if ($is_active) {
             $is_active = $oActivity;
         }
         if (!$is_active) {
             $this->errorNewMessage('%comments_posted_moderating%', false);
             $bNeedFinalPanic = true;
         }
         $oComment->setIsActive($is_active);
         $oComment->setValue('title', $sTitle);
         $oComment->setValue('content', $sContent);
         $oComment->setValue('author_id', $authorId);
         $oComment->setValue('publish_time', new umiDate());
         $oComment->commit();
         // Raise Event
         $oEventPoint = new umiEventPoint("blogs20CommentAdded");
         $oEventPoint->setMode("after");
         $oEventPoint->setParam("id", $iCommentId);
         $oEventPoint->setParam('template', $template);
         $this->setEventPoint($oEventPoint);
         // Redirecting
         if ($bNeedFinalPanic) {
             $this->errorPanic();
         } else {
             $sRefererUri = getServer('HTTP_REFERER');
             if (strlen($sRefererUri)) {
                 $this->redirect($sRefererUri . '#comment_' . $iCommentId);
             }
             return null;
         }
     } else {
         if (!strlen($sContent) && !is_null(getRequest('content'))) {
             $this->errorNewMessage("%errors_missed_field_value%");
             $this->errorPanic();
         }
     }
     $sTplName = $oUsersModule->is_auth() ? 'comment_add_form' : 'comment_add_form_guest';
     list($sFormTemplate) = self::loadTemplates('blogs20/' . $template, $sTplName);
     return self::parseTemplate($sFormTemplate, array('parent_id' => $postId));
 }
 public function onMessagePost(iUmiEventPoint $event)
 {
     $messageId = $event->getParam("message_id");
     antiSpamHelper::checkForSpam($messageId);
 }