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
|
2012-01-28 16:50:33 +00:00
|
|
|
* @copyright 2010-2012 Tim Düsterhus
|
2011-11-26 14:17:17 +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-11-26 14:17:17 +00:00
|
|
|
* @subpackage page
|
|
|
|
*/
|
|
|
|
class ChatPage extends AbstractPage {
|
2012-06-04 18:30:08 +00:00
|
|
|
/**
|
|
|
|
* The version of this installation of Tims Chat 3.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2011-11-27 12:33:44 +00:00
|
|
|
public $chatVersion = '';
|
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-05-31 14:57:20 +00:00
|
|
|
/**
|
|
|
|
* @see \wcf\page\AbstractPage::$neededModules
|
|
|
|
*/
|
2011-12-10 15:56:36 +00:00
|
|
|
public $neededModules = array('CHAT_ACTIVE');
|
2012-05-31 14:57:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \wcf\page\AbstractPage::$neededPermissions
|
|
|
|
*/
|
2012-09-07 20:29:02 +00:00
|
|
|
public $neededPermissions = array();
|
2012-06-04 18:30:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The last X messages for the current room.
|
|
|
|
*
|
|
|
|
* @var array<\wcf\data\chat\message\ChatMessage>
|
|
|
|
*/
|
2011-12-04 21:46:50 +00:00
|
|
|
public $newestMessages = array();
|
2012-06-04 18:30:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The current room.
|
|
|
|
*
|
|
|
|
* @var \wcf\data\chat\room\ChatRoom
|
|
|
|
*/
|
2011-11-26 16:37:46 +00:00
|
|
|
public $room = null;
|
2012-06-04 18:30:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The given roomID.
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
*/
|
2011-11-26 16:37:46 +00:00
|
|
|
public $roomID = 0;
|
2012-06-04 18:30:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of accessible rooms.
|
|
|
|
*
|
|
|
|
* @var \wcf\data\chat\room\ChatRoomList
|
|
|
|
*/
|
2011-11-26 16:37:46 +00:00
|
|
|
public $rooms = array();
|
2012-06-04 18:30:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of smilies in the default category.
|
|
|
|
*
|
|
|
|
* @var array<\wcf\data\smiley\Smiley>
|
|
|
|
* @see \wcf\data\smiley\SmileyCache
|
|
|
|
*/
|
2012-07-14 13:04:53 +00:00
|
|
|
public $defaultSmilies = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of all smiley categories.
|
|
|
|
*
|
|
|
|
* @var array<\wcf\data\smiley\SmileyCategory>
|
|
|
|
* @see \wcf\data\smiley\SmileyCache
|
|
|
|
*/
|
|
|
|
public $smileyCategories = array();
|
2012-06-04 18:30:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Values read from the UserStorage of the current user.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2011-11-28 20:10:19 +00:00
|
|
|
public $userData = array();
|
2011-11-26 16:19:34 +00:00
|
|
|
|
2012-11-17 13:45:51 +00:00
|
|
|
/**
|
|
|
|
* The request that is actually handled.
|
|
|
|
*
|
|
|
|
* @var mixed
|
|
|
|
*/
|
|
|
|
public $request = null;
|
|
|
|
|
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();
|
2012-07-14 13:04:53 +00:00
|
|
|
|
2011-11-26 16:19:34 +00:00
|
|
|
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,
|
2012-07-14 13:04:53 +00:00
|
|
|
'defaultSmilies' => $this->defaultSmilies,
|
2012-10-25 20:58:54 +00:00
|
|
|
'smileyCategories' => $this->smileyCategories,
|
|
|
|
'sidebarCollapsed' => \wcf\system\user\collapsible\content\UserCollapsibleContentHandler::getInstance()->isCollapsed('com.woltlab.wcf.collapsibleSidebar', 'be.bastelstu.wcf.chat.ChatPage'),
|
|
|
|
'sidebarName' => 'be.bastelstu.wcf.chat.ChatPage'
|
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) {
|
2012-03-12 16:18:15 +00:00
|
|
|
if ($package->package != \wcf\util\ChatUtil::PACKAGE_IDENTIFIER) continue;
|
2011-11-27 12:33:44 +00:00
|
|
|
$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');
|
2012-04-15 19:37:20 +00:00
|
|
|
\wcf\util\ChatUtil::writeUserData(array(
|
|
|
|
'roomID' => $this->room->roomID,
|
|
|
|
'away' => null,
|
|
|
|
'lastActivity' => TIME_NOW
|
|
|
|
));
|
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,
|
2012-08-28 19:53:21 +00:00
|
|
|
'message' => serialize(array('ipAddress' => \wcf\util\UserUtil::convertIPv6To4(\wcf\util\UserUtil::getIpAddress()))),
|
2011-12-13 21:35:11 +00:00
|
|
|
'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();
|
2012-06-04 18:30:08 +00:00
|
|
|
$messageAction->getReturnValues();
|
2011-12-10 17:05:21 +00:00
|
|
|
}
|
2011-11-27 12:07:53 +00:00
|
|
|
|
2012-01-28 15:56:20 +00:00
|
|
|
$this->newestMessages = chat\message\ChatMessageList::getNewestMessages($this->room, CHAT_LASTMESSAGES);
|
2012-03-08 20:30:37 +00:00
|
|
|
try {
|
|
|
|
\wcf\util\ChatUtil::writeUserData(array('lastSeen' => end($this->newestMessages)->messageID));
|
|
|
|
}
|
2012-03-08 21:07:46 +00:00
|
|
|
catch (\wcf\system\exception\SystemException $e) {
|
2012-03-08 20:30:37 +00:00
|
|
|
\wcf\util\ChatUtil::writeUserData(array('lastSeen' => 0));
|
|
|
|
}
|
2012-01-28 15:56:20 +00:00
|
|
|
|
2012-07-14 13:04:53 +00:00
|
|
|
$smileyCategories = \wcf\data\smiley\SmileyCache::getInstance()->getCategories();
|
|
|
|
|
|
|
|
foreach($smileyCategories as $category) {
|
|
|
|
if(!$category->disabled) $this->smileyCategories[] = $category;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->defaultSmilies = \wcf\data\smiley\SmileyCache::getInstance()->getCategorySmilies();
|
2011-11-27 12:33:44 +00:00
|
|
|
$this->readChatVersion();
|
2011-11-26 16:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \wcf\page\IPage::readParameters()
|
|
|
|
*/
|
|
|
|
public function readParameters() {
|
|
|
|
parent::readParameters();
|
|
|
|
|
2012-11-17 13:45:51 +00:00
|
|
|
$this->request = $this;
|
2012-02-18 16:21:57 +00:00
|
|
|
switch ($this->action) {
|
|
|
|
case 'Message':
|
2012-11-17 13:45:51 +00:00
|
|
|
$this->request = new ChatMessagePage();
|
|
|
|
$this->request->__run();
|
2012-02-18 16:21:57 +00:00
|
|
|
exit;
|
|
|
|
case 'Log':
|
2012-11-23 19:42:05 +00:00
|
|
|
$this->request = new ChatLogPage();
|
|
|
|
$this->request->__run();
|
2012-02-18 16:21:57 +00:00
|
|
|
exit;
|
|
|
|
case 'RefreshRoomList':
|
2012-11-17 13:45:51 +00:00
|
|
|
$this->request = new ChatRefreshRoomListPage();
|
|
|
|
$this->request->__run();
|
2012-02-18 16:21:57 +00:00
|
|
|
exit;
|
|
|
|
case 'Send':
|
2012-11-17 13:45:51 +00:00
|
|
|
$this->request = new \wcf\form\ChatForm();
|
|
|
|
$this->request->__run();
|
2012-02-18 16:21:57 +00:00
|
|
|
exit;
|
|
|
|
case 'Leave':
|
2012-11-17 13:45:51 +00:00
|
|
|
$this->request = new \wcf\action\ChatLeaveAction();
|
|
|
|
$this->request->__run();
|
2012-02-18 16:21:57 +00:00
|
|
|
exit;
|
|
|
|
case 'Copyright':
|
2012-11-17 13:45:51 +00:00
|
|
|
$this->request = new ChatCopyrightPage();
|
|
|
|
$this->request->__run();
|
2012-02-18 16:21:57 +00:00
|
|
|
exit;
|
2012-01-14 15:33:44 +00:00
|
|
|
}
|
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
|
2012-09-07 20:37:25 +00:00
|
|
|
$room = reset($this->rooms);
|
|
|
|
if ($room === null) {
|
2011-11-28 20:10:19 +00:00
|
|
|
// no valid room found
|
|
|
|
throw new \wcf\system\exception\IllegalLinkException();
|
|
|
|
}
|
2012-09-07 20:37:25 +00:00
|
|
|
// redirect to first chat-room
|
|
|
|
\wcf\util\HeaderUtil::redirect(\wcf\system\request\LinkHandler::getInstance()->getLink('Chat', array(
|
|
|
|
'object' => $room
|
|
|
|
)));
|
|
|
|
exit;
|
2011-11-28 20:10:19 +00:00
|
|
|
}
|
|
|
|
|
2012-09-07 20:37:25 +00:00
|
|
|
if (!isset($this->rooms[$this->roomID])) throw new \wcf\system\exception\IllegalLinkException();
|
|
|
|
$this->room = $this->rooms[$this->roomID];
|
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() {
|
|
|
|
\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);
|
2012-03-08 21:07:46 +00:00
|
|
|
|
2011-11-26 14:29:28 +00:00
|
|
|
parent::show();
|
2012-03-08 21:07:46 +00:00
|
|
|
|
|
|
|
// break if not using 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
|
|
|
|
2012-01-28 15:56:20 +00:00
|
|
|
$messages = array();
|
|
|
|
foreach ($this->newestMessages as $message) $messages[] = $message->jsonify(true);
|
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(),
|
2012-01-28 15:56:20 +00:00
|
|
|
'topic' => WCF::getLanguage()->get($this->room->topic),
|
|
|
|
'messages' => $messages
|
2011-12-03 16:37:20 +00:00
|
|
|
));
|
|
|
|
exit;
|
2011-11-26 14:29:28 +00:00
|
|
|
}
|
2011-11-26 14:17:17 +00:00
|
|
|
}
|