2012-02-18 14:48:58 +00:00
|
|
|
<?php
|
2013-01-19 19:36:40 +00:00
|
|
|
namespace chat\action;
|
|
|
|
use \chat\data;
|
2012-10-20 14:20:52 +00:00
|
|
|
use \wcf\system\exception\IllegalLinkException;
|
2012-02-18 14:48:58 +00:00
|
|
|
use \wcf\system\WCF;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes the user leave Tims Chat.
|
|
|
|
*
|
|
|
|
* @author Tim Düsterhus
|
2013-01-19 19:36:40 +00:00
|
|
|
* @copyright 2010-2013 Tim Düsterhus
|
2012-02-18 14:48:58 +00:00
|
|
|
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
2013-01-19 19:36:40 +00:00
|
|
|
* @package be.bastelstu.chat
|
2012-02-18 14:48:58 +00:00
|
|
|
* @subpackage action
|
|
|
|
*/
|
2013-01-19 19:36:40 +00:00
|
|
|
class LeaveAction extends \wcf\action\AbstractAction {
|
2012-08-08 14:51:24 +00:00
|
|
|
/**
|
|
|
|
* @see wcf\action\AbstractAction::$loginRequired
|
|
|
|
*/
|
|
|
|
public $loginRequired = true;
|
|
|
|
|
2012-02-26 16:55:44 +00:00
|
|
|
/**
|
|
|
|
* @see \wcf\action\AbstractAction::$neededModules
|
|
|
|
*/
|
2012-02-18 14:48:58 +00:00
|
|
|
public $neededModules = array('CHAT_ACTIVE');
|
2012-06-04 19:34:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \wcf\page\AbstractPage::$neededPermissions
|
|
|
|
*/
|
2012-09-07 20:29:02 +00:00
|
|
|
public $neededPermissions = array();
|
2012-06-04 19:34:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The current room.
|
|
|
|
*
|
2013-01-19 19:36:40 +00:00
|
|
|
* @var \chat\data\room\Room
|
2012-06-04 19:34:07 +00:00
|
|
|
*/
|
2012-02-18 14:48:58 +00:00
|
|
|
public $room = null;
|
2012-06-04 19:34:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Values read from the UserStorage of the current user.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2012-02-18 14:48:58 +00:00
|
|
|
public $userData = array();
|
|
|
|
|
2012-08-12 18:30:08 +00:00
|
|
|
/**
|
|
|
|
* shortcut for the active request
|
|
|
|
* @see wcf\system\request\Request::getRequestObject()
|
|
|
|
*/
|
|
|
|
public $request = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disallows direct access.
|
|
|
|
*
|
|
|
|
* @see wcf\page\IPage::__run()
|
|
|
|
*/
|
|
|
|
public function __run() {
|
2012-08-28 19:58:47 +00:00
|
|
|
if (($this->request = \wcf\system\request\RequestHandler::getInstance()->getActiveRequest()->getRequestObject()) === $this) throw new IllegalLinkException();
|
2012-08-12 18:30:08 +00:00
|
|
|
|
|
|
|
parent::__run();
|
|
|
|
}
|
|
|
|
|
2012-02-18 14:48:58 +00:00
|
|
|
/**
|
2012-02-26 16:55:44 +00:00
|
|
|
* @see \wcf\action\IAction::execute()
|
2012-02-18 14:48:58 +00:00
|
|
|
*/
|
|
|
|
public function execute() {
|
|
|
|
parent::execute();
|
|
|
|
|
2013-01-19 19:36:40 +00:00
|
|
|
$this->userData['roomID'] = \chat\util\ChatUtil::readUserData('roomID');
|
2012-02-18 14:48:58 +00:00
|
|
|
|
2013-01-19 19:36:40 +00:00
|
|
|
$cache = data\room\Room::getCache();
|
2012-10-20 14:20:52 +00:00
|
|
|
if (!isset($cache[$this->userData['roomID']])) throw new IllegalLinkException();
|
2012-09-07 20:37:25 +00:00
|
|
|
$this->room = $cache[$this->userData['roomID']];
|
2012-02-18 14:48:58 +00:00
|
|
|
if (!$this->room->canEnter()) throw new \wcf\system\exception\PermissionDeniedException();
|
|
|
|
|
|
|
|
if (CHAT_DISPLAY_JOIN_LEAVE) {
|
2013-01-19 19:36:40 +00:00
|
|
|
$this->userData['color'] = \chat\util\ChatUtil::readUserData('color');
|
2012-02-18 14:48:58 +00:00
|
|
|
|
2012-06-04 19:34:07 +00:00
|
|
|
// leave message
|
2013-01-19 19:36:40 +00:00
|
|
|
$messageAction = new data\message\MessageAction(array(), 'create', array(
|
2012-02-18 14:48:58 +00:00
|
|
|
'data' => array(
|
|
|
|
'roomID' => $this->room->roomID,
|
|
|
|
'sender' => WCF::getUser()->userID,
|
|
|
|
'username' => WCF::getUser()->username,
|
|
|
|
'time' => TIME_NOW,
|
2013-01-19 19:36:40 +00:00
|
|
|
'type' => data\message\Message::TYPE_LEAVE,
|
2012-02-18 14:48:58 +00:00
|
|
|
'message' => '',
|
|
|
|
'color1' => $this->userData['color'][1],
|
|
|
|
'color2' => $this->userData['color'][2]
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$messageAction->executeAction();
|
|
|
|
}
|
|
|
|
|
2012-06-04 19:34:07 +00:00
|
|
|
// set current room to null
|
2013-01-19 19:36:40 +00:00
|
|
|
\chat\util\ChatUtil::writeUserData(array('roomID' => null));
|
2012-02-18 14:48:58 +00:00
|
|
|
|
|
|
|
$this->executed();
|
2012-03-03 22:18:52 +00:00
|
|
|
header("HTTP/1.0 204 No Content");
|
2012-02-18 14:48:58 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|