1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-01 05:55:02 +03:00
This commit is contained in:
Alexey Kachayev 2009-09-05 13:35:44 +00:00
parent 160411be31
commit 94adc3b438
4 changed files with 106 additions and 11 deletions

View file

@ -41,6 +41,7 @@ class ActionProfile extends Action {
$this->AddEvent('friendoffer','EventFriendOffer');
$this->AddEvent('ajaxfriendadd', 'EventAjaxFriendAdd');
$this->AddEvent('ajaxfrienddelete', 'EventAjaxFriendDelete');
$this->AddEvent('ajaxfriendaccept', 'EventAjaxFriendAccept');
$this->AddEventPreg('/^[\w\-\_]+$/i','/^(whois)?$/i','EventWhois');
$this->AddEventPreg('/^[\w\-\_]+$/i','/^favourites$/i','/^comments$/i','/^(page(\d+))?$/i','EventFavouriteComments');
@ -198,9 +199,9 @@ class ActionProfile extends Action {
*/
public function EventFriendOffer() {
require_once Config::Get('path.root.engine').'/lib/external/XXTEA/encrypt.php';
$sUserId=xxtea_decrypt(base64_decode($this->GetParam(1)), Config::Get('module.talk.encrypt'));
//$sUserId=$this->GetParam(1);
$sUserId=xxtea_decrypt(base64_decode(urldecode($this->GetParam(1))), Config::Get('module.talk.encrypt'));
list($sUserId,)=explode('_',$sUserId,2);
$sAction=$this->GetParam(0);
/**
@ -231,7 +232,14 @@ class ActionProfile extends Action {
* переходим в раздел Talk и возвращаем сообщение об ошибке
*/
$oFriend=$this->User_GetFriend($oUserCurrent->getId(),$oUser->getId(),0);
if(!$oFriend || ($oFriend->getFriendStatus()!=LsUser::USER_FRIEND_OFFER+LsUser::USER_FRIEND_NULL)) {
if(!$oFriend
|| !in_array(
$oFriend->getFriendStatus(),
array(
LsUser::USER_FRIEND_OFFER+LsUser::USER_FRIEND_NULL,
)
)
) {
$sMessage=($oFriend)
? $this->Lang_Get('user_friend_offer_already_done')
: $this->Lang_Get('user_friend_offer_not_found');
@ -241,8 +249,8 @@ class ActionProfile extends Action {
func_header_location(Router::GetPath('talk'));
return ;
}
}
/**
* Устанавливаем новый статус связи
*/
@ -270,6 +278,82 @@ class ActionProfile extends Action {
func_header_location(Router::GetPath('talk'));
}
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
&& $oFriend->getStatusTo()==LsUser::USER_FRIEND_REJECT
&& $oFriend->getUserTo()==$this->oUserCurrent->getId() ) {
/**
* Меняем статус с отвергнутое, на акцептованное
*/
$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;
}
public function EventAjaxFriendAdd() {
$this->Viewer_SetResponseAjax();
$sUserId=getRequest('idUser');
@ -437,7 +521,8 @@ class ActionProfile extends Action {
);
require_once Config::Get('path.root.engine').'/lib/external/XXTEA/encrypt.php';
$sCode=base64_encode(xxtea_encrypt($this->oUserCurrent->getId(), Config::Get('module.talk.encrypt')));
$sCode=$this->oUserCurrent->getId().'_'.$oUser->getId();
$sCode=urlencode(base64_encode(xxtea_encrypt($sCode, Config::Get('module.talk.encrypt'))));
$sText=$this->Lang_Get(
'user_friend_offer_text',

View file

@ -344,7 +344,7 @@ return array(
'user_friend_offer_reject' => 'Заявка отклонена',
'user_friend_offer_send' => 'Заявка отправлена',
'user_friend_already_exist' => 'Пользователь уже является вашим другом',
'user_friend_offer_title' => 'Пользователь %%login%% приглашает пользователя %%friend%% в друзья',
'user_friend_offer_title' => 'Пользователь %%login%% приглашает вас дружить',
'user_friend_offer_text' => "Пользователь %%login%% желает добавить вас в друзья.<br/><br/>%%user_text%%<br/><br/><a href='%%accept_path%%'>Принять</a> - <a href='%%reject_path%%'>Отклонить</a>",
'user_friend_add_deleted' => 'Этот пользователь отказался с вами дружить',
'user_friend_add_text_label' => 'Представьтесь:',

View file

@ -1,6 +1,10 @@
{if $oUserFriend and ($oUserFriend->getFriendStatus()==$USER_FRIEND_ACCEPT+$USER_FRIEND_OFFER or $oUserFriend->getFriendStatus()==$USER_FRIEND_ACCEPT+$USER_FRIEND_ACCEPT) }
<li class="del"><a href="#" title="{$aLang.user_friend_del}" onclick="ajaxDeleteUserFriend(this,{$oUserProfile->getId()},'del'); return false;">{$aLang.user_friend_del}</a></li>
{elseif $oUserFriend and $oUserFriend->getFriendStatus()==$USER_FRIEND_OFFER+$USER_FRIEND_REJECT}
{elseif $oUserFriend and $oUserFriend->getStatusTo()==$USER_FRIEND_REJECT and $oUserFriend->getStatusFrom()==$USER_FRIEND_OFFER and $oUserFriend->getUserTo()==$oUserCurrent->getId()}
<li class="add">
<a href="#" title="{$aLang.user_friend_add}" onclick="ajaxAddUserFriend(this,{$oUserProfile->getId()},'accept'); return false;">{$aLang.user_friend_add}</a>
</li>
{elseif $oUserFriend and $oUserFriend->getFriendStatus()==$USER_FRIEND_OFFER+$USER_FRIEND_REJECT and $oUserFriend->getUserTo()!=$oUserCurrent->getId()}
<li class="del">{$aLang.user_friend_offer_reject}</li>
{elseif $oUserFriend and $oUserFriend->getFriendStatus()==$USER_FRIEND_OFFER+$USER_FRIEND_NULL}
<li class="add">{$aLang.user_friend_offer_send}</li>

View file

@ -14,15 +14,21 @@ function toogleFriendForm(obj) {
function ajaxAddUserFriend(obj,idUser,sAction) {
obj = $(obj).getParent('li');
if(sAction!='link') {
if(sAction!='link' && sAction!='accept') {
sText = obj.getElement('form textarea').get('value');
obj.getElement('form').getChildren().each(function(item){item.setProperty('disabled','disabled')});
} else {
sText='';
}
if(sAction=='accept') {
sPath=aRouter.profile+'ajaxfriendaccept/';
} else {
sPath=aRouter.profile+'ajaxfriendadd/';
}
JsHttpRequest.query(
aRouter.profile+'ajaxfriendadd/',
sPath,
{ idUser: idUser,userText: sText },
function(result, errors) {
if (!result) {