1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-05 16:04:24 +03:00
ifhub.club/classes/actions/ActionSubscribe.class.php

124 lines
3.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*-------------------------------------------------------
*
* 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
*
---------------------------------------------------------
*/
class ActionSubscribe extends Action {
/**
* Инициализация
*
*/
public function Init() {
$this->oUserCurrent=$this->User_GetUserCurrent();
}
/**
* Регистрация евентов
*
*/
protected function RegisterEvent() {
$this->AddEventPreg('/^unsubscribe$/i','/^\w{32}$/i','EventUnsubscribe');
$this->AddEvent('ajax-subscribe-toggle','EventAjaxSubscribeToggle');
}
/**********************************************************************************
************************ РЕАЛИЗАЦИЯ ЭКШЕНА ***************************************
**********************************************************************************
*/
/**
* Отписка от подписки
*/
protected function EventUnsubscribe() {
if ($oSubscribe=$this->Subscribe_GetSubscribeByKey($this->getParam(0)) and $oSubscribe->getStatus()==1) {
$oSubscribe->setStatus(0);
$oSubscribe->setDateRemove(date("Y-m-d H:i:s"));
$this->Subscribe_UpdateSubscribe($oSubscribe);
$this->Message_AddNotice($this->Lang_Get('subscribe_change_ok'),null,true);
}
/**
* Получаем URL для редиректа
*/
if ((!$sUrl=$this->Subscribe_GetUrlTarget($oSubscribe->getTargetType(),$oSubscribe->getTargetId()))) {
$sUrl=Router::GetPath('index');
}
Router::Location($sUrl);
}
/**
* Изменение состояния подписки
*/
protected function EventAjaxSubscribeToggle() {
$this->Viewer_SetResponseAjax('json');
/**
* Получаем емайл подписки и проверяем его на валидность
*/
$sMail=getRequest('mail');
if ($this->oUserCurrent) {
$sMail=$this->oUserCurrent->getMail();
}
if (!func_check($sMail,'mail')) {
$this->Message_AddError($this->Lang_Get('registration_mail_error'),$this->Lang_Get('error'));
return ;
}
/**
* Получаем тип объекта подписки
*/
$sTargetType=getRequest('target_type');
if (!$this->Subscribe_IsAllowTargetType($sTargetType)) {
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
return ;
}
$sTargetId=getRequest('target_id') ? getRequest('target_id') : null;
$iValue=getRequest('value') ? 1 : 0;
$oSubscribe=null;
/**
* Есть ли доступ к подписке гостям?
*/
if (!$this->oUserCurrent and !$this->Subscribe_IsAllowTargetForGuest($sTargetType)) {
$this->Message_AddError($this->Lang_Get('need_authorization'),$this->Lang_Get('error'));
return ;
}
/**
* Проверка объекта подписки
*/
if (!$this->Subscribe_CheckTarget($sTargetType,$sTargetId,$iValue)) {
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
return ;
}
/**
* Если подписка еще не существовала, то создаем её
*/
$oSubscribe=$this->Subscribe_AddSubscribeSimple($sTargetType,$sTargetId,$sMail);
if ($oSubscribe) {
$oSubscribe->setStatus($iValue);
$this->Subscribe_UpdateSubscribe($oSubscribe);
$this->Message_AddNotice($this->Lang_Get('subscribe_change_ok'),$this->Lang_Get('attention'));
return ;
}
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
return ;
}
}
?>