/**
  * Проверка URL форума
  *
  * @param $sValue
  * @param $aParams
  * @return bool | string
  */
 public function ValidateUrl($sValue, $aParams)
 {
     if (!$sValue || func_check($sValue, 'login', 2, 50)) {
         return true;
     }
     return $this->Lang_Get('plugin.forum.create_url_error', array('min' => 2, 'max' => 50));
 }
 /**
  * Получить информацию о блоге
  *
  * @return bool
  */
 public function EventAjaxBlogInfo()
 {
     $this->Viewer_SetResponseAjax('json');
     $sBlogName = getRequest('param');
     if (!is_string($sBlogName) or !func_check($sBlogName, 'login', 3, 50)) {
         $this->Message_AddError('Error in blog`s name');
         return false;
     }
     if (!($oBlog = $this->Blog_GetBlogByUrl($sBlogName))) {
         return false;
     }
     // get blog users with all roles
     $aBlogAdministratorsResult = $this->Blog_GetBlogUsersByBlogId($oBlog->getId(), ModuleBlog::BLOG_USER_ROLE_ADMINISTRATOR);
     $aBlogAdministrators = $aBlogAdministratorsResult['collection'];
     $aBlogModeratorsResult = $this->Blog_GetBlogUsersByBlogId($oBlog->getId(), ModuleBlog::BLOG_USER_ROLE_MODERATOR);
     $aBlogModerators = $aBlogModeratorsResult['collection'];
     $aBlogUsersResult = $this->Blog_GetBlogUsersByBlogId($oBlog->getId(), ModuleBlog::BLOG_USER_ROLE_USER, 1, Config::Get('plugin.popupinfo.Blog_User_On_Page'));
     $aBlogUsers = $aBlogUsersResult['collection'];
     $oViewer = $this->Viewer_GetLocalViewer();
     $oViewer->Assign('oBlog', $oBlog);
     $oViewer->Assign('aBlogAdministrators', $aBlogAdministrators);
     $oViewer->Assign('aBlogModerators', $aBlogModerators);
     $oViewer->Assign('aBlogUsers', $aBlogUsers);
     $oViewer->Assign('iCountBlogAdministrators', $aBlogAdministratorsResult['count'] + 1);
     $oViewer->Assign('iCountBlogModerators', $aBlogModeratorsResult['count']);
     $oViewer->Assign('iCountBlogUsers', $aBlogUsersResult['count']);
     $oViewer->Assign('oUserCurrent', $this->oUserCurrent);
     $this->Viewer_AssignAjax('sText', $oViewer->Fetch(Plugin::GetTemplatePath(__CLASS__) . '/getbloginfo.tpl'));
 }
 /**
  * Изменение состояния подписки
  */
 protected function EventAjaxSubscribeToggle()
 {
     $this->Viewer_SetResponseAjax('json');
     /**
      * Получаем емайл подписки и проверяем его на валидность
      */
     $sMail = getRequest('mail');
     if ($this->oUserCurrent) {
         $sMail = $this->oUserCurrent->getMail();
     }
     if (!func_check($sMail, 'mail')) {
         $this->Message_AddError($this->Lang_Get('registration_mail_error'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Получаем тип объекта подписки
      */
     $sTargetType = getRequest('target_type');
     if (!$this->Subscribe_IsAllowTargetType($sTargetType)) {
         $this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     $sTargetId = getRequest('target_id') ? getRequest('target_id') : null;
     $iValue = getRequest('value') ? 1 : 0;
     $oSubscribe = null;
     /**
      * Есть ли доступ к подписке гостям?
      */
     if (!$this->oUserCurrent and !$this->Subscribe_IsAllowTargetForGuest($sTargetType)) {
         $this->Message_AddError($this->Lang_Get('need_authorization'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверка объекта подписки
      */
     if (!$this->Subscribe_CheckTarget($sTargetType, $sTargetId, $iValue)) {
         $this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Если подписка еще не существовала, то создаем её
      */
     $oSubscribe = $this->Subscribe_AddSubscribeSimple($sTargetType, $sTargetId, $sMail);
     if ($oSubscribe) {
         $oSubscribe->setStatus($iValue);
         $this->Subscribe_UpdateSubscribe($oSubscribe);
         $this->Message_AddNotice($this->Lang_Get('subscribe_change_ok'), $this->Lang_Get('attention'));
         return;
     }
     $this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error'));
     return;
 }
 protected function EventParamsSubmit()
 {
     $bOk = true;
     if (isset($_POST['param_reserved_urls'])) {
         $aReservedUrls = explode(',', preg_replace("/\\s+/", '', getRequest('param_reserved_urls')));
         $aNewReservedUrls = array();
         foreach ($aReservedUrls as $sUrl) {
             if (func_check($sUrl, 'login', 1, 50)) {
                 $aNewReservedUrls[] = $sUrl;
             }
         }
         $this->aConfig['reserverd_urls'] = $aNewReservedUrls;
         $sReservedUrls = implode(',', $aNewReservedUrls);
         $result = $this->PluginAceadminpanel_Admin_SetValue('param_reserved_urls', $sReservedUrls);
         $bOk = $bOk and $result['result'];
     }
     if (isset($_POST['param_items_per_page'])) {
         $result = $this->PluginAceadminpanel_Admin_SetValue('param_items_per_page', intval(getRequest('param_items_per_page')));
         $bOk = $bOk and $result['result'];
     }
     if (isset($_POST['param_votes_per_page'])) {
         $result = $this->PluginAceadminpanel_Admin_SetValue('param_votes_per_page', intval(getRequest('param_votes_per_page')));
         $bOk = $bOk and $result['result'];
     }
     if (isset($_POST['param_edit_footer'])) {
         $result = $this->PluginAceadminpanel_Admin_SetValue('param_edit_footer', getRequest('param_edit_footer'));
         $bOk = $bOk and $result['result'];
     }
     if (isset($_POST['param_vote_value'])) {
         $result = $this->PluginAceadminpanel_Admin_SetValue('param_vote_value', intval(getRequest('param_vote_value')));
         $bOk = $bOk and $result['result'];
     }
     if (isset($_POST['param_check_password'])) {
         $param = intval(getRequest('param_check_password'));
     } else {
         $param = 0;
     }
     $result = $this->PluginAceadminpanel_Admin_SetValue('param_check_password', $param);
     $bOk = $bOk and $result['result'];
     if ($bOk) {
         $this->_InitParams();
     }
     return $bOk;
 }
 protected function EventSetBestComment()
 {
     if (!$this->oUserCurrent) {
         $this->Message_AddErrorSingle($this->Lang_Get('need_authorization'), $this->Lang_Get('error'));
         return;
     }
     if (func_check(getRequest('commentId', null, 'post'), 'id', 1, 11)) {
         $commentId = getRequest('commentId', null, 'post');
     }
     if (!($oComment = $this->Comment_GetCommentById($commentId))) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     if (!$oComment->isBestable()) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     if (!($oComment = $this->Comment_GetCommentById($commentId))) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     if (!($oTopic = $this->Topic_GetTopicById($oComment->getTargetId()))) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     $oTopic = $this->Topic_GetTopicById($oComment->getTargetId());
     if ($oComment->isBestable() && $oTopic->getIsAllowBestComment()) {
         if ($oComment->getCommentId() == $oComment->getTarget()->getBestCommentId()) {
             $oTopic->setBestCommentId(0);
             $sMsg = $this->Lang_Get('plugin.qa.comment_unset_best');
             $sTextToggle = $this->Lang_Get('plugin.qa.setbest');
         } else {
             $oTopic->setBestCommentId($oComment->getCommentId());
             $sMsg = $this->Lang_Get('plugin.qa.comment_set_best');
             $sTextToggle = $this->Lang_Get('plugin.qa.unsetbest');
         }
         $this->Topic_UpdateTopic($oTopic);
         $this->Message_AddNoticeSingle($sMsg, $this->Lang_Get('attention'));
         $this->Viewer_AssignAjax('sTextToggle', $sTextToggle);
     }
 }
 /**
  * Формирует из REQUEST массива фильтр для отбора отчетов
  *
  * @return array
  */
 protected function BuildFilter()
 {
     $aFilter = array();
     if ($start = getRequest('start')) {
         if (func_check($start, 'text', 6, 10) && substr_count($start, '.') == 2) {
             list($d, $m, $y) = explode('.', $start);
             if (@checkdate($m, $d, $y)) {
                 $aFilter['date_min'] = "{$y}-{$m}-{$d}";
             } else {
                 $this->Message_AddError($this->Lang_Get('plugin.profiler.filter_error_date_format'), $this->Lang_Get('plugin.profiler.filter_error'));
                 unset($_REQUEST['start']);
             }
         } else {
             $this->Message_AddError($this->Lang_Get('plugin.profiler.filter_error_date_format'), $this->Lang_Get('plugin.profiler.filter_error'));
             unset($_REQUEST['start']);
         }
     }
     if ($end = getRequest('end')) {
         if (func_check($end, 'text', 6, 10) && substr_count($end, '.') == 2) {
             list($d, $m, $y) = explode('.', $end);
             if (@checkdate($m, $d, $y)) {
                 $aFilter['date_max'] = "{$y}-{$m}-{$d} 23:59:59";
             } else {
                 $this->Message_AddError($this->Lang_Get('plugin.profiler.filter_error_date_format'), $this->Lang_Get('plugin.profiler.filter_error'));
                 unset($_REQUEST['end']);
             }
         } else {
             $this->Message_AddError($this->Lang_Get('plugin.profiler.filter_error_date_format'), $this->Lang_Get('plugin.profiler.filter_error'));
             unset($_REQUEST['end']);
         }
     }
     if ($iTimeFull = getRequest('time') and $iTimeFull > 0) {
         $aFilter['time'] = $iTimeFull;
     }
     if ($iPerPage = getRequest('per_page', 0) and $iPerPage > 0) {
         Config::Set('plugins.profiler.per_page', $iPerPage);
     }
     return $aFilter;
 }
 /**
  * Проверка полей на корректность
  *
  * @return unknown
  */
 protected function CheckPageFields()
 {
     $this->Security_ValidateSendForm();
     $bOk = true;
     /**
      * Проверяем есть ли заголовок топика
      */
     if (!func_check(getRequest('page_title', null, 'post'), 'text', 2, 200)) {
         $this->Message_AddError($this->Lang_Get('plugin.page.create_title_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * Проверяем есть ли заголовок топика, с заменой всех пробельных символов на "_"
      */
     $pageUrl = preg_replace("/\\s+/", '_', (string) getRequest('page_url', null, 'post'));
     $_REQUEST['page_url'] = $pageUrl;
     if (!func_check(getRequest('page_url', null, 'post'), 'login', 1, 50)) {
         $this->Message_AddError($this->Lang_Get('plugin.page.create_url_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * Проверяем на счет плохих УРЛов
      */
     if (in_array(getRequest('page_url', null, 'post'), $this->aBadPageUrl)) {
         $this->Message_AddError($this->Lang_Get('plugin.page.create_url_error_bad') . ' ' . join(',', $this->aBadPageUrl), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * Проверяем есть ли содержание страницы
      */
     if (!func_check(getRequest('page_text', null, 'post'), 'text', 1, 50000)) {
         $this->Message_AddError($this->Lang_Get('plugin.page.create_text_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * Проверяем страницу в которую хотим вложить
      */
     if (getRequest('page_pid') != 0 and !($oPageParent = $this->PluginPage_Page_GetPageById(getRequest('page_pid')))) {
         $this->Message_AddError($this->Lang_Get('plugin.page.create_parent_page_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * Проверяем сортировку
      */
     if (getRequest('page_sort') and !is_numeric(getRequest('page_sort'))) {
         $this->Message_AddError($this->Lang_Get('plugin.page.create_sort_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * Выполнение хуков
      */
     $this->Hook_Run('check_page_fields', array('bOk' => &$bOk));
     return $bOk;
 }
 /**
  * Обработка напоминания пароля
  *
  */
 protected function EventReminder()
 {
     $this->Viewer_AddHtmlTitle($this->Lang_Get('password_reminder'));
     if ($this->GetParam(0) == 'send') {
         $this->SetTemplateAction('reminder_send');
         return;
     }
     /**
      * Проверка кода на восстановление пароля и генерация нового пароля
      */
     if (func_check($this->GetParam(0), 'md5')) {
         if ($oReminder = $this->User_GetReminderByCode($this->GetParam(0))) {
             if (!$oReminder->getIsUsed() and strtotime($oReminder->getDateExpire()) > time() and $oUser = $this->User_GetUserById($oReminder->getUserId())) {
                 $sNewPassword = func_generator(7);
                 $oUser->setPassword(func_encrypt($sNewPassword));
                 if ($this->User_Update($oUser)) {
                     $oReminder->setDateUsed(date("Y-m-d H:i:s"));
                     $oReminder->setIsUsed(1);
                     $this->User_UpdateReminder($oReminder);
                     $this->Notify_SendReminderPassword($oUser, $sNewPassword);
                     $this->SetTemplateAction('reminder_confirm');
                     return;
                 }
             }
         }
         $this->Message_AddErrorSingle($this->Lang_Get('password_reminder_bad_code'), $this->Lang_Get('error'));
         return Router::Action('error');
     }
     /**
      * Обрабатываем запрос на смену пароля
      */
     if (isPost('submit_reminder')) {
         if (func_check(getRequest('mail'), 'mail') and $oUser = $this->User_GetUserByMail(getRequest('mail'))) {
             /**
              * Формируем и отправляем ссылку на смену пароля
              */
             $oReminder = Engine::GetEntity('User_Reminder');
             $oReminder->setCode(func_generator(32));
             $oReminder->setDateAdd(date("Y-m-d H:i:s"));
             $oReminder->setDateExpire(date("Y-m-d H:i:s", time() + 60 * 60 * 24 * 7));
             $oReminder->setDateUsed(null);
             $oReminder->setIsUsed(0);
             $oReminder->setUserId($oUser->getId());
             if ($this->User_AddReminder($oReminder)) {
                 $this->Notify_SendReminderCode($oUser, $oReminder);
                 Router::Location(Router::GetPath('login') . 'reminder/send/');
             }
         } else {
             $this->Message_AddError($this->Lang_Get('password_reminder_bad_email'), $this->Lang_Get('error'));
         }
     }
 }
 /**
  * Обработка добавление комментария к топику через 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'));
     }
 }
 /**
  * Проверка полей на корректность
  *
  * @return  bool
  */
 protected function EventPagesCheckFields()
 {
     $this->Security_ValidateSendForm();
     $bOk = true;
     // * Проверяем есть ли заголовок страницы
     if (!func_check(getRequest('page_title'), 'text', 2, 200)) {
         $this->_messageError($this->Lang_Get('page_create_title_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     //  * Проверяем есть ли заголовок страницы, с заменой всех пробельных символов на "_"
     $pageUrl = preg_replace("/\\s+/", '_', getRequest('page_url'));
     $_REQUEST['page_url'] = $pageUrl;
     if (!func_check(getRequest('page_url'), 'login', 1, 50)) {
         $this->_messageError($this->Lang_Get('page_create_url_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     // * Проверяем на плохие/зарезервированные УРЛы
     if (in_array(getRequest('page_url'), $this->aConfig['reserverd_urls'])) {
         $this->_messageError($this->Lang_Get('page_create_url_error_bad') . ' ' . join(',', $this->aConfig['reserverd_urls']), $this->Lang_Get('error'));
         $bOk = false;
     }
     // * Проверяем есть ли содержимое страницы
     if (!func_check(getRequest('page_text'), 'text', 1, 50000)) {
         $this->_messageError($this->Lang_Get('page_create_text_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     // * Проверяем страницу в которую хотим вложить
     if (getRequest('page_pid') != 0 and !($oPageParent = $this->PluginPage_Page_GetPageById(getRequest('page_pid')))) {
         $this->_messageError($this->Lang_Get('page_create_parent_page_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     // * Проверяем сортировку
     if (getRequest('page_sort') and !is_numeric(getRequest('page_sort'))) {
         $this->Message_AddError($this->Lang_Get('page_create_sort_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     // * Выполнение хуков
     $this->Hook_Run('check_page_fields', array('bOk' => &$bOk));
     return $bOk;
 }
 /**
  * Проверка полей формы 
  *
  * @return unknown
  */
 protected function checkTopicFields($oTopic = null)
 {
     $this->Security_ValidateSendForm();
     $bOk = true;
     /**
      * Проверяем есть ли блог в кторый постим
      */
     if (!func_check(getRequest('blog_id', null, 'post'), 'id')) {
         $this->Message_AddError($this->Lang_Get('topic_create_blog_error_unknown'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * Проверяем есть ли описание вопроса
      */
     if (!func_check(getRequest('topic_text', null, 'post'), 'text', 0, 500)) {
         $this->Message_AddError($this->Lang_Get('topic_question_create_text_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * проверяем заполнение вопроса/ответов только если еще никто не голосовал 
      */
     if (is_null($oTopic) or $oTopic->getQuestionCountVote() == 0) {
         /**
          * Проверяем есть ли заголовок топика(вопрос)
          */
         if (!func_check(getRequest('topic_title', null, 'post'), 'text', 2, 200)) {
             $this->Message_AddError($this->Lang_Get('topic_question_create_title_error'), $this->Lang_Get('error'));
             $bOk = false;
         }
         /**
          * Проверяем варианты ответов
          */
         $aAnswers = getRequest('answer', array());
         foreach ($aAnswers as $key => $sAnswer) {
             if (trim($sAnswer) == '') {
                 unset($aAnswers[$key]);
                 continue;
             }
             if (!func_check($sAnswer, 'text', 1, 100)) {
                 $this->Message_AddError($this->Lang_Get('topic_question_create_answers_error'), $this->Lang_Get('error'));
                 $bOk = false;
                 break;
             }
         }
         $_REQUEST['answer'] = $aAnswers;
         if (count($aAnswers) < 2) {
             $this->Message_AddError($this->Lang_Get('topic_question_create_answers_error_min'), $this->Lang_Get('error'));
             $bOk = false;
         }
         if (count($aAnswers) > 20) {
             $this->Message_AddError($this->Lang_Get('topic_question_create_answers_error_max'), $this->Lang_Get('error'));
             $bOk = false;
         }
     }
     /**
      * Проверяем есть ли теги(метки)
      */
     if (!func_check(getRequest('topic_tags', null, 'post'), 'text', 2, 500)) {
         $this->Message_AddError($this->Lang_Get('topic_create_tags_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * проверяем ввод тегов 
      */
     $sTags = getRequest('topic_tags');
     $aTags = explode(',', rtrim($sTags, "\r\n\t\v ."));
     $aTagsNew = array();
     foreach ($aTags as $sTag) {
         $sTag = trim($sTag);
         if (func_check($sTag, 'text', 2, 50)) {
             $aTagsNew[] = $sTag;
         }
     }
     if (!count($aTagsNew)) {
         $this->Message_AddError($this->Lang_Get('topic_create_tags_error_bad'), $this->Lang_Get('error'));
         $bOk = false;
     } else {
         $_REQUEST['topic_tags'] = join(',', $aTagsNew);
     }
     /**
      * Выполнение хуков
      */
     $this->Hook_Run('check_question_fields', array('bOk' => &$bOk));
     return $bOk;
 }
 /**
  * Проверка полей формы
  *
  * @return unknown
  */
 protected function checkTopicFields()
 {
     $this->Security_ValidateSendForm();
     $bOk = true;
     /**
      * Проверяем есть ли блог в кторый постим
      */
     if (!func_check(getRequest('blog_id', null, 'post'), 'id')) {
         $this->Message_AddError($this->Lang_Get('topic_create_blog_error_unknown'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * Проверяем есть ли заголовок топика
      */
     if (!func_check(getRequest('topic_title', null, 'post'), 'text', 2, 200)) {
         $this->Message_AddError($this->Lang_Get('topic_create_title_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * Проверяем есть ли содержание топика
      */
     if (!func_check(getRequest('topic_text', null, 'post'), 'text', 2, Config::Get('module.topic.max_length'))) {
         $this->Message_AddError($this->Lang_Get('topic_create_text_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * Проверяем есть ли теги(метки)
      */
     if (!func_check(getRequest('topic_tags', null, 'post'), 'text', 2, 500)) {
         $this->Message_AddError($this->Lang_Get('topic_create_tags_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * проверяем ввод тегов
      */
     $sTags = getRequest('topic_tags', null, 'post');
     $aTags = explode(',', $sTags);
     $aTagsNew = array();
     $aTagsNewLow = array();
     foreach ($aTags as $sTag) {
         $sTag = trim($sTag);
         if (func_check($sTag, 'text', 2, 50) and !in_array(mb_strtolower($sTag, 'UTF-8'), $aTagsNewLow)) {
             $aTagsNew[] = $sTag;
             $aTagsNewLow[] = mb_strtolower($sTag, 'UTF-8');
         }
     }
     if (!count($aTagsNew)) {
         $this->Message_AddError($this->Lang_Get('topic_create_tags_error_bad'), $this->Lang_Get('error'));
         $bOk = false;
     } else {
         $_REQUEST['topic_tags'] = join(',', $aTagsNew);
     }
     /**
      * Выполнение хуков
      */
     $this->Hook_Run('check_topic_fields', array('bOk' => &$bOk));
     return $bOk;
 }
 /**
  * Сохраняем теги картинки
  */
 public function EventSetImageTags()
 {
     $sTags = getRequest('tags', null, 'post');
     $aTags = explode(',', $sTags);
     $aTagsNew = array();
     $aTagsNewLow = array();
     foreach ($aTags as $sTag) {
         $sTag = trim($sTag);
         if (func_check($sTag, 'text', 2, 50) and !in_array(mb_strtolower($sTag, 'UTF-8'), $aTagsNewLow)) {
             $aTagsNew[] = $sTag;
             $aTagsNewLow[] = mb_strtolower($sTag, 'UTF-8');
         }
     }
     if (!count($aTagsNew)) {
         $sTags = '';
     } else {
         $sTags = join(',', $aTagsNew);
     }
     /* @var $oImage PluginLsgallery_ModuleImage_EntityImage */
     $oImage = $this->PluginLsgallery_Image_GetImageById(getRequest('id'));
     if ($oImage) {
         /* @var $oAlbum PluginLsgallery_ModuleAlbum_EntityAlbum */
         $oAlbum = $this->PluginLsgallery_Album_GetAlbumById($oImage->getAlbumId());
         if (!$oAlbum || !$this->ACL_AllowAdminAlbumImages($this->oUserCurrent, $oAlbum)) {
             $this->Message_AddError($this->Lang_Get('no_access'), $this->Lang_Get('error'));
             return false;
         }
         $oImage->setImageTags($sTags);
         $this->PluginLsgallery_Image_UpdateImage($oImage);
     }
 }
 /**
  * Validate album fields
  *
  * @param PluginLsgallery_ModuleAlbum_EntityAlbum $oAlbum
  * @return boolean
  */
 protected function _checkAlbumFields($oAlbum = null)
 {
     $this->Security_ValidateSendForm();
     $bOk = true;
     if (!is_null($oAlbum)) {
         if ($oAlbum->getId() != getRequest('album_id')) {
             $this->Message_AddError($this->Lang_Get('plugin.lsgallery.lsgallery_album_id_error'), $this->Lang_Get('error'));
             $bOk = false;
         }
     }
     if (!func_check(getRequest('album_title'), 'text', 2, 64)) {
         $this->Message_AddError($this->Lang_Get('plugin.lsgallery.lsgallery_album_title_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     $sDescription = getRequest('album_description');
     if ($sDescription && !func_check($sDescription, 'text', 10, 512)) {
         $this->Message_AddError($this->Lang_Get('plugin.lsgallery.lsgallery_album_description_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     $aTypes = PluginLsgallery_ModuleAlbum_EntityAlbum::getLocalizedTypes($this);
     if (!in_array(getRequest('album_type'), array_keys($aTypes))) {
         $this->Message_AddError($this->Lang_Get('plugin.lsgallery.lsgallery_album_type_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     return $bOk;
 }
Example #15
0
 /**
  * Подготовка запроса на поиск
  *
  * @return unknown
  */
 private function PrepareRequest()
 {
     $aReq['q'] = getRequest('q');
     if (!func_check($aReq['q'], 'text', 2, 255)) {
         /**
          *  Если запрос слишком короткий перенаправляем на начальную страницу поиска
          * Хотя тут лучше показывать юзеру в чем он виноват
          */
         Router::Location(Router::GetPath('search'));
     }
     $aReq['sType'] = strtolower(Router::GetActionEvent());
     /**
      * Определяем текущую страницу вывода результата
      */
     $aReq['iPage'] = intval(preg_replace('#^page(\\d+)$#', '\\1', $this->getParam(0)));
     if (!$aReq['iPage']) {
         $aReq['iPage'] = 1;
     }
     /**
      *  Передача данных в шаблонизатор 
      */
     $this->Viewer_Assign('aReq', $aReq);
     return $aReq;
 }
 /**
  * Проверка на соответсвие коментария родительскому коментарию
  *
  * @param ModuleTopic_EntityTopic $oTopic
  * @param string $sText
  * @param ModuleComment_EntityComment $oCommentParent
  *
  * @return bool result
  */
 protected function CheckParentComment($oTopic, $sText, $oCommentParent)
 {
     $sParentId = 0;
     if ($oCommentParent) {
         $sParentId = $oCommentParent->GetCommentId();
     }
     $bOk = true;
     /**
      * Проверям на какой коммент отвечаем
      */
     if (!func_check($sParentId, 'id')) {
         $this->Message_AddErrorSingle($this->Lang_Get('common.error.system.base'), $this->Lang_Get('common.error.error'));
         $bOk = false;
     }
     if ($sParentId) {
         /**
          * Проверяем существует ли комментарий на который отвечаем
          */
         if (!$oCommentParent) {
             $this->Message_AddErrorSingle($this->Lang_Get('common.error.system.base'), $this->Lang_Get('common.error.error'));
             $bOk = false;
         }
         /**
          * Проверяем из одного топика ли новый коммент и тот на который отвечаем
          */
         if ($oCommentParent->getTargetId() != $oTopic->getId()) {
             $this->Message_AddErrorSingle($this->Lang_Get('common.error.system.base'), $this->Lang_Get('common.error.error'));
             $bOk = false;
         }
     } else {
         $sParentId = null;
     }
     /**
      * Проверка на дублирующий коммент
      */
     if ($this->Comment_GetCommentUnique($oTopic->getId(), 'topic', $this->oUserCurrent->getId(), $sParentId, md5($sText))) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic.comments.notices.spam'), $this->Lang_Get('common.error.error'));
         $bOk = false;
     }
     $this->Hook_Run('comment_check_parent', array('oTopic' => $oTopic, 'sText' => $sText, 'oCommentParent' => $oCommentParent, 'bOk' => &$bOk));
     return $bOk;
 }
 /**
  * Проверка полей формы 
  *
  * @return unknown
  */
 protected function checkTopicFields($oTopic = null)
 {
     $this->Security_ValidateSendForm();
     $bOk = true;
     /**
      * Проверяем есть ли блог в кторый постим
      */
     if (!func_check(getRequest('blog_id', null, 'post'), 'id')) {
         $this->Message_AddError($this->Lang_Get('topic_create_blog_error_unknown'), $this->Lang_Get('error'));
         $bOk = false;
     }
     if (!func_check(getRequest('topic_text', null, 'post'), 'text', 0, Config::Get('module.topic.max_length'))) {
         $this->Message_AddError($this->Lang_Get('topic_create_text_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * проверяем заполнение вопроса/ответов только если еще никто не голосовал 
      */
     if (is_null($oTopic)) {
         /**
          * Проверяем есть ли заголовок топика
          */
         if (!func_check(getRequest('topic_title', null, 'post'), 'text', 2, 200)) {
             $this->Message_AddError($this->Lang_Get('topic_create_title_error'), $this->Lang_Get('error'));
             $bOk = false;
         }
     }
     /**
      * Проверяем есть ли теги(метки)
      */
     if (!func_check(getRequest('topic_tags', null, 'post'), 'text', 2, 500)) {
         $this->Message_AddError($this->Lang_Get('topic_create_tags_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * проверяем ввод тегов 
      */
     $sTags = getRequest('topic_tags');
     $aTags = explode(',', $sTags);
     $aTagsNew = array();
     foreach ($aTags as $sTag) {
         $sTag = trim($sTag);
         if (func_check($sTag, 'text', 2, 50)) {
             $aTagsNew[] = $sTag;
         }
     }
     if (!count($aTagsNew)) {
         $this->Message_AddError($this->Lang_Get('topic_create_tags_error_bad'), $this->Lang_Get('error'));
         $bOk = false;
     } else {
         $_REQUEST['topic_tags'] = join(',', $aTagsNew);
     }
     $iTopicId = getRequest('topic_id');
     $sTargetId = null;
     $iCountPhotos = 0;
     if (!$oTopic) {
         if (isset($_COOKIE['ls_photoset_target_tmp'])) {
             $iCountPhotos = $this->Topic_getCountPhotosByTargetTmp($_COOKIE['ls_photoset_target_tmp']);
         } else {
             $this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error'));
             return false;
         }
     } else {
         $iCountPhotos = $this->Topic_getCountPhotosByTopicId($oTopic->getId());
     }
     if ($iCountPhotos < Config::Get('module.topic.photoset.count_photos_min') || $iCountPhotos > Config::Get('module.topic.photoset.count_photos_max')) {
         $this->Message_AddError($this->Lang_Get('topic_photoset_error_count_photos', array('MIN' => Config::Get('module.topic.photoset.count_photos_min'), 'MAX' => Config::Get('module.topic.photoset.count_photos_max'))), $this->Lang_Get('error'));
         return false;
     }
     /**
      * Выполнение хуков
      */
     $this->Hook_Run('check_photoset_fields', array('bOk' => &$bOk));
     return $bOk;
 }
 protected function EventUsersInvites()
 {
     if ($this->GetParam(1) == 'new') {
         $sMode = 'new';
     } else {
         $sMode = 'list';
     }
     $sInviteMode = $this->_getRequestCheck('adm_invite_mode');
     if (!$sInviteMode) {
         $sInviteMode = 'mail';
     }
     $iInviteCount = 0 + intVal(getRequest('invite_count'));
     $aNewInviteList = array();
     $sInviteOrder = getRequest('invite_order');
     $sInviteSort = getRequest('invite_sort');
     if ($this->_getRequestCheck('adm_invite_submit')) {
         if ($sInviteMode == 'text') {
             if ($iInviteCount <= 0) {
                 $this->_messageError($this->Lang_Get('adm_invaite_text_empty'));
             } else {
                 for ($i = 0; $i < $iInviteCount; $i++) {
                     $oInvite = $this->User_GenerateInvite($this->oUserCurrent);
                     $aNewInviteList[$i + 1] = $oInvite->GetCode();
                 }
                 $this->_messageNotice($this->Lang_Get('adm_invaite_text_done', array('num' => $iInviteCount)));
             }
         } else {
             $sEmails = str_replace("\n", ' ', getRequest('invite_mail'));
             $sEmails = str_replace(';', ' ', $sEmails);
             $sEmails = str_replace(',', ' ', $sEmails);
             $sEmails = preg_replace('/\\s{2,}/', ' ', $sEmails);
             $aEmails = explode(' ', $sEmails);
             $iInviteCount = 0;
             foreach ($aEmails as $sEmail) {
                 if ($sEmail) {
                     if (func_check($sEmail, 'mail')) {
                         $oInvite = $this->User_GenerateInvite($this->oUserCurrent);
                         $this->Notify_SendInvite($this->oUserCurrent, $sEmail, $oInvite);
                         $aNewInviteList[$sEmail] = $oInvite->GetCode();
                         $iInviteCount += 1;
                     } else {
                         $aNewInviteList[$sEmail] = '### ' . $this->Lang_Get('settings_invite_mail_error') . ' ###';
                     }
                 }
             }
             if ($iInviteCount) {
                 $this->_messageNotice($this->Lang_Get('adm_invaite_mail_done', array('num' => $iInviteCount)));
             }
         }
     }
     if ($sMode == 'list') {
         // Передан ли номер страницы
         if (preg_match("/^page(\\d+)\$/i", $this->getParam(1), $aMatch)) {
             $iPage = $aMatch[1];
         } else {
             $iPage = 1;
         }
         $aParam = array();
         if ($sInviteSort and in_array($sInviteSort, array('id', 'code', 'user_from', 'date_add', 'user_to', 'date_used'))) {
             $aParam['sort'] = $sInviteSort;
         }
         if ($sInviteOrder) {
             $aParam['order'] = intVal($sInviteOrder);
         }
         // Получаем список инвайтов
         $iCount = 0;
         $aResult = $this->PluginAceadminpanel_Admin_GetInvites($iCount, $iPage, $this->aConfig['items_per_page'], $aParam);
         $aInvites = $aResult['collection'];
         // Формируем постраничность
         $aPaging = $this->Viewer_MakePaging($aResult['count'], $iPage, $this->aConfig['items_per_page'], 4, Config::Get('path.root.web') . '/' . ROUTE_PAGE_ADMIN . '/users/invites');
         if ($aPaging) {
             $this->Viewer_Assign('aPaging', $aPaging);
         }
         $this->Viewer_Assign('aInvites', $aInvites);
         $this->Viewer_Assign('iCount', $aResult['count']);
     }
     $this->Viewer_Assign('sMode', $sMode);
     if ($this->oUserCurrent->isAdministrator()) {
         $iCountInviteAvailable = -1;
     } else {
         $iCountInviteAvailable = $this->User_GetCountInviteAvailable($this->oUserCurrent);
     }
     $this->Viewer_Assign('iCountInviteAvailable', $iCountInviteAvailable);
     $this->Viewer_Assign('iCountInviteUsed', $this->User_GetCountInviteUsed($this->oUserCurrent->getId()));
     $this->Viewer_Assign('sInviteMode', $sInviteMode);
     $this->Viewer_Assign('iInviteCount', $iInviteCount);
     $this->Viewer_Assign('USER_USE_INVITE', Config::Get('general.reg.invite'));
     $this->Viewer_Assign('aNewInviteList', $aNewInviteList);
     $this->Viewer_Assign('sInviteOrder', getRequest('invite_order'));
     $this->Viewer_Assign('sInviteSort', getRequest('invite_sort'));
     $this->Viewer_Assign('include_tpl', Plugin::GetTemplatePath($this->sPlugin) . '/actions/ActionAdmin/users/users_invites.tpl');
 }
Example #19
0
 public function InitDec()
 {
     if (getRequest('setDec') && func_check(getRequest('setDec'), 'id') && ($oDecActive = $this->PluginAceadminpanel_Decor_GetDecById(getRequest('setDec')))) {
         $aDecors[$oDecActive->getDecPosition()] = $oDecActive;
         $this->Viewer_Assign('aDecors', $aDecors);
     }
 }
Example #20
0
 /**
  * Проверка полей формы
  *
  * @return unknown
  */
 protected function checkTopicFields()
 {
     $bOk = true;
     /**
      * Проверяем есть ли блог в который постим
      */
     if (!func_check(getRequest('blog_id', null, 'post'), 'id')) {
         $this->Message_AddError($this->Lang_Get('topic_create_blog_error_unknown'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * Проверяем есть ли заголовок топика
      */
     if (!func_check(getRequest('topic_title', null, 'post'), 'text', 2, 200)) {
         $this->Message_AddError($this->Lang_Get('topic_create_title_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * Проверяем есть ли ссылка
      */
     if (!func_check(getRequest('topic_link_url', null, 'post'), 'text', 3, 200)) {
         $this->Message_AddError($this->Lang_Get('topic_link_create_url_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * Проверяем есть ли описание топика-ссылки
      */
     if (!func_check(getRequest('topic_text', null, 'post'), 'text', 10, 500)) {
         $this->Message_AddError($this->Lang_Get('topic_link_create_text_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * Проверяем есть ли теги(метки)
      */
     if (!func_check(getRequest('topic_tags', null, 'post'), 'text', 2, 500)) {
         $this->Message_AddError($this->Lang_Get('topic_create_tags_error'), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * проверяем ввод тегов 
      */
     $sTags = getRequest('topic_tags');
     $aTags = explode(',', rtrim($sTags, "\r\n\t\v ."));
     $aTagsNew = array();
     foreach ($aTags as $sTag) {
         $sTag = trim($sTag);
         if (func_check($sTag, 'text', 2, 50)) {
             $aTagsNew[] = $sTag;
         }
     }
     if (!count($aTagsNew)) {
         $this->Message_AddError($this->Lang_Get('topic_create_tags_error_bad'), $this->Lang_Get('error'));
         $bOk = false;
     } else {
         $_REQUEST['topic_tags'] = join(',', $aTagsNew);
     }
     /**
      * Выполнение хуков
      */
     $this->Hook_Run('check_link_fields', array('bOk' => &$bOk));
     return $bOk;
 }
 /**
  * Выводит форму для редактирования профиля и обрабатывает её
  *
  */
 protected function EventProfile()
 {
     /**
      * Устанавливаем title страницы
      */
     $this->Viewer_AddHtmlTitle($this->Lang_Get('settings_menu_profile'));
     $this->Viewer_Assign('aUserFields', $this->User_getUserFields(''));
     $this->Viewer_Assign('aUserFieldsContact', $this->User_getUserFields(array('contact', 'social')));
     /**
      * Загружаем в шаблон JS текстовки
      */
     $this->Lang_AddLangJs(array('settings_profile_field_error_max'));
     /**
      * Если нажали кнопку "Сохранить"
      */
     if (isPost('submit_profile_edit')) {
         $this->Security_ValidateSendForm();
         $bError = false;
         /**
          * Заполняем профиль из полей формы
          */
         /**
          * Определяем гео-объект
          */
         if (getRequest('geo_city')) {
             $oGeoObject = $this->Geo_GetGeoObject('city', getRequestStr('geo_city'));
         } elseif (getRequest('geo_region')) {
             $oGeoObject = $this->Geo_GetGeoObject('region', getRequestStr('geo_region'));
         } elseif (getRequest('geo_country')) {
             $oGeoObject = $this->Geo_GetGeoObject('country', getRequestStr('geo_country'));
         } else {
             $oGeoObject = null;
         }
         /**
          * Проверяем имя
          */
         if (func_check(getRequestStr('profile_name'), 'text', 2, Config::Get('module.user.name_max'))) {
             $this->oUserCurrent->setProfileName(getRequestStr('profile_name'));
         } else {
             $this->oUserCurrent->setProfileName(null);
         }
         /**
          * Проверяем пол
          */
         if (in_array(getRequestStr('profile_sex'), array('man', 'woman', 'other'))) {
             $this->oUserCurrent->setProfileSex(getRequestStr('profile_sex'));
         } else {
             $this->oUserCurrent->setProfileSex('other');
         }
         /**
          * Проверяем дату рождения
          */
         if (func_check(getRequestStr('profile_birthday_day'), 'id', 1, 2) and func_check(getRequestStr('profile_birthday_month'), 'id', 1, 2) and func_check(getRequestStr('profile_birthday_year'), 'id', 4, 4)) {
             $this->oUserCurrent->setProfileBirthday(date("Y-m-d H:i:s", mktime(0, 0, 0, getRequestStr('profile_birthday_month'), getRequestStr('profile_birthday_day'), getRequestStr('profile_birthday_year'))));
         } else {
             $this->oUserCurrent->setProfileBirthday(null);
         }
         /**
          * Проверяем информацию о себе
          */
         if (func_check(getRequestStr('profile_about'), 'text', 1, 3000)) {
             $this->oUserCurrent->setProfileAbout($this->Text_Parser(getRequestStr('profile_about')));
         } else {
             $this->oUserCurrent->setProfileAbout(null);
         }
         /**
          * Ставим дату последнего изменения профиля
          */
         $this->oUserCurrent->setProfileDate(date("Y-m-d H:i:s"));
         /**
          * Запускаем выполнение хуков
          */
         $this->Hook_Run('settings_profile_save_before', array('oUser' => $this->oUserCurrent, 'bError' => &$bError));
         /**
          * Сохраняем изменения профиля
          */
         if (!$bError) {
             if ($this->User_Update($this->oUserCurrent)) {
                 /**
                  * Создаем связь с гео-объектом
                  */
                 if ($oGeoObject) {
                     $this->Geo_CreateTarget($oGeoObject, 'user', $this->oUserCurrent->getId());
                     if ($oCountry = $oGeoObject->getCountry()) {
                         $this->oUserCurrent->setProfileCountry($oCountry->getName());
                     } else {
                         $this->oUserCurrent->setProfileCountry(null);
                     }
                     if ($oRegion = $oGeoObject->getRegion()) {
                         $this->oUserCurrent->setProfileRegion($oRegion->getName());
                     } else {
                         $this->oUserCurrent->setProfileRegion(null);
                     }
                     if ($oCity = $oGeoObject->getCity()) {
                         $this->oUserCurrent->setProfileCity($oCity->getName());
                     } else {
                         $this->oUserCurrent->setProfileCity(null);
                     }
                 } else {
                     $this->Geo_DeleteTargetsByTarget('user', $this->oUserCurrent->getId());
                     $this->oUserCurrent->setProfileCountry(null);
                     $this->oUserCurrent->setProfileRegion(null);
                     $this->oUserCurrent->setProfileCity(null);
                 }
                 $this->User_Update($this->oUserCurrent);
                 /**
                  * Обрабатываем дополнительные поля, type = ''
                  */
                 $aFields = $this->User_getUserFields('');
                 $aData = array();
                 foreach ($aFields as $iId => $aField) {
                     if (isset($_REQUEST['profile_user_field_' . $iId])) {
                         $aData[$iId] = getRequestStr('profile_user_field_' . $iId);
                     }
                 }
                 $this->User_setUserFieldsValues($this->oUserCurrent->getId(), $aData);
                 /**
                  * Динамические поля контактов, type = array('contact','social')
                  */
                 $aType = array('contact', 'social');
                 $aFields = $this->User_getUserFields($aType);
                 /**
                  * Удаляем все поля с этим типом
                  */
                 $this->User_DeleteUserFieldValues($this->oUserCurrent->getId(), $aType);
                 $aFieldsContactType = getRequest('profile_user_field_type');
                 $aFieldsContactValue = getRequest('profile_user_field_value');
                 if (is_array($aFieldsContactType)) {
                     foreach ($aFieldsContactType as $k => $v) {
                         $v = (string) $v;
                         if (isset($aFields[$v]) and isset($aFieldsContactValue[$k]) and is_string($aFieldsContactValue[$k])) {
                             $this->User_setUserFieldsValues($this->oUserCurrent->getId(), array($v => $aFieldsContactValue[$k]), Config::Get('module.user.userfield_max_identical'));
                         }
                     }
                 }
                 $this->Message_AddNoticeSingle($this->Lang_Get('settings_profile_submit_ok'));
                 $this->Hook_Run('settings_profile_save_after', array('oUser' => $this->oUserCurrent));
             } else {
                 $this->Message_AddErrorSingle($this->Lang_Get('system_error'));
             }
         }
     }
     /**
      * Загружаем гео-объект привязки
      */
     $oGeoTarget = $this->Geo_GetTargetByTarget('user', $this->oUserCurrent->getId());
     $this->Viewer_Assign('oGeoTarget', $oGeoTarget);
     /**
      * Загружаем в шаблон список стран, регионов, городов
      */
     $aCountries = $this->Geo_GetCountries(array(), array('sort' => 'asc'), 1, 300);
     $this->Viewer_Assign('aGeoCountries', $aCountries['collection']);
     if ($oGeoTarget) {
         if ($oGeoTarget->getCountryId()) {
             $aRegions = $this->Geo_GetRegions(array('country_id' => $oGeoTarget->getCountryId()), array('sort' => 'asc'), 1, 500);
             $this->Viewer_Assign('aGeoRegions', $aRegions['collection']);
         }
         if ($oGeoTarget->getRegionId()) {
             $aCities = $this->Geo_GetCities(array('region_id' => $oGeoTarget->getRegionId()), array('sort' => 'asc'), 1, 500);
             $this->Viewer_Assign('aGeoCities', $aCities['collection']);
         }
     }
 }
Example #22
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'));
     }
 }
Example #23
0
 /**
  * Сохраняет теги для избранного
  *
  */
 protected function EventFavouriteSaveTags()
 {
     /**
      * Пользователь авторизован?
      */
     if (!$this->oUserCurrent) {
         $this->Message_AddErrorSingle($this->Lang_Get('need_authorization'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Объект уже должен быть в избранном
      */
     if ($oFavourite = $this->Favourite_GetFavourite(getRequestStr('target_id'), getRequestStr('target_type'), $this->oUserCurrent->getId())) {
         /**
          * Обрабатываем теги
          */
         $aTags = explode(',', trim(getRequestStr('tags'), "\r\n\t\v ."));
         $aTagsNew = array();
         $aTagsNewLow = array();
         $aTagsReturn = array();
         foreach ($aTags as $sTag) {
             $sTag = trim($sTag);
             if (func_check($sTag, 'text', 2, 50) and !in_array(mb_strtolower($sTag, 'UTF-8'), $aTagsNewLow)) {
                 $sTagEsc = htmlspecialchars($sTag);
                 $aTagsNew[] = $sTagEsc;
                 $aTagsReturn[] = array('tag' => $sTagEsc, 'url' => $this->oUserCurrent->getUserWebPath() . 'favourites/' . $oFavourite->getTargetType() . 's/tag/' . $sTagEsc . '/');
                 $aTagsNewLow[] = mb_strtolower($sTag, 'UTF-8');
             }
         }
         if (!count($aTagsNew)) {
             $oFavourite->setTags('');
         } else {
             $oFavourite->setTags(join(',', $aTagsNew));
         }
         $this->Viewer_AssignAjax('aTags', $aTagsReturn);
         $this->Favourite_UpdateFavourite($oFavourite);
         return;
     }
     $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
 }
 /**
  * Save banner
  * @param object $oBanner
  * @return boolean
  */
 function Save($oBanner)
 {
     if (isset($_REQUEST['submit_banner'])) {
         // Update or insert banner
         $iBannerId = $oBanner->getId();
         $sStartDate = $_REQUEST['banner_start_date'];
         $sEndDate = $_REQUEST['banner_end_date'];
         $bStateError = 0;
         if (!preg_match(Config::Get('plugin.banneroid.banner_date_reg'), $sStartDate)) {
             $this->Message_AddError($this->Lang_Get("banneroid_error_date_start"), $this->Lang_Get('banneroid_error'));
             $bStateError = 1;
         }
         if (!preg_match(Config::Get('plugin.banneroid.banner_date_reg'), $sEndDate)) {
             $this->Message_AddError($this->Lang_Get("banneroid_error_date_end"), $this->Lang_Get('banneroid_error'));
             $bStateError = 1;
         }
         if (!func_check($_REQUEST['banner_name'], 'text', 2, 3000)) {
             $this->Message_AddError($this->Lang_Get("banneroid_error_name"), $this->Lang_Get('banneroid_error'));
             $bStateError = 1;
         }
         if (!preg_match(Config::Get('plugin.banneroid.banner_url_reg'), $_REQUEST['banner_url']) and !$_REQUEST['banner_html']) {
             $this->Message_AddError($this->Lang_Get("banneroid_error_url"), $this->Lang_Get('banneroid_error'));
             $bStateError = 1;
         }
         if ($bStateError) {
             return false;
         }
         // Fill banner entity object
         $oBanner->setBannerHtml($_REQUEST['banner_html']);
         $oBanner->setBannerName($_REQUEST['banner_name']);
         $oBanner->setBannerUrl($_REQUEST['banner_url']);
         $oBanner->setBannerStartDate($sStartDate);
         $oBanner->setBannerEndDate($sEndDate);
         $oBanner->setBannerType($_REQUEST['banner_type']);
         $oBanner->setBannerIsActive($_REQUEST['banner_is_active']);
         $iOk = 1;
         //upload image for banner ------------
         if (isset($_FILES["banner_image"]) && $_FILES["banner_image"]["error"] == 0) {
             $aImageFile = $_FILES["banner_image"];
             $aSize = @getimagesize($aImageFile["tmp_name"]);
             if (!in_array($aSize['mime'], Config::Get('plugin.banneroid.images_mime'))) {
                 $this->Message_AddError($this->Lang_Get("banneroid_error_image_extension"), $this->Lang_Get('banneroid_error'));
                 $iOk = 0;
             } else {
                 if (!$this->UploadImage($aImageFile, $oBanner)) {
                     $this->Message_AddError($this->Lang_Get("banneroid_error_unable_to_upload_image"), $this->Lang_Get('banneroid_error'));
                     $iOk = 0;
                 }
             }
         }
         if ($iOk) {
             //If no errors add or update banner
             $iRes = $this->UpdateBanner($oBanner);
         }
         if ($iBannerId == 0) {
             // Update id for new banner
             $oBanner->setBannerId($iRes);
         }
         if (!isset($iRes)) {
             //show error editiding banner
             $this->Message_AddError($this->Lang_Get("banneroid_error_edit"), $this->Lang_Get('banneroid_error'));
             return false;
         } else {
             // Add banner pages --------------
             if ($_REQUEST['banner_type'] == 1 && is_array(getRequest('banner_place')) && count(getRequest('banner_place'))) {
                 $aPages[1] = getRequest('banner_place');
             } else {
                 $aPages[1] = array();
             }
             if ($_REQUEST['banner_type'] == 2 && is_array(getRequest('banner_place')) && count(getRequest('banner_place'))) {
                 $aPages[2] = getRequest('banner_place');
             } else {
                 $aPages[2] = array();
             }
             if ($_REQUEST['banner_type'] == 3 && is_array(getRequest('banner_place')) && count(getRequest('banner_place'))) {
                 $aPages[3] = getRequest('banner_place');
             } else {
                 $aPages[3] = array();
             }
             if ($_REQUEST['banner_type'] == 4 && is_array(getRequest('banner_place')) && count(getRequest('banner_place'))) {
                 $aPages[4] = getRequest('banner_place');
             } else {
                 $aPages[4] = array();
             }
             $this->UpdateBannerPages($aPages, $oBanner);
         }
         return true;
     }
     return false;
 }
Example #25
0
 /**
  * Выводит форму для редактирования профиля и обрабатывает её
  *
  */
 protected function EventProfile()
 {
     $this->Viewer_AddHtmlTitle($this->Lang_Get('settings_menu_profile'));
     /**
      * Если нажали кнопку "Сохранить"
      */
     if (isPost('submit_profile_edit')) {
         $this->Security_ValidateSendForm();
         $bError = false;
         /**
          * Заполняем профиль из полей формы
          */
         /**
          * Проверяем имя
          */
         if (func_check(getRequest('profile_name'), 'text', 2, 20)) {
             $this->oUserCurrent->setProfileName(getRequest('profile_name'));
         } else {
             $this->oUserCurrent->setProfileName(null);
         }
         /**
          * Проверка мыла
          */
         if (func_check(getRequest('mail'), 'mail')) {
             if ($oUserMail = $this->User_GetUserByMail(getRequest('mail')) and $oUserMail->getId() != $this->oUserCurrent->getId()) {
                 $this->Message_AddError($this->Lang_Get('settings_profile_mail_error_used'), $this->Lang_Get('error'));
                 $bError = true;
             } else {
                 $this->oUserCurrent->setMail(getRequest('mail'));
             }
         } else {
             $this->Message_AddError($this->Lang_Get('settings_profile_mail_error'), $this->Lang_Get('error'));
             $bError = true;
         }
         /**
          * Проверяем пол
          */
         if (in_array(getRequest('profile_sex'), array('man', 'woman', 'other'))) {
             $this->oUserCurrent->setProfileSex(getRequest('profile_sex'));
         } else {
             $this->oUserCurrent->setProfileSex('other');
         }
         /**
          * Проверяем дату рождения
          */
         if (func_check(getRequest('profile_birthday_day'), 'id', 1, 2) and func_check(getRequest('profile_birthday_month'), 'id', 1, 2) and func_check(getRequest('profile_birthday_year'), 'id', 4, 4)) {
             $this->oUserCurrent->setProfileBirthday(date("Y-m-d H:i:s", mktime(0, 0, 0, getRequest('profile_birthday_month'), getRequest('profile_birthday_day'), getRequest('profile_birthday_year'))));
         } else {
             $this->oUserCurrent->setProfileBirthday(null);
         }
         /**
          * Проверяем страну
          */
         if (func_check(getRequest('profile_country'), 'text', 1, 30)) {
             $this->oUserCurrent->setProfileCountry(getRequest('profile_country'));
         } else {
             $this->oUserCurrent->setProfileCountry(null);
         }
         /**
          * Проверяем регион
          * пока отключим регион, т.к. не понятно нужен ли он вообще =)
          */
         /*
         if (func_check(getRequest('profile_region'),'text',1,30)) {
         	$this->oUserCurrent->setProfileRegion(getRequest('profile_region'));
         } else {
         	$this->oUserCurrent->setProfileRegion(null);
         }
         */
         /**
          * Проверяем город
          */
         if (func_check(getRequest('profile_city'), 'text', 1, 30)) {
             $this->oUserCurrent->setProfileCity(getRequest('profile_city'));
         } else {
             $this->oUserCurrent->setProfileCity(null);
         }
         /**
          * Проверяем ICQ
          */
         if (func_check(getRequest('profile_icq'), 'id', 4, 15)) {
             $this->oUserCurrent->setProfileIcq(getRequest('profile_icq'));
         } else {
             $this->oUserCurrent->setProfileIcq(null);
         }
         /**
          * Проверяем сайт
          */
         if (func_check(getRequest('profile_site'), 'text', 3, 200)) {
             $this->oUserCurrent->setProfileSite(getRequest('profile_site'));
         } else {
             $this->oUserCurrent->setProfileSite(null);
         }
         /**
          * Проверяем название сайта
          */
         if (func_check(getRequest('profile_site_name'), 'text', 3, 50)) {
             $this->oUserCurrent->setProfileSiteName(getRequest('profile_site_name'));
         } else {
             $this->oUserCurrent->setProfileSiteName(null);
         }
         /**
          * Проверяем информацию о себе
          */
         if (func_check(getRequest('profile_about'), 'text', 1, 3000)) {
             $this->oUserCurrent->setProfileAbout(getRequest('profile_about'));
         } else {
             $this->oUserCurrent->setProfileAbout(null);
         }
         /**
          * Проверка на смену пароля
          */
         if (getRequest('password', '') != '') {
             if (func_check(getRequest('password'), 'password', 5)) {
                 if (getRequest('password') == getRequest('password_confirm')) {
                     if (func_encrypt(getRequest('password_now')) == $this->oUserCurrent->getPassword()) {
                         $this->oUserCurrent->setPassword(func_encrypt(getRequest('password')));
                     } else {
                         $bError = true;
                         $this->Message_AddError($this->Lang_Get('settings_profile_password_current_error'), $this->Lang_Get('error'));
                     }
                 } else {
                     $bError = true;
                     $this->Message_AddError($this->Lang_Get('settings_profile_password_confirm_error'), $this->Lang_Get('error'));
                 }
             } else {
                 $bError = true;
                 $this->Message_AddError($this->Lang_Get('settings_profile_password_new_error'), $this->Lang_Get('error'));
             }
         }
         /**
          * Загрузка аватара, делаем ресайзы
          */
         if (isset($_FILES['avatar']) and is_uploaded_file($_FILES['avatar']['tmp_name'])) {
             /**
              * Получаем список текущих аватаров
              */
             $sPathOld = $this->oUserCurrent->getProfileAvatar();
             $aUserAvatars = array();
             if ($sPathOld) {
                 foreach (array_merge(Config::Get('module.user.avatar_size'), array(100)) as $iSize) {
                     $aUserAvatars[$iSize] = $this->oUserCurrent->getProfileAvatarPath($iSize);
                 }
             }
             if ($sPath = $this->User_UploadAvatar($_FILES['avatar'], $this->oUserCurrent)) {
                 $this->oUserCurrent->setProfileAvatar($sPath);
                 /**
                  * Удаляем старые, если путь не совпадает с текущими аватарками
                  */
                 if ($sPathOld and $sPath != $sPathOld and count($aUserAvatars)) {
                     foreach ($aUserAvatars as $iSize => $sAvatarPath) {
                         @unlink($this->Image_GetServerPath($sAvatarPath));
                     }
                 }
             } else {
                 $bError = true;
                 $this->Message_AddError($this->Lang_Get('settings_profile_avatar_error'), $this->Lang_Get('error'));
             }
         }
         /**
          * Удалить аватара
          */
         if (getRequest('avatar_delete')) {
             $this->User_DeleteAvatar($this->oUserCurrent);
             $this->oUserCurrent->setProfileAvatar(null);
         }
         /**
          * Загрузка фото, делаем ресайзы
          */
         if (isset($_FILES['foto']) and is_uploaded_file($_FILES['foto']['tmp_name'])) {
             if ($sFileFoto = $this->User_UploadFoto($_FILES['foto'], $this->oUserCurrent)) {
                 $this->oUserCurrent->setProfileFoto($sFileFoto);
             } else {
                 $bError = true;
                 $this->Message_AddError($this->Lang_Get('settings_profile_foto_error'), $this->Lang_Get('error'));
             }
         }
         /**
          * Удалить фото
          */
         if (isset($_REQUEST['foto_delete'])) {
             $this->User_DeleteFoto($this->oUserCurrent);
             $this->oUserCurrent->setProfileFoto(null);
         }
         /**
          * Ставим дату последнего изменения профиля
          */
         $this->oUserCurrent->setProfileDate(date("Y-m-d H:i:s"));
         /**
          * Сохраняем изменения профиля
          */
         if (!$bError) {
             if ($this->User_Update($this->oUserCurrent)) {
                 /**
                  * Добавляем страну
                  */
                 if ($this->oUserCurrent->getProfileCountry()) {
                     if (!($oCountry = $this->User_GetCountryByName($this->oUserCurrent->getProfileCountry()))) {
                         $oCountry = Engine::GetEntity('User_Country');
                         $oCountry->setName($this->oUserCurrent->getProfileCountry());
                         $this->User_AddCountry($oCountry);
                     }
                     $this->User_SetCountryUser($oCountry->getId(), $this->oUserCurrent->getId());
                 }
                 /**
                  * Добавляем город
                  */
                 if ($this->oUserCurrent->getProfileCity()) {
                     if (!($oCity = $this->User_GetCityByName($this->oUserCurrent->getProfileCity()))) {
                         $oCity = Engine::GetEntity('User_City');
                         $oCity->setName($this->oUserCurrent->getProfileCity());
                         $this->User_AddCity($oCity);
                     }
                     $this->User_SetCityUser($oCity->getId(), $this->oUserCurrent->getId());
                 }
                 $this->Message_AddNoticeSingle($this->Lang_Get('settings_profile_submit_ok'));
             } else {
                 $this->Message_AddErrorSingle($this->Lang_Get('system_error'));
             }
         }
     }
 }
 /**
  * Обработка напоминания пароля, подтверждение смены пароля
  *
  */
 protected function EventReminder()
 {
     /**
      * Устанавливаем title страницы
      */
     $this->Viewer_AddHtmlTitle($this->Lang_Get('password_reminder'));
     /**
      * Проверка кода на восстановление пароля и генерация нового пароля
      */
     if (func_check($this->GetParam(0), 'md5')) {
         /**
          * Проверка кода подтверждения
          */
         if ($oReminder = $this->User_GetReminderByCode($this->GetParam(0))) {
             if (!$oReminder->getIsUsed() and strtotime($oReminder->getDateExpire()) > time() and $oUser = $this->User_GetUserById($oReminder->getUserId())) {
                 $sNewPassword = func_generator(7);
                 $oUser->setPassword(func_encrypt($sNewPassword));
                 if ($this->User_Update($oUser)) {
                     $oReminder->setDateUsed(date("Y-m-d H:i:s"));
                     $oReminder->setIsUsed(1);
                     $this->User_UpdateReminder($oReminder);
                     $this->Notify_SendReminderPassword($oUser, $sNewPassword);
                     $this->SetTemplateAction('reminder_confirm');
                     return;
                 }
             }
         }
         $this->Message_AddErrorSingle($this->Lang_Get('password_reminder_bad_code'), $this->Lang_Get('error'));
         return Router::Action('error');
     }
 }
Example #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();
     }
 }
 /**
  * Проверка полей формы
  *
  * @param ModuleTopic_EntityTopic $oTopic
  * @return bool
  */
 protected function checkTopicFields($oTopic)
 {
     $this->Security_ValidateSendForm();
     $bOk = true;
     if (!$oTopic->_Validate()) {
         $this->Message_AddError($oTopic->_getValidateError(), $this->Lang_Get('error'));
         $bOk = false;
     }
     /**
      * проверяем заполнение ответов только если еще никто не голосовал
      */
     if ($oTopic->getQuestionCountVote() == 0) {
         /**
          * Проверяем варианты ответов
          */
         $aAnswers = getRequest('answer', array());
         foreach ($aAnswers as $key => $sAnswer) {
             $sAnswer = (string) $sAnswer;
             if (trim($sAnswer) == '') {
                 unset($aAnswers[$key]);
                 continue;
             }
             if (!func_check($sAnswer, 'text', 1, 100)) {
                 $this->Message_AddError($this->Lang_Get('topic_question_create_answers_error'), $this->Lang_Get('error'));
                 $bOk = false;
                 break;
             }
         }
         $_REQUEST['answer'] = $aAnswers;
         /**
          * Ограничения на количество вариантов
          */
         if (count($aAnswers) < 2) {
             $this->Message_AddError($this->Lang_Get('topic_question_create_answers_error_min'), $this->Lang_Get('error'));
             $bOk = false;
         }
         if (count($aAnswers) > 20) {
             $this->Message_AddError($this->Lang_Get('topic_question_create_answers_error_max'), $this->Lang_Get('error'));
             $bOk = false;
         }
     }
     /**
      * Выполнение хуков
      */
     $this->Hook_Run('check_question_fields', array('bOk' => &$bOk));
     return $bOk;
 }
Example #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'));
     }
 }
Example #30
0
 /**
  * Обрабатывает активацию аккаунта
  *
  * @return unknown
  */
 protected function EventActivate()
 {
     $bError = false;
     /**
      * Проверяет передан ли код активации
      */
     $sActivateKey = $this->GetParam(0);
     if (!func_check($sActivateKey, 'md5')) {
         $bError = true;
     }
     /**
      * Проверяет верный ли код активации
      */
     if (!($oUser = $this->User_GetUserByActivateKey($sActivateKey))) {
         $bError = true;
     }
     /**
      * 
      */
     if ($oUser and $oUser->getActivate()) {
         $this->Message_AddErrorSingle($this->Lang_Get('registration_activate_error_reactivate'), $this->Lang_Get('error'));
         return Router::Action('error');
     }
     /**
      * Если что то не то
      */
     if ($bError) {
         $this->Message_AddErrorSingle($this->Lang_Get('registration_activate_error_code'), $this->Lang_Get('error'));
         return Router::Action('error');
     }
     /**
      * Активируем
      */
     $oUser->setActivate(1);
     $oUser->setDateActivate(date("Y-m-d H:i:s"));
     /**
      * Сохраняем юзера
      */
     if ($this->User_Update($oUser)) {
         $this->DropInviteRegister();
         $this->Viewer_Assign('bRefreshToHome', true);
         $this->User_Authorization($oUser, false);
         return;
     } else {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'));
         return Router::Action('error');
     }
 }