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\PermissionDeniedException;
|
|
|
|
use \wcf\system\exception\UserInputException;
|
|
|
|
use \wcf\system\WCF;
|
|
|
|
use \wcf\util\StringUtil;
|
2011-12-13 21:10:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts a message
|
|
|
|
*
|
|
|
|
* @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>
|
|
|
|
* @package timwolla.wcf.chat
|
|
|
|
* @subpackage form
|
|
|
|
*/
|
|
|
|
class ChatForm extends AbstractForm {
|
2011-12-20 20:20:32 +00:00
|
|
|
public $enableSmilies = 1;
|
2011-12-26 16:07:46 +00:00
|
|
|
public $message = '';
|
|
|
|
public $room = null;
|
2011-12-13 22:02:00 +00:00
|
|
|
public $userData = array();
|
|
|
|
public $useTemplate = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \wcf\page\AbstractPage::readData()
|
|
|
|
*/
|
|
|
|
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');
|
|
|
|
|
2011-12-26 16:07:46 +00:00
|
|
|
$this->room = chat\room\ChatRoom::getCache()->search($this->userData['roomID']);
|
|
|
|
if (!$this->room) throw new \wcf\system\exception\IllegalLinkException();
|
|
|
|
if (!$this->room->canEnter()) throw new \wcf\system\exception\PermissionDeniedException();
|
|
|
|
|
2011-12-13 22:02:00 +00:00
|
|
|
parent::readData();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \wcf\form\AbstractForm::readFormParameters()
|
|
|
|
*/
|
|
|
|
public function readFormParameters() {
|
|
|
|
parent::readFormParameters();
|
|
|
|
|
|
|
|
if (isset($_REQUEST['text'])) $this->message = 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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \wcf\form\AbstractForm::validate()
|
|
|
|
*/
|
|
|
|
public function validate() {
|
|
|
|
parent::validate();
|
|
|
|
if ($this->message === '') {
|
|
|
|
throw new UserInputException('text');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \wcf\form\AbstractForm::save()
|
|
|
|
*/
|
|
|
|
public function save() {
|
|
|
|
parent::save();
|
|
|
|
|
2011-12-13 22:10:29 +00:00
|
|
|
$commandHandler = new \wcf\system\chat\commands\ChatCommandHandler();
|
|
|
|
var_dump($commandHandler->isCommand($this->message));
|
2011-12-13 22:02:00 +00:00
|
|
|
$messageAction = new chat\message\ChatMessageAction(array(), 'create', array(
|
|
|
|
'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,
|
|
|
|
'time' => TIME_NOW,
|
|
|
|
'type' => chat\message\ChatMessage::TYPE_NORMAL,
|
|
|
|
'message' => $this->message,
|
2011-12-20 20:20:32 +00:00
|
|
|
'enableSmilies' => $this->enableSmilies,
|
2011-12-13 22:02:00 +00:00
|
|
|
'color1' => $this->userData['color'][1],
|
|
|
|
'color2' => $this->userData['color'][2]
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$messageAction->executeAction();
|
|
|
|
|
|
|
|
$this->saved();
|
|
|
|
}
|
2011-12-13 21:10:35 +00:00
|
|
|
}
|