2011-11-26 14:17:17 +00:00
|
|
|
<?php
|
|
|
|
namespace wcf\page;
|
2011-11-26 16:37:46 +00:00
|
|
|
use \wcf\data\chat;
|
2011-11-27 12:33:44 +00:00
|
|
|
use \wcf\system\cache\CacheHandler;
|
|
|
|
use \wcf\system\WCF;
|
2011-11-26 14:17:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the chat-interface
|
|
|
|
*
|
|
|
|
* @author Tim Düsterhus
|
|
|
|
* @copyright 2010-2011 Tim Düsterhus
|
|
|
|
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
|
|
|
* @package timwolla.wcf.chat
|
|
|
|
* @subpackage page
|
|
|
|
*/
|
|
|
|
class ChatPage extends AbstractPage {
|
2011-11-27 12:33:44 +00:00
|
|
|
public $chatVersion = '';
|
2011-12-10 15:56:36 +00:00
|
|
|
public $neededModules = array('CHAT_ACTIVE');
|
2011-11-26 16:19:34 +00:00
|
|
|
//public $neededPermissions = array('user.chat.canEnter');
|
2011-12-04 21:46:50 +00:00
|
|
|
public $newestMessages = array();
|
2011-11-26 16:37:46 +00:00
|
|
|
public $room = null;
|
|
|
|
public $roomID = 0;
|
|
|
|
public $rooms = array();
|
2011-11-27 12:07:53 +00:00
|
|
|
public $smilies = array();
|
2011-11-28 20:10:19 +00:00
|
|
|
public $userData = array();
|
2011-11-26 16:19:34 +00:00
|
|
|
|
2011-11-26 14:29:28 +00:00
|
|
|
/**
|
2011-11-26 16:19:34 +00:00
|
|
|
* @see \wcf\page\IPage::assignVariables()
|
|
|
|
*/
|
|
|
|
public function assignVariables() {
|
|
|
|
parent::assignVariables();
|
|
|
|
|
|
|
|
WCF::getTPL()->assign(array(
|
2011-11-27 12:33:44 +00:00
|
|
|
'chatVersion' => $this->chatVersion,
|
2011-12-04 21:46:50 +00:00
|
|
|
'newestMessages' => $this->newestMessages,
|
2011-11-26 16:56:51 +00:00
|
|
|
'room' => $this->room,
|
|
|
|
'roomID' => $this->roomID,
|
2011-11-27 12:07:53 +00:00
|
|
|
'rooms' => $this->rooms,
|
|
|
|
'smilies' => $this->smilies
|
2011-11-26 16:19:34 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-11-27 16:22:07 +00:00
|
|
|
/**
|
|
|
|
* Reads chat-version. Used to avoid caching of JS-File when Tims Chat is updated.
|
|
|
|
*/
|
2011-11-27 12:33:44 +00:00
|
|
|
public function readChatVersion() {
|
|
|
|
CacheHandler::getInstance()->addResource(
|
|
|
|
'packages',
|
|
|
|
WCF_DIR.'cache/cache.packages.php',
|
|
|
|
'wcf\system\cache\builder\PackageCacheBuilder'
|
|
|
|
);
|
|
|
|
$packages = CacheHandler::getInstance()->get('packages');
|
|
|
|
foreach ($packages as $package) {
|
|
|
|
if ($package->package != 'timwolla.wcf.chat') continue;
|
|
|
|
$this->chatVersion = $package->packageVersion;
|
2011-11-27 16:22:07 +00:00
|
|
|
return;
|
2011-11-27 12:33:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-26 16:19:34 +00:00
|
|
|
/**
|
|
|
|
* @see \wcf\page\IPage::readData()
|
|
|
|
*/
|
|
|
|
public function readData() {
|
|
|
|
parent::readData();
|
2011-11-27 11:38:02 +00:00
|
|
|
|
2012-01-21 16:45:53 +00:00
|
|
|
$this->readRoom();
|
2011-12-23 14:26:54 +00:00
|
|
|
$this->userData['color'] = \wcf\util\ChatUtil::readUserData('color');
|
|
|
|
\wcf\util\ChatUtil::writeUserData(array('roomID' => $this->room->roomID));
|
2012-01-14 11:53:18 +00:00
|
|
|
$this->newestMessages = chat\message\ChatMessageList::getNewestMessages($this->room, CHAT_LASTMESSAGES);
|
2012-01-18 20:18:03 +00:00
|
|
|
\wcf\util\ChatUtil::writeUserData(array('lastSeen' => count($this->newestMessages) ? end($this->newestMessages)->messageID : 0));
|
2011-12-23 14:26:54 +00:00
|
|
|
|
2011-12-10 17:05:21 +00:00
|
|
|
if (CHAT_DISPLAY_JOIN_LEAVE) {
|
2011-12-13 21:35:11 +00:00
|
|
|
$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_JOIN,
|
|
|
|
'message' => '',
|
|
|
|
'color1' => $this->userData['color'][1],
|
|
|
|
'color2' => $this->userData['color'][2]
|
|
|
|
)
|
2011-12-10 17:05:21 +00:00
|
|
|
));
|
2011-12-13 21:35:11 +00:00
|
|
|
$messageAction->executeAction();
|
2011-12-26 15:31:37 +00:00
|
|
|
$return = $messageAction->getReturnValues();
|
2011-12-10 17:05:21 +00:00
|
|
|
}
|
2011-11-27 12:07:53 +00:00
|
|
|
|
2011-11-27 12:33:44 +00:00
|
|
|
$this->readDefaultSmileys();
|
|
|
|
$this->readChatVersion();
|
2011-11-26 16:19:34 +00:00
|
|
|
}
|
|
|
|
|
2011-11-28 20:10:19 +00:00
|
|
|
/**
|
|
|
|
* Reads the smilies in the default category.
|
|
|
|
*/
|
|
|
|
public function readDefaultSmileys() {
|
|
|
|
$smilies = \wcf\data\smiley\SmileyCache::getInstance()->getSmilies();
|
|
|
|
$this->smilies = $smilies[null];
|
|
|
|
}
|
|
|
|
|
2011-11-26 16:19:34 +00:00
|
|
|
/**
|
|
|
|
* @see \wcf\page\IPage::readParameters()
|
|
|
|
*/
|
|
|
|
public function readParameters() {
|
|
|
|
parent::readParameters();
|
|
|
|
|
2011-12-26 16:01:24 +00:00
|
|
|
if ($this->action == 'Message') {
|
|
|
|
new ChatMessagePage();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
else if ($this->action == 'Log') {
|
2011-12-10 20:36:33 +00:00
|
|
|
//TODO: Initialise LogPage
|
|
|
|
exit;
|
|
|
|
}
|
2011-12-18 14:49:17 +00:00
|
|
|
else if ($this->action == 'RefreshRoomList') {
|
|
|
|
new ChatRefreshRoomListPage();
|
|
|
|
exit;
|
|
|
|
}
|
2011-12-10 21:15:23 +00:00
|
|
|
else if ($this->action == 'Send') {
|
2011-12-13 21:10:35 +00:00
|
|
|
new \wcf\form\ChatForm();
|
2011-12-10 20:36:33 +00:00
|
|
|
exit;
|
|
|
|
}
|
2012-01-14 15:33:44 +00:00
|
|
|
else if ($this->action == 'Copyright') {
|
|
|
|
new ChatCopyrightPage();
|
|
|
|
exit;
|
|
|
|
}
|
2011-12-10 20:36:33 +00:00
|
|
|
|
2011-12-03 16:37:20 +00:00
|
|
|
if (isset($_REQUEST['id'])) $this->roomID = (int) $_REQUEST['id'];
|
2011-12-18 14:49:17 +00:00
|
|
|
if (isset($_REQUEST['ajax'])) $this->useTemplate = false;
|
2011-11-26 16:19:34 +00:00
|
|
|
}
|
|
|
|
|
2011-11-27 16:22:07 +00:00
|
|
|
/**
|
2011-11-28 20:10:19 +00:00
|
|
|
* Reads room data.
|
2011-11-27 16:22:07 +00:00
|
|
|
*/
|
2011-11-28 20:10:19 +00:00
|
|
|
public function readRoom() {
|
|
|
|
$this->rooms = chat\room\ChatRoom::getCache();
|
|
|
|
|
|
|
|
if ($this->roomID === 0) {
|
|
|
|
// no room given
|
|
|
|
try {
|
|
|
|
// redirect to first chat-room
|
|
|
|
$this->rooms->seek(0);
|
|
|
|
\wcf\util\HeaderUtil::redirect(\wcf\system\request\LinkHandler::getInstance()->getLink('Chat', array(
|
2011-12-19 15:14:27 +00:00
|
|
|
'object' => $this->rooms->current()
|
2011-11-28 20:10:19 +00:00
|
|
|
)));
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
catch (\OutOfBoundsException $e) {
|
|
|
|
// no valid room found
|
|
|
|
throw new \wcf\system\exception\IllegalLinkException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->room = $this->rooms->search($this->roomID);
|
|
|
|
if (!$this->room) throw new \wcf\system\exception\IllegalLinkException();
|
2011-12-26 13:14:03 +00:00
|
|
|
if (!$this->room->canEnter()) throw new \wcf\system\exception\PermissionDeniedException();
|
2011-11-28 20:10:19 +00:00
|
|
|
}
|
|
|
|
|
2011-11-26 16:19:34 +00:00
|
|
|
/**
|
|
|
|
* @see \wcf\page\IPage::show()
|
2011-11-26 14:29:28 +00:00
|
|
|
*/
|
|
|
|
public function show() {
|
2011-11-27 16:22:07 +00:00
|
|
|
// guests are not supported
|
|
|
|
if (!WCF::getUser()->userID) {
|
|
|
|
throw new \wcf\system\exception\PermissionDeniedException();
|
|
|
|
}
|
2011-11-26 14:29:28 +00:00
|
|
|
\wcf\system\menu\page\PageMenu::getInstance()->setActiveMenuItem('wcf.header.menu.chat');
|
2011-11-27 11:49:13 +00:00
|
|
|
|
|
|
|
// remove index breadcrumb
|
|
|
|
WCF::getBreadcrumbs()->remove(0);
|
2011-11-26 14:29:28 +00:00
|
|
|
parent::show();
|
2011-12-18 14:49:17 +00:00
|
|
|
// break if not ajax
|
2011-12-03 16:53:36 +00:00
|
|
|
if ($this->useTemplate) exit;
|
2011-12-03 16:37:20 +00:00
|
|
|
@header('Content-type: application/json');
|
2011-12-18 14:49:17 +00:00
|
|
|
|
2011-12-03 16:37:20 +00:00
|
|
|
echo \wcf\util\JSON::encode(array(
|
2011-12-10 20:55:34 +00:00
|
|
|
'title' => $this->room->getTitle(),
|
2011-12-03 16:37:20 +00:00
|
|
|
'topic' => WCF::getLanguage()->get($this->room->topic)
|
|
|
|
));
|
|
|
|
exit;
|
2011-11-26 14:29:28 +00:00
|
|
|
}
|
2011-11-26 14:17:17 +00:00
|
|
|
}
|