2011-05-23 16:55:40 +03:00
|
|
|
|
<?php
|
2011-08-28 19:52:30 +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-05-23 16:55:40 +03:00
|
|
|
|
|
2011-08-28 19:52:30 +03:00
|
|
|
|
/**
|
|
|
|
|
* Обрабатывает пользовательские ленты контента
|
|
|
|
|
*
|
2012-05-04 13:12:21 +03:00
|
|
|
|
* @package actions
|
|
|
|
|
* @since 1.0
|
2011-08-28 19:52:30 +03:00
|
|
|
|
*/
|
|
|
|
|
class ActionUserfeed extends Action {
|
|
|
|
|
/**
|
|
|
|
|
* Текущий пользователь
|
|
|
|
|
*
|
2012-05-04 13:12:21 +03:00
|
|
|
|
* @var ModuleUser_EntityUser|null
|
2011-08-28 19:52:30 +03:00
|
|
|
|
*/
|
|
|
|
|
protected $oUserCurrent;
|
2011-05-23 16:55:40 +03:00
|
|
|
|
|
2011-08-28 19:52:30 +03:00
|
|
|
|
/**
|
|
|
|
|
* Инициализация
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function Init() {
|
|
|
|
|
/**
|
|
|
|
|
* Доступ только у авторизованных пользователей
|
|
|
|
|
*/
|
|
|
|
|
$this->oUserCurrent = $this->User_getUserCurrent();
|
|
|
|
|
if (!$this->oUserCurrent) {
|
|
|
|
|
parent::EventNotFound();
|
|
|
|
|
}
|
|
|
|
|
$this->SetDefaultEvent('index');
|
2011-05-23 16:55:40 +03:00
|
|
|
|
|
2011-08-28 19:52:30 +03:00
|
|
|
|
$this->Viewer_Assign('sMenuItemSelect', 'feed');
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Регистрация евентов
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function RegisterEvent() {
|
|
|
|
|
$this->AddEvent('index', 'EventIndex');
|
|
|
|
|
$this->AddEvent('subscribe', 'EventSubscribe');
|
2014-02-07 12:26:28 +02:00
|
|
|
|
$this->AddEvent('ajaxadduser', 'EventAjaxAddUser');
|
2011-08-28 19:52:30 +03:00
|
|
|
|
$this->AddEvent('unsubscribe', 'EventUnSubscribe');
|
|
|
|
|
$this->AddEvent('get_more', 'EventGetMore');
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Выводит ленту контента(топики) для пользователя
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function EventIndex() {
|
|
|
|
|
/**
|
|
|
|
|
* Получаем топики
|
|
|
|
|
*/
|
|
|
|
|
$aTopics = $this->Userfeed_read($this->oUserCurrent->getId());
|
2012-06-10 11:33:03 +03:00
|
|
|
|
/**
|
|
|
|
|
* Вызов хуков
|
|
|
|
|
*/
|
|
|
|
|
$this->Hook_Run('topics_list_show',array('aTopics'=>$aTopics));
|
2011-08-28 19:52:30 +03:00
|
|
|
|
$this->Viewer_Assign('aTopics', $aTopics);
|
|
|
|
|
if (count($aTopics)) {
|
|
|
|
|
$this->Viewer_Assign('iUserfeedLastId', end($aTopics)->getId());
|
|
|
|
|
}
|
|
|
|
|
if (count($aTopics) < Config::Get('module.userfeed.count_default')) {
|
|
|
|
|
$this->Viewer_Assign('bDisableGetMoreButton', true);
|
|
|
|
|
} else {
|
|
|
|
|
$this->Viewer_Assign('bDisableGetMoreButton', false);
|
|
|
|
|
}
|
|
|
|
|
$this->SetTemplateAction('list');
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Подгрузка ленты топиков (замена постраничности)
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function EventGetMore() {
|
2012-05-04 13:12:21 +03:00
|
|
|
|
/**
|
|
|
|
|
* Устанавливаем формат Ajax ответа
|
|
|
|
|
*/
|
2011-08-28 19:52:30 +03:00
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
|
|
|
|
/**
|
|
|
|
|
* Проверяем последний просмотренный ID топика
|
|
|
|
|
*/
|
2012-12-12 08:06:38 +02:00
|
|
|
|
$iFromId = getRequestStr('last_id');
|
2011-08-28 19:52:30 +03:00
|
|
|
|
if (!$iFromId) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Получаем топики
|
|
|
|
|
*/
|
|
|
|
|
$aTopics = $this->Userfeed_read($this->oUserCurrent->getId(), null, $iFromId);
|
2012-06-10 11:33:03 +03:00
|
|
|
|
/**
|
|
|
|
|
* Вызов хуков
|
|
|
|
|
*/
|
|
|
|
|
$this->Hook_Run('topics_list_show',array('aTopics'=>$aTopics));
|
2011-08-28 19:52:30 +03:00
|
|
|
|
/**
|
|
|
|
|
* Загружаем данные в ajax ответ
|
|
|
|
|
*/
|
|
|
|
|
$oViewer=$this->Viewer_GetLocalViewer();
|
2011-05-30 17:14:56 +03:00
|
|
|
|
$oViewer->Assign('aTopics', $aTopics);
|
2013-06-20 14:28:58 +03:00
|
|
|
|
$this->Viewer_AssignAjax('result', $oViewer->Fetch('topics/topic_list.tpl'));
|
2011-08-28 19:52:30 +03:00
|
|
|
|
$this->Viewer_AssignAjax('topics_count', count($aTopics));
|
2011-05-30 17:14:56 +03:00
|
|
|
|
|
2011-08-28 19:52:30 +03:00
|
|
|
|
if (count($aTopics)) {
|
|
|
|
|
$this->Viewer_AssignAjax('iUserfeedLastId', end($aTopics)->getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Подписка на контент блога или пользователя
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function EventSubscribe() {
|
2012-05-04 13:12:21 +03:00
|
|
|
|
/**
|
|
|
|
|
* Устанавливаем формат Ajax ответа
|
|
|
|
|
*/
|
2011-08-28 19:52:30 +03:00
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
|
|
|
|
/**
|
|
|
|
|
* Проверяем наличие ID блога или пользователя
|
|
|
|
|
*/
|
|
|
|
|
if (!getRequest('id')) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
|
|
|
|
|
}
|
2012-12-12 08:06:38 +02:00
|
|
|
|
$sType = getRequestStr('type');
|
2011-08-28 19:52:30 +03:00
|
|
|
|
$iType = null;
|
|
|
|
|
/**
|
|
|
|
|
* Определяем тип подписки
|
|
|
|
|
*/
|
|
|
|
|
switch($sType) {
|
|
|
|
|
case 'blogs':
|
|
|
|
|
$iType = ModuleUserfeed::SUBSCRIBE_TYPE_BLOG;
|
2011-08-30 09:12:19 +03:00
|
|
|
|
/**
|
|
|
|
|
* Проверяем существование блога
|
|
|
|
|
*/
|
2012-12-12 08:06:38 +02:00
|
|
|
|
if (!$this->Blog_GetBlogById(getRequestStr('id'))) {
|
2011-08-30 09:12:19 +03:00
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-08-28 19:52:30 +03:00
|
|
|
|
break;
|
|
|
|
|
case 'users':
|
|
|
|
|
$iType = ModuleUserfeed::SUBSCRIBE_TYPE_USER;
|
2011-08-30 09:12:19 +03:00
|
|
|
|
/**
|
|
|
|
|
* Проверяем существование пользователя
|
|
|
|
|
*/
|
2012-12-12 08:06:38 +02:00
|
|
|
|
if (!$this->User_GetUserById(getRequestStr('id'))) {
|
2011-08-30 09:12:19 +03:00
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-12-12 08:06:38 +02:00
|
|
|
|
if ($this->oUserCurrent->getId() == getRequestStr('id')) {
|
2011-08-28 19:52:30 +03:00
|
|
|
|
$this->Message_AddError($this->Lang_Get('userfeed_error_subscribe_to_yourself'),$this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Подписываем
|
|
|
|
|
*/
|
2012-12-12 08:06:38 +02:00
|
|
|
|
$this->Userfeed_subscribeUser($this->oUserCurrent->getId(), $iType, getRequestStr('id'));
|
2011-08-28 19:52:30 +03:00
|
|
|
|
$this->Message_AddNotice($this->Lang_Get('userfeed_subscribes_updated'), $this->Lang_Get('attention'));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Подписка на пользвователя по логину
|
|
|
|
|
*
|
|
|
|
|
*/
|
2014-02-07 12:26:28 +02:00
|
|
|
|
protected function EventAjaxAddUser() {
|
2012-05-04 13:12:21 +03:00
|
|
|
|
/**
|
|
|
|
|
* Устанавливаем формат Ajax ответа
|
|
|
|
|
*/
|
2011-08-28 19:52:30 +03:00
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
2014-02-07 12:26:28 +02:00
|
|
|
|
$sUsers=getRequestStr('sUserList',null,'post');
|
2011-08-28 19:52:30 +03:00
|
|
|
|
/**
|
2014-02-07 12:26:28 +02:00
|
|
|
|
* Если пользователь не авторизирован, возвращаем ошибку
|
2011-08-28 19:52:30 +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-08-28 19:52:30 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-02-07 12:26:28 +02:00
|
|
|
|
$aUsers=explode(',',$sUsers);
|
|
|
|
|
|
|
|
|
|
$aResult=array();
|
2011-08-28 19:52:30 +03:00
|
|
|
|
/**
|
2014-02-07 12:26:28 +02:00
|
|
|
|
* Обрабатываем добавление по каждому из переданных логинов
|
2011-08-28 19:52:30 +03:00
|
|
|
|
*/
|
2014-02-07 12:26:28 +02:00
|
|
|
|
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();
|
|
|
|
|
$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),
|
|
|
|
|
'sUserHtml'=>$oViewer->Fetch("user_list_small_item.tpl")
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$aResult[]=array(
|
|
|
|
|
'bStateError'=>true,
|
|
|
|
|
'sMsgTitle'=>$this->Lang_Get('error'),
|
|
|
|
|
'sMsg'=>$this->Lang_Get('user_not_found',array('login'=>htmlspecialchars($sUser))),
|
|
|
|
|
'sUserLogin'=>htmlspecialchars($sUser)
|
|
|
|
|
);
|
|
|
|
|
}
|
2011-08-28 19:52:30 +03:00
|
|
|
|
}
|
|
|
|
|
/**
|
2014-02-07 12:26:28 +02:00
|
|
|
|
* Передаем во вьевер массив с результатами обработки по каждому пользователю
|
2011-08-28 19:52:30 +03:00
|
|
|
|
*/
|
2014-02-07 12:26:28 +02:00
|
|
|
|
$this->Viewer_AssignAjax('aUsers',$aResult);
|
2011-08-28 19:52:30 +03:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Отписка от блога или пользователя
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function EventUnsubscribe() {
|
2012-05-04 13:12:21 +03:00
|
|
|
|
/**
|
|
|
|
|
* Устанавливаем формат Ajax ответа
|
|
|
|
|
*/
|
2011-08-28 19:52:30 +03:00
|
|
|
|
$this->Viewer_SetResponseAjax('json');
|
2014-02-07 16:11:30 +02:00
|
|
|
|
$sId=getRequestStr('id');
|
|
|
|
|
|
2012-12-12 08:06:38 +02:00
|
|
|
|
$sType = getRequestStr('type');
|
2011-08-28 19:52:30 +03:00
|
|
|
|
$iType = null;
|
|
|
|
|
/**
|
|
|
|
|
* Определяем от чего отписываемся
|
|
|
|
|
*/
|
|
|
|
|
switch($sType) {
|
|
|
|
|
case 'blogs':
|
|
|
|
|
$iType = ModuleUserfeed::SUBSCRIBE_TYPE_BLOG;
|
|
|
|
|
break;
|
|
|
|
|
case 'users':
|
|
|
|
|
$iType = ModuleUserfeed::SUBSCRIBE_TYPE_USER;
|
2014-02-07 16:11:30 +02:00
|
|
|
|
$sId=getRequestStr('iUserId');
|
2011-08-28 19:52:30 +03:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-02-07 16:11:30 +02:00
|
|
|
|
if (!$sId) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-08-28 19:52:30 +03:00
|
|
|
|
/**
|
|
|
|
|
* Отписываем пользователя
|
|
|
|
|
*/
|
2014-02-07 16:11:30 +02:00
|
|
|
|
$this->Userfeed_unsubscribeUser($this->oUserCurrent->getId(), $iType, $sId);
|
2011-08-28 19:52:30 +03:00
|
|
|
|
$this->Message_AddNotice($this->Lang_Get('userfeed_subscribes_updated'), $this->Lang_Get('attention'));
|
|
|
|
|
}
|
2012-06-19 12:17:33 +03:00
|
|
|
|
/**
|
|
|
|
|
* При завершении экшена загружаем в шаблон необходимые переменные
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
}
|