2011-06-06 14:58:19 +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-06-06 14:58:19 +03:00
|
|
|
|
|
2011-08-28 21:49:01 +03:00
|
|
|
|
/**
|
2012-05-04 13:12:21 +03:00
|
|
|
|
* Экшен обработки ленты активности
|
2011-08-28 21:49:01 +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 21:49:01 +03:00
|
|
|
|
*/
|
2014-10-08 11:49:34 +03:00
|
|
|
|
class ActionStream extends Action
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Текущий пользователь
|
|
|
|
|
*
|
|
|
|
|
* @var ModuleUser_EntityUser|null
|
|
|
|
|
*/
|
|
|
|
|
protected $oUserCurrent;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Какое меню активно
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $sMenuItemSelect = 'user';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Инициализация
|
|
|
|
|
*/
|
|
|
|
|
public function Init()
|
|
|
|
|
{
|
|
|
|
|
$this->oUserCurrent = $this->User_getUserCurrent();
|
|
|
|
|
|
|
|
|
|
// Личная лента доступна только для авторизованных, гостям показываем общую ленту
|
|
|
|
|
if ($this->oUserCurrent) {
|
|
|
|
|
$this->SetDefaultEvent('personal');
|
|
|
|
|
} else {
|
|
|
|
|
$this->SetDefaultEvent('all');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->Viewer_Assign('sMenuHeadItemSelect', 'stream');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Загружаем в шаблон JS текстовки
|
|
|
|
|
*/
|
|
|
|
|
$this->Lang_AddLangJs(array(
|
|
|
|
|
'activity.notices.error_already_subscribed',
|
|
|
|
|
'error'
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Регистрация евентов
|
|
|
|
|
*/
|
|
|
|
|
protected function RegisterEvent()
|
|
|
|
|
{
|
|
|
|
|
$this->AddEvent('personal', 'EventPersonal');
|
|
|
|
|
$this->AddEvent('all', 'EventAll');
|
|
|
|
|
|
|
|
|
|
$this->AddEvent('subscribe', 'EventSubscribe'); // TODO: возможно нужно удалить
|
|
|
|
|
$this->AddEvent('ajaxadduser', 'EventAjaxAddUser');
|
|
|
|
|
$this->AddEvent('ajaxremoveuser', 'EventAjaxRemoveUser');
|
|
|
|
|
$this->AddEvent('switchEventType', 'EventSwitchEventType');
|
|
|
|
|
|
|
|
|
|
$this->AddEvent('get_more_all', 'EventGetMoreAll');
|
|
|
|
|
$this->AddEvent('get_more_personal', 'EventGetMore');
|
|
|
|
|
$this->AddEvent('get_more_user', 'EventGetMoreUser');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Персональная активность
|
|
|
|
|
*/
|
|
|
|
|
protected function EventPersonal()
|
|
|
|
|
{
|
|
|
|
|
if (!$this->oUserCurrent) {
|
|
|
|
|
return parent::EventNotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->Viewer_AddBlock('right', 'activitySettings');
|
|
|
|
|
$this->Viewer_AddBlock('right', 'activityUsers');
|
|
|
|
|
|
|
|
|
|
$this->Viewer_Assign('activityEvents', $this->Stream_Read());
|
|
|
|
|
$this->Viewer_Assign('activityEventsAllCount', $this->Stream_GetCountByReaderId($this->oUserCurrent->getId()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Общая активность
|
|
|
|
|
*/
|
|
|
|
|
protected function EventAll()
|
|
|
|
|
{
|
|
|
|
|
$this->sMenuItemSelect = 'all';
|
|
|
|
|
|
|
|
|
|
$this->Viewer_Assign('activityEvents', $this->Stream_ReadAll());
|
|
|
|
|
$this->Viewer_Assign('activityEventsAllCount', $this->Stream_GetCountAll());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Активаци/деактивация типа события
|
|
|
|
|
*/
|
|
|
|
|
protected function EventSwitchEventType()
|
|
|
|
|
{
|
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
|
|
|
|
|
|
|
|
|
if (!$this->oUserCurrent) {
|
|
|
|
|
return parent::EventNotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!getRequest('type')) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Активируем/деактивируем тип
|
|
|
|
|
*/
|
|
|
|
|
$this->Stream_switchUserEventType($this->oUserCurrent->getId(), getRequestStr('type'));
|
|
|
|
|
$this->Message_AddNotice($this->Lang_Get('common.success.save'), $this->Lang_Get('attention'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Подгрузка событий (замена постраничности)
|
|
|
|
|
*/
|
|
|
|
|
protected function EventGetMore()
|
|
|
|
|
{
|
|
|
|
|
if (!$this->oUserCurrent) {
|
|
|
|
|
return parent::EventNotFound();
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-11 19:22:26 +02:00
|
|
|
|
$_this=$this;
|
|
|
|
|
$this->GetMore(function ($lastId) use ($_this) {
|
|
|
|
|
return $_this->Stream_Read(null, $lastId);
|
2014-10-08 11:49:34 +03:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Подгрузка событий для всего сайта
|
|
|
|
|
*/
|
|
|
|
|
protected function EventGetMoreAll()
|
|
|
|
|
{
|
2015-01-11 19:22:26 +02:00
|
|
|
|
$_this=$this;
|
|
|
|
|
$this->GetMore(function ($lastId) use ($_this) {
|
|
|
|
|
return $_this->Stream_ReadAll(null, $lastId);
|
2014-10-08 11:49:34 +03:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Подгрузка событий для пользователя
|
|
|
|
|
*/
|
|
|
|
|
protected function EventGetMoreUser()
|
|
|
|
|
{
|
2015-01-11 19:22:26 +02:00
|
|
|
|
$_this=$this;
|
|
|
|
|
$this->GetMore(function ($lastId) use ($_this) {
|
|
|
|
|
if (!($oUser = $_this->User_GetUserById(getRequestStr('target_id')))) {
|
2014-10-08 11:49:34 +03:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-11 19:22:26 +02:00
|
|
|
|
return $_this->Stream_ReadByUserId($oUser->getId(), null, $lastId);
|
2014-10-08 11:49:34 +03:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Общий метод подгрузки событий
|
|
|
|
|
*
|
|
|
|
|
* @param callback $getEvents Метод возвращающий список событий
|
|
|
|
|
*/
|
|
|
|
|
protected function GetMore($getEvents)
|
|
|
|
|
{
|
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
|
|
|
|
|
|
|
|
|
// Необходимо передать последний просмотренный ID событий
|
|
|
|
|
$iLastId = getRequestStr('last_id');
|
|
|
|
|
|
|
|
|
|
if (!$iLastId) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Получаем события
|
|
|
|
|
$aEvents = $getEvents($iLastId);
|
|
|
|
|
|
|
|
|
|
if ($aEvents === false) {
|
|
|
|
|
return $this->EventErrorDebug();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$oViewer = $this->Viewer_GetLocalViewer();
|
|
|
|
|
|
|
|
|
|
$oViewer->Assign('events', $aEvents, true);
|
|
|
|
|
$oViewer->Assign('dateLast', getRequestStr('date_last'), true);
|
|
|
|
|
|
|
|
|
|
if (count($aEvents)) {
|
|
|
|
|
$this->Viewer_AssignAjax('last_id', end($aEvents)->getId(), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->Viewer_AssignAjax('count_loaded', count($aEvents));
|
2015-01-31 10:30:29 +02:00
|
|
|
|
$this->Viewer_AssignAjax('html', $oViewer->Fetch('component@activity.event-list'));
|
2014-10-08 11:49:34 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Подписка на пользователя по ID
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function EventSubscribe()
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Устанавливаем формат Ajax ответа
|
|
|
|
|
*/
|
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
|
|
|
|
/**
|
|
|
|
|
* Пользователь авторизован?
|
|
|
|
|
*/
|
|
|
|
|
if (!$this->oUserCurrent) {
|
|
|
|
|
return parent::EventNotFound();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Проверяем существование пользователя
|
|
|
|
|
*/
|
|
|
|
|
if (!$this->User_getUserById(getRequestStr('id'))) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error'));
|
|
|
|
|
}
|
|
|
|
|
if ($this->oUserCurrent->getId() == getRequestStr('id')) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('user_list_add.notices.error_self'), $this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Подписываем на пользователя
|
|
|
|
|
*/
|
|
|
|
|
$this->Stream_subscribeUser($this->oUserCurrent->getId(), getRequestStr('id'));
|
|
|
|
|
$this->Message_AddNotice($this->Lang_Get('stream_subscribes_updated'), $this->Lang_Get('attention'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Подписка на пользователя по логину
|
|
|
|
|
*/
|
|
|
|
|
protected function EventAjaxAddUser()
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Устанавливаем формат Ajax ответа
|
|
|
|
|
*/
|
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
2015-01-27 15:51:02 +02:00
|
|
|
|
$aUsers = getRequest('users', null, 'post');
|
2014-10-08 11:49:34 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Валидация
|
|
|
|
|
*/
|
|
|
|
|
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->Stream_subscribeUser($this->oUserCurrent->getId(), $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))),
|
2015-01-27 15:51:02 +02:00
|
|
|
|
'user_id' => $oUser->getId(),
|
|
|
|
|
'user_login' => htmlspecialchars($sUser),
|
2015-01-31 10:30:29 +02:00
|
|
|
|
'html' => $oViewer->Fetch("component@user-list-add.item")
|
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))),
|
2015-01-27 15:51:02 +02:00
|
|
|
|
'user_login' => htmlspecialchars($sUser)
|
2014-10-08 11:49:34 +03:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Передаем во вьевер массив с результатами обработки по каждому пользователю
|
|
|
|
|
*/
|
2015-01-27 15:51:02 +02:00
|
|
|
|
$this->Viewer_AssignAjax('users', $aResult);
|
2014-10-08 11:49:34 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Отписка от пользователя
|
|
|
|
|
*/
|
|
|
|
|
protected function EventAjaxRemoveUser()
|
|
|
|
|
{
|
2015-01-27 15:51:02 +02:00
|
|
|
|
$iUserId = (int) getRequestStr('user_id');
|
2014-10-08 11:49:34 +03:00
|
|
|
|
/**
|
|
|
|
|
* Устанавливаем формат Ajax ответа
|
|
|
|
|
*/
|
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
|
|
|
|
/**
|
|
|
|
|
* Пользователь авторизован?
|
|
|
|
|
*/
|
|
|
|
|
if (!$this->oUserCurrent) {
|
|
|
|
|
return $this->EventErrorDebug();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Пользователь с таким ID существует?
|
|
|
|
|
*/
|
2015-01-27 15:51:02 +02:00
|
|
|
|
if (!$this->User_GetUserById($iUserId)) {
|
2014-10-08 11:49:34 +03:00
|
|
|
|
return $this->EventErrorDebug();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Отписываем
|
|
|
|
|
*/
|
2015-01-27 15:51:02 +02:00
|
|
|
|
$this->Stream_unsubscribeUser($this->oUserCurrent->getId(), $iUserId);
|
|
|
|
|
$this->Message_AddNotice($this->Lang_Get('common.success.remove'), $this->Lang_Get('attention'));
|
2014-10-08 11:49:34 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Выполняется при завершении работы экшена
|
|
|
|
|
*/
|
|
|
|
|
public function EventShutdown()
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Загружаем в шаблон необходимые переменные
|
|
|
|
|
*/
|
|
|
|
|
$this->Viewer_Assign('sMenuItemSelect', $this->sMenuItemSelect);
|
|
|
|
|
}
|
2013-02-04 01:45:44 +02:00
|
|
|
|
}
|