2009-05-10 10:50:39 +03:00
|
|
|
|
<?php
|
2008-09-21 09:36:57 +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
|
|
|
|
|
*
|
|
|
|
|
---------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Обрабатывает профайл юзера, т.е. УРЛ вида /profile/login/
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
class ActionProfile extends Action {
|
|
|
|
|
/**
|
|
|
|
|
* Логин юзера из УРЛа
|
|
|
|
|
*
|
|
|
|
|
* @var unknown_type
|
|
|
|
|
*/
|
|
|
|
|
protected $sUserLogin=null;
|
|
|
|
|
/**
|
|
|
|
|
* Объект юзера чей профиль мы смотрим
|
|
|
|
|
*
|
|
|
|
|
* @var unknown_type
|
|
|
|
|
*/
|
|
|
|
|
protected $oUserProfile;
|
|
|
|
|
|
2009-01-13 23:13:36 +02:00
|
|
|
|
public function Init() {
|
|
|
|
|
$this->Viewer_AddBlocks('right',array('actions/ActionProfile/sidebar.tpl'));
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
|
2009-03-01 13:59:53 +02:00
|
|
|
|
protected function RegisterEvent() {
|
2009-09-03 10:30:50 +03:00
|
|
|
|
$this->AddEvent('friendoffer','EventFriendOffer');
|
|
|
|
|
$this->AddEvent('ajaxfriendadd', 'EventAjaxFriendAdd');
|
2009-09-03 20:07:02 +03:00
|
|
|
|
$this->AddEvent('ajaxfrienddelete', 'EventAjaxFriendDelete');
|
2009-09-05 16:35:44 +03:00
|
|
|
|
$this->AddEvent('ajaxfriendaccept', 'EventAjaxFriendAccept');
|
2009-09-03 10:30:50 +03:00
|
|
|
|
|
2009-03-01 13:59:53 +02:00
|
|
|
|
$this->AddEventPreg('/^[\w\-\_]+$/i','/^(whois)?$/i','EventWhois');
|
2009-08-22 00:01:09 +03:00
|
|
|
|
$this->AddEventPreg('/^[\w\-\_]+$/i','/^favourites$/i','/^comments$/i','/^(page(\d+))?$/i','EventFavouriteComments');
|
2009-03-01 13:59:53 +02:00
|
|
|
|
$this->AddEventPreg('/^[\w\-\_]+$/i','/^favourites$/i','/^(page(\d+))?$/i','EventFavourite');
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**********************************************************************************
|
|
|
|
|
************************ РЕАЛИЗАЦИЯ ЭКШЕНА ***************************************
|
|
|
|
|
**********************************************************************************
|
|
|
|
|
*/
|
|
|
|
|
/**
|
2009-03-01 13:59:53 +02:00
|
|
|
|
* Выводит список избранноего юзера
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*
|
|
|
|
|
*/
|
2009-03-01 13:59:53 +02:00
|
|
|
|
protected function EventFavourite() {
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
|
|
|
|
* Получаем логин из УРЛа
|
|
|
|
|
*/
|
2009-03-01 13:59:53 +02:00
|
|
|
|
$sUserLogin=$this->sCurrentEvent;
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
|
|
|
|
* Проверяем есть ли такой юзер
|
|
|
|
|
*/
|
2009-03-01 13:59:53 +02:00
|
|
|
|
if (!($this->oUserProfile=$this->User_GetUserByLogin($sUserLogin))) {
|
2008-09-21 09:36:57 +03:00
|
|
|
|
return parent::EventNotFound();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Передан ли номер страницы
|
2009-03-01 13:59:53 +02:00
|
|
|
|
*/
|
|
|
|
|
$iPage=$this->GetParamEventMatch(1,2) ? $this->GetParamEventMatch(1,2) : 1;
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
|
|
|
|
* Получаем список избранных топиков
|
2009-06-13 14:32:06 +03:00
|
|
|
|
*/
|
2009-08-20 10:43:06 +03:00
|
|
|
|
$aResult=$this->Topic_GetTopicsFavouriteByUserId($this->oUserProfile->getId(),$iPage,Config::Get('module.topic.per_page'));
|
2008-09-21 09:36:57 +03:00
|
|
|
|
$aTopics=$aResult['collection'];
|
|
|
|
|
/**
|
|
|
|
|
* Формируем постраничность
|
|
|
|
|
*/
|
2009-08-20 10:43:06 +03:00
|
|
|
|
$aPaging=$this->Viewer_MakePaging($aResult['count'],$iPage,Config::Get('module.topic.per_page'),4,Router::GetPath('profile').$this->oUserProfile->getLogin().'/favourites');
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
|
|
|
|
* Загружаем переменные в шаблон
|
|
|
|
|
*/
|
|
|
|
|
$this->Viewer_Assign('aPaging',$aPaging);
|
|
|
|
|
$this->Viewer_Assign('aTopics',$aTopics);
|
2009-04-07 17:59:43 +03:00
|
|
|
|
$this->Viewer_AddHtmlTitle($this->Lang_Get('user_menu_profile').' '.$this->oUserProfile->getLogin());
|
|
|
|
|
$this->Viewer_AddHtmlTitle($this->Lang_Get('user_menu_profile_favourites'));
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
|
|
|
|
* Устанавливаем шаблон вывода
|
|
|
|
|
*/
|
|
|
|
|
$this->SetTemplateAction('favourites');
|
|
|
|
|
}
|
2009-08-22 00:01:09 +03:00
|
|
|
|
/**
|
|
|
|
|
* Выводит список избранноего юзера
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function EventFavouriteComments() {
|
|
|
|
|
/**
|
|
|
|
|
* Получаем логин из УРЛа
|
|
|
|
|
*/
|
|
|
|
|
$sUserLogin=$this->sCurrentEvent;
|
|
|
|
|
/**
|
|
|
|
|
* Проверяем есть ли такой юзер
|
|
|
|
|
*/
|
|
|
|
|
if (!($this->oUserProfile=$this->User_GetUserByLogin($sUserLogin))) {
|
|
|
|
|
return parent::EventNotFound();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Передан ли номер страницы
|
|
|
|
|
*/
|
|
|
|
|
$iPage=$this->GetParamEventMatch(2,2) ? $this->GetParamEventMatch(2,2) : 1;
|
|
|
|
|
/**
|
|
|
|
|
* Получаем список избранных комментариев
|
|
|
|
|
*/
|
|
|
|
|
$aResult=$this->Comment_GetCommentsFavouriteByUserId($this->oUserProfile->getId(),$iPage,Config::Get('module.comment.per_page'));
|
|
|
|
|
$aComments=$aResult['collection'];
|
|
|
|
|
/**
|
|
|
|
|
* Формируем постраничность
|
|
|
|
|
*/
|
|
|
|
|
$aPaging=$this->Viewer_MakePaging($aResult['count'],$iPage,Config::Get('module.comment.per_page'),4,Router::GetPath('profile').$this->oUserProfile->getLogin().'/favourites/comments');
|
|
|
|
|
/**
|
|
|
|
|
* Загружаем переменные в шаблон
|
|
|
|
|
*/
|
|
|
|
|
$this->Viewer_Assign('aPaging',$aPaging);
|
|
|
|
|
$this->Viewer_Assign('aComments',$aComments);
|
|
|
|
|
$this->Viewer_AddHtmlTitle($this->Lang_Get('user_menu_profile').' '.$this->oUserProfile->getLogin());
|
|
|
|
|
$this->Viewer_AddHtmlTitle($this->Lang_Get('user_menu_profile_favourites_comments'));
|
|
|
|
|
/**
|
|
|
|
|
* Устанавливаем шаблон вывода
|
|
|
|
|
*/
|
|
|
|
|
$this->SetTemplateAction('comments');
|
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
|
|
|
|
* Показывает инфу профиля
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-03-01 13:59:53 +02:00
|
|
|
|
protected function EventWhois() {
|
|
|
|
|
/**
|
|
|
|
|
* Получаем логин из УРЛа
|
|
|
|
|
*/
|
|
|
|
|
$sUserLogin=$this->sCurrentEvent;
|
|
|
|
|
/**
|
|
|
|
|
* Проверяем есть ли такой юзер
|
|
|
|
|
*/
|
|
|
|
|
if (!($this->oUserProfile=$this->User_GetUserByLogin($sUserLogin))) {
|
|
|
|
|
return parent::EventNotFound();
|
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
|
|
|
|
* Получаем список друзей
|
|
|
|
|
*/
|
2009-06-13 14:32:06 +03:00
|
|
|
|
$aUsersFriend=$this->User_GetUsersFriend($this->oUserProfile->getId());
|
2008-10-16 07:29:15 +03:00
|
|
|
|
|
2009-08-20 10:43:06 +03:00
|
|
|
|
if (Config::Get('general.reg.invite')) {
|
2008-10-16 07:29:15 +03:00
|
|
|
|
/**
|
|
|
|
|
* Получаем список тех кого пригласил юзер
|
|
|
|
|
*/
|
|
|
|
|
$aUsersInvite=$this->User_GetUsersInvite($this->oUserProfile->getId());
|
|
|
|
|
$this->Viewer_Assign('aUsersInvite',$aUsersInvite);
|
|
|
|
|
/**
|
|
|
|
|
* Получаем того юзера, кто пригласил текущего
|
|
|
|
|
*/
|
|
|
|
|
$oUserInviteFrom=$this->User_GetUserInviteFrom($this->oUserProfile->getId());
|
|
|
|
|
$this->Viewer_Assign('oUserInviteFrom',$oUserInviteFrom);
|
2009-06-13 14:32:06 +03:00
|
|
|
|
}
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
2009-06-13 14:32:06 +03:00
|
|
|
|
* Получаем список юзеров блога
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*/
|
2009-06-13 14:32:06 +03:00
|
|
|
|
$aBlogUsers=$this->Blog_GetBlogUsersByUserId($this->oUserProfile->getId(),0);
|
|
|
|
|
$aBlogModerators=$this->Blog_GetBlogUsersByUserId($this->oUserProfile->getId(),1);
|
|
|
|
|
$aBlogAdministrators=$this->Blog_GetBlogUsersByUserId($this->oUserProfile->getId(),2);
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
|
|
|
|
* Получаем список блогов которые создал юзер
|
|
|
|
|
*/
|
2009-05-09 20:53:25 +03:00
|
|
|
|
$aBlogsOwner=$this->Blog_GetBlogsByOwnerId($this->oUserProfile->getId());
|
|
|
|
|
/**
|
|
|
|
|
* Вызов хуков
|
|
|
|
|
*/
|
|
|
|
|
$this->Hook_Run('profile_whois_show',array("oUserProfile"=>$this->oUserProfile));
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
|
|
|
|
* Загружаем переменные в шаблон
|
|
|
|
|
*/
|
2009-06-13 14:32:06 +03:00
|
|
|
|
$this->Viewer_Assign('aBlogUsers',$aBlogUsers);
|
|
|
|
|
$this->Viewer_Assign('aBlogModerators',$aBlogModerators);
|
|
|
|
|
$this->Viewer_Assign('aBlogAdministrators',$aBlogAdministrators);
|
2008-09-21 09:36:57 +03:00
|
|
|
|
$this->Viewer_Assign('aBlogsOwner',$aBlogsOwner);
|
2009-06-13 14:32:06 +03:00
|
|
|
|
$this->Viewer_Assign('aUsersFriend',$aUsersFriend);
|
2009-04-07 17:59:43 +03:00
|
|
|
|
$this->Viewer_AddHtmlTitle($this->Lang_Get('user_menu_profile').' '.$this->oUserProfile->getLogin());
|
|
|
|
|
$this->Viewer_AddHtmlTitle($this->Lang_Get('user_menu_profile_whois'));
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
|
|
|
|
* Устанавливаем шаблон вывода
|
|
|
|
|
*/
|
|
|
|
|
$this->SetTemplateAction('whois');
|
2009-09-02 23:36:44 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Добавление пользователя в друзья, по отправленной заявке
|
|
|
|
|
*/
|
|
|
|
|
public function EventFriendOffer() {
|
2009-09-04 22:01:21 +03:00
|
|
|
|
require_once Config::Get('path.root.engine').'/lib/external/XXTEA/encrypt.php';
|
2009-09-06 17:09:27 +03:00
|
|
|
|
$sUserId=xxtea_decrypt(base64_decode(urldecode(getRequest('code'))), Config::Get('module.talk.encrypt'));
|
2009-09-05 16:35:44 +03:00
|
|
|
|
list($sUserId,)=explode('_',$sUserId,2);
|
|
|
|
|
|
2009-09-02 23:36:44 +03:00
|
|
|
|
$sAction=$this->GetParam(0);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Получаем текущего пользователя
|
|
|
|
|
*/
|
|
|
|
|
if(!$this->User_IsAuthorization()) {
|
|
|
|
|
return $this->EventNotFound();
|
|
|
|
|
}
|
|
|
|
|
$oUserCurrent = $this->User_GetUserCurrent();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Получаем объект пользователя приславшего заявку,
|
|
|
|
|
* если пользователь не найден, переводим в раздел сообщений (Talk) -
|
|
|
|
|
* так как пользователь мог перейти сюда либо из talk-сообщений,
|
|
|
|
|
* либо из e-mail письма-уведомления
|
|
|
|
|
*/
|
|
|
|
|
if(!$oUser=$this->User_GetUserById($sUserId)) {
|
|
|
|
|
$this->Message_AddError($this->Lang_Get('user_not_found'),$this->Lang_Get('error'),true);
|
2009-09-03 10:30:50 +03:00
|
|
|
|
$this->Message_Shutdown();
|
|
|
|
|
|
2009-09-02 23:36:44 +03:00
|
|
|
|
func_header_location(Router::GetPath('talk'));
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Получаем связь дружбы из базы данных.
|
|
|
|
|
* Если связь не найдена либо статус отличен от OFFER,
|
|
|
|
|
* переходим в раздел Talk и возвращаем сообщение об ошибке
|
|
|
|
|
*/
|
|
|
|
|
$oFriend=$this->User_GetFriend($oUserCurrent->getId(),$oUser->getId(),0);
|
2009-09-05 16:35:44 +03:00
|
|
|
|
if(!$oFriend
|
|
|
|
|
|| !in_array(
|
|
|
|
|
$oFriend->getFriendStatus(),
|
|
|
|
|
array(
|
|
|
|
|
LsUser::USER_FRIEND_OFFER+LsUser::USER_FRIEND_NULL,
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
) {
|
2009-09-04 10:36:38 +03:00
|
|
|
|
$sMessage=($oFriend)
|
|
|
|
|
? $this->Lang_Get('user_friend_offer_already_done')
|
|
|
|
|
: $this->Lang_Get('user_friend_offer_not_found');
|
|
|
|
|
|
|
|
|
|
$this->Message_AddError($sMessage,$this->Lang_Get('error'),true);
|
2009-09-03 10:30:50 +03:00
|
|
|
|
$this->Message_Shutdown();
|
|
|
|
|
|
2009-09-02 23:36:44 +03:00
|
|
|
|
func_header_location(Router::GetPath('talk'));
|
|
|
|
|
return ;
|
2009-09-05 16:35:44 +03:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-02 23:36:44 +03:00
|
|
|
|
/**
|
|
|
|
|
* Устанавливаем новый статус связи
|
|
|
|
|
*/
|
|
|
|
|
$oFriend->setStatusTo(
|
|
|
|
|
($sAction=='accept')
|
|
|
|
|
? LsUser::USER_FRIEND_ACCEPT
|
|
|
|
|
: LsUser::USER_FRIEND_REJECT
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($this->User_UpdateFriend($oFriend)) {
|
2009-09-04 10:36:38 +03:00
|
|
|
|
$sMessage=($sAction=='accept')
|
|
|
|
|
? $this->Lang_Get('user_friend_add_ok')
|
|
|
|
|
: $this->Lang_Get('user_friend_offer_reject');
|
|
|
|
|
|
|
|
|
|
$this->Message_AddNoticeSingle($sMessage,$this->Lang_Get('attention'),true);
|
2009-09-02 23:36:44 +03:00
|
|
|
|
} else {
|
|
|
|
|
$this->Message_AddErrorSingle(
|
|
|
|
|
$this->Lang_Get('system_error'),
|
|
|
|
|
$this->Lang_Get('error'),
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
}
|
2009-09-03 10:30:50 +03:00
|
|
|
|
|
|
|
|
|
$this->Message_Shutdown();
|
2009-09-02 23:36:44 +03:00
|
|
|
|
func_header_location(Router::GetPath('talk'));
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-05 16:35:44 +03:00
|
|
|
|
public function EventAjaxFriendAccept() {
|
|
|
|
|
$this->Viewer_SetResponseAjax();
|
|
|
|
|
$sUserId=getRequest('idUser');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Если пользователь не авторизирован, возвращаем ошибку
|
|
|
|
|
*/
|
|
|
|
|
if (!$this->User_IsAuthorization()) {
|
|
|
|
|
$this->Message_AddErrorSingle(
|
|
|
|
|
$this->Lang_Get('need_authorization'),
|
|
|
|
|
$this->Lang_Get('error')
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$this->oUserCurrent=$this->User_GetUserCurrent();
|
|
|
|
|
/**
|
|
|
|
|
* При попытке добавить в друзья себя, возвращаем ошибку
|
|
|
|
|
*/
|
|
|
|
|
if ($this->oUserCurrent->getId()==$sUserId) {
|
|
|
|
|
$this->Message_AddErrorSingle(
|
|
|
|
|
$this->Lang_Get('user_friend_add_self'),
|
|
|
|
|
$this->Lang_Get('error')
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Если пользователь не найден, возвращаем ошибку
|
|
|
|
|
*/
|
|
|
|
|
if( !$oUser=$this->User_GetUserById($sUserId) ) {
|
|
|
|
|
$this->Message_AddErrorSingle(
|
|
|
|
|
$this->Lang_Get('user_not_found'),
|
|
|
|
|
$this->Lang_Get('error')
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$this->oUserProfile=$oUser;
|
|
|
|
|
/**
|
|
|
|
|
* Получаем статус дружбы между пользователями
|
|
|
|
|
*/
|
|
|
|
|
$oFriend=$this->User_GetFriend($oUser->getId(),$this->oUserCurrent->getId());
|
|
|
|
|
/**
|
|
|
|
|
* При попытке потдвердить ранее отклоненную заявку,
|
|
|
|
|
* проверяем, чтобы изменяющий был принимающей стороной
|
|
|
|
|
*/
|
|
|
|
|
if($oFriend
|
2009-09-06 17:09:27 +03:00
|
|
|
|
&& ($oFriend->getStatusFrom()==LsUser::USER_FRIEND_OFFER||$oFriend->getStatusFrom()==LsUser::USER_FRIEND_ACCEPT)
|
|
|
|
|
&& ($oFriend->getStatusTo()==LsUser::USER_FRIEND_REJECT||$oFriend->getStatusTo()==LsUser::USER_FRIEND_NULL)
|
|
|
|
|
&& $oFriend->getUserTo()==$this->oUserCurrent->getId()) {
|
2009-09-05 16:35:44 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Меняем статус с отвергнутое, на акцептованное
|
|
|
|
|
*/
|
|
|
|
|
$oFriend->setStatusByUserId(LsUser::USER_FRIEND_ACCEPT,$this->oUserCurrent->getId());
|
|
|
|
|
if($this->User_UpdateFriend($oFriend)) {
|
|
|
|
|
$this->Message_AddNoticeSingle($this->Lang_Get('user_friend_add_ok'),$this->Lang_Get('attention'));
|
|
|
|
|
|
|
|
|
|
$oViewerLocal=$this->GetViewerLocal();
|
|
|
|
|
$oViewerLocal->Assign('oUserFriend',$oFriend);
|
|
|
|
|
$this->Viewer_AssingAjax('sToggleText',$oViewerLocal->Fetch("actions/ActionProfile/friend_item.tpl"));
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
$this->Message_AddErrorSingle(
|
|
|
|
|
$this->Lang_Get('system_error'),
|
|
|
|
|
$this->Lang_Get('error')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->Message_AddErrorSingle(
|
|
|
|
|
$this->Lang_Get('system_error'),
|
|
|
|
|
$this->Lang_Get('error')
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-03 10:30:50 +03:00
|
|
|
|
public function EventAjaxFriendAdd() {
|
|
|
|
|
$this->Viewer_SetResponseAjax();
|
|
|
|
|
$sUserId=getRequest('idUser');
|
|
|
|
|
$sUserText=getRequest('userText','');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Если пользователь не авторизирован, возвращаем ошибку
|
|
|
|
|
*/
|
|
|
|
|
if (!$this->User_IsAuthorization()) {
|
|
|
|
|
$this->Message_AddErrorSingle(
|
|
|
|
|
$this->Lang_Get('need_authorization'),
|
|
|
|
|
$this->Lang_Get('error')
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$this->oUserCurrent=$this->User_GetUserCurrent();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* При попытке добавить в друзья себя, возвращаем ошибку
|
|
|
|
|
*/
|
|
|
|
|
if ($this->oUserCurrent->getId()==$sUserId) {
|
|
|
|
|
$this->Message_AddErrorSingle(
|
|
|
|
|
$this->Lang_Get('user_friend_add_self'),
|
|
|
|
|
$this->Lang_Get('error')
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Если пользователь не найден, возвращаем ошибку
|
|
|
|
|
*/
|
|
|
|
|
if( !$oUser=$this->User_GetUserById($sUserId) ) {
|
|
|
|
|
$this->Message_AddErrorSingle(
|
|
|
|
|
$this->Lang_Get('user_not_found'),
|
|
|
|
|
$this->Lang_Get('error')
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-09-04 02:40:56 +03:00
|
|
|
|
$this->oUserProfile=$oUser;
|
2009-09-03 10:30:50 +03:00
|
|
|
|
/**
|
|
|
|
|
* Получаем статус дружбы между пользователями
|
|
|
|
|
*/
|
|
|
|
|
$oFriend=$this->User_GetFriend($oUser->getId(),$this->oUserCurrent->getId());
|
|
|
|
|
/**
|
|
|
|
|
* Если связи ранее не было в базе данных, добавляем новую
|
|
|
|
|
*/
|
|
|
|
|
if( !$oFriend ) {
|
|
|
|
|
$this->SubmitAddFriend($oUser,$sUserText,$oFriend);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Если статус связи соответствует статусам отправленной и акцептованной заявки,
|
|
|
|
|
* то предупреждаем что этот пользователь уже является нашим другом
|
|
|
|
|
*/
|
|
|
|
|
if($oFriend->getFriendStatus()==LsUser::USER_FRIEND_OFFER + LsUser::USER_FRIEND_ACCEPT) {
|
|
|
|
|
$this->Message_AddErrorSingle(
|
|
|
|
|
$this->Lang_Get('user_friend_already_exist'),
|
|
|
|
|
$this->Lang_Get('error')
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Если пользователь ранее отклонил нашу заявку,
|
|
|
|
|
* возвращаем сообщение об ошибке
|
|
|
|
|
*/
|
|
|
|
|
if($oFriend->getUserFrom()==$this->oUserCurrent->getId()
|
|
|
|
|
&& $oFriend->getStatusTo()==LsUser::USER_FRIEND_REJECT ) {
|
|
|
|
|
$this->Message_AddErrorSingle(
|
|
|
|
|
$this->Lang_Get('user_friend_offer_reject'),
|
|
|
|
|
$this->Lang_Get('error')
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-09-04 02:40:56 +03:00
|
|
|
|
/**
|
|
|
|
|
* Если дружба была удалена, то проверяем кто ее удалил
|
|
|
|
|
* и разрешаем восстановить только удалившему
|
|
|
|
|
*/
|
|
|
|
|
if($oFriend->getFriendStatus()>LsUser::USER_FRIEND_DELETE
|
|
|
|
|
&& $oFriend->getFriendStatus()<LsUser::USER_FRIEND_REJECT) {
|
|
|
|
|
/**
|
|
|
|
|
* Определяем статус связи текущего пользователя
|
|
|
|
|
*/
|
|
|
|
|
$iStatusCurrent = $oFriend->getStatusByUserId($this->oUserCurrent->getId());
|
|
|
|
|
|
|
|
|
|
if($iStatusCurrent==LsUser::USER_FRIEND_DELETE) {
|
|
|
|
|
/**
|
|
|
|
|
* Меняем статус с удаленного, на акцептованное
|
|
|
|
|
*/
|
|
|
|
|
$oFriend->setStatusByUserId(LsUser::USER_FRIEND_ACCEPT,$this->oUserCurrent->getId());
|
|
|
|
|
if($this->User_UpdateFriend($oFriend)) {
|
|
|
|
|
$this->Message_AddNoticeSingle($this->Lang_Get('user_friend_add_ok'),$this->Lang_Get('attention'));
|
|
|
|
|
|
|
|
|
|
$oViewerLocal=$this->GetViewerLocal();
|
|
|
|
|
$oViewerLocal->Assign('oUserFriend',$oFriend);
|
|
|
|
|
$this->Viewer_AssingAjax('sToggleText',$oViewerLocal->Fetch("actions/ActionProfile/friend_item.tpl"));
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
$this->Message_AddErrorSingle(
|
|
|
|
|
$this->Lang_Get('system_error'),
|
|
|
|
|
$this->Lang_Get('error')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
$this->Message_AddErrorSingle(
|
|
|
|
|
$this->Lang_Get('user_friend_add_deleted'),
|
|
|
|
|
$this->Lang_Get('error')
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-04 10:36:38 +03:00
|
|
|
|
/**
|
|
|
|
|
* Функция создает локальный объект вьювера для рендеринга html-объектов в ajax запросах
|
|
|
|
|
*
|
|
|
|
|
* @return LsViewer
|
|
|
|
|
*/
|
2009-09-04 02:40:56 +03:00
|
|
|
|
protected function GetViewerLocal() {
|
|
|
|
|
/**
|
|
|
|
|
* Получаем HTML код inject-объекта
|
|
|
|
|
*/
|
|
|
|
|
if (!class_exists('LsViewer')) {
|
|
|
|
|
require_once(Config::Get('path.root.engine')."/modules/viewer/Viewer.class.php");
|
|
|
|
|
}
|
|
|
|
|
$oViewerLocal=new LsViewer(Engine::getInstance());
|
|
|
|
|
$oViewerLocal->Init();
|
|
|
|
|
$oViewerLocal->VarAssign();
|
|
|
|
|
$oViewerLocal->Assign('aLang',$this->Lang_GetLangMsg());
|
|
|
|
|
$oViewerLocal->Assign('oUserCurrent',$this->oUserCurrent);
|
|
|
|
|
$oViewerLocal->Assign('oUserProfile',$this->oUserProfile);
|
|
|
|
|
|
|
|
|
|
$oViewerLocal->Assign('USER_FRIEND_NULL',LsUser::USER_FRIEND_NULL);
|
|
|
|
|
$oViewerLocal->Assign('USER_FRIEND_OFFER',LsUser::USER_FRIEND_OFFER);
|
|
|
|
|
$oViewerLocal->Assign('USER_FRIEND_ACCEPT',LsUser::USER_FRIEND_ACCEPT);
|
|
|
|
|
$oViewerLocal->Assign('USER_FRIEND_REJECT',LsUser::USER_FRIEND_REJECT);
|
|
|
|
|
$oViewerLocal->Assign('USER_FRIEND_DELETE',LsUser::USER_FRIEND_DELETE);
|
|
|
|
|
|
|
|
|
|
return $oViewerLocal;
|
2009-09-03 10:30:50 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function SubmitAddFriend($oUser,$sUserText,$oFriend=null) {
|
2009-09-08 15:02:51 +03:00
|
|
|
|
$oFriendNew=Engine::GetEntity('User_Friend');
|
2009-09-03 10:30:50 +03:00
|
|
|
|
$oFriendNew->setUserTo($oUser->getId());
|
|
|
|
|
$oFriendNew->setUserFrom($this->oUserCurrent->getId());
|
|
|
|
|
// Добавляем заявку в друзья
|
|
|
|
|
$oFriendNew->setStatusFrom(LsUser::USER_FRIEND_OFFER);
|
|
|
|
|
$oFriendNew->setStatusTo(LsUser::USER_FRIEND_NULL);
|
|
|
|
|
|
|
|
|
|
$bStateError=($oFriend)
|
|
|
|
|
? !$this->User_UpdateFriend($oFriendNew)
|
|
|
|
|
: !$this->User_AddFriend($oFriendNew);
|
|
|
|
|
|
|
|
|
|
if ( !$bStateError ) {
|
|
|
|
|
$this->Message_AddNoticeSingle($this->Lang_Get('user_friend_offer_send'),$this->Lang_Get('attention'));
|
|
|
|
|
|
|
|
|
|
$sTitle=$this->Lang_Get(
|
|
|
|
|
'user_friend_offer_title',
|
|
|
|
|
array(
|
|
|
|
|
'login'=>$this->oUserCurrent->getLogin(),
|
|
|
|
|
'friend'=>$oUser->getLogin()
|
|
|
|
|
)
|
|
|
|
|
);
|
2009-09-04 22:01:21 +03:00
|
|
|
|
|
|
|
|
|
require_once Config::Get('path.root.engine').'/lib/external/XXTEA/encrypt.php';
|
2009-09-05 16:35:44 +03:00
|
|
|
|
$sCode=$this->oUserCurrent->getId().'_'.$oUser->getId();
|
|
|
|
|
$sCode=urlencode(base64_encode(xxtea_encrypt($sCode, Config::Get('module.talk.encrypt'))));
|
2009-09-04 22:01:21 +03:00
|
|
|
|
|
2009-09-06 17:09:27 +03:00
|
|
|
|
$aPath=array(
|
|
|
|
|
'accept'=>Router::GetPath('profile').'friendoffer/accept/?code='.$sCode,
|
|
|
|
|
'reject'=>Router::GetPath('profile').'friendoffer/reject/?code='.$sCode
|
|
|
|
|
);
|
|
|
|
|
|
2009-09-03 10:30:50 +03:00
|
|
|
|
$sText=$this->Lang_Get(
|
|
|
|
|
'user_friend_offer_text',
|
|
|
|
|
array(
|
|
|
|
|
'login'=>$this->oUserCurrent->getLogin(),
|
2009-09-06 17:09:27 +03:00
|
|
|
|
'accept_path'=>$aPath['accept'],
|
|
|
|
|
'reject_path'=>$aPath['reject'],
|
2009-09-03 10:30:50 +03:00
|
|
|
|
'user_text'=>$sUserText
|
|
|
|
|
)
|
|
|
|
|
);
|
2009-09-04 17:57:34 +03:00
|
|
|
|
$oTalk=$this->Talk_SendTalk($sTitle,$sText,$this->oUserCurrent,array($oUser),false,false);
|
2009-09-06 17:09:27 +03:00
|
|
|
|
/**
|
|
|
|
|
* Отправляем пользователю заявку
|
|
|
|
|
*/
|
|
|
|
|
$this->Notify_SendUserFriendNew(
|
|
|
|
|
$oUser,$this->oUserCurrent,$sUserText,
|
|
|
|
|
Router::GetPath('talk').'read/'.$oTalk->getId().'/'
|
2009-09-09 20:39:26 +03:00
|
|
|
|
);
|
2009-09-04 17:57:34 +03:00
|
|
|
|
/**
|
|
|
|
|
* Удаляем отправляющего юзера из переписки
|
|
|
|
|
*/
|
|
|
|
|
$this->Talk_DeleteTalkUserByArray($oTalk->getId(),$this->oUserCurrent->getId());
|
2009-09-03 10:30:50 +03:00
|
|
|
|
} else {
|
|
|
|
|
$this->Message_AddErrorSingle($this->Lang_Get('system_error'),$this->Lang_Get('error'));
|
2009-09-04 02:40:56 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$oViewerLocal=$this->GetViewerLocal();
|
|
|
|
|
$oViewerLocal->Assign('oUserFriend',$oFriendNew);
|
|
|
|
|
$this->Viewer_AssingAjax('sToggleText',$oViewerLocal->Fetch("actions/ActionProfile/friend_item.tpl"));
|
2009-09-03 10:30:50 +03:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-03 20:07:02 +03:00
|
|
|
|
/**
|
|
|
|
|
* Удаление пользователя из друзей
|
|
|
|
|
*/
|
|
|
|
|
public function EventAjaxFriendDelete() {
|
|
|
|
|
$this->Viewer_SetResponseAjax();
|
|
|
|
|
$sUserId=getRequest('idUser');
|
|
|
|
|
/**
|
|
|
|
|
* Если пользователь не авторизирован, возвращаем ошибку
|
|
|
|
|
*/
|
|
|
|
|
if (!$this->User_IsAuthorization()) {
|
|
|
|
|
$this->Message_AddErrorSingle(
|
|
|
|
|
$this->Lang_Get('need_authorization'),
|
|
|
|
|
$this->Lang_Get('error')
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$this->oUserCurrent=$this->User_GetUserCurrent();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* При попытке добавить в друзья себя, возвращаем ошибку
|
|
|
|
|
*/
|
|
|
|
|
if ($this->oUserCurrent->getId()==$sUserId) {
|
|
|
|
|
$this->Message_AddErrorSingle(
|
|
|
|
|
$this->Lang_Get('user_friend_add_self'),
|
|
|
|
|
$this->Lang_Get('error')
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Если пользователь не найден, возвращаем ошибку
|
|
|
|
|
*/
|
|
|
|
|
if( !$oUser=$this->User_GetUserById($sUserId) ) {
|
|
|
|
|
$this->Message_AddErrorSingle(
|
|
|
|
|
$this->Lang_Get('user_friend_del_no'),
|
|
|
|
|
$this->Lang_Get('error')
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-09-04 02:40:56 +03:00
|
|
|
|
$this->oUserProfile=$oUser;
|
2009-09-03 20:07:02 +03:00
|
|
|
|
/**
|
|
|
|
|
* Получаем статус дружбы между пользователями.
|
|
|
|
|
* Если статус не определен, или отличается от принятой заявки,
|
|
|
|
|
* возвращаем ошибку
|
|
|
|
|
*/
|
|
|
|
|
if( !($oFriend=$this->User_GetFriend($oUser->getId(),$this->oUserCurrent->getId()))
|
|
|
|
|
|| $oFriend->getFriendStatus()!=LsUser::USER_FRIEND_ACCEPT+LsUser::USER_FRIEND_OFFER ) {
|
|
|
|
|
$this->Message_AddErrorSingle(
|
|
|
|
|
$this->Lang_Get('user_friend_del_no'),
|
|
|
|
|
$this->Lang_Get('error')
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( $this->User_DeleteFriend($oFriend) ) {
|
|
|
|
|
$this->Message_AddNoticeSingle($this->Lang_Get('user_friend_del_ok'),$this->Lang_Get('attention'));
|
2009-09-04 02:40:56 +03:00
|
|
|
|
|
|
|
|
|
$oViewerLocal=$this->GetViewerLocal();
|
|
|
|
|
$oViewerLocal->Assign('oUserFriend',$oFriend);
|
|
|
|
|
$this->Viewer_AssingAjax('sToggleText',$oViewerLocal->Fetch("actions/ActionProfile/friend_item.tpl"));
|
|
|
|
|
return;
|
2009-09-03 20:07:02 +03:00
|
|
|
|
} else {
|
|
|
|
|
$this->Message_AddErrorSingle($this->Lang_Get('system_error'),$this->Lang_Get('error'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-21 09:36:57 +03:00
|
|
|
|
/**
|
2009-03-01 13:59:53 +02:00
|
|
|
|
* Выполняется при завершении работы экшена
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*/
|
2009-03-01 13:59:53 +02:00
|
|
|
|
public function EventShutdown() {
|
|
|
|
|
if (!$this->oUserProfile) {
|
|
|
|
|
return ;
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
/**
|
2009-03-01 13:59:53 +02:00
|
|
|
|
* Загружаем в шаблон необходимые переменные
|
2008-09-21 09:36:57 +03:00
|
|
|
|
*/
|
2009-03-01 13:59:53 +02:00
|
|
|
|
$iCountTopicFavourite=$this->Topic_GetCountTopicsFavouriteByUserId($this->oUserProfile->getId());
|
|
|
|
|
$iCountTopicUser=$this->Topic_GetCountTopicsPersonalByUser($this->oUserProfile->getId(),1);
|
2009-06-23 20:06:19 +03:00
|
|
|
|
$iCountCommentUser=$this->Comment_GetCountCommentsByUserId($this->oUserProfile->getId(),'topic');
|
2009-08-22 00:01:09 +03:00
|
|
|
|
$iCountCommentFavourite=$this->Comment_GetCountCommentsFavouriteByUserId($this->oUserProfile->getId());
|
2009-09-02 23:36:44 +03:00
|
|
|
|
|
2009-03-01 13:59:53 +02:00
|
|
|
|
$this->Viewer_Assign('oUserProfile',$this->oUserProfile);
|
|
|
|
|
$this->Viewer_Assign('iCountTopicUser',$iCountTopicUser);
|
|
|
|
|
$this->Viewer_Assign('iCountCommentUser',$iCountCommentUser);
|
|
|
|
|
$this->Viewer_Assign('iCountTopicFavourite',$iCountTopicFavourite);
|
2009-08-22 00:01:09 +03:00
|
|
|
|
$this->Viewer_Assign('iCountCommentFavourite',$iCountCommentFavourite);
|
2009-09-02 23:36:44 +03:00
|
|
|
|
$this->Viewer_Assign('USER_FRIEND_NULL',LsUser::USER_FRIEND_NULL);
|
|
|
|
|
$this->Viewer_Assign('USER_FRIEND_OFFER',LsUser::USER_FRIEND_OFFER);
|
|
|
|
|
$this->Viewer_Assign('USER_FRIEND_ACCEPT',LsUser::USER_FRIEND_ACCEPT);
|
|
|
|
|
$this->Viewer_Assign('USER_FRIEND_REJECT',LsUser::USER_FRIEND_REJECT);
|
|
|
|
|
$this->Viewer_Assign('USER_FRIEND_DELETE',LsUser::USER_FRIEND_DELETE);
|
2008-09-21 09:36:57 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
?>
|