/** * Выводит список топиков * */ protected function EventShowTopics() { /** * Меню */ $this->sMenuSubItemSelect = $this->sCurrentEvent; /** * Передан ли номер страницы */ $iPage = $this->GetParamEventMatch(0, 2) ? $this->GetParamEventMatch(0, 2) : 1; /** * Получаем список топиков */ $aResult = E::ModuleTopic()->GetTopicsPersonalByUser($this->oUserCurrent->getId(), $this->sCurrentEvent == 'published' ? 1 : 0, $iPage, Config::Get('module.topic.per_page')); $aTopics = $aResult['collection']; /** * Формируем постраничность */ $aPaging = E::ModuleViewer()->MakePaging($aResult['count'], $iPage, Config::Get('module.topic.per_page'), Config::Get('pagination.pages.count'), R::GetPath('content') . $this->sCurrentEvent); /** * Загружаем переменные в шаблон */ E::ModuleViewer()->Assign('aPaging', $aPaging); E::ModuleViewer()->Assign('aTopics', $aTopics); E::ModuleViewer()->AddHtmlTitle(E::ModuleLang()->Get('topic_menu_' . $this->sCurrentEvent)); }
/** * Получение новых комментариев * */ protected function AjaxResponseComment() { /** * Устанавливаем формат Ajax ответа */ $this->Viewer_SetResponseAjax('json'); /** * Пользователь авторизован? */ if (!$this->oUserCurrent) { $this->oUserCurrent = $this->User_GetUserById(0); } /** * Топик существует? */ $idTopic = getRequest('idTarget', null, 'post'); if (!($oTopic = $this->Topic_GetTopicById($idTopic))) { $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error')); return; } $idCommentLast = getRequest('idCommentLast', null, 'post'); $selfIdComment = getRequest('selfIdComment', null, 'post'); $aComments = array(); /** * Если используется постраничность, возвращаем только добавленный комментарий */ if (getRequest('bUsePaging', null, 'post') and $selfIdComment) { if ($oComment = $this->Comment_GetCommentById($selfIdComment) and $oComment->getTargetId() == $oTopic->getId() and $oComment->getTargetType() == 'topic') { $oViewerLocal = $this->Viewer_GetLocalViewer(); $oViewerLocal->Assign('oUserCurrent', $this->oUserCurrent); $oViewerLocal->Assign('bOneComment', true); $oViewerLocal->Assign('oComment', $oComment); $sText = $oViewerLocal->Fetch($this->Comment_GetTemplateCommentByTarget($oTopic->getId(), 'topic')); $aCmt = array(); $aCmt[] = array('html' => $sText, 'obj' => $oComment); } else { $aCmt = array(); } $aReturn['comments'] = $aCmt; $aReturn['iMaxIdComment'] = $selfIdComment; } else { $aReturn = $this->Comment_GetCommentsNewByTargetId($oTopic->getId(), 'topic', $idCommentLast); } $iMaxIdComment = $aReturn['iMaxIdComment']; $oTopicRead = Engine::GetEntity('Topic_TopicRead'); $oTopicRead->setTopicId($oTopic->getId()); $oTopicRead->setUserId($this->oUserCurrent->getId()); $oTopicRead->setCommentCountLast($oTopic->getCountComment()); $oTopicRead->setCommentIdLast($iMaxIdComment); $oTopicRead->setDateRead(date("Y-m-d H:i:s")); $this->Topic_SetTopicRead($oTopicRead); $aCmts = $aReturn['comments']; if ($aCmts and is_array($aCmts)) { foreach ($aCmts as $aCmt) { $aComments[] = array('html' => $aCmt['html'], 'idParent' => $aCmt['obj']->getPid(), 'id' => $aCmt['obj']->getId()); } } $this->Viewer_AssignAjax('iMaxIdComment', $iMaxIdComment); $this->Viewer_AssignAjax('aComments', $aComments); }
/** * Обработка завершения работу экшена */ public function EventShutdown() { if (!E::User()) { return; } $iCountTalkFavourite = E::ModuleTalk()->GetCountTalksFavouriteByUserId($this->oUserCurrent->getId()); E::ModuleViewer()->Assign('iCountTalkFavourite', $iCountTalkFavourite); $iUserId = E::UserId(); // Get stats of various user publications topics, comments, images, etc. and stats of favourites $aProfileStats = E::ModuleUser()->GetUserProfileStats($iUserId); // Получим информацию об изображениях пользователя /** @var ModuleMresource_EntityMresourceCategory[] $aUserImagesInfo */ $aUserImagesInfo = E::ModuleMresource()->GetAllImageCategoriesByUserId($iUserId); E::ModuleViewer()->Assign('oUserProfile', E::User()); E::ModuleViewer()->Assign('aProfileStats', $aProfileStats); E::ModuleViewer()->Assign('aUserImagesInfo', $aUserImagesInfo); // Old style skin compatibility E::ModuleViewer()->Assign('iCountTopicUser', $aProfileStats['count_topics']); E::ModuleViewer()->Assign('iCountCommentUser', $aProfileStats['count_comments']); E::ModuleViewer()->Assign('iCountTopicFavourite', $aProfileStats['favourite_topics']); E::ModuleViewer()->Assign('iCountCommentFavourite', $aProfileStats['favourite_comments']); E::ModuleViewer()->Assign('iCountNoteUser', $aProfileStats['count_usernotes']); E::ModuleViewer()->Assign('iCountWallUser', $aProfileStats['count_wallrecords']); E::ModuleViewer()->Assign('iPhotoCount', $aProfileStats['count_images']); E::ModuleViewer()->Assign('iCountCreated', $aProfileStats['count_created']); E::ModuleViewer()->Assign('iCountFavourite', $aProfileStats['count_favourites']); E::ModuleViewer()->Assign('iCountFriendsUser', $aProfileStats['count_friends']); E::ModuleViewer()->Assign('sMenuSubItemSelect', $this->sMenuSubItemSelect); E::ModuleViewer()->Assign('sMenuSubItemSelect', $this->sMenuSubItemSelect); // * Передаем константы состояний участников разговора E::ModuleViewer()->Assign('TALK_USER_ACTIVE', ModuleTalk::TALK_USER_ACTIVE); E::ModuleViewer()->Assign('TALK_USER_DELETE_BY_SELF', ModuleTalk::TALK_USER_DELETE_BY_SELF); E::ModuleViewer()->Assign('TALK_USER_DELETE_BY_AUTHOR', ModuleTalk::TALK_USER_DELETE_BY_AUTHOR); }
/** * Отписка от блога или пользователя * */ protected function EventUnsubscribe() { // * Устанавливаем формат Ajax ответа E::ModuleViewer()->SetResponseAjax('json'); if (!F::GetRequest('id')) { E::ModuleMessage()->AddError(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('error')); return; } $sType = F::GetRequestStr('type'); $iType = null; // * Определяем от чего отписываемся switch ($sType) { case 'blogs': case 'blog': $iType = ModuleUserfeed::SUBSCRIBE_TYPE_BLOG; break; case 'users': case 'user': $iType = ModuleUserfeed::SUBSCRIBE_TYPE_USER; break; default: E::ModuleMessage()->AddError(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('error')); return; } // * Отписываем пользователя E::ModuleUserfeed()->UnsubscribeUser($this->oUserCurrent->getId(), $iType, F::GetRequestStr('id')); E::ModuleMessage()->AddNotice(E::ModuleLang()->Get('userfeed_subscribes_updated'), E::ModuleLang()->Get('attention')); }
/** * Голосование админа */ public function EventAjaxVote() { // * Устанавливаем формат ответа E::ModuleViewer()->SetResponseAjax('json'); if (!E::IsAdmin()) { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('need_authorization'), E::ModuleLang()->Get('error')); return; } $nUserId = $this->GetPost('idUser'); if (!$nUserId || !($oUser = E::ModuleUser()->GetUserById($nUserId))) { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('user_not_found'), E::ModuleLang()->Get('error')); return; } $nValue = $this->GetPost('value'); $oUserVote = E::GetEntity('Vote'); $oUserVote->setTargetId($oUser->getId()); $oUserVote->setTargetType('user'); $oUserVote->setVoterId($this->oUserCurrent->getId()); $oUserVote->setDirection($nValue); $oUserVote->setDate(F::Now()); $iVal = (double) E::ModuleRating()->VoteUser($this->oUserCurrent, $oUser, $nValue); $oUserVote->setValue($iVal); $oUser->setCountVote($oUser->getCountVote() + 1); if (E::ModuleVote()->AddVote($oUserVote) && E::ModuleUser()->Update($oUser)) { E::ModuleViewer()->AssignAjax('iRating', $oUser->getRating()); E::ModuleViewer()->AssignAjax('iSkill', $oUser->getSkill()); E::ModuleViewer()->AssignAjax('iCountVote', $oUser->getCountVote()); E::ModuleMessage()->AddNoticeSingle(E::ModuleLang()->Get('user_vote_ok'), E::ModuleLang()->Get('attention')); } else { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('action.admin.vote_error'), E::ModuleLang()->Get('error')); } }
/** * Обработка завершения работу экшена */ public function EventShutdown() { if (!$this->oUserCurrent) { return; } $iCountTalkFavourite = $this->Talk_GetCountTalksFavouriteByUserId($this->oUserCurrent->getId()); $this->Viewer_Assign('iCountTalkFavourite', $iCountTalkFavourite); $iCountTopicFavourite = $this->Topic_GetCountTopicsFavouriteByUserId($this->oUserCurrent->getId()); $iCountTopicUser = $this->Topic_GetCountTopicsPersonalByUser($this->oUserCurrent->getId(), 1); $iCountCommentUser = $this->Comment_GetCountCommentsByUserId($this->oUserCurrent->getId(), 'topic'); $iCountCommentFavourite = $this->Comment_GetCountCommentsFavouriteByUserId($this->oUserCurrent->getId()); $iCountNoteUser = $this->User_GetCountUserNotesByUserId($this->oUserCurrent->getId()); $this->Viewer_Assign('oUserProfile', $this->oUserCurrent); $this->Viewer_Assign('iCountWallUser', $this->Wall_GetCountWall(array('wall_user_id' => $this->oUserCurrent->getId(), 'pid' => null))); /** * Общее число публикация и избранного */ $this->Viewer_Assign('iCountCreated', $iCountNoteUser + $iCountTopicUser + $iCountCommentUser); $this->Viewer_Assign('iCountFavourite', $iCountCommentFavourite + $iCountTopicFavourite); $this->Viewer_Assign('iCountFriendsUser', $this->User_GetCountUsersFriend($this->oUserCurrent->getId())); $this->Viewer_Assign('sMenuProfileItemSelect', $this->sMenuProfileItemSelect); $this->Viewer_Assign('sMenuSubItemSelect', $this->sMenuSubItemSelect); /** * Передаем во вьевер константы состояний участников разговора */ $this->Viewer_Assign('TALK_USER_ACTIVE', ModuleTalk::TALK_USER_ACTIVE); $this->Viewer_Assign('TALK_USER_DELETE_BY_SELF', ModuleTalk::TALK_USER_DELETE_BY_SELF); $this->Viewer_Assign('TALK_USER_DELETE_BY_AUTHOR', ModuleTalk::TALK_USER_DELETE_BY_AUTHOR); }
/** * Отписка от пользователя */ protected function EventAjaxRemoveUser() { $iUserId = (int) getRequestStr('user_id'); /** * Устанавливаем формат Ajax ответа */ $this->Viewer_SetResponseAjax('json'); /** * Пользователь авторизован? */ if (!$this->oUserCurrent) { return $this->EventErrorDebug(); } /** * Пользователь с таким ID существует? */ if (!$this->User_GetUserById($iUserId)) { return $this->EventErrorDebug(); } /** * Отписываем */ $this->Stream_unsubscribeUser($this->oUserCurrent->getId(), $iUserId); $this->Message_AddNotice($this->Lang_Get('common.success.remove'), $this->Lang_Get('common.attention')); }
/** * Отписка от блога или пользователя * */ protected function EventUnsubscribe() { /** * Устанавливаем формат Ajax ответа */ $this->Viewer_SetResponseAjax('json'); if (!getRequest('id')) { $this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error')); return; } $sType = getRequestStr('type'); $iType = null; /** * Определяем от чего отписываемся */ switch ($sType) { case 'blogs': $iType = ModuleUserfeed::SUBSCRIBE_TYPE_BLOG; break; case 'users': $iType = ModuleUserfeed::SUBSCRIBE_TYPE_USER; break; default: $this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error')); return; } /** * Отписываем пользователя */ $this->Userfeed_unsubscribeUser($this->oUserCurrent->getId(), $iType, getRequestStr('id')); $this->Message_AddNotice($this->Lang_Get('userfeed_subscribes_updated'), $this->Lang_Get('attention')); }
/** * Обновляет юзера * * @param ModuleUser_EntityUser $oUser Объект пользователя * @return bool */ public function Update(ModuleUser_EntityUser $oUser) { $sql = "UPDATE " . Config::Get('db.table.user') . "\n SET\n user_password = ? ,\n user_mail = ? ,\n user_skill = ? ,\n user_date_activate = ? ,\n user_date_comment_last = ? ,\n user_rating = ? ,\n user_count_vote = ? ,\n user_activate = ? ,\n user_activate_key = ? ,\n user_profile_name = ? ,\n user_profile_sex = ? ,\n user_profile_country = ? ,\n user_profile_region = ? ,\n user_profile_city = ? ,\n user_profile_birthday = ? ,\n user_profile_about = ? ,\n user_profile_date = ? ,\n user_profile_avatar = ? ,\n user_profile_foto = ? ,\n user_settings_notice_new_topic = ? ,\n user_settings_notice_new_comment = ? ,\n user_settings_notice_new_talk = ? ,\n user_settings_notice_reply_comment = ? ,\n user_settings_notice_new_friend = ? ,\n user_settings_timezone = ?\n WHERE user_id = ?\n "; if ($this->oDb->query($sql, $oUser->getPassword(), $oUser->getMail(), $oUser->getSkill(), $oUser->getDateActivate(), $oUser->getDateCommentLast(), $oUser->getRating(), $oUser->getCountVote(), $oUser->getActivate(), $oUser->getActivateKey(), $oUser->getProfileName(), $oUser->getProfileSex(), $oUser->getProfileCountry(), $oUser->getProfileRegion(), $oUser->getProfileCity(), $oUser->getProfileBirthday(), $oUser->getProfileAbout(), $oUser->getProfileDate(), $oUser->getProfileAvatar(), $oUser->getProfileFoto(), $oUser->getSettingsNoticeNewTopic(), $oUser->getSettingsNoticeNewComment(), $oUser->getSettingsNoticeNewTalk(), $oUser->getSettingsNoticeReplyComment(), $oUser->getSettingsNoticeNewFriend(), $oUser->getSettingsTimezone(), $oUser->getId())) { return true; } return false; }
protected function updateUserCat(ModuleUser_EntityUser $oUser) { $sql = 'UPDATE ' . Config::Get('db.table.user') . ' SET user_cat = ? WHERE user_id = ?d'; if ($this->oDb->query($sql, $oUser->getCategory(), $oUser->getId()) !== null) { return true; } return false; }
/** * Возвращает список media с учетов прав доступа текущего пользователя * В методе происходит проверка на права: * 1. разрешаем объекты, которые создал пользователь * 2. разрешаем объекты, которые связаны таргетом, к которому у пользователя есть доступ на редактирование * @param array $aId * * @return array */ public function GetAllowMediaItemsById($aId) { $aIdItems = array(); foreach ((array) $aId as $iId) { $aIdItems[] = (int) $iId; } $aIdItemsAll = $aIdItems; if (is_array($aIdItems) and count($aIdItems)) { $iUserId = $this->oUserCurrent ? $this->oUserCurrent->getId() : null; $aMediaItems = $this->Media_GetMediaItemsByFilter(array('#where' => array('id in (?a) AND ( user_id is null OR user_id = ?d )' => array($aIdItems, $iUserId)), '#index-from-primary')); /** * Смотрим что осталось */ if (!is_null($iUserId) and $aIdItems = array_diff($aIdItems, array_keys($aMediaItems))) { $aMediaAllowIds = array(); $aTargetMediaGroup = $this->GetTargetItemsByFilter(array('media_id in' => $aIdItems, '#with' => 'media', '#index-group' => 'media_id')); $_this = $this; foreach ($aTargetMediaGroup as $iMediaId => $aTargetMedia) { /** * Проверяем каждый таргет */ foreach ($aTargetMedia as $oTargetMedia) { if ($this->Cache_Remember("media_check_target_{$oTargetMedia->getTargetType()}_{$oTargetMedia->getTargetId()}", function () use($_this, $oTargetMedia, $iUserId) { if ($oTargetMedia->getTargetId()) { return $_this->CheckTarget($oTargetMedia->getTargetType(), $oTargetMedia->getTargetId(), ModuleMedia::TYPE_CHECK_ALLOW_ADD); } if ($oMedia = $oTargetMedia->getMedia() and $oMedia->getUserId() == $iUserId) { return true; } return false; }, false, array(), 'life', true)) { $aMediaAllowIds[] = $oTargetMedia->getMediaId(); break; } } } if ($aMediaAllowIds) { $aMediaItems = $aMediaItems + $this->GetMediaItemsByFilter(array('id in' => $aMediaAllowIds, '#index-from-primary')); } } /** * Нужно отсортировать по первоначальному массиву $aIdItems */ $aReturn = array(); foreach ($aIdItemsAll as $iId) { if (isset($aMediaItems[$iId])) { $aReturn[$iId] = $aMediaItems[$iId]; } } return $aReturn; } return array(); }
/** * Изменение состояния подписки */ protected function EventAjaxSubscribeToggle() { /** * Устанавливаем формат Ajax ответа */ $this->Viewer_SetResponseAjax('json'); /** * Получаем емайл подписки и проверяем его на валидность */ $sMail = getRequestStr('mail'); if ($this->oUserCurrent) { $sMail = $this->oUserCurrent->getMail(); } if (!func_check($sMail, 'mail')) { $this->Message_AddError($this->Lang_Get('field.email.notices.error'), $this->Lang_Get('common.error.error')); return; } /** * Получаем тип объекта подписки */ $sTargetType = getRequestStr('target_type'); if (!$this->Subscribe_IsAllowTargetType($sTargetType)) { return $this->EventErrorDebug(); } $sTargetId = getRequestStr('target_id') ? getRequestStr('target_id') : null; $iValue = getRequest('value') ? 1 : 0; $oSubscribe = null; /** * Есть ли доступ к подписке гостям? */ if (!$this->oUserCurrent and !$this->Subscribe_IsAllowTargetForGuest($sTargetType)) { $this->Message_AddError($this->Lang_Get('common.error.need_authorization'), $this->Lang_Get('common.error.error')); return; } /** * Проверка объекта подписки */ if (!$this->Subscribe_CheckTarget($sTargetType, $sTargetId, $iValue)) { return $this->EventErrorDebug(); } /** * Если подписка еще не существовала, то создаем её */ if ($oSubscribe = $this->Subscribe_AddSubscribeSimple($sTargetType, $sTargetId, $sMail, $this->oUserCurrent ? $this->oUserCurrent->getId() : null)) { $oSubscribe->setStatus($iValue); $this->Subscribe_UpdateSubscribe($oSubscribe); $this->Message_AddNotice($this->Lang_Get('common.success.save'), $this->Lang_Get('common.attention')); return; } return $this->EventErrorDebug(); }
/** * Получение новых комментариев * */ protected function AjaxResponseComment() { $this->Viewer_SetResponseAjax('json'); if (!$this->oUserCurrent) { $this->Message_AddErrorSingle($this->Lang_Get('need_authorization'), $this->Lang_Get('error')); return; } $idImage = getRequest('idTarget', null, 'post'); if (!($oImage = $this->PluginLsgallery_Image_GetImageById($idImage))) { $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error')); return; } $idCommentLast = getRequest('idCommentLast', null, 'post'); $selfIdComment = getRequest('selfIdComment', null, 'post'); $aComments = array(); if (getRequest('bUsePaging', null, 'post') && $selfIdComment) { $oComment = $this->Comment_GetCommentById($selfIdComment); if ($oComment && $oComment->getTargetId() == $oImage->getId() && $oComment->getTargetType() == 'image') { $oViewerLocal = $this->Viewer_GetLocalViewer(); $oViewerLocal->Assign('oUserCurrent', $this->oUserCurrent); $oViewerLocal->Assign('bOneComment', true); $oViewerLocal->Assign('oComment', $oComment); $sText = $oViewerLocal->Fetch("comment.tpl"); $aCmt = array(); $aCmt[] = array('html' => $sText, 'obj' => $oComment); } else { $aCmt = array(); } $aReturn['comments'] = $aCmt; $aReturn['iMaxIdComment'] = $selfIdComment; } else { $aReturn = $this->Comment_GetCommentsNewByTargetId($oImage->getId(), 'image', $idCommentLast); } $iMaxIdComment = $aReturn['iMaxIdComment']; $oImageRead = Engine::GetEntity('PluginLsgallery_ModuleImage_EntityImageRead'); $oImageRead->setImageId($oImage->getId()); $oImageRead->setUserId($this->oUserCurrent->getId()); $oImageRead->setCommentCountLast($oImage->getCountComment()); $oImageRead->setCommentIdLast($iMaxIdComment); $oImageRead->setDateRead(); $this->PluginLsgallery_Image_SetImageRead($oImageRead); $aCmts = $aReturn['comments']; if ($aCmts and is_array($aCmts)) { foreach ($aCmts as $aCmt) { $aComments[] = array('html' => $aCmt['html'], 'idParent' => $aCmt['obj']->getPid(), 'id' => $aCmt['obj']->getId()); } } $this->Viewer_AssignAjax('iMaxIdComment', $iMaxIdComment); $this->Viewer_AssignAjax('aComments', $aComments); }
/** * Проверяет может ли пользователь создавать запись по времени */ public function CanPostTestimonialTime(ModuleUser_EntityUser $oUser) { // Для администраторов ограничение по времени не действует if ($oUser->isAdministrator() or Config::Get('plugin.testimonials.acl.create.limit_time') == 0 or $oUser->getRating() >= Config::Get('plugin.testimonials.acl.create.limit_time_rating')) { return true; } /** * Проверяем, если топик опубликованный меньше чем acl.create.topic.limit_time секунд назад */ $aTestimonials = $this->PluginTestimonials_Testimonials_GetTestimonialsItemsByFilter(array('#page' => array(1, 20), '#order' => array('id' => 'desc'), 'user_id' => $oUser->getId(), 'date_add >' => date("Y-m-d H:i:s", time() - Config::Get('plugin.testimonials.acl.create.limit_time')))); if (isset($aTestimonials['count']) and $aTestimonials['count'] > 0) { return false; } return true; }
/** * Проверка объекта подписки с типом "topic_new_comment" * Название метода формируется автоматически * * @param int $iTargetId ID владельца * @param int $iStatus Статус * * @return bool */ public function CheckTargetTopicNewComment($iTargetId, $iStatus) { if ($oTopic = E::ModuleTopic()->GetTopicById($iTargetId)) { /** * Топик может быть в закрытом блоге, поэтому необходимо разрешить подписку только если пользователь в нем состоит * Отписываться разрешаем с любого топика */ if ($iStatus == 1 && $oTopic->getBlog()->IsPrivate()) { if (!$this->oUserCurrent || !($oTopic->getBlog()->getOwnerId() == $this->oUserCurrent->getId() || E::ModuleBlog()->GetBlogUserByBlogIdAndUserId($oTopic->getBlogId(), $this->oUserCurrent->getId()))) { return false; } } return true; } return false; }
/** * Проверка объекта подписки с типом "topic_new_comment" * Название метода формируется автоматически * * @param int $iTargetId ID владельца * @param int $iStatus Статус * @return bool */ public function CheckTargetTopicNewComment($iTargetId, $iStatus) { if ($oTopic = $this->Topic_GetTopicById($iTargetId)) { /** * Топик может быть в закрытом блоге, поэтому необходимо разрешить подписку только если пользователь в нем состоит, или является автором блога * Отписываться разрешаем с любого топика */ if ($iStatus == 1 and $oTopic->getBlog()->getType() == 'close') { if (!$this->oUserCurrent or !($oTopic->getBlog()->getOwnerId() == $this->oUserCurrent->getId() or $this->Blog_GetBlogUserByBlogIdAndUserId($oTopic->getBlogId(), $this->oUserCurrent->getId()))) { return false; } } return true; } return false; }
/** * Выполняется при завершении работы экшена */ public function EventShutdown() { if (!$this->oUserProfile) { return; } /** * Загружаем в шаблон необходимые переменные */ $iCountTopicFavourite = E::ModuleTopic()->GetCountTopicsFavouriteByUserId($this->oUserProfile->getId()); $iCountTopicUser = E::ModuleTopic()->GetCountTopicsPersonalByUser($this->oUserProfile->getId(), 1); $iCountCommentUser = E::ModuleComment()->GetCountCommentsByUserId($this->oUserProfile->getId(), 'topic'); $iCountCommentFavourite = E::ModuleComment()->GetCountCommentsFavouriteByUserId($this->oUserProfile->getId()); $iCountNoteUser = E::ModuleUser()->GetCountUserNotesByUserId($this->oUserProfile->getId()); // Получим информацию об изображениях пользовтеля // И посчитаем общее количество картинок /** @var ModuleMresource_EntityMresourceCategory[] $aUserImagesInfo */ $aUserImagesInfo = E::ModuleMresource()->GetAllImageCategoriesByUserId($this->oUserProfile->getId()); $iPhotoCount = E::ModuleMresource()->GetCountImagesByUserId($this->oUserProfile->getId()); E::ModuleViewer()->Assign('oUserProfile', $this->oUserProfile); E::ModuleViewer()->Assign('iCountTopicUser', $iCountTopicUser); E::ModuleViewer()->Assign('iCountCommentUser', $iCountCommentUser); E::ModuleViewer()->Assign('iCountTopicFavourite', $iCountTopicFavourite); E::ModuleViewer()->Assign('iCountCommentFavourite', $iCountCommentFavourite); E::ModuleViewer()->Assign('iCountNoteUser', $iCountNoteUser); E::ModuleViewer()->Assign('iCountWallUser', E::ModuleWall()->GetCountWall(array('wall_user_id' => $this->oUserProfile->getId(), 'pid' => null))); E::ModuleViewer()->Assign('oUserImagesInfo', $aUserImagesInfo); E::ModuleViewer()->Assign('iPhotoCount', $iPhotoCount); /** * Общее число публикаций и избранного */ E::ModuleViewer()->Assign('iCountCreated', ($this->oUserCurrent && $this->oUserCurrent->getId() == $this->oUserProfile->getId() ? $iCountNoteUser : 0) + $iCountTopicUser + $iCountCommentUser + $iPhotoCount); E::ModuleViewer()->Assign('iCountFavourite', $iCountCommentFavourite + $iCountTopicFavourite); /** * Заметка текущего пользователя о юзере */ if ($this->oUserCurrent) { E::ModuleViewer()->Assign('oUserNote', $this->oUserProfile->getUserNote()); } E::ModuleViewer()->Assign('iCountFriendsUser', E::ModuleUser()->GetCountUsersFriend($this->oUserProfile->getId())); E::ModuleViewer()->Assign('sMenuSubItemSelect', $this->sMenuSubItemSelect); E::ModuleViewer()->Assign('sMenuHeadItemSelect', $this->sMenuHeadItemSelect); E::ModuleViewer()->Assign('USER_FRIEND_NULL', ModuleUser::USER_FRIEND_NULL); E::ModuleViewer()->Assign('USER_FRIEND_OFFER', ModuleUser::USER_FRIEND_OFFER); E::ModuleViewer()->Assign('USER_FRIEND_ACCEPT', ModuleUser::USER_FRIEND_ACCEPT); E::ModuleViewer()->Assign('USER_FRIEND_REJECT', ModuleUser::USER_FRIEND_REJECT); E::ModuleViewer()->Assign('USER_FRIEND_DELETE', ModuleUser::USER_FRIEND_DELETE); }
/** * Выполняется при завершении работы экшена */ public function EventShutdown() { if (!$this->oUserProfile) { return; } /** * Загружаем в шаблон необходимые переменные */ $iCountTopicFavourite = $this->Topic_GetCountTopicsFavouriteByUserId($this->oUserProfile->getId()); $iCountTopicUser = $this->Topic_GetCountTopicsPersonalByUser($this->oUserProfile->getId(), 1); $iCountCommentUser = $this->Comment_GetCountCommentsByUserId($this->oUserProfile->getId(), 'topic'); $iCountCommentFavourite = $this->Comment_GetCountCommentsFavouriteByUserId($this->oUserProfile->getId()); $iCountNoteUser = $this->User_GetCountUserNotesByUserId($this->oUserProfile->getId()); $this->Viewer_Assign('oUserProfile', $this->oUserProfile); $this->Viewer_Assign('iCountTopicUser', $iCountTopicUser); $this->Viewer_Assign('iCountCommentUser', $iCountCommentUser); $this->Viewer_Assign('iCountTopicFavourite', $iCountTopicFavourite); $this->Viewer_Assign('iCountCommentFavourite', $iCountCommentFavourite); $this->Viewer_Assign('iCountNoteUser', $iCountNoteUser); $this->Viewer_Assign('iCountWallUser', $this->Wall_GetCountWall(array('wall_user_id' => $this->oUserProfile->getId(), 'pid' => null))); /** * Общее число публикация и избранного */ $this->Viewer_Assign('iCountCreated', (($this->oUserCurrent and $this->oUserCurrent->getId() == $this->oUserProfile->getId()) ? $iCountNoteUser : 0) + $iCountTopicUser + $iCountCommentUser); $this->Viewer_Assign('iCountFavourite', $iCountCommentFavourite + $iCountTopicFavourite); /** * Заметка текущего пользователя о юзере */ if ($this->oUserCurrent) { $this->Viewer_Assign('oUserNote', $this->oUserProfile->getUserNote()); } $this->Viewer_Assign('iCountFriendsUser', $this->User_GetCountUsersFriend($this->oUserProfile->getId())); $this->Viewer_Assign('sMenuSubItemSelect', $this->sMenuSubItemSelect); $this->Viewer_Assign('sMenuHeadItemSelect', $this->sMenuHeadItemSelect); $this->Viewer_Assign('sMenuProfileItemSelect', $this->sMenuProfileItemSelect); $this->Viewer_Assign('USER_FRIEND_NULL', ModuleUser::USER_FRIEND_NULL); $this->Viewer_Assign('USER_FRIEND_OFFER', ModuleUser::USER_FRIEND_OFFER); $this->Viewer_Assign('USER_FRIEND_ACCEPT', ModuleUser::USER_FRIEND_ACCEPT); $this->Viewer_Assign('USER_FRIEND_REJECT', ModuleUser::USER_FRIEND_REJECT); $this->Viewer_Assign('USER_FRIEND_DELETE', ModuleUser::USER_FRIEND_DELETE); }
/** * Изменение состояния подписки */ protected function EventAjaxTrackToggle() { /** * Устанавливаем формат Ajax ответа */ E::ModuleViewer()->SetResponseAjax('json'); if (!$this->oUserCurrent) { E::ModuleMessage()->AddError(E::ModuleLang()->Get('need_authorization'), E::ModuleLang()->Get('error')); return; } /** * Получаем тип объекта подписки */ $sTargetType = F::GetRequestStr('target_type'); if (!E::ModuleSubscribe()->IsAllowTargetType($sTargetType)) { E::ModuleMessage()->AddError(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('error')); return; } $sTargetId = F::GetRequestStr('target_id') ? F::GetRequestStr('target_id') : null; $iValue = F::GetRequest('value') ? 1 : 0; $oTrack = null; /** * Проверка объекта подписки */ if (!E::ModuleSubscribe()->CheckTarget($sTargetType, $sTargetId, $iValue)) { E::ModuleMessage()->AddError(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('error')); return; } /** * Если подписка еще не существовала, то создаем её */ if ($oTrack = E::ModuleSubscribe()->AddTrackSimple($sTargetType, $sTargetId, $this->oUserCurrent->getId())) { $oTrack->setStatus($iValue); E::ModuleSubscribe()->UpdateTrack($oTrack); E::ModuleMessage()->AddNotice(E::ModuleLang()->Get('subscribe_change_ok'), E::ModuleLang()->Get('attention')); return; } E::ModuleMessage()->AddError(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('error')); return; }
/** * Выполняется при завершении работы экшена * */ public function EventShutdown() { $iCountTopicFavourite = $this->Topic_GetCountTopicsFavouriteByUserId($this->oUserCurrent->getId()); $iCountTopicUser = $this->Topic_GetCountTopicsPersonalByUser($this->oUserCurrent->getId(), 1); $iCountCommentUser = $this->Comment_GetCountCommentsByUserId($this->oUserCurrent->getId(), 'topic'); $iCountCommentFavourite = $this->Comment_GetCountCommentsFavouriteByUserId($this->oUserCurrent->getId()); $iCountNoteUser = $this->User_GetCountUserNotesByUserId($this->oUserCurrent->getId()); $this->Viewer_Assign('oUserProfile', $this->oUserCurrent); $this->Viewer_Assign('iCountWallUser', $this->Wall_GetCountWall(array('wall_user_id' => $this->oUserCurrent->getId(), 'pid' => null))); /** * Общее число публикация и избранного */ $this->Viewer_Assign('iCountCreated', $iCountNoteUser + $iCountTopicUser + $iCountCommentUser); $this->Viewer_Assign('iCountFavourite', $iCountCommentFavourite + $iCountTopicFavourite); $this->Viewer_Assign('iCountFriendsUser', $this->User_GetCountUsersFriend($this->oUserCurrent->getId())); /** * Загружаем в шаблон необходимые переменные */ $this->Viewer_Assign('sMenuItemSelect', $this->sMenuItemSelect); $this->Viewer_Assign('sMenuSubItemSelect', $this->sMenuSubItemSelect); $this->Hook_Run('action_shutdown_settings'); }
/** * Выполняется при завершении работы экшена */ public function EventShutdown() { if (!$this->oUserProfile) { return; } $iProfileUserId = $this->oUserProfile->getId(); // Get stats of various user publications topics, comments, images, etc. and stats of favourites $aProfileStats = E::ModuleUser()->GetUserProfileStats($iProfileUserId); // Получим информацию об изображениях пользователя /** @var ModuleMresource_EntityMresourceCategory[] $aUserImagesInfo */ //$aUserImagesInfo = E::ModuleMresource()->GetAllImageCategoriesByUserId($iProfileUserId); // * Загружаем в шаблон необходимые переменные E::ModuleViewer()->Assign('oUserProfile', $this->oUserProfile); E::ModuleViewer()->Assign('aProfileStats', $aProfileStats); // unused //E::ModuleViewer()->Assign('aUserImagesInfo', $aUserImagesInfo); // * Заметка текущего пользователя о юзере if (E::User()) { E::ModuleViewer()->Assign('oUserNote', $this->oUserProfile->getUserNote()); } E::ModuleViewer()->Assign('sMenuSubItemSelect', $this->sMenuSubItemSelect); E::ModuleViewer()->Assign('sMenuHeadItemSelect', $this->sMenuHeadItemSelect); E::ModuleViewer()->Assign('USER_FRIEND_NULL', ModuleUser::USER_FRIEND_NULL); E::ModuleViewer()->Assign('USER_FRIEND_OFFER', ModuleUser::USER_FRIEND_OFFER); E::ModuleViewer()->Assign('USER_FRIEND_ACCEPT', ModuleUser::USER_FRIEND_ACCEPT); E::ModuleViewer()->Assign('USER_FRIEND_REJECT', ModuleUser::USER_FRIEND_REJECT); E::ModuleViewer()->Assign('USER_FRIEND_DELETE', ModuleUser::USER_FRIEND_DELETE); // Old style skin compatibility E::ModuleViewer()->Assign('iCountTopicUser', $aProfileStats['count_topics']); E::ModuleViewer()->Assign('iCountCommentUser', $aProfileStats['count_comments']); E::ModuleViewer()->Assign('iCountTopicFavourite', $aProfileStats['favourite_topics']); E::ModuleViewer()->Assign('iCountCommentFavourite', $aProfileStats['favourite_comments']); E::ModuleViewer()->Assign('iCountNoteUser', $aProfileStats['count_usernotes']); E::ModuleViewer()->Assign('iCountWallUser', $aProfileStats['count_wallrecords']); E::ModuleViewer()->Assign('iPhotoCount', $aProfileStats['count_images']); E::ModuleViewer()->Assign('iCountCreated', $aProfileStats['count_created']); E::ModuleViewer()->Assign('iCountFavourite', $aProfileStats['count_favourites']); E::ModuleViewer()->Assign('iCountFriendsUser', $aProfileStats['count_friends']); }
/** * Добавление записи на стену */ public function EventWallAdd() { $this->Viewer_SetResponseAjax('json'); if (!$this->oUserCurrent) { return $this->EventErrorDebug(); } if (!$this->WallCheckUserProfile()) { return $this->EventErrorDebug(); } // Создаем запись $oWall = Engine::GetEntity('Wall'); $oWall->_setValidateScenario('add'); $oWall->setWallUserId($this->oUserProfile->getId()); $oWall->setUserId($this->oUserCurrent->getId()); $oWall->setText(getRequestStr('text')); $oWall->setPid(getRequestStr('pid')); $this->Hook_Run('wall_add_validate_before', array('oWall' => $oWall)); if ($oWall->_Validate()) { // Экранируем текст и добавляем запись в БД $oWall->setText($this->Text_Parser($oWall->getText())); $this->Hook_Run('wall_add_before', array('oWall' => $oWall)); if ($this->Wall_AddWall($oWall)) { $this->Hook_Run('wall_add_after', array('oWall' => $oWall)); // Отправляем уведомления if ($oWall->getWallUserId() != $oWall->getUserId()) { $this->Wall_SendNotifyWallNew($oWall, $this->oUserCurrent); } if ($oWallParent = $oWall->GetPidWall() and $oWallParent->getUserId() != $oWall->getUserId()) { $this->Wall_SendNotifyWallReply($oWallParent, $oWall, $this->oUserCurrent); } // Добавляем событие в ленту $this->Stream_Write($oWall->getUserId(), 'add_wall', $oWall->getId()); } else { $this->Message_AddError($this->Lang_Get('common.error.add'), $this->Lang_Get('common.error.error')); } } else { $this->Message_AddError($oWall->_getValidateError(), $this->Lang_Get('common.error.error')); } }
/** * Возвращает список опросов для объекта * * @param string $sTargetType * @param string $sTargetId * * @return mixed */ public function GetPollItemsByTarget($sTargetType, $sTargetId) { $aFilter = array('target_type' => $sTargetType, 'target_id' => $sTargetId, '#with' => array('answers')); if ($this->oUserCurrent) { $aFilter['#with']['vote_current'] = array('user_id' => $this->oUserCurrent->getId(), '#value-default' => false); } else { $_this = $this; $aFilter['#with']['vote_current'] = array('#value-default' => false, '#callback-filter' => function ($aPollItems, &$aRelationFilter) use($_this) { $aWhere = array(); $aWhereBind = array(); foreach ($aPollItems as $oPoll) { /** * Смотрим по IP */ if ($oPoll->getIsGuestCheckIp()) { $aWhere[] = ' ( t.poll_id = ?d and t.ip = ? ) '; $aWhereBind[] = $oPoll->getId(); $aWhereBind[] = func_getIp(); } /** * Смотрим в куках */ if ($sKey = $_this->Session_GetCookie($_this->GetCookieVoteName($oPoll->getId()))) { $aWhere[] = ' ( t.poll_id = ?d and t.guest_key = ? ) '; $aWhereBind[] = $oPoll->getId(); $aWhereBind[] = $sKey; } } if ($aWhere) { $aRelationFilter['#where'] = array(' ( ' . join(' or ', $aWhere) . ' ) ' => $aWhereBind); } else { $aRelationFilter['#value-set'] = false; } }); } $aPollItems = $this->Poll_GetPollItemsByFilter($aFilter); return $aPollItems; }
public function Update(ModuleUser_EntityUser $oUser) { $sql = 'UPDATE ' . Config::Get('db.table.user') . ' SET user_settings_notice_new_topic = ?, user_settings_notice_new_comment = ?, user_settings_notice_new_talk = ?, user_settings_notice_reply_comment = ?, user_settings_notice_new_friend = ?, user_settings_notice_new_topic_commented = ?, user_settings_notice_friend_news = ?, user_settings_notice_request = ?, user_settings_notice_new_comment_blogs_subscribe = ?, user_settings_notice_new_gift = ?, user_settings_notice_frequency = ?, user_settings_notice_new_user_blogs_subscribe = ? WHERE user_id = ? '; if ($this->oDb->query($sql, $oUser->getSettingsNoticeNewTopic(), $oUser->getSettingsNoticeNewComment(), $oUser->getSettingsNoticeNewTalk(), $oUser->getSettingsNoticeReplyComment(), $oUser->getSettingsNoticeNewFriend(), $oUser->getSettingsNoticeNewTopicCommented(), $oUser->getSettingsNoticeFriendNews(), $oUser->getSettingsNoticeRequest(), $oUser->getSettingsNoticeNewCommentBlogsSubscribe(), $oUser->getSettingsNoticeNewGift(), $oUser->getSettingsNoticeFrequency(), $oUser->getSettingsNoticeNewUserBlogsSubscribe(), $oUser->getId()) !== null) { return parent::Update($oUser); } return false; }
/** * Отписка от пользователя * */ protected function EventUnsubscribe() { /** * Устанавливаем формат Ajax ответа */ E::ModuleViewer()->SetResponseAjax('json'); /** * Пользователь авторизован? */ if (!$this->oUserCurrent) { parent::EventNotFound(); } /** * Пользователь с таким ID существует? */ if (!E::ModuleUser()->GetUserById(F::GetRequestStr('id'))) { E::ModuleMessage()->AddError(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('error')); } /** * Отписываем */ E::ModuleStream()->UnsubscribeUser($this->oUserCurrent->getId(), F::GetRequestStr('id')); E::ModuleMessage()->AddNotice(E::ModuleLang()->Get('stream_subscribes_updated'), E::ModuleLang()->Get('attention')); }
/** * Отписка от пользователя * */ protected function EventUnsubscribe() { /** * Устанавливаем формат Ajax ответа */ $this->Viewer_SetResponseAjax('json'); /** * Пользователь авторизован? */ if (!$this->oUserCurrent) { parent::EventNotFound(); } /** * Пользователь с таким ID существует? */ if (!$this->User_getUserById(getRequestStr('id'))) { $this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error')); } /** * Отписываем */ $this->Stream_unsubscribeUser($this->oUserCurrent->getId(), getRequestStr('id')); $this->Message_AddNotice($this->Lang_Get('stream_subscribes_updated'), $this->Lang_Get('attention')); }
/** * Is allow mark user on picture * * @param ModuleUser_EntityUser $oUserCurrent * @param ModuleUser_EntityUser $oUserMarked */ public function AllowAddUserToImage($oUserCurrent, $oUserMarked) { if ($oUserCurrent->getId() == $oUserMarked->getId()) { return true; } if ($oFriend = $this->User_GetFriend($oUserCurrent->getId(), $oUserMarked->getUserId())) { if ($oFriend->getFriendStatus() == ModuleUser::USER_FRIEND_ACCEPT + ModuleUser::USER_FRIEND_ACCEPT || $oFriend->getFriendStatus() == ModuleUser::USER_FRIEND_ACCEPT + ModuleUser::USER_FRIEND_OFFER) { return true; } } return false; }
/** * Выполняет отправку приглашения в блог * (по внутренней почте и на email) * * @param ModuleBlog_EntityBlog $oBlog * @param ModuleUser_EntityUser $oUser */ protected function SendBlogInvite($oBlog, $oUser) { $sTitle = $this->Lang_Get('blog_user_invite_title', array('blog_title' => $oBlog->getTitle())); require_once Config::Get('path.root.engine') . '/lib/external/XXTEA/encrypt.php'; $sCode = $oBlog->getId() . '_' . $oUser->getId(); $sCode = rawurlencode(base64_encode(xxtea_encrypt($sCode, Config::Get('module.blog.encrypt')))); $aPath = array('accept' => Router::GetPath('blog') . 'invite/accept/?code=' . $sCode, 'reject' => Router::GetPath('blog') . 'invite/reject/?code=' . $sCode); $sText = $this->Lang_Get('blog_user_invite_text', array('login' => $this->oUserCurrent->getLogin(), 'accept_path' => $aPath['accept'], 'reject_path' => $aPath['reject'], 'blog_title' => $oBlog->getTitle())); $oTalk = $this->Talk_SendTalk($sTitle, $sText, $this->oUserCurrent, array($oUser), false, false); /** * Отправляем пользователю заявку */ $this->Notify_SendBlogUserInvite($oUser, $this->oUserCurrent, $oBlog, Router::GetPath('talk') . 'read/' . $oTalk->getId() . '/'); /** * Удаляем отправляющего юзера из переписки */ $this->Talk_DeleteTalkUserByArray($oTalk->getId(), $this->oUserCurrent->getId()); }
/** * Save uploaded image into store * * @param string $sImageFile * @param ModuleUser_EntityUser $oUser * @param string $sType * @param array $aOptions * * @return bool */ protected function _saveTopicImage($sImageFile, $oUser, $sType, $aOptions = array()) { $sExtension = F::File_GetExtension($sImageFile, true); $aConfig = E::ModuleUploader()->GetConfig($sImageFile, 'images.' . $sType); if ($aOptions) { $aConfig['transform'] = F::Array_Merge($aConfig['transform'], $aOptions); } // Check whether to save the original if (isset($aConfig['original']['save']) && $aConfig['original']['save']) { $sSuffix = isset($aConfig['original']['suffix']) ? $aConfig['original']['suffix'] : '-original'; $sOriginalFile = F::File_Copy($sImageFile, $sImageFile . $sSuffix . '.' . $sExtension); } else { $sSuffix = ''; $sOriginalFile = null; } // Transform image before saving $sFileTmp = E::ModuleImg()->TransformFile($sImageFile, $aConfig['transform']); if ($sFileTmp) { $sDirUpload = E::ModuleUploader()->GetUserImageDir($oUser->getId(), true, $sType); $sFileImage = E::ModuleUploader()->Uniqname($sDirUpload, $sExtension); if ($oStoredFile = E::ModuleUploader()->Store($sFileTmp, $sFileImage)) { if ($sOriginalFile) { E::ModuleUploader()->Move($sOriginalFile, $oStoredFile->GetFile() . $sSuffix . '.' . $sExtension); } return $oStoredFile->GetUrl(); } } return false; }
/** * Формирование процесса смены емайла в профиле пользователя * * @param ModuleUser_EntityUser $oUser Объект пользователя * @param string $sMailNew Новый емайл * * @return bool|ModuleUser_EntityChangemail */ public function MakeUserChangemail($oUser, $sMailNew) { /** @var ModuleUser_EntityChangemail $oChangemail */ $oChangemail = E::GetEntity('ModuleUser_EntityChangemail'); $oChangemail->setUserId($oUser->getId()); $oChangemail->setDateAdd(date('Y-m-d H:i:s')); $oChangemail->setDateExpired(date('Y-m-d H:i:s', time() + 3 * 24 * 60 * 60)); // 3 дня для смены емайла $oChangemail->setMailFrom($oUser->getMail() ? $oUser->getMail() : ''); $oChangemail->setMailTo($sMailNew); $oChangemail->setCodeFrom(F::RandomStr(32)); $oChangemail->setCodeTo(F::RandomStr(32)); if ($this->AddUserChangemail($oChangemail)) { // * Если у пользователя раньше не было емайла, то сразу шлем подтверждение на новый емайл if (!$oChangemail->getMailFrom()) { $oChangemail->setConfirmFrom(1); E::ModuleUser()->UpdateUserChangemail($oChangemail); // * Отправляем уведомление на новый емайл E::ModuleNotify()->Send($oChangemail->getMailTo(), 'user_changemail_to.tpl', E::ModuleLang()->Get('notify_subject_user_changemail'), array('oUser' => $oUser, 'oChangemail' => $oChangemail), null, true); } else { // * Отправляем уведомление на старый емайл E::ModuleNotify()->Send($oUser, 'user_changemail_from.tpl', E::ModuleLang()->Get('notify_subject_user_changemail'), array('oUser' => $oUser, 'oChangemail' => $oChangemail), null, true); } return $oChangemail; } return false; }