2011-05-23 16:55:40 +03:00
|
|
|
|
<?php
|
2014-10-08 08:20:29 +03:00
|
|
|
|
/*
|
|
|
|
|
* LiveStreet CMS
|
|
|
|
|
* Copyright © 2013 OOO "ЛС-СОФТ"
|
|
|
|
|
*
|
|
|
|
|
* ------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* Official site: www.livestreetcms.com
|
|
|
|
|
* Contact e-mail: office@livestreetcms.com
|
|
|
|
|
*
|
|
|
|
|
* GNU General Public License, version 2:
|
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
|
*
|
|
|
|
|
* ------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* @link http://www.livestreetcms.com
|
|
|
|
|
* @copyright 2013 OOO "ЛС-СОФТ"
|
|
|
|
|
* @author Maxim Mzhelskiy <rus.engine@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
*/
|
2011-05-23 16:55:40 +03:00
|
|
|
|
|
2011-08-28 19:52:30 +03:00
|
|
|
|
/**
|
|
|
|
|
* Обрабатывает пользовательские ленты контента
|
|
|
|
|
*
|
2014-10-08 08:20:29 +03:00
|
|
|
|
* @package application.actions
|
2012-05-04 13:12:21 +03:00
|
|
|
|
* @since 1.0
|
2011-08-28 19:52:30 +03:00
|
|
|
|
*/
|
2014-10-08 11:49:34 +03:00
|
|
|
|
class ActionUserfeed extends Action
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Текущий пользователь
|
|
|
|
|
*
|
|
|
|
|
* @var ModuleUser_EntityUser|null
|
|
|
|
|
*/
|
|
|
|
|
protected $oUserCurrent;
|
2011-05-23 16:55:40 +03:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
/**
|
|
|
|
|
* Инициализация
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function Init()
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Доступ только у авторизованных пользователей
|
|
|
|
|
*/
|
|
|
|
|
$this->oUserCurrent = $this->User_getUserCurrent();
|
|
|
|
|
if (!$this->oUserCurrent) {
|
|
|
|
|
parent::EventNotFound();
|
|
|
|
|
}
|
|
|
|
|
$this->Viewer_Assign('sMenuItemSelect', 'feed');
|
|
|
|
|
}
|
2014-07-19 19:50:52 +03:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
/**
|
|
|
|
|
* Регистрация евентов
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function RegisterEvent()
|
|
|
|
|
{
|
2014-11-25 12:01:57 +02:00
|
|
|
|
$this->AddEventPreg('/^(page([1-9]\d{0,5}))?$/i', 'EventIndex');
|
2014-10-08 11:49:34 +03:00
|
|
|
|
$this->AddEvent('subscribe', 'EventSubscribe');
|
|
|
|
|
$this->AddEvent('ajaxadduser', 'EventAjaxAddUser');
|
|
|
|
|
$this->AddEvent('unsubscribe', 'EventUnSubscribe');
|
|
|
|
|
}
|
2014-07-19 19:50:52 +03:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
/**
|
|
|
|
|
* Выводит ленту контента(топики) для пользователя
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function EventIndex()
|
|
|
|
|
{
|
2014-11-25 12:01:57 +02:00
|
|
|
|
/**
|
|
|
|
|
* Передан ли номер страницы
|
|
|
|
|
*/
|
|
|
|
|
$iPage = $this->GetEventMatch(2) ? $this->GetEventMatch(2) : 1;
|
|
|
|
|
|
|
|
|
|
$aResult = $this->Userfeed_read($this->oUserCurrent->getId(),$iPage,Config::Get('module.topic.per_page'));
|
|
|
|
|
$aTopics = $aResult['collection'];
|
2014-07-19 19:50:52 +03:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
// Вызов хуков
|
|
|
|
|
$this->Hook_Run('topics_list_show', array('aTopics' => $aTopics));
|
|
|
|
|
/**
|
2014-11-25 12:01:57 +02:00
|
|
|
|
* Формируем постраничность
|
2014-10-08 11:49:34 +03:00
|
|
|
|
*/
|
2014-11-25 12:01:57 +02:00
|
|
|
|
$aPaging = $this->Viewer_MakePaging($aResult['count'], $iPage, Config::Get('module.topic.per_page'),
|
|
|
|
|
Config::Get('pagination.pages.count'), Router::GetPath('feed'));
|
2014-10-08 11:49:34 +03:00
|
|
|
|
/**
|
2014-11-25 12:01:57 +02:00
|
|
|
|
* Загружаем переменные в шаблон
|
2014-10-08 11:49:34 +03:00
|
|
|
|
*/
|
2014-12-05 13:49:29 +02:00
|
|
|
|
$this->Viewer_Assign('topics', $aTopics);
|
|
|
|
|
$this->Viewer_Assign('paging', $aPaging);
|
2014-02-07 12:26:28 +02:00
|
|
|
|
|
2014-11-25 12:01:57 +02:00
|
|
|
|
$this->SetTemplateAction('list');
|
2014-10-08 11:49:34 +03:00
|
|
|
|
}
|
2014-11-25 12:01:57 +02:00
|
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
|
/**
|
|
|
|
|
* Подписка на контент блога или пользователя
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function EventSubscribe()
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Устанавливаем формат Ajax ответа
|
|
|
|
|
*/
|
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
|
|
|
|
/**
|
|
|
|
|
* Проверяем наличие ID блога или пользователя
|
|
|
|
|
*/
|
|
|
|
|
if (!getRequest('id')) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error'));
|
|
|
|
|
}
|
|
|
|
|
$sType = getRequestStr('type');
|
|
|
|
|
$iType = null;
|
|
|
|
|
/**
|
|
|
|
|
* Определяем тип подписки
|
|
|
|
|
*/
|
|
|
|
|
switch ($sType) {
|
|
|
|
|
case 'blogs':
|
|
|
|
|
$iType = ModuleUserfeed::SUBSCRIBE_TYPE_BLOG;
|
|
|
|
|
/**
|
|
|
|
|
* Проверяем существование блога
|
|
|
|
|
*/
|
2014-12-01 09:09:09 +02:00
|
|
|
|
if (!($oBlog=$this->Blog_GetBlogById(getRequestStr('id'))) or !$this->ACL_IsAllowShowBlog($oBlog,$this->oUserCurrent)) {
|
2014-10-08 11:49:34 +03:00
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'users':
|
|
|
|
|
$iType = ModuleUserfeed::SUBSCRIBE_TYPE_USER;
|
|
|
|
|
/**
|
|
|
|
|
* Проверяем существование пользователя
|
|
|
|
|
*/
|
|
|
|
|
if (!$this->User_GetUserById(getRequestStr('id'))) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ($this->oUserCurrent->getId() == getRequestStr('id')) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('user_list_add.notices.error_self'),
|
|
|
|
|
$this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Подписываем
|
|
|
|
|
*/
|
|
|
|
|
$this->Userfeed_subscribeUser($this->oUserCurrent->getId(), $iType, getRequestStr('id'));
|
|
|
|
|
$this->Message_AddNotice($this->Lang_Get('common.success.save'), $this->Lang_Get('attention'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Подписка на пользвователя по логину
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function EventAjaxAddUser()
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Устанавливаем формат Ajax ответа
|
|
|
|
|
*/
|
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
|
|
|
|
$aUsers = getRequest('aUserList', null, 'post');
|
|
|
|
|
/**
|
|
|
|
|
* Валидация
|
|
|
|
|
*/
|
|
|
|
|
if (!is_array($aUsers)) {
|
|
|
|
|
return $this->EventErrorDebug();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Если пользователь не авторизирован, возвращаем ошибку
|
|
|
|
|
*/
|
|
|
|
|
if (!$this->User_IsAuthorization()) {
|
|
|
|
|
$this->Message_AddErrorSingle($this->Lang_Get('need_authorization'), $this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$aResult = array();
|
|
|
|
|
/**
|
|
|
|
|
* Обрабатываем добавление по каждому из переданных логинов
|
|
|
|
|
*/
|
|
|
|
|
foreach ($aUsers as $sUser) {
|
|
|
|
|
$sUser = trim($sUser);
|
|
|
|
|
if ($sUser == '') {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Если пользователь не найден или неактивен, возвращаем ошибку
|
|
|
|
|
*/
|
|
|
|
|
if ($oUser = $this->User_GetUserByLogin($sUser) and $oUser->getActivate() == 1) {
|
|
|
|
|
$this->Userfeed_subscribeUser($this->oUserCurrent->getId(), ModuleUserfeed::SUBSCRIBE_TYPE_USER,
|
|
|
|
|
$oUser->getId());
|
|
|
|
|
|
|
|
|
|
$oViewer = $this->Viewer_GetLocalViewer();
|
2014-11-09 16:19:58 +02:00
|
|
|
|
$oViewer->Assign('user', $oUser, true);
|
|
|
|
|
$oViewer->Assign('showActions', true, true);
|
2014-10-08 11:49:34 +03:00
|
|
|
|
|
|
|
|
|
$aResult[] = array(
|
|
|
|
|
'bStateError' => false,
|
|
|
|
|
'sMsgTitle' => $this->Lang_Get('attention'),
|
|
|
|
|
'sMsg' => $this->Lang_Get('common.success.add',
|
|
|
|
|
array('login' => htmlspecialchars($sUser))),
|
|
|
|
|
'sUserId' => $oUser->getId(),
|
|
|
|
|
'sUserLogin' => htmlspecialchars($sUser),
|
|
|
|
|
'sUserWebPath' => $oUser->getUserWebPath(),
|
|
|
|
|
'sUserAvatar48' => $oUser->getProfileAvatarPath(48),
|
2014-11-09 16:19:58 +02:00
|
|
|
|
'sHtml' => $oViewer->Fetch("components/user-list-add/item.tpl")
|
2014-10-08 11:49:34 +03:00
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$aResult[] = array(
|
|
|
|
|
'bStateError' => true,
|
|
|
|
|
'sMsgTitle' => $this->Lang_Get('error'),
|
|
|
|
|
'sMsg' => $this->Lang_Get('user.notices.not_found',
|
|
|
|
|
array('login' => htmlspecialchars($sUser))),
|
|
|
|
|
'sUserLogin' => htmlspecialchars($sUser)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Передаем во вьевер массив с результатами обработки по каждому пользователю
|
|
|
|
|
*/
|
|
|
|
|
$this->Viewer_AssignAjax('aUserList', $aResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Отписка от блога или пользователя
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function EventUnsubscribe()
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Устанавливаем формат Ajax ответа
|
|
|
|
|
*/
|
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
|
|
|
|
$sId = getRequestStr('id');
|
|
|
|
|
|
|
|
|
|
$sType = getRequestStr('type');
|
|
|
|
|
$iType = null;
|
|
|
|
|
/**
|
|
|
|
|
* Определяем от чего отписываемся
|
|
|
|
|
*/
|
|
|
|
|
switch ($sType) {
|
|
|
|
|
case 'blogs':
|
|
|
|
|
$iType = ModuleUserfeed::SUBSCRIBE_TYPE_BLOG;
|
|
|
|
|
break;
|
|
|
|
|
case 'users':
|
|
|
|
|
$iType = ModuleUserfeed::SUBSCRIBE_TYPE_USER;
|
|
|
|
|
$sId = getRequestStr('iUserId');
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!$sId) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Отписываем пользователя
|
|
|
|
|
*/
|
|
|
|
|
$this->Userfeed_unsubscribeUser($this->oUserCurrent->getId(), $iType, $sId);
|
|
|
|
|
$this->Message_AddNotice($this->Lang_Get('common.success.save'), $this->Lang_Get('attention'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* При завершении экшена загружаем в шаблон необходимые переменные
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function EventShutdown()
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Подсчитываем новые топики
|
|
|
|
|
*/
|
|
|
|
|
$iCountTopicsCollectiveNew = $this->Topic_GetCountTopicsCollectiveNew();
|
|
|
|
|
$iCountTopicsPersonalNew = $this->Topic_GetCountTopicsPersonalNew();
|
|
|
|
|
$iCountTopicsNew = $iCountTopicsCollectiveNew + $iCountTopicsPersonalNew;
|
|
|
|
|
/**
|
|
|
|
|
* Загружаем переменные в шаблон
|
|
|
|
|
*/
|
|
|
|
|
$this->Viewer_Assign('iCountTopicsCollectiveNew', $iCountTopicsCollectiveNew);
|
|
|
|
|
$this->Viewer_Assign('iCountTopicsPersonalNew', $iCountTopicsPersonalNew);
|
|
|
|
|
$this->Viewer_Assign('iCountTopicsNew', $iCountTopicsNew);
|
|
|
|
|
}
|
2011-05-23 16:55:40 +03:00
|
|
|
|
}
|