2011-11-26 14:17:17 +00:00
|
|
|
<?php
|
2013-01-19 19:36:40 +00:00
|
|
|
namespace chat\page;
|
|
|
|
use \chat\data;
|
2013-05-26 15:19:04 +00:00
|
|
|
use \wcf\system\exception;
|
2011-11-27 12:33:44 +00:00
|
|
|
use \wcf\system\WCF;
|
2011-11-26 14:17:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the chat-interface
|
2014-02-28 16:06:50 +00:00
|
|
|
*
|
2011-11-26 14:17:17 +00:00
|
|
|
* @author Tim Düsterhus
|
2014-02-27 22:05:09 +00:00
|
|
|
* @copyright 2010-2014 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>
|
2013-01-19 19:36:40 +00:00
|
|
|
* @package be.bastelstu.chat
|
2011-11-26 14:17:17 +00:00
|
|
|
* @subpackage page
|
|
|
|
*/
|
2013-01-19 19:36:40 +00:00
|
|
|
class ChatPage extends \wcf\page\AbstractPage {
|
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
|
|
|
|
*/
|
2013-05-23 20:14:07 +00:00
|
|
|
public $neededModules = array('MODULE_CHAT');
|
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 current room.
|
|
|
|
*
|
2013-01-19 19:36:40 +00:00
|
|
|
* @var \chat\data\room\Room
|
2012-06-04 18:30:08 +00:00
|
|
|
*/
|
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.
|
|
|
|
*
|
2013-01-19 19:36:40 +00:00
|
|
|
* @var \chat\data\room\RoomList
|
2012-06-04 18:30:08 +00:00
|
|
|
*/
|
2011-11-26 16:37:46 +00:00
|
|
|
public $rooms = array();
|
2012-06-04 18:30:08 +00:00
|
|
|
|
2013-06-01 12:37:18 +00:00
|
|
|
/**
|
|
|
|
* List of installed commands.
|
|
|
|
*
|
|
|
|
* @var array<string>
|
|
|
|
*/
|
|
|
|
public $commands = 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
|
|
|
|
2013-09-14 21:45:34 +00:00
|
|
|
/**
|
|
|
|
* attachment handler
|
|
|
|
* @see \wcf\system\attachment\AttachmentHandler
|
|
|
|
*/
|
|
|
|
public $attachmentHandler = null;
|
|
|
|
|
2013-05-10 15:51:48 +00:00
|
|
|
/**
|
|
|
|
* @see wcf\page\AbstractPage::$enableTracking
|
|
|
|
*/
|
|
|
|
public $enableTracking = true;
|
|
|
|
|
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();
|
2013-06-24 16:09:31 +00:00
|
|
|
|
|
|
|
$reflection = new \ReflectionClass('\chat\data\message\Message');
|
|
|
|
|
2011-11-26 16:19:34 +00:00
|
|
|
WCF::getTPL()->assign(array(
|
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,
|
2013-06-01 12:37:18 +00:00
|
|
|
'commands' => $this->commands,
|
2013-06-24 16:09:31 +00:00
|
|
|
'messageTypes' => $reflection->getConstants(),
|
2012-07-14 13:04:53 +00:00
|
|
|
'defaultSmilies' => $this->defaultSmilies,
|
2012-10-25 20:58:54 +00:00
|
|
|
'smileyCategories' => $this->smileyCategories,
|
2013-09-14 21:45:34 +00:00
|
|
|
'attachmentHandler' => $this->attachmentHandler,
|
2013-01-19 19:36:40 +00:00
|
|
|
'sidebarCollapsed' => \wcf\system\user\collapsible\content\UserCollapsibleContentHandler::getInstance()->isCollapsed('com.woltlab.wcf.collapsibleSidebar', 'be.bastelstu.chat.ChatPage'),
|
|
|
|
'sidebarName' => 'be.bastelstu.chat.ChatPage'
|
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();
|
2013-06-01 12:37:18 +00:00
|
|
|
$this->readCommands();
|
2011-12-23 14:26:54 +00:00
|
|
|
|
2013-04-28 14:54:56 +00:00
|
|
|
// get default smilies
|
|
|
|
if (MODULE_SMILEY) {
|
|
|
|
$this->smileyCategories = \wcf\data\smiley\SmileyCache::getInstance()->getCategories();
|
|
|
|
foreach ($this->smileyCategories as $index => $category) {
|
|
|
|
$category->loadSmilies();
|
|
|
|
|
|
|
|
// remove empty categories
|
|
|
|
if (!count($category) || $category->isDisabled) {
|
|
|
|
unset($this->smileyCategories[$index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$firstCategory = reset($this->smileyCategories);
|
|
|
|
if ($firstCategory) {
|
|
|
|
$this->defaultSmilies = \wcf\data\smiley\SmileyCache::getInstance()->getCategorySmilies($firstCategory->categoryID ?: null);
|
|
|
|
}
|
2012-07-14 13:04:53 +00:00
|
|
|
}
|
2013-09-14 21:45:34 +00:00
|
|
|
|
|
|
|
if (MODULE_ATTACHMENT) {
|
2014-11-15 15:19:53 +00:00
|
|
|
$this->attachmentHandler = new \wcf\system\attachment\AttachmentHandler('be.bastelstu.chat.message', 0, \wcf\util\StringUtil::getRandomID(), 0);
|
2013-09-14 21:45:34 +00:00
|
|
|
}
|
2011-11-26 16:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \wcf\page\IPage::readParameters()
|
|
|
|
*/
|
|
|
|
public function readParameters() {
|
|
|
|
parent::readParameters();
|
|
|
|
|
2011-12-03 16:37:20 +00:00
|
|
|
if (isset($_REQUEST['id'])) $this->roomID = (int) $_REQUEST['id'];
|
2011-11-26 16:19:34 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 12:37:18 +00:00
|
|
|
/**
|
|
|
|
* Reads installed commands.
|
|
|
|
*/
|
|
|
|
public function readCommands() {
|
|
|
|
$regex = new \wcf\system\Regex('Command.class.php$');
|
2013-06-01 15:20:43 +00:00
|
|
|
$directory = \wcf\util\DirectoryUtil::getInstance(CHAT_DIR.'lib/system/command/commands/', false);
|
2013-06-01 12:37:18 +00:00
|
|
|
$files = $directory->getFiles(SORT_ASC, $regex);
|
|
|
|
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$command = $regex->replace(basename($file), '');
|
|
|
|
if ($command == 'Plain') continue;
|
2013-08-19 21:23:26 +00:00
|
|
|
$this->commands[] = mb_strtolower($command);
|
2013-06-01 12:37:18 +00:00
|
|
|
}
|
2013-06-17 21:48:59 +00:00
|
|
|
|
|
|
|
$this->commands = array_merge($this->commands, array_keys(\chat\system\command\CommandHandler::getAliasMap()));
|
|
|
|
sort($this->commands);
|
2013-06-01 12:37:18 +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() {
|
2013-05-24 00:21:49 +00:00
|
|
|
$this->rooms = data\room\RoomCache::getInstance()->getRooms();
|
2011-11-28 20:10:19 +00:00
|
|
|
|
|
|
|
if ($this->roomID === 0) {
|
|
|
|
// no room given
|
2014-02-13 15:39:16 +00:00
|
|
|
if (CHAT_FORCE_ROOM_SELECT) {
|
2014-08-07 23:59:24 +00:00
|
|
|
$this->rooms = array_filter($this->rooms, function ($room) {
|
|
|
|
return $room->canEnter();
|
|
|
|
});
|
|
|
|
|
2014-02-13 15:39:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$room = reset($this->rooms);
|
|
|
|
if ($room === null) {
|
|
|
|
// no valid room found
|
|
|
|
throw new exception\IllegalLinkException();
|
|
|
|
}
|
|
|
|
// redirect to first chat-room
|
|
|
|
\wcf\util\HeaderUtil::redirect(\wcf\system\request\LinkHandler::getInstance()->getLink('Chat', array(
|
2014-08-18 16:20:06 +00:00
|
|
|
'application' => 'chat',
|
2014-02-13 15:39:16 +00:00
|
|
|
'object' => $room
|
|
|
|
)));
|
|
|
|
exit;
|
2011-11-28 20:10:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-26 15:19:04 +00:00
|
|
|
if (!isset($this->rooms[$this->roomID])) throw new exception\IllegalLinkException();
|
2012-09-07 20:37:25 +00:00
|
|
|
$this->room = $this->rooms[$this->roomID];
|
2013-05-26 15:19:04 +00:00
|
|
|
if (!$this->room->canEnter()) throw new 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() {
|
2013-01-19 19:36:40 +00:00
|
|
|
\wcf\system\menu\page\PageMenu::getInstance()->setActiveMenuItem('chat.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();
|
|
|
|
}
|
2013-05-10 15:51:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @see wcf\page\ITrackablePage::getObjectType()
|
|
|
|
*/
|
|
|
|
public function getObjectType() {
|
|
|
|
return 'be.bastelstu.chat.room';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see wcf\page\ITrackablePage::getObjectID()
|
|
|
|
*/
|
|
|
|
public function getObjectID() {
|
2013-05-23 20:40:47 +00:00
|
|
|
if ($this->room === null) return 0;
|
|
|
|
|
2013-05-10 15:51:48 +00:00
|
|
|
return $this->room->roomID;
|
|
|
|
}
|
2011-11-26 14:17:17 +00:00
|
|
|
}
|