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-11-26 16:19:34 +00:00
|
|
|
//public $neededModules = array('CHAT_ACTIVE');
|
|
|
|
//public $neededPermissions = array('user.chat.canEnter');
|
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-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-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 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;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-26 16:19:34 +00:00
|
|
|
/**
|
|
|
|
* @see \wcf\page\IPage::readData()
|
|
|
|
*/
|
|
|
|
public function readData() {
|
|
|
|
parent::readData();
|
2011-11-26 16:37:46 +00:00
|
|
|
$this->rooms = chat\room\ChatRoom::getCache();
|
2011-11-26 16:56:51 +00:00
|
|
|
if ($this->roomID === 0) {
|
2011-11-27 11:38:02 +00:00
|
|
|
try {
|
|
|
|
$this->rooms->seek(0);
|
|
|
|
\wcf\util\HeaderUtil::redirect(\wcf\system\request\LinkHandler::getInstance()->getLink('Chat', array(
|
|
|
|
'object' => $this->rooms->search($this->rooms->key())
|
|
|
|
)));
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
catch (\OutOfBoundsException $e) {
|
|
|
|
throw new \wcf\system\exception\IllegalLinkException();
|
|
|
|
}
|
2011-11-26 16:56:51 +00:00
|
|
|
}
|
2011-11-26 16:49:35 +00:00
|
|
|
$this->room = $this->rooms->search($this->roomID);
|
|
|
|
|
|
|
|
if (!$this->room) throw new \wcf\system\exception\IllegalLinkException();
|
2011-11-27 11:38:02 +00:00
|
|
|
|
|
|
|
chat\message\ChatMessageEditor::create(array(
|
|
|
|
'roomID' => $this->room->roomID,
|
|
|
|
'sender' => WCF::getUser()->userID,
|
|
|
|
'username' => WCF::getUser()->username,
|
|
|
|
'time' => TIME_NOW,
|
|
|
|
'type' => chat\message\ChatMessage::TYPE_JOIN,
|
|
|
|
'message' => 'join',
|
|
|
|
'enableSmilies' => 0,
|
|
|
|
'enableHTML' => 0,
|
|
|
|
'color1' => 0xFF0000,
|
|
|
|
'color2' => 0x00FF00
|
|
|
|
));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \wcf\page\IPage::readParameters()
|
|
|
|
*/
|
|
|
|
public function readParameters() {
|
|
|
|
parent::readParameters();
|
|
|
|
|
|
|
|
if (isset($_GET['id'])) $this->roomID = (int) $_GET['id'];
|
|
|
|
}
|
|
|
|
|
2011-11-27 12:33:44 +00:00
|
|
|
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::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);
|
2011-11-26 14:29:28 +00:00
|
|
|
parent::show();
|
|
|
|
}
|
2011-11-26 14:17:17 +00:00
|
|
|
}
|