2011-12-13 21:10:35 +00:00
|
|
|
<?php
|
|
|
|
namespace wcf\form;
|
2011-12-13 22:02:00 +00:00
|
|
|
use \wcf\data\chat;
|
|
|
|
use \wcf\system\exception\UserInputException;
|
|
|
|
use \wcf\system\WCF;
|
|
|
|
use \wcf\util\StringUtil;
|
2011-12-13 21:10:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts a message
|
2012-02-26 16:55:44 +00:00
|
|
|
*
|
|
|
|
* @author Tim Düsterhus
|
2012-01-28 16:50:33 +00:00
|
|
|
* @copyright 2010-2012 Tim Düsterhus
|
2011-12-13 21:10:35 +00:00
|
|
|
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
2012-03-12 16:18:15 +00:00
|
|
|
* @package be.bastelstu.wcf.chat
|
2011-12-13 21:10:35 +00:00
|
|
|
* @subpackage form
|
|
|
|
*/
|
|
|
|
class ChatForm extends AbstractForm {
|
2012-06-04 19:10:03 +00:00
|
|
|
/**
|
|
|
|
* Should HTML be enabled for this message.
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
*/
|
2012-03-23 22:27:15 +00:00
|
|
|
public $enableHTML = 0;
|
2012-06-04 19:10:03 +00:00
|
|
|
|
2013-01-09 20:34:30 +00:00
|
|
|
/**
|
|
|
|
* Should bbcodes be enabled for this message.
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
*/
|
|
|
|
public $enableBBCodes = CHAT_ENABLE_BBCODES;
|
|
|
|
|
2012-06-04 19:10:03 +00:00
|
|
|
/**
|
|
|
|
* Should smilies be enabled for this message.
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
*/
|
2011-12-20 20:20:32 +00:00
|
|
|
public $enableSmilies = 1;
|
2012-06-04 19:10:03 +00:00
|
|
|
|
2012-08-08 14:51:24 +00:00
|
|
|
/**
|
|
|
|
* @see wcf\page\AbstractPage::$loginRequired
|
|
|
|
*/
|
|
|
|
public $loginRequired = true;
|
|
|
|
|
2012-06-04 19:10:03 +00:00
|
|
|
/**
|
|
|
|
* @see \wcf\page\AbstractPage::$neededModules
|
|
|
|
*/
|
|
|
|
public $neededModules = array('CHAT_ACTIVE');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \wcf\page\AbstractPage::$neededPermissions
|
|
|
|
*/
|
2012-09-07 20:29:02 +00:00
|
|
|
public $neededPermissions = array();
|
2012-06-04 19:10:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The given message-string.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2011-12-26 16:07:46 +00:00
|
|
|
public $message = '';
|
2012-06-04 19:10:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The current room.
|
|
|
|
*
|
|
|
|
* @var \wcf\data\chat\room\ChatRoom
|
|
|
|
*/
|
2011-12-26 16:07:46 +00:00
|
|
|
public $room = null;
|
2012-06-04 19:10:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Values read from the UserStorage of the current user.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2011-12-13 22:02:00 +00:00
|
|
|
public $userData = array();
|
2012-02-26 16:55:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \wcf\page\AbstractForm::$useTemplate
|
|
|
|
*/
|
2011-12-13 22:02:00 +00:00
|
|
|
public $useTemplate = false;
|
|
|
|
|
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() {
|
2013-01-09 20:34:30 +00:00
|
|
|
if (($this->request = \wcf\system\request\RequestHandler::getInstance()->getActiveRequest()->getRequestObject()) === $this) throw new \wcf\system\exception\IllegalLinkException();
|
2012-08-12 18:30:08 +00:00
|
|
|
|
|
|
|
parent::__run();
|
|
|
|
}
|
|
|
|
|
2011-12-13 22:02:00 +00:00
|
|
|
/**
|
2012-02-05 17:49:17 +00:00
|
|
|
* @see \wcf\page\IPage::readData()
|
2011-12-13 22:02:00 +00:00
|
|
|
*/
|
|
|
|
public function readData() {
|
2011-12-23 14:26:54 +00:00
|
|
|
$this->userData['color'] = \wcf\util\ChatUtil::readUserData('color');
|
|
|
|
$this->userData['roomID'] = \wcf\util\ChatUtil::readUserData('roomID');
|
2012-03-22 17:45:36 +00:00
|
|
|
$this->userData['away'] = \wcf\util\ChatUtil::readUserData('away');
|
2011-12-23 14:26:54 +00:00
|
|
|
|
2012-09-07 20:37:25 +00:00
|
|
|
$cache = chat\room\ChatRoom::getCache();
|
|
|
|
if (!isset($cache[$this->userData['roomID']])) throw new \wcf\system\exception\IllegalLinkException();
|
|
|
|
$this->room = $cache[$this->userData['roomID']];
|
|
|
|
|
2011-12-26 16:07:46 +00:00
|
|
|
if (!$this->room->canEnter()) throw new \wcf\system\exception\PermissionDeniedException();
|
2012-03-24 20:47:03 +00:00
|
|
|
if (!$this->room->canWrite()) throw new \wcf\system\exception\PermissionDeniedException();
|
2011-12-13 22:02:00 +00:00
|
|
|
parent::readData();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-05 17:49:17 +00:00
|
|
|
* @see \wcf\form\IForm::readFormParameters()
|
2011-12-13 22:02:00 +00:00
|
|
|
*/
|
|
|
|
public function readFormParameters() {
|
|
|
|
parent::readFormParameters();
|
|
|
|
|
2012-03-04 16:04:10 +00:00
|
|
|
if (isset($_REQUEST['text'])) $this->message = \wcf\util\MessageUtil::stripCrap(StringUtil::trim($_REQUEST['text']));
|
2011-12-20 20:20:32 +00:00
|
|
|
if (isset($_REQUEST['smilies'])) $this->enableSmilies = intval($_REQUEST['smilies']);
|
2011-12-13 22:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-05 17:49:17 +00:00
|
|
|
* @see \wcf\form\IForm::validate()
|
2011-12-13 22:02:00 +00:00
|
|
|
*/
|
|
|
|
public function validate() {
|
|
|
|
parent::validate();
|
2012-03-04 14:48:10 +00:00
|
|
|
|
2011-12-13 22:02:00 +00:00
|
|
|
if ($this->message === '') {
|
|
|
|
throw new UserInputException('text');
|
|
|
|
}
|
2012-03-04 14:48:10 +00:00
|
|
|
|
|
|
|
if (strlen($this->message) > CHAT_MAX_LENGTH) {
|
|
|
|
throw new UserInputException('text', 'tooLong');
|
|
|
|
}
|
2011-12-13 22:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-05 17:49:17 +00:00
|
|
|
* @see \wcf\form\IForm::save()
|
2011-12-13 22:02:00 +00:00
|
|
|
*/
|
|
|
|
public function save() {
|
|
|
|
parent::save();
|
|
|
|
|
2012-03-22 17:45:36 +00:00
|
|
|
\wcf\util\ChatUtil::writeUserData(array('away' => null));
|
2012-03-24 21:37:47 +00:00
|
|
|
$commandHandler = new \wcf\system\chat\command\CommandHandler($this->message);
|
2011-12-27 13:17:13 +00:00
|
|
|
if ($commandHandler->isCommand()) {
|
|
|
|
try {
|
|
|
|
$command = $commandHandler->loadCommand();
|
|
|
|
|
2013-01-09 20:34:30 +00:00
|
|
|
if ($command->enableSmilies != \wcf\system\chat\command\ICommand::SETTING_USER) $this->enableSmilies = $command->enableSmilies;
|
2012-03-23 22:27:15 +00:00
|
|
|
$this->enableHTML = $command->enableHTML;
|
2013-01-09 20:34:30 +00:00
|
|
|
if ($command->enableBBCodes != \wcf\system\chat\command\ICommand::SETTING_USER) $this->enableBBCodes = $command->enableBBCodes;
|
|
|
|
|
2011-12-27 13:17:13 +00:00
|
|
|
$type = $command->getType();
|
|
|
|
$this->message = $command->getMessage();
|
2011-12-27 13:34:42 +00:00
|
|
|
$receiver = $command->getReceiver();
|
2011-12-27 13:17:13 +00:00
|
|
|
}
|
2012-03-24 21:37:47 +00:00
|
|
|
catch (\wcf\system\chat\command\NotFoundException $e) {
|
2012-10-20 16:04:46 +00:00
|
|
|
$this->message = WCF::getLanguage()->get('wcf.chat.error.notFound');
|
2011-12-27 13:17:13 +00:00
|
|
|
$type = chat\message\ChatMessage::TYPE_ERROR;
|
2011-12-27 13:34:42 +00:00
|
|
|
$receiver = WCF::getUser()->userID;
|
2011-12-27 13:17:13 +00:00
|
|
|
}
|
2012-03-24 21:37:47 +00:00
|
|
|
catch (\wcf\system\chat\command\UserNotFoundException $e) {
|
2012-10-20 16:04:46 +00:00
|
|
|
$this->message = WCF::getLanguage()->getDynamicVariable('wcf.chat.error.userNotFound', array('username' => $e->getUsername()));
|
2012-03-23 22:27:15 +00:00
|
|
|
$type = chat\message\ChatMessage::TYPE_ERROR;
|
|
|
|
$receiver = WCF::getUser()->userID;
|
2012-10-20 16:04:46 +00:00
|
|
|
$this->enableHTML = 1;
|
2012-03-23 22:27:15 +00:00
|
|
|
}
|
2011-12-27 13:17:13 +00:00
|
|
|
catch (\wcf\system\exception\PermissionDeniedException $e) {
|
2012-10-20 16:04:46 +00:00
|
|
|
$this->message = WCF::getLanguage()->get('wcf.chat.error.permissionDenied');
|
2011-12-27 13:17:13 +00:00
|
|
|
$type = chat\message\ChatMessage::TYPE_ERROR;
|
2011-12-27 13:34:42 +00:00
|
|
|
$receiver = WCF::getUser()->userID;
|
2011-12-27 13:17:13 +00:00
|
|
|
}
|
2012-03-22 16:38:33 +00:00
|
|
|
catch (\Exception $e) {
|
2012-10-20 16:04:46 +00:00
|
|
|
$this->message = WCF::getLanguage()->get('wcf.chat.error.exception');
|
2012-03-22 16:38:33 +00:00
|
|
|
$type = chat\message\ChatMessage::TYPE_ERROR;
|
|
|
|
$receiver = WCF::getUser()->userID;
|
|
|
|
}
|
2011-12-27 13:17:13 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$type = chat\message\ChatMessage::TYPE_NORMAL;
|
2011-12-27 13:34:42 +00:00
|
|
|
$receiver = null;
|
2011-12-27 13:17:13 +00:00
|
|
|
}
|
|
|
|
|
2012-03-22 17:45:36 +00:00
|
|
|
// mark user as back
|
|
|
|
if ($this->userData['away'] !== null) {
|
|
|
|
$messageAction = new chat\message\ChatMessageAction(array(), 'create', array(
|
|
|
|
'data' => array(
|
|
|
|
'roomID' => $this->room->roomID,
|
|
|
|
'sender' => WCF::getUser()->userID,
|
|
|
|
'username' => WCF::getUser()->username,
|
|
|
|
'time' => TIME_NOW,
|
|
|
|
'type' => chat\message\ChatMessage::TYPE_BACK,
|
|
|
|
'message' => '',
|
|
|
|
'color1' => $this->userData['color'][1],
|
|
|
|
'color2' => $this->userData['color'][2]
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$messageAction->executeAction();
|
|
|
|
}
|
|
|
|
|
2012-08-10 15:15:25 +00:00
|
|
|
$this->objectAction = new chat\message\ChatMessageAction(array(), 'create', array(
|
2011-12-13 22:02:00 +00:00
|
|
|
'data' => array(
|
2011-12-26 16:07:46 +00:00
|
|
|
'roomID' => $this->room->roomID,
|
2011-12-13 22:02:00 +00:00
|
|
|
'sender' => WCF::getUser()->userID,
|
|
|
|
'username' => WCF::getUser()->username,
|
2011-12-27 13:34:42 +00:00
|
|
|
'receiver' => $receiver,
|
2011-12-13 22:02:00 +00:00
|
|
|
'time' => TIME_NOW,
|
2011-12-27 13:17:13 +00:00
|
|
|
'type' => $type,
|
2011-12-13 22:02:00 +00:00
|
|
|
'message' => $this->message,
|
2011-12-20 20:20:32 +00:00
|
|
|
'enableSmilies' => $this->enableSmilies,
|
2012-03-23 22:27:15 +00:00
|
|
|
'enableHTML' => $this->enableHTML,
|
2013-01-09 20:34:30 +00:00
|
|
|
'enableBBCodes' => $this->enableBBCodes,
|
2011-12-13 22:02:00 +00:00
|
|
|
'color1' => $this->userData['color'][1],
|
|
|
|
'color2' => $this->userData['color'][2]
|
|
|
|
)
|
|
|
|
));
|
2012-08-10 15:15:25 +00:00
|
|
|
$this->objectAction->executeAction();
|
2011-12-13 22:02:00 +00:00
|
|
|
|
2013-01-14 20:08:44 +00:00
|
|
|
// add activity points
|
|
|
|
\wcf\system\user\activity\point\UserActivityPointHandler::getInstance()->fireEvent('be.bastelstu.wcf.chat.activityPointEvent.message', TIME_NOW, WCF::getUser()->userID);
|
|
|
|
|
2011-12-13 22:02:00 +00:00
|
|
|
$this->saved();
|
|
|
|
}
|
2012-02-05 17:49:17 +00:00
|
|
|
|
|
|
|
/**
|
2012-02-26 16:55:44 +00:00
|
|
|
* @see \wcf\page\IPage::show()
|
2012-02-05 17:49:17 +00:00
|
|
|
*/
|
|
|
|
public function show() {
|
2012-03-23 22:27:15 +00:00
|
|
|
header("HTTP/1.0 204 No Content");
|
2012-02-05 17:49:17 +00:00
|
|
|
parent::show();
|
|
|
|
}
|
2011-12-13 21:10:35 +00:00
|
|
|
}
|