/**
  * Запуск валидации
  *
  * @param mixed $sValue Данные для валидации
  *
  * @return bool|string
  */
 public function validate($sValue)
 {
     if (is_array($sValue)) {
         return $this->getMessage($this->Lang_Get('validate.captcha.not_valid', null, false), 'msg');
     }
     if ($this->allowEmpty && $this->isEmpty($sValue)) {
         return true;
     }
     $sSecret = Config::Get('module.validate.recaptcha.secret_key');
     $sUrl = "https://www.google.com/recaptcha/api/siteverify?secret={$sSecret}&response={$sValue}";
     if (Config::Get('module.validate.recaptcha.use_ip')) {
         $sUrl .= '&remoteip=' . func_getIp();
     }
     if ($sData = file_get_contents($sUrl)) {
         if ($aData = @json_decode($sData, true)) {
             if (isset($aData['success']) and $aData['success']) {
                 return true;
             }
         } else {
             $this->Logger_Warning('ReCaptcha: error json decode', array('url' => $sUrl));
         }
     } else {
         $aError = error_get_last();
         $this->Logger_Warning('ReCaptcha: ' . ($aError ? $aError['message'] : 'error server request'), array('url' => $sUrl));
     }
     return $this->getMessage($this->Lang_Get('validate.captcha.not_valid', null, false), 'msg');
 }
 protected function beforeSave()
 {
     if ($bResult = parent::beforeSave()) {
         if ($this->_isNew()) {
             $this->setDateCreate(date("Y-m-d H:i:s"));
             $this->setIp(func_getIp());
         }
     }
     return $bResult;
 }
示例#3
0
 /**
  * Добавляет голосование
  *
  * @param ModuleVote_EntityVote $oVote	Объект голосования
  * @return bool
  */
 public function AddVote(ModuleVote_EntityVote $oVote)
 {
     if (!$oVote->getIp()) {
         $oVote->setIp(func_getIp());
     }
     if ($this->oMapper->AddVote($oVote)) {
         $this->Cache_Delete("vote_{$oVote->getTargetType()}_{$oVote->getTargetId()}_{$oVote->getVoterId()}");
         $this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array("vote_update_{$oVote->getTargetType()}_{$oVote->getVoterId()}"));
         return true;
     }
     return false;
 }
示例#4
0
 public function AddVote(ModuleVote_EntityVote $oVote)
 {
     if (!$oVote->getIp()) {
         $oVote->setIp(func_getIp());
     }
     if ($this->oMapper->AddVote($oVote)) {
         $this->Cache_Delete("vote_{$oVote->getTargetType()}_{$oVote->getTargetId()}_{$oVote->getVoterId()}");
         $this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array("vote_update_{$oVote->getTargetType()}_{$oVote->getVoterId()}"));
         if (in_array($oVote->getTargetType(), array('topic', 'comment', 'user'))) {
             $oAction = Engine::GetEntity("PluginFeedbacks_ModuleFeedbacks_EntityAction");
             $oAction->setUserIdFrom($oVote->getVoterId());
             $oAction->setId(null);
             $oAction->setAddDatetime(time());
             $oAction->setDestinationObjectId($oVote->getTargetId());
             if ($oVote->getTargetType() == 'topic') {
                 $oTopic = $this->Topic_GetTopicById($oVote->getTargetId());
                 $oAction->setUserIdTo($oTopic->getUserId());
                 if ($oVote->getDirection() > 0) {
                     $oAction->setActionType('VoteTopic');
                 }
                 if ($oVote->getDirection() < 0) {
                     $oAction->setActionType('VoteDownTopic');
                 }
                 if ($oVote->getDirection() == 0) {
                     $oAction->setActionType('VoteAbstainTopic');
                 }
             }
             if ($oVote->getTargetType() == 'comment') {
                 $oComment = $this->Comment_GetCommentById($oVote->getTargetId());
                 $oAction->setUserIdTo($oComment->getUserId());
                 if ($oVote->getDirection() > 0) {
                     $oAction->setActionType('VoteComment');
                 } else {
                     $oAction->setActionType('VoteDownComment');
                 }
             }
             if ($oVote->getTargetType() == 'user') {
                 $oAction->setUserIdTo($oVote->getTargetId());
                 if ($oVote->getDirection() > 0) {
                     $oAction->setActionType('VoteUser');
                 } else {
                     $oAction->setActionType('VoteDownUser');
                 }
             }
             return true;
             $this->PluginFeedbacks_Feedbacks_SaveAction($oAction);
         }
         return true;
     }
     return false;
 }
示例#5
0
 /**
  * Формирует и отправляет личное сообщение
  *
  * @param string $sTitle
  * @param string $sText
  * @param int | ModuleUser_EntityUser $oUserFrom
  * @param array | int | ModuleUser_EntityUser $aUserTo
  * @param bool $bSendNotify
  */
 public function SendTalk($sTitle, $sText, $oUserFrom, $aUserTo, $bSendNotify = true, $bUseBlacklist = true)
 {
     $iUserIdFrom = $oUserFrom instanceof ModuleUser_EntityUser ? $oUserFrom->getId() : (int) $oUserFrom;
     if (!is_array($aUserTo)) {
         $aUserTo = array($aUserTo);
     }
     $aUserIdTo = array($iUserIdFrom);
     if ($bUseBlacklist) {
         $aUserInBlacklist = $this->GetBlacklistByTargetId($iUserIdFrom);
     }
     foreach ($aUserTo as $oUserTo) {
         $sUserIdTo = $oUserTo instanceof ModuleUser_EntityUser ? $oUserTo->getId() : (int) $oUserTo;
         if (!$bUseBlacklist || !in_array($sUserIdTo, $aUserInBlacklist)) {
             $aUserIdTo[] = $sUserIdTo;
         }
     }
     $aUserIdTo = array_unique($aUserIdTo);
     if (!empty($aUserIdTo)) {
         $oTalk = Engine::GetEntity('Talk');
         $oTalk->setUserId($iUserIdFrom);
         $oTalk->setTitle($sTitle);
         $oTalk->setText($sText);
         $oTalk->setDate(date("Y-m-d H:i:s"));
         $oTalk->setDateLast(date("Y-m-d H:i:s"));
         $oTalk->setUserIp(func_getIp());
         if ($oTalk = $this->AddTalk($oTalk)) {
             foreach ($aUserIdTo as $iUserId) {
                 $oTalkUser = Engine::GetEntity('Talk_TalkUser');
                 $oTalkUser->setTalkId($oTalk->getId());
                 $oTalkUser->setUserId($iUserId);
                 if ($iUserId == $iUserIdFrom) {
                     $oTalkUser->setDateLast(date("Y-m-d H:i:s"));
                 } else {
                     $oTalkUser->setDateLast(null);
                 }
                 $this->AddTalkUser($oTalkUser);
                 if ($bSendNotify) {
                     if ($iUserId != $iUserIdFrom) {
                         $oUserFrom = $this->User_GetUserById($iUserIdFrom);
                         $oUserToMail = $this->User_GetUserById($iUserId);
                         $this->Notify_SendTalkNew($oUserToMail, $oUserFrom, $oTalk);
                     }
                 }
             }
             return $oTalk;
         }
     }
     return false;
 }
示例#6
0
 /**
  * Добавление записи на стену
  *
  * @param ModuleWall_EntityWall $oWall
  *
  * @return bool | ModuleWall_EntityWall
  */
 public function AddWall($oWall)
 {
     if (!$oWall->getDateAdd()) {
         $oWall->setDateAdd(date("Y-m-d H:i:s"));
     }
     if (!$oWall->getIp()) {
         $oWall->setIp(func_getIp());
     }
     if ($iId = $this->oMapper->AddWall($oWall)) {
         $oWall->setId($iId);
         /**
          * Обновляем данные у родительской записи
          */
         if ($oPidWall = $oWall->GetPidWall()) {
             $this->UpdatePidWall($oPidWall);
         }
         return $oWall;
     }
     return false;
 }
 public function GetUserById($nUserId)
 {
     $iCurrentUserId = -1;
     $sql = "SELECT\n                u.*,\n  \t\tIF(ua.user_id IS NULL,0,1) as user_is_administrator,\n                ab.banline, ab.banunlim, ab.bancomment, ab.banactive,\n\t\tINET_ATON('" . func_getIp() . "') as ipn\n            FROM\n                " . Config::Get('db.table.user') . " as u\n            LEFT JOIN " . Config::Get('db.table.user_administrator') . " AS ua ON u.user_id=ua.user_id\n            LEFT JOIN " . Config::Get('db.table.adminban') . " AS ab ON u.user_id=ab.user_id\n            WHERE\n                u.user_id = ? ";
     if ($aRow = @$this->oDb->selectRow($sql, $nUserId)) {
         $aRow['tpoics_count'] = $this->GetCountTopicsByUserId($nUserId);
         $aRow['comments_count'] = $this->GetCountCommentsByUserId($nUserId);
         $sql = "SELECT id FROM " . Config::Get('db.table.adminips') . "\n                WHERE (? BETWEEN ip1 AND ip2) AND (banactive=1) AND (banunlim>0 OR Now()<banline) ";
         if ($nId = $this->oDb->selectCell($sql, $aRow['ipn'])) {
             $aRow['ban_ip'] = $nId;
         } else {
             $aRow['ban_ip'] = 0;
         }
         return new PluginAceadminpanel_ModuleAdmin_EntityUser($aRow);
     }
     return null;
 }
 /**
  * Обработка добавление комментария
  *
  * @return bool
  */
 protected function SubmitComment()
 {
     /**
      * Проверям авторизован ли пользователь
      */
     if (!$this->User_IsAuthorization()) {
         $this->Message_AddErrorSingle($this->Lang_Get('need_authorization'), $this->Lang_Get('error'));
         return;
     }
     /* @var $oImage PluginLsgallery_ModuleImage_EntityImage */
     if (!($oImage = $this->PluginLsgallery_Image_GetImageById(getRequest('cmt_target_id')))) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     /* @var $oAlbum PluginLsgallery_ModuleAlbum_EntityAlbum */
     if (!($oAlbum = $this->PluginLsgallery_Album_GetAlbumById($oImage->getAlbumId()))) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     if (!$this->ACL_AllowViewAlbumImages($this->oUserCurrent, $oAlbum)) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем разрешено ли постить комменты
      */
     if (!$this->ACL_CanPostComment($this->oUserCurrent) and !$this->oUserCurrent->isAdministrator()) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_acl'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем разрешено ли постить комменты по времени
      */
     if (!$this->ACL_CanPostCommentTime($this->oUserCurrent) and !$this->oUserCurrent->isAdministrator()) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_limit'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем текст комментария
      */
     $sText = $this->Text_Parser(getRequest('comment_text'));
     if (!func_check($sText, 'text', 2, 10000)) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_add_text_error'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверям на какой коммент отвечаем
      */
     $sParentId = (int) getRequest('reply');
     if (!func_check($sParentId, 'id')) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     $oCommentParent = null;
     if ($sParentId != 0) {
         /**
          * Проверяем существует ли комментарий на который отвечаем
          */
         if (!($oCommentParent = $this->Comment_GetCommentById($sParentId))) {
             $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
             return;
         }
         /**
          * Проверяем из одного топика ли новый коммент и тот на который отвечаем
          */
         if ($oCommentParent->getTargetId() != $oImage->getId()) {
             $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
             return;
         }
     } else {
         /**
          * Корневой комментарий
          */
         $sParentId = null;
     }
     /**
      * Проверка на дублирующий коммент
      */
     if ($this->Comment_GetCommentUnique($oImage->getId(), 'image', $this->oUserCurrent->getId(), $sParentId, md5($sText))) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_spam'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Создаём коммент
      */
     $oCommentNew = Engine::GetEntity('Comment');
     $oCommentNew->setTargetId($oImage->getId());
     $oCommentNew->setTargetType('image');
     $oCommentNew->setTargetParentId($oImage->getAlbumId());
     $oCommentNew->setUserId($this->oUserCurrent->getId());
     $oCommentNew->setText($sText);
     $oCommentNew->setDate(date("Y-m-d H:i:s"));
     $oCommentNew->setUserIp(func_getIp());
     $oCommentNew->setPid($sParentId);
     $oCommentNew->setTextHash(md5($sText));
     $oCommentNew->setPublish(1);
     /**
      * Добавляем коммент
      */
     $this->Hook_Run('image_comment_add_before', array('oCommentNew' => $oCommentNew, 'oCommentParent' => $oCommentParent, 'oImage' => $oImage));
     if ($this->Comment_AddComment($oCommentNew)) {
         $this->Hook_Run('image_comment_add_after', array('oCommentNew' => $oCommentNew, 'oCommentParent' => $oCommentParent, 'oImage' => $oImage));
         $this->Viewer_AssignAjax('sCommentId', $oCommentNew->getId());
         $this->PluginLsgallery_Image_IncreaseImageCountComment($oCommentNew->getTargetId());
         $this->oUserCurrent->setDateCommentLast(date("Y-m-d H:i:s"));
         $this->User_Update($this->oUserCurrent);
     } else {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
     }
 }
示例#9
0
 /**
  * Обработка добавление комментария к топику
  *	 
  * @return unknown
  */
 protected function SubmitComment()
 {
     /**
      * Проверям авторизован ли пользователь
      */
     if (!$this->User_IsAuthorization()) {
         $this->Message_AddErrorSingle($this->Lang_Get('need_authorization'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем разговор
      */
     if (!($oTalk = $this->Talk_GetTalkById(getRequest('cmt_target_id')))) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     if (!($oTalkUser = $this->Talk_GetTalkUser($oTalk->getId(), $this->oUserCurrent->getId()))) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем разрешено ли отправлять инбокс по времени
      */
     if (!$this->ACL_CanPostTalkCommentTime($this->oUserCurrent)) {
         $this->Message_AddErrorSingle($this->Lang_Get('talk_time_limit'), $this->Lang_Get('error'));
         return false;
     }
     /**
      * Проверяем текст комментария
      */
     $sText = $this->Text_Parser(getRequest('comment_text'));
     if (!func_check($sText, 'text', 2, 3000)) {
         $this->Message_AddErrorSingle($this->Lang_Get('talk_comment_add_text_error'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверям на какой коммент отвечаем
      */
     $sParentId = (int) getRequest('reply');
     if (!func_check($sParentId, 'id')) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     $oCommentParent = null;
     if ($sParentId != 0) {
         /**
          * Проверяем существует ли комментарий на который отвечаем
          */
         if (!($oCommentParent = $this->Comment_GetCommentById($sParentId))) {
             $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
             return;
         }
         /**
          * Проверяем из одного топика ли новый коммент и тот на который отвечаем
          */
         if ($oCommentParent->getTargetId() != $oTalk->getId()) {
             $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
             return;
         }
     } else {
         /**
          * Корневой комментарий
          */
         $sParentId = null;
     }
     /**
      * Проверка на дублирующий коммент
      */
     if ($this->Comment_GetCommentUnique($oTalk->getId(), 'talk', $this->oUserCurrent->getId(), $sParentId, md5($sText))) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_spam'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Создаём коммент
      */
     $oCommentNew = Engine::GetEntity('Comment');
     $oCommentNew->setTargetId($oTalk->getId());
     $oCommentNew->setTargetType('talk');
     $oCommentNew->setUserId($this->oUserCurrent->getId());
     $oCommentNew->setText($sText);
     $oCommentNew->setDate(date("Y-m-d H:i:s"));
     $oCommentNew->setUserIp(func_getIp());
     $oCommentNew->setPid($sParentId);
     $oCommentNew->setTextHash(md5($sText));
     /**
      * Добавляем коммент
      */
     if ($this->Comment_AddComment($oCommentNew)) {
         $this->Viewer_AssignAjax('sCommentId', $oCommentNew->getId());
         $oTalk->setDateLast(date("Y-m-d H:i:s"));
         $oTalk->setCountComment($oTalk->getCountComment() + 1);
         $this->Talk_UpdateTalk($oTalk);
         /**
          * Отсылаем уведомления всем адресатам
          */
         $aUsersTalk = $this->Talk_GetUsersTalk($oTalk->getId(), ModuleTalk::TALK_USER_ACTIVE);
         foreach ($aUsersTalk as $oUserTalk) {
             if ($oUserTalk->getId() != $oCommentNew->getUserId()) {
                 $this->Notify_SendTalkCommentNew($oUserTalk, $this->oUserCurrent, $oTalk, $oCommentNew);
             }
         }
         /**
          * Увеличиваем число новых комментов
          */
         $this->Talk_increaseCountCommentNew($oTalk->getId(), $oCommentNew->getUserId());
     } else {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
     }
 }
示例#10
0
 /**
  * Возвращает объект голосования текущего пользователя за конкретный опрос
  *
  * @param ModulePoll_EntityPoll $oPoll
  * @param int|null $iUserId Если null, то проверяется для гостя
  * @return ModulePoll_EntityVote
  */
 public function GetVoteByUser($oPoll, $iUserId)
 {
     $iUserId = is_object($iUserId) ? $iUserId->getId() : $iUserId;
     if (is_null($iUserId)) {
         /**
          * Для гостя
          * Два варианта - проверка по IP и по кукам
          */
         if ($oPoll->getIsGuestCheckIp()) {
             if ($oVote = $this->Poll_GetVoteByIpAndPollId(func_getIp(), $oPoll->getId())) {
                 return $oVote;
             }
         }
         /**
          * По кукам
          */
         if ($sKey = $this->Session_GetCookie($this->GetCookieVoteName($oPoll))) {
             return $this->Poll_GetVoteByGuestKeyAndPollId($sKey, $oPoll->getId());
         }
         return false;
     } else {
         /**
          * Для авторизованного
          */
         return $this->Poll_GetVoteByUserIdAndPollId($iUserId, $oPoll->getId());
     }
 }
示例#11
0
 /**
  * Обработка редактирования топика
  *
  * @param ModuleTopic_EntityTopic $oTopic
  * @return mixed
  */
 protected function SubmitEdit($oTopic)
 {
     $oTopic->_setValidateScenario('topic');
     /**
      * Сохраняем старое значение идентификатора блога
      */
     $sBlogIdOld = $oTopic->getBlogId();
     /**
      * Заполняем поля для валидации
      */
     $oTopic->setBlogId(getRequestStr('blog_id'));
     $oTopic->setTitle(strip_tags(getRequestStr('topic_title')));
     $oTopic->setTextSource(getRequestStr('topic_text'));
     $oTopic->setTags(getRequestStr('topic_tags'));
     $oTopic->setUserIp(func_getIp());
     /**
      * Проверка корректности полей формы
      */
     if (!$this->checkTopicFields($oTopic)) {
         return false;
     }
     /**
      * Определяем в какой блог делаем запись
      */
     $iBlogId = $oTopic->getBlogId();
     if ($iBlogId == 0) {
         $oBlog = $this->Blog_GetPersonalBlogByUserId($oTopic->getUserId());
     } else {
         $oBlog = $this->Blog_GetBlogById($iBlogId);
     }
     /**
      * Если блог не определен выдаем предупреждение
      */
     if (!$oBlog) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_create_blog_error_unknown'), $this->Lang_Get('error'));
         return false;
     }
     /**
      * Проверяем права на постинг в блог
      */
     if (!$this->ACL_IsAllowBlog($oBlog, $this->oUserCurrent)) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_create_blog_error_noallow'), $this->Lang_Get('error'));
         return false;
     }
     /**
      * Проверяем разрешено ли постить топик по времени
      */
     if (isPost('submit_topic_publish') and !$oTopic->getPublishDraft() and !$this->ACL_CanPostTopicTime($this->oUserCurrent)) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_time_limit'), $this->Lang_Get('error'));
         return;
     }
     $oTopic->setBlogId($oBlog->getId());
     /**
      * Получаемый и устанавливаем разрезанный текст по тегу <cut>
      */
     list($sTextShort, $sTextNew, $sTextCut) = $this->Text_Cut($oTopic->getTextSource());
     $oTopic->setCutText($sTextCut);
     $oTopic->setText($this->Text_Parser($sTextNew));
     $oTopic->setTextShort($this->Text_Parser($sTextShort));
     /**
      * Публикуем или сохраняем в черновиках
      */
     $bSendNotify = false;
     if (isset($_REQUEST['submit_topic_publish'])) {
         $oTopic->setPublish(1);
         if ($oTopic->getPublishDraft() == 0) {
             $oTopic->setPublishDraft(1);
             $oTopic->setDateAdd(date("Y-m-d H:i:s"));
             $bSendNotify = true;
         }
     } else {
         $oTopic->setPublish(0);
     }
     /**
      * Принудительный вывод на главную
      */
     if ($this->ACL_IsAllowPublishIndex($this->oUserCurrent)) {
         if (getRequest('topic_publish_index')) {
             $oTopic->setPublishIndex(1);
         } else {
             $oTopic->setPublishIndex(0);
         }
     }
     /**
      * Запрет на комментарии к топику
      */
     $oTopic->setForbidComment(0);
     if (getRequest('topic_forbid_comment')) {
         $oTopic->setForbidComment(1);
     }
     $this->Hook_Run('topic_edit_before', array('oTopic' => $oTopic, 'oBlog' => $oBlog));
     /**
      * Сохраняем топик
      */
     if ($this->Topic_UpdateTopic($oTopic)) {
         $this->Hook_Run('topic_edit_after', array('oTopic' => $oTopic, 'oBlog' => $oBlog, 'bSendNotify' => &$bSendNotify));
         /**
          * Обновляем данные в комментариях, если топик был перенесен в новый блог
          */
         if ($sBlogIdOld != $oTopic->getBlogId()) {
             $this->Comment_UpdateTargetParentByTargetId($oTopic->getBlogId(), 'topic', $oTopic->getId());
             $this->Comment_UpdateTargetParentByTargetIdOnline($oTopic->getBlogId(), 'topic', $oTopic->getId());
         }
         /**
          * Обновляем количество топиков в блоге
          */
         if ($sBlogIdOld != $oTopic->getBlogId()) {
             $this->Blog_RecalculateCountTopicByBlogId($sBlogIdOld);
         }
         $this->Blog_RecalculateCountTopicByBlogId($oTopic->getBlogId());
         /**
          * Добавляем событие в ленту
          */
         $this->Stream_write($oTopic->getUserId(), 'add_topic', $oTopic->getId(), $oTopic->getPublish() && $oBlog->getType() != 'close');
         /**
          * Рассылаем о новом топике подписчикам блога
          */
         if ($bSendNotify) {
             $this->Topic_SendNotifyTopicNew($oBlog, $oTopic, $oTopic->getUser());
         }
         if (!$oTopic->getPublish() and !$this->oUserCurrent->isAdministrator() and $this->oUserCurrent->getId() != $oTopic->getUserId()) {
             Router::Location($oBlog->getUrlFull());
         }
         Router::Location($oTopic->getUrl());
     } else {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'));
         return Router::Action('error');
     }
 }
 protected function EventAjaxAdd()
 {
     $this->Viewer_SetResponseAjax();
     /**
      * Проверяем тип топика
      */
     $sTopicType = getRequestStr('topic_type');
     if (!($oTopicType = $this->Topic_GetTopicType($sTopicType))) {
         return $this->EventErrorDebug();
     }
     /**
      * Проверяем права на создание топика
      */
     if (!$this->ACL_CanAddTopic($this->oUserCurrent, $oTopicType)) {
         $this->Message_AddErrorSingle($this->Rbac_GetMsgLast());
         return false;
     }
     /**
      * Создаем топик
      */
     $oTopic = Engine::GetEntity('Topic');
     $oTopic->_setDataSafe(getRequest('topic'));
     $oTopic->setProperties(getRequest('property'));
     $oTopic->setUserCreator($this->oUserCurrent);
     $oTopic->setUserId($this->oUserCurrent->getId());
     $oTopic->setDateAdd(date("Y-m-d H:i:s"));
     $oTopic->setUserIp(func_getIp());
     $oTopic->setTopicType($sTopicType);
     if (!$oTopic->getTags() or !$oTopic->getTypeObject()->getParam('allow_tags')) {
         $oTopic->setTags('');
     }
     /**
      * Публикуем или сохраняем
      */
     if (!isset($_REQUEST['is_draft'])) {
         $oTopic->setPublish(1);
         $oTopic->setPublishDraft(1);
     } else {
         $oTopic->setPublish(0);
         $oTopic->setPublishDraft(0);
     }
     /**
      * Принудительный вывод на главную
      */
     $oTopic->setPublishIndex(0);
     if ($this->ACL_IsAllowTopicPublishIndex($this->oUserCurrent)) {
         if (isset($_REQUEST['topic']['topic_publish_index'])) {
             $oTopic->setPublishIndex(1);
         }
     }
     /**
      * Принудительный запрет вывода на главную
      */
     $oTopic->setSkipIndex(0);
     if ($this->ACL_IsAllowTopicSkipIndex($this->oUserCurrent)) {
         if (isset($_REQUEST['topic']['topic_skip_index'])) {
             $oTopic->setSkipIndex(1);
         }
     }
     /**
      * Запрет на комментарии к топику
      */
     $oTopic->setForbidComment(0);
     if (isset($_REQUEST['topic']['topic_forbid_comment'])) {
         $oTopic->setForbidComment(1);
     }
     $this->Hook_Run('topic_add_validate_before', array('oTopic' => $oTopic));
     if ($oTopic->_Validate()) {
         $oBlog = $oTopic->getBlog();
         /**
          * Получаем и устанавливаем разрезанный текст по тегу <cut>
          */
         if ($oTopic->getTypeObject()->getParam('allow_text')) {
             list($sTextShort, $sTextNew, $sTextCut) = $this->Text_Cut($oTopic->getTextSource());
             $oTopic->setCutText($sTextCut);
             $oTopic->setText($this->Topic_Parser($sTextNew, $oTopic));
             if ($sTextShort != $sTextNew) {
                 $oTopic->setTextShort($this->Topic_Parser($sTextShort, $oTopic));
             } else {
                 $oTopic->setTextShort('');
             }
         } else {
             $oTopic->setCutText('');
             $oTopic->setText('');
             $oTopic->setTextShort('');
             $oTopic->setTextSource('');
         }
         $this->Hook_Run('topic_add_before', array('oTopic' => $oTopic, 'oBlog' => $oBlog));
         if ($this->Topic_AddTopic($oTopic)) {
             $this->Hook_Run('topic_add_after', array('oTopic' => $oTopic, 'oBlog' => $oBlog));
             /**
              * Получаем топик, чтоб подцепить связанные данные
              */
             $oTopic = $this->Topic_GetTopicById($oTopic->getId());
             /**
              * Обновляем количество топиков в блогах
              */
             $this->Blog_RecalculateCountTopicByBlogId($oTopic->getBlogsId());
             /**
              * Фиксируем ID у media файлов топика
              */
             $this->Media_ReplaceTargetTmpById('topic', $oTopic->getId());
             /**
              * Фиксируем ID у опросов
              */
             if ($oTopicType->getParam('allow_poll')) {
                 $this->Poll_ReplaceTargetTmpById('topic', $oTopic->getId());
             }
             /**
              * Добавляем автора топика в подписчики на новые комментарии к этому топику
              */
             $oUser = $oTopic->getUser();
             if ($oUser) {
                 $this->Subscribe_AddSubscribeSimple('topic_new_comment', $oTopic->getId(), $oUser->getMail(), $oUser->getId());
             }
             /**
              * Делаем рассылку спама всем, кто состоит в этом блоге
              */
             if ($oTopic->getPublish() == 1 and $oBlog->getType() != 'personal') {
                 $this->Topic_SendNotifyTopicNew($oTopic, $oUser);
             }
             /**
              * Добавляем событие в ленту
              */
             $this->Stream_write($oTopic->getUserId(), 'add_topic', $oTopic->getId(), $oTopic->getPublish() && $oBlog->getType() != 'close');
             $this->Viewer_AssignAjax('sUrlRedirect', $oTopic->getUrl());
             $this->Message_AddNotice('Добавление прошло успешно', $this->Lang_Get('common.attention'));
         } else {
             $this->Message_AddError('Возникла ошибка при добавлении', $this->Lang_Get('common.error.error'));
         }
     } else {
         $this->Message_AddError($oTopic->_getValidateError(), $this->Lang_Get('common.error.error'));
     }
 }
示例#13
0
 /**
  * Обработка редактирования топика
  *
  * @param unknown_type $oTopic
  * @return unknown
  */
 protected function SubmitEdit($oTopic)
 {
     /**
      * Проверка корректности полей формы
      */
     if (!$this->checkTopicFields($oTopic)) {
         return false;
     }
     /**
      * Определяем в какой блог делаем запись
      */
     $iBlogId = getRequest('blog_id');
     if ($iBlogId == 0) {
         $oBlog = $this->Blog_GetPersonalBlogByUserId($oTopic->getUserId());
     } else {
         $oBlog = $this->Blog_GetBlogById($iBlogId);
     }
     /**
      * Если блог не определен выдаем предупреждение
      */
     if (!$oBlog) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_create_blog_error_unknown'), $this->Lang_Get('error'));
         return false;
     }
     /**
      * Проверяем права на постинг в блог
      */
     if (!$this->ACL_IsAllowBlog($oBlog, $this->oUserCurrent)) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_create_blog_error_noallow'), $this->Lang_Get('error'));
         return false;
     }
     /**
      * Проверяем разрешено ли постить топик по времени
      */
     if (isPost('submit_topic_publish') and !$oTopic->getPublishDraft() and !$this->ACL_CanPostTopicTime($this->oUserCurrent)) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_time_limit'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Сохраняем старое значение идентификатора блога
      */
     $sBlogIdOld = $oTopic->getBlogId();
     /**
      * Теперь можно смело редактировать топик
      */
     $oTopic->setBlogId($oBlog->getId());
     $oTopic->setText(htmlspecialchars(getRequest('topic_text')));
     $oTopic->setTextShort(htmlspecialchars(getRequest('topic_text')));
     $oTopic->setTextSource(getRequest('topic_text'));
     $oTopic->setTags(getRequest('topic_tags'));
     $oTopic->setUserIp(func_getIp());
     /**
      * изменяем вопрос/ответы только если еще никто не голосовал
      */
     if ($oTopic->getQuestionCountVote() == 0) {
         $oTopic->setTitle(getRequest('topic_title'));
         $oTopic->clearQuestionAnswer();
         foreach (getRequest('answer', array()) as $sAnswer) {
             $oTopic->addQuestionAnswer($sAnswer);
         }
     }
     $oTopic->setTextHash(md5($oTopic->getType() . $oTopic->getText() . $oTopic->getTitle()));
     /**
      * Проверяем топик на уникальность
      */
     if ($oTopicEquivalent = $this->Topic_GetTopicUnique($this->oUserCurrent->getId(), $oTopic->getTextHash())) {
         if ($oTopicEquivalent->getId() != $oTopic->getId()) {
             $this->Message_AddErrorSingle($this->Lang_Get('topic_create_text_error_unique'), $this->Lang_Get('error'));
             return false;
         }
     }
     /**
      * Публикуем или сохраняем в черновиках
      */
     $bSendNotify = false;
     if (isset($_REQUEST['submit_topic_publish'])) {
         $oTopic->setPublish(1);
         if ($oTopic->getPublishDraft() == 0) {
             $oTopic->setPublishDraft(1);
             $oTopic->setDateAdd(date("Y-m-d H:i:s"));
             $bSendNotify = true;
         }
     } else {
         $oTopic->setPublish(0);
     }
     /**
      * Принудительный вывод на главную
      */
     if ($this->ACL_IsAllowPublishIndex($this->oUserCurrent)) {
         if (getRequest('topic_publish_index')) {
             $oTopic->setPublishIndex(1);
         } else {
             $oTopic->setPublishIndex(0);
         }
     }
     /**
      * Запрет на комментарии к топику
      */
     $oTopic->setForbidComment(0);
     if (getRequest('topic_forbid_comment')) {
         $oTopic->setForbidComment(1);
     }
     $this->Hook_Run('topic_edit_before', array('oTopic' => $oTopic, 'oBlog' => $oBlog));
     /**
      * Сохраняем топик
      */
     if ($this->Topic_UpdateTopic($oTopic)) {
         $this->Hook_Run('topic_edit_after', array('oTopic' => $oTopic, 'oBlog' => $oBlog, 'bSendNotify' => &$bSendNotify));
         /**
          * Обновляем данные в комментариях, если топик был перенесен в новый блог
          */
         if ($sBlogIdOld != $oTopic->getBlogId()) {
             $this->Comment_UpdateTargetParentByTargetId($oTopic->getBlogId(), 'topic', $oTopic->getId());
             $this->Comment_UpdateTargetParentByTargetIdOnline($oTopic->getBlogId(), 'topic', $oTopic->getId());
         }
         /**
          * Обновляем количество топиков в блоге
          */
         if ($sBlogIdOld != $oTopic->getBlogId()) {
             $this->Blog_RecalculateCountTopicByBlogId($sBlogIdOld);
         }
         $this->Blog_RecalculateCountTopicByBlogId($oTopic->getBlogId());
         /**
          * Добавляем событие в ленту
          */
         $this->Stream_write($oTopic->getUserId(), 'add_topic', $oTopic->getId(), $oTopic->getPublish() && $oBlog->getType() != 'close');
         /**
          * Рассылаем о новом топике подписчикам блога
          */
         if ($bSendNotify) {
             $this->Topic_SendNotifyTopicNew($oBlog, $oTopic, $this->oUserCurrent);
         }
         if (!$oTopic->getPublish() and !$this->oUserCurrent->isAdministrator() and $this->oUserCurrent->getId() != $oTopic->getUserId()) {
             Router::Location($oBlog->getUrlFull());
         }
         Router::Location($oTopic->getUrl());
     } else {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'));
         return Router::Action('error');
     }
 }
 public function blackMail($sMail, $sName = null)
 {
     $sIp = func_getIp();
     if (!empty($sMail) && $this->check_whitelist_users_mail($sMail) || !empty($sName) && $this->check_whitelist_users_name($sName) || !empty($sIp) && $this->check_whitelist_users_ip($sIp) || $this->check_whitelist_domains($sMail)) {
         return false;
     }
     if (!empty($sMail) && $this->check_blacklist_users_mail($sMail) || !empty($sName) && $this->check_blacklist_users_name($sName) || !empty($sIp) && $this->check_blacklist_users_ip($sIp) || $this->check_blacklist_domains($sMail)) {
         return true;
     }
     $bCheckMail = Config::Get('plugin.blacklist.check_mail') && $sMail;
     $bCheckIp = Config::Get('plugin.blacklist.check_ip') && $sIp && $sIp !== '127.0.0.1';
     if (!$bCheckMail && !$bCheckIp) {
         return false;
     }
     $bIpExact = Config::Get('plugin.blacklist.check_ip_exact');
     $aResult = $this->check_local_base($sMail, $sIp, $bCheckMail, $bCheckIp);
     if (is_array($aResult)) {
         if ($this->analyse_result($aResult, $bCheckMail, $bCheckIp, $bIpExact)) {
             return true;
         } elseif ((!$bCheckMail || $bCheckMail && isset($aResult[self::TYPE_MAIL])) && (!$bCheckIp || $bCheckIp && isset($aResult[self::TYPE_IP]))) {
             return false;
         }
     }
     $bMail = false;
     $bIp = false;
     $bResult = false;
     if (Config::Get('plugin.blacklist.use_stopforumspam_com')) {
         $aResult = $this->check_stopforumspam_com($sMail, $sIp, $bCheckMail, $bCheckIp);
         $bMail |= is_array($aResult) && isset($aResult[self::TYPE_MAIL]) ? $aResult[self::TYPE_MAIL] : false;
         $bIp |= is_array($aResult) && isset($aResult[self::TYPE_IP]) ? $aResult[self::TYPE_IP] : false;
         $bResult = $this->analyse_result($aResult, $bCheckMail, $bCheckIp, $bIpExact);
         if ($bCheckMail) {
             $this->AddMailResult($sMail, $bMail, self::SERVICE_STOPFORUMSPAM_COM);
         }
         if ($bCheckIp) {
             $this->AddIpResult($sIp, $bIp, self::SERVICE_STOPFORUMSPAM_COM);
         }
     }
     if (!$bResult && Config::Get('plugin.blacklist.use_botscout_com')) {
         $aResult = $this->check_botscout_com($sMail, $sIp, $bCheckMail, $bCheckIp);
         $bMail |= is_array($aResult) && isset($aResult[self::TYPE_MAIL]) ? $aResult[self::TYPE_MAIL] : false;
         $bIp |= is_array($aResult) && isset($aResult[self::TYPE_IP]) ? $aResult[self::TYPE_IP] : false;
         $bResult = $this->analyse_result($aResult, $bCheckMail, $bCheckIp, $bIpExact);
         if ($bCheckMail) {
             $this->AddMailResult($sMail, $bMail, self::SERVICE_BOTSCOUT_COM);
         }
         if ($bCheckIp) {
             $this->AddIpResult($sIp, $bIp, self::SERVICE_BOTSCOUT_COM);
         }
     }
     if (!$bResult && Config::Get('plugin.blacklist.use_fspamlist_com')) {
         $aResult = $this->check_fspamlist_com($sMail, $sIp, $bCheckMail, $bCheckIp);
         $bMail |= is_array($aResult) && isset($aResult[self::TYPE_MAIL]) ? $aResult[self::TYPE_MAIL] : false;
         $bIp |= is_array($aResult) && isset($aResult[self::TYPE_IP]) ? $aResult[self::TYPE_IP] : false;
         $bResult = $this->analyse_result($aResult, $bCheckMail, $bCheckIp, $bIpExact);
         if ($bCheckMail) {
             $this->AddMailResult($sMail, $bMail, self::SERVICE_FSPAMLIST_COM);
         }
         if ($bCheckIp) {
             $this->AddIpResult($sIp, $bIp, self::SERVICE_FSPAMLIST_COM);
         }
     }
     return $bResult;
 }
示例#15
0
 protected function CreateSession(ModuleUser_EntityUser $oUser, $sKey)
 {
     $this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('user_session_update'));
     $this->Cache_Delete("user_session_{$oUser->getId()}");
     $oSession = Engine::GetEntity('User_Session');
     $oSession->setUserId($oUser->getId());
     $oSession->setKey($sKey);
     $oSession->setIpLast(func_getIp());
     $oSession->setIpCreate(func_getIp());
     $oSession->setDateLast(date("Y-m-d H:i:s"));
     $oSession->setDateCreate(date("Y-m-d H:i:s"));
     if ($this->oMapper->CreateSession($oSession)) {
         $this->oSession = $oSession;
         return true;
     }
     return false;
 }
 protected function EventUsersMessageCommon()
 {
     $bOk = true;
     $sTitle = getRequest('talk_title');
     $sText = $this->Text_Parser(getRequest('talk_text'));
     $sDate = date('Y-m-d H:i:s');
     $sIp = func_getIp();
     if ($sUsers = getRequest('users_list')) {
         $aUsers = explode(',', str_replace(' ', '', $sUsers));
     } else {
         $aUsers = array();
     }
     if ($aUsers) {
         if ($bOk and $aUsers) {
             $oTalk = Engine::GetEntity('Talk_Talk');
             $oTalk->setUserId($this->oUserCurrent->getId());
             $oTalk->setUserIdLast($this->oUserCurrent->getId());
             $oTalk->setTitle($sTitle);
             $oTalk->setText($sText);
             $oTalk->setDate($sDate);
             $oTalk->setDateLast($sDate);
             $oTalk->setUserIp($sIp);
             $oTalk = $this->Talk_AddTalk($oTalk);
             // добавляем себя в общий список
             $aUsers[] = $this->oUserCurrent->getLogin();
             // теперь рассылаем остальным
             foreach ($aUsers as $sUserLogin) {
                 if ($sUserLogin and $iUserId = $this->PluginAceadminpanel_Admin_GetUserId($sUserLogin)) {
                     $oTalkUser = Engine::GetEntity('Talk_TalkUser');
                     $oTalkUser->setTalkId($oTalk->getId());
                     $oTalkUser->setUserId($iUserId);
                     if ($sUserLogin != $this->oUserCurrent->getLogin()) {
                         $oTalkUser->setDateLast(null);
                     } else {
                         $oTalkUser->setDateLast($sDate);
                     }
                     $this->Talk_AddTalkUser($oTalkUser);
                     // Отправляем уведомления
                     if ($sUserLogin != $this->oUserCurrent->getLogin() or getRequest('send_copy_self')) {
                         $oUserToMail = $this->User_GetUserById($iUserId);
                         $this->Notify_SendTalkNew($oUserToMail, $this->oUserCurrent, $oTalk);
                     }
                 }
             }
         }
     }
     if ($bOk) {
         $this->_messageNotice($this->Lang_Get('adm_msg_sent_ok'));
     } else {
         $this->_messageError($this->Lang_Get('system_error'));
     }
 }
示例#17
0
 /**
  * Функция создает и публикует сообщение в тему
  *	@param	array	$aData
  *	@return	object
  */
 public function createPost($aData = array())
 {
     $sText = isset($aData['text']) ? $aData['text'] : null;
     $sUser = isset($aData['user']) ? $aData['user'] : null;
     $sTopic = isset($aData['topic']) ? $aData['topic'] : null;
     $sTitle = isset($aData['title']) ? $aData['title'] : null;
     $sGuest = isset($aData['guest']) ? $aData['guest'] : 'unknown';
     if ($sText) {
         $oPost = Engine::GetEntity('PluginForum_Forum_Post');
         $oPost->setTitle($sTitle);
         $oPost->setUserIp(func_getIp());
         $oPost->setDateAdd(date('Y-m-d H:i:s'));
         $oPost->setTextHash(md5($sText));
         $oPost->setTextSource($sText);
         $oPost->setText($this->PluginForum_Forum_TextParse($sText));
         if ($sUser) {
             $oPost->setUserId($sUser);
         } else {
             $oPost->setUserId(0);
             $oPost->setGuestName(strip_tags($sGuest));
         }
         if ($sTopic) {
             $oPost->setTopicId($sTopic);
             return $this->PluginForum_Forum_AddPost($oPost);
         } else {
             return $oPost;
         }
     }
     return null;
 }
 /**
  * Обработка добавление комментария к топику через ajax
  */
 protected function AjaxAddComment()
 {
     $this->Viewer_SetResponseAjax();
     $isGuest = false;
     /**
      * Проверям авторизован ли пользователь
      */
     if (!$this->User_IsAuthorization()) {
         $this->oUserCurrent = $this->User_GetUserById(0);
         $isGuest = true;
         if (!Config::Get('plugin.guestcomments.enabled')) {
             $this->Message_AddErrorSingle($this->Lang_Get('need_authorization'), $this->Lang_Get('error'));
             return;
         }
         if (!func_check(getRequest("guest_name"), "text", 2, 20)) {
             $this->Message_AddErrorSingle($this->Lang_Get('plugin.guestcomments.error_name'), $this->Lang_Get('error'));
             return;
         }
         if (!func_check(getRequest("guest_email"), "mail")) {
             $this->Message_AddErrorSingle($this->Lang_Get('plugin.guestcomments.error_mail'), $this->Lang_Get('error'));
             return;
         }
         if (!isset($_SESSION['captcha_keystring']) or $_SESSION['captcha_keystring'] != strtolower(getRequest('captcha'))) {
             $this->Message_AddErrorSingle($this->Lang_Get('plugin.guestcomments.error_captcha'), $this->Lang_Get('error'));
             return;
         }
     }
     /**
      * Проверяем топик
      */
     if (!($oTopic = $this->Topic_GetTopicById(getRequest('cmt_target_id')))) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Возможность постить коммент в топик в черновиках
      */
     if (!$oTopic->getPublish() and $this->oUserCurrent->getId() != $oTopic->getUserId() and !$this->oUserCurrent->isAdministrator()) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем разрешено ли постить комменты
      */
     if (!$this->ACL_CanPostComment($this->oUserCurrent) and !$this->oUserCurrent->isAdministrator()) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_acl'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем разрешено ли постить комменты по времени
      */
     if (!$this->ACL_CanPostCommentTime($this->oUserCurrent) and !$this->oUserCurrent->isAdministrator()) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_limit'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем запрет на добавления коммента автором топика
      */
     if ($oTopic->getForbidComment()) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_notallow'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем текст комментария
      */
     if ($isGuest == true) {
         $sText = nl2br(strip_tags(getRequest('comment_text')));
     } else {
         $sText = $this->Text_Parser(getRequest('comment_text'));
     }
     if (!func_check($sText, 'text', 2, 10000)) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_add_text_error'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверям на какой коммент отвечаем
      */
     $sParentId = (int) getRequest('reply');
     if (!func_check($sParentId, 'id')) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     $oCommentParent = null;
     if ($sParentId != 0) {
         /**
          * Проверяем существует ли комментарий на который отвечаем
          */
         if (!($oCommentParent = $this->Comment_GetCommentById($sParentId))) {
             $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
             return;
         }
         /**
          * Проверяем из одного топика ли новый коммент и тот на который отвечаем
          */
         if ($oCommentParent->getTargetId() != $oTopic->getId()) {
             $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
             return;
         }
     } else {
         /**
          * Корневой комментарий
          */
         $sParentId = null;
     }
     /**
      * Проверка на дублирующий коммент
      */
     if ($this->Comment_GetCommentUnique($oTopic->getId(), 'topic', $this->oUserCurrent->getId(), $sParentId, md5($sText))) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_spam'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Создаём коммент
      */
     $oCommentNew = Engine::GetEntity('Comment');
     $oCommentNew->setTargetId($oTopic->getId());
     $oCommentNew->setTargetType('topic');
     $oCommentNew->setTargetParentId($oTopic->getBlog()->getId());
     $oCommentNew->setUserId($this->oUserCurrent->getId());
     $oCommentNew->setText($sText);
     $oCommentNew->setDate(date("Y-m-d H:i:s"));
     $oCommentNew->setUserIp(func_getIp());
     $oCommentNew->setPid($sParentId);
     $oCommentNew->setTextHash(md5($sText));
     $oCommentNew->setPublish($oTopic->getPublish());
     if ($this->oUserCurrent->getId() == 0) {
         $oCommentNew->setGuestName(getRequest("guest_name"));
         $oCommentNew->setGuestEmail(getRequest("guest_email"));
         unset($_SESSION['captcha_keystring']);
     }
     /**
      * Добавляем коммент
      */
     $this->Hook_Run('comment_add_before', array('oCommentNew' => $oCommentNew, 'oCommentParent' => $oCommentParent, 'oTopic' => $oTopic));
     if ($this->Comment_AddComment($oCommentNew)) {
         $this->Hook_Run('comment_add_after', array('oCommentNew' => $oCommentNew, 'oCommentParent' => $oCommentParent, 'oTopic' => $oTopic));
         $this->Viewer_AssignAjax('sCommentId', $oCommentNew->getId());
         if ($oTopic->getPublish()) {
             /**
              * Добавляем коммент в прямой эфир если топик не в черновиках
              */
             $oCommentOnline = Engine::GetEntity('Comment_CommentOnline');
             $oCommentOnline->setTargetId($oCommentNew->getTargetId());
             $oCommentOnline->setTargetType($oCommentNew->getTargetType());
             $oCommentOnline->setTargetParentId($oCommentNew->getTargetParentId());
             $oCommentOnline->setCommentId($oCommentNew->getId());
             $this->Comment_AddCommentOnline($oCommentOnline);
         }
         /**
          * Сохраняем дату последнего коммента для юзера
          */
         $this->oUserCurrent->setDateCommentLast(date("Y-m-d H:i:s"));
         $this->User_Update($this->oUserCurrent);
         /**
          * Список емайлов на которые не нужно отправлять уведомление
          */
         $aExcludeMail = array($this->oUserCurrent->getMail());
         /**
          * Отправляем уведомление тому на чей коммент ответили
          */
         if ($oCommentParent and $oCommentParent->getUserId() != $oTopic->getUserId() and $oCommentNew->getUserId() != $oCommentParent->getUserId()) {
             $oUserAuthorComment = $oCommentParent->getUser();
             $aExcludeMail[] = $oUserAuthorComment->getMail();
             $this->Notify_SendCommentReplyToAuthorParentComment($oUserAuthorComment, $oTopic, $oCommentNew, $this->oUserCurrent);
         }
         /**
          * Отправка уведомления автору топика
          */
         $this->Subscribe_Send('topic_new_comment', $oTopic->getId(), 'notify.comment_new.tpl', $this->Lang_Get('notify_subject_comment_new'), array('oTopic' => $oTopic, 'oComment' => $oCommentNew, 'oUserComment' => $this->oUserCurrent), $aExcludeMail);
         /**
          * Добавляем событие в ленту
          */
         $this->Stream_write($oCommentNew->getUserId(), 'add_comment', $oCommentNew->getId(), $oTopic->getPublish() && $oTopic->getBlog()->getType() != 'close');
     } else {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
     }
 }
示例#19
0
 /**
  * Показывает страничку регистрации и обрабатывает её
  *
  * @return unknown
  */
 protected function EventIndex()
 {
     /**
      * Если нажали кнопку "Зарегистрироваться"
      */
     if (isPost('submit_register')) {
         //Проверяем  входные данные
         $bError = false;
         /**
          * Проверка логина
          */
         if (!func_check(getRequest('login'), 'login', 3, 30)) {
             $this->Message_AddError($this->Lang_Get('registration_login_error'), $this->Lang_Get('error'));
             $bError = true;
         }
         /**
          * Проверка мыла
          */
         if (!func_check(getRequest('mail'), 'mail')) {
             $this->Message_AddError($this->Lang_Get('registration_mail_error'), $this->Lang_Get('error'));
             $bError = true;
         }
         /**
          * Проверка пароля
          */
         if (!func_check(getRequest('password'), 'password', 5)) {
             $this->Message_AddError($this->Lang_Get('registration_password_error'), $this->Lang_Get('error'));
             $bError = true;
         } elseif (getRequest('password') != getRequest('password_confirm')) {
             $this->Message_AddError($this->Lang_Get('registration_password_error_different'), $this->Lang_Get('error'));
             $bError = true;
         }
         /**
          * Проверка капчи(циферки с картинки)
          */
         if (!isset($_SESSION['captcha_keystring']) or $_SESSION['captcha_keystring'] != strtolower(getRequest('captcha'))) {
             $this->Message_AddError($this->Lang_Get('registration_captcha_error'), $this->Lang_Get('error'));
             $bError = true;
         }
         /**
          * А не занят ли логин?
          */
         if ($this->User_GetUserByLogin(getRequest('login'))) {
             $this->Message_AddError($this->Lang_Get('registration_login_error_used'), $this->Lang_Get('error'));
             $bError = true;
         }
         /**
          * А не занято ли мыло?
          */
         if ($this->User_GetUserByMail(getRequest('mail'))) {
             $this->Message_AddError($this->Lang_Get('registration_mail_error_used'), $this->Lang_Get('error'));
             $bError = true;
         }
         /**
          * Если всё то пробуем зарегить
          */
         if (!$bError) {
             /**
              * Создаем юзера
              */
             $oUser = Engine::GetEntity('User');
             $oUser->setLogin(getRequest('login'));
             $oUser->setMail(getRequest('mail'));
             $oUser->setPassword(func_encrypt(getRequest('password')));
             $oUser->setDateRegister(date("Y-m-d H:i:s"));
             $oUser->setIpRegister(func_getIp());
             /**
              * Если используется активация, то генерим код активации
              */
             if (Config::Get('general.reg.activation')) {
                 $oUser->setActivate(0);
                 $oUser->setActivateKey(md5(func_generator() . time()));
             } else {
                 $oUser->setActivate(1);
                 $oUser->setActivateKey(null);
             }
             /**
              * Регистрируем
              */
             if ($this->User_Add($oUser)) {
                 /**
                  * Убиваем каптчу
                  */
                 unset($_SESSION['captcha_keystring']);
                 /**
                  * Создаем персональный блог
                  */
                 $this->Blog_CreatePersonalBlog($oUser);
                 /**
                  * Если юзер зарегистрировался по приглашению то обновляем инвайт
                  */
                 if (Config::Get('general.reg.invite') and $oInvite = $this->User_GetInviteByCode($this->GetInviteRegister())) {
                     $oInvite->setUserToId($oUser->getId());
                     $oInvite->setDateUsed(date("Y-m-d H:i:s"));
                     $oInvite->setUsed(1);
                     $this->User_UpdateInvite($oInvite);
                 }
                 /**
                  * Если стоит регистрация с активацией то проводим её
                  */
                 if (Config::Get('general.reg.activation')) {
                     /**
                      * Отправляем на мыло письмо о подтверждении регистрации						 
                      */
                     $this->Notify_SendRegistrationActivate($oUser, getRequest('password'));
                     Router::Location(Router::GetPath('registration') . 'confirm/');
                 } else {
                     $this->Notify_SendRegistration($oUser, getRequest('password'));
                     $this->Viewer_Assign('bRefreshToHome', true);
                     $oUser = $this->User_GetUserById($oUser->getId());
                     $this->User_Authorization($oUser, false);
                     $this->SetTemplateAction('ok');
                     $this->DropInviteRegister();
                 }
             } else {
                 $this->Message_AddErrorSingle($this->Lang_Get('system_error'));
                 return Router::Action('error');
             }
         }
     }
 }
示例#20
0
 /**
  * Создает подписку, если уже есть, то возвращает существующую
  *
  * @param string $sTargetType Тип
  * @param string $sTargetId ID владельца
  * @param string $sMail Емайл
  * @return ModuleSubscribe_EntitySubscribe|bool
  */
 public function AddSubscribeSimple($sTargetType, $sTargetId, $sMail, $sUserId = null)
 {
     if (!$sMail) {
         return false;
     }
     if (!($oSubscribe = $this->Subscribe_GetSubscribeByTargetAndMail($sTargetType, $sTargetId, $sMail))) {
         $oSubscribe = Engine::GetEntity('Subscribe');
         $oSubscribe->setTargetType($sTargetType);
         $oSubscribe->setTargetId($sTargetId);
         $oSubscribe->setMail($sMail);
         $oSubscribe->setDateAdd(date("Y-m-d H:i:s"));
         $oSubscribe->setKey(func_generator(32));
         $oSubscribe->setIp(func_getIp());
         $oSubscribe->setStatus(1);
         /**
          * Если только для авторизованных, то добавляем user_id
          */
         if ($sUserId and !$this->IsAllowTargetForGuest($sTargetType)) {
             $oSubscribe->setUserId($sUserId);
         }
         $this->Subscribe_AddSubscribe($oSubscribe);
     }
     return $oSubscribe;
 }
 /**
  * Create topic comment with default values
  *
  * @param object $oTopic
  * @param object $oUser
  * @param integer $iParentId
  * @param string $sText
  *
  * @return ModuleComment_EntityComment
  */
 protected function _createComment($oTopic, $oUser, $iParentId = null, $sText = 'fixture comment text')
 {
     $oComment = Engine::GetEntity('Comment');
     $oComment->setTargetId($oTopic->getId());
     $oComment->setTargetType('topic');
     $oComment->setTargetParentId($oTopic->getBlogId());
     $oComment->setUserId($oUser->getId());
     $oComment->setText($sText);
     $oComment->setDate(date('Y-m-d H:i:s', time()));
     $oComment->setUserIp(func_getIp());
     $oComment->setPid($iParentId);
     $oComment->setTextHash(md5($sText));
     $oComment->setPublish(true);
     $oComment = $this->oEngine->Comment_AddComment($oComment);
     return $oComment;
 }
示例#22
0
 protected function EventAjaxReceptiondeskSetQuestion()
 {
     $this->Viewer_SetResponseAjax('jsonIframe', false);
     $oQuestion = Engine::GetEntity('PluginReceptiondesk_ModuleQuestion_EntityQuestion');
     $oQuestion->_setValidateScenario('receptiondesk_question');
     $oQuestion->setCategoryId(getRequestStr('question_category_id'));
     $oQuestion->setTextSource(getRequestStr('question_text'));
     $oQuestion->setText($this->Text_Parser($oQuestion->getTextSource()));
     $oQuestion->setCaptcha(getRequestStr('question_captcha'));
     $oQuestion->setUserIp(func_getIp());
     $oQuestion->setTextHash(md5($oQuestion->getTextSource() . $oQuestion->getUserIp()));
     $oQuestion->setAuthorValidMail(getRequestStr('question_author_mail'));
     if ($oQuestion->_Validate()) {
         $oQuestion->setDateAdd(date("Y-m-d H:i:s"));
         $oQuestion->setAuthorMail($oQuestion->getAuthorValidMail());
         $oQuestion->setAuthorName(strip_tags(getRequestStr('question_author_name')));
         $oQuestion->setAuthorAddress(strip_tags(getRequestStr('question_author_address')));
         $oQuestion->setAuthorPhone(strip_tags(getRequestStr('question_author_phone')));
         getRequestStr('question_text_hide') != '' ? $oQuestion->setTextHide(1) : $oQuestion->setTextHide(0);
         getRequestStr('question_author_mail_hide') != '' && $oQuestion->getAuthorMail() ? $oQuestion->setAuthorMailHide(1) : $oQuestion->setAuthorMailHide(0);
         getRequestStr('question_author_name_hide') != '' && $oQuestion->getAuthorName() ? $oQuestion->setAuthorNameHide(1) : $oQuestion->setAuthorNameHide(0);
         getRequestStr('question_author_address_hide') != '' && $oQuestion->getAuthorAddress() ? $oQuestion->setAuthorAddressHide(1) : $oQuestion->setAuthorAddressHide(0);
         getRequestStr('question_author_phone_hide') != '' && $oQuestion->getAuthorPhone() ? $oQuestion->setAuthorPhoneHide(1) : $oQuestion->setAuthorPhoneHide(0);
         if (!$this->PluginReceptiondesk_Question_AddQuestion($oQuestion)) {
             $this->Message_AddErrorSingle($this->Lang_Get('system_error'));
             return;
         }
         unset($_SESSION['captcha_keystring']);
         $sTarget = empty($_COOKIE['ls_receptiondesk_file_target_tmp']) ? null : $_COOKIE['ls_receptiondesk_file_target_tmp'];
         if ($sTarget) {
             $this->PluginReceptiondesk_Tools_UpdateFile($oQuestion->getId(), $sTarget);
             setcookie('ls_receptiondesk_file_target_tmp', null);
         }
         if (Config::Get('plugin.receptiondesk.receptiondesk_create_send_admin')) {
             $this->PluginReceptiondesk_Tools_SendNewQuestionMail($oQuestion);
         }
         $this->Viewer_AssignAjax('sUrlRedirect', Router::GetPath('receptiondesk'));
         $this->Message_AddNoticeSingle($this->Lang_Get('plugin.receptiondesk.receptiondesk_admin_question_create_ok'));
     } else {
         $this->Viewer_AssignAjax('aErrors', $oQuestion->_getValidateErrors());
     }
 }
 /**
  * Обработка формы добавление поста
  *
  */
 protected function submitPostAdd($oForum = null, $oTopic = null)
 {
     if (!($oForum && $oTopic)) {
         return false;
     }
     /**
      * Проверяем разрешено ли постить
      */
     if (!$this->ACL_CanAddForumPost($this->oUserCurrent)) {
         $this->Message_AddErrorSingle($this->Lang_Get('plugin.forum.reply_not_allow'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем разрешено ли постить по времени
      */
     if (!$this->ACL_CanAddForumPostTime($this->oUserCurrent)) {
         $this->Message_AddErrorSingle($this->Lang_Get('plugin.forum.reply_time_limit'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем не закрыто ли обсуждение
      */
     if ($oTopic->getState() == 1 and !$this->ACL_CanAddForumPostClose($this->oUserCurrent)) {
         $this->Message_AddErrorSingle($this->Lang_Get('plugin.forum.reply_not_allow_close'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Создаём
      */
     $oPost = Engine::GetEntity('PluginForum_Forum_Post');
     $oPost->_setValidateScenario('post');
     /**
      * Заполняем поля для валидации
      */
     $oPost->setTitle(forum_parse_title(getRequestStr('post_title')));
     $oPost->setTopicId($oTopic->getId());
     $oPost->setUserIp(func_getIp());
     $oPost->setText($this->PluginForum_Forum_TextParse(getRequestStr('post_text')));
     $oPost->setTextSource(getRequestStr('post_text'));
     $oPost->setTextHash(md5(getRequestStr('post_text')));
     $oPost->setDateAdd(date('Y-m-d H:i:s'));
     if (!$this->User_IsAuthorization()) {
         $oPost->setUserId(0);
         $oPost->setGuestName(strip_tags(getRequestStr('guest_name')));
     } else {
         $oPost->setUserId($this->oUserCurrent->getId());
     }
     if (getRequestStr('replyto')) {
         $oPost->setParentId((int) getRequestStr('replyto'));
     }
     /**
      * Вложения
      */
     $sTargetTmp = isset($_COOKIE['ls_fattach_target_tmp']) ? $_COOKIE['ls_fattach_target_tmp'] : 'null';
     $aFiles = $this->PluginForum_Forum_GetFileItemsByTargetTmp($sTargetTmp);
     /**
      * Проверяем поля формы
      */
     if (!$this->checkPostFields($oPost)) {
         return false;
     }
     /**
      * Вызов хуков
      */
     $this->Hook_Run('forum_post_add_before', array('oPost' => $oPost, 'oTopic' => $oTopic, 'oForum' => $oForum));
     /**
      * Добавляем
      */
     if ($this->PluginForum_Forum_AddPost($oPost)) {
         $this->Hook_Run('forum_post_add_after', array('oPost' => $oPost, 'oTopic' => $oTopic, 'oForum' => $oForum));
         /**
          * Привязываем вложения к id поста
          * TODO: здесь нужно это делать одним запросом, а не перебором сущностей
          */
         if (count($aFiles)) {
             foreach ($aFiles as $oFile) {
                 $oFile->setTargetTmp(null);
                 $this->PluginForum_Forum_UpdateFile($oFile);
                 $oPost->files->add($oFile);
             }
             $oPost->Update();
             $this->PluginForum_Forum_UpdatePost($oPost);
         }
         /**
          * Удаляем временную куку
          */
         setcookie('ls_fattach_target_tmp', null);
         /**
          * Обновляем инфу в топике
          */
         $oTopic->setLastPostId($oPost->getId());
         $oTopic->setLastPostDate($oPost->getDateAdd());
         $oTopic->setCountPost((int) $oTopic->getCountPost() + 1);
         $this->PluginForum_Forum_SaveTopic($oTopic);
         /**
          * Обновляем инфу в форуме
          */
         $oForum->setLastPostId($oPost->getId());
         $oForum->setLastPostDate($oPost->getDateAdd());
         $oForum->setCountPost((int) $oForum->getCountPost() + 1);
         $this->PluginForum_Forum_SaveForum($oForum);
         /**
          * Обновляем инфу о пользователе
          */
         $this->PluginForum_Forum_increaseUserPosts($this->oUserCurrent);
         /**
          * Список емайлов на которые не нужно отправлять уведомление
          */
         $aExcludeMail = array();
         if ($this->oUserCurrent) {
             /**
              * Исключаем автора поста из списка рассылки
              */
             $aExcludeMail[] = $this->oUserCurrent->getMail();
             /**
              * Добавляем событие в ленту
              */
             $this->Stream_write($oPost->getUserId(), 'add_forum_post', $oPost->getId());
         }
         /**
          * Отправка уведомления подписчикам темы
          */
         $this->PluginForum_Forum_SendSubscribeNewPost($oTopic->getId(), array('oForum' => $oForum, 'oTopic' => $oTopic, 'oPost' => $oPost, 'oUser' => $this->oUserCurrent), $aExcludeMail);
         /**
          * Отправка уведомления на отвеченные посты
          */
         $this->PluginForum_Forum_SendNotifyReply($oPost, $aExcludeMail);
         Router::Location($oPost->getUrlFull());
     } else {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'));
         return Router::Action('error');
     }
 }
 /**
  * Обработка добавление комментария к топику
  *
  */
 protected function SubmitComment()
 {
     $oTopic = $this->Topic_GetTopicById(getRequestStr('comment_target_id'));
     $sText = getRequestStr('comment_text');
     $sParentId = (int) getRequest('reply');
     $oCommentParent = null;
     if (!$sParentId) {
         /**
          * Корневой комментарий
          */
         $sParentId = null;
     } else {
         /**
          * Родительский комментарий
          */
         $oCommentParent = $this->Comment_GetCommentById($sParentId);
     }
     /**
      * Проверка на соответсвие комментария требованиям безопасности
      */
     if (!$this->CheckComment($oTopic, $sText)) {
         return;
     }
     /**
      * Проверка на соответсвие комментария родительскому коментарию
      */
     if (!$this->CheckParentComment($oTopic, $sText, $oCommentParent)) {
         return;
     }
     /**
      * Создаём коммент
      */
     $oCommentNew = Engine::GetEntity('Comment');
     $oCommentNew->setTargetId($oTopic->getId());
     $oCommentNew->setTargetType('topic');
     $oCommentNew->setTargetParentId($oTopic->getBlog()->getId());
     $oCommentNew->setUserId($this->oUserCurrent->getId());
     $oCommentNew->setText($this->Text_Parser($sText));
     $oCommentNew->setTextSource($sText);
     $oCommentNew->setDate(date("Y-m-d H:i:s"));
     $oCommentNew->setUserIp(func_getIp());
     $oCommentNew->setPid($sParentId);
     $oCommentNew->setTextHash(md5($sText));
     $oCommentNew->setPublish($oTopic->getPublish());
     /**
      * Добавляем коммент
      */
     $this->Hook_Run('comment_add_before', array('oCommentNew' => $oCommentNew, 'oCommentParent' => $oCommentParent, 'oTopic' => $oTopic));
     if ($this->Comment_AddComment($oCommentNew)) {
         $this->Hook_Run('comment_add_after', array('oCommentNew' => $oCommentNew, 'oCommentParent' => $oCommentParent, 'oTopic' => $oTopic));
         $this->Viewer_AssignAjax('sCommentId', $oCommentNew->getId());
         if ($oTopic->getPublish()) {
             /**
              * Добавляем коммент в прямой эфир если топик не в черновиках
              */
             $oCommentOnline = Engine::GetEntity('Comment_CommentOnline');
             $oCommentOnline->setTargetId($oCommentNew->getTargetId());
             $oCommentOnline->setTargetType($oCommentNew->getTargetType());
             $oCommentOnline->setTargetParentId($oCommentNew->getTargetParentId());
             $oCommentOnline->setCommentId($oCommentNew->getId());
             $this->Comment_AddCommentOnline($oCommentOnline);
         }
         /**
          * Сохраняем дату последнего коммента для юзера
          */
         $this->oUserCurrent->setDateCommentLast(date("Y-m-d H:i:s"));
         $this->User_Update($this->oUserCurrent);
         /**
          * Фиксируем ID у media файлов комментария
          */
         $this->Media_ReplaceTargetTmpById('comment', $oCommentNew->getId());
         /**
          * Список емайлов на которые не нужно отправлять уведомление
          */
         $aExcludeMail = array($this->oUserCurrent->getMail());
         /**
          * Отправляем уведомление тому на чей коммент ответили
          */
         if ($oCommentParent and $oCommentParent->getUserId() != $oTopic->getUserId() and $oCommentNew->getUserId() != $oCommentParent->getUserId()) {
             $oUserAuthorComment = $oCommentParent->getUser();
             $aExcludeMail[] = $oUserAuthorComment->getMail();
             $this->Topic_SendNotifyCommentReplyToAuthorParentComment($oUserAuthorComment, $oTopic, $oCommentNew, $this->oUserCurrent);
         }
         /**
          * Отправка уведомления автору топика
          */
         $this->Subscribe_Send('topic_new_comment', $oTopic->getId(), 'comment_new.tpl', $this->Lang_Get('emails.comment_new.subject'), array('oTopic' => $oTopic, 'oComment' => $oCommentNew, 'oUserComment' => $this->oUserCurrent), $aExcludeMail);
         /**
          * Добавляем событие в ленту
          */
         $this->Stream_write($oCommentNew->getUserId(), 'add_comment', $oCommentNew->getId(), $oTopic->getPublish() && $oTopic->getBlog()->getType() != 'close');
     } else {
         $this->Message_AddErrorSingle($this->Lang_Get('common.error.system.base'), $this->Lang_Get('common.error.error'));
     }
 }
示例#25
0
 /**
  * Проверяет может ли пользователь оставлять посты по времени
  *
  * @param Entity_User $oUser
  * @return bool
  */
 public function CanAddForumPostTime($oUser = null)
 {
     if ($oUser) {
         /**
          * Для администраторов ограничение по времени не действует
          */
         if ($oUser->isAdministrator()) {
             return true;
         }
         /**
          * Органичение по времени выключено
          */
         if (Config::Get('plugin.forum.acl.create.comment.time') == 0) {
             return true;
         }
         /**
          * Отключение ограничения по времени по рейтингу
          */
         if ($oUser->getRating() >= Config::Get('plugin.forum.acl.create.comment.time_rating')) {
             return true;
         }
         /**
          * Проверяем, если пост опубликованный меньше чем plugni.forum.acl.create.post.time секунд назад
          */
         $aPosts = $this->PluginForum_Forum_GetPostItemsByFilter(array('#where' => array('user_id = ?d' => array($oUser->getId()), 'post_date_add >= ?' => array(date("Y-m-d H:i:s", time() - Config::Get('plugin.forum.acl.create.post.time'))))));
         if (count($aPosts) > 0) {
             return false;
         }
     } else {
         /**
          * Для гостей проверяем последние посты по IP
          */
         $aPosts = $this->PluginForum_Forum_GetPostItemsByFilter(array('#where' => array('post_user_ip = ?' => array(func_getIp()), 'post_date_add >= ?' => array(date("Y-m-d H:i:s", time() - Config::Get('plugin.forum.acl.create.post.time'))))));
         if (count($aPosts) > 0) {
             return false;
         }
     }
     return true;
 }
示例#26
0
 /**
  * Обработка редактирования топика
  *
  * @param unknown_type $oTopic
  * @return unknown
  */
 protected function SubmitEdit($oTopic)
 {
     /**
      * Проверка корректности полей формы
      */
     if (!$this->checkTopicFields()) {
         return false;
     }
     /**
      * Определяем в какой блог делаем запись
      */
     $iBlogId = getRequest('blog_id');
     if ($iBlogId == 0) {
         $oBlog = $this->Blog_GetPersonalBlogByUserId($oTopic->getUserId());
     } else {
         $oBlog = $this->Blog_GetBlogById($iBlogId);
     }
     /**
      * Если блог не определен выдаем предупреждение
      */
     if (!$oBlog) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_create_blog_error_unknown'), $this->Lang_Get('error'));
         return false;
     }
     /**
      * Проверяем права на постинг в блог
      */
     if (!$this->ACL_IsAllowBlog($oBlog, $this->oUserCurrent)) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_create_blog_error_noallow'), $this->Lang_Get('error'));
         return false;
     }
     /**
      * Проверяем разрешено ли постить топик по времени
      */
     if (isPost('submit_topic_publish') and !$oTopic->getPublishDraft() and !$this->ACL_CanPostTopicTime($this->oUserCurrent)) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_time_limit'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Теперь можно смело редактировать топик
      */
     $oTopic->setBlogId($oBlog->getId());
     $oTopic->setTitle(getRequest('topic_title'));
     $oTopic->setText(htmlspecialchars(getRequest('topic_text')));
     $oTopic->setTextShort(htmlspecialchars(getRequest('topic_text')));
     $oTopic->setTextSource(getRequest('topic_text'));
     $oTopic->setLinkUrl(getRequest('topic_link_url'));
     $oTopic->setTags(getRequest('topic_tags'));
     $oTopic->setUserIp(func_getIp());
     $oTopic->setTextHash(md5($oTopic->getType() . $oTopic->getText() . $oTopic->getLinkUrl()));
     /**
      * Проверяем топик на уникальность
      */
     if ($oTopicEquivalent = $this->Topic_GetTopicUnique($this->oUserCurrent->getId(), $oTopic->getTextHash())) {
         if ($oTopicEquivalent->getId() != $oTopic->getId()) {
             $this->Message_AddErrorSingle($this->Lang_Get('topic_create_text_error_unique'), $this->Lang_Get('error'));
             return false;
         }
     }
     /**
      * Публикуем или сохраняем в черновиках
      */
     $bSendNotify = false;
     if (isset($_REQUEST['submit_topic_publish'])) {
         $oTopic->setPublish(1);
         if ($oTopic->getPublishDraft() == 0) {
             $oTopic->setPublishDraft(1);
             $oTopic->setDateAdd(date("Y-m-d H:i:s"));
             $bSendNotify = true;
         }
     } else {
         $oTopic->setPublish(0);
     }
     /**
      * Принудительный вывод на главную
      */
     if ($this->oUserCurrent->isAdministrator()) {
         if (getRequest('topic_publish_index')) {
             $oTopic->setPublishIndex(1);
         } else {
             $oTopic->setPublishIndex(0);
         }
     }
     /**
      * Запрет на комментарии к топику
      */
     $oTopic->setForbidComment(0);
     if (getRequest('topic_forbid_comment')) {
         $oTopic->setForbidComment(1);
     }
     $this->Hook_Run('topic_edit_before', array('oTopic' => $oTopic, 'oBlog' => $oBlog));
     /**
      * Сохраняем топик
      */
     if ($this->Topic_UpdateTopic($oTopic)) {
         $this->Hook_Run('topic_edit_after', array('oTopic' => $oTopic, 'oBlog' => $oBlog, 'bSendNotify' => &$bSendNotify));
         /**
          * Рассылаем о новом топике подписчикам блога
          */
         if ($bSendNotify) {
             $this->Topic_SendNotifyTopicNew($oBlog, $oTopic, $this->oUserCurrent);
         }
         if (!$oTopic->getPublish() and !$this->oUserCurrent->isAdministrator() and $this->oUserCurrent->getId() != $oTopic->getUserId()) {
             Router::Location($oBlog->getUrlFull());
         }
         Router::Location($oTopic->getUrl());
     } else {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'));
         return Router::Action('error');
     }
 }
示例#27
0
 /**
  * Обработка добавление комментария к письму
  *
  */
 protected function SubmitComment()
 {
     /**
      * Проверям авторизован ли пользователь
      */
     if (!$this->User_IsAuthorization()) {
         $this->Message_AddErrorSingle($this->Lang_Get('common.error.need_authorization'), $this->Lang_Get('common.error.error'));
         return;
     }
     /**
      * Проверяем разговор
      */
     if (!($oTalk = $this->Talk_GetTalkById(getRequestStr('comment_target_id')))) {
         return $this->EventErrorDebug();
     }
     if (!($oTalkUser = $this->Talk_GetTalkUser($oTalk->getId(), $this->oUserCurrent->getId()))) {
         return $this->EventErrorDebug();
     }
     if (!in_array($oTalkUser->getUserActive(), array(ModuleTalk::TALK_USER_ACTIVE))) {
         return $this->EventErrorDebug();
     }
     /**
      * Проверяем разрешено ли постить комменты
      */
     if (!$this->ACL_CanPostTalkComment($this->oUserCurrent)) {
         $this->Message_AddErrorSingle($this->Rbac_GetMsgLast());
         return;
     }
     /**
      * Проверяем текст комментария
      */
     $sText = getRequestStr('comment_text');
     if (!func_check($sText, 'text', 2, 3000)) {
         $this->Message_AddErrorSingle($this->Lang_Get('talk.message.notices.error_text'), $this->Lang_Get('common.error.error'));
         return;
     }
     /**
      * Проверям на какой коммент отвечаем
      */
     $sParentId = (int) getRequest('reply');
     if (!func_check($sParentId, 'id')) {
         return $this->EventErrorDebug();
     }
     $oCommentParent = null;
     if ($sParentId != 0) {
         /**
          * Проверяем существует ли комментарий на который отвечаем
          */
         if (!($oCommentParent = $this->Comment_GetCommentById($sParentId))) {
             return $this->EventErrorDebug();
         }
         /**
          * Проверяем из одного топика ли новый коммент и тот на который отвечаем
          */
         if ($oCommentParent->getTargetId() != $oTalk->getId()) {
             return $this->EventErrorDebug();
         }
     } else {
         /**
          * Корневой комментарий
          */
         $sParentId = null;
     }
     /**
      * Проверка на дублирующий коммент
      */
     if ($this->Comment_GetCommentUnique($oTalk->getId(), 'talk', $this->oUserCurrent->getId(), $sParentId, md5($sText))) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic.comments.notices.spam'), $this->Lang_Get('common.error.error'));
         return;
     }
     /**
      * Создаём коммент
      */
     $oCommentNew = Engine::GetEntity('Comment');
     $oCommentNew->setTargetId($oTalk->getId());
     $oCommentNew->setTargetType('talk');
     $oCommentNew->setUserId($this->oUserCurrent->getId());
     $oCommentNew->setText($this->Text_Parser($sText));
     $oCommentNew->setTextSource($sText);
     $oCommentNew->setDate(date("Y-m-d H:i:s"));
     $oCommentNew->setUserIp(func_getIp());
     $oCommentNew->setPid($sParentId);
     $oCommentNew->setTextHash(md5($sText));
     $oCommentNew->setPublish(1);
     /**
      * Добавляем коммент
      */
     $this->Hook_Run('talk_comment_add_before', array('oCommentNew' => $oCommentNew, 'oCommentParent' => $oCommentParent, 'oTalk' => $oTalk));
     if ($this->Comment_AddComment($oCommentNew)) {
         $this->Hook_Run('talk_comment_add_after', array('oCommentNew' => $oCommentNew, 'oCommentParent' => $oCommentParent, 'oTalk' => $oTalk));
         $this->Viewer_AssignAjax('sCommentId', $oCommentNew->getId());
         $oTalk->setDateLast(date("Y-m-d H:i:s"));
         $oTalk->setUserIdLast($oCommentNew->getUserId());
         $oTalk->setCommentIdLast($oCommentNew->getId());
         $oTalk->setCountComment($oTalk->getCountComment() + 1);
         $this->Talk_UpdateTalk($oTalk);
         /**
          * Отсылаем уведомления всем адресатам
          */
         $aUsersTalk = $this->Talk_GetUsersTalk($oTalk->getId(), ModuleTalk::TALK_USER_ACTIVE);
         foreach ($aUsersTalk as $oUserTalk) {
             if ($oUserTalk->getId() != $oCommentNew->getUserId()) {
                 $this->Talk_SendNotifyTalkCommentNew($oUserTalk, $this->oUserCurrent, $oTalk, $oCommentNew);
             }
         }
         /**
          * Увеличиваем число новых комментов
          */
         $this->Talk_increaseCountCommentNew($oTalk->getId(), $oCommentNew->getUserId());
     } else {
         return $this->EventErrorDebug();
     }
 }
 /**
  * Обработка Ajax регистрации
  */
 protected function EventAjaxRegistration()
 {
     /**
      * Устанавливаем формат Ajax ответа
      */
     $this->Viewer_SetResponseAjax('json');
     /**
      * Создаем объект пользователя и устанавливаем сценарий валидации
      */
     $oUser = Engine::GetEntity('ModuleUser_EntityUser');
     $oUser->_setValidateScenario('registration');
     /**
      * Заполняем поля (данные)
      */
     $oUser->setLogin(getRequestStr('login'));
     $oUser->setMail(getRequestStr('mail'));
     $oUser->setPassword(getRequestStr('password'));
     $oUser->setPasswordConfirm(getRequestStr('password_confirm'));
     $oUser->setCaptcha(getRequestStr('captcha'));
     $oUser->setDateRegister(date("Y-m-d H:i:s"));
     $oUser->setIpRegister(func_getIp());
     /**
      * Если используется активация, то генерим код активации
      */
     if (Config::Get('general.reg.activation')) {
         $oUser->setActivate(0);
         $oUser->setActivateKey(md5(func_generator() . time()));
     } else {
         $oUser->setActivate(1);
         $oUser->setActivateKey(null);
     }
     $this->Hook_Run('registration_validate_before', array('oUser' => $oUser));
     /**
      * Запускаем валидацию
      */
     if ($oUser->_Validate()) {
         $this->Hook_Run('registration_validate_after', array('oUser' => $oUser));
         $oUser->setPassword(md5($oUser->getPassword()));
         if ($this->User_Add($oUser)) {
             $this->Hook_Run('registration_after', array('oUser' => $oUser));
             /**
              * Убиваем каптчу
              */
             unset($_SESSION['captcha_keystring']);
             /**
              * Подписываем пользователя на дефолтные события в ленте активности
              */
             $this->Stream_switchUserEventDefaultTypes($oUser->getId());
             /**
              * Если юзер зарегистрировался по приглашению то обновляем инвайт
              */
             if (Config::Get('general.reg.invite') and $oInvite = $this->User_GetInviteByCode($this->GetInviteRegister())) {
                 $oInvite->setUserToId($oUser->getId());
                 $oInvite->setDateUsed(date("Y-m-d H:i:s"));
                 $oInvite->setUsed(1);
                 $this->User_UpdateInvite($oInvite);
             }
             /**
              * Если стоит регистрация с активацией то проводим её
              */
             if (Config::Get('general.reg.activation')) {
                 /**
                  * Отправляем на мыло письмо о подтверждении регистрации
                  */
                 $this->Notify_SendRegistrationActivate($oUser, getRequestStr('password'));
                 $this->Viewer_AssignAjax('sUrlRedirect', Router::GetPath('registration') . 'confirm/');
             } else {
                 $this->Notify_SendRegistration($oUser, getRequestStr('password'));
                 $oUser = $this->User_GetUserById($oUser->getId());
                 /**
                  * Сразу авторизуем
                  */
                 $this->User_Authorization($oUser, false);
                 $this->DropInviteRegister();
                 /**
                  * Определяем URL для редиректа после авторизации
                  */
                 $sUrl = Config::Get('module.user.redirect_after_registration');
                 if (getRequestStr('return-path')) {
                     $sUrl = getRequestStr('return-path');
                 }
                 $this->Viewer_AssignAjax('sUrlRedirect', $sUrl ? $sUrl : Config::Get('path.root.web'));
                 $this->Message_AddNoticeSingle($this->Lang_Get('registration_ok'));
             }
         } else {
             $this->Message_AddErrorSingle($this->Lang_Get('system_error'));
             return;
         }
     } else {
         /**
          * Получаем ошибки
          */
         $this->Viewer_AssignAjax('aErrors', $oUser->_getValidateErrors());
     }
 }
示例#29
0
 /**
  * Обработка добавление комментария к топику
  *	 
  * @return bool
  */
 protected function SubmitComment()
 {
     /**
      * Проверям авторизован ли пользователь
      */
     if (!$this->User_IsAuthorization()) {
         $this->Message_AddErrorSingle($this->Lang_Get('need_authorization'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем топик
      */
     if (!($oTopic = $this->Topic_GetTopicById(getRequest('cmt_target_id')))) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Возможность постить коммент в топик в черновиках
      */
     if (!$oTopic->getPublish() and $this->oUserCurrent->getId() != $oTopic->getUserId() and !$this->oUserCurrent->isAdministrator()) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем разрешено ли постить комменты
      */
     if (!$this->ACL_CanPostComment($this->oUserCurrent) and !$this->oUserCurrent->isAdministrator()) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_acl'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем разрешено ли постить комменты по времени
      */
     if (!$this->ACL_CanPostCommentTime($this->oUserCurrent) and !$this->oUserCurrent->isAdministrator()) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_limit'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем запрет на добавления коммента автором топика
      */
     if ($oTopic->getForbidComment()) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_notallow'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем текст комментария
      */
     $sText = $this->Text_Parser(getRequest('comment_text'));
     if (!func_check($sText, 'text', 2, 10000)) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_add_text_error'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверям на какой коммент отвечаем
      */
     $sParentId = (int) getRequest('reply');
     if (!func_check($sParentId, 'id')) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     $oCommentParent = null;
     if ($sParentId != 0) {
         /**
          * Проверяем существует ли комментарий на который отвечаем
          */
         if (!($oCommentParent = $this->Comment_GetCommentById($sParentId))) {
             $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
             return;
         }
         /**
          * Проверяем из одного топика ли новый коммент и тот на который отвечаем
          */
         if ($oCommentParent->getTargetId() != $oTopic->getId()) {
             $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
             return;
         }
     } else {
         /**
          * Корневой комментарий
          */
         $sParentId = null;
     }
     /**
      * Проверка на дублирующий коммент
      */
     if ($this->Comment_GetCommentUnique($oTopic->getId(), 'topic', $this->oUserCurrent->getId(), $sParentId, md5($sText))) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_spam'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Создаём коммент
      */
     $oCommentNew = Engine::GetEntity('Comment');
     $oCommentNew->setTargetId($oTopic->getId());
     $oCommentNew->setTargetType('topic');
     $oCommentNew->setTargetParentId($oTopic->getBlog()->getId());
     $oCommentNew->setUserId($this->oUserCurrent->getId());
     $oCommentNew->setText($sText);
     $oCommentNew->setDate(date("Y-m-d H:i:s"));
     $oCommentNew->setUserIp(func_getIp());
     $oCommentNew->setPid($sParentId);
     $oCommentNew->setTextHash(md5($sText));
     /**
      * Добавляем коммент
      */
     $this->Hook_Run('comment_add_before', array('oCommentNew' => $oCommentNew, 'oCommentParent' => $oCommentParent, 'oTopic' => $oTopic));
     if ($this->Comment_AddComment($oCommentNew)) {
         $this->Hook_Run('comment_add_after', array('oCommentNew' => $oCommentNew, 'oCommentParent' => $oCommentParent, 'oTopic' => $oTopic));
         $this->Viewer_AssignAjax('sCommentId', $oCommentNew->getId());
         if ($oTopic->getPublish()) {
             /**
              * Добавляем коммент в прямой эфир если топик не в черновиках
              */
             $oCommentOnline = Engine::GetEntity('Comment_CommentOnline');
             $oCommentOnline->setTargetId($oCommentNew->getTargetId());
             $oCommentOnline->setTargetType($oCommentNew->getTargetType());
             $oCommentOnline->setTargetParentId($oCommentNew->getTargetParentId());
             $oCommentOnline->setCommentId($oCommentNew->getId());
             $this->Comment_AddCommentOnline($oCommentOnline);
         }
         /**
          * Сохраняем дату последнего коммента для юзера
          */
         $this->oUserCurrent->setDateCommentLast(date("Y-m-d H:i:s"));
         $this->User_Update($this->oUserCurrent);
         /**
          * Отправка уведомления автору топика
          */
         $oUserTopic = $oTopic->getUser();
         if ($oCommentNew->getUserId() != $oUserTopic->getId()) {
             $this->Notify_SendCommentNewToAuthorTopic($oUserTopic, $oTopic, $oCommentNew, $this->oUserCurrent);
         }
         /**
          * Отправляем уведомление тому на чей коммент ответили
          */
         if ($oCommentParent and $oCommentParent->getUserId() != $oTopic->getUserId() and $oCommentNew->getUserId() != $oCommentParent->getUserId()) {
             $oUserAuthorComment = $oCommentParent->getUser();
             $this->Notify_SendCommentReplyToAuthorParentComment($oUserAuthorComment, $oTopic, $oCommentNew, $this->oUserCurrent);
         }
     } else {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
     }
 }
示例#30
0
 /**
  * Создает подписку, если уже есть, то возвращает существующую
  *
  * @param string $sTargetType	Тип
  * @param string $sTargetId	ID владельца
  * @param string $sMail	Емайл
  * @return ModuleSubscribe_EntitySubscribe|bool
  */
 public function AddSubscribeSimple($sTargetType, $sTargetId, $sMail)
 {
     if (!$sMail) {
         return false;
     }
     if (!($oSubscribe = $this->Subscribe_GetSubscribeByTargetAndMail($sTargetType, $sTargetId, $sMail))) {
         $oSubscribe = Engine::GetEntity('Subscribe');
         $oSubscribe->setTargetType($sTargetType);
         $oSubscribe->setTargetId($sTargetId);
         $oSubscribe->setMail($sMail);
         $oSubscribe->setDateAdd(date("Y-m-d H:i:s"));
         $oSubscribe->setKey(func_generator(32));
         $oSubscribe->setIp(func_getIp());
         $oSubscribe->setStatus(1);
         $this->Subscribe_AddSubscribe($oSubscribe);
     }
     return $oSubscribe;
 }