2011-06-06 14:58:19 +03:00
|
|
|
|
<?php
|
2011-07-31 19:52:50 +03:00
|
|
|
|
/*-------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* LiveStreet Engine Social Networking
|
|
|
|
|
* Copyright © 2008 Mzhelskiy Maxim
|
|
|
|
|
*
|
|
|
|
|
*--------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* Official site: www.livestreet.ru
|
|
|
|
|
* Contact e-mail: rus.engine@gmail.com
|
|
|
|
|
*
|
|
|
|
|
* GNU General Public License, version 2:
|
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
|
*
|
|
|
|
|
---------------------------------------------------------
|
|
|
|
|
*/
|
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
|
|
|
|
*
|
2012-05-04 13:12:21 +03:00
|
|
|
|
* @package actions
|
|
|
|
|
* @since 1.0
|
2011-08-28 21:49:01 +03:00
|
|
|
|
*/
|
|
|
|
|
class ActionStream extends Action {
|
|
|
|
|
/**
|
|
|
|
|
* Текущий пользователь
|
|
|
|
|
*
|
2012-05-04 13:12:21 +03:00
|
|
|
|
* @var ModuleUser_EntityUser|null
|
2011-08-28 21:49:01 +03:00
|
|
|
|
*/
|
2011-07-22 18:07:41 +03:00
|
|
|
|
protected $oUserCurrent;
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
2012-04-14 10:32:27 +03:00
|
|
|
|
/**
|
|
|
|
|
* Какое меню активно
|
|
|
|
|
*
|
2012-05-04 13:12:21 +03:00
|
|
|
|
* @var string
|
2012-04-14 10:32:27 +03:00
|
|
|
|
*/
|
|
|
|
|
protected $sMenuItemSelect='user';
|
2011-06-06 14:58:19 +03:00
|
|
|
|
|
2011-08-28 21:49:01 +03:00
|
|
|
|
/**
|
|
|
|
|
* Инициализация
|
|
|
|
|
*/
|
|
|
|
|
public function Init() {
|
2011-07-22 18:07:41 +03:00
|
|
|
|
$this->oUserCurrent = $this->User_getUserCurrent();
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
|
|
|
|
// Личная лента доступна только для авторизованных, гостям показываем общую ленту
|
2012-04-14 10:32:27 +03:00
|
|
|
|
if ($this->oUserCurrent) {
|
2014-07-18 18:45:16 +03:00
|
|
|
|
$this->SetDefaultEvent('personal');
|
2012-04-14 10:32:27 +03:00
|
|
|
|
} else {
|
|
|
|
|
$this->SetDefaultEvent('all');
|
2011-07-22 18:07:41 +03:00
|
|
|
|
}
|
2011-06-06 14:58:19 +03:00
|
|
|
|
|
2012-04-14 10:32:27 +03:00
|
|
|
|
$this->Viewer_Assign('sMenuHeadItemSelect', 'stream');
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
2011-07-31 19:52:50 +03:00
|
|
|
|
/**
|
|
|
|
|
* Загружаем в шаблон JS текстовки
|
|
|
|
|
*/
|
|
|
|
|
$this->Lang_AddLangJs(array(
|
2014-07-18 18:45:16 +03:00
|
|
|
|
'activity.notices.error_already_subscribed', 'error'
|
|
|
|
|
));
|
2011-07-22 18:07:41 +03:00
|
|
|
|
}
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
2011-08-28 21:49:01 +03:00
|
|
|
|
/**
|
|
|
|
|
* Регистрация евентов
|
|
|
|
|
*/
|
|
|
|
|
protected function RegisterEvent() {
|
2014-07-18 18:45:16 +03:00
|
|
|
|
$this->AddEvent('personal', 'EventPersonal');
|
2012-04-14 10:32:27 +03:00
|
|
|
|
$this->AddEvent('all', 'EventAll');
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
2014-02-07 12:26:28 +02:00
|
|
|
|
$this->AddEvent('subscribe', 'EventSubscribe'); // TODO: возможно нужно удалить
|
|
|
|
|
$this->AddEvent('ajaxadduser', 'EventAjaxAddUser');
|
|
|
|
|
$this->AddEvent('ajaxremoveuser', 'EventAjaxRemoveUser');
|
2011-07-22 18:07:41 +03:00
|
|
|
|
$this->AddEvent('switchEventType', 'EventSwitchEventType');
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
2012-04-14 10:32:27 +03:00
|
|
|
|
$this->AddEvent('get_more_all', 'EventGetMoreAll');
|
2014-07-18 18:45:16 +03:00
|
|
|
|
$this->AddEvent('get_more_personal', 'EventGetMore');
|
|
|
|
|
$this->AddEvent('get_more_user', 'EventGetMoreUser');
|
2011-07-22 18:07:41 +03:00
|
|
|
|
}
|
2011-06-06 14:58:19 +03:00
|
|
|
|
|
2011-08-28 21:49:01 +03:00
|
|
|
|
/**
|
2014-07-18 18:45:16 +03:00
|
|
|
|
* Персональная активность
|
2011-08-28 21:49:01 +03:00
|
|
|
|
*/
|
2014-07-18 18:45:16 +03:00
|
|
|
|
protected function EventPersonal() {
|
|
|
|
|
if ( ! $this->oUserCurrent ) {
|
2013-02-04 01:45:44 +02:00
|
|
|
|
return parent::EventNotFound();
|
2012-04-14 10:32:27 +03:00
|
|
|
|
}
|
2014-03-04 10:32:38 +02:00
|
|
|
|
|
2014-07-18 18:45:16 +03:00
|
|
|
|
$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()) );
|
2011-07-22 18:07:41 +03:00
|
|
|
|
}
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
2012-04-14 10:32:27 +03:00
|
|
|
|
/**
|
2014-07-18 18:45:16 +03:00
|
|
|
|
* Общая активность
|
2012-04-14 10:32:27 +03:00
|
|
|
|
*/
|
|
|
|
|
protected function EventAll() {
|
2014-07-18 18:45:16 +03:00
|
|
|
|
$this->sMenuItemSelect = 'all';
|
|
|
|
|
|
|
|
|
|
$this->Viewer_Assign('activityEvents', $this->Stream_ReadAll());
|
|
|
|
|
$this->Viewer_Assign('activityEventsAllCount', $this->Stream_GetCountAll());
|
2012-04-14 10:32:27 +03:00
|
|
|
|
}
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
2011-08-28 21:49:01 +03:00
|
|
|
|
/**
|
|
|
|
|
* Активаци/деактивация типа события
|
|
|
|
|
*/
|
|
|
|
|
protected function EventSwitchEventType() {
|
2012-05-04 13:12:21 +03:00
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
|
|
|
|
if ( ! $this->oUserCurrent ) {
|
2013-02-04 01:45:44 +02:00
|
|
|
|
return parent::EventNotFound();
|
2012-04-14 10:32:27 +03:00
|
|
|
|
}
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
|
|
|
|
if ( ! getRequest('type') ) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error'));
|
2011-07-22 18:07:41 +03:00
|
|
|
|
}
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
2012-05-04 13:12:21 +03:00
|
|
|
|
/**
|
|
|
|
|
* Активируем/деактивируем тип
|
|
|
|
|
*/
|
2012-12-12 08:06:38 +02:00
|
|
|
|
$this->Stream_switchUserEventType($this->oUserCurrent->getId(), getRequestStr('type'));
|
2014-07-18 18:45:16 +03:00
|
|
|
|
$this->Message_AddNotice($this->Lang_Get('common.success.save'), $this->Lang_Get('attention'));
|
2011-07-22 18:07:41 +03:00
|
|
|
|
}
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
2011-08-28 21:49:01 +03:00
|
|
|
|
/**
|
2014-07-18 18:45:16 +03:00
|
|
|
|
* Подгрузка событий (замена постраничности)
|
2011-08-28 21:49:01 +03:00
|
|
|
|
*/
|
|
|
|
|
protected function EventGetMore() {
|
2014-07-18 18:45:16 +03:00
|
|
|
|
if ( ! $this->oUserCurrent ) {
|
2013-02-04 01:45:44 +02:00
|
|
|
|
return parent::EventNotFound();
|
2012-04-14 10:32:27 +03:00
|
|
|
|
}
|
2014-03-04 10:32:38 +02:00
|
|
|
|
|
2014-07-18 18:45:16 +03:00
|
|
|
|
$this->GetMore(function($lastId) {
|
|
|
|
|
return $this->Stream_Read(null, $lastId);
|
|
|
|
|
});
|
2011-07-22 18:07:41 +03:00
|
|
|
|
}
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
2012-04-14 10:32:27 +03:00
|
|
|
|
/**
|
2014-07-18 18:45:16 +03:00
|
|
|
|
* Подгрузка событий для всего сайта
|
2012-04-14 10:32:27 +03:00
|
|
|
|
*/
|
|
|
|
|
protected function EventGetMoreAll() {
|
2014-07-18 18:45:16 +03:00
|
|
|
|
$this->GetMore(function($lastId) {
|
|
|
|
|
return $this->Stream_ReadAll(null, $lastId);
|
|
|
|
|
});
|
|
|
|
|
}
|
2012-04-14 10:32:27 +03:00
|
|
|
|
|
2014-07-18 18:45:16 +03:00
|
|
|
|
/**
|
|
|
|
|
* Подгрузка событий для пользователя
|
|
|
|
|
*/
|
|
|
|
|
protected function EventGetMoreUser() {
|
|
|
|
|
$this->GetMore(function($lastId) {
|
|
|
|
|
if ( ! ( $oUser = $this->User_GetUserById(getRequestStr('target_id')) ) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-03-04 10:32:38 +02:00
|
|
|
|
|
2014-07-18 18:45:16 +03:00
|
|
|
|
return $this->Stream_ReadByUserId($oUser->getId(), null, $lastId);
|
|
|
|
|
});
|
2012-04-14 10:32:27 +03:00
|
|
|
|
}
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
2012-03-19 23:10:06 +02:00
|
|
|
|
/**
|
2014-07-18 18:45:16 +03:00
|
|
|
|
* Общий метод подгрузки событий
|
2012-03-19 23:10:06 +02:00
|
|
|
|
*
|
2014-07-18 18:45:16 +03:00
|
|
|
|
* @param callback $getEvents Метод возвращающий список событий
|
2012-03-19 23:10:06 +02:00
|
|
|
|
*/
|
2014-07-18 18:45:16 +03:00
|
|
|
|
protected function GetMore( $getEvents ) {
|
2012-03-19 23:10:06 +02:00
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
|
|
|
|
// Необходимо передать последний просмотренный ID событий
|
|
|
|
|
$iLastId = getRequestStr('last_id');
|
|
|
|
|
|
|
|
|
|
if ( ! $iLastId ) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'), $this->Lang_Get('error'));
|
2012-03-19 23:10:06 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
|
|
|
|
// Получаем события
|
|
|
|
|
$aEvents = $getEvents( $iLastId );
|
|
|
|
|
|
|
|
|
|
if ( $aEvents === false ) {
|
|
|
|
|
return $this->EventErrorDebug();
|
2012-03-19 23:10:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-18 18:45:16 +03:00
|
|
|
|
$oViewer = $this->Viewer_GetLocalViewer();
|
|
|
|
|
|
|
|
|
|
$oViewer->Assign('events', $aEvents, true);
|
|
|
|
|
$oViewer->Assign('dateLast', getRequestStr('date_last'), true);
|
2014-03-04 10:32:38 +02:00
|
|
|
|
|
2014-07-18 18:45:16 +03:00
|
|
|
|
if ( count($aEvents) ) {
|
|
|
|
|
$this->Viewer_AssignAjax('last_id', end($aEvents)->getId(), true);
|
2012-03-19 23:10:06 +02:00
|
|
|
|
}
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
|
|
|
|
$this->Viewer_AssignAjax('count_loaded', count($aEvents));
|
|
|
|
|
$this->Viewer_AssignAjax('html', $oViewer->Fetch('components/activity/event-list.tpl'));
|
2012-03-19 23:10:06 +02:00
|
|
|
|
}
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
2011-08-28 21:49:01 +03:00
|
|
|
|
/**
|
|
|
|
|
* Подписка на пользователя по ID
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function EventSubscribe() {
|
2012-05-04 13:12:21 +03:00
|
|
|
|
/**
|
|
|
|
|
* Устанавливаем формат Ajax ответа
|
|
|
|
|
*/
|
2011-07-22 18:07:41 +03:00
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
2012-05-04 13:12:21 +03:00
|
|
|
|
/**
|
|
|
|
|
* Пользователь авторизован?
|
|
|
|
|
*/
|
2012-04-14 10:32:27 +03:00
|
|
|
|
if (!$this->oUserCurrent) {
|
2013-02-04 01:45:44 +02:00
|
|
|
|
return parent::EventNotFound();
|
2012-04-14 10:32:27 +03:00
|
|
|
|
}
|
2011-08-28 21:49:01 +03:00
|
|
|
|
/**
|
|
|
|
|
* Проверяем существование пользователя
|
|
|
|
|
*/
|
2012-12-12 08:06:38 +02:00
|
|
|
|
if (!$this->User_getUserById(getRequestStr('id'))) {
|
2011-07-22 18:07:41 +03:00
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
|
|
|
|
|
}
|
2012-12-12 08:06:38 +02:00
|
|
|
|
if ($this->oUserCurrent->getId() == getRequestStr('id')) {
|
2014-04-08 14:44:28 +03:00
|
|
|
|
$this->Message_AddError($this->Lang_Get('user_list_add.notices.error_self'),$this->Lang_Get('error'));
|
2011-07-22 18:07:41 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
2011-08-28 21:49:01 +03:00
|
|
|
|
/**
|
|
|
|
|
* Подписываем на пользователя
|
|
|
|
|
*/
|
2012-12-12 08:06:38 +02:00
|
|
|
|
$this->Stream_subscribeUser($this->oUserCurrent->getId(), getRequestStr('id'));
|
2011-07-22 18:07:41 +03:00
|
|
|
|
$this->Message_AddNotice($this->Lang_Get('stream_subscribes_updated'), $this->Lang_Get('attention'));
|
|
|
|
|
}
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
2011-08-28 21:49:01 +03:00
|
|
|
|
/**
|
|
|
|
|
* Подписка на пользователя по логину
|
|
|
|
|
*/
|
2014-02-07 12:26:28 +02:00
|
|
|
|
protected function EventAjaxAddUser() {
|
2012-05-04 13:12:21 +03:00
|
|
|
|
/**
|
|
|
|
|
* Устанавливаем формат Ajax ответа
|
|
|
|
|
*/
|
2011-07-22 18:07:41 +03:00
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
2014-04-03 10:36:30 +03:00
|
|
|
|
$aUsers=getRequest('aUserList',null,'post');
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
2014-04-03 10:36:30 +03:00
|
|
|
|
/**
|
|
|
|
|
* Валидация
|
|
|
|
|
*/
|
|
|
|
|
if ( ! is_array($aUsers) ) {
|
|
|
|
|
return $this->EventErrorDebug();
|
|
|
|
|
}
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
2012-05-04 13:12:21 +03:00
|
|
|
|
/**
|
2014-02-07 12:26:28 +02:00
|
|
|
|
* Если пользователь не авторизирован, возвращаем ошибку
|
2011-08-28 21:49:01 +03:00
|
|
|
|
*/
|
2014-02-07 12:26:28 +02:00
|
|
|
|
if (!$this->User_IsAuthorization()) {
|
|
|
|
|
$this->Message_AddErrorSingle($this->Lang_Get('need_authorization'),$this->Lang_Get('error'));
|
2011-07-22 18:07:41 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-02-07 12:26:28 +02:00
|
|
|
|
|
|
|
|
|
$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();
|
|
|
|
|
$oViewer->Assign('oUser', $oUser);
|
|
|
|
|
$oViewer->Assign('bUserListSmallShowActions', true);
|
|
|
|
|
|
|
|
|
|
$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-04-28 13:32:22 +03:00
|
|
|
|
'sHtml'=>$oViewer->Fetch("components/user_list_small/user_list_small_item.tpl")
|
2014-02-07 12:26:28 +02:00
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$aResult[]=array(
|
|
|
|
|
'bStateError'=>true,
|
|
|
|
|
'sMsgTitle'=>$this->Lang_Get('error'),
|
2014-08-05 17:28:36 +03:00
|
|
|
|
'sMsg'=>$this->Lang_Get('user.notices.not_found',array('login'=>htmlspecialchars($sUser))),
|
2014-02-07 12:26:28 +02:00
|
|
|
|
'sUserLogin'=>htmlspecialchars($sUser)
|
|
|
|
|
);
|
|
|
|
|
}
|
2011-07-22 18:07:41 +03:00
|
|
|
|
}
|
2011-08-28 21:49:01 +03:00
|
|
|
|
/**
|
2014-02-07 12:26:28 +02:00
|
|
|
|
* Передаем во вьевер массив с результатами обработки по каждому пользователю
|
2011-08-28 21:49:01 +03:00
|
|
|
|
*/
|
2014-04-03 10:36:30 +03:00
|
|
|
|
$this->Viewer_AssignAjax('aUserList',$aResult);
|
2011-07-22 18:07:41 +03:00
|
|
|
|
}
|
2011-08-28 21:49:01 +03:00
|
|
|
|
/**
|
|
|
|
|
* Отписка от пользователя
|
|
|
|
|
*/
|
2014-02-07 12:26:28 +02:00
|
|
|
|
protected function EventAjaxRemoveUser() {
|
2012-05-04 13:12:21 +03:00
|
|
|
|
/**
|
|
|
|
|
* Устанавливаем формат Ajax ответа
|
|
|
|
|
*/
|
2011-07-22 18:07:41 +03:00
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
2012-05-04 13:12:21 +03:00
|
|
|
|
/**
|
|
|
|
|
* Пользователь авторизован?
|
|
|
|
|
*/
|
2012-04-14 10:32:27 +03:00
|
|
|
|
if (!$this->oUserCurrent) {
|
2014-02-07 12:26:28 +02:00
|
|
|
|
return $this->EventErrorDebug();
|
2012-04-14 10:32:27 +03:00
|
|
|
|
}
|
2012-05-04 13:12:21 +03:00
|
|
|
|
/**
|
|
|
|
|
* Пользователь с таким ID существует?
|
|
|
|
|
*/
|
2014-02-07 12:26:28 +02:00
|
|
|
|
if (!$this->User_GetUserById(getRequestStr('iUserId'))) {
|
|
|
|
|
return $this->EventErrorDebug();
|
2011-07-22 18:07:41 +03:00
|
|
|
|
}
|
2011-08-28 21:49:01 +03:00
|
|
|
|
/**
|
|
|
|
|
* Отписываем
|
|
|
|
|
*/
|
2014-02-07 12:46:33 +02:00
|
|
|
|
$this->Stream_unsubscribeUser($this->oUserCurrent->getId(), getRequestStr('iUserId'));
|
2011-07-22 18:07:41 +03:00
|
|
|
|
$this->Message_AddNotice($this->Lang_Get('stream_subscribes_updated'), $this->Lang_Get('attention'));
|
|
|
|
|
}
|
2014-07-18 18:45:16 +03:00
|
|
|
|
|
2012-04-14 10:32:27 +03:00
|
|
|
|
/**
|
|
|
|
|
* Выполняется при завершении работы экшена
|
|
|
|
|
*/
|
|
|
|
|
public function EventShutdown() {
|
|
|
|
|
/**
|
|
|
|
|
* Загружаем в шаблон необходимые переменные
|
|
|
|
|
*/
|
|
|
|
|
$this->Viewer_Assign('sMenuItemSelect',$this->sMenuItemSelect);
|
|
|
|
|
}
|
2013-02-04 01:45:44 +02:00
|
|
|
|
}
|